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

An imported session's steps carry their tokens and the page shows them, where the file holds them #18372

opened this

Merged 4h 1m ago, live in production

An imported session's trace page now shows tokens on each model step line, and the total is the sum of those steps. The new tests pass, and so do the existing trace and imported-page tests I ran. bun x tsc --noEmit and the design lint came back clean.

Notes

opened this

An imported session's trace page now shows tokens on each model step line, and the total is the sum of those steps. The new tests pass, and so do the existing trace and imported-page tests I ran. bun x tsc --noEmit and the design lint came back clean. I did not run the full suite, and I haven't tried the page on a preview. After the last push the gate still prints a "look pages" warning for src/web/pages/trace.ts. It asks for a "Looks:" or "No look:" line, and I didn't add one, so a reviewer decides.

  • Readers: the Claude Code and Codex readers already read per-message usage onto each step. A reply split across several records is counted once. A file with no usage, or with a malformed value, still gives 0 and "not recorded in this file".
  • API: GET /api/v1/traces/<id> for an imported id already answered per-step tokens and the totals, so there is no change there.
  • Page: stepNode in src/web/pages/trace.ts adds one inline span per step that has tokens, for example 5 in, 7 cached, 9 out. It uses no new script or CSS and sits in the existing summary line.
  • Raw-step text: the text of a step's raw-lines route (stepLine in src/trace/read.ts) appends the same figures. Crew runs hold no per-step tokens, so their pages are unchanged.
  • Docs: docs/features/traces.md no longer lists tokens per step under "Not yet" for imports.
  • Tests: the new test/trace-imported-tokens.test.ts has fixtures for a Claude Code session with usage (per-step and total figures) and one without. It also covers malformed usage on both readers, a Codex token_count landing on the reply before it, the page, and the API.
  • Terminal: forge trace already printed per-step tokens and totals, and the terminal screens use the shared stepLine. Imported traces have no screen under src/tui/ yet, so the commit says "No door".
  • Not done: cost per step or per import stays "not recorded in this file", since prices change and I won't guess.
  • Truncation: the total comes from the stored row, so for a session longer than 20,000 steps it can exceed the visible steps. The page already says it is cut.
  • Reuse: I reused stepTime, stepLine, the existing token fields and totalsOf. The only new function is the small stepTokens.

Try: open /traces/<id> for an imported session whose file has usage.

[{"go":"/traces/<id of an imported Claude Code session with usage>","look":"each model step line, and the Tokens fact above the tree","expect":"a step shows `N in, N cached, N out` beside its time; the Tokens fact is the sum; a session without usage still reads `not recorded in this file`"}]

Closes #18367

3 earlier comments · 1 event
commented

An imported session's trace page now shows tokens on each model step line, and the total is the sum of those steps. The new tests pass, and so do the existing trace and imported-page tests I ran. bun x tsc --noEmit and the design lint came back clean. I did not run the full suite, and I haven't tried the page on a preview. After the last push the gate still prints a "look pages" warning for src/web/pages/trace.ts. It asks for a "Looks:" or "No look:" line, and I didn't add one, so a reviewer decides.

  • Readers: the Claude Code and Codex readers already read per-message usage onto each step. A reply split across several records is counted once. A file with no usage, or with a malformed value, still gives 0 and "not recorded in this file".
  • API: GET /api/v1/traces/<id> for an imported id already answered per-step tokens and the totals, so there is no change there.
  • Page: stepNode in src/web/pages/trace.ts adds one inline span per step that has tokens, for example 5 in, 7 cached, 9 out. It uses no new script or CSS and sits in the existing summary line.
  • Raw-step text: the text of a step's raw-lines route (stepLine in src/trace/read.ts) appends the same figures. Crew runs hold no per-step tokens, so their pages are unchanged.
  • Docs: docs/features/traces.md no longer lists tokens per step under "Not yet" for imports.
  • Tests: the new test/trace-imported-tokens.test.ts has fixtures for a Claude Code session with usage (per-step and total figures) and one without. It also covers malformed usage on both readers, a Codex token_count landing on the reply before it, the page, and the API.
  • Terminal: forge trace already printed per-step tokens and totals, and the terminal screens use the shared stepLine. Imported traces have no screen under src/tui/ yet, so the commit says "No door".
  • Not done: cost per step or per import stays "not recorded in this file", since prices change and I won't guess.
  • Truncation: the total comes from the stored row, so for a session longer than 20,000 steps it can exceed the visible steps. The page already says it is cut.
  • Reuse: I reused stepTime, stepLine, the existing token fields and totalsOf. The only new function is the small stepTokens.

Try: open /traces/<id> for an imported session whose file has usage.

[{"go":"/traces/<id of an imported Claude Code session with usage>","look":"each model step line, and the Tokens fact above the tree","expect":"a step shows `N in, N cached, N out` beside its time; the Tokens fact is the sum; a session without usage still reads `not recorded in this file`"}]
commented

<!-- look-pages e1473681fc88 --> Look pages for e147368, from the gate:

  • look pages (none): this pull changes src/web/pages/trace.ts but the forge could not trace the route of /, /admin/telemetry, /explore and 28 more (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

<!-- look-pages 3b4af8de01ed --> Look pages for 3b4af8d, from the gate:

  • look pages (none): "Looks: /traces/:id" is not a page of app.looks in forge.json; this pull changes src/web/pages/trace.ts but the forge could not trace the route of /, /admin/telemetry, /explore and 28 more (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
the crew's run was interrupted: restart, resumes on the next pass — cancelled
commented

An imported session's steps now show their tokens on /traces/<id> and in the text step line, where the file holds them. Replies split across records count once, and malformed values give 0. Only server-built numbers are rendered, so nothing needs escaping.

Feedback addressed: the look-pages gate refused Looks: /traces/:id because that route is not a page of app.looks in forge.json. The last commit, 2345ec6e6, replaces it with No look: …. It says an imported session's trace needs an import by a signed-in owner, and no app.looks page has one. test/trace-imported-tokens.test.ts reads the page instead.

Checks: that test file passes, 6 tests, and scripts/gate.ts runs clean. I didn't re-run bun x tsc --noEmit or the other three tests the check names (both doors, duplicate import, module-level state, first-view budget). The change adds no imports, no module-level state and no new page weight beyond one inline span per step.

Tooling: the clone I was given went missing mid-session. The working tree is now at 18367.broken-1796542835685, with nothing uncommitted and origin/scout/18367-an-imported-session-s-steps-carry-their already at 2345ec6e6, so I didn't push again. I ran those checks from that directory.

Left out: I did not add CSS for trace-tokens. The sentinel noted it has no rule behind it and is only a hook, and a style would be new design surface. Imported traces have no terminal screen under src/tui/, and forge trace already prints per-step tokens, so there is no terminal side to add.

Try it: import a Claude Code session whose file has usage, open /traces/<id>, and each model step shows its tokens.

Sign in to join this conversation.

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

Keyboard shortcuts

Docs