* Create a temporary directory for a stream token * Use ~/.mux-tmp instead of system temp directory (e.g., /var/folders/...) * because macOS user-scoped temp paths are extremely long, which leads to: * - Agent mistakes when copying/manipulating paths * - Harder to read in tool outputs
(streamToken: StreamToken, runtime: Runtime)
| 831 | * Uses the Runtime abstraction so temp directories work for both local and SSH runtimes. |
| 832 | */ |
| 833 | public async createTempDirForStream(streamToken: StreamToken, runtime: Runtime): Promise<string> { |
| 834 | const tempDir = `~/.mux-tmp/${streamToken}`; |
| 835 | |
| 836 | // Resolve ~ in the runtime's context. |
| 837 | // |
| 838 | // IMPORTANT: On Windows local runtime, Git Bash may use a customized $HOME, |
| 839 | // while runtime.resolvePath expands ~ via Node (USERPROFILE). To avoid drift, |
| 840 | // create the directory using the resolved absolute path. |
| 841 | let resolvedPath = (await runtime.resolvePath(tempDir)).trim(); |
| 842 | |
| 843 | // In the main process, PlatformPaths defaults to POSIX behavior (no navigator), |
| 844 | // so we normalize Windows paths to forward slashes. |
| 845 | if (process.platform === "win32") { |
| 846 | resolvedPath = resolvedPath.replace(/\\/g, "/"); |
| 847 | } |
| 848 | |
| 849 | try { |
| 850 | await runtime.ensureDir(resolvedPath); |
| 851 | } catch (err) { |
| 852 | const msg = getErrorMessage(err); |
| 853 | throw new Error(`Failed to create temp directory ${resolvedPath}: ${msg}`); |
| 854 | } |
| 855 | |
| 856 | return resolvedPath; |
| 857 | } |
| 858 | |
| 859 | private cleanupStreamTempDir(runtime: Runtime, runtimeTempDir: string): void { |
| 860 | // Use parent directory as cwd for safety - if runtimeTempDir is malformed, |
no test coverage detected