codex-multi-auth 2.3.1 → 2.3.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,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-multi-auth",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "Install and operate codex-multi-auth for the official @openai/codex CLI with multi-account OAuth rotation, switching, health checks, and recovery tools.",
5
5
  "interface": {
6
6
  "composerIcon": "./assets/codex-multi-auth-icon.svg"
package/README.md CHANGED
@@ -383,7 +383,8 @@ codex-multi-auth doctor --json
383
383
 
384
384
  ## Release Notes
385
385
 
386
- - Current stable: [docs/releases/v2.3.1.md](docs/releases/v2.3.1.md) — install via `npm i -g codex-multi-auth`
386
+ - Current stable: [docs/releases/v2.3.2.md](docs/releases/v2.3.2.md) — install via `npm i -g codex-multi-auth`
387
+ - Previous stable: [docs/releases/v2.3.1.md](docs/releases/v2.3.1.md)
387
388
  - Previous stable: [docs/releases/v2.3.0.md](docs/releases/v2.3.0.md)
388
389
  - Previous stable: [docs/releases/v2.2.2.md](docs/releases/v2.2.2.md)
389
390
  - Previous stable: [docs/releases/v2.2.1.md](docs/releases/v2.2.1.md)
@@ -44,6 +44,13 @@ export interface AppBindRouterStatus {
44
44
  export interface AppBindStatus {
45
45
  bound: boolean;
46
46
  running: boolean;
47
+ /**
48
+ * True when config.toml is bound to the runtime proxy but the app-bind state
49
+ * file is gone (orphaned bind, #614). In this case `bound` is also true and
50
+ * `state` is null — the config needs `unbind-app` to recover even though the
51
+ * normal state-file tracking is missing.
52
+ */
53
+ unmanagedBind: boolean;
47
54
  state: AppBindState | null;
48
55
  router: AppBindRouterStatus | null;
49
56
  paths: AppBindPaths;
@@ -1 +1 @@
1
- {"version":3,"file":"app-bind.d.ts","sourceRoot":"","sources":["../../../lib/runtime/app-bind.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,YAAY;IAC5B,SAAS,EAAE,MAAM,CAAC;IACl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E,MAAM,CAAC;IAC9B,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AA+BD,wBAAgB,2BAA2B,CAC1C,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,YAAY,SAAK,GACf,MAAM,CAMR;AAED,wBAAgB,4BAA4B,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAKlG;AAgPD,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,cAAmB,GAAG,YAAY,CAwB9E;AAkMD,wBAAsB,gBAAgB,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CAqB3F;AAED,wBAAsB,2BAA2B,CAChD,OAAO,GAAE,cAAmB,GAC1B,OAAO,CAAC,aAAa,CAAC,CAKxB;AA+GD,wBAAsB,6BAA6B,CAClD,OAAO,GAAE,cAAmB,GAC1B,OAAO,CAAC,aAAa,CAAC,CAKxB;AAsFD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAsCjE"}
@@ -8,7 +8,7 @@ import process from "node:process";
8
8
  import { fileURLToPath } from "node:url";
9
9
  import { withFileOperationRetry } from "../fs-retry.js";
10
10
  import { getCodexMultiAuthDir } from "../runtime-paths.js";
11
- import { restoreConfigTomlFromRuntimeRotationProvider, rewriteConfigTomlForRuntimeRotationProvider, } from "./config-toml.js";
11
+ import { configHasRuntimeRotationProvider, restoreConfigTomlFromRuntimeRotationProvider, restoreConfigTomlFromRuntimeRotationProviderWithoutBackup, rewriteConfigTomlForRuntimeRotationProvider, } from "./config-toml.js";
12
12
  const APP_BIND_DIR_NAME = "app-bind";
13
13
  const APP_BIND_STATE_FILE = "runtime-rotation-app-bind.json";
14
14
  const APP_BIND_BACKUP_FILE = "codex-config-backup.json";
@@ -464,9 +464,19 @@ export async function getAppBindStatus(options = {}) {
464
464
  const paths = resolveAppBindPaths(options);
465
465
  const state = await readAppBindState(paths.statePath);
466
466
  const router = await readRouterStatus(paths.statusPath);
467
+ // When no state file is present, the bind may still be live in config.toml
468
+ // (orphaned bind, #614). Detect that from the config directly so status and
469
+ // downstream callers don't report a bound config as "not configured".
470
+ let unmanagedBind = false;
471
+ if (state === null) {
472
+ const current = await readConfigIfExists(paths.configPath);
473
+ unmanagedBind =
474
+ current.existed && configHasRuntimeRotationProvider(current.content);
475
+ }
467
476
  return {
468
- bound: state !== null,
477
+ bound: state !== null || unmanagedBind,
469
478
  running: router !== null && router.state === "running" && isProcessAlive(router.pid),
479
+ unmanagedBind,
470
480
  state,
471
481
  router,
472
482
  paths,
@@ -587,6 +597,7 @@ async function unbindCodexAppRuntimeRotationLocked(options, paths) {
587
597
  await removeAppBindStartup(state);
588
598
  }
589
599
  const backup = await readAppBindBackup(paths.backupPath);
600
+ let selfHealed = false;
590
601
  if (backup) {
591
602
  const current = await readConfigIfExists(backup.configPath);
592
603
  if (state && current.existed && sha256(current.content) !== state.boundConfigHash) {
@@ -606,6 +617,18 @@ async function unbindCodexAppRuntimeRotationLocked(options, paths) {
606
617
  await atomicWriteFile(state.configPath, restoreConfigTomlFromAppBind(current.content, ""));
607
618
  }
608
619
  }
620
+ else {
621
+ // Orphaned-bind recovery (#614): no backup and no state file, but the
622
+ // config may still be bound to the runtime proxy (e.g. the state/backup
623
+ // were lost while config.toml stayed rewritten). The state-file checks
624
+ // above can't see this, so consult the config directly and self-heal it
625
+ // back to a working provider when it is bound.
626
+ const current = await readConfigIfExists(paths.configPath);
627
+ if (current.existed && configHasRuntimeRotationProvider(current.content)) {
628
+ await atomicWriteFile(paths.configPath, restoreConfigTomlFromRuntimeRotationProviderWithoutBackup(current.content));
629
+ selfHealed = true;
630
+ }
631
+ }
609
632
  for (const candidate of [
610
633
  paths.statePath,
611
634
  paths.backupPath,
@@ -619,14 +642,32 @@ async function unbindCodexAppRuntimeRotationLocked(options, paths) {
619
642
  }
620
643
  }
621
644
  const status = await getAppBindStatus(options);
645
+ let message;
646
+ if (backup) {
647
+ message = `Unbound Codex app config ${backup.configPath}`;
648
+ }
649
+ else if (selfHealed) {
650
+ message = `Restored Codex app config ${paths.configPath} from an orphaned runtime-proxy bind (no backup was present)`;
651
+ }
652
+ else {
653
+ message = "Codex app bind was not configured";
654
+ }
622
655
  return {
623
656
  status,
624
- message: backup
625
- ? `Unbound Codex app config ${backup.configPath}`
626
- : "Codex app bind was not configured",
657
+ message,
627
658
  };
628
659
  }
629
660
  export function formatAppBindStatus(status) {
661
+ if (status.unmanagedBind && !status.state) {
662
+ return [
663
+ `Codex app bind: bound but unmanaged (config=${status.paths.configPath} points at the runtime proxy, but no app-bind state/backup is present)`,
664
+ [
665
+ "Run `codex-multi-auth rotation unbind-app` to restore the original",
666
+ "Codex provider/config. This recovers the orphaned bind even though no",
667
+ "backup was saved (#614).",
668
+ ].join(" "),
669
+ ].join("\n");
670
+ }
630
671
  if (!status.bound || !status.state)
631
672
  return "Codex app bind: not configured";
632
673
  const parts = [
@@ -3,4 +3,22 @@ export declare function restoreTopLevelModelProvider(currentConfig: string, orig
3
3
  export declare function restoreTopLevelResponseStorage(currentConfig: string, originalConfig: string): string;
4
4
  export declare function rewriteConfigTomlForRuntimeRotationProvider(rawConfig: string, baseUrl: string, clientApiKey?: string): string;
5
5
  export declare function restoreConfigTomlFromRuntimeRotationProvider(currentConfig: string, originalConfig: string): string;
6
+ /**
7
+ * Detects whether a config.toml is currently bound to the runtime rotation
8
+ * proxy — either the top-level `model_provider` points at the proxy id, or the
9
+ * proxy `[model_providers.<id>]` block is present. Used to recover an orphaned
10
+ * bind whose app-bind state/backup files were lost: in that situation the
11
+ * state-file-based status check reports "not configured" even though the config
12
+ * is still bound, so unbind/status must consult the config itself.
13
+ */
14
+ export declare function configHasRuntimeRotationProvider(rawConfig: string): boolean;
15
+ /**
16
+ * Restores a bound config when no backup of the user's original config exists
17
+ * (the orphaned-bind recovery path). Strips the proxy provider block and any
18
+ * bind-written top-level lines, and — because there is no original
19
+ * `model_provider` line to bring back — falls back to `defaultProvider`
20
+ * (Codex's native `"openai"`) so the config is left on a working provider
21
+ * rather than the dangling proxy id.
22
+ */
23
+ export declare function restoreConfigTomlFromRuntimeRotationProviderWithoutBackup(currentConfig: string, defaultProvider?: string): string;
6
24
  //# sourceMappingURL=config-toml.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config-toml.d.ts","sourceRoot":"","sources":["../../../lib/runtime/config-toml.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAqBvD;AA4FD,wBAAgB,4BAA4B,CAC3C,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACpB,MAAM,CAiCR;AAED,wBAAgB,8BAA8B,CAC7C,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACpB,MAAM,CAkDR;AA2BD,wBAAgB,2CAA2C,CAC1D,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,YAAY,SAAK,GACf,MAAM,CAkBR;AAED,wBAAgB,4CAA4C,CAC3D,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACpB,MAAM,CAYR"}
1
+ {"version":3,"file":"config-toml.d.ts","sourceRoot":"","sources":["../../../lib/runtime/config-toml.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAqBvD;AA4FD,wBAAgB,4BAA4B,CAC3C,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACpB,MAAM,CAiDR;AAED,wBAAgB,8BAA8B,CAC7C,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACpB,MAAM,CAkDR;AA2BD,wBAAgB,2CAA2C,CAC1D,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,YAAY,SAAK,GACf,MAAM,CAkBR;AAED,wBAAgB,4CAA4C,CAC3D,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACpB,MAAM,CAYR;AAED;;;;;;;GAOG;AACH,wBAAgB,gCAAgC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAoB3E;AAED;;;;;;;GAOG;AACH,wBAAgB,yDAAyD,CACxE,aAAa,EAAE,MAAM,EACrB,eAAe,SAAW,GACxB,MAAM,CAkBR"}
@@ -121,14 +121,32 @@ export function restoreTopLevelModelProvider(currentConfig, originalConfig) {
121
121
  output.push(line);
122
122
  }
123
123
  if (!handled && originalLine) {
124
- // Splice the restored line into the root table — appending at tail
125
- // would land it inside whatever section appears last in `output`.
126
- const firstSectionIdx = output.findIndex((line) => readTomlTableName(line) !== null);
127
- if (firstSectionIdx === -1) {
128
- output.push(originalLine);
129
- }
130
- else {
131
- output.splice(firstSectionIdx, 0, originalLine);
124
+ // Only splice the original line back when the current config has no
125
+ // top-level model_provider at all (bind stripped it). If a non-proxy
126
+ // top-level model_provider already exists — e.g. a half-orphaned config
127
+ // where the proxy block is present but the provider line already points
128
+ // elsewhere — inserting another line would create a duplicate top-level
129
+ // key and produce invalid TOML. In that case the existing line is
130
+ // already correct, so leave it untouched.
131
+ const hasTopLevelModelProvider = (() => {
132
+ for (const line of output) {
133
+ if (readTomlTableName(line) !== null)
134
+ return false;
135
+ if (/^\s*model_provider\s*=/.test(line))
136
+ return true;
137
+ }
138
+ return false;
139
+ })();
140
+ if (!hasTopLevelModelProvider) {
141
+ // Splice the restored line into the root table — appending at tail
142
+ // would land it inside whatever section appears last in `output`.
143
+ const firstSectionIdx = output.findIndex((line) => readTomlTableName(line) !== null);
144
+ if (firstSectionIdx === -1) {
145
+ output.push(originalLine);
146
+ }
147
+ else {
148
+ output.splice(firstSectionIdx, 0, originalLine);
149
+ }
132
150
  }
133
151
  }
134
152
  return output.join(lineEnding);
@@ -204,3 +222,56 @@ export function restoreConfigTomlFromRuntimeRotationProvider(currentConfig, orig
204
222
  const withResponseStorage = restoreTopLevelResponseStorage(withoutProvider, originalConfig);
205
223
  return ensureTomlTrailingNewline(restoreTopLevelModelProvider(withResponseStorage, originalConfig).replace(/[\r\n]*$/, ""));
206
224
  }
225
+ /**
226
+ * Detects whether a config.toml is currently bound to the runtime rotation
227
+ * proxy — either the top-level `model_provider` points at the proxy id, or the
228
+ * proxy `[model_providers.<id>]` block is present. Used to recover an orphaned
229
+ * bind whose app-bind state/backup files were lost: in that situation the
230
+ * state-file-based status check reports "not configured" even though the config
231
+ * is still bound, so unbind/status must consult the config itself.
232
+ */
233
+ export function configHasRuntimeRotationProvider(rawConfig) {
234
+ if (rawConfig.length === 0)
235
+ return false;
236
+ const providerTable = `model_providers.${RUNTIME_ROTATION_PROXY_PROVIDER_ID}`;
237
+ let inTopLevel = true;
238
+ for (const line of rawConfig.split(/\r?\n/)) {
239
+ const tableName = readTomlTableName(line);
240
+ if (tableName !== null) {
241
+ if (tableName === providerTable)
242
+ return true;
243
+ inTopLevel = false;
244
+ continue;
245
+ }
246
+ if (inTopLevel &&
247
+ /^\s*model_provider\s*=/.test(line) &&
248
+ line.includes(RUNTIME_ROTATION_PROXY_PROVIDER_ID)) {
249
+ return true;
250
+ }
251
+ }
252
+ return false;
253
+ }
254
+ /**
255
+ * Restores a bound config when no backup of the user's original config exists
256
+ * (the orphaned-bind recovery path). Strips the proxy provider block and any
257
+ * bind-written top-level lines, and — because there is no original
258
+ * `model_provider` line to bring back — falls back to `defaultProvider`
259
+ * (Codex's native `"openai"`) so the config is left on a working provider
260
+ * rather than the dangling proxy id.
261
+ */
262
+ export function restoreConfigTomlFromRuntimeRotationProviderWithoutBackup(currentConfig, defaultProvider = "openai") {
263
+ const lineEnding = currentConfig.includes("\r\n") ? "\r\n" : "\n";
264
+ // Synthesize a minimal "original" config carrying only the default
265
+ // top-level model_provider, so the shared restore path rewrites the proxy
266
+ // line back to a usable provider instead of leaving it dangling.
267
+ const syntheticOriginal = `model_provider = ${tomlStringLiteral(defaultProvider)}${lineEnding}`;
268
+ const restored = restoreConfigTomlFromRuntimeRotationProvider(currentConfig, syntheticOriginal);
269
+ // Normalize line endings to match the input config. The shared restore path
270
+ // derives its EOL from intermediate state, which can collapse to "\n" when
271
+ // the bound config was almost entirely proxy content; pin it back to the
272
+ // original style so a CRLF (Windows-authored) config stays CRLF.
273
+ if (lineEnding === "\r\n") {
274
+ return restored.replace(/\r?\n/g, "\r\n");
275
+ }
276
+ return restored.replace(/\r\n/g, "\n");
277
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-multi-auth",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "Codex CLI multi-account OAuth manager with account switching, health checks, runtime rotation, diagnostics, and recovery tools for @openai/codex",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",