Public: anyone can read this; the crew can change it.
An imported session's page has a red Delete that asks for its title typed #18423
Merged 1h 22m ago, live in production
scout/forge:scout/18389-an-imported-session-s-page-has-a-red-del → main 0 commits fork 4 threads · 4 unresolved
4 files
changed +46
−6
docs/design/areas/traces.md +2
| @@ -5,3 +5,5 @@ | ||
| 5 | 5 | `/traces` (`src/web/pages/traces.ts`), the list. Page-local classes, drawn from existing tokens: `.traces-search` (the search form: the input grows, the button and the Filters disclosure wrap under it on a phone) and `.traces-facets` (the facet selects and dates, an auto-fit grid of `.field`s). `#traces-list` only ellipsises a row's title and meta to one line each. A removable active filter is the shared `.badge` with the `x` icon inside its link. |
| 6 | 6 | |
| 7 | 7 | `/traces/:id/compare/:other` (`src/web/pages/trace_compare.ts`) is one `table` of the shared table class, A and B as column heads and B − A last; `/traces/shared/:token` (`src/web/pages/trace_share.ts`) is the same `details` rows with the raw lines inline and no script. No new classes. |
| 8 | ||
| 9 | `/traces/:id` of an imported session (`src/web/pages/trace_imported.ts`) holds its Delete in `.trace-delete`, a `details` closed on first paint (so nothing shifts) whose red summary opens a form: what is lost, the title to type, and a Delete button the browser will not submit until the input's `pattern` (the title, escaped) matches. It uses the shared `.stack`, no new class or style. A crew run's or Talk turn's page has no such control. |
docs/features/traces.md +1 −1
| @@ -58,7 +58,7 @@ For Codex, point the same command at a rollout: `--data-binary @"$(ls -t ~/.code | ||
| 58 | 58 | |
| 59 | 59 | A new source is one file implementing `ImportAdapter` (`src/trace/import_adapter.ts`, see `import_claude_code.ts`) and one line in `ADAPTERS`; Codex rollouts are taken the same way (`import_codex.ts`). |
| 60 | 60 | |
| 61 | `DELETE /api/v1/traces/<id>` (#18388) deletes one imported session, with `{ "confirm": "<the session's title>" }` as its body (at most 4 KiB; `traceDelete` in `src/kernel/body_caps.ts`). Nothing is removed unless the title is sent exactly: a wrong or missing one is a 422 (`name_mismatch`) and the file and rows stay. Only the importer may: another person's or an unknown id is a 404, a crew run or Talk turn is a 403 (`record_kept`, its record is kept), a session caller's cross-origin request is a 403, and a session with a live share link is a 409 (`shared`: stop sharing first). A right name removes `traces/imported/<id>.jsonl.gz`, the index row and its touched tools and files (`deleteImported` in `src/trace/import.ts`), frees the quota, and answers `{ removed, title, bytes }`. The red Delete on the session's page (the title typed exactly, a plain click does nothing) and `X` in the terminal's Traces list do the same and answer a receipt (#18359); on a shared session they say to stop sharing first, so deleting never leaves a link that a re-import of the same session would bring back. Not yet: an undo. | |
| 61 | `DELETE /api/v1/traces/<id>` (#18388) deletes one imported session, with `{ "confirm": "<the session's title>" }` as its body (at most 4 KiB; `traceDelete` in `src/kernel/body_caps.ts`). Nothing is removed unless the title is sent exactly: a wrong or missing one is a 422 (`name_mismatch`) and the file and rows stay. Only the importer may: another person's or an unknown id is a 404, a crew run or Talk turn is a 403 (`record_kept`, its record is kept), a session caller's cross-origin request is a 403, and a session with a live share link is a 409 (`shared`: stop sharing first). A right name removes `traces/imported/<id>.jsonl.gz`, the index row and its touched tools and files (`deleteImported` in `src/trace/import.ts`), frees the quota, and answers `{ removed, title, bytes }`. The red Delete on the session's page (a closed `details` that says what is lost and that a live share link must be stopped first; the title typed exactly, the browser refusing to submit until the input's `pattern` matches the title, which holds without CSS or script, and the server checking the title again) and `X` in the terminal's Traces list do the same and answer a receipt (#18359); on a shared session they say to stop sharing first, so deleting never leaves a link that a re-import of the same session would bring back. Not yet: an undo. | |
| 62 | 62 | |
| 63 | 63 | `/traces/<id>` of an imported trace (#18357) is the same tree and strip a crew run has, read from the stored file (`src/trace/imported_read.ts`, `src/web/pages/trace_imported.ts`), with `#step-N` permalinks and each step's raw lines (the file's lines that name it) on demand at `/traces/<id>/steps/<n>`. Only the importer reads it; anyone else gets the not-found an unknown id gets. Each step line shows the tokens its file held for it (`5 in, 7 cached, 9 out`; a reply split across records is counted once) and the total is their sum; a session holds no cost, and sometimes no tokens: the page says "not recorded in this file" rather than zero. Steps are capped at 20,000. `GET /api/v1/traces/<id>` answers the same tree for an imported id. |
| 64 | 64 | ## One trace as a tree (#18022) |
src/web/pages/trace_imported.ts +15 −5
| @@ -28,6 +28,12 @@ export function importedRowOf(ctx: Ctx): TraceRow | undefined { | ||
| 28 | 28 | return row?.kind === "imported" ? row : undefined; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | /** | |
| 32 | * A regular expression matching exactly `title`, for the input's pattern: the button stays inert | |
| 33 | * until it does. | |
| 34 | */ | |
| 35 | const titlePattern = (title: string): string => title.replace(/[\\^$.*+?()[\]{}|/]/g, "\\$&"); | |
| 36 | ||
| 31 | 37 | export function importedTracePage(ctx: Ctx, row: TraceRow): Response { |
| 32 | 38 | const read = parseImported(ctx.app, row); |
| 33 | 39 | if (read === undefined) return notFoundPage(ctx); |
| @@ -48,11 +54,15 @@ export function importedTracePage(ctx: Ctx, row: TraceRow): Response { | ||
| 48 | 54 | <div><dt>Cost</dt><dd id="trace-cost">${row.costUsd > 0 ? `$${row.costUsd.toFixed(2)}` : "not recorded in this file"}</dd></div> |
| 49 | 55 | </dl> |
| 50 | 56 | <nav class="bar small" id="trace-links" aria-label="Where this trace is"><a href="/traces">All traces</a></nav> |
| 51 | <form method="post" class="bar small" id="trace-delete" action="${base}/delete" autocomplete="off"> | |
| 52 | <label for="trace-delete-name" class="muted">Delete this session for good: type its title exactly to confirm.</label> | |
| 53 | <input class="input" id="trace-delete-name" name="name" required autocomplete="off" spellcheck="false" placeholder="${row.title}" /> | |
| 54 | <button type="submit" class="btn" data-variant="danger">Delete</button> | |
| 55 | </form> | |
| 57 | <details class="trace-delete" id="trace-delete"> | |
| 58 | <summary class="btn small" data-variant="danger">Delete this session</summary> | |
| 59 | <form method="post" class="stack" action="${base}/delete" autocomplete="off"> | |
| 60 | <p class="small muted">Deleting removes this session's file and its steps for good; only importing the original file again brings it back. A live share link must be stopped first.</p> | |
| 61 | <label for="trace-delete-name" class="small">Type its title exactly to confirm: <b>${row.title}</b></label> | |
| 62 | <input class="input" id="trace-delete-name" name="name" required autocomplete="off" spellcheck="false" pattern="${titlePattern(row.title)}" title="The session's title, exactly" /> | |
| 63 | <button type="submit" class="btn" data-variant="danger">Delete</button> | |
| 64 | </form> | |
| 65 | </details> | |
| 56 | 66 | ${shared === undefined ? null : html`<form method="post" class="bar small" id="trace-share" action="${base}/${shared ? "unshare" : "share"}"> |
| 57 | 67 | <span class="muted">${shared ? "A share link is live: anyone holding it reads this session, secrets redacted." : "Not shared. A link lets anyone who holds it read this session. The forge hides the credentials it knows, but a file can hold others, so share only what you have read."}</span> |
| 58 | 68 | <button type="submit">${shared ? "Stop sharing" : "Make a share link"}</button> |
test/trace-delete.test.ts +28
| @@ -119,3 +119,31 @@ test("the page's form removes it too and says what went", async () => { | ||
| 119 | 119 | expect(res.headers.get("location")).toContain("/traces"); |
| 120 | 120 | expect(await list(alice)).not.toContain(again); |
| 121 | 121 | }); |
| 122 | ||
| 123 | test("the page's control names what is lost, keeps the button inert by a pattern of the exact title, and a crew run's page has none", async () => { | |
| 124 | const sent = await api("/api/v1/traces/import", alice, { method: "POST", body: SESSION.replace("fix the login bug", "fix the (login) bug.") }); | |
| 125 | const again = ((await sent.json()) as { id: string }).id; | |
| 126 | const page = await (await fetch(`${servers.url}/traces/${again}`, { headers: { cookie: aliceCookie } })).text(); | |
| 127 | expect(page).toContain('id="trace-delete"'); | |
| 128 | expect(page).toContain("must be stopped first"); | |
| 129 | expect(page).toContain('pattern="fix the \\(login\\) bug\\."'); | |
| 130 | const crew = await fetch(`${servers.url}/traces/run1`, { headers: { cookie: aliceCookie } }); | |
| 131 | expect(await crew.text()).not.toContain('id="trace-delete"'); | |
| 132 | const typed = await fetch(`${servers.url}/traces/${again}/delete`, { method: "POST", redirect: "manual", headers: { cookie: aliceCookie, "content-type": "application/x-www-form-urlencoded", origin: servers.url }, body: new URLSearchParams({ name: "fix the (login) bug." }) }); | |
| 133 | expect(typed.status).toBe(303); | |
| 134 | expect(await list(alice)).not.toContain(again); | |
| 135 | }); | |
| 136 | ||
| 137 | test("the page's own form: a wrong name keeps the session and says why, a cross-origin post is 403", async () => { | |
| 138 | const sent = await api("/api/v1/traces/import", alice, { method: "POST", body: SESSION.replace("fix the login bug", "keep me") }); | |
| 139 | const keep = ((await sent.json()) as { id: string }).id; | |
| 140 | const post = (name: string, origin: string) => fetch(`${servers.url}/traces/${keep}/delete`, { method: "POST", redirect: "manual", headers: { cookie: aliceCookie, "content-type": "application/x-www-form-urlencoded", origin }, body: new URLSearchParams({ name }) }); | |
| 141 | const wrong = await post("keep", servers.url); | |
| 142 | expect(wrong.status).toBe(303); | |
| 143 | expect(wrong.headers.get("location")).toBe(`/traces/${keep}`); | |
| 144 | const shown = await fetch(`${servers.url}/traces/${keep}`, { headers: { cookie: aliceCookie, ...(wrong.headers.get("set-cookie") ? { cookie: `${aliceCookie}; ${wrong.headers.get("set-cookie")!.split(";")[0]}` } : {}) } }); | |
| 145 | expect(await shown.text()).toContain("That is not the session's title: nothing was removed."); | |
| 146 | expect(await list(alice)).toContain(keep); | |
| 147 | expect((await post("keep me", "https://evil.example")).status).toBe(403); | |
| 148 | expect(await list(alice)).toContain(keep); | |
| 149 | }); |
new above
offline
Principle 3: use the space tokens, not a raw .5rem for the margin or a fallback literal in var().