Skip to content

Commit d00be95

Browse files
fix(server): pick up newly installed provider CLIs on Windows refresh
Refresh was probing with a stale process PATH, so CLIs installed after launch stayed Not found until restart. Re-read User/Machine PATH (and known Codex dir) before re-probe. Co-authored-by: Cursor <[email protected]>
1 parent b73232b commit d00be95

5 files changed

Lines changed: 50 additions & 5 deletions

File tree

‎apps/desktop/src/shell/DesktopShellEnvironment.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ describe("DesktopShellEnvironment", () => {
229229
"C:\\Windows\\System32",
230230
"C:\\Users\\testuser\\AppData\\Roaming\\npm",
231231
"C:\\Users\\testuser\\AppData\\Local\\Programs\\nodejs",
232+
"C:\\Users\\testuser\\AppData\\Local\\Programs\\OpenAI\\Codex\\bin",
232233
"C:\\Users\\testuser\\AppData\\Local\\Volta\\bin",
233234
"C:\\Users\\testuser\\AppData\\Local\\pnpm",
234235
"C:\\Users\\testuser\\.local\\bin",

‎apps/desktop/src/shell/DesktopShellEnvironment.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,12 @@ const knownWindowsCliDirs = (env: NodeJS.ProcessEnv): ReadonlyArray<string> => [
201201
...trimNonEmpty(env.LOCALAPPDATA).pipe(
202202
Option.match({
203203
onNone: () => [],
204-
onSome: (value) => [`${value}\\Programs\\nodejs`, `${value}\\Volta\\bin`, `${value}\\pnpm`],
204+
onSome: (value) => [
205+
`${value}\\Programs\\nodejs`,
206+
`${value}\\Programs\\OpenAI\\Codex\\bin`,
207+
`${value}\\Volta\\bin`,
208+
`${value}\\pnpm`,
209+
],
205210
}),
206211
),
207212
...trimNonEmpty(env.USERPROFILE).pipe(
@@ -242,9 +247,21 @@ const captureWindowsEnvironmentCommand = (names: ReadonlyArray<string>) =>
242247
[
243248
"$ErrorActionPreference = 'Stop'",
244249
...names.flatMap((name) => {
250+
const valueStatements =
251+
name === "PATH"
252+
? [
253+
"$machine = [Environment]::GetEnvironmentVariable('PATH', 'Machine')",
254+
"$user = [Environment]::GetEnvironmentVariable('PATH', 'User')",
255+
"$parts = @()",
256+
"if ($null -ne $machine -and $machine.Length -gt 0) { $parts += $machine }",
257+
"if ($null -ne $user -and $user.Length -gt 0) { $parts += $user }",
258+
"$value = $parts -join ';'",
259+
]
260+
: [`$value = [Environment]::GetEnvironmentVariable('${name}')`];
261+
245262
return [
246263
`Write-Output '${startMarker(name)}'`,
247-
`$value = [Environment]::GetEnvironmentVariable('${name}')`,
264+
...valueStatements,
248265
"if ($null -ne $value -and $value.Length -gt 0) { Write-Output $value }",
249266
`Write-Output '${endMarker(name)}'`,
250267
];

‎apps/server/src/provider/Layers/ProviderRegistry.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import * as Stream from "effect/Stream";
4141
import * as Semaphore from "effect/Semaphore";
4242

4343
import { ServerConfig } from "../../config.ts";
44+
import { fixPath } from "../../os-jank.ts";
4445
import { ProviderInstanceRegistry } from "../Services/ProviderInstanceRegistry.ts";
4546
import { ProviderRegistry, type ProviderRegistryShape } from "../Services/ProviderRegistry.ts";
4647
import {
@@ -470,6 +471,7 @@ export const ProviderRegistryLive = Layer.effect(
470471
});
471472

472473
const refresh = Effect.fn("refresh")(function* (provider?: ProviderDriverKind) {
474+
yield* fixPath();
473475
if (provider === undefined) {
474476
return yield* refreshAll();
475477
}
@@ -488,6 +490,7 @@ export const ProviderRegistryLive = Layer.effect(
488490
const refreshInstance = Effect.fn("refreshInstance")(function* (
489491
instanceId: ProviderInstanceId,
490492
) {
493+
yield* fixPath();
491494
const sources = yield* getLiveSources;
492495
const providerSource = sources.find((candidate) => candidate.instanceId === instanceId);
493496
if (!providerSource) {

‎packages/shared/src/shell.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ describe("readEnvironmentFromWindowsShell", () => {
236236
expect.arrayContaining(["-NoLogo", "-NoProfile", "-NonInteractive", "-Command"]),
237237
{ encoding: "utf8", timeout: 5000 },
238238
);
239+
const command = execFile.mock.calls[0]?.[1]?.at(-1);
240+
expect(command).toContain("[Environment]::GetEnvironmentVariable('PATH', 'Machine')");
241+
expect(command).toContain("[Environment]::GetEnvironmentVariable('PATH', 'User')");
239242
});
240243

241244
it("strips CRLF delimiters from captured PowerShell values", () => {
@@ -334,6 +337,7 @@ describe("resolveKnownWindowsCliDirs", () => {
334337
).toEqual([
335338
"C:\\Users\\testuser\\AppData\\Roaming\\npm",
336339
"C:\\Users\\testuser\\AppData\\Local\\Programs\\nodejs",
340+
"C:\\Users\\testuser\\AppData\\Local\\Programs\\OpenAI\\Codex\\bin",
337341
"C:\\Users\\testuser\\AppData\\Local\\Volta\\bin",
338342
"C:\\Users\\testuser\\AppData\\Local\\pnpm",
339343
"C:\\Users\\testuser\\.local\\bin",
@@ -475,6 +479,7 @@ effectIt.layer(NodeServices.layer)("resolveWindowsEnvironment", (it) => {
475479
PATH: [
476480
"C:\\Users\\testuser\\AppData\\Roaming\\npm",
477481
"C:\\Users\\testuser\\AppData\\Local\\Programs\\nodejs",
482+
"C:\\Users\\testuser\\AppData\\Local\\Programs\\OpenAI\\Codex\\bin",
478483
"C:\\Users\\testuser\\AppData\\Local\\Volta\\bin",
479484
"C:\\Users\\testuser\\AppData\\Local\\pnpm",
480485
"C:\\Users\\testuser\\.local\\bin",
@@ -524,6 +529,7 @@ effectIt.layer(NodeServices.layer)("resolveWindowsEnvironment", (it) => {
524529
"C:\\Windows\\System32",
525530
"C:\\Users\\testuser\\AppData\\Roaming\\npm",
526531
"C:\\Users\\testuser\\AppData\\Local\\Programs\\nodejs",
532+
"C:\\Users\\testuser\\AppData\\Local\\Programs\\OpenAI\\Codex\\bin",
527533
"C:\\Users\\testuser\\AppData\\Local\\Volta\\bin",
528534
"C:\\Users\\testuser\\AppData\\Local\\pnpm",
529535
"C:\\Users\\testuser\\.local\\bin",

‎packages/shared/src/shell.ts‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,21 @@ function buildWindowsEnvironmentCaptureCommand(names: ReadonlyArray<string>): st
269269
throw new Error(`Unsupported environment variable name: ${name}`);
270270
}
271271

272+
const valueStatements =
273+
name === "PATH"
274+
? [
275+
"$machine = [Environment]::GetEnvironmentVariable('PATH', 'Machine')",
276+
"$user = [Environment]::GetEnvironmentVariable('PATH', 'User')",
277+
"$parts = @()",
278+
"if ($null -ne $machine -and $machine.Length -gt 0) { $parts += $machine }",
279+
"if ($null -ne $user -and $user.Length -gt 0) { $parts += $user }",
280+
"$value = $parts -join ';'",
281+
]
282+
: [`$value = [Environment]::GetEnvironmentVariable('${name}')`];
283+
272284
return [
273285
`Write-Output '${envCaptureStart(name)}'`,
274-
`$value = [Environment]::GetEnvironmentVariable('${name}')`,
286+
...valueStatements,
275287
"if ($null -ne $value -and $value.Length -gt 0) { Write-Output $value }",
276288
`Write-Output '${envCaptureEnd(name)}'`,
277289
];
@@ -680,8 +692,14 @@ export function resolveKnownWindowsCliDirs(env: NodeJS.ProcessEnv): ReadonlyArra
680692

681693
return [
682694
...(appData ? [`${appData}\\npm`] : []),
683-
...(localAppData ? [`${localAppData}\\Programs\\nodejs`, `${localAppData}\\Volta\\bin`] : []),
684-
...(localAppData ? [`${localAppData}\\pnpm`] : []),
695+
...(localAppData
696+
? [
697+
`${localAppData}\\Programs\\nodejs`,
698+
`${localAppData}\\Programs\\OpenAI\\Codex\\bin`,
699+
`${localAppData}\\Volta\\bin`,
700+
`${localAppData}\\pnpm`,
701+
]
702+
: []),
685703
...(userProfile
686704
? [`${userProfile}\\.local\\bin`, `${userProfile}\\.bun\\bin`, `${userProfile}\\scoop\\shims`]
687705
: []),

0 commit comments

Comments
 (0)