You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: agent.go
+59-8Lines changed: 59 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,9 @@ import (
5
5
"encoding/json"
6
6
"fmt"
7
7
"os"
8
+
"os/exec"
8
9
"path/filepath"
10
+
"runtime"
9
11
"strings"
10
12
"sync"
11
13
"time"
@@ -61,13 +63,13 @@ debug, and modify software projects.
61
63
Available tools:
62
64
- read_file: Read file contents with line numbers. Use offset/limit for large files.
63
65
- write_file: Create or overwrite a file. Parent directories are created automatically.
64
-
- edit_file: Surgical find-and-replace in a file. old_text must match exactly and be unique.
66
+
- edit_file: Surgical find-and-replace in a file. old_text must match exactly and be unique. If old_text is not found, re-read the file and check for exact whitespace and line endings.
65
67
- multi_edit: Batch multiple edits across files. Per-file atomicity with rollback.
66
68
- list_files: List directory contents or glob for files (e.g. "**/*.go").
67
69
- search_files: Regex search across files (powered by ripgrep). Find definitions, usages, etc.
68
70
- web_search: Search the web. Use for current info, docs, versions, error solutions, or anything not in local files.
69
71
- dispatch_agent: Spawn a read-only research subagent to investigate questions in isolated context.
70
-
- shell: Run any shell command. Use for builds, tests, package management.
72
+
- shell: Run a shell command. Use for builds, tests, package management, and any terminal task.
71
73
- git_status: Show working tree status (staged, unstaged, untracked files).
72
74
- git_diff: Show file diffs (staged, unstaged, or between refs).
73
75
- git_log: Show recent commit history.
@@ -79,16 +81,21 @@ Available tools:
79
81
- get_task: Get full details of a specific task.
80
82
81
83
Guidelines:
84
+
- ALWAYS read a file before editing it — never guess at file contents
85
+
- ALWAYS use search_files or list_files to explore before assuming project structure
82
86
- You can call multiple tools in parallel — read_file, list_files, search_files, web_search, dispatch_agent, list_tasks, and get_task all run concurrently
83
-
- Use list_files and search_files to explore the project before making changes
84
-
- Read files before editing them — understand existing code first
- For multiple related edits, prefer multi_edit over separate edit_file calls
87
89
- Use git tools instead of shell for git operations — they provide structured output
88
-
- After you edit files, the system may report diagnostics (errors, warnings) from language tools. If diagnostics appear, fix the issues before moving on.
89
-
- If a tool fails, read the error and try a different approach
90
+
- After you edit files, the system may report diagnostics (errors, warnings) from language tools. If diagnostics appear, fix the issues before moving on
90
91
- When finished, briefly summarize what you changed and why
91
92
93
+
Error recovery:
94
+
- If edit_file fails with "old_text not found", re-read the file to see the actual content, then retry with corrected text
95
+
- If edit_file fails with "found N times", add more surrounding context lines to old_text to make it unique
96
+
- If a shell command fails, read the error output carefully and try a different approach
97
+
- Never repeat a failed tool call with identical arguments
98
+
92
99
Task management:
93
100
- For multi-step work (3+ steps), create tasks upfront so the user can track progress
94
101
- Set status to "in_progress" BEFORE starting work on a task
sb.WriteString("\nShell commands run in PowerShell. Use PowerShell syntax (e.g. `Get-ChildItem` not `ls`, `Remove-Item` not `rm`, `;` or `&&` to chain commands).\n")
Copy file name to clipboardExpand all lines: subagent.go
+15-4Lines changed: 15 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ import (
4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
+
"runtime"
7
8
"strings"
8
9
)
9
10
@@ -18,7 +19,7 @@ import (
18
19
19
20
constsubagentMaxTurns=25
20
21
21
-
constsubagentSystemPrompt=`You are a focused research assistant. You help gather information by reading files, searching code, and listing directories.
22
+
constsubagentSystemPromptBase=`You are a focused research assistant. You help gather information by reading files, searching code, and listing directories.
22
23
23
24
You have read-only access to the project. You CANNOT modify any files.
24
25
@@ -29,7 +30,7 @@ Guidelines:
29
30
- Use search_files to find relevant code quickly
30
31
- Use list_files to explore project structure
31
32
- Use web_search when you need external documentation, API references, or current information
32
-
- Use shell for read-only commands only (ls, cat, grep, git log, etc.)
33
+
- Use shell for read-only commands only (e.g. git log, git status, directory listings)
33
34
- When done, provide a clear, concise summary of your findings`
34
35
35
36
// subagentToolDefs contains only read-only tools.
@@ -47,7 +48,7 @@ func init() {
47
48
48
49
// RunSubagent executes a read-only research subagent and returns its final text.
0 commit comments