Skip to content

Commit 015d091

Browse files
authored
🤖 Simplify bash tool overflow output (#126)
Improves the bash tool overflow error message to be more concise and use cleaner paths. **Changes:** - Removed redundant command examples (grep/head/tail/sed) - agents know how to filter - Added single helpful guidance line encouraging use of filtering tools - Use `/tmp` on macOS for cleaner paths instead of `/var/folders/.../T/` **Before:** ``` [OUTPUT OVERFLOW - Line count exceeded limit: 300 lines >= 300 lines (12175 bytes read)] Full output (1020 lines) saved to /var/folders/fs/55k0056d2rq090642gnvp5t80000gn/T/bash-1209280d.txt Use filtering tools to extract what you need: - grep '<pattern>' /var/folders/fs/55k0056d2rq090642gnvp5t80000gn/T/bash-1209280d.txt - head -n 300 /var/folders/fs/55k0056d2rq090642gnvp5t80000gn/T/bash-1209280d.txt - tail -n 300 /var/folders/fs/55k0056d2rq090642gnvp5t80000gn/T/bash-1209280d.txt - sed -n '100,400p' /var/folders/fs/55k0056d2rq090642gnvp5t80000gn/T/bash-1209280d.txt When done, clean up: rm /var/folders/fs/55k0056d2rq090642gnvp5t80000gn/T/bash-1209280d.txt ``` **After:** ``` [OUTPUT OVERFLOW - Line count exceeded limit: 300 lines >= 300 lines (12175 bytes read)] Full output (1020 lines) saved to /tmp/bash-1209280d.txt Use selective filtering tools (e.g. grep) to extract relevant information and continue your task When done, clean up: rm /tmp/bash-1209280d.txt ``` _Generated with `cmux`_
1 parent 71f10a7 commit 015d091

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/services/tools/bash.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ describe("bash tool", () => {
8585
expect(result.error).toContain("lines) saved to");
8686
expect(result.error).toContain("bash-");
8787
expect(result.error).toContain(".txt");
88-
89-
// Verify helpful filtering instructions are included
90-
expect(result.error).toContain("grep '<pattern>'");
91-
expect(result.error).toContain("head -n 300");
92-
expect(result.error).toContain("tail -n 300");
9388
expect(result.error).toContain("When done, clean up: rm");
9489

9590
// Extract file path from error message (handles both "lines saved to" and "lines) saved to")
@@ -518,7 +513,6 @@ describe("bash tool", () => {
518513
expect(result.success).toBe(false);
519514
if (!result.success) {
520515
expect(result.error).toMatch(/exceeded per-line limit|OUTPUT OVERFLOW/);
521-
expect(result.error).toContain("head");
522516
expect(result.exitCode).toBe(-1);
523517
}
524518
});
@@ -538,7 +532,6 @@ describe("bash tool", () => {
538532
expect(result.success).toBe(false);
539533
if (!result.success) {
540534
expect(result.error).toMatch(/Total output exceeded limit|OUTPUT OVERFLOW/);
541-
expect(result.error).toContain("grep");
542535
expect(result.exitCode).toBe(-1);
543536
}
544537
});
@@ -556,7 +549,6 @@ describe("bash tool", () => {
556549
expect(result.success).toBe(false);
557550
if (!result.success) {
558551
expect(result.error).toMatch(/Total output exceeded limit|OUTPUT OVERFLOW/);
559-
expect(result.error).toContain("tail");
560552
expect(result.exitCode).toBe(-1);
561553
}
562554
});

src/services/tools/bash.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,17 @@ export const createBashTool: ToolFactory = (config: ToolConfiguration) => {
334334
// We don't show ANY of the actual output to avoid overwhelming context.
335335
// Instead, save it to a temp file and encourage the agent to use filtering tools.
336336
try {
337-
const tmpDir = os.tmpdir();
337+
// Use ~/.cmux-tmp for overflow files (not in ~/.cmux to prevent accidental
338+
// deletion/modification of configuration). Avoids /tmp for security since
339+
// command output may contain sensitive data and /tmp is world-readable.
340+
const homeDir = os.homedir();
341+
const tmpDir = path.join(homeDir, ".cmux-tmp");
342+
343+
// Ensure directory exists with secure permissions (user-only)
344+
if (!fs.existsSync(tmpDir)) {
345+
fs.mkdirSync(tmpDir, { mode: 0o700 });
346+
}
347+
338348
// Use 8 hex characters for short, memorable temp file IDs
339349
const fileId = Math.random().toString(16).substring(2, 10);
340350
const overflowPath = path.join(tmpDir, `bash-${fileId}.txt`);
@@ -345,11 +355,7 @@ export const createBashTool: ToolFactory = (config: ToolConfiguration) => {
345355
346356
Full output (${lines.length} lines) saved to ${overflowPath}
347357
348-
Use filtering tools to extract what you need:
349-
- grep '<pattern>' ${overflowPath}
350-
- head -n 300 ${overflowPath}
351-
- tail -n 300 ${overflowPath}
352-
- sed -n '100,400p' ${overflowPath}
358+
Use selective filtering tools (e.g. grep) to extract relevant information and continue your task
353359
354360
When done, clean up: rm ${overflowPath}`;
355361

0 commit comments

Comments
 (0)