CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

feat(tui): live shell output during execution - show real-time progress

Open donglovejava opened this issue 6 months ago • 7 comments

Summary

Add real-time incremental output display for shell execution commands. The TUI now displays shell output while the command is still running, instead of hiding all output until completion.

Changes

  • ExecCell: Added live_output: Option<String> field to store incremental output during execution
  • history.rs: Modified render logic to show live_output when output is not yet available (priority: final output > live output > hints)
  • app.rs: Added poll_shell_progress() method that polls ShellManager during idle frames and updates matching ExecCell entries
  • ui.rs: Wired poll_shell_progress() into the event loop after tick_quit_armed()
  • All ExecCell construction sites: Added live_output: None to 8 files

How it works

  1. During idle frames, the TUI polls ShellManager.list_jobs() for running shell processes
  2. Running exec cells are matched to shell jobs by command prefix
  3. Live output (tail of stdout/stderr) is written to ExecCell.live_output
  4. The renderer displays it in the transcript immediately

Files changed

crates/tui/src/tui/active_cell.rs  |  1 +
crates/tui/src/tui/app.rs          | 69 +++++++++++++++++++++++++++++
crates/tui/src/tui/history.rs      | 11 ++++
crates/tui/src/tui/sidebar.rs      |  5 ++
crates/tui/src/tui/tool_routing.rs |  2 +
crates/tui/src/tui/transcript.rs   |  1 +
crates/tui/src/tui/ui.rs           |  2 +
crates/tui/src/tui/ui/tests.rs     |  3 +

donglovejava avatar May 25 '26 03:05 donglovejava

Independent review:

Build break (blocking). cargo check -p codewhale-tui --tests fails:

  • app.rs:2566 — ref mut ec inside if let Some(...) rejected on rustc 1.94 (error: cannot explicitly borrow within an implicitly-borrowing pattern). Drop ref mut, the binding is already by-ref.
  • history.rs lines 3822, 4129, 4159, 4427, 4598 — 5 in-file test ExecCell { ... } literals missing live_output: None (you updated 8 sites, missed the 5 in the same file as the struct). All test builds fail with E0063.

Polling cost is non-trivial. poll_shell_progress runs every idle frame (~120ms) and calls shell_mgr.lock().list_jobs(), which poll()s every background shell and copies a 1200-byte tail per job. Same mutex is contended by stdout reader threads. Consider: skip when running_execs.is_empty() is already done — also skip when last poll was <250ms ago, and avoid taking the lock when no exec is Running.

Correctness: O(N·M) prefix match on first 100 chars is fragile (two npm run … cells alias). Match by task_id (stored on ExecCell at start_tool) instead. trim() on stderr_tail/stdout_tail discards leading whitespace forever (progress bars, indented logs). Use raw tail; trim only for emptiness check.

Backpressure / truncation: OK — shell.rs caps tail at 1200 bytes via tail_from_buffer, so huge output can't blow memory here. But live_output is replaced wholesale each tick, so any line that scrolls past the 1200B window between polls is lost forever (no scrollback for live view). Document or note.

