make it so much better

This commit is contained in:
Daniel Newman 2026-05-15 12:26:40 -04:00
commit c108c8175e

274
bin/burn
View file

@ -5,7 +5,7 @@ set -euo pipefail
FILLER_TOKENS=1000 FILLER_TOKENS=1000
SYSTEM_OVERHEAD_TOKENS=9000 # measured: claude -p system prompt + tool defs SYSTEM_OVERHEAD_TOKENS=9000 # measured: claude -p system prompt + tool defs
TOKENS_PER_CALL=$(( SYSTEM_OVERHEAD_TOKENS + FILLER_TOKENS )) TOKENS_PER_CALL=$((SYSTEM_OVERHEAD_TOKENS + FILLER_TOKENS))
MIN_TOKENS=$TOKENS_PER_CALL # asking for less than one call can't be honored MIN_TOKENS=$TOKENS_PER_CALL # asking for less than one call can't be honored
FILLER_LINE="Burn baby burn, this is a disco inferno, burning tokens is for great engineers. " FILLER_LINE="Burn baby burn, this is a disco inferno, burning tokens is for great engineers. "
@ -29,30 +29,53 @@ model=""
tokens="" tokens=""
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
-h|--help) usage; exit 0 ;; -h | --help)
usage
exit 0
;;
--model) --model)
if [[ $# -lt 2 ]]; then echo "error: --model requires a value" >&2; exit 2; fi if [[ $# -lt 2 ]]; then
model="$2"; shift 2 ;; echo "error: --model requires a value" >&2
--model=*) model="${1#*=}"; shift ;; exit 2
--) shift; break ;; fi
-*) echo "error: unknown flag: $1" >&2; usage >&2; exit 2 ;; model="$2"
shift 2
;;
--model=*)
model="${1#*=}"
shift
;;
--)
shift
break
;;
-*)
echo "error: unknown flag: $1" >&2
usage >&2
exit 2
;;
*) *)
if [[ -n "$tokens" ]]; then if [[ -n "$tokens" ]]; then
echo "error: unexpected extra argument: $1" >&2 echo "error: unexpected extra argument: $1" >&2
exit 2 exit 2
fi fi
tokens="$1"; shift ;; tokens="$1"
shift
;;
esac esac
done done
if [[ -z "$tokens" ]]; then if [[ -z "$tokens" ]]; then
usage >&2; exit 2 usage >&2
exit 2
fi fi
if ! [[ "$tokens" =~ ^[0-9]+$ ]]; then if ! [[ "$tokens" =~ ^[0-9]+$ ]]; then
echo "error: TOKENS must be a positive integer (got '$tokens')" >&2; exit 2 echo "error: TOKENS must be a positive integer (got '$tokens')" >&2
exit 2
fi fi
if (( tokens < MIN_TOKENS )); then if ((tokens < MIN_TOKENS)); then
echo "error: tokens must be at least ${MIN_TOKENS} (got ${tokens})" >&2; exit 2 echo "error: tokens must be at least ${MIN_TOKENS} (got ${tokens})" >&2
exit 2
fi fi
if ! command -v claude >/dev/null 2>&1; then if ! command -v claude >/dev/null 2>&1; then
@ -67,26 +90,32 @@ if ! command -v jq >/dev/null 2>&1; then
fi fi
# ~4 chars/token is the standard rule of thumb for English text. # ~4 chars/token is the standard rule of thumb for English text.
target_chars=$(( FILLER_TOKENS * 4 )) target_chars=$((FILLER_TOKENS * 4))
filler_len=${#FILLER_LINE} filler_len=${#FILLER_LINE}
repeats=$(( target_chars / filler_len )) repeats=$((target_chars / filler_len))
(( repeats < 1 )) && repeats=1 ((repeats < 1)) && repeats=1
filler="" filler=""
for ((i=0; i<repeats; i++)); do for ((i = 0; i < repeats; i++)); do
filler+="$FILLER_LINE" filler+="$FILLER_LINE"
done done
prompt=$(printf "Reply with the single word 'burned' and nothing else. Ignore the filler text below; it exists only to consume tokens.\n\n%s" "$filler") prompt=$(printf "Reply with the single word 'burned' and nothing else. Ignore the filler text below; it exists only to consume tokens.\n\n%s" "$filler")
if [[ -t 1 ]]; then if [[ -t 1 ]]; then
ORANGE=$'\033[1;33m' ORANGE=$'\033[1;33m'
RED=$'\033[0;31m' MAGENTA=$'\033[1;35m'
CYAN=$'\033[1;36m'
RED=$'\033[1;31m'
YELLOW=$'\033[1;93m'
DIM=$'\033[2m' DIM=$'\033[2m'
RESET=$'\033[0m' RESET=$'\033[0m'
HIDE_CURSOR=$'\033[?25l' HIDE_CURSOR=$'\033[?25l'
SHOW_CURSOR=$'\033[?25h' SHOW_CURSOR=$'\033[?25h'
else else
ORANGE='' ORANGE=''
MAGENTA=''
CYAN=''
RED='' RED=''
YELLOW=''
DIM='' DIM=''
RESET='' RESET=''
HIDE_CURSOR='' HIDE_CURSOR=''
@ -95,71 +124,113 @@ fi
PAD=' ' PAD=' '
# Three flame frames cycled to make the fire dance. Each row is exactly # Four disco frames cycled to make the dancer sway across the floor while
# 23 characters wide so it sits cleanly inside the fireplace opening. # the ball glitters on the off-beat. Each row is exactly 23 characters wide
flame_frame() { # so it sits cleanly inside the booth opening.
disco_frame() {
case "$1_$2" in case "$1_$2" in
0_0) printf '%s' ' ) ) ) ' ;; # frame 0 — centered Travolta: left hand on hip, right arm pointing up-right
0_1) printf '%s' ' )\ )\ )\ ' ;; 0_0) printf '%s' ' | ' ;;
0_2) printf '%s' ' ( ( ( ( ( ( ( ( ( ' ;; 0_1) printf '%s' ' 🪩 ' ;;
0_3) printf '%s' ' ) ) ) ) ) ) ) ) ) ' ;; 0_2) printf '%s' ' /|\ ' ;;
0_4) printf '%s' ' \_/ \_/ \_/ ' ;; 0_3) printf '%s' ' / ' ;;
1_0) printf '%s' ' ( ( ( ' ;; 0_4) printf '%s' ' o/ ' ;;
1_1) printf '%s' ' /( /( /( ' ;; 0_5) printf '%s' ' <| ' ;;
1_2) printf '%s' ' ( ( ( ( ( ( ( ( ( ' ;; 0_6) printf '%s' ' | ' ;;
1_3) printf '%s' ' ( ) ( ) ( ) ( ) ( ' ;; 0_7) printf '%s' ' / \ ' ;;
1_4) printf '%s' ' \_/ \_/ \_/ ' ;; 0_8) printf '%s' ' ▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓ ' ;;
2_0) printf '%s' ' ) ( ) ' ;; # frame 1 — lean left, same Travolta pose; sparkles on the chain
2_1) printf '%s' ' (( )( (( ' ;; 1_0) printf '%s' ' * | * ' ;;
2_2) printf '%s' ' ( ( ( ( ( ( ( ( ( ' ;; 1_1) printf '%s' ' 🪩 ' ;;
2_3) printf '%s' ' ) ( ) ( ) ( ) ( ) ' ;; 1_2) printf '%s' ' \|/ ' ;;
2_4) printf '%s' ' \_/ \_/ \_/ ' ;; 1_3) printf '%s' ' / ' ;;
1_4) printf '%s' ' o/ ' ;;
1_5) printf '%s' ' <| ' ;;
1_6) printf '%s' ' | ' ;;
1_7) printf '%s' ' / \ ' ;;
1_8) printf '%s' ' ▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒ ' ;;
# frame 2 — centered mirror: right hand on hip, left arm pointing up-left
2_0) printf '%s' ' | ' ;;
2_1) printf '%s' ' 🪩 ' ;;
2_2) printf '%s' ' /|\ ' ;;
2_3) printf '%s' ' \ ' ;;
2_4) printf '%s' ' \o ' ;;
2_5) printf '%s' ' |> ' ;;
2_6) printf '%s' ' | ' ;;
2_7) printf '%s' ' / \ ' ;;
2_8) printf '%s' ' ▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓ ' ;;
# frame 3 — lean right, mirror Travolta; sparkles on the chain
3_0) printf '%s' ' * | * ' ;;
3_1) printf '%s' ' 🪩 ' ;;
3_2) printf '%s' ' \|/ ' ;;
3_3) printf '%s' ' \ ' ;;
3_4) printf '%s' ' \o ' ;;
3_5) printf '%s' ' |> ' ;;
3_6) printf '%s' ' | ' ;;
3_7) printf '%s' ' / \ ' ;;
3_8) printf '%s' ' ▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒▓▒ ' ;;
esac esac
} }
flame_color_for_row() { disco_color_for_row() {
case "$1" in case "$1" in
0|1) printf '%s' "$ORANGE" ;; 0 | 2) printf '%s' "$ORANGE" ;; # chain sparkles + light rays
*) printf '%s' "$RED" ;; 1 | 8) printf '%s' "$MAGENTA" ;; # disco ball + dance floor
*) printf '%s' "$CYAN" ;; # dancer (and blank rows)
esac esac
} }
print_flame_row() { # Render `count` copies of `char` colored across a cycling fire palette
local frame=$1 row=$2 content color # (red → orange → yellow). `offset` rotates the cycle so the strip flickers.
content=$(flame_frame "$frame" "$row") fire_strip() {
color=$(flame_color_for_row "$row") local count=$1 char=$2 offset=${3:-0}
printf '%s%s│░░░│%s%s%s%s%s│░░░│%s\n' \ local palette=("$RED" "$ORANGE" "$YELLOW")
"$PAD" "$DIM" "$RESET" "$color" "$content" "$RESET" "$DIM" "$RESET" local n=${#palette[@]}
} local i out=""
for ((i = 0; i < count; i++)); do
draw_fireplace() { out+="${palette[$(((i + offset) % n))]}${char}"
local frame=${1:-0}
printf '%s%s┌───────────────────────────────┐%s\n' "$PAD" "$DIM" "$RESET"
printf '%s%s│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│%s\n' "$PAD" "$DIM" "$RESET"
printf '%s%s│░░░┌───────────────────────┐░░░│%s\n' "$PAD" "$DIM" "$RESET"
printf '%s%s│░░░│ │░░░│%s\n' "$PAD" "$DIM" "$RESET"
printf '%s%s│░░░│ │░░░│%s\n' "$PAD" "$DIM" "$RESET"
for row in 0 1 2 3 4; do
print_flame_row "$frame" "$row"
done done
printf '%s%s│░░░│ │░░░│%s\n' "$PAD" "$DIM" "$RESET" printf '%s' "$out"
printf '%s%s│░░░│%s %s▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓%s %s│░░░│%s\n' \
"$PAD" "$DIM" "$RESET" "$RED" "$RESET" "$DIM" "$RESET"
printf '%s%s│░░░└───────────────────────┘░░░│%s\n' "$PAD" "$DIM" "$RESET"
printf '%s%s└───────────────────────────────┘%s\n' "$PAD" "$DIM" "$RESET"
} }
# Distance (in lines) from the progress-bar cursor up to the top flame row: print_disco_row() {
# blank line above bar + outer-bottom + inner-bottom + log + blank-below-flames local frame=$1 row=$2 content color fl
# + 5 flame rows = 10. content=$(disco_frame "$frame" "$row")
FLAME_OFFSET=10 color=$(disco_color_for_row "$row")
fl=$(fire_strip 3 '░' "$frame")
printf '%s%s│%s%s│%s%s%s%s%s│%s%s│%s\n' \
"$PAD" "$RED" "$fl" "$YELLOW" "$RESET" \
"$color" "$content" "$RESET" \
"$YELLOW" "$fl" "$RED" "$RESET"
}
redraw_flames() { draw_disco() {
local frame=${1:-0}
local flames fr3
flames=$(fire_strip 31 '▲')
fr3=$(fire_strip 3 '░')
printf '%s%s┌───────────────────────────────┐%s\n' "$PAD" "$RED" "$RESET"
printf '%s%s│%s%s│%s\n' "$PAD" "$RED" "$flames" "$RED" "$RESET"
printf '%s%s│%s%s┌───────────────────────┐%s%s│%s\n' \
"$PAD" "$RED" "$fr3" "$YELLOW" "$fr3" "$RED" "$RESET"
for row in 0 1 2 3 4 5 6 7 8; do
print_disco_row "$frame" "$row"
done
printf '%s%s│%s%s└───────────────────────┘%s%s│%s\n' \
"$PAD" "$RED" "$fr3" "$YELLOW" "$fr3" "$RED" "$RESET"
printf '%s%s└───────────────────────────────┘%s\n' "$PAD" "$RED" "$RESET"
}
# Distance (in lines) from the progress-bar cursor up to the top inner row:
# blank line above bar + outer-bottom + inner-bottom + 9 inner rows = 12.
DISCO_OFFSET=12
redraw_disco() {
local frame=$1 local frame=$1
printf '\033[s' # save cursor printf '\033[s' # save cursor
printf '\033[%dA\r' "$FLAME_OFFSET" # move up to top flame row printf '\033[%dA\r' "$DISCO_OFFSET" # move up to top inner row
for row in 0 1 2 3 4; do for row in 0 1 2 3 4 5 6 7 8; do
print_flame_row "$frame" "$row" print_disco_row "$frame" "$row"
done done
printf '\033[u' # restore cursor printf '\033[u' # restore cursor
} }
@ -180,12 +251,12 @@ claude_cmd+=(--)
draw_bar() { draw_bar() {
local pct filled empty bar="" i suffix="${1:-}" local pct filled empty bar="" i suffix="${1:-}"
pct=$(( burned * 100 / tokens )) pct=$((burned * 100 / tokens))
(( pct > 100 )) && pct=100 ((pct > 100)) && pct=100
filled=$(( pct * BAR_WIDTH / 100 )) filled=$((pct * BAR_WIDTH / 100))
empty=$(( BAR_WIDTH - filled )) empty=$((BAR_WIDTH - filled))
for ((i=0; i<filled; i++)); do bar+='█'; done for ((i = 0; i < filled; i++)); do bar+='█'; done
for ((i=0; i<empty; i++)); do bar+='░'; done for ((i = 0; i < empty; i++)); do bar+='░'; done
# \033[K clears any leftover characters from a longer previous draw. # \033[K clears any leftover characters from a longer previous draw.
printf "\r[%s] %3d%% • %d/%d tokens • \$%s • %d call(s)%s\033[K" \ printf "\r[%s] %3d%% • %d/%d tokens • \$%s • %d call(s)%s\033[K" \
"$bar" "$pct" "$burned" "$tokens" "$total_cost" "$iteration" "$suffix" "$bar" "$pct" "$burned" "$tokens" "$total_cost" "$iteration" "$suffix"
@ -196,14 +267,37 @@ restore_cursor() {
} }
trap restore_cursor EXIT trap restore_cursor EXIT
CELEBRATIONS=(
"🔧 You are a great engineer!"
"🪄 You are an AI wizard!"
"🕺 Tokens burned. Groove restored."
"✨ Claude never saw that coming."
"🚀 You shipped faster than the flame could spread."
"💃 The code is hot and the vibes are immaculate."
"🪩 Groovy job. Productivity achieved."
"⚡ The tokens are gone, but the legend remains."
"🏆 Another glorious victory for human-machine collaboration."
"⚡ You turned tokens into pure developer energy."
"🎩 Behold: a masterclass in responsible token combustion."
"🌈 The code goblins approve this burn."
"🛠️ Great work. The token furnace is pleased."
)
# Round a dollar amount to the nearest cent.
round_cents() {
awk -v c="$1" 'BEGIN{printf "%.2f", c}'
}
on_interrupt() { on_interrupt() {
if [[ -n "$claude_pid" ]]; then if [[ -n "$claude_pid" ]]; then
kill "$claude_pid" 2>/dev/null || true kill "$claude_pid" 2>/dev/null || true
wait "$claude_pid" 2>/dev/null || true wait "$claude_pid" 2>/dev/null || true
fi fi
echo local cost_rounded
printf "stopped. burned %s tokens across %s call(s), spent \$%s.\n" \ cost_rounded=$(round_cents "$total_cost")
"$burned" "$iteration" "$total_cost" printf "\n\n🛑 stopped early.\n\n"
printf " 🔥 You torched %s tokens across %s call(s), and spent \$%s\n\n" "$cost_rounded 💰💰💰" "$burned" "$iteration"
printf " 💰 spent "
exit 130 exit 130
} }
trap on_interrupt INT trap on_interrupt INT
@ -213,14 +307,14 @@ trap on_interrupt INT
run_claude() { run_claude() {
local output_file local output_file
output_file=$(mktemp) output_file=$(mktemp)
"${claude_cmd[@]}" "$prompt" > "$output_file" 2>/dev/null & "${claude_cmd[@]}" "$prompt" >"$output_file" 2>/dev/null &
claude_pid=$! claude_pid=$!
local frame=0 local frame=0
while kill -0 "$claude_pid" 2>/dev/null; do while kill -0 "$claude_pid" 2>/dev/null; do
redraw_flames $(( frame % 3 )) redraw_disco $((frame % 4))
frame=$(( frame + 1 )) frame=$((frame + 1))
sleep 0.25 sleep 0.4
done done
if wait "$claude_pid" 2>/dev/null; then if wait "$claude_pid" 2>/dev/null; then
@ -237,12 +331,12 @@ run_claude() {
printf '%s' "$HIDE_CURSOR" printf '%s' "$HIDE_CURSOR"
echo echo
draw_fireplace 0 draw_disco 0
echo echo
draw_bar draw_bar
while (( burned < tokens )); do while ((burned < tokens)); do
iteration=$(( iteration + 1 )) iteration=$((iteration + 1))
if ! run_claude; then if ! run_claude; then
draw_bar " (retrying)" draw_bar " (retrying)"
@ -265,11 +359,15 @@ while (( burned < tokens )); do
exit 1 exit 1
fi fi
burned=$(( burned + this_call )) burned=$((burned + this_call))
total_cost=$(awk -v a="$total_cost" -v b="$this_cost" 'BEGIN{printf "%.6f", a+b}') total_cost=$(awk -v a="$total_cost" -v b="$this_cost" 'BEGIN{printf "%.6f", a+b}')
draw_bar draw_bar
done done
echo cost_rounded=$(round_cents "$total_cost")
printf "done. burned %s tokens across %s call(s) (target was %s), spent \$%s.\n" \ msg="${CELEBRATIONS[RANDOM % ${#CELEBRATIONS[@]}]}"
"$burned" "$iteration" "$tokens" "$total_cost"
printf "\n\n%s\n\n" "$msg"
printf " 🔥 torched %s fire tokens across %s call(s) (target: %s)\n" \
"$burned" "$iteration" "$tokens"
printf " 💰 spent \$%s\n\n" "$cost_rounded"