Add -NoProfile to launched pwsh consoles#49
Conversation
📝 WalkthroughWalkthroughThis PR consolidates PowerShell launcher command-line construction across platform-specific implementations. A shared ChangesShared Launcher Command-Line Builders
🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
PowerShell.MCP.Proxy/Services/PowerShellProcessManager.cs (1)
316-325:⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy liftWindows launcher missing critical agentId escaping and startLocation handling.
The Windows launcher builds its command inline (lines 316-324) instead of using
BuildInitCommand, causing several inconsistencies with other platforms:
Critical: Line 319 and 323 construct
$global:PowerShellMCPAgentId = '{agentId}'without escaping single quotes. IfagentIdcontains a single quote (e.g.,"test'id"), the resulting PowerShell will be malformed:$global:PowerShellMCPAgentId = 'test'id', causing a syntax error or potential command injection.Major: The
startLocationparameter is ignored in the command construction (only used aslpCurrentDirectoryinCreateProcessWon line 335), whileBuildInitCommandincludesSet-Location -LiteralPathwith proper escaping (lines 205-207 inBuildInitCommand). This creates inconsistent behavior across platforms.Major: Missing
ModuleCaseFix(line 210 inBuildInitCommand) that handles case-sensitive file systems.🔧 Proposed fix to use BuildInitCommand for consistency
var proxyPid = Process.GetCurrentProcess().Id; - string command; - if (!string.IsNullOrEmpty(startupCommands)) - { - command = $"{PwshLauncherShared.EncodingPrelude}$global:PowerShellMCPProxyPid = {proxyPid}; $global:PowerShellMCPAgentId = '{agentId}'; Import-Module PowerShell.MCP -Force; Import-Module PSReadLine; {startupCommands}"; - } - else - { - command = $"{PwshLauncherShared.EncodingPrelude}$global:PowerShellMCPProxyPid = {proxyPid}; $global:PowerShellMCPAgentId = '{agentId}'; Import-Module PowerShell.MCP -Force; Import-Module PSReadLine"; - } + var initCommand = PwshLauncherShared.BuildInitCommand(proxyPid, agentId, startupCommands, startLocation); + // Windows imports PSReadLine explicitly (other platforms remove it to avoid conflicts) + var command = $"{initCommand}; Import-Module PSReadLine"; string commandLine = PwshLauncherShared.BuildWindowsCommandLine(command);Note: This changes Windows to remove PSReadLine then re-import it. If that's undesirable, add a parameter to
BuildInitCommandto control PSReadLine handling, or add the PSReadLine import inBuildInitCommandconditionally.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@PowerShell.MCP.Proxy/Services/PowerShellProcessManager.cs` around lines 316 - 325, Replace the inline Windows command construction in PowerShellProcessManager (the block that sets `command` and calls `PwshLauncherShared.BuildWindowsCommandLine`) with a call to the existing BuildInitCommand so agentId is properly escaped and startLocation and ModuleCaseFix are applied; specifically, call BuildInitCommand with the same inputs used elsewhere (agentId, proxyPid, startupCommands, startLocation) to produce the init command (it already applies literal-path Set-Location, escapes quotes, and handles ModuleCaseFix), then pass the resulting string through PwshLauncherShared.EncodingPrelude/BuildWindowsCommandLine as before and remove the duplicated manual `Import-Module`/PSReadLine logic (or if PSReadLine must differ on Windows, add a parameter to BuildInitCommand to control PSReadLine behavior and use that).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@PowerShell.MCP.Proxy/Services/PowerShellProcessManager.cs`:
- Around line 316-325: Replace the inline Windows command construction in
PowerShellProcessManager (the block that sets `command` and calls
`PwshLauncherShared.BuildWindowsCommandLine`) with a call to the existing
BuildInitCommand so agentId is properly escaped and startLocation and
ModuleCaseFix are applied; specifically, call BuildInitCommand with the same
inputs used elsewhere (agentId, proxyPid, startupCommands, startLocation) to
produce the init command (it already applies literal-path Set-Location, escapes
quotes, and handles ModuleCaseFix), then pass the resulting string through
PwshLauncherShared.EncodingPrelude/BuildWindowsCommandLine as before and remove
the duplicated manual `Import-Module`/PSReadLine logic (or if PSReadLine must
differ on Windows, add a parameter to BuildInitCommand to control PSReadLine
behavior and use that).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0ddf34e6-b286-4041-ba81-9fdeb49a1595
📒 Files selected for processing (2)
PowerShell.MCP.Proxy/Services/PowerShellProcessManager.csTests/Unit/Proxy/PwshLauncherSharedTests.cs
|
Thanks for this, @sharpninja — clean cross-platform work and I appreciate the test coverage on the launch argument builders. I want to be transparent about how I'm thinking about it, because the change bundles a refactor with a behavior change and I land differently on the two halves. On The launched consoles in this project aren't only automation targets. On Windows, macOS, and Linux, The headless path ( So my ask: could you narrow this PR to apply On the refactor itself. Each of the new builder methods has a single call site, so this is more indirection than de-duplication — there wasn't actually repeated launch-string code to consolidate (the four platforms each have a distinct command shape). I'm not opposed to a small shared helper, but I'd keep it minimal; happy to just take the headless Thanks again for the contribution — happy to merge once the |
|
How about making it optional? Driven by env variable? Cache the environment var on first use to static to avoid repeated registry calls. If we make it optional, then the new method becomes necessary. |
|
@sharpninja what's the actual motivation for I can't change the default to |
Summary
-NoProfileto everypwshlaunch path used bystart_consoleValidation
dotnet test Tests/PowerShell.MCP.Tests.csproj --configuration Release --no-restoredotnet build PowerShell.MCP.sln --configuration Release --no-restoreSummary by CodeRabbit
Refactor
Tests