Skip to content

Preserve shell output head and tail - #16

Merged
CalvinSturm merged 1 commit into
mainfrom
feat/middle-truncate-tool-output
Jul 1, 2026
Merged

Preserve shell output head and tail#16
CalvinSturm merged 1 commit into
mainfrom
feat/middle-truncate-tool-output

Conversation

@CalvinSturm

Copy link
Copy Markdown
Owner

Summary

Improves shell/tool output truncation so long output preserves both the beginning and the end.

Why

Head-only truncation can discard the most useful part of build/test output, especially final compiler errors, test failures, or panic summaries.

This makes LocalAgent more useful during real coding tasks by keeping the command context and the actionable failure details.

What changed

  • Replaced head-only truncation with middle truncation
  • Preserves valid UTF-8
  • Keeps output within the configured byte budget
  • Inserts a clear truncation marker
  • Preserves existing behavior for output under the limit
  • Keeps truncation flags accurate

Validation

  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings
  • focused truncation/unit tests
  • cargo test --lib target::
  • cargo test --lib tools::
  • cargo test --test tool_call_accuracy_ci
  • cargo test --test artifact_golden
  • python scripts/ci_release_readiness.py

Follow-ups

  • Default shell timeout policy
  • Live shell output streaming / TUI tail events
  • Robust process-tree cleanup
  • Lightweight in-run todo/update_plan tool

Shell stdout/stderr truncation was head-biased: output over
max_tool_output_bytes kept the first N bytes and dropped the tail, discarding
the trailing compiler/test failure that is usually the most useful part.

Add middle_truncate_utf8_to_bytes, which keeps both the head and the tail
joined by a "[... truncated N bytes ...]" marker, stays within the byte budget,
and never splits a UTF-8 codepoint. Apply it to the host shell result envelope
(build_shell_target_result) only; read_file and the shared docker run_container
primitive keep head truncation. Output under budget and max_bytes == 0 are
unchanged (parity with the head-truncation helper). stdout_truncated /
stderr_truncated semantics are preserved.

Tests: short output unchanged; long ASCII preserves head+tail within budget;
marker reports the omitted byte count exactly; long 3-byte-codepoint UTF-8 stays
valid and within budget; shell envelope middle-truncates stdout; small timeout
partial output passes through unchanged.
@CalvinSturm
CalvinSturm merged commit c8e46a2 into main Jul 1, 2026
1 check passed
@CalvinSturm
CalvinSturm deleted the feat/middle-truncate-tool-output branch July 1, 2026 00:30
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