mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-07-03 11:39:13 -04:00
fix: Move Quick Refactor agent to toml file
This commit is contained in:
@@ -185,7 +185,7 @@ void QuickRefactorHandler::prepareAndSendRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
session->systemPrompt()->setLayer(
|
session->systemPrompt()->setLayer(
|
||||||
QStringLiteral("refactor"), buildSystemPrompt(editor, range));
|
QStringLiteral("refactor"), buildContextLayer(editor, range));
|
||||||
|
|
||||||
client->setTransferTimeout(
|
client->setTransferTimeout(
|
||||||
static_cast<int>(Settings::generalSettings().requestTimeout() * 1000));
|
static_cast<int>(Settings::generalSettings().requestTimeout() * 1000));
|
||||||
@@ -221,7 +221,7 @@ void QuickRefactorHandler::prepareAndSendRequest(
|
|||||||
m_activeRequests[requestId] = {QJsonObject{{"id", requestId}}, session};
|
m_activeRequests[requestId] = {QJsonObject{{"id", requestId}}, session};
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QuickRefactorHandler::buildSystemPrompt(
|
QString QuickRefactorHandler::buildContextLayer(
|
||||||
TextEditor::TextEditorWidget *editor, const Utils::Text::Range &range)
|
TextEditor::TextEditorWidget *editor, const Utils::Text::Range &range)
|
||||||
{
|
{
|
||||||
Q_UNUSED(range)
|
Q_UNUSED(range)
|
||||||
@@ -306,29 +306,20 @@ QString QuickRefactorHandler::buildSystemPrompt(
|
|||||||
taggedContent = contextBefore + "<cursor>" + contextAfter;
|
taggedContent = contextBefore + "<cursor>" + contextAfter;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString systemPrompt = Context::EnvBlockFormatter::formatFile(
|
QString contextLayer = Context::EnvBlockFormatter::formatFile(
|
||||||
{documentInfo.filePath, documentInfo.mimeType});
|
{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:";
|
contextLayer += "\n\n# What to Generate:";
|
||||||
systemPrompt += cursor.hasSelection()
|
contextLayer += cursor.hasSelection()
|
||||||
? "\n- Generate ONLY the code that should REPLACE the selected text between "
|
? "\n- Generate ONLY the code that should REPLACE the selected text between "
|
||||||
"<selection_start> and <selection_end> markers"
|
"<selection_start> and <selection_end> markers"
|
||||||
"\n- Your output will completely replace the selected code"
|
"\n- Your output will completely replace the selected code"
|
||||||
: "\n- Generate ONLY the code that should be INSERTED at the <cursor> position"
|
: "\n- Generate ONLY the code that should be INSERTED at the <cursor> position"
|
||||||
"\n- Your output will be inserted at the cursor location";
|
"\n- Your output will be inserted at the cursor location";
|
||||||
|
|
||||||
systemPrompt += "\n\n## Formatting Rules:"
|
QString indentNote;
|
||||||
"\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 <cursor> or </cursor> and other tags"
|
|
||||||
"\n- The output must be ready to insert directly into the editor as-is";
|
|
||||||
|
|
||||||
systemPrompt += "\n\n## Indentation and Whitespace:";
|
|
||||||
|
|
||||||
if (cursor.hasSelection()) {
|
if (cursor.hasSelection()) {
|
||||||
QTextBlock startBlock = documentInfo.document->findBlock(cursor.selectionStart());
|
QTextBlock startBlock = documentInfo.document->findBlock(cursor.selectionStart());
|
||||||
int leadingSpaces = 0;
|
int leadingSpaces = 0;
|
||||||
@@ -338,12 +329,12 @@ QString QuickRefactorHandler::buildSystemPrompt(
|
|||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
if (leadingSpaces > 0) {
|
if (leadingSpaces > 0) {
|
||||||
systemPrompt += QString("\n- CRITICAL: The code to replace starts with %1 spaces of indentation"
|
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- Your output MUST start with exactly %1 spaces (or equivalent tabs)"
|
||||||
"\n- Each line in your output must maintain this base indentation")
|
"\n- Each line in your output must maintain this base indentation")
|
||||||
.arg(leadingSpaces);
|
.arg(leadingSpaces);
|
||||||
}
|
}
|
||||||
systemPrompt += "\n- PRESERVE all indentation from the original code";
|
indentNote += "\n- PRESERVE all indentation from the original code";
|
||||||
} else {
|
} else {
|
||||||
QTextBlock block = documentInfo.document->findBlock(cursorPos);
|
QTextBlock block = documentInfo.document->findBlock(cursorPos);
|
||||||
QString lineText = block.text();
|
QString lineText = block.text();
|
||||||
@@ -354,26 +345,20 @@ QString QuickRefactorHandler::buildSystemPrompt(
|
|||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
if (leadingSpaces > 0) {
|
if (leadingSpaces > 0) {
|
||||||
systemPrompt += QString("\n- CRITICAL: Current line has %1 spaces of indentation"
|
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 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)")
|
"\n- If generating single-line code, it will be inserted inline (no indentation needed)")
|
||||||
.arg(leadingSpaces);
|
.arg(leadingSpaces);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!indentNote.isEmpty())
|
||||||
systemPrompt += "\n- Use the same indentation style (spaces or tabs) as the surrounding code"
|
contextLayer += "\n\n## Indentation:" + indentNote;
|
||||||
"\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 (Settings::quickRefactorSettings().useOpenFilesInQuickRefactor()) {
|
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()
|
void QuickRefactorHandler::cancelRequest()
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ private:
|
|||||||
|
|
||||||
void onRefactorFinished(const QString &requestId);
|
void onRefactorFinished(const QString &requestId);
|
||||||
void onRefactorFailed(const QString &requestId, const QodeAssist::ErrorInfo &error);
|
void onRefactorFailed(const QString &requestId, const QodeAssist::ErrorInfo &error);
|
||||||
QString buildSystemPrompt(
|
QString buildContextLayer(
|
||||||
TextEditor::TextEditorWidget *editor, const Utils::Text::Range &range);
|
TextEditor::TextEditorWidget *editor, const Utils::Text::Range &range);
|
||||||
QString pickRefactorAgent() const;
|
QString pickRefactorAgent() const;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<file>claude_completion.toml</file>
|
<file>claude_completion.toml</file>
|
||||||
<file>claude_compression.toml</file>
|
<file>claude_compression.toml</file>
|
||||||
<file>claude_quick_refactor.toml</file>
|
<file>claude_quick_refactor.toml</file>
|
||||||
|
<file>claude_quick_refactor_fast.toml</file>
|
||||||
<file>openai_base_chat.toml</file>
|
<file>openai_base_chat.toml</file>
|
||||||
<file>openai_chat_completions.toml</file>
|
<file>openai_chat_completions.toml</file>
|
||||||
<file>openai_responses_base.toml</file>
|
<file>openai_responses_base.toml</file>
|
||||||
@@ -19,6 +20,8 @@
|
|||||||
<file>ollama_base_fim.toml</file>
|
<file>ollama_base_fim.toml</file>
|
||||||
<file>ollama_fim.toml</file>
|
<file>ollama_fim.toml</file>
|
||||||
<file>ollama_codellama_qml_fim.toml</file>
|
<file>ollama_codellama_qml_fim.toml</file>
|
||||||
|
<file>ollama_quick_refactor.toml</file>
|
||||||
|
<file>ollama_compression.toml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/roles">
|
<qresource prefix="/roles">
|
||||||
<file alias="qt-cpp-developer.md">roles/qt-cpp-developer.md</file>
|
<file alias="qt-cpp-developer.md">roles/qt-cpp-developer.md</file>
|
||||||
@@ -29,5 +32,6 @@
|
|||||||
<qresource prefix="/tasks">
|
<qresource prefix="/tasks">
|
||||||
<file alias="chat-compressor.md">tasks/chat-compressor.md</file>
|
<file alias="chat-compressor.md">tasks/chat-compressor.md</file>
|
||||||
<file alias="code-completion.md">tasks/code-completion.md</file>
|
<file alias="code-completion.md">tasks/code-completion.md</file>
|
||||||
|
<file alias="quick-refactor.md">tasks/quick-refactor.md</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@@ -2,12 +2,17 @@ schema_version = 1
|
|||||||
|
|
||||||
extends = "Claude Base Chat"
|
extends = "Claude Base Chat"
|
||||||
name = "Claude Quick Refactor"
|
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"
|
model = "claude-sonnet-4-6"
|
||||||
enable_tools = false
|
enable_tools = true
|
||||||
tags = ["refactor", "claude", "cloud"]
|
enable_thinking = true
|
||||||
|
tags = ["refactor", "claude", "cloud"]
|
||||||
|
|
||||||
|
system_prompt = """{{ read_file(":/tasks/quick-refactor.md") }}"""
|
||||||
|
|
||||||
[body]
|
[body]
|
||||||
max_tokens = 16000
|
max_tokens = 16000
|
||||||
temperature = 0.2
|
temperature = 1
|
||||||
|
thinking = { type = "adaptive", display = "summarized" }
|
||||||
|
output_config = { effort = "high" }
|
||||||
|
|||||||
16
sources/agents/claude_quick_refactor_fast.toml
Normal file
16
sources/agents/claude_quick_refactor_fast.toml
Normal file
@@ -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
|
||||||
@@ -28,4 +28,4 @@ messages = """
|
|||||||
num_predict = 512
|
num_predict = 512
|
||||||
temperature = 0.2
|
temperature = 0.2
|
||||||
keep_alive = "5m"
|
keep_alive = "5m"
|
||||||
stop = ["</code_context>"]
|
stop = ["</code_context>"]
|
||||||
|
|||||||
@@ -16,8 +16,18 @@ file_patterns = ["*.qml"]
|
|||||||
prompt = """{{ tojson("<SUF>" + ctx.suffix + "<PRE>" + ctx.prefix + "<MID>") }}"""
|
prompt = """{{ tojson("<SUF>" + ctx.suffix + "<PRE>" + ctx.prefix + "<MID>") }}"""
|
||||||
|
|
||||||
[body.options]
|
[body.options]
|
||||||
temperature = 0
|
temperature = 0
|
||||||
top_p = 1
|
top_p = 1
|
||||||
repeat_penalty = 1.05
|
repeat_penalty = 1.05
|
||||||
num_predict = 500
|
num_predict = 500
|
||||||
stop = ["<SUF>", "<PRE>", "</PRE>", "</SUF>", "< EOT >", "\\end", "<MID>", "</MID>", "##"]
|
stop = [
|
||||||
|
"<SUF>",
|
||||||
|
"<PRE>",
|
||||||
|
"</PRE>",
|
||||||
|
"</SUF>",
|
||||||
|
"< EOT >",
|
||||||
|
"\\end",
|
||||||
|
"<MID>",
|
||||||
|
"</MID>",
|
||||||
|
"##",
|
||||||
|
]
|
||||||
|
|||||||
17
sources/agents/ollama_compression.toml
Normal file
17
sources/agents/ollama_compression.toml
Normal file
@@ -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"
|
||||||
@@ -8,6 +8,6 @@ model = "qwen2.5-coder:7b"
|
|||||||
tags = ["completion", "ollama", "local", "fim"]
|
tags = ["completion", "ollama", "local", "fim"]
|
||||||
|
|
||||||
[body.options]
|
[body.options]
|
||||||
num_predict = 512
|
num_predict = 256
|
||||||
temperature = 0.2
|
temperature = 0.2
|
||||||
keep_alive = "5m"
|
keep_alive = "5m"
|
||||||
|
|||||||
16
sources/agents/ollama_quick_refactor.toml
Normal file
16
sources/agents/ollama_quick_refactor.toml
Normal file
@@ -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"
|
||||||
19
sources/agents/tasks/quick-refactor.md
Normal file
19
sources/agents/tasks/quick-refactor.md
Normal file
@@ -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 <cursor> or </cursor> 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
|
||||||
Reference in New Issue
Block a user