Skip to content

Commit b0d1f31

Browse files
authored
🤖 Add byte limits to bash tool output (#91)
## Problem The bash tool can break models due to excessive output despite the 1000-line hard cap: - Lines can be arbitrarily long (1000 lines × 100KB/line = 100MB possible) - No byte-based limits exist - Truncated partial output pollutes context and doesn't teach models to be conservative ## Solution Add byte limits that **fail with an error instead of returning truncated output**: - **BASH_MAX_LINE_BYTES**: 1KB per line - **BASH_MAX_TOTAL_BYTES**: 16KB total output - **Commands that exceed limits fail completely** (no partial output) This encourages models to be conservative and use output-limiting commands. ### Changes 1. **Constants** (`src/constants/toolLimits.ts`): - Added `BASH_MAX_LINE_BYTES = 1024` - Added `BASH_MAX_TOTAL_BYTES = 16 * 1024` 2. **Bash Tool** (`src/services/tools/bash.ts`): - Track `totalBytesAccumulated` across stdout/stderr - Kill process when per-line or total byte limits exceeded - Return error (not partial output) when limits hit - Error message suggests using head/tail/grep 3. **Tool Definition** (`src/utils/tools/toolDefinitions.ts`): - Emphasize limits are strict and will FAIL - Encourage conservative usage: "use head, tail, grep" - Clear messaging that no partial output is returned 4. **Tests** (`src/services/tools/bash.test.ts`): - Test per-line limit fails correctly - Test total bytes limit fails correctly - Test early termination returns error - Verify error messages include helpful suggestions ## Benefits - **Forces conservative behavior**: Models learn to limit output proactively - **Clean context**: No polluted partial output in conversation history - **Predictable failures**: Clear error messages guide models to fix commands - **Early termination**: Don't waste cycles processing excessive output _Generated with `cmux`_
1 parent 146adcd commit b0d1f31

File tree

6 files changed

+205
-178
lines changed

6 files changed

+205
-178
lines changed

src/constants/toolLimits.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export const BASH_DEFAULT_MAX_LINES = 1000;
22
export const BASH_HARD_MAX_LINES = 1000;
3+
export const BASH_MAX_LINE_BYTES = 1024; // 1KB per line
4+
export const BASH_MAX_TOTAL_BYTES = 16 * 1024; // 16KB total output

0 commit comments

Comments
 (0)