Skip to content

Commit ddb0387

Browse files
committed
Add wiggum
1 parent 6e6c499 commit ddb0387

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

lib/zsh/functions/wiggum

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
wiggum() {
2+
local prompt_file max_iterations iteration current_branch custom_prompt no_git model
3+
4+
while [[ $# -gt 0 ]]; do
5+
case "$1" in
6+
-p|--prompt)
7+
custom_prompt="$2"
8+
shift 2
9+
;;
10+
--no-git)
11+
no_git=1
12+
shift
13+
;;
14+
-i|--iterations)
15+
max_iterations="$2"
16+
shift 2
17+
;;
18+
-m|--model)
19+
model="$2"
20+
shift 2
21+
;;
22+
*)
23+
shift
24+
;;
25+
esac
26+
done
27+
28+
max_iterations="${max_iterations:-0}"
29+
prompt_file="${custom_prompt:-PROMPT.md}"
30+
31+
iteration=0
32+
current_branch=$(git branch --show-current)
33+
34+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
35+
echo "Prompt: $prompt_file"
36+
echo "Model: ${model:-opus}"
37+
echo "Branch: $current_branch"
38+
[[ $max_iterations -gt 0 ]] && echo "Max: $max_iterations iterations" || echo "Max: unlimited"
39+
[[ -z "$no_git" ]] && echo "Commit: true" || echo "Commit: false"
40+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
41+
42+
if [[ ! -f "$prompt_file" ]]; then
43+
echo "Error: $prompt_file not found"
44+
return 1
45+
fi
46+
47+
while true; do
48+
iteration=$((iteration + 1))
49+
50+
if [[ $max_iterations -gt 0 ]] && [[ $iteration -gt $max_iterations ]]; then
51+
echo "Reached max iterations: $max_iterations"
52+
break
53+
fi
54+
55+
local output=$({
56+
cat "$prompt_file"
57+
cat <<EOF
58+
59+
## Iteration context
60+
61+
This prompt is iteration number $iteration.
62+
63+
After you have completed the task, append an entry to wiggum_log.json with:
64+
65+
- a summary of what was done
66+
- a list of actions taken
67+
- a list of all commands run
68+
- errors or issues encountered
69+
- success or failure
70+
71+
If wiggum_log.json doesn't exist, create it. It should be a JSON file containing an array of objects:
72+
73+
\`\`\`
74+
[
75+
{
76+
"iteration": 1,
77+
"success": true,
78+
"summary": "CSS added to style header",
79+
"steps_taken": [
80+
"decided to name CSS file foo.css",
81+
"created CSS file"
82+
],
83+
"commands_run": [
84+
"touch ./foo.css",
85+
],
86+
"issues_encountered": [],
87+
},
88+
...
89+
]
90+
\`\`\`
91+
92+
If there is no further work to do, output exactly WIGGUM:OVER
93+
EOF
94+
} | claude -p \
95+
--dangerously-skip-permissions \
96+
--output-format=stream-json \
97+
--model "${model:-opus}" \
98+
--verbose)
99+
100+
if [[ "$output" == *"WIGGUM:OVER"* ]]; then
101+
echo "Work complete (WIGGUM:OVER)"
102+
break
103+
fi
104+
105+
if [[ -f "wiggum_log.json" ]]; then
106+
echo -e "\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
107+
jq ".[] | select(.iteration == $iteration)" wiggum_log.json
108+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
109+
fi
110+
111+
[[ -z "$no_git" ]] && git commit -am "Wiggum iteration $iteration"
112+
echo -e "\n\n======================== LOOP $iteration ========================\n"
113+
done
114+
}

0 commit comments

Comments
 (0)