Repository navigation
Refresh PATH and let npm shims run in bb's shells on Windows - #4731
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f71be879f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| POWERSHELL_EXECUTION_POLICY_VARIABLE, | ||
| ) === undefined | ||
| ) { | ||
| shellEnv[POWERSHELL_EXECUTION_POLICY_VARIABLE] = "RemoteSigned"; |
There was a problem hiding this comment.
Preserve explicitly configured execution policies
When a user has deliberately configured AllSigned or Restricted at CurrentUser or LocalMachine scope, unconditionally setting the process scope to RemoteSigned overrides that policy because PowerShell gives Process higher precedence. The environment-variable check only detects an already inherited process-scope setting, so ordinary Set-ExecutionPolicy -Scope CurrentUser ... configurations are silently weakened in every bb terminal and agent shell; inject this default only when no explicit non-Group-Policy scope has been configured.
Useful? React with 👍 / 👎.
| .replace( | ||
| WINDOWS_ENVIRONMENT_REFERENCE_PATTERN, | ||
| (reference, name: string) => | ||
| windowsEnvironmentValue(env, name) ?? reference, |
There was a problem hiding this comment.
Expand PATH using refreshed registry variables
When an installer adds both a new environment variable and a PATH entry referencing it, such as JAVA_HOME plus %JAVA_HOME%\bin, this expansion consults only the daemon's inherited environment. Since that long-running process cannot contain the newly installed variable, the refreshed PATH retains the literal reference and children still cannot find the installed executable, defeating the refresh for a common installer pattern. Read the relevant machine/user registry variables and expand against that refreshed environment before publishing PATH.
Useful? React with 👍 / 👎.
On Windows the daemon kept the PATH it started with, so a provider CLI installed afterwards was not found until bb restarted. The shell environment refresh now reads the machine and user Path values from the registry, expands their variable references, and keeps any inherited entries the registry does not list. Co-Authored-By: Claude Code <[email protected]>
The always-on introduction told every agent to invoke "$BB_CLI" directly, which is Bourne syntax and not runnable on Windows, where BB_CLI names a script that needs Node. The introduction and the bb-cli skill now say the examples use POSIX syntax and how to read an environment variable, chain commands, and continue a line in PowerShell. Co-Authored-By: Claude Code <[email protected]>
Windows client editions block every PowerShell script by default, and npm installs its commands as .ps1 shims, so npm, pnpm, and codex failed with 'running scripts is disabled' in bb terminals and agent shells. The shell environment bb hands to terminals, agents, and hooks now sets PSExecutionPolicyPreference to RemoteSigned for those processes only, unless the user already set it. Group Policy still wins. Co-Authored-By: Claude Code <[email protected]>
8f71be8 to
82960c6
Compare
Human comments
What was wrong
Three problems with the environment bb gives shells on Windows. Part of #1206.
PATHit started with.resolveUserShellCommandreturns no shell on Windows, so the periodic shell-environment refresh did nothing, and a provider CLI installed after bb started was not found until bb restarted..ps1shims. In bb terminals and agent shellsnpm,pnpm, andcodexfailed with "running scripts is disabled on this system"."$BB_CLI"directly. That is Bourne syntax, and on WindowsBB_CLInames a script that needs Node.What changed
Three commits:
apps/host-daemon/src/runtime-shell-env.ts): on Windows the refresh reads the machine and user environment from the registry withreg.exe, expands%VAR%references against those refreshed values (so%JAVA_HOME%\binworks when the installer addedJAVA_HOMEtoo), removes duplicates without regard to case, and appends inherited entries the registry does not list. If the machine environment cannot be read it keeps the previous result.PSExecutionPolicyPreference=RemoteSignedin the environment it hands to terminals, agents, and hooks on Windows, but only when nobody chose a policy:resolvePowerShellExecutionPolicyDefaultreturns nothing if the variable is already set, if the user or machine registry scope has anExecutionPolicy, or if a PowerShell 7powershell.config.json(user, or beside apwshon PATH) sets one. A process-scope value outranks those scopes, so setting it unconditionally would have weakened a deliberateAllSignedorRestricted. Group Policy still wins.RemoteSignedis the default on Windows Server and still requires a signature on downloaded scripts. The whole behavior is one option passed instart-host-daemon.ts.No wire or CLI changes.
How you verified
--command "Get-ExecutionPolicy -Scope Process"printedRemoteSigned, and--command "npm --version"exited 0 and printed the version (it failed before).Pathin the registry while bb was running, a terminal could not find a command in it; afterbb machine provider-cli statustriggered the refresh, a new terminal ran the command. bb was not restarted. The same worked with a new user variable and aPathentry of%THAT_VARIABLE%\bin.Set-ExecutionPolicy -Scope CurrentUser AllSigned, a new terminal reported process scopeUndefinedand effective policyAllSigned; after setting it back toUndefined, process scope wasRemoteSignedagain.runtime-shell-env.test.tscovers the registry read (expansion against refreshed variables, de-duplication, unreadable user or machine environment) and the policy default (offered only with no registry or config-file policy, never when the variable is set, the registry cannot be read, or off Windows); the bb-guide plugin tests pass. On this branch before the last rebase,turbo run lint typecheck test --filter='...[origin/main]': 20 of 20 tasks passed. After the rebase onto current main, lint and typecheck pass for the same filter.Not verified: a machine where Group Policy enforces a stricter execution policy.
🤖 Generated with Claude Code