Commit b0d1f31
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- src
- constants
- services/tools
- types
- utils/tools
- tests/ipcMain
6 files changed
+205
-178
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
0 commit comments