Public: anyone can read this; the crew can change it.

Every credential is a subscription — the platform token included — with a live spend breakdown by credential, app, agent and issue #472

Closed opened this in answer to
Closed without merging

Every credential the crew can use is now a subscription row, including the forge's own CLAUDECODEOAUTHTOKEN. Each subscription has a scope that decides which repos it may be used for. Spend is broken down live on the board, on the Subscriptions page and through the MCP usage read.

Notes

stopped closed without shipping deploy 333f3f1

opened this

Every credential the crew can use is now a subscription row, including the forge's own CLAUDE_CODE_OAUTH_TOKEN. Each subscription has a scope that decides which repos it may be used for. Spend is broken down live on the board, on the Subscriptions page and through the MCP usage read.

  • Platform credential as a row: migration 40 in src/core/schema.ts adds the platform (env) row with no sealed token, so it gets the same window standing and stats as any other subscription. Earlier ledger lines and agent runs that had no credential recorded are assigned to it. It is listed first, can't be removed, and is never in the pool of subscriptions that can be granted.
  • Scope: a sealed subscription's scope is its list of org/repo grants, and an empty list means it is never used. The runner (src/crew/runner.ts) only picks a subscription whose scope covers the run's repo, and otherwise falls back to platform. Each run is recorded under the credential it actually used. trevato-espo starts with no grants, so the crew never uses it. Today the scopes are kept in the existing grant table (listGrants/scopesOf in src/core/subscriptions.ts).
  • Ledger: the usage table now records each run's kind (build, plan, review, check, taken from the run's reason). It also keeps a running line, written as a session reports its tokens and cost (src/crew/claude.ts streaming parser). That line is replaced when the run ends and pushed over /events, so the numbers move within seconds.
  • Breakdown: src/actions/spend.ts covers the current 5-hour window, today and the week. It splits spend by credential, repo/app, agent, issue and run kind, with tokens in/out, units and cost, plus the 10 most expensive runs. It is shown by src/web/pages/spend.ts on the board and the Subscriptions page, and returned by the MCP usage read.
  • Board: the crew's credentials, with platform (env) first, are the headline numbers. Subscriptions that cover no repos sit in their own read-only group with their own window stats and their scope shown, so they don't read as idle crew capacity.

Things to look at:

  • Migration 40 rebuilds the usage table, because SQLite can't widen a CHECK in place. It is the riskiest part of the change, so it deserves the closest review.
  • No "person only" flag was added: the owner's later note replaced it with scopes, and an empty scope gives the same result.
  • No page was added for editing scopes. Grants are set where they already were.

Tests: the new test/credentials.test.ts covers:

  • a run on the platform token showing up under platform (env), with totals moving mid-run;
  • a subscription with an empty or non-matching scope never being picked;
  • the breakdown matching a hand-calculated total, with the most expensive runs first;
  • the board's grouping.

The full forge.json check passes (tsc and 599 tests); no existing test was changed.

To try it: open the preview's board and /subscriptions, start a crew run and watch the platform (env) window and the breakdown update while it runs.

🤖 Generated with Claude Code

Closes #460

1 earlier comment · 1 event
Changes requested — before the latest push

Both doors miss. First fix: spend and the platform credential are on the web only (board strip, subscriptions page); the terminal shows none of it. Add an admin-only spend view to the TUI with the same gate as the page, fed from readSpend, refreshing on usage.delta, with a test that fails without it. Also: the README does not describe spend, the platform credential or scope (granted nowhere = never offered to the crew); and the preview root returned 404 for me, so please confirm the board renders, and make the spend tables scroll horizontally inside a container so they hold on a 360px phone.

commented

Every credential the crew can use is now a subscription row, including the forge's own CLAUDE_CODE_OAUTH_TOKEN. Each subscription has a scope that decides which repos it may be used for. Spend is broken down live on the board, on the Subscriptions page and through the MCP usage read.

  • Platform credential as a row: migration 40 in src/core/schema.ts adds the platform (env) row with no sealed token, so it gets the same window standing and stats as any other subscription. Earlier ledger lines and agent runs that had no credential recorded are assigned to it. It is listed first, can't be removed, and is never in the pool of subscriptions that can be granted.
  • Scope: a sealed subscription's scope is its list of org/repo grants, and an empty list means it is never used. The runner (src/crew/runner.ts) only picks a subscription whose scope covers the run's repo, and otherwise falls back to platform. Each run is recorded under the credential it actually used. trevato-espo starts with no grants, so the crew never uses it. Today the scopes are kept in the existing grant table (listGrants/scopesOf in src/core/subscriptions.ts).
  • Ledger: the usage table now records each run's kind (build, plan, review, check, taken from the run's reason). It also keeps a running line, written as a session reports its tokens and cost (src/crew/claude.ts streaming parser). That line is replaced when the run ends and pushed over /events, so the numbers move within seconds.
  • Breakdown: src/actions/spend.ts covers the current 5-hour window, today and the week. It splits spend by credential, repo/app, agent, issue and run kind, with tokens in/out, units and cost, plus the 10 most expensive runs. It is shown by src/web/pages/spend.ts on the board and the Subscriptions page, and returned by the MCP usage read.
  • Board: the crew's credentials, with platform (env) first, are the headline numbers. Subscriptions that cover no repos sit in their own read-only group with their own window stats and their scope shown, so they don't read as idle crew capacity.
  • Merge with main: the forge.json conflict came from both sides adding test files to the check list. The check now runs main's list plus test/credentials.test.ts.

Things to look at:

  • Migration 40 rebuilds the usage table, because SQLite can't widen a CHECK in place. It is the riskiest part of the change, so it deserves the closest review.
  • No "person only" flag was added: the owner's later note replaced it with scopes, and an empty scope gives the same result.
  • No page was added for editing scopes. Grants are set where they already were.

Tests: the new test/credentials.test.ts covers:

  • a run on the platform token showing up under platform (env), with totals moving mid-run;
  • a subscription with an empty or non-matching scope never being picked;
  • the breakdown matching a hand-calculated total, with the most expensive runs first;
  • the board's grouping.

After the merge, the full check ran 618 tests with 1 failure: checks > when a slot frees, the newest of several queued checks runs first. This branch doesn't change checks code or that test. The test passed on all three reruns of test/checks.test.ts on its own, so it looks like a timing failure under load, but the forge check has not re-run green yet.

To try it: open the preview's board and /subscriptions, start a crew run and watch the platform (env) window and the breakdown update while it runs.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("checks > when a slot frees, the newest of several queued checks runs first") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs