@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/index.js CHANGED
@@ -22935,6 +22935,16 @@ function isClaudeCodePermissionMode(value) {
22935
22935
  return MODE_SET.has(value);
22936
22936
  }
22937
22937
 
22938
+ // ../types/src/codex-permission-mode.ts
22939
+ function isCodexPermissionMode(value) {
22940
+ return value.trim() !== "";
22941
+ }
22942
+ function normalizeCodexPermissionModeInput(raw) {
22943
+ if (typeof raw !== "string") return null;
22944
+ const t = raw.trim();
22945
+ return isCodexPermissionMode(t) ? t : null;
22946
+ }
22947
+
22938
22948
  // ../types/src/cli-permission-mode.ts
22939
22949
  var CLI_PERMISSION_MODE_DEFAULT = "default";
22940
22950
  var CLI_PERMISSION_MODE_DANGEROUS = "dangerous";
@@ -23006,6 +23016,7 @@ function buildCliAutoApprovedPermissionRpcResult(requestParams) {
23006
23016
  // ../types/src/agent-config.ts
23007
23017
  var AGENT_CONFIG_CLAUDE_PERMISSION_MODE_KEY = "claude_permission_mode";
23008
23018
  var AGENT_CONFIG_CLI_PERMISSION_MODE_KEY = "cli_permission_mode";
23019
+ var AGENT_CONFIG_CODEX_PERMISSION_MODE_KEY = "codex_permission_mode";
23009
23020
  var AGENT_CONFIG_AGENT_MODEL_KEY = "agent_model";
23010
23021
  function getClaudePermissionModeFromAgentConfig(config2) {
23011
23022
  if (!config2) return null;
@@ -23018,6 +23029,10 @@ function getCliPermissionModeFromAgentConfig(config2) {
23018
23029
  if (!config2) return CLI_PERMISSION_MODE_DEFAULT;
23019
23030
  return normalizeCliPermissionModeInput(config2[AGENT_CONFIG_CLI_PERMISSION_MODE_KEY]);
23020
23031
  }
23032
+ function getCodexPermissionModeFromAgentConfig(config2) {
23033
+ if (!config2) return null;
23034
+ return normalizeCodexPermissionModeInput(config2[AGENT_CONFIG_CODEX_PERMISSION_MODE_KEY]);
23035
+ }
23021
23036
  function getAgentModelFromAgentConfig(config2) {
23022
23037
  if (!config2) return null;
23023
23038
  const cur = config2[AGENT_CONFIG_AGENT_MODEL_KEY];
@@ -23080,8 +23095,60 @@ async function applyClaudePermissionFromAcpSession(params) {
23080
23095
  }
23081
23096
  }
23082
23097
 
23083
- // src/agents/acp/apply-acp-model-from-agent-session.ts
23098
+ // src/agents/acp/codex-acp-permission-from-session.ts
23084
23099
  function flattenSelectOptions2(options) {
23100
+ if (options == null || options.length === 0) return [];
23101
+ const first2 = options[0];
23102
+ if (first2 != null && typeof first2 === "object" && "group" in first2 && first2.group != null) {
23103
+ return options.flatMap(
23104
+ (g) => Array.isArray(g.options) ? g.options : []
23105
+ );
23106
+ }
23107
+ return options;
23108
+ }
23109
+ function pickModeConfigOption2(configOptions) {
23110
+ if (configOptions == null || configOptions.length === 0) return null;
23111
+ const byCategory = configOptions.find((o) => o.category === "mode");
23112
+ if (byCategory) return byCategory;
23113
+ return configOptions.find((o) => o.id === "mode") ?? null;
23114
+ }
23115
+ async function applyCodexPermissionFromAcpSession(params) {
23116
+ const { sessionId, agentConfig, configOptions, modes, setSessionConfigOption, setSessionMode, logDebug: logDebug2 } = params;
23117
+ const desiredMode = getCodexPermissionModeFromAgentConfig(agentConfig);
23118
+ if (desiredMode == null) return;
23119
+ const modeOpt = pickModeConfigOption2(configOptions ?? null);
23120
+ if (modeOpt != null) {
23121
+ const flat = flattenSelectOptions2(modeOpt.options);
23122
+ const allowed = flat.some((o) => o.value === desiredMode);
23123
+ if (allowed && modeOpt.currentValue !== desiredMode) {
23124
+ try {
23125
+ logDebug2(
23126
+ `[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`
23127
+ );
23128
+ await setSessionConfigOption({ sessionId, configId: modeOpt.id, value: desiredMode });
23129
+ } catch (e) {
23130
+ logDebug2(`[Agent] Codex: session/set_config_option failed: ${e instanceof Error ? e.message : String(e)}`);
23131
+ }
23132
+ }
23133
+ return;
23134
+ }
23135
+ if (modes?.availableModes?.length) {
23136
+ const allowed = modes.availableModes.some((m) => m.id === desiredMode);
23137
+ if (allowed && desiredMode !== modes.currentModeId) {
23138
+ try {
23139
+ logDebug2(
23140
+ `[Agent] Codex: sending ACP session/set_mode modeId=${JSON.stringify(desiredMode)} was=${JSON.stringify(modes.currentModeId ?? null)} sessionId=${sessionId.slice(0, 8)}\u2026`
23141
+ );
23142
+ await setSessionMode({ sessionId, modeId: desiredMode });
23143
+ } catch (e) {
23144
+ logDebug2(`[Agent] Codex: session/set_mode failed: ${e instanceof Error ? e.message : String(e)}`);
23145
+ }
23146
+ }
23147
+ }
23148
+ }
23149
+
23150
+ // src/agents/acp/apply-acp-model-from-agent-session.ts
23151
+ function flattenSelectOptions3(options) {
23085
23152
  if (options == null || options.length === 0) return [];
23086
23153
  const first2 = options[0];
23087
23154
  if (first2 != null && typeof first2 === "object" && "group" in first2 && first2.group != null) {
@@ -23106,7 +23173,7 @@ async function applyAcpModelFromAcpSession(params) {
23106
23173
  if (desired == null) return;
23107
23174
  const modelOpt = pickModelConfigOption(configOptions ?? null);
23108
23175
  if (modelOpt == null) return;
23109
- const flat = flattenSelectOptions2(modelOpt.options);
23176
+ const flat = flattenSelectOptions3(modelOpt.options);
23110
23177
  const allowed = flat.some((o) => o.value === desired);
23111
23178
  if (!allowed) return;
23112
23179
  if (modelOpt.currentValue === desired) return;
@@ -23186,12 +23253,41 @@ function parseAcpInitAgentCapabilities(initResult) {
23186
23253
  }
23187
23254
 
23188
23255
  // src/agents/acp/clients/shared/bootstrap-acp-wire-session.ts
23256
+ function configOptionsWithModes(configOptions, modes) {
23257
+ const modeState = modes && typeof modes === "object" ? modes : null;
23258
+ if (!modeState?.availableModes?.length) return configOptions;
23259
+ const hasModeConfig = Array.isArray(configOptions) && configOptions.some((raw) => {
23260
+ if (raw == null || typeof raw !== "object" || Array.isArray(raw)) return false;
23261
+ const o = raw;
23262
+ return o.category === "mode" || o.id === "mode";
23263
+ });
23264
+ if (hasModeConfig) return configOptions;
23265
+ return [
23266
+ ...configOptions ?? [],
23267
+ {
23268
+ id: "mode",
23269
+ name: "Mode",
23270
+ type: "select",
23271
+ category: "mode",
23272
+ currentValue: modeState.currentModeId ?? null,
23273
+ options: modeState.availableModes.map((m) => {
23274
+ const r = m;
23275
+ return {
23276
+ value: m.id,
23277
+ name: m.name ?? m.id,
23278
+ ...typeof r.description === "string" && r.description.trim() !== "" ? { description: r.description.trim() } : {}
23279
+ };
23280
+ })
23281
+ }
23282
+ ];
23283
+ }
23189
23284
  async function bootstrapAcpWireSession(transport, ctx, initializeRequest) {
23190
23285
  const initResult = await transport.initialize(initializeRequest);
23191
23286
  const { canResume, canLoad, promptSupportsImage } = parseAcpInitAgentCapabilities(initResult);
23192
23287
  ctx.agentPromptImageSupported = promptSupportsImage;
23193
23288
  await transport.afterInitialize?.();
23194
23289
  const established = await establishAcpSessionWithTransport(transport, ctx, canResume, canLoad);
23290
+ established.configOptions = configOptionsWithModes(established.configOptions, established.modes);
23195
23291
  const sessionId = established.sessionId;
23196
23292
  ctx.onAcpSessionEstablished?.({
23197
23293
  acpSessionId: sessionId,
@@ -23214,6 +23310,22 @@ async function bootstrapAcpWireSession(transport, ctx, initializeRequest) {
23214
23310
  logDebug: ctx.logDebug
23215
23311
  });
23216
23312
  }
23313
+ if (ctx.backendAgentType === "codex-acp") {
23314
+ const cfg = ctx.agentConfig != null && typeof ctx.agentConfig === "object" && !Array.isArray(ctx.agentConfig) ? ctx.agentConfig : null;
23315
+ const configOptionsTyped = established.configOptions;
23316
+ const modesTyped = established.modes;
23317
+ await applyCodexPermissionFromAcpSession({
23318
+ sessionId,
23319
+ agentConfig: cfg,
23320
+ configOptions: configOptionsForPermission(ctx.getActiveConfigOptions, configOptionsTyped),
23321
+ modes: modesTyped,
23322
+ setSessionConfigOption: transport.setSessionConfigOption ? (p) => transport.setSessionConfigOption(p) : async () => {
23323
+ },
23324
+ setSessionMode: transport.setSessionMode ? (p) => transport.setSessionMode(p) : async () => {
23325
+ },
23326
+ logDebug: ctx.logDebug
23327
+ });
23328
+ }
23217
23329
  const cfgAll = ctx.agentConfig != null && typeof ctx.agentConfig === "object" && !Array.isArray(ctx.agentConfig) ? ctx.agentConfig : null;
23218
23330
  const configOptionsForModel = established.configOptions;
23219
23331
  if (transport.setSessionConfigOption) {
@@ -23964,7 +24076,7 @@ function installBridgeProcessResilience() {
23964
24076
  }
23965
24077
 
23966
24078
  // src/cli-version.ts
23967
- var CLI_VERSION = "0.1.36".length > 0 ? "0.1.36" : "0.0.0-dev";
24079
+ var CLI_VERSION = "0.1.38".length > 0 ? "0.1.38" : "0.0.0-dev";
23968
24080
 
23969
24081
  // src/connection/heartbeat/constants.ts
23970
24082
  var BRIDGE_APP_HEARTBEAT_INTERVAL_MS = 1e4;
@@ -30940,13 +31052,18 @@ function isCodexAcpCommand(command) {
30940
31052
  const i = command.indexOf("@zed-industries/codex-acp");
30941
31053
  return i >= 0 && (i === 0 || command[i - 1] === "npx" || command[i - 1] === "bunx");
30942
31054
  }
30943
- function buildCodexAcpSpawnCommand(base, _sessionMode) {
31055
+ function buildCodexAcpSpawnCommand(base, _sessionMode, _agentConfig) {
30944
31056
  return [...base];
30945
31057
  }
30946
31058
  async function createCodexAcpClient(options) {
30947
31059
  const base = options.command?.length && options.command.some((a) => a.includes("codex-acp")) ? options.command : [...DEFAULT_CODEX_ACP_COMMAND];
30948
- const command = buildCodexAcpSpawnCommand(base, options.sessionMode);
30949
- return createSdkStdioAcpClient({ ...options, command });
31060
+ const command = buildCodexAcpSpawnCommand(base, options.sessionMode, options.agentConfig);
31061
+ return createSdkStdioAcpClient({
31062
+ ...options,
31063
+ command,
31064
+ /** Codex ACP can ignore `session/cancel`; mirror Claude Code's subprocess fallback. */
31065
+ killSubprocessAfterCancelMs: options.killSubprocessAfterCancelMs ?? 2500
31066
+ });
30950
31067
  }
30951
31068
 
30952
31069
  // src/agents/acp/clients/cursor/cursor-acp-client.ts
@@ -31344,7 +31461,7 @@ function resolveAgentCommand(preferredAgentType) {
31344
31461
  command,
31345
31462
  label: preferredAgentType,
31346
31463
  createClient: createCodexAcpClient,
31347
- spawnCommandForSession: (sessionMode, _agentConfig) => buildCodexAcpSpawnCommand(command, sessionMode)
31464
+ spawnCommandForSession: (sessionMode, agentConfig) => buildCodexAcpSpawnCommand(command, sessionMode, agentConfig)
31348
31465
  };
31349
31466
  }
31350
31467
  if (useKiroAcp(preferredAgentType, command)) {
@@ -31522,7 +31639,7 @@ function createBridgeOnFileChange(opts) {
31522
31639
 
31523
31640
  // src/agents/acp/hooks/bridge-on-request.ts
31524
31641
  function createBridgeOnRequest(opts) {
31525
- const { routing, getSendRequest, log: log2, getAutoApproveAcpPermissions, resolveAcpPermissionRequest } = opts;
31642
+ const { routing, getSendRequest, log: log2, getAutoApproveAcpPermissions, resolveAcpPermissionRequest, nextTranscriptStreamSeq } = opts;
31526
31643
  return (request) => {
31527
31644
  const runId = routing.runId;
31528
31645
  const sessionId = routing.sessionId;
@@ -31551,6 +31668,7 @@ function createBridgeOnRequest(opts) {
31551
31668
  );
31552
31669
  }
31553
31670
  try {
31671
+ const transcriptStreamSeq = nextTranscriptStreamSeq?.(runId);
31554
31672
  sendReq({
31555
31673
  type: "session_update",
31556
31674
  ...sessionId ? { sessionId } : {},
@@ -31561,7 +31679,8 @@ function createBridgeOnRequest(opts) {
31561
31679
  requestId: request.requestId,
31562
31680
  method: request.method,
31563
31681
  params: request.params
31564
- }
31682
+ },
31683
+ ...transcriptStreamSeq != null ? { transcriptStreamSeq } : {}
31565
31684
  });
31566
31685
  } catch (err) {
31567
31686
  log2(
@@ -31962,7 +32081,7 @@ function sendSessionInfoTitleUpdate(params) {
31962
32081
 
31963
32082
  // src/agents/acp/hooks/bridge-on-session-update/create-bridge-on-session-update.ts
31964
32083
  function createBridgeOnSessionUpdate(opts) {
31965
- const { routing, getSendSessionUpdate, log: log2, sessionParentPath } = opts;
32084
+ const { routing, getSendSessionUpdate, log: log2, sessionParentPath, nextTranscriptStreamSeq } = opts;
31966
32085
  const pathTracker = new PathSnapshotTracker();
31967
32086
  return (params) => {
31968
32087
  const runId = routing.runId;
@@ -32040,12 +32159,14 @@ function createBridgeOnSessionUpdate(opts) {
32040
32159
  return;
32041
32160
  }
32042
32161
  try {
32162
+ const transcriptStreamSeq = nextTranscriptStreamSeq?.(runId);
32043
32163
  send({
32044
32164
  type: "session_update",
32045
32165
  ...sessionId ? { sessionId } : {},
32046
32166
  runId,
32047
32167
  kind: updateKind,
32048
- payload: params
32168
+ payload: params,
32169
+ ...transcriptStreamSeq != null ? { transcriptStreamSeq } : {}
32049
32170
  });
32050
32171
  } catch (err) {
32051
32172
  log2(
@@ -32058,10 +32179,17 @@ function createBridgeOnSessionUpdate(opts) {
32058
32179
 
32059
32180
  // src/agents/acp/hooks/build-acp-session-bridge-hooks.ts
32060
32181
  function buildAcpSessionBridgeHooks(opts) {
32182
+ const transcriptStreamSeqByRunId = /* @__PURE__ */ new Map();
32183
+ const nextTranscriptStreamSeq = (runId) => {
32184
+ const n = (transcriptStreamSeqByRunId.get(runId) ?? 0) + 1;
32185
+ transcriptStreamSeqByRunId.set(runId, n);
32186
+ return n;
32187
+ };
32188
+ const optsWithSeq = { ...opts, nextTranscriptStreamSeq };
32061
32189
  return {
32062
- onFileChange: createBridgeOnFileChange(opts),
32063
- onSessionUpdate: createBridgeOnSessionUpdate(opts),
32064
- onRequest: createBridgeOnRequest(opts)
32190
+ onFileChange: createBridgeOnFileChange(optsWithSeq),
32191
+ onSessionUpdate: createBridgeOnSessionUpdate(optsWithSeq),
32192
+ onRequest: createBridgeOnRequest(optsWithSeq)
32065
32193
  };
32066
32194
  }
32067
32195