From e200278f9aa1b7a89e7a2469f94c138f5421c31d Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Mon, 29 Jun 2026 00:27:01 +0200 Subject: [PATCH] fix: Move Quick Refactor agent to toml file --- QuickRefactorHandler.cpp | 55 +++++++------------ QuickRefactorHandler.hpp | 2 +- sources/agents/agents.qrc | 4 ++ sources/agents/claude_quick_refactor.toml | 17 ++++-- .../agents/claude_quick_refactor_fast.toml | 16 ++++++ sources/agents/ollama_chat_completion.toml | 2 +- sources/agents/ollama_codellama_qml_fim.toml | 18 ++++-- sources/agents/ollama_compression.toml | 17 ++++++ sources/agents/ollama_fim.toml | 2 +- sources/agents/ollama_quick_refactor.toml | 16 ++++++ sources/agents/tasks/quick-refactor.md | 19 +++++++ 11 files changed, 120 insertions(+), 48 deletions(-) create mode 100644 sources/agents/claude_quick_refactor_fast.toml create mode 100644 sources/agents/ollama_compression.toml create mode 100644 sources/agents/ollama_quick_refactor.toml create mode 100644 sources/agents/tasks/quick-refactor.md diff --git a/QuickRefactorHandler.cpp b/QuickRefactorHandler.cpp index 51d49ca..51c25ba 100644 --- a/QuickRefactorHandler.cpp +++ b/QuickRefactorHandler.cpp @@ -185,7 +185,7 @@ void QuickRefactorHandler::prepareAndSendRequest( } session->systemPrompt()->setLayer( - QStringLiteral("refactor"), buildSystemPrompt(editor, range)); + QStringLiteral("refactor"), buildContextLayer(editor, range)); client->setTransferTimeout( static_cast(Settings::generalSettings().requestTimeout() * 1000)); @@ -221,7 +221,7 @@ void QuickRefactorHandler::prepareAndSendRequest( m_activeRequests[requestId] = {QJsonObject{{"id", requestId}}, session}; } -QString QuickRefactorHandler::buildSystemPrompt( +QString QuickRefactorHandler::buildContextLayer( TextEditor::TextEditorWidget *editor, const Utils::Text::Range &range) { Q_UNUSED(range) @@ -306,29 +306,20 @@ QString QuickRefactorHandler::buildSystemPrompt( taggedContent = contextBefore + "" + contextAfter; } - QString systemPrompt = Context::EnvBlockFormatter::formatFile( + QString contextLayer = Context::EnvBlockFormatter::formatFile( {documentInfo.filePath, documentInfo.mimeType}); - systemPrompt += "\n# Code Context with Position Markers\n" + taggedContent; + contextLayer += "\n# Code Context with Position Markers\n" + taggedContent; - systemPrompt += "\n\n# Output Requirements\n## What to Generate:"; - systemPrompt += cursor.hasSelection() + contextLayer += "\n\n# What to Generate:"; + contextLayer += cursor.hasSelection() ? "\n- Generate ONLY the code that should REPLACE the selected text between " " and markers" "\n- Your output will completely replace the selected code" : "\n- Generate ONLY the code that should be INSERTED at the position" "\n- Your output will be inserted at the cursor location"; - systemPrompt += "\n\n## Formatting Rules:" - "\n- Output ONLY the code itself, without ANY explanations or descriptions" - "\n- Do NOT include markdown code blocks (no ```, no language tags)" - "\n- Do NOT add comments explaining what you changed" - "\n- Do NOT repeat existing code, be precise with context" - "\n- Do NOT send in answer or and other tags" - "\n- The output must be ready to insert directly into the editor as-is"; - - systemPrompt += "\n\n## Indentation and Whitespace:"; - + QString indentNote; if (cursor.hasSelection()) { QTextBlock startBlock = documentInfo.document->findBlock(cursor.selectionStart()); int leadingSpaces = 0; @@ -338,12 +329,12 @@ QString QuickRefactorHandler::buildSystemPrompt( else break; } if (leadingSpaces > 0) { - systemPrompt += QString("\n- CRITICAL: The code to replace starts with %1 spaces of indentation" - "\n- Your output MUST start with exactly %1 spaces (or equivalent tabs)" - "\n- Each line in your output must maintain this base indentation") - .arg(leadingSpaces); + indentNote = QString("\n- CRITICAL: The code to replace starts with %1 spaces of indentation" + "\n- Your output MUST start with exactly %1 spaces (or equivalent tabs)" + "\n- Each line in your output must maintain this base indentation") + .arg(leadingSpaces); } - systemPrompt += "\n- PRESERVE all indentation from the original code"; + indentNote += "\n- PRESERVE all indentation from the original code"; } else { QTextBlock block = documentInfo.document->findBlock(cursorPos); QString lineText = block.text(); @@ -354,26 +345,20 @@ QString QuickRefactorHandler::buildSystemPrompt( else break; } if (leadingSpaces > 0) { - systemPrompt += QString("\n- CRITICAL: Current line has %1 spaces of indentation" - "\n- If generating multiline code, EVERY line must start with at least %1 spaces" - "\n- If generating single-line code, it will be inserted inline (no indentation needed)") - .arg(leadingSpaces); + indentNote = QString("\n- CRITICAL: Current line has %1 spaces of indentation" + "\n- If generating multiline code, EVERY line must start with at least %1 spaces" + "\n- If generating single-line code, it will be inserted inline (no indentation needed)") + .arg(leadingSpaces); } } - - systemPrompt += "\n- Use the same indentation style (spaces or tabs) as the surrounding code" - "\n- Maintain consistent indentation for nested blocks" - "\n- Do NOT remove or reduce the base indentation level" - "\n\n## Code Style:" - "\n- Match the coding style of the surrounding code (naming, spacing, braces, etc.)" - "\n- Preserve the original code structure when possible" - "\n- Only change what is necessary to fulfill the user's request"; + if (!indentNote.isEmpty()) + contextLayer += "\n\n## Indentation:" + indentNote; if (Settings::quickRefactorSettings().useOpenFilesInQuickRefactor()) { - systemPrompt += "\n\n" + m_contextManager.openedFilesContext({documentInfo.filePath}); + contextLayer += "\n\n" + m_contextManager.openedFilesContext({documentInfo.filePath}); } - return systemPrompt; + return contextLayer; } void QuickRefactorHandler::cancelRequest() diff --git a/QuickRefactorHandler.hpp b/QuickRefactorHandler.hpp index c9c7266..b7fad4a 100644 --- a/QuickRefactorHandler.hpp +++ b/QuickRefactorHandler.hpp @@ -60,7 +60,7 @@ private: void onRefactorFinished(const QString &requestId); void onRefactorFailed(const QString &requestId, const QodeAssist::ErrorInfo &error); - QString buildSystemPrompt( + QString buildContextLayer( TextEditor::TextEditorWidget *editor, const Utils::Text::Range &range); QString pickRefactorAgent() const; diff --git a/sources/agents/agents.qrc b/sources/agents/agents.qrc index e06f541..aae36ad 100644 --- a/sources/agents/agents.qrc +++ b/sources/agents/agents.qrc @@ -7,6 +7,7 @@ claude_completion.toml claude_compression.toml claude_quick_refactor.toml + claude_quick_refactor_fast.toml openai_base_chat.toml openai_chat_completions.toml openai_responses_base.toml @@ -19,6 +20,8 @@ ollama_base_fim.toml ollama_fim.toml ollama_codellama_qml_fim.toml + ollama_quick_refactor.toml + ollama_compression.toml roles/qt-cpp-developer.md @@ -29,5 +32,6 @@ tasks/chat-compressor.md tasks/code-completion.md + tasks/quick-refactor.md diff --git a/sources/agents/claude_quick_refactor.toml b/sources/agents/claude_quick_refactor.toml index 82b3d56..fe18d50 100644 --- a/sources/agents/claude_quick_refactor.toml +++ b/sources/agents/claude_quick_refactor.toml @@ -2,12 +2,17 @@ schema_version = 1 extends = "Claude Base Chat" name = "Claude Quick Refactor" -description = "Anthropic Claude — deterministic inline refactor. QuickRefactorHandler supplies the refactor system prompt; output is cleaned and inserted into the editor. No thinking; tools off." +description = "Anthropic Claude Sonnet — agentic inline refactor with extended thinking and tools (gathers context before editing). Static output rules from :/tasks/quick-refactor.md; QuickRefactorHandler injects the live editor context (file, code, cursor/selection)." -model = "claude-sonnet-4-6" -enable_tools = false -tags = ["refactor", "claude", "cloud"] +model = "claude-sonnet-4-6" +enable_tools = true +enable_thinking = true +tags = ["refactor", "claude", "cloud"] + +system_prompt = """{{ read_file(":/tasks/quick-refactor.md") }}""" [body] -max_tokens = 16000 -temperature = 0.2 +max_tokens = 16000 +temperature = 1 +thinking = { type = "adaptive", display = "summarized" } +output_config = { effort = "high" } diff --git a/sources/agents/claude_quick_refactor_fast.toml b/sources/agents/claude_quick_refactor_fast.toml new file mode 100644 index 0000000..5424b6f --- /dev/null +++ b/sources/agents/claude_quick_refactor_fast.toml @@ -0,0 +1,16 @@ +schema_version = 1 + +extends = "Claude Base Chat" +name = "Claude Quick Refactor Fast" +description = "Anthropic Claude Haiku — fast single-shot inline refactor. Static output rules from :/tasks/quick-refactor.md; QuickRefactorHandler injects the live editor context (file, code, cursor/selection). No thinking; tools off." + +model = "claude-haiku-4-5" +enable_tools = false +enable_thinking = false +tags = ["refactor", "claude", "cloud", "fast"] + +system_prompt = """{{ read_file(":/tasks/quick-refactor.md") }}""" + +[body] +max_tokens = 8000 +temperature = 0.2 diff --git a/sources/agents/ollama_chat_completion.toml b/sources/agents/ollama_chat_completion.toml index ed96e90..43bceb1 100644 --- a/sources/agents/ollama_chat_completion.toml +++ b/sources/agents/ollama_chat_completion.toml @@ -28,4 +28,4 @@ messages = """ num_predict = 512 temperature = 0.2 keep_alive = "5m" -stop = [""] \ No newline at end of file +stop = [""] diff --git a/sources/agents/ollama_codellama_qml_fim.toml b/sources/agents/ollama_codellama_qml_fim.toml index a8972ed..d389c0e 100644 --- a/sources/agents/ollama_codellama_qml_fim.toml +++ b/sources/agents/ollama_codellama_qml_fim.toml @@ -16,8 +16,18 @@ file_patterns = ["*.qml"] prompt = """{{ tojson("" + ctx.suffix + "
" + ctx.prefix + "") }}"""
 
 [body.options]
-temperature    = 0
-top_p          = 1
+temperature = 0
+top_p = 1
 repeat_penalty = 1.05
-num_predict    = 500
-stop           = ["", "
", "
", "
", "< EOT >", "\\end", "", "", "##"] +num_predict = 500 +stop = [ + "", + "
",
+  "
", + "
", + "< EOT >", + "\\end", + "", + "", + "##", +] diff --git a/sources/agents/ollama_compression.toml b/sources/agents/ollama_compression.toml new file mode 100644 index 0000000..be92648 --- /dev/null +++ b/sources/agents/ollama_compression.toml @@ -0,0 +1,17 @@ +schema_version = 1 + +extends = "Ollama Base Chat" +name = "Ollama Chat Compression" +description = "Local Ollama conversation summarization (qwen2.5-coder). Carries the summary system prompt; no tools." + +model = "qwen2.5-coder:7b" +enable_tools = false +tags = ["compression", "ollama", "local"] + +system_prompt = """{{ read_file(":/tasks/chat-compressor.md") }}""" + +[body.options] +num_predict = 2048 +temperature = 0.3 +num_ctx = 8192 +keep_alive = "5m" diff --git a/sources/agents/ollama_fim.toml b/sources/agents/ollama_fim.toml index 25ebd9e..5d4c979 100644 --- a/sources/agents/ollama_fim.toml +++ b/sources/agents/ollama_fim.toml @@ -8,6 +8,6 @@ model = "qwen2.5-coder:7b" tags = ["completion", "ollama", "local", "fim"] [body.options] -num_predict = 512 +num_predict = 256 temperature = 0.2 keep_alive = "5m" diff --git a/sources/agents/ollama_quick_refactor.toml b/sources/agents/ollama_quick_refactor.toml new file mode 100644 index 0000000..dc03b5a --- /dev/null +++ b/sources/agents/ollama_quick_refactor.toml @@ -0,0 +1,16 @@ +schema_version = 1 + +extends = "Ollama Base Chat" +name = "Ollama Quick Refactor" +description = "Local Ollama deterministic inline refactor (qwen2.5-coder). Static output rules from :/tasks/quick-refactor.md; QuickRefactorHandler injects the live editor context. No tools." + +model = "qwen2.5-coder:7b" +enable_tools = false +tags = ["refactor", "ollama", "local"] + +system_prompt = """{{ read_file(":/tasks/quick-refactor.md") }}""" + +[body.options] +num_predict = 2048 +temperature = 0.2 +keep_alive = "5m" diff --git a/sources/agents/tasks/quick-refactor.md b/sources/agents/tasks/quick-refactor.md new file mode 100644 index 0000000..5c15367 --- /dev/null +++ b/sources/agents/tasks/quick-refactor.md @@ -0,0 +1,19 @@ +# Output Requirements + +## Formatting Rules: +- Output ONLY the code itself, without ANY explanations or descriptions +- Do NOT include markdown code blocks (no ```, no language tags) +- Do NOT add comments explaining what you changed +- Do NOT repeat existing code, be precise with context +- Do NOT send in answer or and other tags +- The output must be ready to insert directly into the editor as-is + +## Indentation and Whitespace: +- Use the same indentation style (spaces or tabs) as the surrounding code +- Maintain consistent indentation for nested blocks +- Do NOT remove or reduce the base indentation level + +## Code Style: +- Match the coding style of the surrounding code (naming, spacing, braces, etc.) +- Preserve the original code structure when possible +- Only change what is necessary to fulfill the user's request