-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaider_builder
More file actions
executable file
·246 lines (206 loc) · 9.01 KB
/
aider_builder
File metadata and controls
executable file
·246 lines (206 loc) · 9.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/zsh
VERSION="5.0.3"
# Built-in builder rules
BUILDER_RULES='If you see this text, you are expected to work in BUILDER mode. In BUILDER mode, you will be asked this very prompt in a loop for several iterations. This will allow you to tackle complex tasks like coding entire apps or writing LaTeX documents all from a single specification file.
<BUILDER_RULES>
## CORE RULES:
1. ROADMAP.md CREATION: If there is no ROADMAP.md file at the root of the repo, you must create it with these sections:
* PROGRESS: Overall completion percentage, TODOs remaining, and active issues count
* OBJECTIVES: High-level goals from the user'\''s specifications
* COMPLETED: Checked-off tasks with completion notes
* IN_PROGRESS: Currently active task (should only be ONE item)
* TODO: Remaining tasks with priority (P0/P1/P2) and estimated complexity
Extra sections you can create if relevant for the project:
* BLOCKED: Tasks that cannot proceed, with reasons and attempted solutions
* DECISIONS: Key design decisions you took and rationale
* LESSONS_LEARNED: Errors encountered, what didn'\''t work, and why
* FUTURE_ENHANCEMENTS: Features/improvements not in original OBJECTIVES (for scope management)
2. ROADMAP.md PURPOSE: ROADMAP.md is used exclusively by you to coordinate across iterations. You must record your initiatives, design choices and errors into it. ROADMAP.md is how iterations coordinate, so err on caution - coordination with slow progress is preferable to losing track of the big picture. Do not start actual building until you are certain ROADMAP.md is ready.
3. MILITARY-STYLE COMMUNICATION: Keep ROADMAP entries BRIEF, SPECIFIC, ACTIONABLE
- Format: "ACTION: what. REASON: why. STATUS: done/blocked/pending"
- Example: "ADDED: logging to api.py. REASON: debug user auth errors. STATUS: done, tested"
- No fluff, no verbose explanations - clarity over completeness
4. CONTEXT CHECK: Start each iteration by reading ROADMAP.md. Verify your next action still aligns with OBJECTIVES given current state.
6. SCOPE: Never add features beyond specifications. In BUILDER mode you only build but you do not try to test the code. If tempted, note as future enhancement in ROADMAP.md. Working solution beats perfect solution.
7. STEP SIZE: Do ONE small, atomic change per iteration (e.g., edit one file, add one section, implement one small thing).
- If a TODO seems too large, break it into smaller TODOs first
- Better too small than too large
8. UPDATE ROADMAP: Each step must include updating ROADMAP.md to reflect the change.
9. ADAPTIVE LEARNING: When errors occur or decisions prove wrong:
- Document in ROADMAP.md what failed and why
- If same issue appears twice, STOP and document alternatives in BLOCKED
- Don'\''t hesitate to move "completed" items back to TODO if issues are discovered
- Correction is progress, not failure
10. FINISHED.md: Create only when all tasks are done and verified. Include: what was built, key decisions, verification evidence, known limitations. After creating FINISHED.md, ask the user what to do next.
</BUILDER_RULES>
'
# Function to show usage
show_help() {
cat << EOF
Usage: aider_builder.sh -n_iter N -s SPECIFICATIONS [AIDER_ARGS...]
Run aider in a loop with builder rules.
Required arguments:
-n_iter N Maximum number of iterations (must be > 1). You can always rerun aider_builder.
-s, --specifications SPEC Specifications for what to build (passed as --message to aider). Can be a direct
string or a path to a file containing the specifications.
Optional arguments:
-h, --help Show this help message and exit
-v, --version Show version and exit
--include PATTERN Glob pattern for files to include in context (can be used multiple times)
Example: --include "**/*.py" --include "*.md"
Matched files will be added with --file to each aider iteration
AIDER_ARGS... Additional arguments to pass to aider
Note: Do not use --message in AIDER_ARGS as it will be
automatically set from the --specifications argument
EOF
exit 0
}
# Parse arguments
n_iter=""
specifications=""
include_patterns=()
aider_args=()
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_help
;;
-v|--version)
echo "aider_builder.sh version $VERSION"
exit 0
;;
-n_iter)
if [[ -z "$2" ]] || [[ ! "$2" =~ ^[0-9]+$ ]]; then
echo "Error: -n_iter requires a number as argument"
exit 1
fi
n_iter=$2
shift 2
;;
-s|--specifications)
if [[ -z "$2" ]]; then
echo "Error: -s/--specifications requires a string as argument."
exit 1
fi
specifications=$2
shift 2
;;
--include)
if [[ -z "$2" ]]; then
echo "Error: --include requires a pattern as argument"
exit 1
fi
include_patterns+=("$2")
shift 2
;;
*)
aider_args+=("$1")
shift
;;
esac
done
# Show help if no arguments provided
if [[ -z "$n_iter" ]] && [[ -z "$specifications" ]] && [[ ${#aider_args[@]} -eq 0 ]]; then
show_help
fi
# Validate required arguments
if [[ -z "$n_iter" ]]; then
echo "Error: -n_iter argument is required"
echo "Use -h or --help for usage information"
exit 1
fi
if [[ -z "$specifications" ]]; then
echo "Error: -s/--specifications argument is required"
echo "Use -h or --help for usage information"
exit 1
fi
# Check that --message is not in aider_args
for arg in "${aider_args[@]}"; do
if [[ "$arg" == "--message" || "$arg" == "-m" ]]; then
echo "Error: --message/-m should not be provided in AIDER_ARGS"
echo "Use -s/--specifications instead, which will be passed as --message to aider"
exit 1
fi
done
if [[ $n_iter -le 1 ]]; then
echo "Error: -n_iter must be greater than 1"
exit 1
fi
# Check if specifications is a path to a non-empty file
# If so, read its contents as the specification
if [[ -f "$specifications" ]] && [[ -s "$specifications" ]]; then
echo "Reading specifications from file: $specifications"
specifications=$(<"$specifications")
fi
# Create temporary file for rules
rules_tmp_file=$(mktemp)
trap "rm -f $rules_tmp_file" EXIT
echo "$BUILDER_RULES" > "$rules_tmp_file"
# Ensure ROADMAP.md exists (create if it doesn't)
touch ROADMAP.md
# Check if FINISHED.md already exists before starting
if [[ -f "FINISHED.md" ]]; then
echo "Error: FINISHED.md already exists in the current directory"
echo "This file indicates a previous build has finished."
echo "Please remove or rename FINISHED.md before starting a new build session."
exit 1
fi
counter=0
total_iterations=0
while true; do
# Run loop n_iter times
for ((i=1; i<=n_iter; i++)); do
# Check if build is finished
if [[ -f "FINISHED.md" ]]; then
echo "\n###################"
echo "# Build finished! FINISHED.md detected."
echo "###################"
echo "Completed $total_iterations total iterations."
exit 0
fi
counter=$((counter + 1))
total_iterations=$((total_iterations + 1))
echo "\n###################"
echo "# AiderBuilder iteration #$total_iterations ($(date))"
echo "###################"
# Expand include patterns and add to aider_args
if [[ ${#include_patterns[@]} -gt 0 ]]; then
echo "Expanding include patterns..."
for pattern in "${include_patterns[@]}"; do
# Enable extended globbing for ** patterns
setopt extended_glob
matched_files=(${~pattern})
if [[ ${#matched_files[@]} -eq 0 ]]; then
echo "Warning: Pattern '$pattern' matched no files"
else
echo "Pattern '$pattern' matched ${#matched_files[@]} file(s)"
for file in "${matched_files[@]}"; do
# Only add if it's a regular file (not directory)
if [[ -f "$file" ]]; then
aider_args+=(--file "$file")
fi
done
fi
done
fi
aider --read "$rules_tmp_file" --file ROADMAP.md --message "You are in BUILDER mode.
Here are the user specifications:
<SPECIFICATIONS>
$specifications
</SPECIFICATIONS>
" "${aider_args[@]}"
done
# Ask user to continue
echo "\nCompleted $n_iter iterations (total: $total_iterations)"
read "response?Continue for another $n_iter iterations? (y/N): "
case $response in
[Yy]* )
echo "Continuing..."
counter=0
;;
* )
echo "Stopping."
exit 0
;;
esac
done