Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

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:

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:

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

- Change parseRuntimeString to use ~/cmux instead of process.env.USER
- Backend resolves tildes via runtime.resolvePath() (from PR #451)
- Add eslint rule to prevent process.env usage in renderer code
- Prevents 'process is not defined' error in workspace creation

This fixes the regression introduced in PR #451 where chatCommands.ts
(renderer code) was trying to access process.env.USER to construct
SSH paths. Now we just use ~/cmux and let the backend resolve it.

ESLint rule catches future attempts to use process.env in renderer:
- Applies to src/**/*.ts(x) except main, preload, services, runtime, etc.
- Error: 'Renderer code cannot access process.env'

Generated with `cmux`
@ammario ammario merged commit 33d047c into main Oct 27, 2025
13 checks passed
@ammario ammario deleted the fix-process-env-renderer branch October 27, 2025 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants