Commit 33d047c
authored
🤖 Fix: Use tilde path in SSH runtime to avoid process.env in renderer (#458)
Fixes regression from #451 where was using `process.env.USER` in
renderer code, causing "process is not defined" error during workspace
creation.
## Problem
After merging #451, workspace creation fails with:
```
ReferenceError: process is not defined
at parseRuntimeString (chatCommands.ts:56:66)
```
The issue: `chatCommands.ts` is renderer code that was trying to access
`process.env.USER` to construct SSH default paths. The `process` global
is not available in Electron renderer processes.
## Solution
**Use tilde paths instead** - Now that we have tilde resolution from
#451, we can simply use `~/cmux` as the default SSH `srcBaseDir`. The
backend will resolve it via `runtime.resolvePath()`.
Before:
```typescript
const user = atIndex > 0 ? hostPart.substring(0, atIndex) : (process.env.USER ?? "user");
const homeDir = user === "root" ? "/root" : `/home/${user}`;
return {
type: "ssh",
host: hostPart,
srcBaseDir: `${homeDir}/cmux`,
};
```
After:
```typescript
return {
type: "ssh",
host: hostPart,
srcBaseDir: "~/cmux", // Backend resolves via runtime.resolvePath()
};
```
## ESLint Rule
Added `no-restricted-globals` and `no-restricted-syntax` rules to
prevent future `process.env` usage in renderer code:
- Applies to: `src/**/*.ts(x)`
- Excludes: main, preload, services, runtime, telemetry, utils/main,
utils/providers, tests
- Error message guides developers to use IPC or constants instead
This catches the issue at development time rather than runtime.
## Testing
- Unit tests updated to expect `~/cmux` instead of computed paths
- ESLint passes with new rules
- Workspace creation now works without process.env
_Generated with `cmux`_1 parent f36f7a4 commit 33d047c
File tree
3 files changed
+48
-22
lines changed- src/utils
3 files changed
+48
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
394 | 430 | | |
395 | 431 | | |
396 | 432 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
| 50 | + | |
53 | 51 | | |
54 | 52 | | |
55 | 53 | | |
56 | | - | |
| 54 | + | |
57 | 55 | | |
58 | 56 | | |
59 | 57 | | |
60 | 58 | | |
61 | 59 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 60 | + | |
65 | 61 | | |
66 | 62 | | |
67 | 63 | | |
68 | | - | |
| 64 | + | |
69 | 65 | | |
70 | 66 | | |
71 | 67 | | |
72 | | - | |
| 68 | + | |
73 | 69 | | |
| 70 | + | |
74 | 71 | | |
75 | 72 | | |
76 | 73 | | |
77 | | - | |
| 74 | + | |
78 | 75 | | |
79 | 76 | | |
80 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | 54 | | |
63 | 55 | | |
| 56 | + | |
64 | 57 | | |
65 | 58 | | |
66 | 59 | | |
67 | | - | |
| 60 | + | |
68 | 61 | | |
69 | 62 | | |
70 | 63 | | |
| |||
0 commit comments