codex-multi-auth 2.0.0 → 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.
- package/README.md +13 -10
- package/config/README.md +4 -4
- package/config/codex-legacy.json +45 -120
- package/config/codex-modern.json +36 -52
- package/config/minimal-codex.json +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +85 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/auth/device-auth.d.ts +46 -0
- package/dist/lib/auth/device-auth.d.ts.map +1 -0
- package/dist/lib/auth/device-auth.js +325 -0
- package/dist/lib/auth/device-auth.js.map +1 -0
- package/dist/lib/auth/index.d.ts +2 -0
- package/dist/lib/auth/index.d.ts.map +1 -1
- package/dist/lib/auth/index.js +1 -0
- package/dist/lib/auth/index.js.map +1 -1
- package/dist/lib/auto-update-checker.d.ts +23 -1
- package/dist/lib/auto-update-checker.d.ts.map +1 -1
- package/dist/lib/auto-update-checker.js +481 -8
- package/dist/lib/auto-update-checker.js.map +1 -1
- package/dist/lib/cli.d.ts +5 -0
- package/dist/lib/cli.d.ts.map +1 -1
- package/dist/lib/cli.js.map +1 -1
- package/dist/lib/codex-manager/commands/best.js +1 -1
- package/dist/lib/codex-manager/commands/best.js.map +1 -1
- package/dist/lib/codex-manager/commands/forecast.js +3 -3
- package/dist/lib/codex-manager/commands/forecast.js.map +1 -1
- package/dist/lib/codex-manager/commands/report.js +3 -3
- package/dist/lib/codex-manager/commands/report.js.map +1 -1
- package/dist/lib/codex-manager/commands/rotation.d.ts +4 -0
- package/dist/lib/codex-manager/commands/rotation.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/rotation.js +37 -11
- package/dist/lib/codex-manager/commands/rotation.js.map +1 -1
- package/dist/lib/codex-manager/commands/status.d.ts +6 -0
- package/dist/lib/codex-manager/commands/status.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/status.js +26 -3
- package/dist/lib/codex-manager/commands/status.js.map +1 -1
- package/dist/lib/codex-manager/forecast-report-commands.js +4 -4
- package/dist/lib/codex-manager/forecast-report-commands.js.map +1 -1
- package/dist/lib/codex-manager/help.d.ts +1 -0
- package/dist/lib/codex-manager/help.d.ts.map +1 -1
- package/dist/lib/codex-manager/help.js +20 -3
- package/dist/lib/codex-manager/help.js.map +1 -1
- package/dist/lib/codex-manager/rate-limit-markers.d.ts +2 -0
- package/dist/lib/codex-manager/rate-limit-markers.d.ts.map +1 -0
- package/dist/lib/codex-manager/rate-limit-markers.js +4 -0
- package/dist/lib/codex-manager/rate-limit-markers.js.map +1 -0
- package/dist/lib/codex-manager/repair-commands.js +3 -3
- package/dist/lib/codex-manager/repair-commands.js.map +1 -1
- package/dist/lib/codex-manager.d.ts.map +1 -1
- package/dist/lib/codex-manager.js +78 -91
- package/dist/lib/codex-manager.js.map +1 -1
- package/dist/lib/config.js +2 -2
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/prompts/codex.d.ts +1 -1
- package/dist/lib/prompts/codex.d.ts.map +1 -1
- package/dist/lib/prompts/codex.js +3 -3
- package/dist/lib/prompts/codex.js.map +1 -1
- package/dist/lib/quota-probe.js +1 -1
- package/dist/lib/quota-probe.js.map +1 -1
- package/dist/lib/quota-readiness.d.ts +16 -0
- package/dist/lib/quota-readiness.d.ts.map +1 -0
- package/dist/lib/quota-readiness.js +82 -0
- package/dist/lib/quota-readiness.js.map +1 -0
- package/dist/lib/request/fetch-helpers.d.ts.map +1 -1
- package/dist/lib/request/fetch-helpers.js +19 -8
- package/dist/lib/request/fetch-helpers.js.map +1 -1
- package/dist/lib/request/helpers/model-map.d.ts +2 -1
- package/dist/lib/request/helpers/model-map.d.ts.map +1 -1
- package/dist/lib/request/helpers/model-map.js +52 -60
- package/dist/lib/request/helpers/model-map.js.map +1 -1
- package/dist/lib/request/request-transformer.d.ts +2 -2
- package/dist/lib/request/request-transformer.js +4 -3
- package/dist/lib/request/request-transformer.js.map +1 -1
- package/dist/lib/runtime/login-menu-accounts.d.ts +5 -0
- package/dist/lib/runtime/login-menu-accounts.d.ts.map +1 -1
- package/dist/lib/runtime/login-menu-accounts.js +7 -2
- package/dist/lib/runtime/login-menu-accounts.js.map +1 -1
- package/dist/lib/runtime/quota-probe.js +1 -1
- package/dist/lib/runtime/quota-probe.js.map +1 -1
- package/dist/lib/runtime/runtime-current-account.d.ts +52 -0
- package/dist/lib/runtime/runtime-current-account.d.ts.map +1 -0
- package/dist/lib/runtime/runtime-current-account.js +252 -0
- package/dist/lib/runtime/runtime-current-account.js.map +1 -0
- package/dist/lib/runtime-rotation-proxy.js +1 -1
- package/dist/lib/runtime-rotation-proxy.js.map +1 -1
- package/dist/lib/schemas.d.ts +3 -0
- package/dist/lib/schemas.d.ts.map +1 -1
- package/dist/lib/schemas.js +1 -0
- package/dist/lib/schemas.js.map +1 -1
- package/dist/lib/ui/auth-menu.d.ts +6 -1
- package/dist/lib/ui/auth-menu.d.ts.map +1 -1
- package/dist/lib/ui/auth-menu.js +22 -2
- package/dist/lib/ui/auth-menu.js.map +1 -1
- package/package.json +1 -1
- package/scripts/bench-format/codex-host.mjs +142 -142
- package/scripts/bench-format/models.mjs +20 -22
- package/scripts/benchmark-edit-formats.mjs +9 -9
- package/scripts/codex-app-router.js +121 -121
- package/scripts/codex.js +3636 -3473
- package/scripts/postinstall.js +120 -14
|
@@ -2,12 +2,10 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { resolveCodexExecutable } from "./codex-host.mjs";
|
|
3
3
|
|
|
4
4
|
const FALLBACK_OPENAI_CODEX_STABLE = [
|
|
5
|
-
"openai/gpt-5-codex",
|
|
6
|
-
"openai/gpt-5.1-codex",
|
|
7
|
-
"openai/gpt-5.1-codex-mini",
|
|
8
|
-
"openai/gpt-5.1-codex-max",
|
|
9
|
-
"openai/gpt-5.2-codex",
|
|
10
5
|
"openai/gpt-5.3-codex",
|
|
6
|
+
"openai/gpt-5.4",
|
|
7
|
+
"openai/gpt-5.4-mini",
|
|
8
|
+
"openai/gpt-5.5",
|
|
11
9
|
];
|
|
12
10
|
|
|
13
11
|
const OPENAI_CODEX_PREFIXES = ["openai/", "openai-multi/"];
|
|
@@ -25,14 +23,14 @@ export function canonicalCodexModelId(modelId) {
|
|
|
25
23
|
return `openai/${codexTail(modelId)}`;
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
export function aliasCandidatesForCodexModel(modelId) {
|
|
29
|
-
if (!isOpenAiCodexProviderPrefix(modelId)) {
|
|
30
|
-
return [modelId];
|
|
31
|
-
}
|
|
32
|
-
const tail = codexTail(modelId);
|
|
33
|
-
const candidates = [`openai/${tail}`, `openai-multi/${tail}`];
|
|
34
|
-
return [...new Set([tail, modelId, ...candidates])];
|
|
35
|
-
}
|
|
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
|
+
}
|
|
36
34
|
|
|
37
35
|
export function isStableOpenAiCodexModel(modelId) {
|
|
38
36
|
if (!isOpenAiCodexProviderPrefix(modelId)) {
|
|
@@ -47,15 +45,15 @@ export function isStableOpenAiCodexModel(modelId) {
|
|
|
47
45
|
return true;
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
export function listCodexModels() {
|
|
51
|
-
const executable = resolveCodexExecutable();
|
|
52
|
-
const child = spawnSync(executable.command, [...(executable.argsPrefix ?? []), "models"], {
|
|
53
|
-
encoding: "utf8",
|
|
54
|
-
windowsHide: true,
|
|
55
|
-
shell: executable.shell,
|
|
56
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
57
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
58
|
-
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),
|
|
59
57
|
killSignal: "SIGKILL",
|
|
60
58
|
});
|
|
61
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-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
|
},
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
chmodSync,
|
|
5
|
-
closeSync,
|
|
6
|
-
fstatSync,
|
|
7
|
-
ftruncateSync,
|
|
8
|
-
mkdirSync,
|
|
9
|
-
openSync,
|
|
10
|
-
readFileSync,
|
|
11
|
-
renameSync,
|
|
12
|
-
rmSync,
|
|
13
|
-
statSync,
|
|
14
|
-
truncateSync,
|
|
15
|
-
writeSync,
|
|
16
|
-
writeFileSync,
|
|
17
|
-
} from "node:fs";
|
|
3
|
+
import {
|
|
4
|
+
chmodSync,
|
|
5
|
+
closeSync,
|
|
6
|
+
fstatSync,
|
|
7
|
+
ftruncateSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
openSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
renameSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
statSync,
|
|
14
|
+
truncateSync,
|
|
15
|
+
writeSync,
|
|
16
|
+
writeFileSync,
|
|
17
|
+
} from "node:fs";
|
|
18
18
|
import { basename, dirname, join } from "node:path";
|
|
19
19
|
import process from "node:process";
|
|
20
20
|
|
|
21
|
-
const DEFAULT_MAX_LOG_BYTES = 1024 * 1024;
|
|
22
|
-
const LOG_SIZE_CHECK_INTERVAL_MS = 60_000;
|
|
23
|
-
|
|
24
|
-
function parsePort(value) {
|
|
25
|
-
if (typeof value !== "string" && typeof value !== "number") return Number.NaN;
|
|
26
|
-
const text = String(value).trim();
|
|
21
|
+
const DEFAULT_MAX_LOG_BYTES = 1024 * 1024;
|
|
22
|
+
const LOG_SIZE_CHECK_INTERVAL_MS = 60_000;
|
|
23
|
+
|
|
24
|
+
function parsePort(value) {
|
|
25
|
+
if (typeof value !== "string" && typeof value !== "number") return Number.NaN;
|
|
26
|
+
const text = String(value).trim();
|
|
27
27
|
if (!/^\d+$/.test(text)) return Number.NaN;
|
|
28
28
|
const port = Number(text);
|
|
29
29
|
return Number.isInteger(port) && port >= 0 && port <= 65535
|
|
@@ -33,13 +33,13 @@ function parsePort(value) {
|
|
|
33
33
|
|
|
34
34
|
function parseArgs(argv) {
|
|
35
35
|
const result = {
|
|
36
|
-
host: "127.0.0.1",
|
|
37
|
-
port: 0,
|
|
38
|
-
statusPath: "",
|
|
39
|
-
statePath: "",
|
|
40
|
-
logPath: "",
|
|
41
|
-
maxLogBytes: DEFAULT_MAX_LOG_BYTES,
|
|
42
|
-
};
|
|
36
|
+
host: "127.0.0.1",
|
|
37
|
+
port: 0,
|
|
38
|
+
statusPath: "",
|
|
39
|
+
statePath: "",
|
|
40
|
+
logPath: "",
|
|
41
|
+
maxLogBytes: DEFAULT_MAX_LOG_BYTES,
|
|
42
|
+
};
|
|
43
43
|
for (let index = 0; index < argv.length; index += 1) {
|
|
44
44
|
const arg = argv[index];
|
|
45
45
|
const next = argv[index + 1] ?? "";
|
|
@@ -58,26 +58,26 @@ function parseArgs(argv) {
|
|
|
58
58
|
index += 1;
|
|
59
59
|
continue;
|
|
60
60
|
}
|
|
61
|
-
if (arg === "--state") {
|
|
62
|
-
result.statePath = next;
|
|
63
|
-
index += 1;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (arg === "--max-log-bytes") {
|
|
67
|
-
const parsed = Number.parseInt(next, 10);
|
|
68
|
-
result.maxLogBytes =
|
|
69
|
-
Number.isFinite(parsed) && parsed > 0
|
|
70
|
-
? parsed
|
|
71
|
-
: DEFAULT_MAX_LOG_BYTES;
|
|
72
|
-
index += 1;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
if (arg === "--log") {
|
|
76
|
-
result.logPath = next;
|
|
77
|
-
index += 1;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
61
|
+
if (arg === "--state") {
|
|
62
|
+
result.statePath = next;
|
|
63
|
+
index += 1;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (arg === "--max-log-bytes") {
|
|
67
|
+
const parsed = Number.parseInt(next, 10);
|
|
68
|
+
result.maxLogBytes =
|
|
69
|
+
Number.isFinite(parsed) && parsed > 0
|
|
70
|
+
? parsed
|
|
71
|
+
: DEFAULT_MAX_LOG_BYTES;
|
|
72
|
+
index += 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (arg === "--log") {
|
|
76
|
+
result.logPath = next;
|
|
77
|
+
index += 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
function readState(path) {
|
|
@@ -175,79 +175,79 @@ function isLoopbackHost(host) {
|
|
|
175
175
|
unbracketed === "::1" ||
|
|
176
176
|
unbracketed === "localhost"
|
|
177
177
|
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function truncateLogFdIfTooLarge(fd, maxBytes) {
|
|
181
|
-
if (!Number.isFinite(maxBytes) || maxBytes <= 0) return;
|
|
182
|
-
try {
|
|
183
|
-
const stats = fstatSync(fd);
|
|
184
|
-
if (!stats.isFile() || stats.size <= maxBytes) return;
|
|
185
|
-
ftruncateSync(fd, 0);
|
|
186
|
-
writeSync(
|
|
187
|
-
fd,
|
|
188
|
-
`codex-multi-auth app router log truncated after exceeding ${maxBytes} bytes\n`,
|
|
189
|
-
);
|
|
190
|
-
} catch {
|
|
191
|
-
// stdout/stderr may be pipes or otherwise unavailable; logging must not fail startup.
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function truncateLogPathIfTooLarge(logPath, maxBytes) {
|
|
196
|
-
if (!logPath || !Number.isFinite(maxBytes) || maxBytes <= 0) return false;
|
|
197
|
-
try {
|
|
198
|
-
const stats = statSync(logPath);
|
|
199
|
-
if (!stats.isFile() || stats.size <= maxBytes) return false;
|
|
200
|
-
truncateSync(logPath, 0);
|
|
201
|
-
return true;
|
|
202
|
-
} catch {
|
|
203
|
-
// Log path may not exist yet or may be locked; fd-level checks can still work.
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function writeLogTruncatedMarker(maxBytes) {
|
|
209
|
-
try {
|
|
210
|
-
writeSync(
|
|
211
|
-
1,
|
|
212
|
-
`codex-multi-auth app router log truncated after exceeding ${maxBytes} bytes\n`,
|
|
213
|
-
);
|
|
214
|
-
} catch {
|
|
215
|
-
// A closed stdout/stderr should not crash the router while enforcing log bounds.
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function installLogBounds(maxBytes, logPath) {
|
|
220
|
-
if (truncateLogPathIfTooLarge(logPath, maxBytes)) {
|
|
221
|
-
writeLogTruncatedMarker(maxBytes);
|
|
222
|
-
}
|
|
223
|
-
truncateLogFdIfTooLarge(1, maxBytes);
|
|
224
|
-
truncateLogFdIfTooLarge(2, maxBytes);
|
|
225
|
-
return setInterval(() => {
|
|
226
|
-
if (truncateLogPathIfTooLarge(logPath, maxBytes)) {
|
|
227
|
-
writeLogTruncatedMarker(maxBytes);
|
|
228
|
-
}
|
|
229
|
-
truncateLogFdIfTooLarge(1, maxBytes);
|
|
230
|
-
truncateLogFdIfTooLarge(2, maxBytes);
|
|
231
|
-
}, LOG_SIZE_CHECK_INTERVAL_MS);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
async function main() {
|
|
235
|
-
const args = parseArgs(process.argv.slice(2));
|
|
236
|
-
installLogBounds(args.maxLogBytes, args.logPath).unref?.();
|
|
237
|
-
const stateRecord = readState(args.statePath);
|
|
238
|
-
if (args.statePath && stateRecord === null) {
|
|
239
|
-
const error = new Error(
|
|
240
|
-
"Codex app runtime router state is unreadable; refusing to bind an ephemeral port.",
|
|
241
|
-
);
|
|
242
|
-
writeStatus(
|
|
243
|
-
args.statusPath,
|
|
244
|
-
createStatusPayload({ state: "error", proxyServer: null, error, stateRecord: null }),
|
|
245
|
-
);
|
|
246
|
-
throw error;
|
|
247
|
-
}
|
|
248
|
-
const host =
|
|
249
|
-
typeof stateRecord?.host === "string" && stateRecord.host.trim().length > 0
|
|
250
|
-
? stateRecord.host.trim()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function truncateLogFdIfTooLarge(fd, maxBytes) {
|
|
181
|
+
if (!Number.isFinite(maxBytes) || maxBytes <= 0) return;
|
|
182
|
+
try {
|
|
183
|
+
const stats = fstatSync(fd);
|
|
184
|
+
if (!stats.isFile() || stats.size <= maxBytes) return;
|
|
185
|
+
ftruncateSync(fd, 0);
|
|
186
|
+
writeSync(
|
|
187
|
+
fd,
|
|
188
|
+
`codex-multi-auth app router log truncated after exceeding ${maxBytes} bytes\n`,
|
|
189
|
+
);
|
|
190
|
+
} catch {
|
|
191
|
+
// stdout/stderr may be pipes or otherwise unavailable; logging must not fail startup.
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function truncateLogPathIfTooLarge(logPath, maxBytes) {
|
|
196
|
+
if (!logPath || !Number.isFinite(maxBytes) || maxBytes <= 0) return false;
|
|
197
|
+
try {
|
|
198
|
+
const stats = statSync(logPath);
|
|
199
|
+
if (!stats.isFile() || stats.size <= maxBytes) return false;
|
|
200
|
+
truncateSync(logPath, 0);
|
|
201
|
+
return true;
|
|
202
|
+
} catch {
|
|
203
|
+
// Log path may not exist yet or may be locked; fd-level checks can still work.
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function writeLogTruncatedMarker(maxBytes) {
|
|
209
|
+
try {
|
|
210
|
+
writeSync(
|
|
211
|
+
1,
|
|
212
|
+
`codex-multi-auth app router log truncated after exceeding ${maxBytes} bytes\n`,
|
|
213
|
+
);
|
|
214
|
+
} catch {
|
|
215
|
+
// A closed stdout/stderr should not crash the router while enforcing log bounds.
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function installLogBounds(maxBytes, logPath) {
|
|
220
|
+
if (truncateLogPathIfTooLarge(logPath, maxBytes)) {
|
|
221
|
+
writeLogTruncatedMarker(maxBytes);
|
|
222
|
+
}
|
|
223
|
+
truncateLogFdIfTooLarge(1, maxBytes);
|
|
224
|
+
truncateLogFdIfTooLarge(2, maxBytes);
|
|
225
|
+
return setInterval(() => {
|
|
226
|
+
if (truncateLogPathIfTooLarge(logPath, maxBytes)) {
|
|
227
|
+
writeLogTruncatedMarker(maxBytes);
|
|
228
|
+
}
|
|
229
|
+
truncateLogFdIfTooLarge(1, maxBytes);
|
|
230
|
+
truncateLogFdIfTooLarge(2, maxBytes);
|
|
231
|
+
}, LOG_SIZE_CHECK_INTERVAL_MS);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function main() {
|
|
235
|
+
const args = parseArgs(process.argv.slice(2));
|
|
236
|
+
installLogBounds(args.maxLogBytes, args.logPath).unref?.();
|
|
237
|
+
const stateRecord = readState(args.statePath);
|
|
238
|
+
if (args.statePath && stateRecord === null) {
|
|
239
|
+
const error = new Error(
|
|
240
|
+
"Codex app runtime router state is unreadable; refusing to bind an ephemeral port.",
|
|
241
|
+
);
|
|
242
|
+
writeStatus(
|
|
243
|
+
args.statusPath,
|
|
244
|
+
createStatusPayload({ state: "error", proxyServer: null, error, stateRecord: null }),
|
|
245
|
+
);
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
const host =
|
|
249
|
+
typeof stateRecord?.host === "string" && stateRecord.host.trim().length > 0
|
|
250
|
+
? stateRecord.host.trim()
|
|
251
251
|
: args.host;
|
|
252
252
|
const statePort = parsePort(stateRecord?.port);
|
|
253
253
|
const port = Number.isFinite(statePort) ? statePort : args.port;
|