codex-multi-auth 1.3.2 → 2.0.0

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.
Files changed (69) hide show
  1. package/README.md +39 -26
  2. package/config/README.md +3 -3
  3. package/dist/lib/codex-manager/commands/rotation.d.ts +22 -0
  4. package/dist/lib/codex-manager/commands/rotation.d.ts.map +1 -0
  5. package/dist/lib/codex-manager/commands/rotation.js +287 -0
  6. package/dist/lib/codex-manager/commands/rotation.js.map +1 -0
  7. package/dist/lib/codex-manager/commands/status.d.ts.map +1 -1
  8. package/dist/lib/codex-manager/commands/status.js +38 -7
  9. package/dist/lib/codex-manager/commands/status.js.map +1 -1
  10. package/dist/lib/codex-manager/help.d.ts.map +1 -1
  11. package/dist/lib/codex-manager/help.js +1 -0
  12. package/dist/lib/codex-manager/help.js.map +1 -1
  13. package/dist/lib/codex-manager.d.ts.map +1 -1
  14. package/dist/lib/codex-manager.js +59 -1
  15. package/dist/lib/codex-manager.js.map +1 -1
  16. package/dist/lib/config.d.ts +1 -0
  17. package/dist/lib/config.d.ts.map +1 -1
  18. package/dist/lib/config.js +9 -0
  19. package/dist/lib/config.js.map +1 -1
  20. package/dist/lib/constants.d.ts +2 -0
  21. package/dist/lib/constants.d.ts.map +1 -1
  22. package/dist/lib/constants.js +2 -0
  23. package/dist/lib/constants.js.map +1 -1
  24. package/dist/lib/fs-retry.d.ts +7 -0
  25. package/dist/lib/fs-retry.d.ts.map +1 -0
  26. package/dist/lib/fs-retry.js +35 -0
  27. package/dist/lib/fs-retry.js.map +1 -0
  28. package/dist/lib/index.d.ts +1 -0
  29. package/dist/lib/index.d.ts.map +1 -1
  30. package/dist/lib/index.js +1 -0
  31. package/dist/lib/index.js.map +1 -1
  32. package/dist/lib/logger.d.ts.map +1 -1
  33. package/dist/lib/logger.js +1 -0
  34. package/dist/lib/logger.js.map +1 -1
  35. package/dist/lib/runtime/app-bind.d.ts +74 -0
  36. package/dist/lib/runtime/app-bind.d.ts.map +1 -0
  37. package/dist/lib/runtime/app-bind.js +620 -0
  38. package/dist/lib/runtime/app-bind.js.map +1 -0
  39. package/dist/lib/runtime/config-toml.d.ts +10 -0
  40. package/dist/lib/runtime/config-toml.d.ts.map +1 -0
  41. package/dist/lib/runtime/config-toml.js +128 -0
  42. package/dist/lib/runtime/config-toml.js.map +1 -0
  43. package/dist/lib/runtime/runtime-observability.d.ts +5 -0
  44. package/dist/lib/runtime/runtime-observability.d.ts.map +1 -1
  45. package/dist/lib/runtime/runtime-observability.js +5 -0
  46. package/dist/lib/runtime/runtime-observability.js.map +1 -1
  47. package/dist/lib/runtime-constants.d.ts +3 -0
  48. package/dist/lib/runtime-constants.d.ts.map +1 -0
  49. package/dist/lib/runtime-constants.js +3 -0
  50. package/dist/lib/runtime-constants.js.map +1 -0
  51. package/dist/lib/runtime-rotation-proxy.d.ts +36 -0
  52. package/dist/lib/runtime-rotation-proxy.d.ts.map +1 -0
  53. package/dist/lib/runtime-rotation-proxy.js +828 -0
  54. package/dist/lib/runtime-rotation-proxy.js.map +1 -0
  55. package/dist/lib/schemas.d.ts +1 -0
  56. package/dist/lib/schemas.d.ts.map +1 -1
  57. package/dist/lib/schemas.js +1 -0
  58. package/dist/lib/schemas.js.map +1 -1
  59. package/package.json +13 -11
  60. package/scripts/bench-format/codex-host.mjs +142 -73
  61. package/scripts/bench-format/models.mjs +17 -16
  62. package/scripts/benchmark-edit-formats.mjs +8 -6
  63. package/scripts/check-pack-budget-lib.js +49 -6
  64. package/scripts/codex-app-launcher.js +653 -0
  65. package/scripts/codex-app-router.js +322 -0
  66. package/scripts/codex-multi-auth.js +3 -1
  67. package/scripts/codex-routing.js +6 -0
  68. package/scripts/codex.js +3390 -1570
  69. package/scripts/postinstall.js +237 -0
@@ -1,6 +1,15 @@
1
1
  import { exec } from "node:child_process";
2
2
  import { promisify } from "node:util";
3
3
 
