@livx.cc/agentx 0.99.167 → 0.99.169

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/cli.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bun
2
- import { w as RouterState, H as Hooks, c as AgentOptions, x as RunResult, f as ChatUsage, R as ReasoningEffort, d as ChannelMode, b as Agent } from './secondChannel-DLB-hDny.js';
2
+ import { w as RouterState, H as Hooks, c as AgentOptions, x as RunResult, f as ChatUsage, R as ReasoningEffort, d as ChannelMode, b as Agent } from './secondChannel-CaP6zhH6.js';
3
3
  import { IFilesystem } from '@livx.cc/wcli/core';
4
4
  import { M as Message, U as UserQuestion, H as HostBridge, c as ContentPart, o as MessageContent } from './tools-DwfeF8VQ.js';
5
5
 
@@ -34,6 +34,12 @@ interface SessionMeta {
34
34
  n: number;
35
35
  model: string;
36
36
  };
37
+ /** codex/*: the Codex thread behind this transcript (resumed by id while the transcript is still its `n` messages). */
38
+ codex?: {
39
+ thread: string;
40
+ n: number;
41
+ model: string;
42
+ };
37
43
  /** Sticky delegate/advisor mode set by a `[a->b]` / `[a<-b]` directive (`{}` = cleared by `[off]`) — outlives
38
44
  * the process, so a resumed `-r` turn without a prefix keeps it. Absent = never set (the flags apply). */
39
45
  mode?: TurnMode;
@@ -195,6 +201,15 @@ interface Args {
195
201
  trust?: boolean;
196
202
  }
197
203
  declare function parseArgs(argv: string[]): Args;
204
+ /**
205
+ * Codex routing for a requested model, before the API catalog: a BARE id the Codex subscription serves (`gpt-6.2-astra`)
206
+ * -> `codex/<id>` (the subscription wins over the paid `openai/` API, which stays reachable by its prefix). An explicit
207
+ * `codex/<id>` this account does not serve THROWS: falling back to another model would be a silent billing switch.
208
+ * undefined = not a Codex question, resolve as usual.
209
+ */
210
+ declare function codexRoute(want: string, served: string[]): string | undefined;
211
+ /** Banner billing note for codex/*: which Codex profile pays (`~/.codex-circles` → "circles"), never the API. */
212
+ declare function codexBilling(model: string, home?: string | undefined): string;
198
213
  /** Fallback .env loader: CWD .env (bun), install-dir .env, then ~/.agent/.env (user-wide). Never overrides. */
199
214
  declare function loadInstallEnv(): void;
200
215
  /** Fetch secrets from a Bodify app's secrets store into process.env: overrides .env-file values, never the shell's.
@@ -421,4 +436,4 @@ declare function duplexError(e: unknown, reflexModel: string): string;
421
436
  * the next turn (a re-final's fuller text) runs warm, as if that one was never sent. Returns the messages dropped. */
422
437
  declare function rollbackTurn(agent: Agent, store: Pick<SessionStore, 'save'>, session: SessionData, start: number): Promise<number>;
423
438
 
424
- export { type PermMode, abortActiveTurn, apiKeysFromEnv, appendMemoryNote, applyTurnMode, cacheMultipliers, condenseReplay, costOf, duplexError, duplexModels, estimateTranscriptTokens, expandMentions, exportMarkdown, fmtUsd, formatHistory, formatStatus, formatTranscriptFull, jsonResult, loadBodifySecrets, loadInstallEnv, makeHost, mcpMentionResolver, mentionRefs, modelUsable, parseArgs, pastePathClassifier, readImageParts, readMultiline, resolvePermMode, rollbackTurn, runShellLine, runTurn, setMcpMentionResolver, summarizeResult, turnCost };
439
+ export { type PermMode, abortActiveTurn, apiKeysFromEnv, appendMemoryNote, applyTurnMode, cacheMultipliers, codexBilling, codexRoute, condenseReplay, costOf, duplexError, duplexModels, estimateTranscriptTokens, expandMentions, exportMarkdown, fmtUsd, formatHistory, formatStatus, formatTranscriptFull, jsonResult, loadBodifySecrets, loadInstallEnv, makeHost, mcpMentionResolver, mentionRefs, modelUsable, parseArgs, pastePathClassifier, readImageParts, readMultiline, resolvePermMode, rollbackTurn, runShellLine, runTurn, setMcpMentionResolver, summarizeResult, turnCost };
package/dist/cli.js CHANGED
@@ -2816,6 +2816,10 @@ function findOnPath(cmd, env = process.env) {
2816
2816
  }
2817
2817
  return void 0;
2818
2818
  }
2819
+ function codexBin(env = process.env) {
2820
+ const home = env.HOME ?? env.USERPROFILE ?? "";
2821
+ return findOnPath("codex", env) ?? (IS_WIN ? void 0 : [np2.join(home, ".local/bin/codex"), "/opt/homebrew/bin/codex", "/usr/local/bin/codex"].find(isFile));
2822
+ }
2819
2823
  function hasCommand(cmd) {
2820
2824
  if (!IS_WIN) return spawnSync2("which", [cmd]).status === 0;
2821
2825
  return !!findOnPath(cmd);
@@ -3366,8 +3370,10 @@ import { spawnSync as spawnSync7 } from "child_process";
3366
3370
  // src/runtimes.ts
3367
3371
  var RUNTIMES = {
3368
3372
  "claude-code": { keyless: true, ownsTools: true },
3369
- cursor: { keyless: false, ownsTools: false }
3373
+ cursor: { keyless: false, ownsTools: false },
3370
3374
  // host tools are bridged in through its toolExecutor
3375
+ codex: { keyless: true, ownsTools: true }
3376
+ // `codex app-server` on the ChatGPT subscription login; MCP via per-thread config
3371
3377
  };
3372
3378
  function runtimeOf(model) {
3373
3379
  const p = (model ?? "").split("/")[0];
@@ -3376,6 +3382,7 @@ function runtimeOf(model) {
3376
3382
  var isDelegated = (model) => !!runtimeOf(model);
3377
3383
  var isClaudeCode = (model) => runtimeOf(model) === "claude-code";
3378
3384
  var isCursor = (model) => runtimeOf(model) === "cursor";
3385
+ var isCodex = (model) => runtimeOf(model) === "codex";
3379
3386
  var isKeyless = (modelOrProvider) => {
3380
3387
  const p = (modelOrProvider ?? "").split("/")[0];
3381
3388
  return !!RUNTIMES[p]?.keyless;
@@ -3463,7 +3470,7 @@ function copyTextToClipboard(text, platform2 = process.platform) {
3463
3470
 
3464
3471
  // cli/cli.ts
3465
3472
  import { join as join17, resolve as resolve5, basename as basename4, extname, dirname as dirname6 } from "path";
3466
- import { AIClient as AIClient2, listModels, listProviders, getProviderFromModel, getModelInfo, resolveModel, isModelSupported, disposeCursorSessions, disposeClaudeCodeSessions, rewindClaudeCodeSession } from "ai.libx.js";
3473
+ import { AIClient as AIClient2, listModels, listProviders, getProviderFromModel, getModelInfo, resolveModel, isModelSupported, disposeCursorSessions, disposeClaudeCodeSessions, rewindClaudeCodeSession, disposeCodexSessions, listCliModels } from "ai.libx.js";
3467
3474
 
3468
3475
  // src/ccBridge.ts
3469
3476
  var CC_BRIDGED = /* @__PURE__ */ new Set(["Recall", "Remember", "MemorySearch", "Forget"]);
@@ -5287,6 +5294,20 @@ var Agent = class _Agent {
5287
5294
  this.parkedMs += Date.now() - t;
5288
5295
  }
5289
5296
  }
5297
+ /** codex/*: Codex runs its own tools, so its approval requests (a command, a file change) go through the SAME hooks an
5298
+ * agentx tool call does: permission policy (allow/deny/ask resolver -> live `waiting`/`denied`), plan mode. The wait
5299
+ * holds the stall watchdog (a human may take minutes; Codex is silent meanwhile) and is parked out of the timeout. */
5300
+ async codexApprove(req) {
5301
+ const call = codexApprovalCall(req);
5302
+ const job = this.jobs.track({ kind: "host", label: `approve:${call.name}`, holds: true });
5303
+ try {
5304
+ const r = await this.park(Promise.resolve(this.activeHooks?.preToolUse?.(call, { id: "codex-approval" })));
5305
+ return r?.block ? "decline" : "accept";
5306
+ } finally {
5307
+ job.finish("done");
5308
+ this.stallPoke?.();
5309
+ }
5310
+ }
5290
5311
  /** Force the next `send()`/`run()` to rebuild the system prompt, tools, plan-mode and permission hooks
5291
5312
  * from `options` — apply mid-conversation changes to `planMode`/`permissions`/`model` etc. (prepare()
5292
5313
  * is otherwise memoized per conversation). */
@@ -5520,7 +5541,7 @@ var Agent = class _Agent {
5520
5541
  tools: worker ? delegateTools([...o.tools, ...this.injectedTools], o.model, o.delegate?.plannerMay) : [...o.tools, ...this.injectedTools],
5521
5542
  systemPrompt: o.systemPrompt,
5522
5543
  // A child never resumes the parent's own claude-code session (the host's `resume` link is the parent's).
5523
- providerOptionsFor: o.providerOptionsFor ?? ((m) => modelProvider(m) === modelProvider(o.model) && o.providerOptions ? { ...o.providerOptions, resume: void 0, onClaudeCodeSession: void 0 } : void 0)
5544
+ providerOptionsFor: o.providerOptionsFor ?? ((m) => modelProvider(m) === modelProvider(o.model) && o.providerOptions ? { ...o.providerOptions, resume: void 0, onClaudeCodeSession: void 0, onCodexThread: void 0 } : void 0)
5524
5545
  };
5525
5546
  tools = [...tools, makeTaskTool(taskOpts), makeTaskBatchTool(taskOpts)];
5526
5547
  }
@@ -5718,6 +5739,7 @@ var Agent = class _Agent {
5718
5739
  };
5719
5740
  const cursorPo = isCursorWithTools ? { toolTimeoutMs: effectiveToolTimeoutMs, toolExecutor: hostExec } : void 0;
5720
5741
  const claudeSteerPo = this.claudeCodePo();
5742
+ const codexPo = isCodex(o.model) ? { onApproval: (req) => this.codexApprove(req) } : void 0;
5721
5743
  if (this.ccServer) this.ccExec = hostExec;
5722
5744
  const cursorDeny = isCursor(o.model) ? o.permissions?.denyRules(true) ?? [] : [];
5723
5745
  if (isCursor(o.model) && o.permissions?.options.default === "deny")
@@ -5727,7 +5749,7 @@ var Agent = class _Agent {
5727
5749
  const reasonOpts = {
5728
5750
  ...frag,
5729
5751
  ...o.promptCache ? { promptCache: true } : {},
5730
- ...o.providerOptions || cursorPo || claudeSteerPo ? { providerOptions: { ...frag.providerOptions, ...o.providerOptions, ...cursorPo, ...claudeSteerPo } } : {}
5752
+ ...o.providerOptions || cursorPo || claudeSteerPo || codexPo ? { providerOptions: { ...frag.providerOptions, ...o.providerOptions, ...cursorPo, ...claudeSteerPo, ...codexPo } } : {}
5731
5753
  };
5732
5754
  try {
5733
5755
  for (let attempt = 0; ; attempt++) {
@@ -6573,6 +6595,12 @@ function toolKey(name) {
6573
6595
  const k = name.toLowerCase();
6574
6596
  return TOOL_ALIASES[k] ?? k;
6575
6597
  }
6598
+ function codexApprovalCall(req) {
6599
+ if (req.kind === "command") return { name: "bash", args: { command: req.command ?? "", ...req.cwd ? { cwd: req.cwd } : {} } };
6600
+ if (req.kind === "mcpToolCall") return { name: `mcp__${req.server ?? ""}__${req.tool ?? ""}`, args: req.args ?? {} };
6601
+ const paths = (req.changes ?? []).map((c) => c.path);
6602
+ return { name: "Edit", args: { path: paths[0] ?? "", ...paths.length > 1 ? { paths } : {} } };
6603
+ }
6576
6604
 
6577
6605
  // src/index.ts
6578
6606
  init_models();
@@ -17473,8 +17501,34 @@ function claudeCodeProviderOptions(model, cwd, mcpServers) {
17473
17501
  const warm = process.env.AGENTX_CC_WARM === "0" ? {} : { claudeCodeSession: randomUUID() };
17474
17502
  return { cwd, env, ...warm, ...toClaudeCodeMcp(mcpServers) ?? {} };
17475
17503
  }
17504
+ function toCodexMcp(servers) {
17505
+ if (!servers) return void 0;
17506
+ const out = {};
17507
+ for (const [name, s] of Object.entries(servers)) {
17508
+ if (!s || s.disabled) continue;
17509
+ if (s.command) {
17510
+ out[`mcp_servers.${name}`] = { command: s.command, ...s.args ? { args: s.args } : {}, ...s.env ? { env: s.env } : {}, ...s.cwd ? { cwd: s.cwd } : {} };
17511
+ } else if (s.url) {
17512
+ if (s.auth === "oauth" && !s.bearerToken) continue;
17513
+ const headers = { ...s.headers ?? {}, ...s.bearerToken ? { Authorization: `Bearer ${s.bearerToken}` } : {} };
17514
+ out[`mcp_servers.${name}`] = { url: s.url, ...Object.keys(headers).length ? { http_headers: headers } : {} };
17515
+ }
17516
+ }
17517
+ return Object.keys(out).length ? out : void 0;
17518
+ }
17519
+ function codexProviderOptions(model, cwd, mcpServers) {
17520
+ if (!isCodex(model)) return void 0;
17521
+ const config = toCodexMcp(mcpServers);
17522
+ return {
17523
+ cwd,
17524
+ ...process.env.CODEX_HOME ? { codexHome: process.env.CODEX_HOME } : {},
17525
+ ...codexBin() ? { codexBin: codexBin() } : {},
17526
+ ...config ? { config } : {},
17527
+ ...process.env.AGENTX_CODEX_WARM === "0" ? {} : { codexSession: randomUUID() }
17528
+ };
17529
+ }
17476
17530
  function providerOptionsFor(model, cwd, mcpServers, hostMcpServers) {
17477
- return cursorProviderOptions(model, cwd, mcpServers, hostMcpServers) ?? claudeCodeProviderOptions(model, cwd, mcpServers);
17531
+ return cursorProviderOptions(model, cwd, mcpServers, hostMcpServers) ?? claudeCodeProviderOptions(model, cwd, mcpServers) ?? codexProviderOptions(model, cwd, mcpServers);
17478
17532
  }
17479
17533
  var CONFINE_DENY = ["**/.agent", "**/.agent/**", "**/.claude", "**/.claude/**", "**/.mcp.json", "**/AGENTS.md", "**/CLAUDE.md", "**/CLAUDE.local.md"];
17480
17534
  async function buildAgent(o) {
@@ -17618,7 +17672,7 @@ Reference files in them by their mount path (the left side).`;
17618
17672
  // worker under an anthropic planner ran with none. Same provider: the Agent default (parent's, minus its resume).
17619
17673
  providerOptionsFor: (m) => {
17620
17674
  const a = agentRef.agent, po = a?.options.providerOptions;
17621
- if (modelProvider(m) === modelProvider(a?.options.model ?? "")) return po ? { ...po, resume: void 0, onClaudeCodeSession: void 0 } : void 0;
17675
+ if (modelProvider(m) === modelProvider(a?.options.model ?? "")) return po ? { ...po, resume: void 0, onClaudeCodeSession: void 0, onCodexThread: void 0 } : void 0;
17622
17676
  return providerOptionsFor(m, cwd, o.mcpServers, o.hostMcpServers);
17623
17677
  },
17624
17678
  ...(() => {
@@ -22745,10 +22799,12 @@ function printModels() {
22745
22799
  if (!byProvider.has(provider)) byProvider.set(provider, []);
22746
22800
  byProvider.get(provider).push(id);
22747
22801
  }
22802
+ if (codexModels().length) byProvider.set("codex", codexModels().map((m) => `codex/${m}`));
22748
22803
  for (const [provider, ids] of Array.from(byProvider.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
22749
22804
  console.log(`
22750
22805
  ${provider}`);
22751
- ids.sort((a, b) => (getModelInfo(b)?.releaseDate ?? "").localeCompare(getModelInfo(a)?.releaseDate ?? ""));
22806
+ if (provider === "codex") console.log(` (Codex subscription \xB7 ${process.env.CODEX_HOME ?? "~/.codex"})`);
22807
+ else ids.sort((a, b) => (getModelInfo(b)?.releaseDate ?? "").localeCompare(getModelInfo(a)?.releaseDate ?? ""));
22752
22808
  for (const id of ids) {
22753
22809
  const info = getModelInfo(id);
22754
22810
  const meta = [info?.displayName, info?.releaseDate].filter(Boolean).join(" \xB7 ");
@@ -22756,8 +22812,27 @@ ${provider}`);
22756
22812
  }
22757
22813
  }
22758
22814
  }
22815
+ var codexModels = /* @__PURE__ */ (() => {
22816
+ let c;
22817
+ return () => c ??= codexBin() ? listCliModels("codex").map((m) => m.value) : [];
22818
+ })();
22819
+ function codexRoute(want, served) {
22820
+ if (want.startsWith("codex/")) {
22821
+ const id = want.slice("codex/".length);
22822
+ if (served.includes(id)) return want;
22823
+ throw new Error(served.length ? `model "${want}" is not served by this Codex login (${process.env.CODEX_HOME ?? "~/.codex"}). Available: ${served.map((m) => `codex/${m}`).join(", ")}` : `model "${want}" needs the Codex CLI signed in to a ChatGPT subscription (no \`codex\` on PATH, or no models_cache.json in ${process.env.CODEX_HOME ?? "~/.codex"}). Run \`CODEX_HOME=<profile> codex login\`.`);
22824
+ }
22825
+ return !want.includes("/") && served.includes(want) ? `codex/${want}` : void 0;
22826
+ }
22827
+ function codexBilling(model, home = process.env.CODEX_HOME) {
22828
+ if (!model.startsWith("codex/")) return "";
22829
+ const base = home ? home.replace(/\/+$/, "").split("/").pop() : ".codex";
22830
+ return ` \xB7 Codex subscription \xB7 ${base.replace(/^\.codex-?/, "") || "default"}`;
22831
+ }
22759
22832
  function resolveModelOrNewest(model) {
22760
22833
  const want = model ?? new AgentOptions().model;
22834
+ const routed = codexRoute(want, codexModels());
22835
+ if (routed) return routed;
22761
22836
  const resolved = resolveModel(want);
22762
22837
  if (isModelSupported(resolved)) return resolved;
22763
22838
  const provider = getProviderFromModel(want) ?? void 0;
@@ -23795,6 +23870,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
23795
23870
  }
23796
23871
  function bindClaudeCodeSession(agent, session) {
23797
23872
  const po = agent.options.providerOptions;
23873
+ if (po?.codexSession) return bindCodexThread(agent, session, po);
23798
23874
  if (!po?.claudeCodeSession) return void 0;
23799
23875
  const cc = session.meta.cc, model = agent.options.model;
23800
23876
  let id;
@@ -23806,6 +23882,17 @@ function bindClaudeCodeSession(agent, session) {
23806
23882
  session.meta.cc = ok && id ? { id, n: agent.transcript.length, model } : void 0;
23807
23883
  };
23808
23884
  }
23885
+ function bindCodexThread(agent, session, po) {
23886
+ const cx = session.meta.codex, model = agent.options.model;
23887
+ let id;
23888
+ const resume = cx && cx.model === model && cx.n === agent.transcript.length ? cx.thread : void 0;
23889
+ agent.options.providerOptions = { ...po, resume, onCodexThread: (t) => {
23890
+ id = t;
23891
+ } };
23892
+ return (ok) => {
23893
+ session.meta.codex = ok && id ? { thread: id, n: agent.transcript.length, model } : void 0;
23894
+ };
23895
+ }
23809
23896
  var remintSessionImages = (data, store, cwd) => remintImageRefs(data.messages, [join17(store.dir, `${data.meta.id}.images`), cwd]);
23810
23897
  function startSession(args, store, agent, cwd) {
23811
23898
  if (args.resume || args.cont) {
@@ -24488,6 +24575,10 @@ ${SPOKEN_TURN}`, { id });
24488
24575
  disposeClaudeCodeSessions();
24489
24576
  } catch {
24490
24577
  }
24578
+ try {
24579
+ disposeCodexSessions();
24580
+ } catch {
24581
+ }
24491
24582
  void closeMcp(mounted);
24492
24583
  process.exit(code);
24493
24584
  };
@@ -25796,7 +25887,7 @@ ${task}`;
25796
25887
  quit: { desc: "quit", run: () => true }
25797
25888
  };
25798
25889
  const banner = (line) => err((process.stderr.isTTY ? wrapAnsi(line, process.stderr.columns ?? 80, " ") : line) + "\n");
25799
- banner(bold("agentx") + cyan(" v" + VERSION) + dim(` \u2014 ${work.model} \xB7 ${cwd}`));
25890
+ banner(bold("agentx") + cyan(" v" + VERSION) + dim(` \u2014 ${work.model}${codexBilling(work.model)} \xB7 ${cwd}`));
25800
25891
  banner(dim("Type a task, or /help. Type / or @ for live suggestions (\u2191/\u2193 \u23CE). Esc cancels/clears; double-Esc jumps back; Ctrl-D exits."));
25801
25892
  if (dx) banner(dim(`\u25D1 duplex \u2014 reflex: ${dx.options.reflexModel} \xB7 act: ${work.model}${dx.options.thinkModel !== false ? ` \xB7 think: ${dx.options.thinkModel}` : ""} (real work runs in background tasks, re-voiced when done)`));
25802
25893
  if (args.updateCheck !== false && cfg.updateCheck !== false) checkForUpdate(VERSION).then((msg) => {
@@ -26449,6 +26540,7 @@ ${out}
26449
26540
  releaseStdin();
26450
26541
  disposeCursorSessions();
26451
26542
  disposeClaudeCodeSessions();
26543
+ disposeCodexSessions();
26452
26544
  await closeMcp(mounted);
26453
26545
  process.exit(130);
26454
26546
  }
@@ -26459,6 +26551,7 @@ ${out}
26459
26551
  releaseStdin();
26460
26552
  disposeCursorSessions();
26461
26553
  disposeClaudeCodeSessions();
26554
+ disposeCodexSessions();
26462
26555
  await closeMcp(mounted);
26463
26556
  }
26464
26557
  function duplexError(e, reflexModel) {
@@ -26790,6 +26883,7 @@ async function rollbackTurn(agent, store, session, start) {
26790
26883
  agent.transcript.splice(start);
26791
26884
  session.messages = agent.transcript;
26792
26885
  session.meta.updated = Date.now();
26886
+ session.meta.codex = void 0;
26793
26887
  session.meta.cc = void 0;
26794
26888
  const cc = agent.options.providerOptions?.claudeCodeSession;
26795
26889
  if (typeof cc === "string" && isClaudeCode(agent.options.model)) await rewindClaudeCodeSession(cc);
@@ -26993,6 +27087,8 @@ export {
26993
27087
  appendMemoryNote,
26994
27088
  applyTurnMode,
26995
27089
  cacheMultipliers,
27090
+ codexBilling,
27091
+ codexRoute,
26996
27092
  condenseReplay,
26997
27093
  costOf,
26998
27094
  duplexError,