From dfd99794504a835c359e6c92d33d6a748e411ea3 Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Sun, 26 Oct 2025 21:04:37 +0100 Subject: [PATCH] refactor: Optimize tool guidelines and disable tools by default --- ChatView/ClientInterface.cpp | 44 +++++++------------------ settings/GeneralSettings.cpp | 2 +- tools/EditFileTool.cpp | 60 +++++++++++------------------------ tools/FindSymbolTool.cpp | 9 +++--- tools/GetIssuesListTool.cpp | 4 +-- tools/ReadFilesByPathTool.cpp | 6 ++-- tools/SearchInProjectTool.cpp | 5 ++- 7 files changed, 43 insertions(+), 87 deletions(-) diff --git a/ChatView/ClientInterface.cpp b/ChatView/ClientInterface.cpp index c2a075e..6bec293 100644 --- a/ChatView/ClientInterface.cpp +++ b/ChatView/ClientInterface.cpp @@ -88,38 +88,18 @@ void ClientInterface::sendMessage( if (Settings::generalSettings().useTools()) { systemPrompt - += "\n\n# Smart Tool Combinations\n\n" - "**Understanding code structure:**\n" - "find_cpp_symbol → read_project_file_by_path → find_cpp_symbol (for related " - "symbols)\n\n" - "**Finding usages and references:**\n" - "find_cpp_symbol (declaration) → search_in_project (with precise name) → read " - "files\n\n" - "**Fixing compilation errors:**\n" - "get_issues_list → find_cpp_symbol (error location) → read_project_file_by_path " - "→ edit_project_file\n\n" - "**Complex refactoring:**\n" - "find_cpp_symbol (all targets) → read files → search_in_project (verify " - "coverage) → edit files\n\n" - "**Adding features to existing code:**\n" - "find_cpp_symbol (target class/namespace) → read_project_file_by_path → " - "edit_project_file\n\n" - "# Best Practices\n\n" - "- **Prefer semantic over text search**: Use find_cpp_symbol before " - "search_in_project\n" - "- **Make atomic edits**: One comprehensive change instead of multiple small " - "ones\n" - "- **Read once, understand fully**: Avoid re-reading the same file multiple " - "times\n" - "- **Start with visible context**: Use read_visible_files when user references " - "current work\n" - "- **Verify before editing**: Always read and understand code before proposing " - "changes\n" - "- **Use file patterns**: Narrow search_in_project with *.cpp, *.h patterns\n" - "- **Chain intelligently**: Each tool result should inform the next tool " - "choice\n" - "- **Fix related issues together**: When fixing errors, address all related " - "problems in one edit\n"; + += "\n\n# Tool Usage Guidelines\n\n" + "**Workflow patterns:**\n" + "- Code structure: find_cpp_symbol → read_files_by_path\n" + "- Find usages: find_cpp_symbol → search_in_project\n" + "- Fix errors: get_issues_list → find_cpp_symbol → read_files_by_path → edit_file\n" + "- Refactoring: find_cpp_symbol → read_files → search_in_project → edit_file\n\n" + "**Best practices:**\n" + "- Prefer find_cpp_symbol over search_in_project for code symbols\n" + "- Read once, edit comprehensively (atomic edits)\n" + "- Use read_visible_files for current editor context\n" + "- Verify before editing\n" + "- Use file patterns (*.cpp, *.h) to narrow searches\n"; } auto project = LLMCore::RulesLoader::getActiveProject(); diff --git a/settings/GeneralSettings.cpp b/settings/GeneralSettings.cpp index 2583a81..6383048 100644 --- a/settings/GeneralSettings.cpp +++ b/settings/GeneralSettings.cpp @@ -212,7 +212,7 @@ GeneralSettings::GeneralSettings() "Enable tool use capabilities for the assistant(OpenAI function calling, Claude tools " "and etc) " "if plugin and provider support")); - useTools.setDefaultValue(true); + useTools.setDefaultValue(false); allowFileSystemRead.setSettingsKey(Constants::CA_ALLOW_FILE_SYSTEM_READ); allowFileSystemRead.setLabelText(Tr::tr("Allow File System Read Access for tools")); diff --git a/tools/EditFileTool.cpp b/tools/EditFileTool.cpp index 30d2444..13439a9 100644 --- a/tools/EditFileTool.cpp +++ b/tools/EditFileTool.cpp @@ -56,50 +56,28 @@ QString EditFileTool::stringName() const QString EditFileTool::description() const { - return "Edit a project file with two distinct modes of operation. " - "IMPORTANT: All text fields must contain COMPLETE LINES with trailing newlines (\\n). " - "If you forget to add \\n, it will be added automatically.\n" + return "Edit project files with two modes: REPLACE (find and replace text) or INSERT_AFTER " + "(insert after specific line). All text parameters must be complete lines with trailing " + "newlines (\\n auto-added if missing).\n" "\n" - "TWO MODES OF OPERATION:\n" + "REPLACE MODE:\n" + "- Finds search_text and replaces with new_text\n" + "- Context verification: line_before/line_after searched NEAR search_text (~500 chars), " + "not necessarily adjacent\n" + "- Both context lines: most precise matching\n" + "- One context line: directional search (before/after)\n" + "- No context: first occurrence\n" "\n" - "1. REPLACE MODE (mode='replace'):\n" - " - Finds search_text in the file and replaces it with new_text\n" - " - REQUIRED: search_text (the text to find and replace)\n" - " - OPTIONAL: line_before and/or line_after for context verification\n" - " - Context verification strategy:\n" - " * line_before/line_after are searched NEAR search_text (within ~500 chars)\n" - " * They do NOT need to be immediately adjacent to search_text\n" - " * Both provided: BOTH must be found near search_text (most precise)\n" - " * Only line_before: must be found BEFORE search_text\n" - " * Only line_after: must be found AFTER search_text\n" - " * Neither: accepts first occurrence (use when search_text is unique)\n" - " - Use this to replace existing content\n" + "INSERT_AFTER MODE:\n" + "- Inserts new_text RIGHT AFTER line_before\n" + "- Empty line_before: inserts at file start (useful for empty files)\n" + "- line_after: must IMMEDIATELY follow line_before for verification\n" + "- search_text is ignored\n" "\n" - "2. INSERT_AFTER MODE (mode='insert_after'):\n" - " - Inserts new_text after the line specified in line_before\n" - " - If line_before is empty, inserts at the beginning of the file (useful for empty files)\n" - " - OPTIONAL: line_before (the line to insert after; empty = insert at start)\n" - " - OPTIONAL: line_after (must IMMEDIATELY follow line_before for verification)\n" - " - search_text is IGNORED\n" - " - Use this to insert content after a specific line or at the start of file\n" - " - Note: In this mode, new_text is inserted RIGHT AFTER line_before\n" - "\n" - "BEST PRACTICES for multiple edits to the same file:\n" - "- Use INSERT_AFTER mode for sequential additions (each edit uses previous addition as line_before)\n" - "- Provide stable context lines that won't be modified by current or subsequent edits\n" - "- For empty files: use INSERT_AFTER with empty line_before\n" - "- Example: When adding multiple class properties:\n" - " * First edit: INSERT_AFTER with class declaration as line_before\n" - " * Second edit: INSERT_AFTER with first property as line_before\n" - " * Third edit: INSERT_AFTER with second property as line_before\n" - "\n" - "Parameters:\n" - "- mode: 'replace' or 'insert_after'\n" - "- filepath: absolute or relative file path to edit\n" - "- new_text: complete line(s) to insert/replace (with \\n)\n" - "- search_text: (replace mode only) complete line(s) to find and replace (with \\n)\n" - "- line_before: complete line for context (with \\n), usage depends on mode\n" - "- line_after: complete line for context (with \\n), usage depends on mode"; + "BEST PRACTICES:\n" + "- Sequential additions: use INSERT_AFTER with previous addition as line_before\n" + "- Provide stable context lines that won't change\n" + "- Make atomic edits (one comprehensive change vs multiple small ones)"; } QJsonObject EditFileTool::getDefinition(LLMCore::ToolSchemaFormat format) const diff --git a/tools/FindSymbolTool.cpp b/tools/FindSymbolTool.cpp index 559ec51..b949116 100644 --- a/tools/FindSymbolTool.cpp +++ b/tools/FindSymbolTool.cpp @@ -51,11 +51,10 @@ QString FindSymbolTool::stringName() const QString FindSymbolTool::description() const { - return "Find C++ symbols (classes, functions, enums, variables, typedefs, namespaces) in the " - "project. " - "Returns file paths and line numbers where symbols are defined. " - "Use read_project_file_by_path to read the actual code. " - "Supports exact match, wildcard patterns, and regular expressions."; + return "Find C++ symbols (classes, functions, enums, variables, typedefs, namespaces) in the project. " + "Returns file paths and line numbers. " + "Supports exact match, wildcards (* patterns), and regex. " + "Use read_files_by_path to read the actual code after finding symbols."; } QJsonObject FindSymbolTool::getDefinition(LLMCore::ToolSchemaFormat format) const diff --git a/tools/GetIssuesListTool.cpp b/tools/GetIssuesListTool.cpp index 344ee0c..502925a 100644 --- a/tools/GetIssuesListTool.cpp +++ b/tools/GetIssuesListTool.cpp @@ -139,8 +139,8 @@ QString GetIssuesListTool::stringName() const QString GetIssuesListTool::description() const { return "Get compilation errors, warnings, and diagnostics from Qt Creator's Issues panel. " - "Filter by severity ('error', 'warning', or 'all'). " - "Returns issue descriptions with file paths and line numbers."; + "Returns issue descriptions with file paths and line numbers. " + "Optional severity filter: 'error', 'warning', or 'all' (default)."; } QJsonObject GetIssuesListTool::getDefinition(LLMCore::ToolSchemaFormat format) const diff --git a/tools/ReadFilesByPathTool.cpp b/tools/ReadFilesByPathTool.cpp index 69b9e4e..3b8285e 100644 --- a/tools/ReadFilesByPathTool.cpp +++ b/tools/ReadFilesByPathTool.cpp @@ -54,9 +54,9 @@ QString ReadFilesByPathTool::stringName() const QString ReadFilesByPathTool::description() const { - return "Read content of one or multiple project files by absolute path(s). " - "Use 'filepath' for single file or 'filepaths' for multiple files (e.g., .h and .cpp). " - "Files must exist, be within project scope, and not excluded by .qodeassistignore."; + return "Read content of project file(s) by absolute path. " + "Use 'filepath' for single file or 'filepaths' array for multiple files (e.g., .h and .cpp). " + "Files must exist and not be excluded by .qodeassistignore."; } QJsonObject ReadFilesByPathTool::getDefinition(LLMCore::ToolSchemaFormat format) const diff --git a/tools/SearchInProjectTool.cpp b/tools/SearchInProjectTool.cpp index 9ad323d..5bc2025 100644 --- a/tools/SearchInProjectTool.cpp +++ b/tools/SearchInProjectTool.cpp @@ -51,10 +51,9 @@ QString SearchInProjectTool::stringName() const QString SearchInProjectTool::description() const { - return "Search for text or patterns across all project files. " + return "Search for text or regex patterns across project files. " "Returns matching lines with file paths, line numbers, and context. " - "Supports plain text, regex, case-sensitive/insensitive search, whole word matching, " - "and file pattern filtering."; + "Supports case-sensitive/insensitive, whole word matching, and file pattern filtering (*.cpp, *.h)."; } QJsonObject SearchInProjectTool::getDefinition(LLMCore::ToolSchemaFormat format) const