Skip to content

Commit ce0e24d

Browse files
committed
Fix path expansion: return absolute path from createTempDirForStream
The previous implementation returned '~/.cmux-tmp/{token}' which is not an absolute path. This would fail when passed to runtime.writeFile() in LocalRuntime, as fs operations don't expand tilde. Solution: Use 'mkdir -p ~/.cmux-tmp/{token} && cd ... && pwd' to get the absolute path after creation. This works for both LocalRuntime and SSHRuntime: - LocalRuntime: returns '/home/user/.cmux-tmp/{token}' - SSHRuntime: returns '/home/remoteuser/.cmux-tmp/{token}' (remote path) Also switched to execBuffered() helper for cleaner code.
1 parent 9edb677 commit ce0e24d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/services/streamManager.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { AsyncMutex } from "@/utils/concurrency/asyncMutex";
3232
import type { ToolPolicy } from "@/utils/tools/toolPolicy";
3333
import { StreamingTokenTracker } from "@/utils/main/StreamingTokenTracker";
3434
import type { Runtime } from "@/runtime/Runtime";
35+
import { execBuffered } from "@/utils/runtime/helpers";
3536

3637
// Type definitions for stream parts with extended properties
3738
interface ReasoningDeltaPart {
@@ -252,18 +253,22 @@ export class StreamManager extends EventEmitter {
252253
streamToken: StreamToken,
253254
runtime: Runtime
254255
): Promise<string> {
255-
const tempDir = path.join("~", ".cmux-tmp", streamToken);
256-
// Use runtime.exec() to create directory (works for both local and remote)
257-
const result = await runtime.exec(`mkdir -p "${tempDir}"`, {
258-
cwd: "~",
256+
// Create directory and get absolute path (works for both local and remote)
257+
// Use 'cd' + 'pwd' to resolve ~ to absolute path
258+
const command = `mkdir -p ~/.cmux-tmp/${streamToken} && cd ~/.cmux-tmp/${streamToken} && pwd`;
259+
const result = await execBuffered(runtime, command, {
260+
cwd: "/",
259261
timeout: 10,
260262
});
261-
// Wait for command to complete
262-
const exitCode = await result.exitCode;
263-
if (exitCode !== 0) {
264-
throw new Error(`Failed to create temp directory ${tempDir}: exit code ${exitCode}`);
263+
264+
if (result.exitCode !== 0) {
265+
throw new Error(
266+
`Failed to create temp directory ~/.cmux-tmp/${streamToken}: exit code ${result.exitCode}`
267+
);
265268
}
266-
return tempDir;
269+
270+
// Return absolute path (e.g., "/home/user/.cmux-tmp/abc123")
271+
return result.stdout.trim();
267272
}
268273

269274
/**

0 commit comments

Comments
 (0)