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

Traces 5c: the trace list and one trace read through MCP tools and a terminal screen compare #18183

opened this

Merged 4h 34m ago, live in production

The terminal Traces list can now mark two runs and open their comparison, and tests now show the MCP trace tool agreeing with the API compare route. The MCP list is not the same list as the API's, though. I didn't write a new traceslist, traceget or tracecompare tool.

Notes

opened this

The terminal Traces list can now mark two runs and open their comparison, and tests now show the MCP trace tool agreeing with the API compare route. The MCP list is not the same list as the API's, though. I didn't write a new traces_list, trace_get or trace_compare tool. The existing trace tool already had list, read and compare, and the issue says to prefer an action on an existing tool.

I ran test/trace-share.test.ts, test/traces-leak.test.ts, test/keymap-terminal.test.ts, test/mcp-size.test.ts and test/doorless.test.ts, plus tsc, and all pass. I didn't run bun scripts/similar.ts, and I reused nothing.

What changed

  • Marking and comparing: in the Traces screen (src/tui/screens/traces.ts), v marks the selected run, up to two (a third drops the oldest mark). d opens the two as the comparison the trace screen already draws.
  • Refusals: if two runs belong to different issues or repositories, d toasts "those two are not runs of one issue". With fewer than two marked, it toasts "mark two runs of one issue with v".
  • Key choice: Space is the terminal's leader key, and test/keymap-terminal.test.ts refuses it for marking, so I used v for marking and d for compare.
  • Tests: in test/trace-share.test.ts, MCP trace compare returns the same table, timeDiffMs and costDiffUsd as GET /api/v1/traces/compare, and read and list return rows. A second test marks two runs of one issue and opens the comparison, and shows two runs of different issues are refused.
  • Docs: docs/features/traces.md names the new keys.

Left out

  • The MCP list still lists one repository's recent agent runs. It does not take the page's filters (model, outcome, dates, person, search), so it is not the page's /traces list.
  • trace_get and trace_compare as separate tools: the existing trace tool's read and compare actions cover them, which also keeps mcp-size unchanged.
  • The test run data isn't in the trace index, so the MCP read and list are not checked against GET /api/v1/traces or GET /api/v1/traces/:id. That is a gap against the issue's "same data as the API".

gate.ts still prints a similarity note: my test helper in test/trace-share.test.ts looks like one in test/egress-default.test.ts. It didn't block the push, and I left both as they are.

Try: open Traces in the terminal palette, press v on two runs of one issue, then d.

No door: the MCP tool already existed; only tests were added there.

🤖 Generated with Claude Code

Closes #18085

2 earlier comments
commented

The terminal Traces list can now mark two runs and open their comparison, and tests now show the MCP trace tool agreeing with the API compare route. The MCP list is not the same list as the API's, though. I didn't write a new traces_list, trace_get or trace_compare tool. The existing trace tool already had list, read and compare, and the issue says to prefer an action on an existing tool.

I ran test/trace-share.test.ts, test/traces-leak.test.ts, test/keymap-terminal.test.ts, test/mcp-size.test.ts and test/doorless.test.ts, plus tsc, and all pass. I didn't run bun scripts/similar.ts, and I reused nothing.

What changed

  • Marking and comparing: in the Traces screen (src/tui/screens/traces.ts), v marks the selected run, up to two (a third drops the oldest mark). d opens the two as the comparison the trace screen already draws.
  • Refusals: if two runs belong to different issues or repositories, d toasts "those two are not runs of one issue". With fewer than two marked, it toasts "mark two runs of one issue with v".
  • Key choice: Space is the terminal's leader key, and test/keymap-terminal.test.ts refuses it for marking, so I used v for marking and d for compare.
  • Tests: in test/trace-share.test.ts, MCP trace compare returns the same table, timeDiffMs and costDiffUsd as GET /api/v1/traces/compare, and read and list return rows. A second test marks two runs of one issue and opens the comparison, and shows two runs of different issues are refused.
  • Docs: docs/features/traces.md names the new keys.

Left out

  • The MCP list still lists one repository's recent agent runs. It does not take the page's filters (model, outcome, dates, person, search), so it is not the page's /traces list.
  • trace_get and trace_compare as separate tools: the existing trace tool's read and compare actions cover them, which also keeps mcp-size unchanged.
  • The test run data isn't in the trace index, so the MCP read and list are not checked against GET /api/v1/traces or GET /api/v1/traces/:id. That is a gap against the issue's "same data as the API".

