Replace NodeJS dict aliases with maps and named field reads
Agents / agent (pull_request) Has been skipped
Check / check (pull_request) Successful in 49s

This commit is contained in:
Danny Kim
2026-10-19 02:30:54 +09:00
parent 32806120b3
commit c8ffb9cc6f
15 changed files with 275 additions and 196 deletions
+13 -9
View File
@@ -80,8 +80,12 @@ export function runProfiles<T, P extends ProfileIdentity>(
return attemptFrom(profiles, attempt, failures, 0);
}
export function sanitizedEnvironment(environment: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
const result: NodeJS.ProcessEnv = {};
// Environments are maps from variable name to value, converted to the object
// form only where a child process is spawned.
export function sanitizedEnvironment(
environment: ReadonlyMap<string, string>,
): Map<string, string> {
const result: Map<string, string> = new Map();
for (const name of [
"PATH",
"HOME",
@@ -108,27 +112,27 @@ export function sanitizedEnvironment(environment: NodeJS.ProcessEnv): NodeJS.Pro
"SSL_CERT_DIR",
"NODE_EXTRA_CA_CERTS",
]) {
const value = environment[name];
if (value !== undefined) result[name] = value;
const value = environment.get(name);
if (value !== undefined) result.set(name, value);
}
return result;
}
export function agentEnvironment(
environment: NodeJS.ProcessEnv,
environment: ReadonlyMap<string, string>,
profile: ProfileHome,
token?: string,
): NodeJS.ProcessEnv {
): Map<string, string> {
const result = sanitizedEnvironment(environment);
result["HOME"] = profile.home;
if (profile.type === "codex") result["CODEX_HOME"] = `${profile.home}/.codex`;
result.set("HOME", profile.home);
if (profile.type === "codex") result.set("CODEX_HOME", `${profile.home}/.codex`);
if (token !== undefined && token !== "") {
const tokenName = {
claude: "CLAUDE_CODE_OAUTH_TOKEN",
codex: "OPENAI_API_KEY",
opencode: "OPENROUTER_API_KEY",
}[profile.type];
result[tokenName] = token;
result.set(tokenName, token);
}
return result;
}