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