Skip to content

feat(native): raw item inspector in tool rows - #82

Merged
rynfar merged 6 commits into
nativefrom
nw/78-inspector
Nov 2, 2026
Merged

rynfar merged 6 commits into
nativefrom
nw/78-inspector

Conversation

@rynfar

@rynfar rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Problem

An expanded tool row in the native client showed an approximation of the web's V2ItemInspector. The rules differed from the web: which rows open, the indent, and output that was never fetched for reads. Copy also differed: "Output is no longer available." was shown on its own, and commands had a $ prefix. There was no JSON highlighting and no tool output images, and the text could not be selected. The withheld-detail fetch also decoded the item on the UI thread.

Approach

  • Core: pure logic, with tests mirroring the TS.
    • timeline/detail.rs now ports all of itemDetail.ts: toolCallLines, formatToolValue (content blocks, resource links, structuredContent, JSON and JSON-lines pretty-printing), turnItemOutputText, turnItemOutputImages (with readToolOutputImage and the 8-image cap), turnItemHasDetail, turnItemNeedsDetailFetch and turnItemDetailRevision.
    • New timeline/inspector.rs ports two pieces of web logic. From TimelineWorkEntryRow: plainOutput, canExpandProjectedItem, and whether a row gets the inspector, a read's or skill's plain output plus FetchedToolOutput, or QuestionAnswerHistory. From V2ItemInspector: useFetchedTurnItem / ToolOutput states (pending, error, Couldn't load output: Output is no longer available., No output.) and the inspector's text lines.
    • New json_text.rs:
      • JSON.stringify as JS prints it (key order including array-index keys first, number formatting, escapes).
      • isJsonText.
      • A JSON tokenizer that names each run by the capture @pierre/highlights gives it, so colors come from the same syntax theme.
    • serde_json now has preserve_order set explicitly. The app already got it through feature unification, but cargo test -p t3-core did not, so argument order differed between the two builds.
    • AssetResource::ToolOutputImage added. FileChangeDetail gains fileType / mimeType.
  • App:
    • New transcript/inspector.rs is a RenderOnce port of V2ItemInspector / FetchedToolOutput. It derives its blocks once per (item, fetched item, fetch state, appearance) through keyed state, not on every frame.
    • All text uses SelectableText from feat(native): selectable text element, used by command output #72. Long blocks scroll in their own capped scrollers, and a drag past the edge autoscrolls them.
    • JSON arguments are highlighted, and a JS REPL's code argument is highlighted as TypeScript. Tool output images come from the media cache and open the viewer.
    • Web search results open their links. A file change shows its counts in diff_addition / diff_deletion, plus "Open diff".
    • The panel follows WorkLogDetails kind="panel": flush with the icon, mt-0.5 mb-1.5 pb-2.
  • Fetch:
    • thread_view.rs::fetch_detail uses AppState::request, so the result decodes on the network runtime.
    • It asks core's entry_fetches_detail, so reads and skills with withheld output now fetch, as FetchedToolOutput does. The inspector of a streamed command still doesn't fetch.
    • It is still bounded (64 entries, open rows kept), keyed by revision, and only runs for open rows.
    • Only the body of fetch_detail changed in that file.
  • Wire:
    • New conformance fixture item-detail.jsonl and replay in tests/conformance.rs. Items are sent as real orchestration.getTurnItem results through the contracts codec, and every itemDetail.ts output is compared.
    • It also checks per-character JSON highlight captures against @pierre/highlights, using a theme that colors each capture differently.
    • The probe gains --turn-items.

Ledger

TR-INSPECT: todo → partial.

  • Native path: crates/app/src/transcript/inspector.rs, crates/core/src/timeline/inspector.rs, crates/core/src/timeline/detail.rs, crates/core/src/json_text.rs.
  • Issue: Raw item inspector in tool rows (TR-INSPECT) #78.
  • Gap: the command line is still not syntax-highlighted (ShellCommandBlock's highlighter, already noted on TR-CMDOUT).

Out of this row and not ported here:

  • Viewed-image previews belong to TR-WORK.
  • QuestionAnswerHistory attachments show by name, not as thumbnails.

docs/design-system.md §7.7's expanded-body row now matches the panel.

Screenshots

Offscreen GPUI renderer (--snapshot, same clicks on both builds). They are in /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/15deb025-b650-4cf9-a1aa-1cc16b006f6d/scratchpad/shots78/:

  • Smoke server, "Native client showcase", file change and streamed command open:
    • crop-before-command-filechange.png: indented 28px, $ vp test run.
    • crop-after-command-filechange.png and crop-after-command-filechange-light.png: flush like the web, no $.
    • The full windows are the same names without crop-.
  • Real-data server 14700 (read-only), an MCP tool with withheld output:
    • before-mcp-row.png.
    • after-mcp-row.png: url … with the key muted, then the fetched output.
    • after-mcp-select.png: a drag selects across the argument line.
    • These are cropped to a public repo's PR row.
  • JSON highlighting rarely shows on real data. Arguments are almost always a record, and those show as key value lines, as on the web. The conformance fixture pins it per character instead.

Probe transcript

cargo run -p t3-client --example probe -- --thread mcp:60fa4373-… --turn-items --seconds 6 against the smoke server (item ids shortened):

status: Connected
thread mcp:60fa4373-…: snapshot seq=3134 items=28 visible=28 has_more=Some(false) watermark=Some(3000009)
turn-item …showcase-test (command_execution, revision 2026-11-02T08:45:33.994Z): loaded output_chars=90 images=0
turn-item …workspace-preparation… (command_execution, revision 2026-11-02T08:45:29.079Z): loaded output_chars=32 images=0
turn-item …showcase-read (dynamic_tool, revision 2026-11-02T08:45:31.116Z): loaded output_chars=169 images=0 args=1 args_text_chars=0

Notes

  • Pre-existing crash in the sidebar (not touched here). sidebar/row.rs sets hover twice on a receding working row. GPUI panics with "hover style already set" as soon as one is drawn. It reproduces on the base build against real data. I patched it locally, without committing, only to take the real-data captures.
  • Expanded group rows. In the showcase replay, an open group doesn't list completed reads. This comes from work_entry_is_visible_in_group, which was ported from the web, so the read row isn't reachable there.
  • No real-window capture. I didn't launch a real window: main.rs calls cx.activate(true), which would take focus.

Closes #78

@rynfar

rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

I've addressed all three review findings in 1b438d4aca, which is rebased on native (#80). Clippy, workspace tests, gen-theme, parity and conformance checks all pass.

1. Large outputs did their work on the UI thread (fixed). An inspector's blocks are now prepared without colors and stored in a cache outside render (PreparedCache, a global entity).

  • The cache keys on the item and fetched item by identity and keeps up to 32 entries, dropping the least recently drawn. Scrolling back reuses an entry and does not derive again.
  • Items under 16 KiB of text are prepared during render. Larger ones are prepared on the background executor, and the view is notified when the result lands.
  • JSON and TypeScript highlighting are skipped for text over 64 KiB, which then draws plain.
  • Tests: large_items_derive_off_the_ui_thread and text_past_the_budget_draws_plain.

2. Answer attachments looked like links but did nothing (fixed). answered_questions now keeps each attachment's id and whether it is an image.

  • Image attachments show as thumbnails up to 128×80 (h-20 max-w-32, contain), loaded from the media cache.
  • A file, or an image that hasn't loaded yet, shows its underlined name.
  • Clicking either one signs the attachment with assets.createUrl and opens the signed URL in the browser, like the web's <a href={url} target=_blank> (the signature in the URL is the credential).
  • The core test now asserts the id and kind are kept.

3. Argument colors survived a theme change (fixed). Prepared text stores what colors each run (argument keys, JSON captures, or the TypeScript syntax tree), not the colors themselves. Colors are looked up when the text is drawn and kept per theme: the palette's &'static pointer plus the syntax theme's Arc. Switching between two light themes now resolves them again. Test: colors_resolve_again_when_the_theme_changes.

sidebar/row.rs was never part of this PR. I patched it only in my local build to take the real-data screenshots and reverted it before committing. That crash is #83.

@rynfar

rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Both points from the follow-up are fixed in 1606be5edb. Every gate passes.

  1. Pending work was unbounded (fixed). At most RUNNING_LIMIT (4) background derives run at once. Further requests wait as Queued entries, and the most recently requested one starts next. The cache is trimmed on every insert and on every completion. When it holds more than CACHE_LIMIT (32) entries, the oldest Ready entries go first, then the oldest Queued ones. Running entries are never more than 4, so the total stays bounded. Queuing instead of evicting means several large open tools can't keep cancelling each other. Tests: the_cache_stays_bounded_while_derives_wait and only_a_few_derives_run_at_once_newest_first.

  2. Search queries weren't counted (fixed). item_bytes is replaced by a Budget walk over every string the inspector draws: file-search patterns and results, web-search queries and results, the file-change name, paths and types, the tool name, arguments and output, and so on. The walk stops as soon as the budget runs out, and the fetched item draws from the same budget. Test: every_drawn_string_counts_toward_the_inline_budget.

@rynfar

rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Fixed in 6c50d293bb: dropped queued entries no longer lose their waiters.

  • trim() now returns the waiters of every Queued entry it drops.
  • get() and finish() wake those views, deferred until the cache update ends so no view is notified mid-draw. They then ask again on their next draw.
  • Regression test: a_view_whose_waiting_derive_is_dropped_is_woken_to_ask_again. The dropped row belongs to a side chat while every running derive belongs to the main view.

All gates pass. One run of the client test local::tests::a_timed_out_cli_takes_everything_it_started_with_it failed on timing. That file isn't touched here, and the test passed three times on rerun.

@rynfar

rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Fixed in 5048ce3d07: a redraw now always follows progress.

  • Eviction no longer wakes anyone. trim() moves the waiters of a dropped Queued entry into a deduplicated starved set.
  • Only a completion wakes views. complete() (called by finish()) wakes the finished derive's own waiters and drains starved, so evicted rows ask again only when a derive is free.
  • get() never schedules a redraw.
  • Test: a_dropped_waiting_row_is_retried_only_after_a_derive_completes. Trimming, even repeatedly, leaves the side chat's owner starved with no wakeups. A completion of the main view's derive wakes both views and empties the set.

All gates pass.

@rynfar

rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Fixed in dda0c105ad: the cache no longer recomputes rows that are on screen.

  • Each entry records the frame that last drew it. A frame opens with its first get() and closes once that draw's updates settle, through a deferred close that also trims.
  • trim() never drops an entry drawn in the current frame. The cache can grow past 32 by what is on screen, and shrinks back to the limit after a frame that no longer draws those rows.
  • Test: rows_on_screen_derive_once_even_past_the_limit. 40 rows are redrawn after every completion; each derives exactly once, and the cache trims back to 32 once they stop drawing.

Rebased on native; all gates pass.

@rynfar
rynfar merged commit 2ad8ce7 into native Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant