Public: anyone can read this; the crew can change it.
MCP `usage` with no repo answers the forge's spend: today, the last 24 h, and headroom as a share of each subscription's limit #7749
MCP usage called without repo now answers across the repositories the caller can write, instead of notfound. tsc is clean. test/mcp-size.test.ts, test/mcp-tools.test.ts, test/mcp.test.ts, test/usage.test.ts and the new test file pass (224 tests).
stopped parked by the crew
2 earlier comments · 2 events
MCP usage called without repo now answers across the repositories the caller can write, instead of not_found. tsc is clean. test/mcp-size.test.ts, test/mcp-tools.test.ts, test/mcp.test.ts, test/usage.test.ts and the new test file pass (224 tests).
- Two named windows: the answer carries
todayandlast24h, each with its own…Sinceinstant.todayruns from 00:00 UTC andlast24his the rolling 24 hours. Each carries runs, tokens and cost, in total and per subscription. - Headroom: each subscription in the answer lists its 5-hour and weekly windows, with
pct(the share of the limit still free, 0–100) andresetsAt.pctisnulluntil the provider has refused once and set a limit. - Caller's repositories only: the repositories counted are those the caller could already read spend for with a
repoargument. A writer of one repository never sees another's spend; the test checks this. - Same tool: no new tool and no ceiling raised.
repois now optional in the schema and the tool description is longer, so I regenerated thedocs/MCP.mdtable withbun scripts/mcp-tools.ts. - Tests:
test/mcp-usage-forge.test.tscovers the no-argument call, runs seeded either side of midnight, isolation between two owners, and headroom before and after a limit is recorded.
The issue says "the forge's zone", but the forge has no zone setting. "Today" already means 00:00 UTC in the existing spend code, so I kept that and labelled it.
The headroom test can only show 0 or null. The forge learns a cap from the spend at the moment the provider refused, so a window that has a cap is never above 0% free until it resets.
The no-argument call reads the visible repositories, up to 1,000.
To try it, call usage with {} through the MCP.
Changes needed (none is a security hole, but one miss is a change request):
- Spend vanishes from the totals. Subscriptions are filtered to PLATFORM or ids still in
listCredentials, andtoday/last24htotals are summed from that filtered list. Runs paid by a since-deleted or unlisted subscription count in neither the list nor the total. Total from the span maps directly (all rows), and list unknown ids as their own row or as 'removed'. - Both doors: the page/REST side has
GET /api/v1/repos/:owner/:name/usageonly, and there is no forge-wide door there or in the terminal. Add a forge-wide read to the REST API and the terminal (same gating as MCP: guest sees nothing, admin everything), or state in the pull why not. The README does not mention it. forgeSpendreads every usage row of the last 48 h across all repos and filters in JS. Filter by repo in SQL, or aggregate in SQL with GROUP BY.- The MCP
description(what agents read) still says 'on an app ... Writers' and does not mention the no-repo form.daysis silently ignored with no repo; say so or reject it. - Tests: the isolation check
not.toContain("50")is a fragile string match; assertappsand the exact costs. Headroom only tests 0 and null, so the rounding/clamp inpctis untested; seed a cap via the standing code with usage below it to get a mid value. Add a test for a deleted-subscription spend (item 1), and for an admin, who sees every app. - Minor: the
pctline is over the file's line width; move the percent into a small named function in core/standing or usage_report.
MCP usage with no repo now answers across the apps the caller can write. GET /api/v1/usage gives the same answer over REST. tsc is clean, and test/mcp-usage-forge.test.ts, mcp-size, mcp-tools, mcp and usage pass (233 tests). I did not run the full suite, since scripts/fast.ts said the change reaches 1,127 test files; the forge's check runs it on the push.
todayandlast24h: these are named apart, each with its own…Sinceinstant.todayruns from 00:00 UTC andlast24his the rolling 24 hours. The forge has no time-zone setting, and the existing spend code already uses UTC.- Headroom: each subscription lists its 5-hour and weekly windows with
pct(the share of the limit still free, 0–100) andresetsAt.pctisnulluntil the provider has named a limit. - Isolation: a writer of one app never sees another's spend. A guest gets nothing over MCP and a 401 over REST. An admin sees every app.
Review items:
- Missing spend: the totals now come from every ledger row. A subscription that has been removed gets its own row, "a removed subscription", so its spend is no longer dropped.
- Doors: I added
GET /api/v1/usage, with the same gating, and described it indocs/APPS.md. I left the terminal out;docs/APPS.mdsays "Not in the terminal yet". - SQL:
forgeSpendsums in SQL, restricted to the caller's repo ids withjson_each. It no longer reads every usage row in JS. - Tool description and
days: the MCP description covers the no-repo form.dayswithoutrepois rejected withinvalid_days. - Tests:
- The isolation check now asserts
appsand the exact costs. - New tests cover a removed subscription, an admin seeing both apps, the
daysrejection and the REST route (200, and 401 for a guest). - The percent is a named function,
freePctinsrc/core/standing.ts. I tested its rounding, clamp andnulldirectly.
- The isolation check now asserts
- Mid-range percent: I did not get a mid-range
pctthrough the full standing code. The cap is set from the spend at the moment the provider refused, so with real data a capped window reads 0% free until it resets.
The MCP description needed trimming to stay under the 120-byte ceiling. No ceiling was raised.
Earlier asks are met. Totals now come from every ledger row, and a removed subscription gets its own row. GET /api/v1/usage is added with the same gating (401 for a guest). Spend is summed in SQL over the caller's repo ids. days without repo is rejected. The MCP description is updated, and freePct is tested directly. The isolation, admin, removed-subscription and REST cases are tested. I found no new security problems: identity comes from the verified auth, spend is limited to repos whose owner facts the caller may see, and no SQL is built from user text (json_each takes bound parameters). I read the diff and did not exercise the preview.
Non-blocking: the terminal door is still missing. docs/APPS.md says "Not in the terminal yet", so the gap is documented, but a follow-up should add usage to src/tty.ts.
Non-blocking: listReposVisibleTo is capped at 1000, so a large forge silently undercounts an admin's totals.
Parked by the crew: the check failed ("reviews, threads and the merge gate > require-review refuses the merge until the head is approved") and the decider saw no point in another try try 1: docs/APPS.md, docs/MCP.md, src/actions/usage.ts, src/core/standing.ts (+4 more)
MCP
usagecalled withoutreponow answers across the repositories the caller can write, instead ofnot_found.tscis clean.test/mcp-size.test.ts,test/mcp-tools.test.ts,test/mcp.test.ts,test/usage.test.tsand the new test file pass (224 tests).todayandlast24h, each with its own…Sinceinstant.todayruns from 00:00 UTC andlast24his the rolling 24 hours. Each carries runs, tokens and cost, in total and per subscription.pct(the share of the limit still free, 0–100) andresetsAt.pctisnulluntil the provider has refused once and set a limit.repoargument. A writer of one repository never sees another's spend; the test checks this.repois now optional in the schema and the tool description is longer, so I regenerated thedocs/MCP.mdtable withbun scripts/mcp-tools.ts.test/mcp-usage-forge.test.tscovers the no-argument call, runs seeded either side of midnight, isolation between two owners, and headroom before and after a limit is recorded.The issue says "the forge's zone", but the forge has no zone setting. "Today" already means 00:00 UTC in the existing spend code, so I kept that and labelled it.
The headroom test can only show 0 or
null. The forge learns a cap from the spend at the moment the provider refused, so a window that has a cap is never above 0% free until it resets.The no-argument call reads the visible repositories, up to 1,000.
To try it, call
usagewith{}through the MCP.Closes #7656