Skip to content

feat(native): stream a command's output live into its expanded row - #66

Merged
rynfar merged 2 commits into
nativefrom
nw/64-cmdout
Nov 2, 2026
Merged

rynfar merged 2 commits into
nativefrom
nw/64-cmdout

Conversation

@rynfar

@rynfar rynfar commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Problem

Expanding a command row in the native transcript showed only the output persisted on the item (or fetched with getTurnItem), so a running command showed nothing until it settled, and ANSI output was not normalized or coloured. The web streams it (CommandOutputPanel.tsx): live while the command runs, final once it settles.

Approach

  • crates/core/src/terminal_output.rs: a line-for-line port of packages/shared/src/terminalOutput.ts (the fold the server also runs): the 64-line live window, cursor moves, erases, save/restore, hidden OSC/DCS strings, pending escapes across chunks, the 64K tail with its newline-preferring and style-preserving cuts, and lengths counted in UTF-16 units so cuts land where the server's do. Also terminalOutputSpans with both TERMINAL_PALETTES, inverse, the badge contrast fix and the 2,000-span cap.
  • crates/core/src/command_output.rs: the frame wire type, applyCommandOutputFrame (replace resets, append folds, truncated sticks until a replace), and the panel's branches with the web's copy: "Loading output…", "No output.", "Couldn't load output: …", "Earlier output not shown", nothing while a running command has printed nothing.
  • crates/client/src/command_output.rs: orchestration.subscribeCommandOutput decoded and folded on the network runtime; the row reads only the newest result from a watch. It stops when the server ends the stream after settling, reports server failures, resubscribes after a dropped connection, and dropping the handle interrupts it.
  • crates/app/src/transcript/command_output.rs + work.rs/thread_view.rs: only when the server advertises commandOutputStreaming, an open command row subscribes and skips the getTurnItem fetch, as the web does. Closing the row, folding its group, switching thread or connection drops the subscription. Output scrolls in its own 20rem panel pinned to the tail while the reader stays within 8px of the bottom. Rows redraw only when a frame lands; nothing ticks. Older servers keep the old path.
  • The probe gains --command-output (stream every command of the watched thread) and --delete-after (remove a scratch launch).

Not ported: ShellCommandBlock's syntax highlighting of the command line (still plain mono), so the ledger row is partial.

Ledger

TR-CMDOUT: partial, Native = the four modules above, Issue #64. #64 stays open for the command highlighting gap.

Evidence

  • Conformance: new conformance/commandOutputCases.ts writes crates/core/tests/conformance/command-output.jsonl from the real TypeScript (52 seeded cases, 1,336 states: chunked folds under 16–2,000 char budgets, astral text, and frames built the way CommandOutputHub builds them, with resume-text replaces); command_output_matches_typescript replays them and compares text, truncated, pending, running and spans. A deliberate one-character drift in the tail cut fails it with 19 divergences.
  • Unit tests: terminal_output::tests::* (redraws, cursor moves, split strings, pending limit, every truncation path, spans), command_output::tests::{a_replace_after_appends_starts_over, truncated_sticks_until_a_replace_clears_it, appends_past_the_tail_truncate_on_the_client, continues_an_escape_and_a_redraw_split_across_appends, panel_follows_the_web_branches}, t3-client command_output::tests::{folds_frames_until_the_command_settles_then_stops, collapsing_interrupts_and_a_lost_connection_resubscribes, a_server_failure_is_reported_and_not_retried}.
  • Screenshots (smoke server, "Native client showcase", vp test run expanded): /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3ca997f3-68be-482e-8fff-7893917dbe2a/scratchpad/after-dark.png, /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3ca997f3-68be-482e-8fff-7893917dbe2a/scratchpad/after-light.png (crops: /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3ca997f3-68be-482e-8fff-7893917dbe2a/scratchpad/crop-dark.png, /private/tmp/claude-501/-Volumes-DevSSD-t3code-native/3ca997f3-68be-482e-8fff-7893917dbe2a/scratchpad/crop-light.png). A settled row looks as it did before; the change is what happens while it runs.
  • Probe transcript (smoke server, free devReplay showcase launch, deleted afterwards):
command-output …showcase-test: subscribed (running)
command-output …showcase-test: running=true truncated=false chars=0 error=None tail=""
command-output …showcase-test: running=false truncated=false chars=90 error=None tail="s (12 tests) 14ms\n\n Test Files  1 passed (1)\n      Tests  12 passed (12)"
command-output …showcase-test: stream ended
deleted a72c84ac-…: Ok("{\"sequence\":2527}")

Gates: cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace, node scripts/gen-theme.ts --check, node --test parity/sync.test.ts, node ../../apps/native/conformance/generate.ts --check all pass.

@rynfar

rynfar commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Review round 1, addressed in d7a7ff7 (rebased on fork/native).

1. [P2] Folding a group or turn didn't resync subscriptions. Fixed. rederive now reconciles subscriptions whenever the rows change (crates/app/src/thread_view.rs:243). Every fold toggle (toggle_group, toggle_run, toggle_attempt) and every thread update goes through rederive, so folding drops the slot and reopening recreates it. The desired set is now a pure selector, t3_core::timeline::open_command_items (crates/core/src/timeline/detail.rs:74). It includes only open command entries that a drawn RowKind::Work row shows. Test: timeline::tests::open_command_items_follow_folded_groups (crates/core/src/timeline/tests.rs:1303) folds and reopens the group and the turn. The missing call was inside a GPUI view the app crate has no test harness for, so the test covers the selector it now calls.

2. [P2] Every frame invalidated every row. Fixed.

  • remeasure_entry (thread_view.rs:393) now remeasures only the row that draws the entry, and only the open group list that holds it.
  • A frame triggers it only when the height can change (thread_view.rs:378, transcript/command_output.rs:64). Once the output fills its capped scroller, a frame with the same notice and at least as many lines as the cap shows keeps the same height, whatever the wrapping. Fewer lines, a new truncation notice, or a branch change still remeasure. See CommandOutputStatus::keeps_capped_height (crates/core/src/command_output.rs:119). Test: command_output::tests::a_filled_panel_keeps_its_height_until_its_lines_or_notice_change.

3. [P3] Output can't be selected or copied. Recorded as a gap, not built. Native has no selectable plain or styled text element. The only selectable text is gpui-component's markdown TextViewState (crates/app/src/transcript/markdown.rs:93,142), which can't carry ANSI runs. Other mono tool output in work rows isn't selectable either. The TR-CMDOUT ledger row now names the gap ("the output cannot be selected or copied yet").

Gates: clippy -D warnings, cargo test --workspace, gen-theme --check, parity/sync.test.ts, conformance --check all pass. Re-checked in a real window: expand vp test run, fold its group, reopen it, and the output shows again.

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