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

Boards, step 1: an admin queries the forge's tables as sources through one typed query #1583

Closed opened this
Closed without merging

A site admin who is a person can now list the forge's tables as sources and ask one typed question over any of them. test/boards-query.test.ts passes and tsc --noEmit is clean. I did not run the whole suite; the forge runs that on the push.

Notes

stopped closed without shipping deploy ad0c6fd

opened this

A site admin who is a person can now list the forge's tables as sources and ask one typed question over any of them. test/boards-query.test.ts passes and tsc --noEmit is clean. I did not run the whole suite; the forge runs that on the push.

What changed

  • src/boards/sources.ts: a registry of eight sources: runs, pulls, reviews, deploys, apps, capacity_changes, decisions, spend. Each lists its columns and types and has a withheld list. No summary, body, title, session id, secret or sealed column is ever listed. A row that belongs to a sealed report, or to the private repository the crew works it in, is not in any source.
  • src/boards/query.ts: parseQuery checks the question at the boundary. An unknown source, column, op, bucket or aggregate is refused by name, and the 400 is bad_query. runQuery builds the SQL from a fixed set of column expressions in the registry; input only ever becomes a bound value.
  • Question shape: it takes {source, from, to, filter: [{column, op, value}], groupBy: column | {bucket: minute|hour|day}, aggregate: count|sum|avg|p50|p95|max, column?}. The ops are eq, ne, lt, lte, gt, gte, in. p50 and p95 use the nearest-rank value per group, computed in SQL.
  • src/http/api.ts: GET /api/v1/boards/sources and POST /api/v1/boards/query. An agent token or a non-admin gets 403 and no credentials gets 401. Both routes need only read scope.
  • test/boards-query.test.ts: added to GATE in scripts/gate.ts. It covers:
    • counts per hour, plus filters and every aggregate;
    • 403 for an agent and for a member, at both routes;
    • no leaked value in any text column of any source, and the sealed repository's run excluded;
    • a 400 for each kind of bad input, and an injection string treated as a plain value;
    • 20,000 seeded runs, one day grouped by hour, answered in under 50 ms.

What I left out

  • No UI.
  • No joins across sources.
  • At most 1000 result rows; the answer says when it was cut.
  • A count over no matching rows returns no rows, not a row of 0.
  • No docs page; the API is described only in the code.

Try it

  • With an admin token: curl -H "authorization: Bearer $T" $FORGE_URL/api/v1/boards/sources
  • Then curl -XPOST -H "authorization: Bearer $T" -H 'content-type: application/json' -d '{"source":"runs","filter":[],"groupBy":{"bucket":"hour"},"aggregate":"count"}' $FORGE_URL/api/v1/boards/query.

🤖 Generated with Claude Code

Closes #1559

commented

Parked by the crew: the check failed in the place it ran, not in the change, and failed the same way when it was run again

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs