@agentconnect/cli 0.1.1 → 0.1.3
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/dist/index.js +47 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -885,6 +885,8 @@ function runClaudePrompt({
|
|
|
885
885
|
|
|
886
886
|
// src/providers/codex.ts
|
|
887
887
|
import { spawn as spawn3 } from "child_process";
|
|
888
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
889
|
+
import os3 from "os";
|
|
888
890
|
import path3 from "path";
|
|
889
891
|
var CODEX_PACKAGE = "@openai/codex";
|
|
890
892
|
var DEFAULT_LOGIN2 = "codex login";
|
|
@@ -898,6 +900,36 @@ function trimOutput(value, limit = 400) {
|
|
|
898
900
|
if (cleaned.length <= limit) return cleaned;
|
|
899
901
|
return `${cleaned.slice(0, limit)}...`;
|
|
900
902
|
}
|
|
903
|
+
function getCodexConfigDir() {
|
|
904
|
+
return process.env.CODEX_CONFIG_DIR || path3.join(os3.homedir(), ".codex");
|
|
905
|
+
}
|
|
906
|
+
function hasAuthValue(value) {
|
|
907
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
908
|
+
}
|
|
909
|
+
async function hasCodexAuth() {
|
|
910
|
+
const home = os3.homedir();
|
|
911
|
+
const candidates = [
|
|
912
|
+
path3.join(getCodexConfigDir(), "auth.json"),
|
|
913
|
+
path3.join(home, ".config", "codex", "auth.json")
|
|
914
|
+
];
|
|
915
|
+
for (const filePath of candidates) {
|
|
916
|
+
try {
|
|
917
|
+
const raw = await readFile2(filePath, "utf8");
|
|
918
|
+
const parsed = JSON.parse(raw);
|
|
919
|
+
if (hasAuthValue(parsed.OPENAI_API_KEY)) return true;
|
|
920
|
+
if (hasAuthValue(parsed.access_token)) return true;
|
|
921
|
+
if (hasAuthValue(parsed.token)) return true;
|
|
922
|
+
const tokens = parsed.tokens;
|
|
923
|
+
if (tokens) {
|
|
924
|
+
if (hasAuthValue(tokens.access_token)) return true;
|
|
925
|
+
if (hasAuthValue(tokens.refresh_token)) return true;
|
|
926
|
+
if (hasAuthValue(tokens.id_token)) return true;
|
|
927
|
+
}
|
|
928
|
+
} catch {
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
return false;
|
|
932
|
+
}
|
|
901
933
|
function buildCodexExecArgs(options) {
|
|
902
934
|
const { prompt, cdTarget, resumeSessionId, model, reasoningEffort, mode } = options;
|
|
903
935
|
const args2 = ["exec", "--skip-git-repo-check"];
|
|
@@ -967,12 +999,25 @@ async function getCodexStatus() {
|
|
|
967
999
|
const versionCheck = await checkCommandVersion(command2, [["--version"], ["-V"]]);
|
|
968
1000
|
const installed = versionCheck.ok || commandExists(command2);
|
|
969
1001
|
let loggedIn = false;
|
|
1002
|
+
let explicitLoggedOut = false;
|
|
970
1003
|
if (installed) {
|
|
971
1004
|
const status = buildStatusCommand("AGENTCONNECT_CODEX_STATUS", DEFAULT_STATUS2);
|
|
972
1005
|
if (status.command) {
|
|
973
1006
|
const statusCommand = resolveWindowsCommand(status.command);
|
|
974
|
-
const result = await runCommand(statusCommand, status.args);
|
|
975
|
-
|
|
1007
|
+
const result = await runCommand(statusCommand, status.args, { env: { ...process.env, CI: "1" } });
|
|
1008
|
+
const output = `${result.stdout}
|
|
1009
|
+
${result.stderr}`.toLowerCase();
|
|
1010
|
+
if (output.includes("not logged in") || output.includes("not logged") || output.includes("login required") || output.includes("please login") || output.includes("run codex login")) {
|
|
1011
|
+
explicitLoggedOut = true;
|
|
1012
|
+
loggedIn = false;
|
|
1013
|
+
} else if (output.includes("logged in") || output.includes("signed in") || output.includes("authenticated")) {
|
|
1014
|
+
loggedIn = true;
|
|
1015
|
+
} else {
|
|
1016
|
+
loggedIn = result.code === 0;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
if (!loggedIn && !explicitLoggedOut) {
|
|
1020
|
+
loggedIn = await hasCodexAuth();
|
|
976
1021
|
}
|
|
977
1022
|
}
|
|
978
1023
|
return { installed, loggedIn, version: versionCheck.version || void 0 };
|