v0.8.48 (PR #2256) conflict: clean on code — only CHANGELOG/Cargo version bumps overlap. No ExecCell field changes in 2256. Safe to land in either order after rebase.

Dead code check: Wiring exists (ui.rs:2067). Not dead.

Hmbown avatar May 27 '26 13:05 Hmbown

Thanks for taking on live shell output. I am keeping this open because it is currently blocked and the implementation needs a sturdier association model before merge: command-prefix matching is fragile, polling cost can add up, and live-tail whitespace trimming can misrepresent output.

The next good slice is to fix the compile/build break, match live output by task/job id instead of command prefix, and add focused TUI shell-output tests. After that, cargo check -p codewhale-tui --tests plus a live shell smoke would make this much easier to review.

Hmbown avatar May 31 '26 04:05 Hmbown

Thanks @donglovejava — live shell output would be a useful TUI improvement, but I am leaving this unmerged for now.

What I need before landing it:

  • refresh/rebase onto current main and run the current codewhale-tui checks, not just the lightweight security scan
  • address the review concerns around prefix-based job matching, repeated string cloning/allocations, and preserving raw output instead of trimming it
  • add or update focused tests for matching the correct running shell job and rendering live output before final output arrives

The feature direction is good; it just needs that correctness pass before it is safe to merge into the transcript/rendering path.

Hmbown avatar May 31 '26 07:05 Hmbown

Thanks @donglovejava. The live shell-output direction is useful, but I'd keep this unmerged for now. I reproduced the current build break in cargo check -p codewhale-tui --tests, and the implementation still needs a correctness pass before it is safe in the transcript path: matching jobs by command prefix can misattribute output, trimming tails can alter real terminal output, and the polling loop needs focused coverage.

A good next slice would be to rebase onto current main, fix the compile errors, match live output by a stable shell task/job id, preserve raw output, and add tests for similar concurrent commands plus live-before-final rendering.

Hmbown avatar May 31 '26 09:05 Hmbown

Thanks @donglovejava. The live shell-output direction is useful, but I would keep this unmerged for now.\n\nThe PR still only has the lightweight security check, needs a refresh against current main, and the current head appears to need compile fixes plus a correctness pass around job association. A good next slice would be to rebase, match live output by a stable shell task/job id instead of command prefix, preserve raw stdout/stderr tails, and add focused tests for similar concurrent commands plus live-before-final rendering.

Hmbown avatar May 31 '26 17:05 Hmbown

This is a good product instinct: live shell output can make CodeWhale feel much more honest and less like a black box. I am leaving it unmerged in the 0.8.48 pass because the PR is currently blocked, and this path touches cancellation/job-state UX where we need to be especially careful.

For a refreshed version, I would love to see it rebased onto current main with a small checklist for cancel behavior, Esc behavior, background task state, and whether any running indicator stops immediately when the user stops a task. That would line this up with the calmer, user-controlled direction we want.

Hmbown avatar Jun 01 '26 02:06 Hmbown

Thanks @donglovejava. I reviewed this again for the v0.9.0 stewardship branch. The user-visible goal is still good: shell cells should be able to show live progress before the final output arrives.

I am deferring this PR rather than merging it as-is. The branch is far behind the current TUI shape, is currently blocked with only GitGuardian reported, and the implementation has risks we should avoid in the release train: command-prefix matching can attach output to the wrong similar command, trim() can alter progress/whitespace output, stderr priority can hide stdout progress, and idle-loop polling through the shell manager lock is heavier than it needs to be. Current shell jobs already carry stable ids, so a fresh implementation should key live output by job/task id instead.

If we harvest this behavior later, we should credit #2048 and add tests for live-before-final rendering, concurrent similar commands, raw whitespace preservation, cancellation/background state, and final-output precedence.

Hmbown avatar Jun 05 '26 17:06 Hmbown

Thanks @donglovejava / dongchao for the live shell-output work in this PR. I harvested the v0.9-safe slice into maintainer PR #2826 rather than cherry-picking this branch.

What landed in #2826:

  • background shell Exec cards now keep the shell task_id from tool metadata;
  • the TUI refreshes bounded stdout/stderr tails from existing ShellManager::list_jobs() snapshots;
  • refreshes match by exact shell task id, not command text/prefix;
  • final Exec output remains authoritative, so stale live tails do not replace completed tool output.

I intentionally did not bring over broader command-matching or UI-state changes from this branch because the current v0.9 shell manager already has task-linked job snapshots, which gives us a narrower and safer path.

Verification in #2826 includes focused renderer and task-id matching tests plus TUI clippy/version drift checks. Keeping this PR open as the source branch for the original contributor intent while #2826 gets CI.

Hmbown avatar Jun 06 '26 04:06 Hmbown

Thanks again @donglovejava / dongchao. I’m closing this PR as harvested by #2826, now merged into codex/v0.9.0-stewardship as 787383591.

What landed from the original intent:

  • background shell Exec cards keep the shell task_id from tool metadata;
  • the TUI shows bounded stdout/stderr tails from existing ShellManager::list_jobs() snapshots;
  • live refreshes match by exact shell task id, not command text or prefix;
  • final Exec output remains authoritative over any stale live tail.

Verification on #2826 included cargo test -p codewhale-tui shell_live_output --locked, cargo test -p codewhale-tui exec_cell_ --locked, TUI clippy, format, version drift, and whitespace checks. Your live shell-output direction is credited in the PR body and both changelogs. Appreciate the useful product instinct here; it made the v0.9 TUI noticeably more honest for long-running shell work.

Hmbown avatar Jun 06 '26 04:06 Hmbown