Skip to content

Commit 88b0c80

Browse files
committed
Fix bash tool to use runtime-appropriate temp directory
- Changed overflow file path from config.tempDir to {cwd}/.cmux/tmp/ - This fixes SSH runtime support where config.tempDir was a local path - Runtime.writeFile() expects runtime-appropriate paths (remote for SSH) - Updated test to verify files are created in .cmux/tmp subdirectory
1 parent 2ee355f commit 88b0c80

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/services/tools/bash.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createBashTool } from "./bash";
33
import type { BashToolArgs, BashToolResult } from "@/types/tools";
44
import { BASH_MAX_TOTAL_BYTES } from "@/constants/toolLimits";
55
import * as fs from "fs";
6+
import * as path from "path";
67
import { TestTempDir } from "./testHelpers";
78
import { createRuntime } from "@/runtime/runtimeFactory";
89

@@ -269,7 +270,7 @@ describe("bash tool", () => {
269270
it("should use tmpfile policy by default when overflow_policy not specified", async () => {
270271
const tempDir = new TestTempDir("test-bash-default");
271272
const tool = createBashTool({
272-
cwd: process.cwd(),
273+
cwd: tempDir.path, // Use tempDir as cwd so we can verify file creation
273274
runtime: createRuntime({ type: "local", srcBaseDir: "/tmp" }),
274275
tempDir: tempDir.path,
275276
// overflow_policy not specified - should default to tmpfile
@@ -289,8 +290,10 @@ describe("bash tool", () => {
289290
expect(result.error).toContain("saved to");
290291
expect(result.error).not.toContain("[OUTPUT TRUNCATED");
291292

292-
// Verify temp file was created
293-
const files = fs.readdirSync(tempDir.path);
293+
// Verify temp file was created in .cmux/tmp subdirectory
294+
const cmuxTmpDir = path.join(tempDir.path, ".cmux", "tmp");
295+
expect(fs.existsSync(cmuxTmpDir)).toBe(true);
296+
const files = fs.readdirSync(cmuxTmpDir);
294297
const bashFiles = files.filter((f) => f.startsWith("bash-"));
295298
expect(bashFiles.length).toBe(1);
296299
}

src/services/tools/bash.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,9 @@ export const createBashTool: ToolFactory = (config: ToolConfiguration) => {
421421
try {
422422
// Use 8 hex characters for short, memorable temp file IDs
423423
const fileId = Math.random().toString(16).substring(2, 10);
424-
const overflowPath = path.join(config.tempDir, `bash-${fileId}.txt`);
424+
// Write to .cmux/tmp directory relative to cwd for runtime-agnostic path
425+
// This works for both LocalRuntime (local path) and SSHRuntime (remote path)
426+
const overflowPath = path.join(config.cwd, ".cmux", "tmp", `bash-${fileId}.txt`);
425427
const fullOutput = lines.join("\n");
426428

427429
// Use runtime.writeFile() for SSH support

0 commit comments

Comments
 (0)