feat(gaia): per-action token + wall-clock cost readout (SPEC-013)#536
Conversation
Add .gaia/scripts/token-tally.sh: reads the session's main transcript and every sub-agent sidecar, dedups usage by message.id, sums the four billing buckets (fresh input, cache write, cache read, output) plus total, computes wall-clock elapsed over usage-bearing turns, appends a durable machine-local ledger record resolved to the main checkout, writes tokens.md, and prints the tally. Exit code is always 0; unreadable input degrades to a partial figure with a marker, never a fabricated number. Ship the UAT-006 fixture tree (anchor + single/zero/malformed) and token-tally.bats (91-case suite, all green) as the non-circular oracle, and add the manifest entry for the shipped helper. Extend link-worktree.sh to symlink .gaia/local/telemetry/ into the main checkout alongside setup-state.json, cache/, and audit/, so a worktree KICKOFF run's token ledger consolidates on main (UAT-008 defense-in-depth). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Mark SPEC-014 and SPEC-015 merged and register SPEC-016 (specified). Registry bookkeeping carried along on this branch; unrelated to the token-accounting feature itself. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
code-review-audit skipped: no audit-relevant files changed in the un-audited delta (since the last clean audit); GAIA-Audit commit status stamped on HEAD so the merge gate is satisfied with no local audit run |
… (SPEC-013) Add the three call sites that invoke .gaia/scripts/token-tally.sh at each action's completion point, all matching the frozen C1 contract: - /gaia-spec (spec.md step 9): --action spec, keyed to $SPEC_ID, tokens.md beside SPEC.md, surfaced in the save confirmation; runs in interactive and auto mode. - /gaia-plan (plan.md step 4.8): --action plan, SPEC id derived from the SPEC folder name with a plan-slug fallback, tokens.md in the plan folder, surfaced in the step-5 report. - KICKOFF execution (plan.md step 4 ORCHESTRATOR template): --action execute, emitted into every generated ORCHESTRATOR.md so each plan reports its own end-of-run cost, running after the pre-merge code-review-audit marker and before self-cleanup, -x guarded. All three carry a trailing `|| true`; the tally never blocks or fails its action and degrades to a partial figure on unreadable input. Also folds in a one-line handoff-blockquote formatting tweak in spec.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
code-review-audit skipped: no audit-relevant files changed in the un-audited delta (since the last clean audit); GAIA-Audit commit status stamped on HEAD so the merge gate is satisfied with no local audit run |
…ck readout (SPEC-013) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
code-review-audit skipped: no audit-relevant files changed in the un-audited delta (since the last clean audit); GAIA-Audit commit status stamped on HEAD so the merge gate is satisfied with no local audit run |
…PEC-013) The token tally's human surfaces (stdout block and tokens.md) now render the elapsed window's start and end in the machine's local zone instead of raw UTC, read from the system clock (jq for the DST-correct local clock, `date +%Z` for the zone label — jq's own %z/%Z misreport the offset across a DST boundary on some builds). The durable ledger record keeps the raw UTC endpoints, which are timezone-independent. Epoch math stays jq-only; `date +%Z` parses no timestamp, so the epoch-parsing ban is unaffected. Adds two bats cases: a TZ=UTC baseline and a TZ=JST-9 conversion proof (crossing midnight, ledger still UTC), keeping the span timezone-independent. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
code-review-audit skipped: no audit-relevant files changed in the un-audited delta (since the last clean audit); GAIA-Audit commit status stamped on HEAD so the merge gate is satisfied with no local audit run |
…ill) (#553) Backfills the missing ## [Unreleased] Added entry for the token-to-dollar cost conversion that shipped in #547. The existing token-cost lines cover only the token tally (#536/#546) and the roll-up reader that renders the token breakdown (#539); neither names the dollar pricing. Distinct line keeps the #547 provenance. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What
Give the user a ground-truth cost readout for GAIA's three expensive actions —
/gaia-spec,/gaia-plan, and KICKOFF plan execution. At each action's completion point, a new shell helper tallies the four billing buckets (fresh input, cache write, cache read, output) plus total, and reports wall-clock elapsed (first to last billed model turn).How
.gaia/scripts/token-tally.sh(new) reads the session's main transcript and every sub-agent sidecar, dedups usage bymessage.id(transcript lines repeat the same usage ~3x — naive summing overcounts output ~3x), sums the buckets, computes elapsed over usage-bearing turns, appends one durable machine-local ledger record resolved to the main checkout (survives plan-folder deletion and linked worktrees), writestokens.md, and prints the tally.link-worktree.shnow symlinks.gaia/local/telemetry/into the main checkout alongside the existing shared state (UAT-008 defense-in-depth)..meta.jsonexclusion, ledger durability, worktree→main resolution, graceful degradation, and the wall-clock-duration cases (PL-001).Phase 2 (next commit) wires the helper into the three call sites.
Provenance
Implements SPEC-013 (immutable), with the post-freeze wall-clock-duration addition folded in at plan level (governed by the bats-enforced PL-001 criterion). Plan/spec artifacts are machine-local under gitignored
.gaia/local/.Also carries a
chore(specs)registry-status sync (unrelated to the feature).Quality gate
Shell + markdown only — the TS
pnpm typecheck && pnpm lintgate has nothing to inspect (documented skip). Shell gates:shellcheckclean,bats .gaia/scripts/tests/91/91 green,jqmanifest valid.🤖 Generated with Claude Code