Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit 156aff5

Browse files
committed
feat: Allow verification agent to fix
1 parent e4560b0 commit 156aff5

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

internal/orchestrator/verification_agent.go

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Respond with ONLY one word: "QUESTION" or "IMPLEMENTATION"`
9898
return true, "Classified as an implementation request", nil
9999
}
100100

101-
// buildToolRegistry creates a tool registry with read tools and go_sandbox access.
101+
// buildToolRegistry creates a tool registry with read tools, edit tools, and go_sandbox access.
102102
func (a *VerificationAgent) buildToolRegistry(verificationSession *session.Session) *tools.Registry {
103103
// Use the orchestrator's authorizer (which respects session-level authorizations)
104104
registry := tools.NewRegistryWithSecrets(a.orch.authorizer, secretdetect.NewDetector())
@@ -109,6 +109,41 @@ func (a *VerificationAgent) buildToolRegistry(verificationSession *session.Sessi
109109
// Read File - essential for checking modified files
110110
registry.Register(a.orch.getReadFileTool(modelFamily, verificationSession))
111111

112+
// Edit file tools - allow verification agent to fix issues it finds
113+
if a.orch.shouldUseReplaceFileTool(modelFamily) {
114+
registry.RegisterSpec(
115+
&tools.ReplaceFileToolSpec{},
116+
tools.NewReplaceFileToolFactory(a.orch.fs, verificationSession),
117+
)
118+
}
119+
if a.orch.shouldUseNonDiffUpdateTool(modelFamily) {
120+
registry.RegisterSpec(
121+
&tools.WriteFileJSONToolSpec{},
122+
tools.NewWriteFileJSONToolFactory(a.orch.fs, verificationSession),
123+
)
124+
} else if a.orch.shouldUseSimpleSingleDiffTool(modelFamily) {
125+
registry.RegisterSpec(
126+
&tools.WriteFileReplaceSingleToolSpec{},
127+
tools.NewWriteFileReplaceSingleToolFactory(a.orch.fs, verificationSession),
128+
)
129+
} else if a.orch.shouldUseSimpleDiffTool(modelFamily) {
130+
registry.RegisterSpec(
131+
&tools.WriteFileReplaceToolSpec{},
132+
tools.NewWriteFileReplaceToolFactory(a.orch.fs, verificationSession),
133+
)
134+
} else {
135+
registry.RegisterSpec(
136+
&tools.WriteFileDiffToolSpec{},
137+
tools.NewWriteFileDiffToolFactory(a.orch.fs, verificationSession),
138+
)
139+
}
140+
141+
// Create file tool - for creating new files if needed
142+
registry.RegisterSpec(
143+
&tools.CreateFileToolSpec{},
144+
tools.NewCreateFileToolFactory(a.orch.fs, verificationSession),
145+
)
146+
112147
// Search tools - for finding related files
113148
registry.Register(tools.NewSearchFilesTool(a.orch.fs))
114149
registry.Register(tools.NewSearchFileContentTool(a.orch.fs))
@@ -164,6 +199,7 @@ Verify that the code changes are correct by:
164199
2. Running the project build command to ensure it compiles
165200
3. Running the linter (if available) to catch style/quality issues
166201
4. Running relevant tests to ensure functionality works
202+
5. Fixing simple issues automatically when possible (typos, formatting, minor errors)
167203
168204
## Modified Files
169205
%s
@@ -175,6 +211,9 @@ Verify that the code changes are correct by:
175211
%s
176212
177213
## Available Tools
214+
- **edit_file**: Update existing files using diff or text replacement
215+
- **create_file**: Create new files if needed
216+
- **replace_file**: Replace entire file content (use with caution)
178217
- **go_sandbox**: Execute Go code in a sandboxed environment and run shell commands
179218
- **read_file**: Read files to check modifications
180219
- **search_files/search_file_content**: Find relevant files
@@ -193,7 +232,12 @@ Note: Commands will go through normal authorization checks. The system will dete
193232
3. Run code formatting to ensure code follows project style conventions
194233
4. Run linting if a linter is configured
195234
5. Run tests - if tests exist in the project, they MUST be run.
196-
6. Report any failures with clear error messages
235+
6. **IF YOU CAN AUTOMATICALLY FIX SIMPLE ISSUES**, do so and re-run verification:
236+
- Minor formatting errors detected by linters
237+
- Missing imports
238+
- Typos or syntax errors
239+
- Simple logic mistakes
240+
7. Report any failures with clear error messages
197241
198242
## Important Notes
199243
- Be efficient: don't read files that weren't modified
@@ -202,6 +246,9 @@ Note: Commands will go through normal authorization checks. The system will dete
202246
- If a command fails, report the error but continue with other checks
203247
- Keep command output concise (avoid verbose flags unless debugging)
204248
- Use go_sandbox for all command execution (build, lint, test)
249+
- **Only make automatic fixes for simple, obvious issues** - leave complex bugs for the user
250+
- Always re-run verification after making fixes
251+
- Read files before editing them (read-before-write rule)
205252
206253
When complete, provide a summary wrapped in <verification_result> tags:
207254
<verification_result>

internal/orchestrator/verification_agent_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ func TestBuildToolRegistry(t *testing.T) {
253253
// Verify that the registry is created successfully
254254
assert.NotNil(t, registry)
255255

256+
// Verify that edit file tools are registered
257+
toolsJSON := registry.ToJSONSchema()
258+
assert.Contains(t, toolsJSON, "edit_file", "edit_file tool should be registered")
259+
assert.Contains(t, toolsJSON, "create_file", "create_file tool should be registered")
260+
assert.Contains(t, toolsJSON, "replace_file", "replace_file tool should be registered")
261+
assert.Contains(t, toolsJSON, "go_sandbox", "go_sandbox tool should be registered")
262+
assert.Contains(t, toolsJSON, "read_file", "read_file tool should be registered")
263+
256264
// The registry should use normal authorization flow (no pre-authorized commands)
257265
// Commands will be checked by the authorization actor at runtime
258266
}
@@ -288,6 +296,10 @@ func TestBuildSystemPrompt(t *testing.T) {
288296
assert.Contains(t, prompt, "Language/Framework: Go")
289297
assert.Contains(t, prompt, "go build")
290298
assert.Contains(t, prompt, "verification_result")
299+
// Verify edit file tools are included in the prompt
300+
assert.Contains(t, prompt, "edit_file")
301+
assert.Contains(t, prompt, "create_file")
302+
assert.Contains(t, prompt, "Fixing simple issues automatically")
291303
}
292304

293305
// Test buildSystemPrompt with unknown project type

0 commit comments

Comments
 (0)