coder-agent 2.9.7 → 2.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.js +67 -0
- package/dist/memory.js +3 -3
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -83,6 +83,30 @@ function extractDiagnostics(text) {
|
|
|
83
83
|
}
|
|
84
84
|
return diagnostics;
|
|
85
85
|
}
|
|
86
|
+
function extractFilePaths(text) {
|
|
87
|
+
const pathRegex = /(?:\.\/|\.\.\\|[a-zA-Z]:\\)?(?:[a-zA-Z0-9_\-\.]+[\\\/])+[a-zA-Z0-9_\-\.]+\.[a-zA-Z0-9]+/g;
|
|
88
|
+
const fileRegex = /\b[a-zA-Z0-9_\-\.]+\.[a-zA-Z0-9]+\b/g;
|
|
89
|
+
const matches = new Set();
|
|
90
|
+
let match;
|
|
91
|
+
while ((match = pathRegex.exec(text)) !== null) {
|
|
92
|
+
matches.add(match[0]);
|
|
93
|
+
}
|
|
94
|
+
while ((match = fileRegex.exec(text)) !== null) {
|
|
95
|
+
matches.add(match[0]);
|
|
96
|
+
}
|
|
97
|
+
const paths = [];
|
|
98
|
+
for (const m of matches) {
|
|
99
|
+
const trimmed = m.trim();
|
|
100
|
+
if (!trimmed)
|
|
101
|
+
continue;
|
|
102
|
+
if (/^\d/.test(trimmed))
|
|
103
|
+
continue;
|
|
104
|
+
if (trimmed.includes("://") || trimmed.startsWith("http"))
|
|
105
|
+
continue;
|
|
106
|
+
paths.push(trimmed);
|
|
107
|
+
}
|
|
108
|
+
return paths;
|
|
109
|
+
}
|
|
86
110
|
function getToolBadge(name) {
|
|
87
111
|
const blue = chalk.hex('#0a84ff');
|
|
88
112
|
const amber = chalk.hex('#ff9f0a');
|
|
@@ -680,6 +704,49 @@ export class Agent {
|
|
|
680
704
|
}
|
|
681
705
|
enrichedPrompt += "\n\n=== Enriched Code Context (Auto-Parsed) ===\n" + contexts.join("\n\n") + "\n===========================================";
|
|
682
706
|
}
|
|
707
|
+
// Auto-resolve any file paths explicitly mentioned in the user message
|
|
708
|
+
try {
|
|
709
|
+
const potentialPaths = extractFilePaths(userMessage);
|
|
710
|
+
const autoResolvedContexts = [];
|
|
711
|
+
for (const rawPath of potentialPaths) {
|
|
712
|
+
// Skip if already in diagnostics to avoid duplication
|
|
713
|
+
if (diagnostics.some(d => d.resource.toLowerCase().includes(rawPath.toLowerCase()))) {
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
const filePath = normalizeFilePath(rawPath);
|
|
717
|
+
try {
|
|
718
|
+
const stats = await fs.stat(filePath);
|
|
719
|
+
if (stats.isFile()) {
|
|
720
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
721
|
+
const lines = content.split(/\r?\n/);
|
|
722
|
+
const fileContentText = lines.length > 800
|
|
723
|
+
? lines.slice(0, 800).join("\n") + "\n... [Content truncated: first 800 lines shown] ..."
|
|
724
|
+
: content;
|
|
725
|
+
autoResolvedContexts.push(`File: ${rawPath}\n\`\`\`\n${fileContentText}\n\`\`\``);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
catch {
|
|
729
|
+
try {
|
|
730
|
+
// Try resolving relative path if absolute resolution failed
|
|
731
|
+
const relativePath = path.relative("/", filePath).replace(/^[a-zA-Z]:/, "").replace(/^\\+|^[//]+/, "");
|
|
732
|
+
const stats = await fs.stat(relativePath);
|
|
733
|
+
if (stats.isFile()) {
|
|
734
|
+
const content = await fs.readFile(relativePath, "utf-8");
|
|
735
|
+
const lines = content.split(/\r?\n/);
|
|
736
|
+
const fileContentText = lines.length > 800
|
|
737
|
+
? lines.slice(0, 800).join("\n") + "\n... [Content truncated: first 800 lines shown] ..."
|
|
738
|
+
: content;
|
|
739
|
+
autoResolvedContexts.push(`File: ${rawPath}\n\`\`\`\n${fileContentText}\n\`\`\``);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
catch { }
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
if (autoResolvedContexts.length > 0) {
|
|
746
|
+
enrichedPrompt += "\n\n=== Auto-Resolved File Context ===\n" + autoResolvedContexts.join("\n\n") + "\n===================================";
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
catch { }
|
|
683
750
|
this.memory.add({ role: "user", content: enrichedPrompt });
|
|
684
751
|
let iterations = 0;
|
|
685
752
|
const MAX_ITERATIONS = 12;
|
package/dist/memory.js
CHANGED
|
@@ -15,7 +15,7 @@ CORE OPERATING PRINCIPLES
|
|
|
15
15
|
- What is the correct file/folder structure?
|
|
16
16
|
- What dependencies are required and at what versions?
|
|
17
17
|
- What edge cases exist in this domain?
|
|
18
|
-
If the target file
|
|
18
|
+
If the target file is clear, or if its contents are already provided in the prompt context (e.g. under "Auto-Resolved File Context"), skip writing a plan, reasoning preamble, or explanation. Proceed directly to executing the edit tools (like patch_file or write_file) in the very first turn to achieve the goal as fast as possible. Minimize conversational turns and thinking overhead.
|
|
19
19
|
|
|
20
20
|
2. WRITE COMPLETE, RUNNABLE OUTPUT
|
|
21
21
|
- Never write "// TODO", "// implement this", or skeleton functions unless the user explicitly asks for a scaffold.
|
|
@@ -239,12 +239,12 @@ When writing code in your response, always use this block format:
|
|
|
239
239
|
|
|
240
240
|
Guidelines & Controls:
|
|
241
241
|
- Be extremely concise in your explanations; let code and command output speak for itself.
|
|
242
|
-
-
|
|
242
|
+
- Be decisive and clear at the end of the task. If you have successfully achieved the goal or completed the user's request, state clearly and confidently that the goal has been achieved (e.g., "I have successfully achieved the goal of..."). Do not sound tentative, confused, or ask vague follow-up questions. If you genuinely need input, feedback, or clarification from the user to proceed, ask for it directly. Keep final responses minimal and brief.
|
|
243
243
|
- When writing or modifying code, always use the write_file or patch_file tools to apply the changes directly to the codebase. NEVER output raw code blocks or snippets in your chat response when they can be applied using tools. Chat responses should contain only brief status confirmations or final explanations. Always run a verify script/compile tool (like run_shell) after editing to verify the code works.
|
|
244
244
|
- Prefer using search_grep to locate code, read_file_lines to read relevant parts, and patch_file to make targeted edits, especially in large codebases. This prevents token/context overflow.
|
|
245
245
|
- Before answering questions or checking for errors in the codebase, always inspect the workspace to identify the files and languages present. Do not guess.
|
|
246
246
|
- Focus on the actual files and programming language of the codebase you are currently running in.
|
|
247
|
-
- If a task is ambiguous or you cannot find the code the user is referring to, ask
|
|
247
|
+
- If a task is ambiguous or you cannot find the code the user is referring to, ask the user a specific clarifying question directly.
|
|
248
248
|
- CRITICAL (Tool Calling): Use the native API tool calling mechanism to execute tools. Never output raw XML tags, HTML tags, or mock function call strings (like '<function=...>') in your conversational chat response.
|
|
249
249
|
- CRITICAL (Response Limitation): When calling a tool, do not output any conversational explanations, thoughts, or markdown before or after the tool call in the same response. Only output conversational text when you are providing the final answer.
|
|
250
250
|
- CRITICAL SECURITY GUARDRAILS:
|