codex-multi-auth 0.1.0 → 0.1.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.
Files changed (124) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +223 -98
  3. package/assets/readme-hero.svg +31 -31
  4. package/config/README.md +30 -87
  5. package/config/{opencode-legacy.json → codex-legacy.json} +571 -571
  6. package/config/{opencode-modern.json → codex-modern.json} +241 -239
  7. package/config/{minimal-opencode.json → minimal-codex.json} +15 -13
  8. package/config/schema/config.schema.json +21 -0
  9. package/dist/index.d.ts +5 -5
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +23 -20
  12. package/dist/index.js.map +1 -1
  13. package/dist/lib/accounts.d.ts +1 -1
  14. package/dist/lib/accounts.d.ts.map +1 -1
  15. package/dist/lib/auth/auth.d.ts +1 -1
  16. package/dist/lib/auth/auth.js +1 -1
  17. package/dist/lib/cli.d.ts +1 -1
  18. package/dist/lib/cli.js +4 -4
  19. package/dist/lib/cli.js.map +1 -1
  20. package/dist/lib/codex-manager/settings-hub.d.ts +6 -0
  21. package/dist/lib/codex-manager/settings-hub.d.ts.map +1 -0
  22. package/dist/lib/codex-manager/settings-hub.js +1786 -0
  23. package/dist/lib/codex-manager/settings-hub.js.map +1 -0
  24. package/dist/lib/codex-manager.d.ts.map +1 -1
  25. package/dist/lib/codex-manager.js +5 -1637
  26. package/dist/lib/codex-manager.js.map +1 -1
  27. package/dist/lib/config.d.ts.map +1 -1
  28. package/dist/lib/config.js +20 -11
  29. package/dist/lib/config.js.map +1 -1
  30. package/dist/lib/context-overflow.d.ts +1 -1
  31. package/dist/lib/context-overflow.js +11 -11
  32. package/dist/lib/oauth-success.html +1 -1
  33. package/dist/lib/prompts/codex-host-bridge.d.ts +19 -0
  34. package/dist/lib/prompts/codex-host-bridge.d.ts.map +1 -0
  35. package/dist/lib/prompts/{codex-opencode-bridge.js → codex-host-bridge.js} +143 -143
  36. package/dist/lib/prompts/codex-host-bridge.js.map +1 -0
  37. package/dist/lib/prompts/codex.d.ts +2 -2
  38. package/dist/lib/prompts/codex.d.ts.map +1 -1
  39. package/dist/lib/prompts/codex.js +3 -3
  40. package/dist/lib/prompts/host-codex-prompt.d.ts +25 -0
  41. package/dist/lib/prompts/host-codex-prompt.d.ts.map +1 -0
  42. package/dist/lib/prompts/{opencode-codex.js → host-codex-prompt.js} +136 -47
  43. package/dist/lib/prompts/host-codex-prompt.js.map +1 -0
  44. package/dist/lib/recovery/storage.d.ts +2 -2
  45. package/dist/lib/recovery/storage.js +2 -2
  46. package/dist/lib/recovery/types.d.ts +1 -1
  47. package/dist/lib/recovery/types.js +1 -1
  48. package/dist/lib/recovery.d.ts +1 -1
  49. package/dist/lib/recovery.d.ts.map +1 -1
  50. package/dist/lib/recovery.js +1 -4
  51. package/dist/lib/recovery.js.map +1 -1
  52. package/dist/lib/request/fetch-helpers.d.ts +3 -3
  53. package/dist/lib/request/fetch-helpers.d.ts.map +1 -1
  54. package/dist/lib/request/fetch-helpers.js +6 -2
  55. package/dist/lib/request/fetch-helpers.js.map +1 -1
  56. package/dist/lib/request/helpers/input-utils.d.ts +2 -2
  57. package/dist/lib/request/helpers/input-utils.d.ts.map +1 -1
  58. package/dist/lib/request/helpers/input-utils.js +14 -14
  59. package/dist/lib/request/helpers/input-utils.js.map +1 -1
  60. package/dist/lib/request/helpers/model-map.d.ts +2 -2
  61. package/dist/lib/request/helpers/model-map.js +2 -2
  62. package/dist/lib/request/request-transformer.d.ts +12 -12
  63. package/dist/lib/request/request-transformer.d.ts.map +1 -1
  64. package/dist/lib/request/request-transformer.js +23 -24
  65. package/dist/lib/request/request-transformer.js.map +1 -1
  66. package/dist/lib/runtime-paths.d.ts +4 -4
  67. package/dist/lib/runtime-paths.d.ts.map +1 -1
  68. package/dist/lib/runtime-paths.js +57 -13
  69. package/dist/lib/runtime-paths.js.map +1 -1
  70. package/dist/lib/storage/paths.d.ts +11 -0
  71. package/dist/lib/storage/paths.d.ts.map +1 -1
  72. package/dist/lib/storage/paths.js +167 -5
  73. package/dist/lib/storage/paths.js.map +1 -1
  74. package/dist/lib/storage.d.ts +1 -0
  75. package/dist/lib/storage.d.ts.map +1 -1
  76. package/dist/lib/storage.js +290 -81
  77. package/dist/lib/storage.js.map +1 -1
  78. package/dist/lib/tools/hashline-tools.d.ts +1 -1
  79. package/dist/lib/tools/hashline-tools.d.ts.map +1 -1
  80. package/dist/lib/tools/hashline-tools.js +1 -1
  81. package/dist/lib/tools/hashline-tools.js.map +1 -1
  82. package/dist/lib/types.d.ts +1 -1
  83. package/dist/lib/types.d.ts.map +1 -1
  84. package/dist/lib/ui/copy.d.ts +6 -6
  85. package/dist/lib/ui/copy.js +6 -6
  86. package/dist/lib/ui/copy.js.map +1 -1
  87. package/node_modules/@codex-ai/plugin/dist/index.d.ts +2 -0
  88. package/node_modules/@codex-ai/plugin/dist/index.js +2 -0
  89. package/node_modules/@codex-ai/plugin/dist/tool.d.ts +42 -0
  90. package/node_modules/@codex-ai/plugin/dist/tool.js +29 -0
  91. package/node_modules/@codex-ai/plugin/package.json +9 -0
  92. package/package.json +30 -16
  93. package/scripts/audit-dev-allowlist.js +128 -128
  94. package/scripts/bench-format/{opencode.mjs → codex-host.mjs} +206 -205
  95. package/scripts/bench-format/hashline-v2.mjs +642 -642
  96. package/scripts/bench-format/models.mjs +111 -105
  97. package/scripts/bench-format/render.mjs +496 -496
  98. package/scripts/bench-format/stats.mjs +54 -54
  99. package/scripts/bench-format/tasks.mjs +151 -151
  100. package/scripts/benchmark-edit-formats.mjs +1162 -1161
  101. package/scripts/benchmark-render-dashboard.mjs +49 -49
  102. package/scripts/codex.js +40 -2
  103. package/scripts/copy-oauth-success.js +37 -37
  104. package/scripts/install-codex-auth-utils.js +49 -0
  105. package/scripts/{install-opencode-codex-auth.js → install-codex-auth.js} +220 -193
  106. package/scripts/repo-hygiene.js +320 -0
  107. package/scripts/test-all-models.sh +7 -7
  108. package/scripts/test-model-matrix.js +475 -423
  109. package/scripts/validate-model-map.sh +7 -7
  110. package/vendor/codex-ai-plugin/dist/index.d.ts +2 -0
  111. package/vendor/codex-ai-plugin/dist/index.js +2 -0
  112. package/vendor/codex-ai-plugin/dist/tool.d.ts +42 -0
  113. package/vendor/codex-ai-plugin/dist/tool.js +29 -0
  114. package/vendor/codex-ai-plugin/package.json +9 -0
  115. package/vendor/codex-ai-sdk/dist/index.d.ts +4 -0
  116. package/vendor/codex-ai-sdk/dist/index.js +2 -0
  117. package/vendor/codex-ai-sdk/package.json +8 -0
  118. package/assets/opencode-logo-ornate-dark.svg +0 -18
  119. package/dist/lib/prompts/codex-opencode-bridge.d.ts +0 -19
  120. package/dist/lib/prompts/codex-opencode-bridge.d.ts.map +0 -1
  121. package/dist/lib/prompts/codex-opencode-bridge.js.map +0 -1
  122. package/dist/lib/prompts/opencode-codex.d.ts +0 -25
  123. package/dist/lib/prompts/opencode-codex.d.ts.map +0 -1
  124. package/dist/lib/prompts/opencode-codex.js.map +0 -1
