Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Summary

When the bash tool's output exceeds the max_lines limit, instead of discarding all output, this PR saves it to a temporary file and includes the file path in the truncated output message.

This prevents expensive commands from needing to be re-run just to see their full output.

Changes

  • Modified bash tool to continue collecting lines even after truncation is triggered
  • Write full output to /tmp/bash-overflow-<timestamp>.txt when truncation occurs
  • Include temp file path in the truncation marker message
  • Updated tests to verify overflow file creation and proper cleanup
  • Fixed existing tests to account for new truncation message format

Example

Before:

line1
line2
line3
line4
line5 [TRUNCATED]

After:

line1
line2
line3
line4
line5
[TRUNCATED - Full output (100 lines) saved to: /tmp/bash-overflow-1234567890.txt]

Testing

  • All 27 existing bash tool tests pass
  • Added new test that verifies temp file creation, content, and cleanup
  • Verified type checking passes

Generated with cmux

When bash tool output exceeds limits (100 lines, 16KB, or 1KB/line), save the
full output to a temp file instead of failing with no output. This prevents
expensive commands from needing to be re-run.

Key design decisions:
- NO output shown when truncated - avoids overwhelming context
- Short 8-char hex file IDs (bash-a1b2c3d4.txt) for easy recall
- Helpful filtering examples (grep, head, tail, sed)
- Reminder to clean up temp file when done
- Reduce max_lines to 100 (from 1000) to trigger overflow more reasonably

Changes:
- Continue collecting lines even after truncation triggered
- Write full output to /tmp/bash-<8hex>.txt on overflow
- Return error with file path and filtering instructions
- Update tests to verify overflow file creation and format
- Reduce BASH_DEFAULT_MAX_LINES and BASH_HARD_MAX_LINES to 100

_Generated with `cmux`_
@ammar-agent ammar-agent force-pushed the bash-overflow-temp-file branch from b9a2eb8 to 4cff873 Compare October 8, 2025 19:59
Comment on lines 221 to 222
stdoutReader.close();
stderrReader.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would a using pattern clean up this duplication / bug risk?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! Added a triggerTruncation() helper function that eliminates the duplication. This ensures consistent cleanup and reduces bug risk across all 6 call sites.

…mit to 300

Changes:
- Add triggerTruncation() helper to eliminate code duplication (6 instances)
- Increase max_lines from 100 to 300 (better balance for common use cases)
- Update overflow message examples to reflect 300 line limit
- Update test to verify 300+ lines collected

Addresses review comment about duplication and bug risk.

_Generated with `cmux`_
@ammar-agent
Copy link
Collaborator Author

✅ Fixed! Added a triggerTruncation() helper function that eliminates the duplication at line 222 (and 5 other places). This ensures consistent cleanup and reduces bug risk.

- Replace dynamic import with static fs import at top of file
- Use String(err) in template literal to satisfy type checker
- Use RegExp.exec() instead of String.match()

_Generated with `cmux`_
@ammario ammario added this pull request to the merge queue Oct 8, 2025
Merged via the queue into main with commit 5b27f80 Oct 8, 2025
6 checks passed
@ammario ammario deleted the bash-overflow-temp-file branch October 8, 2025 20:26
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.

2 participants