mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-11-12 21:12:44 -05:00
feat: Add edit file tool (#249)
* feat: Add edit file tool * feat: Add icons for action buttons
This commit is contained in:
@ -7,6 +7,7 @@ add_library(QodeAssistSettings STATIC
|
||||
SettingsTr.hpp
|
||||
CodeCompletionSettings.hpp CodeCompletionSettings.cpp
|
||||
ChatAssistantSettings.hpp ChatAssistantSettings.cpp
|
||||
ToolsSettings.hpp ToolsSettings.cpp
|
||||
SettingsDialog.hpp SettingsDialog.cpp
|
||||
ProjectSettings.hpp ProjectSettings.cpp
|
||||
ProjectSettingsPanel.hpp ProjectSettingsPanel.cpp
|
||||
|
||||
@ -205,40 +205,6 @@ GeneralSettings::GeneralSettings()
|
||||
caTemplateDescription.setDefaultValue("");
|
||||
caTemplateDescription.setLabelText(TrConstants::CURRENT_TEMPLATE_DESCRIPTION);
|
||||
|
||||
useTools.setSettingsKey(Constants::CA_USE_TOOLS);
|
||||
useTools.setLabelText(Tr::tr("Enable tools"));
|
||||
useTools.setToolTip(
|
||||
Tr::tr(
|
||||
"Enable tool use capabilities for the assistant(OpenAI function calling, Claude tools "
|
||||
"and etc) "
|
||||
"if plugin and provider support"));
|
||||
useTools.setDefaultValue(true);
|
||||
|
||||
allowFileSystemRead.setSettingsKey(Constants::CA_ALLOW_FILE_SYSTEM_READ);
|
||||
allowFileSystemRead.setLabelText(Tr::tr("Allow File System Read Access for tools"));
|
||||
allowFileSystemRead.setToolTip(
|
||||
Tr::tr("Allow tools to read files from disk (project files, open editors)"));
|
||||
allowFileSystemRead.setDefaultValue(true);
|
||||
|
||||
allowFileSystemWrite.setSettingsKey(Constants::CA_ALLOW_FILE_SYSTEM_WRITE);
|
||||
allowFileSystemWrite.setLabelText(Tr::tr("Allow File System Write Access for tools"));
|
||||
allowFileSystemWrite.setToolTip(
|
||||
Tr::tr("Allow tools to write and modify files on disk (WARNING: Use with caution!)"));
|
||||
allowFileSystemWrite.setDefaultValue(false);
|
||||
|
||||
allowAccessOutsideProject.setSettingsKey(Constants::CA_ALLOW_ACCESS_OUTSIDE_PROJECT);
|
||||
allowAccessOutsideProject.setLabelText(Tr::tr("Allow file access outside project"));
|
||||
allowAccessOutsideProject.setToolTip(
|
||||
Tr::tr("Allow tools to access (read/write) files outside the project scope (system headers, Qt files, external libraries)"));
|
||||
allowAccessOutsideProject.setDefaultValue(true);
|
||||
|
||||
autoApplyFileEdits.setSettingsKey(Constants::CA_AUTO_APPLY_FILE_EDITS);
|
||||
autoApplyFileEdits.setLabelText(Tr::tr("Automatically apply file edits"));
|
||||
autoApplyFileEdits.setToolTip(
|
||||
Tr::tr("When enabled, file edits suggested by AI will be applied automatically. "
|
||||
"When disabled, you will need to manually approve each edit."));
|
||||
autoApplyFileEdits.setDefaultValue(false);
|
||||
|
||||
readSettings();
|
||||
|
||||
Logger::instance().setLoggingEnabled(enableLogging());
|
||||
@ -286,9 +252,6 @@ GeneralSettings::GeneralSettings()
|
||||
title(TrConstants::CHAT_ASSISTANT),
|
||||
Column{
|
||||
caGrid,
|
||||
Column{
|
||||
useTools, allowFileSystemRead, allowFileSystemWrite, allowAccessOutsideProject,
|
||||
/*autoApplyFileEdits*/},
|
||||
caTemplateDescription}};
|
||||
|
||||
auto rootLayout = Column{
|
||||
@ -543,11 +506,6 @@ void GeneralSettings::resetPageToDefaults()
|
||||
resetAspect(ccPreset1CustomEndpoint);
|
||||
resetAspect(caEndpointMode);
|
||||
resetAspect(caCustomEndpoint);
|
||||
resetAspect(useTools);
|
||||
resetAspect(allowFileSystemRead);
|
||||
resetAspect(allowFileSystemWrite);
|
||||
resetAspect(allowAccessOutsideProject);
|
||||
resetAspect(autoApplyFileEdits);
|
||||
writeSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,12 +100,6 @@ public:
|
||||
Utils::StringAspect caStatus{this};
|
||||
ButtonAspect caTest{this};
|
||||
|
||||
Utils::BoolAspect useTools{this};
|
||||
Utils::BoolAspect allowFileSystemRead{this};
|
||||
Utils::BoolAspect allowFileSystemWrite{this};
|
||||
Utils::BoolAspect allowAccessOutsideProject{this};
|
||||
Utils::BoolAspect autoApplyFileEdits{this};
|
||||
|
||||
Utils::StringAspect caTemplateDescription{this};
|
||||
|
||||
void showSelectionDialog(
|
||||
|
||||
@ -89,6 +89,7 @@ const char CA_USE_TOOLS[] = "QodeAssist.caUseTools";
|
||||
const char CA_ALLOW_FILE_SYSTEM_READ[] = "QodeAssist.caAllowFileSystemRead";
|
||||
const char CA_ALLOW_FILE_SYSTEM_WRITE[] = "QodeAssist.caAllowFileSystemWrite";
|
||||
const char CA_ALLOW_ACCESS_OUTSIDE_PROJECT[] = "QodeAssist.caAllowAccessOutsideProject";
|
||||
const char CA_ENABLE_EDIT_FILE_TOOL[] = "QodeAssist.caEnableEditFileTool";
|
||||
|
||||
const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
|
||||
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";
|
||||
@ -96,13 +97,14 @@ const char QODE_ASSIST_CODE_COMPLETION_SETTINGS_PAGE_ID[]
|
||||
= "QodeAssist.2CodeCompletionSettingsPageId";
|
||||
const char QODE_ASSIST_CHAT_ASSISTANT_SETTINGS_PAGE_ID[]
|
||||
= "QodeAssist.3ChatAssistantSettingsPageId";
|
||||
const char QODE_ASSIST_CUSTOM_PROMPT_SETTINGS_PAGE_ID[] = "QodeAssist.4CustomPromptSettingsPageId";
|
||||
const char QODE_ASSIST_TOOLS_SETTINGS_PAGE_ID[] = "QodeAssist.4ToolsSettingsPageId";
|
||||
const char QODE_ASSIST_CUSTOM_PROMPT_SETTINGS_PAGE_ID[] = "QodeAssist.5CustomPromptSettingsPageId";
|
||||
|
||||
const char QODE_ASSIST_GENERAL_OPTIONS_CATEGORY[] = "QodeAssist.Category";
|
||||
const char QODE_ASSIST_GENERAL_OPTIONS_DISPLAY_CATEGORY[] = "QodeAssist";
|
||||
|
||||
// Provider Settings Page ID
|
||||
const char QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID[] = "QodeAssist.5ProviderSettingsPageId";
|
||||
const char QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID[] = "QodeAssist.6ProviderSettingsPageId";
|
||||
|
||||
// Provider API Keys
|
||||
const char OPEN_ROUTER_API_KEY[] = "QodeAssist.openRouterApiKey";
|
||||
|
||||
157
settings/ToolsSettings.cpp
Normal file
157
settings/ToolsSettings.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 Petr Mironychev
|
||||
*
|
||||
* This file is part of QodeAssist.
|
||||
*
|
||||
* QodeAssist is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QodeAssist is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ToolsSettings.hpp"
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "SettingsConstants.hpp"
|
||||
#include "SettingsTr.hpp"
|
||||
#include "SettingsUtils.hpp"
|
||||
|
||||
namespace QodeAssist::Settings {
|
||||
|
||||
ToolsSettings &toolsSettings()
|
||||
{
|
||||
static ToolsSettings settings;
|
||||
return settings;
|
||||
}
|
||||
|
||||
ToolsSettings::ToolsSettings()
|
||||
{
|
||||
setAutoApply(false);
|
||||
|
||||
setDisplayName(Tr::tr("Tools"));
|
||||
|
||||
useTools.setSettingsKey(Constants::CA_USE_TOOLS);
|
||||
useTools.setLabelText(Tr::tr("Enable tools"));
|
||||
useTools.setToolTip(Tr::tr(
|
||||
"Enable tool use capabilities for the assistant (OpenAI function calling, Claude tools "
|
||||
"and etc) if plugin and provider support"));
|
||||
useTools.setDefaultValue(true);
|
||||
|
||||
allowFileSystemRead.setSettingsKey(Constants::CA_ALLOW_FILE_SYSTEM_READ);
|
||||
allowFileSystemRead.setLabelText(Tr::tr("Allow File System Read Access for tools"));
|
||||
allowFileSystemRead.setToolTip(
|
||||
Tr::tr("Allow tools to read files from disk (project files, open editors)"));
|
||||
allowFileSystemRead.setDefaultValue(true);
|
||||
|
||||
allowFileSystemWrite.setSettingsKey(Constants::CA_ALLOW_FILE_SYSTEM_WRITE);
|
||||
allowFileSystemWrite.setLabelText(Tr::tr("Allow File System Write Access for tools"));
|
||||
allowFileSystemWrite.setToolTip(
|
||||
Tr::tr("Allow tools to write and modify files on disk (WARNING: Use with caution!)"));
|
||||
allowFileSystemWrite.setDefaultValue(false);
|
||||
|
||||
allowAccessOutsideProject.setSettingsKey(Constants::CA_ALLOW_ACCESS_OUTSIDE_PROJECT);
|
||||
allowAccessOutsideProject.setLabelText(Tr::tr("Allow file access outside project"));
|
||||
allowAccessOutsideProject.setToolTip(
|
||||
Tr::tr("Allow tools to access (read/write) files outside the project scope (system "
|
||||
"headers, Qt files, external libraries)"));
|
||||
allowAccessOutsideProject.setDefaultValue(true);
|
||||
|
||||
autoApplyFileEdits.setSettingsKey(Constants::CA_AUTO_APPLY_FILE_EDITS);
|
||||
autoApplyFileEdits.setLabelText(Tr::tr("Automatically apply file edits"));
|
||||
autoApplyFileEdits.setToolTip(
|
||||
Tr::tr("When enabled, file edits suggested by AI will be applied automatically. "
|
||||
"When disabled, you will need to manually approve each edit."));
|
||||
autoApplyFileEdits.setDefaultValue(false);
|
||||
|
||||
enableEditFileTool.setSettingsKey(Constants::CA_ENABLE_EDIT_FILE_TOOL);
|
||||
enableEditFileTool.setLabelText(Tr::tr("Enable Edit File Tool (Experimental)"));
|
||||
enableEditFileTool.setToolTip(
|
||||
Tr::tr("Enable the experimental edit_file tool that allows AI to directly modify files. "
|
||||
"This feature is under testing and may have unexpected behavior."));
|
||||
enableEditFileTool.setDefaultValue(false);
|
||||
|
||||
resetToDefaults.m_buttonText = Tr::tr("Reset Page to Defaults");
|
||||
|
||||
readSettings();
|
||||
|
||||
setupConnections();
|
||||
|
||||
setLayouter([this]() {
|
||||
using namespace Layouting;
|
||||
|
||||
return Column{
|
||||
Row{Stretch{1}, resetToDefaults},
|
||||
Space{8},
|
||||
Group{
|
||||
title(Tr::tr("Tool Settings")),
|
||||
Column{
|
||||
useTools,
|
||||
Space{8},
|
||||
allowFileSystemRead,
|
||||
allowFileSystemWrite,
|
||||
allowAccessOutsideProject,
|
||||
}},
|
||||
Space{8},
|
||||
Group{
|
||||
title(Tr::tr("Experimental Features")),
|
||||
Column{enableEditFileTool, autoApplyFileEdits}},
|
||||
Stretch{1}};
|
||||
});
|
||||
}
|
||||
|
||||
void ToolsSettings::setupConnections()
|
||||
{
|
||||
connect(
|
||||
&resetToDefaults,
|
||||
&ButtonAspect::clicked,
|
||||
this,
|
||||
&ToolsSettings::resetSettingsToDefaults);
|
||||
}
|
||||
|
||||
void ToolsSettings::resetSettingsToDefaults()
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(
|
||||
Core::ICore::dialogParent(),
|
||||
Tr::tr("Reset Settings"),
|
||||
Tr::tr("Are you sure you want to reset all settings to default values?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if (reply == QMessageBox::Yes) {
|
||||
resetAspect(useTools);
|
||||
resetAspect(allowFileSystemRead);
|
||||
resetAspect(allowFileSystemWrite);
|
||||
resetAspect(allowAccessOutsideProject);
|
||||
resetAspect(autoApplyFileEdits);
|
||||
resetAspect(enableEditFileTool);
|
||||
writeSettings();
|
||||
}
|
||||
}
|
||||
|
||||
class ToolsSettingsPage : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
ToolsSettingsPage()
|
||||
{
|
||||
setId(Constants::QODE_ASSIST_TOOLS_SETTINGS_PAGE_ID);
|
||||
setDisplayName(Tr::tr("Tools"));
|
||||
setCategory(Constants::QODE_ASSIST_GENERAL_OPTIONS_CATEGORY);
|
||||
setSettingsProvider([] { return &toolsSettings(); });
|
||||
}
|
||||
};
|
||||
|
||||
const ToolsSettingsPage toolsSettingsPage;
|
||||
|
||||
} // namespace QodeAssist::Settings
|
||||
51
settings/ToolsSettings.hpp
Normal file
51
settings/ToolsSettings.hpp
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 Petr Mironychev
|
||||
*
|
||||
* This file is part of QodeAssist.
|
||||
*
|
||||
* QodeAssist is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QodeAssist is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utils/aspects.h>
|
||||
|
||||
#include "ButtonAspect.hpp"
|
||||
|
||||
namespace QodeAssist::Settings {
|
||||
|
||||
class ToolsSettings : public Utils::AspectContainer
|
||||
{
|
||||
public:
|
||||
ToolsSettings();
|
||||
|
||||
ButtonAspect resetToDefaults{this};
|
||||
|
||||
Utils::BoolAspect useTools{this};
|
||||
Utils::BoolAspect allowFileSystemRead{this};
|
||||
Utils::BoolAspect allowFileSystemWrite{this};
|
||||
Utils::BoolAspect allowAccessOutsideProject{this};
|
||||
|
||||
// Experimental features
|
||||
Utils::BoolAspect enableEditFileTool{this};
|
||||
Utils::BoolAspect autoApplyFileEdits{this};
|
||||
|
||||
private:
|
||||
void setupConnections();
|
||||
void resetSettingsToDefaults();
|
||||
};
|
||||
|
||||
ToolsSettings &toolsSettings();
|
||||
|
||||
} // namespace QodeAssist::Settings
|
||||
Reference in New Issue
Block a user