@buildautomaton/cli 0.1.36 → 0.1.38

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.js CHANGED
@@ -25064,7 +25064,7 @@ var {
25064
25064
  } = import_index.default;
25065
25065
 
25066
25066
  // src/cli-version.ts
25067
- var CLI_VERSION = "0.1.36".length > 0 ? "0.1.36" : "0.0.0-dev";
25067
+ var CLI_VERSION = "0.1.38".length > 0 ? "0.1.38" : "0.0.0-dev";
25068
25068
 
25069
25069
  // src/cli/defaults.ts
25070
25070
  var DEFAULT_API_URL = process.env.BUILDAUTOMATON_API_URL ?? "https://api.buildautomaton.com";
@@ -27711,6 +27711,16 @@ function isClaudeCodePermissionMode(value) {
27711
27711
  return MODE_SET.has(value);
27712
27712
  }
27713
27713
 
27714
+ // ../types/src/codex-permission-mode.ts
27715
+ function isCodexPermissionMode(value) {
27716
+ return value.trim() !== "";
27717
+ }
27718
+ function normalizeCodexPermissionModeInput(raw) {
27719
+ if (typeof raw !== "string") return null;
27720
+ const t = raw.trim();
27721
+ return isCodexPermissionMode(t) ? t : null;
27722
+ }
27723
+
27714
27724
  // ../types/src/cli-permission-mode.ts
27715
27725
  var CLI_PERMISSION_MODE_DEFAULT = "default";
27716
27726
  var CLI_PERMISSION_MODE_DANGEROUS = "dangerous";
@@ -27782,6 +27792,7 @@ function buildCliAutoApprovedPermissionRpcResult(requestParams) {
27782
27792
  // ../types/src/agent-config.ts
27783
27793
  var AGENT_CONFIG_CLAUDE_PERMISSION_MODE_KEY = "claude_permission_mode";
27784
27794
  var AGENT_CONFIG_CLI_PERMISSION_MODE_KEY = "cli_permission_mode";
27795
+ var AGENT_CONFIG_CODEX_PERMISSION_MODE_KEY = "codex_permission_mode";
27785
27796
  var AGENT_CONFIG_AGENT_MODEL_KEY = "agent_model";
27786
27797
  function getClaudePermissionModeFromAgentConfig(config2) {
27787
27798
  if (!config2) return null;
@@ -27794,6 +27805,10 @@ function getCliPermissionModeFromAgentConfig(config2) {
27794
27805
  if (!config2) return CLI_PERMISSION_MODE_DEFAULT;
27795
27806
  return normalizeCliPermissionModeInput(config2[AGENT_CONFIG_CLI_PERMISSION_MODE_KEY]);
27796
27807
  }
27808
+ function getCodexPermissionModeFromAgentConfig(config2) {
27809
+ if (!config2) return null;
27810
+ return normalizeCodexPermissionModeInput(config2[AGENT_CONFIG_CODEX_PERMISSION_MODE_KEY]);
27811
+ }
27797
27812
  function getAgentModelFromAgentConfig(config2) {
27798
27813
  if (!config2) return null;
27799
27814
  const cur = config2[AGENT_CONFIG_AGENT_MODEL_KEY];
@@ -33394,8 +33409,60 @@ async function applyClaudePermissionFromAcpSession(params) {
33394
33409
  }
33395
33410
  }
33396
33411
 
33397
- // src/agents/acp/apply-acp-model-from-agent-session.ts
33412
+ // src/agents/acp/codex-acp-permission-from-session.ts
33398
33413
  function flattenSelectOptions2(options) {
33414
+ if (options == null || options.length === 0) return [];
33415
+ const first2 = options[0];
33416
+ if (first2 != null && typeof first2 === "object" && "group" in first2 && first2.group != null) {
33417
+ return options.flatMap(
33418
+ (g) => Array.isArray(g.options) ? g.options : []
33419
+ );
33420
+ }
33421
+ return options;
33422
+ }
33423
+ function pickModeConfigOption2(configOptions) {
33424
+ if (configOptions == null || configOptions.length === 0) return null;
33425
+ const byCategory = configOptions.find((o) => o.category === "mode");
33426
+ if (byCategory) return byCategory;
33427
+ return configOptions.find((o) => o.id === "mode") ?? null;
33428
+ }
33429
+ async function applyCodexPermissionFromAcpSession(params) {
33430
+ const { sessionId, agentConfig, configOptions, modes, setSessionConfigOption, setSessionMode, logDebug: logDebug2 } = params;
33431
+ const desiredMode = getCodexPermissionModeFromAgentConfig(agentConfig);
33432
+ if (desiredMode == null) return;
33433
+ const modeOpt = pickModeConfigOption2(configOptions ?? null);
33434
+ if (modeOpt != null) {
33435
+ const flat = flattenSelectOptions2(modeOpt.options);
33436
+ const allowed = flat.some((o) => o.value === desiredMode);
33437
+ if (allowed && modeOpt.currentValue !== desiredMode) {
33438
+ try {
33439
+ logDebug2(
33440
+ `[Agent] Codex: sending ACP session/set_config_option (mode) configId=${JSON.stringify(modeOpt.id)} value=${JSON.stringify(desiredMode)} was=${JSON.stringify(modeOpt.currentValue)} sessionId=${sessionId.slice(0, 8)}\u2026`
33441
+ );
33442
+ await setSessionConfigOption({ sessionId, configId: modeOpt.id, value: desiredMode });
33443
+ } catch (e) {
33444
+ logDebug2(`[Agent] Codex: session/set_config_option failed: ${e instanceof Error ? e.message : String(e)}`);
33445
+ }
33446
+ }
33447
+ return;
33448
+ }
33449
+ if (modes?.availableModes?.length) {
33450
+ const allowed = modes.availableModes.some((m) => m.id === desiredMode);
33451
+ if (allowed && desiredMode !== modes.currentModeId) {
33452
+ try {
33453
+ logDebug2(
33454
+ `[Agent] Codex: sending ACP session/set_mode modeId=${JSON.stringify(desiredMode)} was=${JSON.stringify(modes.currentModeId ?? null)} sessionId=${sessionId.slice(0, 8)}\u2026`
33455
+ );
33456
+ await setSessionMode({ sessionId, modeId: desiredMode });
33457
+ } catch (e) {
33458
+ logDebug2(`[Agent] Codex: session/set_mode failed: ${e instanceof Error ? e.message : String(e)}`);
33459
+ }
33460
+ }
33461
+ }
33462
+ }
33463
+
33464
+ // src/agents/acp/apply-acp-model-from-agent-session.ts
33465
+ function flattenSelectOptions3(options) {
33399
33466
  if (options == null || options.length === 0) return [];
33400
33467
  const first2 = options[0];
33401
33468
  if (first2 != null && typeof first2 === "object" && "group" in first2 && first2.group != null) {
@@ -33420,7 +33487,7 @@ async function applyAcpModelFromAcpSession(params) {
33420
33487
  if (desired == null) return;
33421
33488
  const modelOpt = pickModelConfigOption(configOptions ?? null);
33422
33489
  if (modelOpt == null) return;
33423
- const flat = flattenSelectOptions2(modelOpt.options);
33490
+ const flat = flattenSelectOptions3(modelOpt.options);
33424
33491
  const allowed = flat.some((o) => o.value === desired);
33425
33492
  if (!allowed) return;
33426
33493
  if (modelOpt.currentValue === desired) return;
@@ -33500,12 +33567,41 @@ function parseAcpInitAgentCapabilities(initResult) {
33500
33567
  }
33501
33568
 
33502
33569
  // src/agents/acp/clients/shared/bootstrap-acp-wire-session.ts
33570
+ function configOptionsWithModes(configOptions, modes) {
33571
+ const modeState = modes && typeof modes === "object" ? modes : null;
33572
+ if (!modeState?.availableModes?.length) return configOptions;
33573
+ const hasModeConfig = Array.isArray(configOptions) && configOptions.some((raw) => {
33574
+ if (raw == null || typeof raw !== "object" || Array.isArray(raw)) return false;
33575
+ const o = raw;
33576
+ return o.category === "mode" || o.id === "mode";
33577
+ });
33578
+ if (hasModeConfig) return configOptions;
33579
+ return [
33580
+ ...configOptions ?? [],
33581
+ {
33582
+ id: "mode",
33583
+ name: "Mode",
33584
+ type: "select",
33585
+ category: "mode",
33586
+ currentValue: modeState.currentModeId ?? null,
33587
+ options: modeState.availableModes.map((m) => {
33588
+ const r = m;
33589
+ return {
33590
+ value: m.id,
33591
+ name: m.name ?? m.id,
33592
+ ...typeof r.description === "string" && r.description.trim() !== "" ? { description: r.description.trim() } : {}
33593
+ };
33594
+ })
33595
+ }
33596
+ ];
33597
+ }
33503
33598
  async function bootstrapAcpWireSession(transport, ctx, initializeRequest) {
33504
33599
  const initResult = await transport.initialize(initializeRequest);
33505
33600
  const { canResume, canLoad, promptSupportsImage } = parseAcpInitAgentCapabilities(initResult);
33506
33601
  ctx.agentPromptImageSupported = promptSupportsImage;
33507
33602
  await transport.afterInitialize?.();
33508
33603
  const established = await establishAcpSessionWithTransport(transport, ctx, canResume, canLoad);
33604
+ established.configOptions = configOptionsWithModes(established.configOptions, established.modes);
33509
33605
  const sessionId = established.sessionId;
33510
33606
  ctx.onAcpSessionEstablished?.({
33511
33607
  acpSessionId: sessionId,
@@ -33528,6 +33624,22 @@ async function bootstrapAcpWireSession(transport, ctx, initializeRequest) {
33528
33624
  logDebug: ctx.logDebug
33529
33625
  });
33530
33626
  }
33627
+ if (ctx.backendAgentType === "codex-acp") {
33628
+ const cfg = ctx.agentConfig != null && typeof ctx.agentConfig === "object" && !Array.isArray(ctx.agentConfig) ? ctx.agentConfig : null;
33629
+ const configOptionsTyped = established.configOptions;
33630
+ const modesTyped = established.modes;
33631
+ await applyCodexPermissionFromAcpSession({
33632
+ sessionId,
33633
+ agentConfig: cfg,
33634
+ configOptions: configOptionsForPermission(ctx.getActiveConfigOptions, configOptionsTyped),
33635
+ modes: modesTyped,
33636
+ setSessionConfigOption: transport.setSessionConfigOption ? (p) => transport.setSessionConfigOption(p) : async () => {
33637
+ },
33638
+ setSessionMode: transport.setSessionMode ? (p) => transport.setSessionMode(p) : async () => {
33639
+ },
33640
+ logDebug: ctx.logDebug
33641
+ });
33642
+ }
33531
33643
  const cfgAll = ctx.agentConfig != null && typeof ctx.agentConfig === "object" && !Array.isArray(ctx.agentConfig) ? ctx.agentConfig : null;
33532
33644
  const configOptionsForModel = established.configOptions;
33533
33645
  if (transport.setSessionConfigOption) {
@@ -33900,13 +34012,18 @@ function isCodexAcpCommand(command) {
33900
34012
  const i = command.indexOf("@zed-industries/codex-acp");
33901
34013
  return i >= 0 && (i === 0 || command[i - 1] === "npx" || command[i - 1] === "bunx");
33902
34014
  }
33903
- function buildCodexAcpSpawnCommand(base, _sessionMode) {
34015
+ function buildCodexAcpSpawnCommand(base, _sessionMode, _agentConfig) {
33904
34016
  return [...base];
33905
34017
  }
33906
34018
  async function createCodexAcpClient(options) {
33907
34019
  const base = options.command?.length && options.command.some((a) => a.includes("codex-acp")) ? options.command : [...DEFAULT_CODEX_ACP_COMMAND];
33908
- const command = buildCodexAcpSpawnCommand(base, options.sessionMode);
33909
- return createSdkStdioAcpClient({ ...options, command });
34020
+ const command = buildCodexAcpSpawnCommand(base, options.sessionMode, options.agentConfig);
34021
+ return createSdkStdioAcpClient({
34022
+ ...options,
34023
+ command,
34024
+ /** Codex ACP can ignore `session/cancel`; mirror Claude Code's subprocess fallback. */
34025
+ killSubprocessAfterCancelMs: options.killSubprocessAfterCancelMs ?? 2500
34026
+ });
33910
34027
  }
33911
34028
 
33912
34029
  // src/agents/acp/clients/cursor/cursor-acp-client.ts
@@ -34304,7 +34421,7 @@ function resolveAgentCommand(preferredAgentType) {
34304
34421
  command,
34305
34422
  label: preferredAgentType,
34306
34423
  createClient: createCodexAcpClient,
34307
- spawnCommandForSession: (sessionMode, _agentConfig) => buildCodexAcpSpawnCommand(command, sessionMode)
34424
+ spawnCommandForSession: (sessionMode, agentConfig) => buildCodexAcpSpawnCommand(command, sessionMode, agentConfig)
34308
34425
  };
34309
34426
  }
34310
34427
  if (useKiroAcp(preferredAgentType, command)) {
@@ -34482,7 +34599,7 @@ function createBridgeOnFileChange(opts) {
34482
34599
 
34483
34600
  // src/agents/acp/hooks/bridge-on-request.ts
34484
34601
  function createBridgeOnRequest(opts) {
34485
- const { routing, getSendRequest, log: log2, getAutoApproveAcpPermissions, resolveAcpPermissionRequest } = opts;
34602
+ const { routing, getSendRequest, log: log2, getAutoApproveAcpPermissions, resolveAcpPermissionRequest, nextTranscriptStreamSeq } = opts;
34486
34603
  return (request) => {
34487
34604
  const runId = routing.runId;
34488
34605
  const sessionId = routing.sessionId;
@@ -34511,6 +34628,7 @@ function createBridgeOnRequest(opts) {
34511
34628
  );
34512
34629
  }
34513
34630
  try {
34631
+ const transcriptStreamSeq = nextTranscriptStreamSeq?.(runId);
34514
34632
  sendReq({
34515
34633
  type: "session_update",
34516
34634
  ...sessionId ? { sessionId } : {},
@@ -34521,7 +34639,8 @@ function createBridgeOnRequest(opts) {
34521
34639
  requestId: request.requestId,
34522
34640
  method: request.method,
34523
34641
  params: request.params
34524
- }
34642
+ },
34643
+ ...transcriptStreamSeq != null ? { transcriptStreamSeq } : {}
34525
34644
  });
34526
34645
  } catch (err) {
34527
34646
  log2(
@@ -34922,7 +35041,7 @@ function sendSessionInfoTitleUpdate(params) {
34922
35041
 
34923
35042
  // src/agents/acp/hooks/bridge-on-session-update/create-bridge-on-session-update.ts
34924
35043
  function createBridgeOnSessionUpdate(opts) {
34925
- const { routing, getSendSessionUpdate, log: log2, sessionParentPath } = opts;
35044
+ const { routing, getSendSessionUpdate, log: log2, sessionParentPath, nextTranscriptStreamSeq } = opts;
34926
35045
  const pathTracker = new PathSnapshotTracker();
34927
35046
  return (params) => {
34928
35047
  const runId = routing.runId;
@@ -35000,12 +35119,14 @@ function createBridgeOnSessionUpdate(opts) {
35000
35119
  return;
35001
35120
  }
35002
35121
  try {
35122
+ const transcriptStreamSeq = nextTranscriptStreamSeq?.(runId);
35003
35123
  send({
35004
35124
  type: "session_update",
35005
35125
  ...sessionId ? { sessionId } : {},
35006
35126
  runId,
35007
35127
  kind: updateKind,
35008
- payload: params
35128
+ payload: params,
35129
+ ...transcriptStreamSeq != null ? { transcriptStreamSeq } : {}
35009
35130
  });
35010
35131
  } catch (err) {
35011
35132
  log2(
@@ -35018,10 +35139,17 @@ function createBridgeOnSessionUpdate(opts) {
35018
35139
 
35019
35140
  // src/agents/acp/hooks/build-acp-session-bridge-hooks.ts
35020
35141
  function buildAcpSessionBridgeHooks(opts) {
35142
+ const transcriptStreamSeqByRunId = /* @__PURE__ */ new Map();
35143
+ const nextTranscriptStreamSeq = (runId) => {
35144
+ const n = (transcriptStreamSeqByRunId.get(runId) ?? 0) + 1;
35145
+ transcriptStreamSeqByRunId.set(runId, n);
35146
+ return n;
35147
+ };
35148
+ const optsWithSeq = { ...opts, nextTranscriptStreamSeq };
35021
35149
  return {
35022
- onFileChange: createBridgeOnFileChange(opts),
35023
- onSessionUpdate: createBridgeOnSessionUpdate(opts),
35024
- onRequest: createBridgeOnRequest(opts)
35150
+ onFileChange: createBridgeOnFileChange(optsWithSeq),
35151
+ onSessionUpdate: createBridgeOnSessionUpdate(optsWithSeq),
35152
+ onRequest: createBridgeOnRequest(optsWithSeq)
35025
35153
  };
35026
35154
  }
35027
35155