Repository navigation
feat: record token usage per board run and show it in the web UI - #23
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The runner drops a row on 400, so a token not yet granted on a scope would have lost its rows. Plain string tests replace the regex literals, which the edge runtime's parser refused to boot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a backlog per tick - POST /usage answers 503 for a database error, so the runner retries it - workers killed by a double Ctrl-C are counted from their transcripts - the sender sends at most 10 rows per loop tick Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The board runner records the raw token counts (input, output, cache read, cache write, per model; never dollars) of every session it starts, stores them in shared memory, and the web UI shows them.
resultline, or summed from its messages (each message id once) when it was killed or cut off. Workers orphaned by a crashed runner, or killed by a double Ctrl-C, are counted too.board_usagetable (20261127120000_board_usage.sql). Writes go only throughrecord_board_usage(an upsert on scope, board and run label;can_writerequired). The intent id is kept only when it names an intent of that board. Reads are under acan_readpolicy.delete_board_usagedeletes a board's rows. Agents never see the rows.POST /usage,GET /usage?scope=&board=(runs, newest first, plus the summed total),POST /usage/delete. Scope errors answer 404 or 403 and database errors 503, so the runner retries them.usage-pending.jsonlfirst and are retried with backoff until accepted, at most 10 per loop tick. Only 400, 413 and 422 drop a row. Credentials come fromAGENT_MEMORY_TOKENandWEB_API_URLin the environment, or from the board file'susage_env_file.board-runner forget-usage <board file>deletes a board's rows (toy-board cleanup).GET /api/usageonly.board_usage.Design:
docs/superpowers/specs/2026-11-27-token-usage-design.md; plan:docs/superpowers/plans/2026-11-27-token-usage.md.Tests
deno task check, 318 unit tests, integration (usage-store,web-api,backup), pgTAP18_board_usage, and the runnerunittestsuite all pass.web-api, then GET through the local web server proxy, thenforget-usage.Found and fixed along the way
web-api.ts, althoughdeno checkpassed (BOOT_ERROR). It is replaced, and noted in CLAUDE.md.Deferred minors
startedAtresets on each runner restart.After merge (each needs consent)
supabase db push --remote --dry-run, a backup, thensupabase db push --remote.supabase functions deploy web-api --use-api.AGENT_MEMORY_TOKENandWEB_API_URL(orusage_env_file).🤖 Generated with Claude Code