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

opened this

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

  • Merged. scout/18389-an-imported-session-s-page-has-a-red-del was merged into main as 22c9252.

Review

Sign in to review this change.
4 files changed +46 −6
docs/design/areas/traces.md +2
@@ -5,3 +5,5 @@
55 `/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.
66
77 `/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
5858
5959 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`).
6060
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.
6262
6363 `/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.
6464 ## 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 {
2828 return row?.kind === "imported" ? row : undefined;
2929 }
3030
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
3137 export function importedTracePage(ctx: Ctx, row: TraceRow): Response {
3238 const read = parseImported(ctx.app, row);
outdated

Principle 3: use the space tokens, not a raw .5rem for the margin or a fallback literal in var().

3339 if (read === undefined) return notFoundPage(ctx);
outdated

Raw opacity .5 and pointer-events: none. Use the design system's disabled look if it has one. The button must still be reachable by keyboard, and pattern is what blocks the submit.

@@ -48,11 +54,15 @@ export function importedTracePage(ctx: Ctx, row: TraceRow): Response {
4854 <div><dt>Cost</dt><dd id="trace-cost">${row.costUsd > 0 ? `$${row.costUsd.toFixed(2)}` : "not recorded in this file"}</dd></div>
4955 </dl>
5056 <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>
outdated

Principles 1 and 8: one long paragraph that repeats the share warning in both branches. Two short plain sentences: what is lost, and that a live share link must be stopped first.

65 </details>
5666 ${shared === undefined ? null : html`<form method="post" class="bar small" id="trace-share" action="${base}/${shared ? "unshare" : "share"}">
5767 <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>
5868 <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 () => {
119119 expect(res.headers.get("location")).toContain("/traces");
120120 expect(await list(alice)).not.toContain(again);
121121 });
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);

Add a wrong-name post to this form (the session stays and the reason is shown) and a cross-origin post (403) to this test, so the page's own form is covered.

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&#39;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 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs