codex-multi-auth 2.1.13-beta.0 → 2.1.13-beta.1
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/LICENSE +21 -21
- package/README.md +415 -415
- package/assets/codex-multi-auth-icon.svg +39 -39
- package/assets/readme-hero.svg +31 -31
- package/config/README.md +29 -29
- package/config/codex-legacy.json +571 -571
- package/config/codex-modern.json +258 -258
- package/config/minimal-codex.json +15 -15
- package/config/schema/config.schema.json +20 -20
- package/dist/lib/accounts.d.ts +13 -0
- package/dist/lib/accounts.d.ts.map +1 -1
- package/dist/lib/accounts.js +58 -14
- package/dist/lib/accounts.js.map +1 -1
- package/dist/lib/codex-manager/commands/status.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/status.js +9 -1
- package/dist/lib/codex-manager/commands/status.js.map +1 -1
- package/dist/lib/codex-manager/commands/workspace.d.ts +19 -0
- package/dist/lib/codex-manager/commands/workspace.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/workspace.js +85 -0
- package/dist/lib/codex-manager/commands/workspace.js.map +1 -0
- 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 +27 -2
- package/dist/lib/codex-manager/help.js.map +1 -1
- package/dist/lib/codex-manager.d.ts.map +1 -1
- package/dist/lib/codex-manager.js +35 -1
- package/dist/lib/codex-manager.js.map +1 -1
- package/dist/lib/context-overflow.js +10 -10
- package/dist/lib/oauth-success.html +125 -125
- package/dist/lib/prompts/codex-host-bridge.js +138 -138
- package/dist/lib/prompts/codex.js +79 -79
- package/dist/lib/schemas.d.ts +54 -0
- package/dist/lib/schemas.d.ts.map +1 -1
- package/dist/lib/schemas.js +18 -0
- package/dist/lib/schemas.js.map +1 -1
- package/node_modules/@codex-ai/plugin/dist/index.d.ts +2 -2
- package/node_modules/@codex-ai/plugin/dist/index.js +2 -2
- package/node_modules/@codex-ai/plugin/dist/tool.d.ts +42 -42
- package/node_modules/@codex-ai/plugin/dist/tool.js +29 -29
- package/node_modules/@codex-ai/plugin/package.json +9 -9
- package/package.json +193 -193
- package/scripts/codex-app-launcher.js +653 -653
- package/scripts/codex-app-router.js +322 -322
- package/scripts/codex-bin-resolver.js +254 -254
- package/scripts/codex-multi-auth.js +59 -59
- package/scripts/codex-routing.js +56 -56
- package/scripts/codex.js +4275 -4275
- package/scripts/install-codex-auth-utils.js +206 -206
- package/scripts/postinstall.js +343 -343
- package/scripts/preuninstall.js +254 -254
- package/vendor/codex-ai-plugin/dist/index.d.ts +2 -2
- package/vendor/codex-ai-plugin/dist/index.js +2 -2
- package/vendor/codex-ai-plugin/dist/tool.d.ts +42 -42
- package/vendor/codex-ai-plugin/dist/tool.js +29 -29
- package/vendor/codex-ai-plugin/package.json +9 -9
- package/vendor/codex-ai-sdk/dist/index.d.ts +4 -4
- package/vendor/codex-ai-sdk/dist/index.js +2 -2
- package/vendor/codex-ai-sdk/package.json +8 -8
|
@@ -1,254 +1,254 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync, realpathSync } from "node:fs";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
import { basename, delimiter, dirname, extname, join } from "node:path";
|
|
5
|
-
import process from "node:process";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
|
|
8
|
-
function isJavaScriptEntryPath(candidate) {
|
|
9
|
-
const extension = extname(candidate).toLowerCase();
|
|
10
|
-
return extension === ".js" || extension === ".mjs" || extension === ".cjs";
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function createResolvedCodexBin(path) {
|
|
14
|
-
return {
|
|
15
|
-
path,
|
|
16
|
-
launchWithNode: isJavaScriptEntryPath(path),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function normalizeResolvedPath(candidatePath, realpathSyncImpl) {
|
|
21
|
-
try {
|
|
22
|
-
return realpathSyncImpl(candidatePath);
|
|
23
|
-
} catch {
|
|
24
|
-
return candidatePath;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function resolveWrapperScriptPath(moduleUrl, realpathSyncImpl) {
|
|
29
|
-
return normalizeResolvedPath(fileURLToPath(moduleUrl), realpathSyncImpl);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const DEFAULT_WRAPPER_MODULE_URL = new URL("./codex.js", import.meta.url).href;
|
|
33
|
-
|
|
34
|
-
function defaultResolvePackageBin(moduleUrl) {
|
|
35
|
-
try {
|
|
36
|
-
const require = createRequire(moduleUrl);
|
|
37
|
-
return require.resolve("@openai/codex/bin/codex.js");
|
|
38
|
-
} catch {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function resolveWindowsCmdPath(env) {
|
|
44
|
-
const comSpec = (env.ComSpec ?? env.COMSPEC ?? "").trim();
|
|
45
|
-
if (comSpec.length > 0) return comSpec;
|
|
46
|
-
|
|
47
|
-
const systemRoot = (env.SystemRoot ?? env.SYSTEMROOT ?? "").trim();
|
|
48
|
-
if (systemRoot.length > 0) {
|
|
49
|
-
return `${systemRoot.replace(/[\\/]+$/, "")}\\System32\\cmd.exe`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return "cmd.exe";
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function splitPathEntries(pathValue) {
|
|
56
|
-
if (typeof pathValue !== "string" || pathValue.trim().length === 0) {
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
59
|
-
return pathValue
|
|
60
|
-
.split(delimiter)
|
|
61
|
-
.map((entry) => entry.trim())
|
|
62
|
-
.filter((entry) => entry.length > 0);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function resolvePathExecutableName(platform) {
|
|
66
|
-
return platform === "win32" ? "codex.exe" : "codex";
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function resolveCandidateExecutableNames(platform) {
|
|
70
|
-
if (platform !== "win32") {
|
|
71
|
-
return [resolvePathExecutableName(platform)];
|
|
72
|
-
}
|
|
73
|
-
return ["codex.exe", "codex"];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function resolveCodexExecutableFromPath(
|
|
77
|
-
pathEntries,
|
|
78
|
-
platform,
|
|
79
|
-
existsSyncImpl,
|
|
80
|
-
selfScriptPath,
|
|
81
|
-
realpathSyncImpl,
|
|
82
|
-
) {
|
|
83
|
-
for (const entry of pathEntries) {
|
|
84
|
-
for (const executableName of resolveCandidateExecutableNames(platform)) {
|
|
85
|
-
const candidate = join(entry, executableName);
|
|
86
|
-
if (!existsSyncImpl(candidate)) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
if (
|
|
90
|
-
selfScriptPath &&
|
|
91
|
-
normalizeResolvedPath(candidate, realpathSyncImpl) === selfScriptPath
|
|
92
|
-
) {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
return candidate;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function normalizeWhereOutput(stdout) {
|
|
102
|
-
return stdout
|
|
103
|
-
.split(/\r?\n/)
|
|
104
|
-
.map((line) => line.trim())
|
|
105
|
-
.filter((line) => line.length > 0);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function resolveCodexExecutableFromSystemPath(
|
|
109
|
-
env,
|
|
110
|
-
platform,
|
|
111
|
-
spawnSyncImpl,
|
|
112
|
-
existsSyncImpl,
|
|
113
|
-
selfScriptPath,
|
|
114
|
-
realpathSyncImpl,
|
|
115
|
-
) {
|
|
116
|
-
const pathEntries = splitPathEntries(env.PATH ?? env.Path ?? "");
|
|
117
|
-
const fromEnvPath = resolveCodexExecutableFromPath(
|
|
118
|
-
pathEntries,
|
|
119
|
-
platform,
|
|
120
|
-
existsSyncImpl,
|
|
121
|
-
selfScriptPath,
|
|
122
|
-
realpathSyncImpl,
|
|
123
|
-
);
|
|
124
|
-
if (fromEnvPath) {
|
|
125
|
-
return fromEnvPath;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
const lookupResult =
|
|
130
|
-
platform === "win32"
|
|
131
|
-
? spawnSyncImpl(resolveWindowsCmdPath(env), ["/d", "/s", "/c", "where codex"], {
|
|
132
|
-
encoding: "utf8",
|
|
133
|
-
env,
|
|
134
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
135
|
-
timeout: 5000,
|
|
136
|
-
windowsHide: true,
|
|
137
|
-
})
|
|
138
|
-
: spawnSyncImpl("which", ["codex"], {
|
|
139
|
-
encoding: "utf8",
|
|
140
|
-
env,
|
|
141
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
142
|
-
timeout: 5000,
|
|
143
|
-
});
|
|
144
|
-
if (lookupResult.status !== 0) {
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
for (const candidate of normalizeWhereOutput(lookupResult.stdout)) {
|
|
148
|
-
if (!existsSyncImpl(candidate)) {
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if (
|
|
152
|
-
selfScriptPath &&
|
|
153
|
-
normalizeResolvedPath(candidate, realpathSyncImpl) === selfScriptPath
|
|
154
|
-
) {
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
const fileName = basename(candidate).toLowerCase();
|
|
158
|
-
if (fileName === "codex" || fileName === "codex.exe") {
|
|
159
|
-
return candidate;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
} catch {
|
|
163
|
-
// Ignore and fall through.
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return null;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function resolveRealCodexBin(options = {}) {
|
|
170
|
-
const {
|
|
171
|
-
env = process.env,
|
|
172
|
-
argv = process.argv,
|
|
173
|
-
platform = process.platform,
|
|
174
|
-
moduleUrl = DEFAULT_WRAPPER_MODULE_URL,
|
|
175
|
-
existsSyncImpl = existsSync,
|
|
176
|
-
realpathSyncImpl = realpathSync,
|
|
177
|
-
spawnSyncImpl = spawnSync,
|
|
178
|
-
resolvePackageBin = defaultResolvePackageBin,
|
|
179
|
-
} = options;
|
|
180
|
-
|
|
181
|
-
const override = (env.CODEX_MULTI_AUTH_REAL_CODEX_BIN ?? "").trim();
|
|
182
|
-
if (override.length > 0) {
|
|
183
|
-
if (existsSyncImpl(override)) return createResolvedCodexBin(override);
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const resolved = resolvePackageBin(moduleUrl);
|
|
188
|
-
if (typeof resolved === "string" && resolved.length > 0 && existsSyncImpl(resolved)) {
|
|
189
|
-
return createResolvedCodexBin(resolved);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const searchRoots = [];
|
|
193
|
-
const scriptDir = dirname(fileURLToPath(moduleUrl));
|
|
194
|
-
searchRoots.push(join(scriptDir, "..", ".."));
|
|
195
|
-
|
|
196
|
-
const invokedScript = argv[1];
|
|
197
|
-
if (typeof invokedScript === "string" && invokedScript.length > 0) {
|
|
198
|
-
searchRoots.push(join(dirname(invokedScript), "..", ".."));
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const npmPrefix = (env.npm_config_prefix ?? env.PREFIX ?? "").trim();
|
|
202
|
-
if (npmPrefix.length > 0) {
|
|
203
|
-
searchRoots.push(join(npmPrefix, "node_modules"));
|
|
204
|
-
searchRoots.push(join(npmPrefix, "lib", "node_modules"));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
for (const root of searchRoots) {
|
|
208
|
-
const candidate = join(root, "@openai", "codex", "bin", "codex.js");
|
|
209
|
-
if (existsSyncImpl(candidate)) return createResolvedCodexBin(candidate);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
try {
|
|
213
|
-
const rootResult =
|
|
214
|
-
platform === "win32"
|
|
215
|
-
? spawnSyncImpl(resolveWindowsCmdPath(env), ["/d", "/s", "/c", "npm root -g"], {
|
|
216
|
-
encoding: "utf8",
|
|
217
|
-
env,
|
|
218
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
219
|
-
timeout: 5000,
|
|
220
|
-
windowsHide: true,
|
|
221
|
-
})
|
|
222
|
-
: spawnSyncImpl("npm", ["root", "-g"], {
|
|
223
|
-
encoding: "utf8",
|
|
224
|
-
env,
|
|
225
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
226
|
-
timeout: 5000,
|
|
227
|
-
});
|
|
228
|
-
if (rootResult.status === 0) {
|
|
229
|
-
const globalRoot = rootResult.stdout.trim();
|
|
230
|
-
if (globalRoot.length > 0) {
|
|
231
|
-
const globalBin = join(globalRoot, "@openai", "codex", "bin", "codex.js");
|
|
232
|
-
if (existsSyncImpl(globalBin)) return createResolvedCodexBin(globalBin);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
} catch {
|
|
236
|
-
// Ignore and fall through to null.
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const selfScriptPath = resolveWrapperScriptPath(moduleUrl, realpathSyncImpl);
|
|
240
|
-
|
|
241
|
-
const nativeCodexBin = resolveCodexExecutableFromSystemPath(
|
|
242
|
-
env,
|
|
243
|
-
platform,
|
|
244
|
-
spawnSyncImpl,
|
|
245
|
-
existsSyncImpl,
|
|
246
|
-
selfScriptPath,
|
|
247
|
-
realpathSyncImpl,
|
|
248
|
-
);
|
|
249
|
-
if (nativeCodexBin) {
|
|
250
|
-
return createResolvedCodexBin(nativeCodexBin);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return null;
|
|
254
|
-
}
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { basename, delimiter, dirname, extname, join } from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
function isJavaScriptEntryPath(candidate) {
|
|
9
|
+
const extension = extname(candidate).toLowerCase();
|
|
10
|
+
return extension === ".js" || extension === ".mjs" || extension === ".cjs";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function createResolvedCodexBin(path) {
|
|
14
|
+
return {
|
|
15
|
+
path,
|
|
16
|
+
launchWithNode: isJavaScriptEntryPath(path),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeResolvedPath(candidatePath, realpathSyncImpl) {
|
|
21
|
+
try {
|
|
22
|
+
return realpathSyncImpl(candidatePath);
|
|
23
|
+
} catch {
|
|
24
|
+
return candidatePath;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function resolveWrapperScriptPath(moduleUrl, realpathSyncImpl) {
|
|
29
|
+
return normalizeResolvedPath(fileURLToPath(moduleUrl), realpathSyncImpl);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const DEFAULT_WRAPPER_MODULE_URL = new URL("./codex.js", import.meta.url).href;
|
|
33
|
+
|
|
34
|
+
function defaultResolvePackageBin(moduleUrl) {
|
|
35
|
+
try {
|
|
36
|
+
const require = createRequire(moduleUrl);
|
|
37
|
+
return require.resolve("@openai/codex/bin/codex.js");
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function resolveWindowsCmdPath(env) {
|
|
44
|
+
const comSpec = (env.ComSpec ?? env.COMSPEC ?? "").trim();
|
|
45
|
+
if (comSpec.length > 0) return comSpec;
|
|
46
|
+
|
|
47
|
+
const systemRoot = (env.SystemRoot ?? env.SYSTEMROOT ?? "").trim();
|
|
48
|
+
if (systemRoot.length > 0) {
|
|
49
|
+
return `${systemRoot.replace(/[\\/]+$/, "")}\\System32\\cmd.exe`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return "cmd.exe";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function splitPathEntries(pathValue) {
|
|
56
|
+
if (typeof pathValue !== "string" || pathValue.trim().length === 0) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
return pathValue
|
|
60
|
+
.split(delimiter)
|
|
61
|
+
.map((entry) => entry.trim())
|
|
62
|
+
.filter((entry) => entry.length > 0);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function resolvePathExecutableName(platform) {
|
|
66
|
+
return platform === "win32" ? "codex.exe" : "codex";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function resolveCandidateExecutableNames(platform) {
|
|
70
|
+
if (platform !== "win32") {
|
|
71
|
+
return [resolvePathExecutableName(platform)];
|
|
72
|
+
}
|
|
73
|
+
return ["codex.exe", "codex"];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function resolveCodexExecutableFromPath(
|
|
77
|
+
pathEntries,
|
|
78
|
+
platform,
|
|
79
|
+
existsSyncImpl,
|
|
80
|
+
selfScriptPath,
|
|
81
|
+
realpathSyncImpl,
|
|
82
|
+
) {
|
|
83
|
+
for (const entry of pathEntries) {
|
|
84
|
+
for (const executableName of resolveCandidateExecutableNames(platform)) {
|
|
85
|
+
const candidate = join(entry, executableName);
|
|
86
|
+
if (!existsSyncImpl(candidate)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (
|
|
90
|
+
selfScriptPath &&
|
|
91
|
+
normalizeResolvedPath(candidate, realpathSyncImpl) === selfScriptPath
|
|
92
|
+
) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
return candidate;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function normalizeWhereOutput(stdout) {
|
|
102
|
+
return stdout
|
|
103
|
+
.split(/\r?\n/)
|
|
104
|
+
.map((line) => line.trim())
|
|
105
|
+
.filter((line) => line.length > 0);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function resolveCodexExecutableFromSystemPath(
|
|
109
|
+
env,
|
|
110
|
+
platform,
|
|
111
|
+
spawnSyncImpl,
|
|
112
|
+
existsSyncImpl,
|
|
113
|
+
selfScriptPath,
|
|
114
|
+
realpathSyncImpl,
|
|
115
|
+
) {
|
|
116
|
+
const pathEntries = splitPathEntries(env.PATH ?? env.Path ?? "");
|
|
117
|
+
const fromEnvPath = resolveCodexExecutableFromPath(
|
|
118
|
+
pathEntries,
|
|
119
|
+
platform,
|
|
120
|
+
existsSyncImpl,
|
|
121
|
+
selfScriptPath,
|
|
122
|
+
realpathSyncImpl,
|
|
123
|
+
);
|
|
124
|
+
if (fromEnvPath) {
|
|
125
|
+
return fromEnvPath;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
const lookupResult =
|
|
130
|
+
platform === "win32"
|
|
131
|
+
? spawnSyncImpl(resolveWindowsCmdPath(env), ["/d", "/s", "/c", "where codex"], {
|
|
132
|
+
encoding: "utf8",
|
|
133
|
+
env,
|
|
134
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
135
|
+
timeout: 5000,
|
|
136
|
+
windowsHide: true,
|
|
137
|
+
})
|
|
138
|
+
: spawnSyncImpl("which", ["codex"], {
|
|
139
|
+
encoding: "utf8",
|
|
140
|
+
env,
|
|
141
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
142
|
+
timeout: 5000,
|
|
143
|
+
});
|
|
144
|
+
if (lookupResult.status !== 0) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
for (const candidate of normalizeWhereOutput(lookupResult.stdout)) {
|
|
148
|
+
if (!existsSyncImpl(candidate)) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (
|
|
152
|
+
selfScriptPath &&
|
|
153
|
+
normalizeResolvedPath(candidate, realpathSyncImpl) === selfScriptPath
|
|
154
|
+
) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const fileName = basename(candidate).toLowerCase();
|
|
158
|
+
if (fileName === "codex" || fileName === "codex.exe") {
|
|
159
|
+
return candidate;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} catch {
|
|
163
|
+
// Ignore and fall through.
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function resolveRealCodexBin(options = {}) {
|
|
170
|
+
const {
|
|
171
|
+
env = process.env,
|
|
172
|
+
argv = process.argv,
|
|
173
|
+
platform = process.platform,
|
|
174
|
+
moduleUrl = DEFAULT_WRAPPER_MODULE_URL,
|
|
175
|
+
existsSyncImpl = existsSync,
|
|
176
|
+
realpathSyncImpl = realpathSync,
|
|
177
|
+
spawnSyncImpl = spawnSync,
|
|
178
|
+
resolvePackageBin = defaultResolvePackageBin,
|
|
179
|
+
} = options;
|
|
180
|
+
|
|
181
|
+
const override = (env.CODEX_MULTI_AUTH_REAL_CODEX_BIN ?? "").trim();
|
|
182
|
+
if (override.length > 0) {
|
|
183
|
+
if (existsSyncImpl(override)) return createResolvedCodexBin(override);
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const resolved = resolvePackageBin(moduleUrl);
|
|
188
|
+
if (typeof resolved === "string" && resolved.length > 0 && existsSyncImpl(resolved)) {
|
|
189
|
+
return createResolvedCodexBin(resolved);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const searchRoots = [];
|
|
193
|
+
const scriptDir = dirname(fileURLToPath(moduleUrl));
|
|
194
|
+
searchRoots.push(join(scriptDir, "..", ".."));
|
|
195
|
+
|
|
196
|
+
const invokedScript = argv[1];
|
|
197
|
+
if (typeof invokedScript === "string" && invokedScript.length > 0) {
|
|
198
|
+
searchRoots.push(join(dirname(invokedScript), "..", ".."));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const npmPrefix = (env.npm_config_prefix ?? env.PREFIX ?? "").trim();
|
|
202
|
+
if (npmPrefix.length > 0) {
|
|
203
|
+
searchRoots.push(join(npmPrefix, "node_modules"));
|
|
204
|
+
searchRoots.push(join(npmPrefix, "lib", "node_modules"));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
for (const root of searchRoots) {
|
|
208
|
+
const candidate = join(root, "@openai", "codex", "bin", "codex.js");
|
|
209
|
+
if (existsSyncImpl(candidate)) return createResolvedCodexBin(candidate);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
try {
|
|
213
|
+
const rootResult =
|
|
214
|
+
platform === "win32"
|
|
215
|
+
? spawnSyncImpl(resolveWindowsCmdPath(env), ["/d", "/s", "/c", "npm root -g"], {
|
|
216
|
+
encoding: "utf8",
|
|
217
|
+
env,
|
|
218
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
219
|
+
timeout: 5000,
|
|
220
|
+
windowsHide: true,
|
|
221
|
+
})
|
|
222
|
+
: spawnSyncImpl("npm", ["root", "-g"], {
|
|
223
|
+
encoding: "utf8",
|
|
224
|
+
env,
|
|
225
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
226
|
+
timeout: 5000,
|
|
227
|
+
});
|
|
228
|
+
if (rootResult.status === 0) {
|
|
229
|
+
const globalRoot = rootResult.stdout.trim();
|
|
230
|
+
if (globalRoot.length > 0) {
|
|
231
|
+
const globalBin = join(globalRoot, "@openai", "codex", "bin", "codex.js");
|
|
232
|
+
if (existsSyncImpl(globalBin)) return createResolvedCodexBin(globalBin);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
} catch {
|
|
236
|
+
// Ignore and fall through to null.
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const selfScriptPath = resolveWrapperScriptPath(moduleUrl, realpathSyncImpl);
|
|
240
|
+
|
|
241
|
+
const nativeCodexBin = resolveCodexExecutableFromSystemPath(
|
|
242
|
+
env,
|
|
243
|
+
platform,
|
|
244
|
+
spawnSyncImpl,
|
|
245
|
+
existsSyncImpl,
|
|
246
|
+
selfScriptPath,
|
|
247
|
+
realpathSyncImpl,
|
|
248
|
+
);
|
|
249
|
+
if (nativeCodexBin) {
|
|
250
|
+
return createResolvedCodexBin(nativeCodexBin);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// @ts-check
|
|
4
|
-
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
|
-
import { AUTH_SUBCOMMANDS } from "./codex-routing.js";
|
|
7
|
-
|
|
8
|
-
const versionFlags = new Set(["--version", "-v"]);
|
|
9
|
-
|
|
10
|
-
function resolveCliVersion() {
|
|
11
|
-
const require = createRequire(import.meta.url);
|
|
12
|
-
try {
|
|
13
|
-
const pkg = require("../package.json");
|
|
14
|
-
const version = typeof pkg?.version === "string" ? pkg.version.trim() : "";
|
|
15
|
-
if (version.length > 0) {
|
|
16
|
-
return version;
|
|
17
|
-
}
|
|
18
|
-
} catch {
|
|
19
|
-
// Best effort only.
|
|
20
|
-
}
|
|
21
|
-
return "";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @param {string[]} args
|
|
26
|
-
* @returns {string[]}
|
|
27
|
-
*/
|
|
28
|
-
function normalizeStandaloneArgs(args) {
|
|
29
|
-
if (args[0] === "auth") return args;
|
|
30
|
-
const firstArg = args[0] ?? "";
|
|
31
|
-
if (AUTH_SUBCOMMANDS.has(firstArg)) {
|
|
32
|
-
// Keep this exhaustive: generic names here are reserved for auth routing.
|
|
33
|
-
return ["auth", ...args];
|
|
34
|
-
}
|
|
35
|
-
return args;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const args = normalizeStandaloneArgs(process.argv.slice(2));
|
|
39
|
-
const version = resolveCliVersion();
|
|
40
|
-
|
|
41
|
-
if (version.length > 0) {
|
|
42
|
-
process.env.CODEX_MULTI_AUTH_CLI_VERSION = version;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const firstArg = args[0] ?? "";
|
|
46
|
-
|
|
47
|
-
if (args.length === 1 && versionFlags.has(firstArg)) {
|
|
48
|
-
if (version.length > 0) {
|
|
49
|
-
process.stdout.write(`${version}\n`);
|
|
50
|
-
process.exitCode = 0;
|
|
51
|
-
} else {
|
|
52
|
-
process.stderr.write("codex-multi-auth version is unavailable.\n");
|
|
53
|
-
process.exitCode = 1;
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
const { runCodexMultiAuthCli } = await import("../dist/lib/codex-manager.js");
|
|
57
|
-
const exitCode = await runCodexMultiAuthCli(args);
|
|
58
|
-
process.exitCode = Number.isInteger(exitCode) ? exitCode : 1;
|
|
59
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// @ts-check
|
|
4
|
+
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { AUTH_SUBCOMMANDS } from "./codex-routing.js";
|
|
7
|
+
|
|
8
|
+
const versionFlags = new Set(["--version", "-v"]);
|
|
9
|
+
|
|
10
|
+
function resolveCliVersion() {
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
try {
|
|
13
|
+
const pkg = require("../package.json");
|
|
14
|
+
const version = typeof pkg?.version === "string" ? pkg.version.trim() : "";
|
|
15
|
+
if (version.length > 0) {
|
|
16
|
+
return version;
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
// Best effort only.
|
|
20
|
+
}
|
|
21
|
+
return "";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {string[]} args
|
|
26
|
+
* @returns {string[]}
|
|
27
|
+
*/
|
|
28
|
+
function normalizeStandaloneArgs(args) {
|
|
29
|
+
if (args[0] === "auth") return args;
|
|
30
|
+
const firstArg = args[0] ?? "";
|
|
31
|
+
if (AUTH_SUBCOMMANDS.has(firstArg)) {
|
|
32
|
+
// Keep this exhaustive: generic names here are reserved for auth routing.
|
|
33
|
+
return ["auth", ...args];
|
|
34
|
+
}
|
|
35
|
+
return args;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const args = normalizeStandaloneArgs(process.argv.slice(2));
|
|
39
|
+
const version = resolveCliVersion();
|
|
40
|
+
|
|
41
|
+
if (version.length > 0) {
|
|
42
|
+
process.env.CODEX_MULTI_AUTH_CLI_VERSION = version;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const firstArg = args[0] ?? "";
|
|
46
|
+
|
|
47
|
+
if (args.length === 1 && versionFlags.has(firstArg)) {
|
|
48
|
+
if (version.length > 0) {
|
|
49
|
+
process.stdout.write(`${version}\n`);
|
|
50
|
+
process.exitCode = 0;
|
|
51
|
+
} else {
|
|
52
|
+
process.stderr.write("codex-multi-auth version is unavailable.\n");
|
|
53
|
+
process.exitCode = 1;
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
const { runCodexMultiAuthCli } = await import("../dist/lib/codex-manager.js");
|
|
57
|
+
const exitCode = await runCodexMultiAuthCli(args);
|
|
58
|
+
process.exitCode = Number.isInteger(exitCode) ? exitCode : 1;
|
|
59
|
+
}
|