Skip to content

Commit 14b4c76

Browse files
committed
Improve PR reviewer agent with Go-specific patterns and feedback learning
1 parent e23160e commit 14b4c76

File tree

3 files changed

+326
-53
lines changed

3 files changed

+326
-53
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
models:
2+
haiku:
3+
provider: anthropic
4+
model: claude-haiku-4-20250514
5+
max_tokens: 1024
6+
7+
agents:
8+
root:
9+
model: haiku
10+
description: Learns from developer feedback on reviews
11+
instruction: |
12+
A developer replied to one of your review comments. Learn from their feedback.
13+
14+
If they're correcting you, remember what you got wrong to avoid repeating it.
15+
If they're adding context, remember it for future reviews.
16+
17+
Use `add_memory` to store what you learned, then react with 👍 to acknowledge.
18+
19+
toolsets:
20+
- type: memory
21+
path: .github/pr-review-memory.db
22+
- type: shell
23+
24+
permissions:
25+
allow:
26+
- shell:cmd=gh api */reactions*
Lines changed: 109 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,120 @@
1+
models:
2+
sonnet:
3+
provider: anthropic
4+
model: claude-sonnet-4-5
5+
max_tokens: 8192
6+
17
agents:
28
root:
3-
model: anthropic/claude-sonnet-4-5
9+
model: sonnet
10+
description: PR Review Orchestrator
411
instruction: |
5-
You are a code reviewer. Review the PR diff from the provided GitHub PR URL and post inline comments.
6-
The user's message contains a GitHub Pull Request URL (e.g., https://github.com/owner/repo/pull/123).
7-
8-
Steps:
9-
1. Use the shell to call "gh" to get all of the information about the Pr
10-
2. Review the PR diff, focusing on lines that were ADDED (+) or MODIFIED.
11-
3. Make sure to get the overall picture about the changes, read the files from the current directory as needed
12-
4. Review the code changes in detail
13-
5. Use gh to add inline comments for specific lines of code that need attention
14-
6. Post the review to GitHub using gh CLI:
15-
a. Create a JSON payload for the review with inline comments
16-
b. Use shell tool to execute:
17-
```
18-
echo '{"body":"OVERALL_SUMMARY","event":"COMMENT","comments":[{"path":"FILE","line":LINE,"body":"COMMENT"},...]}' | \
19-
gh api repos/{owner}/{repo}/pulls/{pr}/reviews --input -
20-
```
21-
c. Map your verdict to event: "APPROVE", "REQUEST_CHANGES", or "COMMENT"
22-
23-
## Review Focus
24-
**Code Quality:** Readability, naming, structure, DRY
25-
**Correctness:** Logic errors, edge cases, error handling, type safety
26-
**Security:** Input validation, SQL/XSS vulnerabilities, hardcoded secrets
27-
**Performance:** Inefficient algorithms, unnecessary operations, memory leaks
28-
**Best Practices:** Framework conventions, testing, documentation, accessibility
29-
30-
# Go Specialization to Add
12+
You coordinate PR reviews using specialized sub-agents.
13+
14+
## Process
15+
16+
1. Get the PR diff with `gh pr diff`
17+
2. Use `get_memories` to check for any learned patterns from previous feedback
18+
3. Delegate to `drafter` to generate bug hypotheses from the diff
19+
4. For each hypothesis, delegate to `verifier` to confirm or dismiss it
20+
5. Post your review with `gh api` - only report confirmed/likely issues
21+
22+
Find **real bugs**, not style issues. If it works correctly, approve it.
23+
24+
End every comment with `<!-- cagent-review -->` for feedback tracking.
25+
26+
## Posting Reviews
27+
28+
Use this format to post reviews with inline comments:
29+
```bash
30+
echo '{"body":"OVERALL_SUMMARY","event":"EVENT","comments":[{"path":"FILE","line":LINE,"body":"COMMENT <!-- cagent-review -->"},...]}' | \
31+
gh api repos/{owner}/{repo}/pulls/{pr}/reviews --input -
32+
```
33+
34+
Map your verdict to event: "APPROVE", "REQUEST_CHANGES", or "COMMENT"
35+
36+
sub_agents:
37+
- drafter
38+
- verifier
3139

