Stream compound command output progressively (#43) - #106
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #43
- Fix virtual command interference in streaming mode by bypassing virtual commands when streaming mode is enabled and shell operators are present - Add proper real-time output handling for commands with shell operators like semicolons, pipes, and redirects - Commands like `echo "immediate"; sleep 0.1; echo "delayed"` now properly stream their output in real-time instead of being processed by virtual command handlers - Add comprehensive test suite to verify streaming functionality - Maintain backward compatibility with existing functionality 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Resolve conflicts, and double check that is the best possible way to address all these issues. If there is a better way fix it. If that is not documented, make sure we document well enough all the best practices, and show bad examples to avoid. If there is multiple different solutions we should check competitors best practices and provide all solutions they have. |
|
🤖 AI Work Session Started Starting automated work session at 2026-07-28T20:24:46.636Z The PR has been converted to draft mode while work is in progress. This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback. |
Working session summaryPR #106 is ready for review, conflict-free, mergeable, and green on commit Implemented:
Validation:
This summary was automatically extracted from the AI working session output. |
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
📊 Context and tokens usage:
Total: (519.5K + 14.0M cached) input tokens, 68.7K output tokens, $22.313423 cost 🤖 Models used:
📎 Log file uploaded as Gist (5090KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
🎉 Auto-mergedThis pull request has been automatically merged by hive-mind.
Auto-merged by hive-mind with --auto-merge flag |
Summary
Fix compound commands so
.stream()emits each virtual or nested process chunk as it arrives instead of misclassifying the whole command or waiting for nested work to finish.Closes #43.
Root cause
The JavaScript runner deliberately skipped its enhanced shell parser whenever streaming was active. A command such as:
therefore fell through to the simple virtual-command parser, which could treat everything after
echoas arguments. The earlier draft worked around that with substring checks and forced compound streams into a system shell. That would make common cases stream, but it also:Solution
kill()and async-iterator cancellation to the active nested process.&without allowing the tokenizer to stall.sleeptimers, polling intervals, and abort listeners on both completion and cancellation.Reproduction and regression coverage
The minimal regression registers a virtual command that blocks until the test releases it:
Before the fix, the first chunk was the misparsed literal command text. After the fix,
before\nis available while the second command is still blocked.js/tests/issue-43-stream-output.test.mjsalso verifies:;,*,[, and?remain ordinary virtual-command arguments;Execution models and documentation
The new Real-time Streaming section in
js/BEST-PRACTICES.mdcompares the main approaches used by Bun Shell, zx, Execa, and Node:It documents when to choose each model and includes bad examples for completion-buffered output, unnecessary
sh -c, untrusted raw syntax, and producer-side buffering.js/examples/streaming-compound-commands.mjsis a runnable progressive-output example.Validation
bun test js/tests/ --timeout 10000: 790 passed, 5 skipped, 0 failedbun run lint: passed (one pre-existing warning incommands/$.cd.mjs)bun run format:checkbun run check:duplicationbun scripts/validate-changeset.mjscargo fmt --all -- --checkcargo clippy --all-targets --all-featurescargo test --all-features --verbosecargo test --doc --all-features --verbosecargo build --release --verbosecargo package --allow-dirtyThis is intentionally JavaScript-only and carries
parity-exempt: Rust'sStreamingRunneralready launches the complete compound command in one system shell and streams that child, while the bug was in JavaScript's virtual-command orchestration lifecycle.Release
Adds a patch changeset for
command-stream.