Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 14, 2025

Fixes #7094

Problem

When Roo Code creates terminals (especially in remote SSH environments), it was not inheriting the user's PATH customizations and other environment variables from their shell configuration files. This meant that tools and commands available in the user's normal shell were not accessible in Roo's integrated terminal.

Solution

Modified Terminal.getEnv() to start with process.env and then apply Roo-specific overrides. This ensures that:

  • User PATH customizations are preserved
  • Shell aliases and custom environment variables are available
  • Roo-specific requirements (like VTE_VERSION, PAGER) are still properly set

Changes

  • Modified Terminal.getEnv() to inherit from process.env while filtering out undefined values
  • Added comprehensive tests for environment variable inheritance
  • Updated existing tests to use expect.objectContaining() for more flexible environment checks

Testing

  • Added new test suite Terminal.env.spec.ts with 11 tests covering environment inheritance
  • All existing terminal tests pass
  • TypeScript compilation successful
  • Linting passes

This change ensures that users working in remote SSH environments or with custom shell configurations will have their full environment available when Roo executes commands.


Important

Terminal.getEnv() now inherits user environment variables, preserving PATH and custom settings while applying Roo-specific overrides, with comprehensive tests added.

  • Behavior:
    • Terminal.getEnv() now starts with process.env to inherit user environment variables, preserving PATH and custom variables.
    • Roo-specific overrides like VTE_VERSION and PAGER are applied after inheriting user environment.
  • Testing:
    • Added Terminal.env.spec.ts with 11 tests for environment variable inheritance.
    • Updated tests in TerminalRegistry.spec.ts to use expect.objectContaining() for environment checks.
  • Misc:
    • Ensures full environment availability in remote SSH and custom shell configurations.

This description was created by Ellipsis for 6b50a26. You can customize this summary. It will automatically update as commits are pushed.

- Modified Terminal.getEnv() to start with process.env and apply Roo-specific overrides
- This ensures user PATH customizations and other environment variables are available in Roo terminals
- Added comprehensive tests for environment variable inheritance
- Updated existing tests to use expect.objectContaining() for environment checks

Fixes #7094
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 14, 2025 11:05
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 14, 2025
@dosubot dosubot bot added the bug Something isn't working label Aug 14, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.

// Start with the current process environment to inherit user's PATH and other customizations
// Filter out undefined values to satisfy the return type
const env: Record<string, string> = {}
for (const [key, value] of Object.entries(process.env)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security consideration: We're now inheriting ALL environment variables from process.env. While this solves the PATH issue perfectly, should we consider adding a whitelist/blacklist mechanism to filter out potentially sensitive variables like API keys or tokens? Some users might have secrets in their environment that shouldn't be exposed to terminal processes.

VTE_VERSION: "0",
// Start with the current process environment to inherit user's PATH and other customizations
// Filter out undefined values to satisfy the return type
const env: Record<string, string> = {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance thought: Would using Object.assign() with spread operator be more performant here? Something like:

Suggested change
const env: Record<string, string> = {}
// Start with the current process environment to inherit user's PATH and other customizations
// Filter out undefined values to satisfy the return type
const env: Record<string, string> = { ...process.env }
for (const key in env) {
if (env[key] === undefined) {
delete env[key]
}
}

Though the current approach is clear and works well.

expect(env.VTE_VERSION).toBe("0")
expect(env.PAGER).toBeDefined()
// PATH and HOME will be undefined but that's okay
expect(env.PATH).toBeUndefined()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice edge case testing! Though I wonder if we should set sensible defaults for essential variables like PATH when they're undefined? Some shell operations might fail without these critical variables.

// See https://wiki.gnome.org/Apps/Terminal/VTE
VTE_VERSION: "0",
// Start with the current process environment to inherit user's PATH and other customizations
// Filter out undefined values to satisfy the return type
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make this comment more explicit about WHY we filter undefined values? Something like: "Filter out undefined values to satisfy TypeScript's Record<string, string> return type"

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 14, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 16, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 16, 2025
@daniel-lxs
Copy link
Member

Closing this PR, the integrated shell won't have access to the user profile, the user should enable terminal integration instead.

@daniel-lxs daniel-lxs closed this Aug 19, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Aug 19, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Integrated shell missing commands

4 participants