gate.ts still prints a similarity note: my test helper in test/trace-share.test.ts looks like one in test/egress-default.test.ts. It didn't block the push, and I left both as they are.

Try: open Traces in the terminal palette, press v on two runs of one issue, then d.

No door: the MCP tool already existed; only tests were added there.

🤖 Generated with Claude Code

commented

The MCP trace tool now calls the same readers as the page and the API. The terminal no longer loses a mark when a filter hides the run. The trace tests, the three check tests you named (unused exports, module state, job slices) and tsc pass. The gate is clean except two similar-code hints on the test helpers, which I merged into one helper. I did not run the full suite.

What changed

  • List: list now calls listTraces (src/trace/list.ts) with the arguments passed through readFilter, so it is the page's list with the page's viewer gating. It takes model, outcome, from, to, by, q and before, and returns next. A malformed filter is dropped, as on the page. I kept the existing trace tool and added no tools.
  • Read: I moved the tree builder and seeing out of src/http/api/traces.ts into a new src/trace/tree.ts. GET /api/v1/traces/:id and MCP read both call traceTree. read returns the existing rows plus tree, which is null if the run is not in the trace index.
  • Terminal: d looks the marked runs up by id with getRun, so a mark survives a search, a filter or a later page. If a marked run no longer exists, the toast says "a marked run is gone". The header now shows marked n/2 (*).
  • Docs: docs/features/traces.md now covers the v and d keys and the MCP list filters, the read tree and compare. This commit changes the MCP tool as well as the terminal and docs, so it carries no No door: line, and its subject starts with Direction: and names #18085.

Tests

  • Fixture: the fixture runs were left in state queued, so they never reached the trace index. They are now ok and indexed in beforeAll.
  • Equality: read.tree equals the API's GET /api/v1/traces/:id body. list equals listTraces for the same filters, and its ids match the API's repository=alice/notes&kind=run list.
  • Gating: a signed-in non-member (eve) gets a 404 from the API on read and compare, and the MCP tool refuses both. Her list is empty through both, and an unauthenticated MCP call never shows the run.
  • Terminal: with both marks filtered off screen, d still opens the comparison and the header reads marked 2/2.

Where I differ from the review

  • API list: GET /api/v1/traces lists from the trace index with its own filters (kind, since, until and others), not from listTraces. I did not merge the two. The test checks only that the MCP list and the API list give the same runs for one repository.
  • outcome filter: the MCP schema limits it to the page's values (ok, failed, cancelled, running, queued), so a bad value is refused at the boundary rather than dropped.

To try it Run bun test test/trace-share.test.ts. In the terminal, open Traces, press v on two runs of one issue, change the search, then press d.

commented

The MCP trace tool now uses the same functions as the trace API routes for listing, reading and comparing.

List. The parameter checks and the gated reader that GET /api/v1/traces had inline now live in src/trace/tree.ts as readListAsk and listSeenTraces. The API route and the tool's list both call them, so the tool returns the API's exact { items, next_cursor } body. It takes the API's filters (kind, model, outcome, since, until, limit, cursor) and refuses a bad value with the API's error code. The list's response bodies don't change, but the API now reaches its error codes through the shared parser, so look at that mapping. seeing is no longer exported.

Read. traceTree now takes a User, with no undefined case. It checks access through seenTraceRow and builds the tree with treeOf. The tool's read passes the trace readTrace already parsed to treeOf, so the run log is read and parsed once. It still applies the API's access check on the index row, which costs a database lookup and no log read, so a row the API answers 404 for gives tree: null.

What changes for callers. The tool's list no longer takes the page's filters (from, to, by, q, before). Its rows are the API's index rows rather than the page's rows, and with no kind filter they include every kind the caller may see, not only crew runs. The page and the terminal list still use listTraces and are unchanged. docs/features/traces.md describes the new tool list. The commit carries a No door: line because no page or terminal screen changes.

Tests. test/trace-share.test.ts now compares whole MCP and API list bodies: no filter, kind and model, a first page with limit: 1, the next page from its cursor, and a rejected since value. It still checks that the MCP tree equals the API tree. A stranger gets { items: [], next_cursor: null } from the tool.

Checks. bun x tsc --noEmit and bun scripts/gate.ts (38 of 38 rules) pass. The MCP, trace and traces-API suites pass: 1394 tests across 226 files, plus the traces-api, traces-import, openapi-errors and private-by-default files. scripts/fast.ts named 2744 files, too many to run here, so the rest of the suite is left to the forge's check.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs