@commonlyai/cli 0.1.298 → 0.1.300
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/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Commonly CLI
|
|
2
2
|
|
|
3
|
-
Developer CLI for Commonly — log in,
|
|
3
|
+
Developer CLI for Commonly — log in, connect your computer so your own AI agents can join pods, scaffold a custom bot, tail pod messages, manage a local dev environment.
|
|
4
4
|
|
|
5
5
|
**User guide with every subcommand + config format + troubleshooting:** [`/docs/cli/README.md`](../docs/cli/README.md)
|
|
6
6
|
|
|
7
7
|
**Deep dives:**
|
|
8
|
-
- [Local CLI wrapper](../docs/agents/LOCAL_CLI_WRAPPER.md) — `attach` / `run` / `detach` lifecycle
|
|
8
|
+
- [Local CLI wrapper](../docs/agents/LOCAL_CLI_WRAPPER.md) — connecting a computer (`daemon register` / `install`), and the older `attach` / `run` / `detach` lifecycle
|
|
9
9
|
- [Webhook SDK](../docs/agents/WEBHOOK_SDK.md) — `init` + Python reference bot
|
|
10
10
|
|
|
11
11
|
## Run from source
|
|
@@ -180,6 +180,13 @@ export const readUpstreamRefusal = (stdout, { credentials = [] } = {}) => {
|
|
|
180
180
|
if (attemptStatus) {
|
|
181
181
|
status = attemptStatus;
|
|
182
182
|
raw = bodyFromError(candidate);
|
|
183
|
+
} else if (typeof candidate === 'string' && candidate.trim()) {
|
|
184
|
+
// F341: the retries ended on a failure that names no status ("fetch
|
|
185
|
+
// failed"), so that is the turn's cause, not a 429 an earlier attempt
|
|
186
|
+
// hit. Holding the old status named the turn refused and it went
|
|
187
|
+
// unretried. An end with no error text at all says nothing, and keeps it.
|
|
188
|
+
status = null;
|
|
189
|
+
raw = null;
|
|
183
190
|
}
|
|
184
191
|
continue;
|
|
185
192
|
}
|
package/package.json
CHANGED
|
@@ -83,6 +83,7 @@ import { isLegacySandboxTrust, normalizeSandboxTrust, refuseWorkspaceTrust } fro
|
|
|
83
83
|
import { contains, realpathOfNearest, refuseWorkspaceHoldingTurnDirs } from '../sandbox/turn-dir.js';
|
|
84
84
|
import { adapterFailure, spawnCredentials } from '../upstream-refusal.js';
|
|
85
85
|
import { publicSeatWithheldTools } from '../public-withheld-tools.js';
|
|
86
|
+
import { startProviderProxy } from '../provider-proxy.js';
|
|
86
87
|
import { resolveLaunch, resolveMcpCommand, resolveWindowsCommandWithReason } from '../windows-command.js';
|
|
87
88
|
|
|
88
89
|
// Default timeout for a single codex spawn (exec mode).
|
|
@@ -382,7 +383,10 @@ const operatorCodexHome = (ctx) => ctx.env?.CODEX_HOME
|
|
|
382
383
|
|| process.env.CODEX_HOME
|
|
383
384
|
|| join(homedir(), '.codex');
|
|
384
385
|
|
|
385
|
-
|
|
386
|
+
// `login: false` is the proxy route (D250): codex authenticates with the
|
|
387
|
+
// per-turn token, so the public home gets no link to the person's Codex login,
|
|
388
|
+
// and a link an earlier turn left is removed.
|
|
389
|
+
const preparePublicCodexHome = async (ctx, childEnv, { login = true } = {}) => {
|
|
386
390
|
const operatorHome = operatorCodexHome(ctx);
|
|
387
391
|
const identity = ctx.agentName || ctx.cwd || 'anonymous';
|
|
388
392
|
const identityHash = createHash('sha256').update(identity).digest('hex').slice(0, 20);
|
|
@@ -444,7 +448,9 @@ const preparePublicCodexHome = async (ctx, childEnv) => {
|
|
|
444
448
|
if (targetStat && !targetStat.isSymbolicLink()) {
|
|
445
449
|
throw new Error(`refusing to replace non-symlink public Codex credential: ${targetAuth}`);
|
|
446
450
|
}
|
|
447
|
-
if (
|
|
451
|
+
if (!login) {
|
|
452
|
+
if (targetStat) await unlink(targetAuth);
|
|
453
|
+
} else if (sourceStat) {
|
|
448
454
|
const currentTarget = targetStat
|
|
449
455
|
? pathResolve(dirname(targetAuth), await readlink(targetAuth))
|
|
450
456
|
: null;
|
|
@@ -750,9 +756,10 @@ export const publicModelRouteBaseUrl = (source = {}) => {
|
|
|
750
756
|
// it is kept or logged. Only "apikey" counts as a key; a file with any other
|
|
751
757
|
// mode, no mode, or that does not parse is treated as a login and fails closed,
|
|
752
758
|
// whatever OPENAI_API_KEY says, since codex prefers its stored login. With no
|
|
753
|
-
// auth.json, an OPENAI_API_KEY
|
|
754
|
-
//
|
|
755
|
-
// it counts as a login whatever
|
|
759
|
+
// auth.json, an OPENAI_API_KEY in the env is the key (a CODEX_API_KEY never gets
|
|
760
|
+
// here: it takes the proxy route below). A CODEX_ACCESS_TOKEN in the env is a
|
|
761
|
+
// token codex sends in place of a key, so it counts as a login whatever
|
|
762
|
+
// auth.json says.
|
|
756
763
|
const CODEX_OWN_AUTH_ENVS = ['OPENAI_API_KEY', 'CODEX_API_KEY', 'CODEX_ACCESS_TOKEN', 'OPENAI_BASE_URL'];
|
|
757
764
|
|
|
758
765
|
const CHATGPT_ROUTE_IGNORED = 'OPENAI_BASE_URL is ignored while Codex is signed in with ChatGPT; '
|
|
@@ -769,13 +776,45 @@ export const codexAuthKind = async (operatorHome, source = {}) => {
|
|
|
769
776
|
if (err?.code !== 'ENOENT' && err?.code !== 'ENOTDIR') return 'login';
|
|
770
777
|
}
|
|
771
778
|
if (text === null) {
|
|
772
|
-
return envSet(source, 'OPENAI_API_KEY')
|
|
779
|
+
return envSet(source, 'OPENAI_API_KEY') ? 'apikey' : 'none';
|
|
773
780
|
}
|
|
774
781
|
let mode = null;
|
|
775
782
|
try { mode = JSON.parse(text)?.auth_mode ?? null; } catch { /* unreadable: a login */ }
|
|
776
783
|
return mode === 'apikey' ? 'apikey' : 'login';
|
|
777
784
|
};
|
|
778
785
|
|
|
786
|
+
// D250: the F188 route leaves the key in codex's own environment. With
|
|
787
|
+
// CODEX_API_KEY in the seat's environment (codex's own name for an exec key),
|
|
788
|
+
// the key stays on the host behind the per-turn loopback proxy, as a Claude
|
|
789
|
+
// seat's ANTHROPIC_API_KEY does, and codex gets a provider entry naming the
|
|
790
|
+
// proxy plus a per-turn token in an env var of our own. Measured on 0.162.1
|
|
791
|
+
// with `--ignore-user-config`: these two `-c` overrides sent
|
|
792
|
+
// `POST <base_url>/responses` with `Authorization: Bearer $<env_key>`. The URL
|
|
793
|
+
// passes the same check as F188's. Without this key the seat takes F188's
|
|
794
|
+
// route or the person's Codex login, as before.
|
|
795
|
+
const CODEX_PROXY_PROVIDER = 'commonly_proxy';
|
|
796
|
+
const CODEX_PROVIDER_TOKEN_ENV = 'COMMONLY_CODEX_PROVIDER_TOKEN';
|
|
797
|
+
const OPENAI_DEFAULT_BASE_URL = 'https://api.openai.com/v1';
|
|
798
|
+
|
|
799
|
+
const publicProviderRoute = (source = {}) => {
|
|
800
|
+
if (!envSet(source, 'CODEX_API_KEY')) return null;
|
|
801
|
+
return {
|
|
802
|
+
baseURL: publicModelRouteBaseUrl(source) || OPENAI_DEFAULT_BASE_URL,
|
|
803
|
+
key: source.CODEX_API_KEY.trim(),
|
|
804
|
+
};
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
const providerRouteFlags = (proxy) => {
|
|
808
|
+
if (!proxy) return [];
|
|
809
|
+
// codex appends `/responses` itself, so a trailing slash would double it.
|
|
810
|
+
const baseUrl = proxy.baseURL.replace(/\/+$/, '');
|
|
811
|
+
return [
|
|
812
|
+
'-c', `model_provider=${toml(CODEX_PROXY_PROVIDER)}`,
|
|
813
|
+
'-c', `model_providers.${CODEX_PROXY_PROVIDER}={name=${toml('Commonly host proxy')},`
|
|
814
|
+
+ `base_url=${toml(baseUrl)},env_key=${toml(CODEX_PROVIDER_TOKEN_ENV)},wire_api="responses"}`,
|
|
815
|
+
];
|
|
816
|
+
};
|
|
817
|
+
|
|
779
818
|
// Build the argv after the `codex` binary. Resume vs new turn is a
|
|
780
819
|
// subcommand-level distinction in modern codex, not an option flag — keep
|
|
781
820
|
// that detail isolated here so the spawn path stays linear.
|
|
@@ -791,6 +830,7 @@ const buildArgs = ({
|
|
|
791
830
|
mcpReadDirectories = [],
|
|
792
831
|
codexHelperReadPaths = [],
|
|
793
832
|
modelBaseUrl = null,
|
|
833
|
+
providerProxy = null,
|
|
794
834
|
platform = process.platform,
|
|
795
835
|
workspacePath = null,
|
|
796
836
|
}) => {
|
|
@@ -821,6 +861,7 @@ const buildArgs = ({
|
|
|
821
861
|
platform,
|
|
822
862
|
workspacePath,
|
|
823
863
|
),
|
|
864
|
+
...providerRouteFlags(providerProxy),
|
|
824
865
|
...PUBLIC_BUILTIN_TOOL_FLAGS,
|
|
825
866
|
]
|
|
826
867
|
: ['--dangerously-bypass-approvals-and-sandbox'];
|
|
@@ -1071,6 +1112,7 @@ export default {
|
|
|
1071
1112
|
root: dir,
|
|
1072
1113
|
});
|
|
1073
1114
|
|
|
1115
|
+
let providerProxy = null;
|
|
1074
1116
|
try {
|
|
1075
1117
|
const mcp = buildMcpOverrideArgs(ctx.environment?.mcp, {
|
|
1076
1118
|
runtimeToken: ctx.runtimeToken,
|
|
@@ -1101,14 +1143,25 @@ export default {
|
|
|
1101
1143
|
// Checked before the public home is prepared, so a refused route changes nothing.
|
|
1102
1144
|
// Only a seat that will forward the URL validates it: a ChatGPT host with an
|
|
1103
1145
|
// OPENAI_BASE_URL set for some other tool keeps running, as it did before.
|
|
1104
|
-
let modelBaseUrl = null;
|
|
1105
1146
|
const routeEnv = ctx.env || process.env;
|
|
1106
|
-
|
|
1147
|
+
const route = publicSandboxMode !== null ? publicProviderRoute(routeEnv) : null;
|
|
1148
|
+
let modelBaseUrl = null;
|
|
1149
|
+
if (!route && publicSandboxMode !== null && String(routeEnv.OPENAI_BASE_URL || '').trim()) {
|
|
1107
1150
|
const authKind = await codexAuthKind(operatorCodexHome(ctx), routeEnv);
|
|
1108
1151
|
if (authKind === 'apikey') modelBaseUrl = publicModelRouteBaseUrl(routeEnv);
|
|
1109
1152
|
else if (authKind === 'login') process.stderr.write(`[codex] ${CHATGPT_ROUTE_IGNORED}\n`);
|
|
1110
1153
|
}
|
|
1111
1154
|
const childEnv = { ...(ctx.env || process.env), ...mcp.forwardedEnv };
|
|
1155
|
+
// codex talks to the proxy alone, so none of the names it or its gateway
|
|
1156
|
+
// read stays in its environment, on the turn or on the version probe; the
|
|
1157
|
+
// turn gets the per-turn token instead. In upper case, as above: Windows
|
|
1158
|
+
// env names are case-insensitive, and this is a plain copy of them.
|
|
1159
|
+
if (route) {
|
|
1160
|
+
const routeNames = new Set([...CODEX_PROVIDER_KEY_ENVS, ...CODEX_OWN_AUTH_ENVS]);
|
|
1161
|
+
for (const name of Object.keys(childEnv)) {
|
|
1162
|
+
if (routeNames.has(name.toUpperCase())) delete childEnv[name];
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1112
1165
|
// Before the public home is prepared, so a refused seat changes nothing.
|
|
1113
1166
|
if (publicSandboxMode !== null) {
|
|
1114
1167
|
const codexVersion = await readCodexVersion(ctx, childEnv);
|
|
@@ -1117,8 +1170,17 @@ export default {
|
|
|
1117
1170
|
}
|
|
1118
1171
|
}
|
|
1119
1172
|
const publicCodexHome = publicSandboxMode !== null
|
|
1120
|
-
? await preparePublicCodexHome(ctx, childEnv)
|
|
1173
|
+
? await preparePublicCodexHome(ctx, childEnv, { login: !route })
|
|
1121
1174
|
: null;
|
|
1175
|
+
if (route) {
|
|
1176
|
+
providerProxy = await (ctx._startProviderProxy || startProviderProxy)({
|
|
1177
|
+
provider: { baseURL: route.baseURL },
|
|
1178
|
+
keyMaterial: route.key,
|
|
1179
|
+
wire: 'openai-responses',
|
|
1180
|
+
adapterLabel: 'Codex',
|
|
1181
|
+
});
|
|
1182
|
+
childEnv[CODEX_PROVIDER_TOKEN_ENV] = providerProxy.token;
|
|
1183
|
+
}
|
|
1122
1184
|
const args = buildArgs({
|
|
1123
1185
|
sessionId: ctx.sessionId || null,
|
|
1124
1186
|
prompt: fullPrompt,
|
|
@@ -1131,6 +1193,7 @@ export default {
|
|
|
1131
1193
|
commitAttributionEnv: ctx.commitAttributionEnv,
|
|
1132
1194
|
codexHelperReadPaths: publicCodexHome?.helperReadPaths || [],
|
|
1133
1195
|
modelBaseUrl,
|
|
1196
|
+
providerProxy,
|
|
1134
1197
|
platform: ctx._platform || process.platform,
|
|
1135
1198
|
workspacePath,
|
|
1136
1199
|
});
|
|
@@ -1168,7 +1231,8 @@ export default {
|
|
|
1168
1231
|
// authenticates with. Snapshot HERE — `withholdRuntimeCredential` above
|
|
1169
1232
|
// already removed the token from the child copy, and after that there is
|
|
1170
1233
|
// nothing left to compare a tail against.
|
|
1171
|
-
|
|
1234
|
+
// The per-turn proxy token is one too: codex was handed it in place of the key.
|
|
1235
|
+
credentials: [...spawnCredentials(ctx, CODEX_PROVIDER_KEY_ENVS), route?.key, providerProxy?.token].filter(Boolean),
|
|
1172
1236
|
spawnImpl: ctx._spawnImpl, onSpawn: ctx.onSpawn, controls: controlsFromArguments(args.slice(args.indexOf('exec') + (args[args.indexOf('exec') + 1] === 'resume' ? 3 : 1), -1), { modelFlag: '--model', valueFlags: ['-c', '-o', '--permission-profile'], codex: true }), // test seam only — do not use in production
|
|
1173
1237
|
ownGroup: wantsOwnProcessGroup(ctx),
|
|
1174
1238
|
turnReap: ctx._turnReap,
|
|
@@ -1208,6 +1272,7 @@ export default {
|
|
|
1208
1272
|
...(typeof effort === 'string' && effort ? { effort } : {}) };
|
|
1209
1273
|
return { text, newSessionId, ...(Object.keys(stats).length ? { stats } : {}) };
|
|
1210
1274
|
} finally {
|
|
1275
|
+
try { await providerProxy?.close(); } catch { /* ignore */ }
|
|
1211
1276
|
try { await rm(dir, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
1212
1277
|
}
|
|
1213
1278
|
},
|