Skip to content

Commit 3af1b28

Browse files
committed
Record total tokens/duration
1 parent 2c91b13 commit 3af1b28

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

lib/zsh/functions/wiggum

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ wiggum() {
4444
return 1
4545
fi
4646

47+
local total_duration=0
48+
local total_input_tokens=0
49+
local total_output_tokens=0
50+
4751
while true; do
4852
iteration=$((iteration + 1))
4953
echo -e "\n======================== LOOP $iteration ========================\n"
@@ -82,12 +86,12 @@ EOF
8286
--model "${model:-opus}")
8387
local end_time=$(date -Iseconds)
8488

85-
if [[ "$output" == *"WIGGUM:OVER"* ]]; then
89+
local result_text=$(echo "$output" | jq -r '.result // empty')
90+
91+
if [[ "$result_text" == *"WIGGUM:OVER"* ]]; then
8692
echo "Work complete (WIGGUM:OVER)"
8793
break
8894
fi
89-
90-
local result_text=$(echo "$output" | jq -r '.result // empty')
9195
local log_json=$(echo "$result_text" | grep -oE 'WIGGUM_LOG:\{[^}]+\}' | head -1 | sed 's/WIGGUM_LOG://')
9296
local input_tokens=$(echo "$output" | jq -r '.usage.input_tokens // 0')
9397
local output_tokens=$(echo "$output" | jq -r '.usage.output_tokens // 0')
@@ -114,8 +118,20 @@ EOF
114118
echo -e "\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
115119
echo "$entry" | jq -r '"Success: \(.success)\nSummary: \(.summary)\nSteps: \(.steps_taken | join(", "))\nCommands: \(.commands_run | join(", "))\nIssues: \(.issues_encountered | if length == 0 then "none" else join(", ") end)\nDuration: \(.duration_secs)s\nTokens: \(.input_tokens) in / \(.output_tokens) out"'
116120
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
121+
122+
total_duration=$((total_duration + duration_secs))
123+
total_input_tokens=$((total_input_tokens + input_tokens))
124+
total_output_tokens=$((total_output_tokens + output_tokens))
117125
fi
118126

119127
[[ -z "$no_git" ]] && git commit -am "Wiggum iteration $iteration"
120128
done
129+
130+
echo -e "\n════════════════════════════════════════"
131+
echo "TOTALS"
132+
echo "════════════════════════════════════════"
133+
echo "Iterations: $((iteration - 1))"
134+
echo "Duration: ${total_duration}s"
135+
echo "Tokens: ${total_input_tokens} in / ${total_output_tokens} out"
136+
echo "════════════════════════════════════════"
121137
}

0 commit comments

Comments
 (0)