Skip to content

feat: shell passthrough context injection and real-time streaming#77

Merged
emal-avala merged 3 commits intomainfrom
feat/shell-passthrough-context-injection
Apr 6, 2026
Merged

feat: shell passthrough context injection and real-time streaming#77
emal-avala merged 3 commits intomainfrom
feat/shell-passthrough-context-injection

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

Upgrades the ! prefix shell command (repl.rs:603) with two missing capabilities:

  • Real-time streaming: Switches from .output() (waits for completion) to Stdio::piped() with line-by-line BufReader output. Long-running commands now stream to the terminal as they execute.
  • Context injection: Captures stdout+stderr into a buffer and injects it into conversation history as a UserMessage with is_meta: true. The agent can reference shell output in subsequent turns without the user copy-pasting or using the Bash tool.
  • 50KB truncation: Prevents context bloat from large outputs (verbose test suites, build logs). Appends [output truncated at 50KB] when the limit is hit.

Before

> ! cargo test
(waits... waits... then dumps all output at once)
(agent has no idea what the output was)

After

> ! cargo test
running 45 tests              ← streams in real-time
test auth::test_login ... ok
test billing::test_charge ... FAILED

> The billing test is failing — can you see why?
(agent has the test output in context, can analyze it immediately)

What doesn't change

  • No LLM tokens consumed (not a turn)
  • No permission check needed (user explicitly invoked the command)
  • The ! prefix syntax is unchanged

Implements roadmap item 7.18.

Test plan

  • cargo check — clean compile
  • cargo clippy -- -D warnings — zero warnings
  • cargo test — all 232+ tests pass
  • Manual: run ! echo hello and verify output appears in real-time
  • Manual: run ! ls then ask agent "what files did you see?" — verify it references the output
  • Manual: run a command producing >50KB output, verify truncation message appears

🤖 Generated with Claude Code

Upgrades the `!` prefix shell command to:

1. Stream output in real-time using piped stdout/stderr with line-by-line
   reading, instead of capturing after completion with `.output()`. Users
   now see long-running command output as it happens.

2. Inject captured output into conversation history as a UserMessage with
   `is_meta: true`. The agent can reference shell output in subsequent
   turns without the user needing to copy-paste or use the Bash tool.

3. Truncate captured output at 50KB to prevent context window bloat from
   large command outputs (e.g., verbose test suites, build logs).

The shell passthrough does not count as a turn and does not consume LLM
tokens. It bridges the gap between "run this command yourself" and "let
the agent run it via the Bash tool" by giving the user direct control
while keeping the agent informed.

Implements roadmap item 7.18.
@emal-avala emal-avala merged commit 7ee2e6a into main Apr 6, 2026
13 of 14 checks passed
@emal-avala emal-avala deleted the feat/shell-passthrough-context-injection branch April 6, 2026 19:06
@emal-avala emal-avala mentioned this pull request Apr 6, 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