Skip to main content

Module shell_output

Module shell_output 

Source
Expand description

Mirrors packages/agent/src/harness/utils/shell-output.ts — the bash tool’s output-capture layer wrapping Shell::exec.

Combines stdout+stderr into a single rolling tail buffer (capped at max_output_bytes = DEFAULT_MAX_BYTES * 2 = 100KB), spills to a temp file (bash-*.log) once cumulative output exceeds DEFAULT_MAX_BYTES/DEFAULT_MAX_LINES, and produces a ShellCaptureResult carrying truncation metadata + the temp-file path. on_chunk fires per sanitized/CR-stripped chunk with a progress snapshot.

return_execution_errors: true causes exec failures to come back as a success-result with execution_error populated (so the bash tool — not the env — owns error rendering via append_status). There is NO time-based throttle here; throttling lives in the bash tool.

v1 divergence from the TS: the TS initializes the temp file mid-stream (inside the stdout/stderr callback) and appends subsequent chunks. Doing async file I/O from a sync FnMut callback is unsound in Rust, so the v1 port performs the spill in a single post-stream pass: the entire captured tail is written to the temp file after exec resolves. The full_output_path and truncation metadata are identical; only the timing of the file write differs. Tests verify the temp file exists when output exceeds limits — they don’t depend on mid-stream creation.

Re-exports§

pub use crate::truncate::format_size;

Structs§

ShellCaptureOptions
Mirrors ShellCaptureOptions.
ShellCaptureProgress
Mirrors ShellCaptureProgress.
ShellCaptureResult
Mirrors ShellCaptureResult.

Functions§

execute_shell_with_capture
Mirrors executeShellWithCapture. Drives env.exec with on_stdout/on_stderr callbacks that fold into [CaptureState], spills to a temp file in a post-stream pass, and returns the terminal ShellCaptureResult.