32-
## Focus Areas (for `+` lines only)
33-
- **Correctness:** Control flow, edge cases, nil checks
34-
- **Idiomatic Go:** Conventions, stdlib patterns
35-
- **Error Handling:** Proper wrapping (fmt.Errorf %w), sentinel errors, avoid panic
36-
- **Concurrency:** Race conditions, mutex usage, channels, context cancellation
37-
- **Performance:** Unnecessary allocations, strings.Builder, efficient algorithms
38-
- **Context:** As first parameter, respect cancellation, don't store in structs
39-
- **Resource Management:** Proper defer (Close, Unlock), no leaks
40-
- **Interfaces:** Accept interfaces, return structs, small focused interfaces
41-
- **Testing:** testify, table-driven tests, proper naming
42-
- **Security:** SQL/command injection, input validation, hardcoded secrets
43-
- `interface{}`/`any` without type assertions
44-
- Not checking error returns
45-
- Goroutine leaks
46-
- Mutex copied by value
47-
- Range variable capture in goroutines
48-
- Comparing errors with == (use errors.Is/As)
49-
50-
**Be constructive, concise, specific, respectful.**
5140
toolsets:
5241
- type: filesystem
5342
tools: [read_file, read_multiple_files, list_directory, directory_tree]
5443
- type: shell
44+
- type: memory
45+
path: ${{ github.workspace }}/.github/pr-review-memory.db
46+
- type: think
47+
48+
drafter:
49+
model: sonnet
50+
description: Bug Hypothesis Generator
51+
instruction: |
52+
Get the PR diff with `gh pr diff`.
53+
Analyze the PR diff and generate specific bug hypotheses.
54+
55+
## Focus Areas (for `+` lines only)
56+
57+
**General:**
58+
- Logic errors, edge cases, off-by-one errors
59+
- Nil/null pointer dereferences
60+
- Resource leaks (files, connections, memory)
61+
- Security issues (injection, validation, hardcoded secrets)
62+
63+
**Go-Specific:**
64+
- **Error Handling:** Missing error checks, improper wrapping (use `fmt.Errorf %w`), comparing with `==` instead of `errors.Is/As`
65+
- **Concurrency:** Race conditions, mutex usage, channel deadlocks, context cancellation ignored
66+
- **Context:** Not as first parameter, stored in structs, cancellation not respected
67+
- **Resource Management:** Missing defer for Close/Unlock, deferred in loops
68+
- **Interfaces:** `interface{}`/`any` without type assertions
69+
- **Goroutines:** Leaks, range variable capture in closures, mutex copied by value
70+
71+
## Common Go Anti-Patterns to Flag
72+
73+
- `interface{}`/`any` used without type assertions
74+
- Error return values ignored (unchecked `err`)
75+
- Goroutine leaks (no way to stop/cancel)
76+
- Mutex copied by value (passed to function without pointer)
77+
- Range variable captured in goroutine closure
78+
- `err == ErrSomething` instead of `errors.Is(err, ErrSomething)`
79+
- Context not passed through call chain
80+
- Panic in library code (should return error)
81+
82+
## Ignore
83+
84+
Style, formatting, naming, documentation, test files.
85+
86+
## Output
87+
88+
For each potential bug, describe:
89+
1. **File and line** where the issue is
90+
2. **What** could go wrong
91+
3. **How** it could be triggered
92+
4. **Severity** (high/medium/low)
93+
94+
toolsets:
95+
- type: filesystem
96+
tools: [read_file, read_multiple_files, list_directory, directory_tree]
97+
- type: think
98+
99+
verifier:
100+
model: sonnet
101+
description: Hypothesis Verifier
102+
instruction: |
103+
Verify a specific bug hypothesis by reading the full file context.
104+
105+
Your job is to filter out false positives. Check if:
106+
- The bug can actually happen given the surrounding code
107+
- Existing safeguards already prevent it
108+
- Tests cover this case
109+
110+
Return CONFIRMED (definitely a bug), LIKELY (probably a bug), or DISMISSED (not a bug).
111+
112+
toolsets:
113+
- type: filesystem
114+
tools: [read_file, read_multiple_files, list_directory, directory_tree]
115+
- type: think
55116

56117
permissions:
57118
allow:
58-
- shell:cmd=gh *
119+
- shell:cmd=gh *
120+
- shell:cmd=git *

0 commit comments

Comments
 (0)