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

The forge watches its own use: every page, fragment, route and tool counted, a usage map, and what nobody uses is proposed for the drop #1355

Closed opened this in answer to
Closed without merging

The forge now counts every request it answers, with a usage map at /usage, GET /api/v1/usage and an MCP usage tool. Counting, rollup, map and sentinel proposals are tested; the HTTP-served paths are not run here, and the explorer metrics (P2) and SSH counting are not done.

Notes

stopped closed without shipping deploy 162890e

opened this

The forge now counts every request it answers, with a usage map at /usage, GET /api/v1/usage and an MCP usage tool. Counting, rollup, map and sentinel proposals are tested; the HTTP-served paths are not run here, and the explorer metrics (P2) and SSH counting are not done.

tsc is clean, and test/hits.test.ts and check-list pass here. The suites that bind a unix socket (mcp, app, accounts, reserved-names, usage, migrate) can't run in this sandbox, so the forge's check is their first run. That includes the usage entry I added to the tool list in test/mcp.test.ts.

What changed

  • Counting: each answer is counted once after it is answered, by route pattern, method, status, role, surface and flag variant. No path, id, query, body or person is stored. Health checks and static assets are not counted. Router.match now returns its pattern for this.
  • Storage: counts are batched in memory and written in one transaction. Migration 73 adds hit_hour and hit_day, and whole past days roll up into hit_day on boot and hourly.
  • Reading it: /usage has tabs for pages, fragments, tools, settings and API, plus a "never used" list. Lines show 7, 30 and 90 day counts, last use, role breakdown and trend. The API route and the MCP tool are admin-only; others get a 404, or forbidden over MCP. /usage is now a reserved name.
  • Sentinel: src/crew/sentinel.ts is new, because none existed. dropProposals proposes a drop for anything no person used in 30 days, quoting the numbers. It proposes nothing until the forge has counted for 30 days, and agent calls don't keep a thing alive.

Choices

  • Naming: the new modules are core/hits.ts and actions/hits.ts, not usage.ts, because core/usage.ts and actions/usage.ts already hold the crew's spend ledger.
  • Roles: with no repo context, owner means the viewer is the user named in the path. A token with ro scope counts as reader, and a session or rw token as writer.

Left out

  • SSH commands are not counted.
  • The flag variant is always empty, since there are no flags yet.
  • The drop proposals are not filed as asks at the plan-approval door yet. They are only returned by dropProposals.
  • The explorer's real metrics (opens, previews looked at, tells, by week) don't read this table yet.

To try it, sign in as an admin and open /usage, or call GET /api/v1/usage with an admin token.

🤖 Generated with Claude Code

Closes #1136

commented

I merged main into this branch to clear the conflict in src/core/schema.ts, and pushed. I didn't wait for the full bun test run; test/hits.test.ts and the two schema tests pass (22 pass, 0 fail).

What conflicted: main took migration 73 for oauth_code (#971, MCP OAuth authorization codes). My hit_hour and hit_day tables (#1136) also claimed 73.

Resolution: oauth_code keeps 73 and the usage tables move to 74. Their definitions are otherwise unchanged. Nothing else conflicted. scripts/gate.ts and src/http/server.ts merged automatically, and I didn't open them to check the result.

What to look at: the migration order at the end of the list in src/core/schema.ts. Anything that references migration number 73 for the usage tables would now be wrong.

Left out: nothing new in this push; the feature itself is as described in #1136.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("a crew run's line, and who may read it > each run is attributed to the account it ran on, the app, the agent and the issue") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs