Skip to content

Commit 0b730a9

Browse files
authored
Add code review example using simple tools specification (#84)
This document demonstrates how to build a complete code review system using the simple tools specification and markdown-based agents. Includes: - Basic Git tools (changed-files, file-diff, all-diffs) - Analysis tools (analyze-file, analyze-diff) - Review coordination agents - Complete workflow examples Shows the composability and power of the simple tools approach for building sophisticated AI-assisted development workflows.
1 parent b59a467 commit 0b730a9

File tree

1 file changed

+363
-0
lines changed

1 file changed

+363
-0
lines changed
Lines changed: 363 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,363 @@
1+
# Code Review Example: Simple Tools and Agents
2+
3+
This document shows how to build up a complete code review system using the simple tools specification and markdown-based agents.
4+
5+
## Building Blocks: Basic Git Tools
6+
7+
### changed-files.yaml
8+
```yaml
9+
name: changed-files
10+
description: Get list of files changed since master
11+
12+
bash: git diff --name-only {BASE_BRANCH}..HEAD
13+
14+
parameters:
15+
BASE_BRANCH:
16+
type: string
17+
description: Branch to compare against
18+
default: "master"
19+
20+
tags: [git, read]
21+
platforms: [windows, linux, macos]
22+
```
23+
24+
### file-diff.yaml
25+
```yaml
26+
name: file-diff
27+
description: Show diff for a specific file since master
28+
29+
bash: git diff {BASE_BRANCH}..HEAD -- "{FILE}"
30+
31+
parameters:
32+
FILE:
33+
type: string
34+
description: Path to the file to show diff for
35+
required: true
36+
BASE_BRANCH:
37+
type: string
38+
description: Branch to compare against
39+
default: "master"
40+
41+
tags: [git, read]
42+
platforms: [windows, linux, macos]
43+
```
44+
45+
### all-diffs.yaml
46+
```yaml
47+
name: all-diffs
48+
description: Show all diffs since master
49+
50+
bash: git diff {BASE_BRANCH}..HEAD
51+
52+
parameters:
53+
BASE_BRANCH:
54+
type: string
55+
description: Branch to compare against
56+
default: "master"
57+
58+
tags: [git, read]
59+
platforms: [windows, linux, macos]
60+
```
61+
62+
## Analysis Tools
63+
64+
### analyze-file.yaml
65+
```yaml
66+
name: analyze-file
67+
description: Analyze a single file for code quality issues
68+
69+
bash: |
70+
echo "=== File Analysis: {FILE} ==="
71+
echo "Lines of code:"
72+
wc -l "{FILE}"
73+
echo ""
74+
echo "File type:"
75+
file "{FILE}"
76+
echo ""
77+
echo "Recent changes:"
78+
git log --oneline -5 -- "{FILE}" || echo "No git history"
79+
80+
parameters:
81+
FILE:
82+
type: string
83+
description: Path to file to analyze
84+
required: true
85+
86+
tags: [analysis, read]
87+
platforms: [windows, linux, macos]
88+
```
89+
90+
### analyze-diff.yaml
91+
```yaml
92+
name: analyze-diff
93+
description: Analyze diff content for patterns and complexity
94+
95+
python: |
96+
import sys
97+
diff_content = """{DIFF_CONTENT}"""
98+
99+
lines = diff_content.split('\n')
100+
added_lines = [l for l in lines if l.startswith('+') and not l.startswith('+++')]
101+
removed_lines = [l for l in lines if l.startswith('-') and not l.startswith('---')]
102+
103+
print(f"Lines added: {len(added_lines)}")
104+
print(f"Lines removed: {len(removed_lines)}")
105+
print(f"Net change: {len(added_lines) - len(removed_lines)}")
106+
107+
# Look for potential issues
108+
issues = []
109+
for line in added_lines:
110+
if 'TODO' in line: issues.append(f"TODO found: {line.strip()}")
111+
if 'console.log' in line: issues.append(f"Debug code: {line.strip()}")
112+
if 'password' in line.lower(): issues.append(f"Password reference: {line.strip()}")
113+
114+
if issues:
115+
print("\nPotential issues:")
116+
for issue in issues: print(f" - {issue}")
117+
118+
parameters:
119+
DIFF_CONTENT:
120+
type: string
121+
description: The diff content to analyze
122+
required: true
123+
124+
tags: [analysis, read]
125+
platforms: [windows, linux, macos]
126+
```
127+
128+
## Composition Tools
129+
130+
### review-single-file.yaml
131+
```yaml
132+
name: review-single-file
133+
description: Complete review of one file - both current state and recent changes
134+
135+
steps:
136+
- name: get-file-diff
137+
tool: file-diff
138+
with:
139+
FILE: "{FILE}"
140+
BASE_BRANCH: "{BASE_BRANCH}"
141+
142+
- name: analyze-current-file
143+
tool: analyze-file
144+
with:
145+
FILE: "{FILE}"
146+
147+
- name: analyze-the-diff
148+
tool: analyze-diff
149+
with:
150+
DIFF_CONTENT: "{get-file-diff.output}"
151+
152+
- name: show-summary
153+
bash: |
154+
echo "=== REVIEW SUMMARY FOR {FILE} ==="
155+
echo ""
156+
echo "Current file analysis:"
157+
echo "{analyze-current-file.output}"
158+
echo ""
159+
echo "Diff analysis:"
160+
echo "{analyze-the-diff.output}"
161+
echo ""
162+
echo "Git diff:"
163+
echo "{get-file-diff.output}"
164+
165+
parameters:
166+
FILE:
167+
type: string
168+
description: File to review
169+
required: true
170+
BASE_BRANCH:
171+
type: string
172+
description: Branch to compare against
173+
default: "master"
174+
175+
tags: [review, analysis, read]
176+
platforms: [windows, linux, macos]
177+
```
178+
179+
### loop-review-files.yaml
180+
```yaml
181+
name: loop-review-files
182+
description: Loop through files and review each one individually
183+
184+
steps:
185+
- name: get-changed-files
186+
tool: changed-files
187+
with:
188+
BASE_BRANCH: "{BASE_BRANCH}"
189+
190+
- name: review-each-file
191+
bash: |
192+
echo "=== REVIEWING ALL CHANGED FILES ==="
193+
echo ""
194+
echo "Changed files:"
195+
echo "{get-changed-files.output}"
196+
echo ""
197+
for file in {get-changed-files.output}; do
198+
if [ -f "$file" ]; then
199+
echo "========================================"
200+
cycod tool run review-file --param FILE="$file" --param BASE_BRANCH="{BASE_BRANCH}"
201+
echo ""
202+
fi
203+
done
204+
205+
parameters:
206+
BASE_BRANCH:
207+
type: string
208+
description: Branch to compare against
209+
default: "master"
210+
211+
tags: [review, analysis, read]
212+
platforms: [windows, linux, macos]
213+
```
214+
215+
## Agent Wrapper Tools
216+
217+
### review-file.yaml
218+
```yaml
219+
name: review-file
220+
description: Review a specific file using the file-reviewer agent
221+
222+
file-reviewer:
223+
FILE: "{FILE}"
224+
BASE_BRANCH: "{BASE_BRANCH}"
225+
226+
parameters:
227+
FILE:
228+
type: string
229+
description: File to review
230+
required: true
231+
BASE_BRANCH:
232+
type: string
233+
description: Branch to compare against
234+
default: "master"
235+
236+
tags: [review, agent-wrapper]
237+
platforms: [windows, linux, macos]
238+
```
239+
240+
### review-changes.yaml
241+
```yaml
242+
name: review-changes
243+
description: Review all changed files using code-reviewer agent
244+
245+
steps:
246+
- name: get-files
247+
tool: changed-files
248+
with:
249+
BASE_BRANCH: "{BASE_BRANCH}"
250+
251+
- name: invoke-reviewer
252+
code-reviewer:
253+
CHANGED_FILES: "{get-files.output}"
254+
BASE_BRANCH: "{BASE_BRANCH}"
255+
256+
parameters:
257+
BASE_BRANCH:
258+
type: string
259+
description: Branch to compare against
260+
default: "master"
261+
262+
tags: [review, agent-wrapper]
263+
platforms: [windows, linux, macos]
264+
```
265+
266+
## Agents
267+
268+
### file-reviewer.md
269+
```markdown
270+
---
271+
uses:
272+
tools: [analyze-file, analyze-diff, file-diff]
273+
---
274+
275+
# File Reviewer
276+
277+
You are a senior software engineer who can review files for quality, security, and best practices.
278+
279+
When asked to review a file, you should:
280+
281+
1. **Use available tools** - gather technical data about the file and its changes
282+
2. **Analyze current state** - code quality, structure, readability
283+
3. **Examine recent changes** - what was added, removed, or modified
284+
4. **Identify issues** - bugs, security concerns, style violations
285+
5. **Suggest improvements** - specific, actionable recommendations
286+
6. **Prioritize findings** - focus on the most impactful issues first
287+
288+
Be constructive and specific. Reference line numbers when possible.
289+
Explain WHY something is an issue, not just WHAT the issue is.
290+
291+
You have access to file analysis tools - use them to inform your review.
292+
```
293+
294+
### code-reviewer.md
295+
```markdown
296+
---
297+
uses:
298+
tools: [changed-files, all-diffs]
299+
---
300+
301+
# Code Reviewer
302+
303+
You are a lead engineer who can conduct comprehensive code reviews.
304+
305+
When asked to review changes, you should:
306+
307+
1. **Get the big picture** - understand what files changed and why
308+
2. **Use available tools** - gather technical data about the changes
309+
3. **Analyze each file** - review individual files for quality and issues
310+
4. **Consider cross-file impact** - how changes interact across the codebase
311+
5. **Provide summary** - prioritize findings and suggest next steps
312+
313+
Focus on:
314+
- Code quality and maintainability
315+
- Potential bugs or regressions
316+
- Security implications
317+
- Performance considerations
318+
- Team coding standards
319+
- Architecture and design patterns
320+
321+
Provide both detailed feedback and a high-level summary for stakeholders.
322+
323+
You have access to git tools - use them to understand the scope and nature of changes.
324+
```
325+
326+
## Usage Examples
327+
328+
### Review a single file (via tool that wraps agent)
329+
```bash
330+
cycod tool run review-file --param FILE=src/main.py
331+
```
332+
333+
### Review all changes since master (via tool that wraps agent)
334+
```bash
335+
cycod tool run review-changes --param BASE_BRANCH=master
336+
```
337+
338+
### Loop through and review each file individually
339+
```bash
340+
cycod tool run loop-review-files --param BASE_BRANCH=develop
341+
```
342+
343+
### Direct agent usage (if you want to interact with the agent directly)
344+
```bash
345+
cycod agent run file-reviewer --param FILE=src/main.py
346+
cycod agent run code-reviewer --param BASE_BRANCH=master
347+
```
348+
349+
## Architecture Demonstration
350+
351+
This example shows:
352+
353+
- **Simple tools** (changed-files, file-diff, analyze-file) that do one thing well
354+
- **Composition tools** (review-single-file, loop-review-files) that combine simple tools
355+
- **Agent wrapper tools** (review-file, review-changes) that invoke agents cleanly
356+
- **Agents** (file-reviewer, code-reviewer) that provide intelligence and can use tools
357+
- **The neat interplay**:
358+
- Tools can wrap agents (`review-file``file-reviewer`)
359+
- Agents can use tools (`file-reviewer``analyze-file`)
360+
- Clean agent invocation syntax (`file-reviewer: { params }`)
361+
- **Consistent patterns** - same `uses:`/`with:` dependency system across tools and agents
362+
363+
The result is a complete code review system built from simple, reusable components that demonstrate the power of tools and agents working together through clean composition patterns.

0 commit comments

Comments
 (0)