4
+ /**
5
+ * @typedef {{ packageSize: number, paths: string[] }} ParsedPackMetadata
6
+ * @typedef {{ windowsHide: boolean, maxBuffer: number }} ExecOptions
7
+ * @typedef {{ stdout: string | Buffer, stderr?: string | Buffer }} ExecResult
8
+ * @typedef {(command: string, options: ExecOptions) => Promise<ExecResult>} ExecAsync
9
+ * @typedef {{ execAsync?: ExecAsync, log?: (message: string) => void }} RunPackBudgetDeps
10
+ */
11
+
12
+ /** @type {ExecAsync} */
4
13
  const execAsync = promisify(exec);
5
14
 
6
15
  export const MAX_PACKAGE_SIZE = 8 * 1024 * 1024;
@@ -25,18 +34,35 @@ export const FORBIDDEN_PREFIXES = [
25
34
  ".codex/",
26
35
  ];
27
36
 
37
+ /**
38
+ * @param {unknown} value
39
+ * @returns {value is Record<string, unknown>}
40
+ */
41
+ function isRecord(value) {
42
+ return typeof value === "object" && value !== null && !Array.isArray(value);
43
+ }
44
+
45
+ /**
46
+ * @param {string} filePath
47
+ * @returns {string}
48
+ */
28
49
  export function normalizePackPath(filePath) {
29
50
  return filePath.replaceAll("\\", "/");
30
51
  }
31
52
 
53
+ /**
54
+ * @param {string} stdout
55
+ * @returns {ParsedPackMetadata}
56
+ */
32
57
  export function parsePackMetadata(stdout) {
58
+ /** @type {unknown} */
33
59
  const packs = JSON.parse(stdout);
34
60
  if (!Array.isArray(packs) || packs.length === 0) {
35
61
  throw new Error("npm pack --dry-run --json returned no package metadata");
36
62
  }
37
63
 
38
64
  const pack = packs[0];
39
- if (!pack || !Array.isArray(pack.files)) {
65
+ if (!isRecord(pack) || !Array.isArray(pack.files)) {
40
66
  throw new Error("npm pack metadata did not include file list");
41
67
  }
42
68
 
@@ -46,13 +72,17 @@ export function parsePackMetadata(stdout) {
46
72
  }
47
73
 
48
74
  const paths = pack.files
49
- .map((file) => file?.path)
75
+ .map((file) => (isRecord(file) ? file.path : undefined))
50
76
  .filter((value) => typeof value === "string")
51
77
  .map((value) => normalizePackPath(value));
52
78
 
53
79
  return { packageSize, paths };
54
80
  }
55
81
 
82
+ /**
83
+ * @param {ParsedPackMetadata} metadata
84
+ * @returns {string}
85
+ */
56
86
  export function validatePackMetadata({ packageSize, paths }) {
57
87
  if (packageSize > MAX_PACKAGE_SIZE) {
58
88
  throw new Error(
@@ -83,20 +113,33 @@ export function validatePackMetadata({ packageSize, paths }) {
83
113
  return `Pack budget ok: ${packageSize} bytes across ${paths.length} files`;
84
114
  }
85
115
 
116
+ /**
117
+ * @param {RunPackBudgetDeps} [deps]
118
+ * @returns {Promise<string>}
119
+ */
86
120
  export async function runPackBudgetCheck(deps = {}) {
87
121
  const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
88
122
  const runExec = deps.execAsync ?? execAsync;
89
123
  const log = deps.log ?? console.log;
90
124
  let stdout = "";
91
125
  try {
92
- ({ stdout } = await runExec(`${npmCommand} pack --dry-run --json`, {
126
+ const result = await runExec(`${npmCommand} pack --dry-run --json`, {
93
127
  windowsHide: true,
94
128
  maxBuffer: 10 * 1024 * 1024,
95
- }));
129
+ });
130
+ if (result.stdout === null || result.stdout === undefined) {
131
+ throw new Error("npm pack --dry-run --json returned no stdout");
132
+ }
133
+ stdout =
134
+ typeof result.stdout === "string"
135
+ ? result.stdout
136
+ : result.stdout.toString("utf8");
96
137
  } catch (error) {
97
138
  const message = error instanceof Error ? error.message : String(error);
98
- const stdoutText = typeof error === "object" && error && "stdout" in error ? String(error.stdout ?? "") : "";
99
- const stderrText = typeof error === "object" && error && "stderr" in error ? String(error.stderr ?? "") : "";
139
+ const stdoutText =
140
+ isRecord(error) && "stdout" in error ? String(error.stdout ?? "") : "";
141
+ const stderrText =
142
+ isRecord(error) && "stderr" in error ? String(error.stderr ?? "") : "";
100
143
  throw new Error(`npm pack --dry-run --json failed via ${npmCommand}: ${message}${stdoutText ? `
101
144
  stdout: ${stdoutText.slice(0, 500)}` : ""}${stderrText ? `
102
145
  stderr: ${stderrText.slice(0, 500)}` : ""}`);