@@ -1,193 +1,220 @@
1
- #!/usr/bin/env node
2
-
3
- import { existsSync } from "node:fs";
4
- import { readFile, writeFile, mkdir, copyFile, rm } from "node:fs/promises";
5
- import { fileURLToPath } from "node:url";
6
- import { dirname, join, resolve } from "node:path";
7
- import { homedir } from "node:os";
8
-
9
- const PLUGIN_NAME = "codex-multi-auth";
10
-
11
- const args = new Set(process.argv.slice(2));
12
-
13
- if (args.has("--help") || args.has("-h")) {
14
- console.log(`Usage: ${PLUGIN_NAME} [--modern|--legacy] [--dry-run] [--no-cache-clear]\n\n` +
15
- "Default behavior:\n" +
16
- " - Installs/updates global config at ~/.config/opencode/opencode.json\n" +
17
- " - Uses modern config (variants) by default\n" +
18
- " - Ensures plugin is unpinned (latest)\n" +
19
- " - Clears OpenCode plugin cache\n\n" +
20
- "Options:\n" +
21
- " --modern Force modern config (default)\n" +
22
- " --legacy Use legacy config (older OpenCode versions)\n" +
23
- " --dry-run Show actions without writing\n" +
24
- " --no-cache-clear Skip clearing OpenCode cache\n"
25
- );
26
- process.exit(0);
27
- }
28
-
29
- const useLegacy = args.has("--legacy");
30
- const useModern = args.has("--modern") || !useLegacy;
31
- const dryRun = args.has("--dry-run");
32
- const skipCacheClear = args.has("--no-cache-clear");
33
-
34
- const scriptDir = dirname(fileURLToPath(import.meta.url));
35
- const repoRoot = resolve(scriptDir, "..");
36
- const templatePath = join(
37
- repoRoot,
38
- "config",
39
- useLegacy ? "opencode-legacy.json" : "opencode-modern.json"
40
- );
41
-
42
- const configDir = join(homedir(), ".config", "opencode");
43
- const configPath = join(configDir, "opencode.json");
44
- const cacheDir = join(homedir(), ".cache", "opencode");
45
- const cacheNodeModules = join(cacheDir, "node_modules", PLUGIN_NAME);
46
- const cacheBunLock = join(cacheDir, "bun.lock");
47
- const cachePackageJson = join(cacheDir, "package.json");
48
-
49
- function log(message) {
50
- console.log(message);
51
- }
52
-
53
- function normalizePluginList(list) {
54
- const entries = Array.isArray(list) ? list.filter(Boolean) : [];
55
- const filtered = entries.filter((entry) => {
56
- if (typeof entry !== "string") return true;
57
- return entry !== PLUGIN_NAME && !entry.startsWith(`${PLUGIN_NAME}@`);
58
- });
59
- return [...filtered, PLUGIN_NAME];
60
- }
61
-
62
- function formatJson(obj) {
63
- return `${JSON.stringify(obj, null, 2)}\n`;
64
- }
65
-
66
- async function readJson(filePath) {
67
- const content = await readFile(filePath, "utf-8");
68
- return JSON.parse(content);
69
- }
70
-
71
- async function backupConfig(sourcePath) {
72
- const timestamp = new Date()
73
- .toISOString()
74
- .replace(/[:.]/g, "-")
75
- .replace("T", "_")
76
- .replace("Z", "");
77
- const backupPath = `${sourcePath}.bak-${timestamp}`;
78
- if (!dryRun) {
79
- await copyFile(sourcePath, backupPath);
80
- }
81
- return backupPath;
82
- }
83
-
84
- async function removePluginFromCachePackage() {
85
- if (!existsSync(cachePackageJson)) {
86
- return;
87
- }
88
-
89
- let cacheData;
90
- try {
91
- cacheData = await readJson(cachePackageJson);
92
- } catch (error) {
93
- log(`Warning: Could not parse ${cachePackageJson} (${error}). Skipping.`);
94
- return;
95
- }
96
-
97
- const sections = [
98
- "dependencies",
99
- "devDependencies",
100
- "peerDependencies",
101
- "optionalDependencies",
102
- ];
103
-
104
- let changed = false;
105
- for (const section of sections) {
106
- const deps = cacheData?.[section];
107
- if (deps && typeof deps === "object" && PLUGIN_NAME in deps) {
108
- delete deps[PLUGIN_NAME];
109
- changed = true;
110
- }
111
- }
112
-
113
- if (!changed) {
114
- return;
115
- }
116
-
117
- if (dryRun) {
118
- log(`[dry-run] Would update ${cachePackageJson} to remove ${PLUGIN_NAME}`);
119
- return;
120
- }
121
-
122
- await writeFile(cachePackageJson, formatJson(cacheData), "utf-8");
123
- }
124
-
125
- async function clearCache() {
126
- if (skipCacheClear) {
127
- log("Skipping cache clear (--no-cache-clear).");
128
- return;
129
- }
130
-
131
- if (dryRun) {
132
- log(`[dry-run] Would remove ${cacheNodeModules}`);
133
- log(`[dry-run] Would remove ${cacheBunLock}`);
134
- } else {
135
- await rm(cacheNodeModules, { recursive: true, force: true });
136
- await rm(cacheBunLock, { force: true });
137
- }
138
-
139
- await removePluginFromCachePackage();
140
- }
141
-
142
- async function main() {
143
- if (!existsSync(templatePath)) {
144
- throw new Error(`Config template not found at ${templatePath}`);
145
- }
146
-
147
- const template = await readJson(templatePath);
148
- template.plugin = [PLUGIN_NAME];
149
-
150
- let nextConfig = template;
151
- if (existsSync(configPath)) {
152
- const backupPath = await backupConfig(configPath);
153
- log(`${dryRun ? "[dry-run] Would create backup" : "Backup created"}: ${backupPath}`);
154
-
155
- try {
156
- const existing = await readJson(configPath);
157
- const merged = { ...existing };
158
- merged.plugin = normalizePluginList(existing.plugin);
159
- const provider = (existing.provider && typeof existing.provider === "object")
160
- ? { ...existing.provider }
161
- : {};
162
- provider.openai = template.provider.openai;
163
- merged.provider = provider;
164
- nextConfig = merged;
165
- } catch (error) {
166
- log(`Warning: Could not parse existing config (${error}). Replacing with template.`);
167
- nextConfig = template;
168
- }
169
- } else {
170
- log("No existing config found. Creating new global config.");
171
- }
172
-
173
- if (dryRun) {
174
- log(`[dry-run] Would write ${configPath} using ${useLegacy ? "legacy" : "modern"} config`);
175
- } else {
176
- await mkdir(configDir, { recursive: true });
177
- await writeFile(configPath, formatJson(nextConfig), "utf-8");
178
- log(`Wrote ${configPath} (${useLegacy ? "legacy" : "modern"} config)`);
179
- }
180
-
181
- await clearCache();
182
-
183
- log("\nDone. Restart OpenCode to (re)install the plugin.");
184
- log("Example: opencode");
185
- if (useLegacy) {
186
- log("Note: Legacy config requires OpenCode v1.0.209 or older.");
187
- }
188
- }
189
-
190
- main().catch((error) => {
191
- console.error(`Installer failed: ${error instanceof Error ? error.message : error}`);
192
- process.exit(1);
193
- });
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync } from "node:fs";
4
+ import { readFile, writeFile, mkdir, copyFile, rm, rename } from "node:fs/promises";
5
+ import { fileURLToPath } from "node:url";
6
+ import { dirname, join, resolve } from "node:path";
7
+ import { normalizePluginList, resolveInstallPaths } from "./install-codex-auth-utils.js";
8
+
9
+ const PLUGIN_NAME = "codex-multi-auth";
10
+
11
+ const args = new Set(process.argv.slice(2));
12
+
13
+ if (args.has("--help") || args.has("-h")) {
14
+ console.log(`Usage: ${PLUGIN_NAME} [--modern|--legacy] [--dry-run] [--no-cache-clear]\n\n` +
15
+ "Default behavior:\n" +
16
+ " - Installs/updates global config at ~/.config/Codex/Codex.json\n" +
17
+ " - Uses modern config (variants) by default\n" +
18
+ " - Ensures plugin is unpinned (latest)\n" +
19
+ " - Clears Codex plugin cache\n\n" +
20
+ "Options:\n" +
21
+ " --modern Force modern config (default)\n" +
22
+ " --legacy Use legacy config (older Codex versions)\n" +
23
+ " --dry-run Show actions without writing\n" +
24
+ " --no-cache-clear Skip clearing Codex cache\n"
25
+ );
26
+ process.exit(0);
27
+ }
28
+
29
+ const useLegacy = args.has("--legacy");
30
+ const useModern = args.has("--modern") || !useLegacy;
31
+ const dryRun = args.has("--dry-run");
32
+ const skipCacheClear = args.has("--no-cache-clear");
33
+
34
+ const scriptDir = dirname(fileURLToPath(import.meta.url));
35
+ const repoRoot = resolve(scriptDir, "..");
36
+ const templatePath = join(
37
+ repoRoot,
38
+ "config",
39
+ useLegacy ? "codex-legacy.json" : "codex-modern.json"
40
+ );
41
+
42
+ const installPaths = resolveInstallPaths();
43
+ const { configDir, configPath, cacheNodeModules, cacheBunLock, cachePackageJson } = installPaths;
44
+
45
+ function log(message) {
46
+ console.log(message);
47
+ }
48
+
49
+ function formatJson(obj) {
50
+ return `${JSON.stringify(obj, null, 2)}\n`;
51
+ }
52
+
53
+ async function readJson(filePath) {
54
+ const content = await readFile(filePath, "utf-8");
55
+ return JSON.parse(content);
56
+ }
57
+
58
+ async function writeJsonAtomic(filePath, value) {
59
+ const tempPath = `${filePath}.tmp-${process.pid}-${Date.now()}-${Math.random()
60
+ .toString(36)
61
+ .slice(2, 8)}`;
62
+ const content = formatJson(value);
63
+ try {
64
+ await writeFile(tempPath, content, "utf-8");
65
+ await rename(tempPath, filePath);
66
+ } finally {
67
+ if (existsSync(tempPath)) {
68
+ await rm(tempPath, { force: true });
69
+ }
70
+ }
71
+ }
72
+
73
+ async function backupConfig(sourcePath) {
74
+ const timestamp = new Date()
75
+ .toISOString()
76
+ .replace(/[:.]/g, "-")
77
+ .replace("T", "_")
78
+ .replace("Z", "");
79
+ const nonce = `${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
80
+ const backupPath = `${sourcePath}.bak-${timestamp}-${nonce}`;
81
+ if (!dryRun) {
82
+ await copyFile(sourcePath, backupPath);
83
+ }
84
+ return backupPath;
85
+ }
86
+
87
+ async function removePluginFromCachePackage() {
88
+ if (!existsSync(cachePackageJson)) {
89
+ return;
90
+ }
91
+
92
+ let cacheData;
93
+ try {
94
+ cacheData = await readJson(cachePackageJson);
95
+ } catch (error) {
96
+ log(`Warning: Could not parse ${cachePackageJson} (${error}). Skipping.`);
97
+ return;
98
+ }
99
+
100
+ const sections = [
101
+ "dependencies",
102
+ "devDependencies",
103
+ "peerDependencies",
104
+ "optionalDependencies",
105
+ ];
106
+
107
+ let changed = false;
108
+ for (const section of sections) {
109
+ const deps = cacheData?.[section];
110
+ if (deps && typeof deps === "object" && PLUGIN_NAME in deps) {
111
+ delete deps[PLUGIN_NAME];
112
+ changed = true;
113
+ }
114
+ }
115
+
116
+ if (!changed) {
117
+ return;
118
+ }
119
+
120
+ if (dryRun) {
121
+ log(`[dry-run] Would update ${cachePackageJson} to remove ${PLUGIN_NAME}`);
122
+ return;
123
+ }
124
+
125
+ await writeJsonAtomic(cachePackageJson, cacheData);
126
+ }
127
+
128
+ async function clearCache() {
129
+ if (skipCacheClear) {
130
+ log("Skipping cache clear (--no-cache-clear).");
131
+ return;
132
+ }
133
+
134
+ if (dryRun) {
135
+ log(`[dry-run] Would remove ${cacheNodeModules}`);
136
+ log(`[dry-run] Would remove ${cacheBunLock}`);
137
+ } else {
138
+ try {
139
+ await rm(cacheNodeModules, { recursive: true, force: true });
140
+ await rm(cacheBunLock, { force: true });
141
+ } catch (error) {
142
+ log(
143
+ `Warning: Could not fully clear cache (${error instanceof Error ? error.message : String(error)}). You may need to restart Codex.`,
144
+ );
145
+ }
146
+ }
147
+
148
+ await removePluginFromCachePackage();
149
+ }
150
+
151
+ async function main() {
152
+ if (!existsSync(templatePath)) {
153
+ throw new Error(`Config template not found at ${templatePath}`);
154
+ }
155
+
156
+ const template = await readJson(templatePath);
157
+ template.plugin = [PLUGIN_NAME];
158
+
159
+ let nextConfig = template;
160
+ if (existsSync(configPath)) {
161
+ const backupPath = await backupConfig(configPath);
162
+ log(`${dryRun ? "[dry-run] Would create backup" : "Backup created"}: ${backupPath}`);
163
+
164
+ try {
165
+ const existing = await readJson(configPath);
166
+ const merged = { ...existing };
167
+ merged.plugin = normalizePluginList(existing.plugin);
168
+ const provider = (existing.provider && typeof existing.provider === "object")
169
+ ? { ...existing.provider }
170
+ : {};
171
+ const existingOpenAi = provider.openai && typeof provider.openai === "object"
172
+ ? provider.openai
173
+ : {};
174
+ const templateOpenAi = template.provider && typeof template.provider === "object" &&
175
+ template.provider.openai && typeof template.provider.openai === "object"
176
+ ? template.provider.openai
177
+ : {};
178
+ provider.openai = { ...templateOpenAi, ...existingOpenAi };
179
+ merged.provider = provider;
180
+ nextConfig = merged;
181
+ } catch (error) {
182
+ log(`Warning: Could not parse existing config (${error}). Replacing with template.`);
183
+ nextConfig = template;
184
+ }
185
+ } else {
186
+ log("No existing config found. Creating new global config.");
187
+ }
188
+
189
+ if (dryRun) {
190
+ log(`[dry-run] Would write ${configPath} using ${useLegacy ? "legacy" : "modern"} config`);
191
+ } else {
192
+ await mkdir(configDir, { recursive: true });
193
+ await writeJsonAtomic(configPath, nextConfig);
194
+ log(`Wrote ${configPath} (${useLegacy ? "legacy" : "modern"} config)`);
195
+ }
196
+
197
+ await clearCache();
198
+
199
+ log("\nDone. Restart Codex to (re)install the plugin.");
200
+ log("Example: Codex");
201
+ if (useLegacy) {
202
+ log("Note: Legacy config requires Codex v1.0.209 or older.");
203
+ }
204
+ }
205
+
206
+ const isDirectRun = (() => {
207
+ try {
208
+ return resolve(process.argv[1] ?? "") === fileURLToPath(import.meta.url);
209
+ } catch {
210
+ return false;
211
+ }
212
+ })();
213
+
214
+ if (isDirectRun) {
215
+ main().catch((error) => {
216
+ console.error(`Installer failed: ${error instanceof Error ? error.message : error}`);
217
+ process.exit(1);
218
+ });
219
+ }
220
+