@livx.cc/agentx 0.99.167 → 0.99.168

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
@@ -3366,8 +3366,10 @@ import { spawnSync as spawnSync7 } from "child_process";
3366
3366
  // src/runtimes.ts
3367
3367
  var RUNTIMES = {
3368
3368
  "claude-code": { keyless: true, ownsTools: true },
3369
- cursor: { keyless: false, ownsTools: false }
3369
+ cursor: { keyless: false, ownsTools: false },
3370
3370
  // host tools are bridged in through its toolExecutor
3371
+ codex: { keyless: true, ownsTools: true }
3372
+ // `codex app-server` on the ChatGPT subscription login; MCP via per-thread config
3371
3373
  };
3372
3374
  function runtimeOf(model) {
3373
3375
  const p = (model ?? "").split("/")[0];
@@ -3376,6 +3378,7 @@ function runtimeOf(model) {
3376
3378
  var isDelegated = (model) => !!runtimeOf(model);
3377
3379
  var isClaudeCode = (model) => runtimeOf(model) === "claude-code";
3378
3380
  var isCursor = (model) => runtimeOf(model) === "cursor";
3381
+ var isCodex = (model) => runtimeOf(model) === "codex";
3379
3382
  var isKeyless = (modelOrProvider) => {
3380
3383
  const p = (modelOrProvider ?? "").split("/")[0];
3381
3384
  return !!RUNTIMES[p]?.keyless;
@@ -3463,7 +3466,7 @@ function copyTextToClipboard(text, platform2 = process.platform) {
3463
3466
 
3464
3467
  // cli/cli.ts
3465
3468
  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";
3469
+ import { AIClient as AIClient2, listModels, listProviders, getProviderFromModel, getModelInfo, resolveModel, isModelSupported, disposeCursorSessions, disposeClaudeCodeSessions, rewindClaudeCodeSession, disposeCodexSessions, listCliModels } from "ai.libx.js";
3467
3470
 
3468
3471
  // src/ccBridge.ts
3469
3472
  var CC_BRIDGED = /* @__PURE__ */ new Set(["Recall", "Remember", "MemorySearch", "Forget"]);
@@ -5287,6 +5290,20 @@ var Agent = class _Agent {
5287
5290
  this.parkedMs += Date.now() - t;
5288
5291
  }
5289
5292
  }
5293
+ /** codex/*: Codex runs its own tools, so its approval requests (a command, a file change) go through the SAME hooks an
5294
+ * agentx tool call does: permission policy (allow/deny/ask resolver -> live `waiting`/`denied`), plan mode. The wait
5295
+ * holds the stall watchdog (a human may take minutes; Codex is silent meanwhile) and is parked out of the timeout. */
5296
+ async codexApprove(req) {
5297
+ const call = codexApprovalCall(req);
5298
+ const job = this.jobs.track({ kind: "host", label: `approve:${call.name}`, holds: true });
5299
+ try {
5300
+ const r = await this.park(Promise.resolve(this.activeHooks?.preToolUse?.(call, { id: "codex-approval" })));
5301
+ return r?.block ? "decline" : "accept";
5302
+ } finally {
5303
+ job.finish("done");
5304
+ this.stallPoke?.();
5305
+ }
5306
+ }
5290
5307
  /** Force the next `send()`/`run()` to rebuild the system prompt, tools, plan-mode and permission hooks
5291
5308
  * from `options` — apply mid-conversation changes to `planMode`/`permissions`/`model` etc. (prepare()
5292
5309
  * is otherwise memoized per conversation). */
@@ -5520,7 +5537,7 @@ var Agent = class _Agent {
5520
5537
  tools: worker ? delegateTools([...o.tools, ...this.injectedTools], o.model, o.delegate?.plannerMay) : [...o.tools, ...this.injectedTools],
5521
5538
  systemPrompt: o.systemPrompt,
5522
5539
  // 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)
5540
+ 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
5541
  };
5525
5542
  tools = [...tools, makeTaskTool(taskOpts), makeTaskBatchTool(taskOpts)];
5526
5543
  }
@@ -5718,6 +5735,7 @@ var Agent = class _Agent {
5718
5735
  };
5719
5736
  const cursorPo = isCursorWithTools ? { toolTimeoutMs: effectiveToolTimeoutMs, toolExecutor: hostExec } : void 0;
5720
5737
  const claudeSteerPo = this.claudeCodePo();
5738
+ const codexPo = isCodex(o.model) ? { onApproval: (req) => this.codexApprove(req) } : void 0;
5721
5739
  if (this.ccServer) this.ccExec = hostExec;
5722
5740
  const cursorDeny = isCursor(o.model) ? o.permissions?.denyRules(true) ?? [] : [];
5723
5741
  if (isCursor(o.model) && o.permissions?.options.default === "deny")
@@ -5727,7 +5745,7 @@ var Agent = class _Agent {
5727
5745
  const reasonOpts = {
5728
5746
  ...frag,
5729
5747
  ...o.promptCache ? { promptCache: true } : {},
5730
- ...o.providerOptions || cursorPo || claudeSteerPo ? { providerOptions: { ...frag.providerOptions, ...o.providerOptions, ...cursorPo, ...claudeSteerPo } } : {}
5748
+ ...o.providerOptions || cursorPo || claudeSteerPo || codexPo ? { providerOptions: { ...frag.providerOptions, ...o.providerOptions, ...cursorPo, ...claudeSteerPo, ...codexPo } } : {}
5731
5749
  };
5732
5750
  try {
5733
5751
  for (let attempt = 0; ; attempt++) {
@@ -6573,6 +6591,12 @@ function toolKey(name) {
6573
6591
  const k = name.toLowerCase();
6574
6592
  return TOOL_ALIASES[k] ?? k;
6575
6593
  }
6594
+ function codexApprovalCall(req) {
6595
+ if (req.kind === "command") return { name: "bash", args: { command: req.command ?? "", ...req.cwd ? { cwd: req.cwd } : {} } };
6596
+ if (req.kind === "mcpToolCall") return { name: `mcp__${req.server ?? ""}__${req.tool ?? ""}`, args: req.args ?? {} };
6597
+ const paths = (req.changes ?? []).map((c) => c.path);
6598
+ return { name: "Edit", args: { path: paths[0] ?? "", ...paths.length > 1 ? { paths } : {} } };
6599
+ }
6576
6600
 
6577
6601
  // src/index.ts
6578
6602
  init_models();
@@ -17473,8 +17497,33 @@ function claudeCodeProviderOptions(model, cwd, mcpServers) {
17473
17497
  const warm = process.env.AGENTX_CC_WARM === "0" ? {} : { claudeCodeSession: randomUUID() };
17474
17498
  return { cwd, env, ...warm, ...toClaudeCodeMcp(mcpServers) ?? {} };
17475
17499
  }
17500
+ function toCodexMcp(servers) {
17501
+ if (!servers) return void 0;
17502
+ const out = {};
17503
+ for (const [name, s] of Object.entries(servers)) {
17504
+ if (!s || s.disabled) continue;
17505
+ if (s.command) {
17506
+ out[`mcp_servers.${name}`] = { command: s.command, ...s.args ? { args: s.args } : {}, ...s.env ? { env: s.env } : {}, ...s.cwd ? { cwd: s.cwd } : {} };
17507
+ } else if (s.url) {
17508
+ if (s.auth === "oauth" && !s.bearerToken) continue;
17509
+ const headers = { ...s.headers ?? {}, ...s.bearerToken ? { Authorization: `Bearer ${s.bearerToken}` } : {} };
17510
+ out[`mcp_servers.${name}`] = { url: s.url, ...Object.keys(headers).length ? { http_headers: headers } : {} };
17511
+ }
17512
+ }
17513
+ return Object.keys(out).length ? out : void 0;
17514
+ }
17515
+ function codexProviderOptions(model, cwd, mcpServers) {
17516
+ if (!isCodex(model)) return void 0;
17517
+ const config = toCodexMcp(mcpServers);
17518
+ return {
17519
+ cwd,
17520
+ ...process.env.CODEX_HOME ? { codexHome: process.env.CODEX_HOME } : {},
17521
+ ...config ? { config } : {},
17522
+ ...process.env.AGENTX_CODEX_WARM === "0" ? {} : { codexSession: randomUUID() }
17523
+ };
17524
+ }
17476
17525
  function providerOptionsFor(model, cwd, mcpServers, hostMcpServers) {
17477
- return cursorProviderOptions(model, cwd, mcpServers, hostMcpServers) ?? claudeCodeProviderOptions(model, cwd, mcpServers);
17526
+ return cursorProviderOptions(model, cwd, mcpServers, hostMcpServers) ?? claudeCodeProviderOptions(model, cwd, mcpServers) ?? codexProviderOptions(model, cwd, mcpServers);
17478
17527
  }
17479
17528
  var CONFINE_DENY = ["**/.agent", "**/.agent/**", "**/.claude", "**/.claude/**", "**/.mcp.json", "**/AGENTS.md", "**/CLAUDE.md", "**/CLAUDE.local.md"];
17480
17529
  async function buildAgent(o) {
@@ -17618,7 +17667,7 @@ Reference files in them by their mount path (the left side).`;
17618
17667
  // worker under an anthropic planner ran with none. Same provider: the Agent default (parent's, minus its resume).
17619
17668
  providerOptionsFor: (m) => {
17620
17669
  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;
17670
+ if (modelProvider(m) === modelProvider(a?.options.model ?? "")) return po ? { ...po, resume: void 0, onClaudeCodeSession: void 0, onCodexThread: void 0 } : void 0;
17622
17671
  return providerOptionsFor(m, cwd, o.mcpServers, o.hostMcpServers);
17623
17672
  },
17624
17673
  ...(() => {
@@ -22745,10 +22794,12 @@ function printModels() {
22745
22794
  if (!byProvider.has(provider)) byProvider.set(provider, []);
22746
22795
  byProvider.get(provider).push(id);
22747
22796
  }
22797
+ if (codexModels().length) byProvider.set("codex", codexModels().map((m) => `codex/${m}`));
22748
22798
  for (const [provider, ids] of Array.from(byProvider.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
22749
22799
  console.log(`
22750
22800
  ${provider}`);
22751
- ids.sort((a, b) => (getModelInfo(b)?.releaseDate ?? "").localeCompare(getModelInfo(a)?.releaseDate ?? ""));
22801
+ if (provider === "codex") console.log(` (Codex subscription \xB7 ${process.env.CODEX_HOME ?? "~/.codex"})`);
22802
+ else ids.sort((a, b) => (getModelInfo(b)?.releaseDate ?? "").localeCompare(getModelInfo(a)?.releaseDate ?? ""));
22752
22803
  for (const id of ids) {
22753
22804
  const info = getModelInfo(id);
22754
22805
  const meta = [info?.displayName, info?.releaseDate].filter(Boolean).join(" \xB7 ");
@@ -22756,8 +22807,27 @@ ${provider}`);
22756
22807
  }
22757
22808
  }
22758
22809
  }
22810
+ var codexModels = /* @__PURE__ */ (() => {
22811
+ let c;
22812
+ return () => c ??= hasCommand("codex") ? listCliModels("codex").map((m) => m.value) : [];
22813
+ })();
22814
+ function codexRoute(want, served) {
22815
+ if (want.startsWith("codex/")) {
22816
+ const id = want.slice("codex/".length);
22817
+ if (served.includes(id)) return want;
22818
+ 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\`.`);
22819
+ }
22820
+ return !want.includes("/") && served.includes(want) ? `codex/${want}` : void 0;
22821
+ }
22822
+ function codexBilling(model, home = process.env.CODEX_HOME) {
22823
+ if (!model.startsWith("codex/")) return "";
22824
+ const base = home ? home.replace(/\/+$/, "").split("/").pop() : ".codex";
22825
+ return ` \xB7 Codex subscription \xB7 ${base.replace(/^\.codex-?/, "") || "default"}`;
22826
+ }
22759
22827
  function resolveModelOrNewest(model) {
22760
22828
  const want = model ?? new AgentOptions().model;
22829
+ const routed = codexRoute(want, codexModels());
22830
+ if (routed) return routed;
22761
22831
  const resolved = resolveModel(want);
22762
22832
  if (isModelSupported(resolved)) return resolved;
22763
22833
  const provider = getProviderFromModel(want) ?? void 0;
@@ -23795,6 +23865,7 @@ async function runTurn(agent, store, session, task, cp, cwd = process.cwd(), sen
23795
23865
  }
23796
23866
  function bindClaudeCodeSession(agent, session) {
23797
23867
  const po = agent.options.providerOptions;
23868
+ if (po?.codexSession) return bindCodexThread(agent, session, po);
23798
23869
  if (!po?.claudeCodeSession) return void 0;
23799
23870
  const cc = session.meta.cc, model = agent.options.model;
23800
23871
  let id;
@@ -23806,6 +23877,17 @@ function bindClaudeCodeSession(agent, session) {
23806
23877
  session.meta.cc = ok && id ? { id, n: agent.transcript.length, model } : void 0;
23807
23878
  };
23808
23879
  }
23880
+ function bindCodexThread(agent, session, po) {
23881
+ const cx = session.meta.codex, model = agent.options.model;
23882
+ let id;
23883
+ const resume = cx && cx.model === model && cx.n === agent.transcript.length ? cx.thread : void 0;
23884
+ agent.options.providerOptions = { ...po, resume, onCodexThread: (t) => {
23885
+ id = t;
23886
+ } };
23887
+ return (ok) => {
23888
+ session.meta.codex = ok && id ? { thread: id, n: agent.transcript.length, model } : void 0;
23889
+ };
23890
+ }
23809
23891
  var remintSessionImages = (data, store, cwd) => remintImageRefs(data.messages, [join17(store.dir, `${data.meta.id}.images`), cwd]);
23810
23892
  function startSession(args, store, agent, cwd) {
23811
23893
  if (args.resume || args.cont) {
@@ -24488,6 +24570,10 @@ ${SPOKEN_TURN}`, { id });
24488
24570
  disposeClaudeCodeSessions();
24489
24571
  } catch {
24490
24572
  }
24573
+ try {
24574
+ disposeCodexSessions();
24575
+ } catch {
24576
+ }
24491
24577
  void closeMcp(mounted);
24492
24578
  process.exit(code);
24493
24579
  };
@@ -25796,7 +25882,7 @@ ${task}`;
25796
25882
  quit: { desc: "quit", run: () => true }
25797
25883
  };
25798
25884
  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}`));
25885
+ banner(bold("agentx") + cyan(" v" + VERSION) + dim(` \u2014 ${work.model}${codexBilling(work.model)} \xB7 ${cwd}`));
25800
25886
  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
25887
  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
25888
  if (args.updateCheck !== false && cfg.updateCheck !== false) checkForUpdate(VERSION).then((msg) => {
@@ -26449,6 +26535,7 @@ ${out}
26449
26535
  releaseStdin();
26450
26536
  disposeCursorSessions();
26451
26537
  disposeClaudeCodeSessions();
26538
+ disposeCodexSessions();
26452
26539
  await closeMcp(mounted);
26453
26540
  process.exit(130);
26454
26541
  }
@@ -26459,6 +26546,7 @@ ${out}
26459
26546
  releaseStdin();
26460
26547
  disposeCursorSessions();
26461
26548
  disposeClaudeCodeSessions();
26549
+ disposeCodexSessions();
26462
26550
  await closeMcp(mounted);
26463
26551
  }
26464
26552
  function duplexError(e, reflexModel) {
@@ -26790,6 +26878,7 @@ async function rollbackTurn(agent, store, session, start) {
26790
26878
  agent.transcript.splice(start);
26791
26879
  session.messages = agent.transcript;
26792
26880
  session.meta.updated = Date.now();
26881
+ session.meta.codex = void 0;
26793
26882
  session.meta.cc = void 0;
26794
26883
  const cc = agent.options.providerOptions?.claudeCodeSession;
26795
26884
  if (typeof cc === "string" && isClaudeCode(agent.options.model)) await rewindClaudeCodeSession(cc);
@@ -26993,6 +27082,8 @@ export {
26993
27082
  appendMemoryNote,
26994
27083
  applyTurnMode,
26995
27084
  cacheMultipliers,
27085
+ codexBilling,
27086
+ codexRoute,
26996
27087
  condenseReplay,
26997
27088
  costOf,
26998
27089
  duplexError,