codex-multi-auth 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,39 +1,39 @@
1
- import { spawnSync } from "node:child_process";
2
- import { existsSync } from "node:fs";
3
- import { dirname, join, resolve } from "node:path";
4
- import { fileURLToPath } from "node:url";
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
5
 
6
6
  const scriptDir = dirname(fileURLToPath(import.meta.url));
7
7
  const repoRoot = resolve(scriptDir, "..", "..");
8
8
 
9
- export function getRepoRoot() {
10
- return repoRoot;
11
- }
12
-
13
- function resolveWindowsNpmShim(command) {
14
- if (!/\.(cmd|bat)$/i.test(command)) {
15
- return { command, shell: false };
16
- }
17
-
18
- const codexScript = join(dirname(command), "node_modules", "codex-multi-auth", "scripts", "codex.js");
19
- if (existsSync(codexScript)) {
20
- return {
21
- command: process.execPath,
22
- shell: false,
23
- argsPrefix: [codexScript],
24
- shimCommand: command,
25
- };
26
- }
27
-
28
- return { command, shell: true };
29
- }
30
-
31
- export function resolveCodexExecutable() {
32
- const envOverride = process.env.CODEX_BIN;
33
- if (envOverride && envOverride.trim().length > 0) {
34
- const command = envOverride.trim();
35
- return process.platform === "win32" ? resolveWindowsNpmShim(command) : { command, shell: false };
36
- }
9
+ export function getRepoRoot() {
10
+ return repoRoot;
11
+ }
12
+
13
+ function resolveWindowsNpmShim(command) {
14
+ if (!/\.(cmd|bat)$/i.test(command)) {
15
+ return { command, shell: false };
16
+ }
17
+
18
+ const codexScript = join(dirname(command), "node_modules", "codex-multi-auth", "scripts", "codex.js");
19
+ if (existsSync(codexScript)) {
20
+ return {
21
+ command: process.execPath,
22
+ shell: false,
23
+ argsPrefix: [codexScript],
24
+ shimCommand: command,
25
+ };
26
+ }
27
+
28
+ return { command, shell: true };
29
+ }
30
+
31
+ export function resolveCodexExecutable() {
32
+ const envOverride = process.env.CODEX_BIN;
33
+ if (envOverride && envOverride.trim().length > 0) {
34
+ const command = envOverride.trim();
35
+ return process.platform === "win32" ? resolveWindowsNpmShim(command) : { command, shell: false };
36
+ }
37
37
 
38
38
  if (process.platform !== "win32") {
39
39
  return { command: "codex", shell: false };
@@ -57,15 +57,15 @@ export function resolveCodexExecutable() {
57
57
  return { command: exactExe, shell: false };
58
58
  }
59
59
 
60
- const exactCmd = candidates.find((candidate) => /npm\\Codex\.cmd$/i.test(candidate));
61
- if (exactCmd) {
62
- return resolveWindowsNpmShim(exactCmd);
63
- }
64
-
65
- const anyCmd = candidates.find((candidate) => /\.cmd$/i.test(candidate));
66
- if (anyCmd) {
67
- return resolveWindowsNpmShim(anyCmd);
68
- }
60
+ const exactCmd = candidates.find((candidate) => /npm\\Codex\.cmd$/i.test(candidate));
61
+ if (exactCmd) {
62
+ return resolveWindowsNpmShim(exactCmd);
63
+ }
64
+
65
+ const anyCmd = candidates.find((candidate) => /\.cmd$/i.test(candidate));
66
+ if (anyCmd) {
67
+ return resolveWindowsNpmShim(anyCmd);
68
+ }
69
69
 
70
70
  return { command: candidates[0], shell: false };
71
71
  }
@@ -86,35 +86,35 @@ export function parseNdjson(text) {
86
86
  return events;
87
87
  }
88
88
 
89
- export function getToolEvents(events) {
90
- const legacyToolEvents = events
91
- .filter((event) => event?.type === "tool_use" && event?.part?.type === "tool")
92
- .map((event) => ({
93
- tool: event.part.tool,
94
- input: event.part.state?.input ?? {},
95
- output: event.part.state?.output,
89
+ export function getToolEvents(events) {
90
+ const legacyToolEvents = events
91
+ .filter((event) => event?.type === "tool_use" && event?.part?.type === "tool")
92
+ .map((event) => ({
93
+ tool: event.part.tool,
94
+ input: event.part.state?.input ?? {},
95
+ output: event.part.state?.output,
96
96
  status: event.part.state?.status,
97
97
  start: event.part.state?.time?.start,
98
98
  end: event.part.state?.time?.end,
99
99
  durationMs:
100
100
  typeof event.part.state?.time?.start === "number" &&
101
101
  typeof event.part.state?.time?.end === "number"
102
- ? event.part.state.time.end - event.part.state.time.start
103
- : null,
104
- }));
105
- const execToolEvents = events
106
- .filter((event) => event?.type === "item.completed" && event?.item?.type === "command_execution")
107
- .map((event) => ({
108
- tool: "command_execution",
109
- input: { command: event.item.command },
110
- output: event.item.aggregated_output,
111
- status: event.item.status,
112
- start: null,
113
- end: null,
114
- durationMs: null,
115
- }));
116
- return [...legacyToolEvents, ...execToolEvents];
117
- }
102
+ ? event.part.state.time.end - event.part.state.time.start
103
+ : null,
104
+ }));
105
+ const execToolEvents = events
106
+ .filter((event) => event?.type === "item.completed" && event?.item?.type === "command_execution")
107
+ .map((event) => ({
108
+ tool: "command_execution",
109
+ input: { command: event.item.command },
110
+ output: event.item.aggregated_output,
111
+ status: event.item.status,
112
+ start: null,
113
+ end: null,
114
+ durationMs: null,
115
+ }));
116
+ return [...legacyToolEvents, ...execToolEvents];
117
+ }
118
118
 
119
119
  export function getSessionDuration(events) {
120
120
  const starts = events
@@ -129,12 +129,12 @@ export function getSessionDuration(events) {
129
129
  return Math.max(...finishes) - Math.min(...starts);
130
130
  }
131
131
 
132
- export function getTokenTotals(events) {
133
- const stepFinishes = events.filter((event) => event?.type === "step_finish" && event?.part?.tokens);
134
- const turnCompletions = events.filter((event) => event?.type === "turn.completed" && event?.usage);
135
- if (stepFinishes.length === 0 && turnCompletions.length === 0) {
136
- return null;
137
- }
132
+ export function getTokenTotals(events) {
133
+ const stepFinishes = events.filter((event) => event?.type === "step_finish" && event?.part?.tokens);
134
+ const turnCompletions = events.filter((event) => event?.type === "turn.completed" && event?.usage);
135
+ if (stepFinishes.length === 0 && turnCompletions.length === 0) {
136
+ return null;
137
+ }
138
138
  const total = {
139
139
  total: 0,
140
140
  input: 0,
@@ -153,49 +153,49 @@ export function getTokenTotals(events) {
153
153
  total.input += input;
154
154
  total.output += output;
155
155
  total.reasoning += reasoning;
156
- total.cacheRead += Number(tokens.cache?.read ?? 0);
157
- total.cacheWrite += Number(tokens.cache?.write ?? 0);
158
- }
159
- for (const event of turnCompletions) {
160
- const usage = event.usage ?? {};
161
- const input = Number(usage.input_tokens ?? 0);
162
- const output = Number(usage.output_tokens ?? 0);
163
- const reasoning = Number(usage.reasoning_output_tokens ?? 0);
164
- total.total += input + output;
165
- total.input += input;
166
- total.output += output;
167
- total.reasoning += reasoning;
168
- total.cacheRead += Number(usage.cached_input_tokens ?? 0);
169
- }
170
- return total;
171
- }
156
+ total.cacheRead += Number(tokens.cache?.read ?? 0);
157
+ total.cacheWrite += Number(tokens.cache?.write ?? 0);
158
+ }
159
+ for (const event of turnCompletions) {
160
+ const usage = event.usage ?? {};
161
+ const input = Number(usage.input_tokens ?? 0);
162
+ const output = Number(usage.output_tokens ?? 0);
163
+ const reasoning = Number(usage.reasoning_output_tokens ?? 0);
164
+ total.total += input + output;
165
+ total.input += input;
166
+ total.output += output;
167
+ total.reasoning += reasoning;
168
+ total.cacheRead += Number(usage.cached_input_tokens ?? 0);
169
+ }
170
+ return total;
171
+ }
172
172
 
173
- export function getTextOutput(events) {
174
- const legacyText = events
175
- .filter((event) => event?.type === "text" && typeof event?.part?.text === "string")
176
- .map((event) => event.part.text)
177
- .join("\n");
178
- const execText = events
179
- .filter((event) => event?.type === "item.completed" && event?.item?.type === "agent_message" && typeof event.item.text === "string")
180
- .map((event) => event.item.text)
181
- .join("\n");
182
- return [legacyText, execText].filter(Boolean).join("\n");
183
- }
184
-
185
- export function getEventError(events) {
186
- const lastCompletedIndex = events.findLastIndex((event) => event?.type === "turn.completed");
187
- const failureIndex = events.findLastIndex(
188
- (event, index) => index > lastCompletedIndex && (event?.type === "error" || event?.type === "turn.failed"),
189
- );
190
- if (failureIndex < 0) {
191
- return null;
192
- }
193
- const errorEvent = events[failureIndex];
194
- return {
195
- name: errorEvent.error?.name ?? errorEvent.type ?? "UnknownError",
196
- message: errorEvent.error?.data?.message ?? errorEvent.error?.message ?? errorEvent.message ?? "Unknown error",
197
- };
198
- }
173
+ export function getTextOutput(events) {
174
+ const legacyText = events
175
+ .filter((event) => event?.type === "text" && typeof event?.part?.text === "string")
176
+ .map((event) => event.part.text)
177
+ .join("\n");
178
+ const execText = events
179
+ .filter((event) => event?.type === "item.completed" && event?.item?.type === "agent_message" && typeof event.item.text === "string")
180
+ .map((event) => event.item.text)
181
+ .join("\n");
182
+ return [legacyText, execText].filter(Boolean).join("\n");
183
+ }
184
+
185
+ export function getEventError(events) {
186
+ const lastCompletedIndex = events.findLastIndex((event) => event?.type === "turn.completed");
187
+ const failureIndex = events.findLastIndex(
188
+ (event, index) => index > lastCompletedIndex && (event?.type === "error" || event?.type === "turn.failed"),
189
+ );
190
+ if (failureIndex < 0) {
191
+ return null;
192
+ }
193
+ const errorEvent = events[failureIndex];
194
+ return {
195
+ name: errorEvent.error?.name ?? errorEvent.type ?? "UnknownError",
196
+ message: errorEvent.error?.data?.message ?? errorEvent.error?.message ?? errorEvent.message ?? "Unknown error",
197
+ };
198
+ }
199
199
 
200
200
  export function runCodexJson({
201
201
  executable,
@@ -207,33 +207,33 @@ export function runCodexJson({
207
207
  homeDir,
208
208
  timeoutMs,
209
209
  extraEnv,
210
- }) {
211
- const startWall = Date.now();
212
- const args = [
213
- "exec",
214
- "--json",
215
- "--model",
216
- model,
217
- "--skip-git-repo-check",
218
- "--sandbox",
219
- "danger-full-access",
220
- "-c",
221
- "approval_policy='never'",
222
- ];
223
- if (variant) {
224
- args.push("-c", `model_reasoning_effort='${variant}'`);
225
- }
226
- void agent;
227
- args.push(prompt);
228
- const childArgs = [...(executable.argsPrefix ?? []), ...args];
229
-
230
- const child = spawnSync(executable.command, childArgs, {
210
+ }) {
211
+ const startWall = Date.now();
212
+ const args = [
213
+ "exec",
214
+ "--json",
215
+ "--model",
216
+ model,
217
+ "--skip-git-repo-check",
218
+ "--sandbox",
219
+ "danger-full-access",
220
+ "-c",
221
+ "approval_policy='never'",
222
+ ];
223
+ if (variant) {
224
+ args.push("-c", `model_reasoning_effort='${variant}'`);
225
+ }
226
+ void agent;
227
+ args.push(prompt);
228
+ const childArgs = [...(executable.argsPrefix ?? []), ...args];
229
+
230
+ const child = spawnSync(executable.command, childArgs, {
231
231
  cwd: cwd ?? repoRoot,
232
232
  encoding: "utf8",
233
- windowsHide: true,
234
- shell: executable.shell,
235
- stdio: ["ignore", "pipe", "pipe"],
236
- timeout: timeoutMs,
233
+ windowsHide: true,
234
+ shell: executable.shell,
235
+ stdio: ["ignore", "pipe", "pipe"],
236
+ timeout: timeoutMs,
237
237
  maxBuffer: 30 * 1024 * 1024,
238
238
  env: {
239
239
  ...process.env,
@@ -254,11 +254,11 @@ export function runCodexJson({
254
254
  if (child.error && !timedOut) {
255
255
  throw child.error;
256
256
  }
257
- const failed = (child.status ?? 1) !== 0 || eventError !== null;
258
- const modelNotFound =
259
- failed &&
260
- (/Model not found|ProviderModelNotFoundError|model is not supported|not supported when using Codex/i.test(`${stdout}\n${stderr}`) ||
261
- /Model not found|model is not supported|not supported when using Codex/i.test(eventError?.message ?? ""));
257
+ const failed = (child.status ?? 1) !== 0 || eventError !== null;
258
+ const modelNotFound =
259
+ failed &&
260
+ (/Model not found|ProviderModelNotFoundError|model is not supported|not supported when using Codex/i.test(`${stdout}\n${stderr}`) ||
261
+ /Model not found|model is not supported|not supported when using Codex/i.test(eventError?.message ?? ""));
262
262
 
263
263
  return {
264
264
  status: child.status ?? 1,
@@ -1,12 +1,12 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import { resolveCodexExecutable } from "./codex-host.mjs";
3
3
 
4
- const FALLBACK_OPENAI_CODEX_STABLE = [
5
- "openai/gpt-5.3-codex",
6
- "openai/gpt-5.4",
7
- "openai/gpt-5.4-mini",
8
- "openai/gpt-5.5",
9
- ];
4
+ const FALLBACK_OPENAI_CODEX_STABLE = [
5
+ "openai/gpt-5.3-codex",
6
+ "openai/gpt-5.4",
7
+ "openai/gpt-5.4-mini",
8
+ "openai/gpt-5.5",
9
+ ];
10
10
 
11
11
  const OPENAI_CODEX_PREFIXES = ["openai/", "openai-multi/"];
12
12
 
@@ -23,14 +23,14 @@ export function canonicalCodexModelId(modelId) {
23
23
  return `openai/${codexTail(modelId)}`;
24
24
  }
25
25
 
26
- export function aliasCandidatesForCodexModel(modelId) {
27
- if (!isOpenAiCodexProviderPrefix(modelId)) {
28
- return [modelId];
29
- }
30
- const tail = codexTail(modelId);
31
- const candidates = [`openai/${tail}`, `openai-multi/${tail}`];
32
- return [...new Set([tail, modelId, ...candidates])];
33
- }
26
+ export function aliasCandidatesForCodexModel(modelId) {
27
+ if (!isOpenAiCodexProviderPrefix(modelId)) {
28
+ return [modelId];
29
+ }
30
+ const tail = codexTail(modelId);
31
+ const candidates = [`openai/${tail}`, `openai-multi/${tail}`];
32
+ return [...new Set([tail, modelId, ...candidates])];
33
+ }
34
34
 
35
35
  export function isStableOpenAiCodexModel(modelId) {
36
36
  if (!isOpenAiCodexProviderPrefix(modelId)) {
@@ -45,15 +45,15 @@ export function isStableOpenAiCodexModel(modelId) {
45
45
  return true;
46
46
  }
47
47
 
48
- export function listCodexModels() {
49
- const executable = resolveCodexExecutable();
50
- const child = spawnSync(executable.command, [...(executable.argsPrefix ?? []), "models"], {
51
- encoding: "utf8",
52
- windowsHide: true,
53
- shell: executable.shell,
54
- stdio: ["ignore", "pipe", "pipe"],
55
- maxBuffer: 10 * 1024 * 1024,
56
- timeout: Number.parseInt(process.env.CODEX_MODELS_TIMEOUT_MS ?? "30000", 10),
48
+ export function listCodexModels() {
49
+ const executable = resolveCodexExecutable();
50
+ const child = spawnSync(executable.command, [...(executable.argsPrefix ?? []), "models"], {
51
+ encoding: "utf8",
52
+ windowsHide: true,
53
+ shell: executable.shell,
54
+ stdio: ["ignore", "pipe", "pipe"],
55
+ maxBuffer: 10 * 1024 * 1024,
56
+ timeout: Number.parseInt(process.env.CODEX_MODELS_TIMEOUT_MS ?? "30000", 10),
57
57
  killSignal: "SIGKILL",
58
58
  });
59
59
  if (child.error && child.error.code === "ETIMEDOUT") {
@@ -63,7 +63,7 @@ function printUsage() {
63
63
  " --help Show this help",
64
64
  "",
65
65
  "Examples:",
66
- " node scripts/benchmark-edit-formats.mjs --smoke --models=openai/gpt-5.3-codex",
66
+ " node scripts/benchmark-edit-formats.mjs --smoke --models=openai/gpt-5.3-codex",
67
67
  " node scripts/benchmark-edit-formats.mjs --preset=codex-core --warmup-runs=1 --measured-runs=5",
68
68
  ].join("\n"));
69
69
  }
@@ -588,14 +588,14 @@ function aggregateSummary({ options, runRecords, failures, startTime, endTime, e
588
588
  warmupRunsPerTask: options.warmupRuns,
589
589
  measuredRunsPerTask: options.measuredRuns,
590
590
  timeoutMs: options.timeoutMs,
591
- outputRoot: options.outputRoot,
592
- runDir: options.runDir,
593
- homeDir: options.homeDir || null,
594
- CodexCommand: executable.command,
595
- CodexArgsPrefix: executable.argsPrefix ?? [],
596
- CodexShimCommand: executable.shimCommand ?? null,
597
- CodexUsesShell: executable.shell,
598
- keepRawLogs: options.keepRawLogs,
591
+ outputRoot: options.outputRoot,
592
+ runDir: options.runDir,
593
+ homeDir: options.homeDir || null,
594
+ CodexCommand: executable.command,
595
+ CodexArgsPrefix: executable.argsPrefix ?? [],
596
+ CodexShimCommand: executable.shimCommand ?? null,
597
+ CodexUsesShell: executable.shell,
598
+ keepRawLogs: options.keepRawLogs,
599
599
  runCount: measuredRuns.length,
600
600
  warmupCount: warmupRuns.length,
601
601
  },