Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/local-agent-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ assert.deepEqual(inherited, {
OPENAI_API_KEY: "inherited",
UNCHANGED: "yes",
});
{
// Windows environment blocks commonly store "Path"; a spread drops the
// case-insensitive process.env.PATH lookup that command resolution relies on.
const windowsInherited = { Path: "C:\\tools;C:\\Windows", Other: "kept" };
const providerEnv = localAgentProviderEnvironment(
subagentsConfigSchema.parse({ enabled: true, providers: [{ id: "codex", enabled: true }] }),
"codex",
windowsInherited,
);
assert.equal(providerEnv.PATH, "C:\\tools;C:\\Windows");
assert.equal(providerEnv.Path, "C:\\tools;C:\\Windows");
assert.equal(providerEnv.Other, "kept");
}
assert.equal(
localAgentProviderConfigRevision(config),
localAgentProviderConfigRevision(subagentsConfigSchema.parse({
Expand Down
12 changes: 12 additions & 0 deletions src/local-agent-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,24 @@ export function localAgentProviderEnvironment(
): NodeJS.ProcessEnv {
const providerConfig = subagentProviderConfig(config, provider);
const env = { ...inherited, ...providerConfig?.env };
// process.env lookups are case-insensitive on Windows, but spreading copies
// only the original key casing (commonly "Path"); consumers reading the
// plain object's env.PATH then miss. Restore the canonical keys.
const pathValue = environmentValueCaseInsensitive(inherited, "PATH");
if (env.PATH === undefined && pathValue !== undefined) env.PATH = pathValue;
const pathExtValue = environmentValueCaseInsensitive(inherited, "PATHEXT");
if (env.PATHEXT === undefined && pathExtValue !== undefined) env.PATHEXT = pathExtValue;
const commandVariable = providerCommandVariable(provider);
const command = providerConfig && "command" in providerConfig ? providerConfig.command : undefined;
if (commandVariable && command) env[commandVariable] = command;
return env;
}

function environmentValueCaseInsensitive(env: NodeJS.ProcessEnv, key: string): string | undefined {
const found = Object.keys(env).find((entry) => entry.toUpperCase() === key);
return found === undefined ? undefined : env[found];
}

export function localAgentProviderEnvironmentOverrides(
config: SubagentsConfig,
provider: LocalAgentProvider,
Expand Down