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

The terminal's data screen runs a query the way the page and the MCP do #13117

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13109-the-terminal-s-data-screen-runs-a-query → main 2 commits fork 1 thread · 1 unresolved

  • Merged. scout/13109-the-terminal-s-data-screen-runs-a-query was merged into main as bd28fbb.

Review

Sign in to review this change.
2 files changed +17 −3
docs/features/data-browser.md +1 −3
@@ -14,12 +14,10 @@ Limits on work: `query` runs at most 2 workers at once (a third is told it is bu
1414
1515 Terminal: `src/tui/screens/data.ts` is a tree (repos → apps → environments → files → tables → first 50 rows; `src/data/tree.ts` builds it), offered by `maySeeData`. Keys: `j`/`k` move, `l`/Enter open, `h` close or go up, `/` filter the open lines, `:` a read-only SQL prompt against the file under the cursor (same caps; a write is refused), `y` yank a row as JSON (OSC 52), `n`/`p` next/previous page of 50 rows on a table or row, `r` read the files afresh. The tree is built once and rebuilt only when a node opens, a page turns or `r` is pressed; the files are read once per open node. Shell: `forge data <app> [env] [sql] [--json]` (docs/CLI.md) calls the MCP tool.
1616
17 Not done: a filter that reaches into closed lines, SQL on the web page. SQL on any door (web, terminal, `forge data` and the MCP `data` tool) is 20 runs a minute per person (`src/data/sql_window.ts`); beyond that it says when to retry.
17 Not done: a filter that reaches into closed lines. SQL on any door (web, terminal, `forge data` and the MCP `data` tool) is 20 runs a minute per person (`src/data/sql_window.ts`); beyond that it says when to retry.
1818
1919 API and MCP by repository (`data/repo_scope.ts`, `http/api/data.ts`): `GET /api/v1/repos/:o/:n/data` (databases as `{ env, file }`), `…/data/:env/:file/tables`, `…/rows?table=&page=`, `POST …/query {sql}`; MCP `data` with `{ repo, env?, file?, table?, sql? }` answers the same. Only writers of the repository (and admins) see anything; everyone else gets a 404 (an error from the tool). Same masking, read-only SQL and 1,000-row cap as the web; SQL shares the per-person 20 a minute (`sql_window.ts`), and past it the API answers 429 with `retry-after`, the tool an error. `page` is a whole number from 0 to 1000.
2020
21 Not done: SQL in the terminal (SQL is on the web page and MCP).
22
2321 ## On the web (#7580)
2422
2523 Three doors, one body (`src/web/pages/data_view.ts`): `/data` (every file you may see), `/admin/data` (the forge's own database, admins; the Forge data button on `/data`) and `/:owner/:name/data` (an app's Data tab for its writers: environments → files → tables → rows; a reader gets the 404). Rows sort by header (`sort`, `dir`), filter by text on one column or all (`q`, `col`), JSON cells are pretty-printed, and a copy button per row puts it on the clipboard as JSON. Sealed columns show `••••••` and cannot be sorted or searched. The SQL box is a GET form (`sql`, capped at 4,000 characters), so a query is an address to share; it shows the rows and the elapsed ms. The sorted column carries `aria-sort` and a muted arrow from CSS; a wide grid scrolls sideways only. Not done: saved queries, export, editing rows.
test/tui-data.test.ts +16
@@ -241,6 +241,22 @@ test("a control byte in a cell cannot reach the terminal from a result, and y on
241241 tui.stop?.();
242242 });
243243
244 test(": caps rows as the page does and says so; a bad query is one plain sentence", async () => {
245 const { tui } = await fresh("alice");
246 await open_(tui, 4);
247 await askSql(tui, "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM n WHERE i < 1500) SELECT i FROM n");
248 expect(tui.screen.toText()).toContain("1000 rows (cut)");
249 press(tui, "esc");
250 await askSql(tui, "SELECT nope FROM users");
251 const text = tui.screen.toText();
252 expect(text).toContain("no such column: nope");
253 expect(text).not.toContain("Result");
outdated

Assert the actual error sentence here (e.g. toContain the query error text, not toContain('Result')). toContain("Data") is the screen title and passes regardless of what the error says.

254 expect(text).not.toMatch(/\bat \S+ \(|Error:/);
255 const sentence = text.split("\n").find((l) => l.includes("no such column"))!.trim();
256 expect(sentence).toBe("no such column: nope");
257 tui.stop?.();
258 });
259
244260 test(": is refused once the person's SQL budget is spent", async () => {
245261 const { tui, session } = await (async () => {
246262 const { app: tui, session } = open("alice");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs