acpx 0.13.0 → 0.13.2

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.
@@ -1,11 +1,10 @@
1
- import { At as withInterrupt, Bt as isRetryablePromptError, C as mergeSessionOptions, Ct as isPromptInput, D as applyLifecycleSnapshotToRecord, Dt as textPrompt, E as applyConversation, Et as promptToDisplayText, F as modelStateFromConfigOptions, G as findSessionByDirectoryWalk, H as absolutePath, Ht as extractAcpError, J as listSessionsForAgent, Jt as OUTPUT_ERROR_CODES, K as isoNow, N as assertRequestedModelSupported, Ot as InterruptedError, Q as writeSessionRecord, R as splitCommandLine, S as advertisedModelState, T as sessionOptionsFromRecord, U as findGitRepositoryRoot, Vt as normalizeOutputError, W as findSession, Wt as toAcpErrorPayload, X as pruneSessions, Y as normalizeName, Yt as OUTPUT_ERROR_ORIGINS, Z as resolveSessionRecord, _ as createSessionConversation, _t as sessionEventSegmentPath, a as applyRequestedModelIfAdvertised, at as recordPerfDuration, b as recordSessionUpdate, bt as parseJsonRpcErrorMessage, c as setCurrentModelId, ct as startPerfTimer, d as setDesiredModelId, dt as normalizeRuntimeSessionId, f as syncAdvertisedModelState, g as cloneSessionConversation, gt as sessionEventLockPath, h as cloneSessionAcpxState, ht as sessionEventActivePath, i as connectAndLoadSession, it as measurePerf, jt as withTimeout, k as AcpClient, kt as TimeoutError, l as setDesiredConfigOption, m as applyConfigOptionsToState, mt as sessionBaseDir, n as runPromptTurn, nn as QueueConnectionError, nt as getPerfMetricsSnapshot, o as currentModelIdFromSetModelResponse, ot as resetPerfMetrics, p as applyConfigOptionsToRecord, pt as defaultSessionEventLog, q as listSessions, r as withConnectedSession, rn as QueueProtocolError, rt as incrementPerfCounter, s as clearDesiredConfigOption, st as setPerfGauge, t as LiveSessionCheckpoint, tt as formatPerfMetric, u as setDesiredModeId, v as recordClientOperation, vt as extractSessionUpdateNotification, w as persistSessionOptions, x as trimConversationForRuntime, xt as parsePromptStopReason, y as recordPromptSubmission, yt as isAcpJsonRpcMessage, zt as formatErrorMessage } from "./live-checkpoint-CBecfnSH.js";
1
+ import { $ as formatPerfMetric, B as absolutePath, Bt as extractAcpError, C as sessionOptionsFromRecord, D as AcpClient, Dt as TimeoutError, Et as InterruptedError, F as runTimedExecFile, G as listSessions, H as findSession, Ht as toAcpErrorPayload, I as splitCommandLine, J as pruneSessions, K as listSessionsForAgent, Kt as OUTPUT_ERROR_CODES, Lt as formatErrorMessage, M as modelStateFromConfigOptions, Ot as withInterrupt, Rt as isRetryablePromptError, S as persistSessionOptions, T as applyLifecycleSnapshotToRecord, Tt as textPrompt, U as findSessionByDirectoryWalk, V as findGitRepositoryRoot, W as isoNow, X as writeSessionRecord, Y as resolveSessionRecord, _ as recordPromptSubmission, _t as isAcpJsonRpcMessage, a as applyConfigOptionSelection, at as setPerfGauge, b as advertisedModelState, c as applyRequestedModelIfAdvertised, d as setDesiredModeId, dt as defaultSessionEventLog, en as QueueConnectionError, et as getPerfMetricsSnapshot, f as syncAdvertisedModelState, ft as sessionBaseDir, g as recordClientOperation, gt as extractSessionUpdateNotification, h as createSessionConversation, ht as sessionEventSegmentPath, i as connectAndLoadSession, it as resetPerfMetrics, kt as withTimeout, l as currentModelIdFromSetModelResponse, lt as normalizeRuntimeSessionId, m as cloneSessionConversation, mt as sessionEventLockPath, n as runPromptTurn, nt as measurePerf, o as applyConfigOptionsToRecord, ot as startPerfTimer, p as cloneSessionAcpxState, pt as sessionEventActivePath, q as normalizeName, qt as OUTPUT_ERROR_ORIGINS, r as withConnectedSession, rt as recordPerfDuration, s as applyModelSelection, t as LiveSessionCheckpoint, tn as QueueProtocolError, tt as incrementPerfCounter, u as setCurrentModelId, v as recordSessionUpdate, vt as parseJsonRpcErrorMessage, w as applyConversation, wt as promptToDisplayText, x as mergeSessionOptions, xt as isPromptInput, y as trimConversationForRuntime, yt as parsePromptStopReason, zt as normalizeOutputError } from "./live-checkpoint-Gw2oGjhe.js";
2
2
  import fs, { mkdtempSync, realpathSync, writeFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import fs$1 from "node:fs/promises";
5
5
  import os from "node:os";
6
6
  import { createHash, randomInt, randomUUID } from "node:crypto";
7
- import { execFile, spawn } from "node:child_process";
8
- import { promisify } from "node:util";
7
+ import { spawn } from "node:child_process";
9
8
  import net from "node:net";
10
9
  //#region \0rolldown/runtime.js
11
10
  var __defProp = Object.defineProperty;
@@ -1117,7 +1116,7 @@ var SessionQueueOwner = class SessionQueueOwner {
1117
1116
  };
1118
1117
  //#endregion
1119
1118
  //#region src/cli/queue/ipc.ts
1120
- const MAX_MESSAGE_BUFFER_SIZE = 10 * 1024 * 1024;
1119
+ const MAX_MESSAGE_BUFFER_SIZE = 10485760;
1121
1120
  const STALE_OWNER_PROTOCOL_DETAIL_CODES = /* @__PURE__ */ new Set(["QUEUE_PROTOCOL_MALFORMED_MESSAGE", "QUEUE_PROTOCOL_UNEXPECTED_RESPONSE"]);
1122
1121
  async function maybeRecoverStaleOwnerAfterProtocolMismatch(params) {
1123
1122
  if (!(params.error instanceof QueueProtocolError)) return false;
@@ -1605,6 +1604,7 @@ async function trySetConfigOptionOnRunningOwner(sessionId, configId, value, time
1605
1604
  function buildDirectConnectedSessionOptions(options, run) {
1606
1605
  return {
1607
1606
  sessionRecordId: options.sessionRecordId,
1607
+ replacingConfigOption: options.replacingConfigOption,
1608
1608
  loadRecord: resolveSessionRecord,
1609
1609
  saveRecord: writeSessionRecord,
1610
1610
  mcpServers: options.mcpServers,
@@ -1636,12 +1636,13 @@ async function runSessionSetModeDirect(options) {
1636
1636
  })));
1637
1637
  }
1638
1638
  async function runSessionSetModelDirect(options) {
1639
- const result = await withConnectedSession(buildDirectConnectedSessionOptions(options, async ({ client, sessionId, record }) => {
1639
+ const result = await withConnectedSession(buildDirectConnectedSessionOptions({
1640
+ ...options,
1641
+ replacingConfigOption: { key: "model" }
1642
+ }, async ({ client, sessionId, record }) => {
1640
1643
  const models = advertisedModelState(record.acpx);
1641
1644
  const response = await withTimeout(client.setSessionModel(sessionId, options.modelId, models), options.timeoutMs);
1642
- applyConfigOptionsToRecord(record, response);
1643
- setDesiredModelId(record, options.modelId, models?.configId);
1644
- setCurrentModelId(record, currentModelIdFromSetModelResponse(response, options.modelId));
1645
+ record.acpx = applyModelSelection(record.acpx, options.modelId, response);
1645
1646
  return response;
1646
1647
  }));
1647
1648
  return {
@@ -1650,15 +1651,12 @@ async function runSessionSetModelDirect(options) {
1650
1651
  };
1651
1652
  }
1652
1653
  async function runSessionSetConfigOptionDirect(options) {
1653
- const result = await withConnectedSession(buildDirectConnectedSessionOptions(options, async ({ client, sessionId, record }) => {
1654
- const modelConfigId = advertisedModelState(record.acpx)?.configId;
1654
+ const result = await withConnectedSession(buildDirectConnectedSessionOptions({
1655
+ ...options,
1656
+ replacingConfigOption: { key: options.configId }
1657
+ }, async ({ client, sessionId, record }) => {
1655
1658
  const response = await withTimeout(client.setSessionConfigOption(sessionId, options.configId, options.value), options.timeoutMs);
1656
- applyConfigOptionsToRecord(record, response);
1657
- if (options.configId === modelConfigId) {
1658
- setDesiredModelId(record, options.value, options.configId);
1659
- setCurrentModelId(record, currentModelIdFromSetModelResponse(response, options.value));
1660
- } else if (options.configId === "mode") setDesiredModeId(record, options.value);
1661
- else setDesiredConfigOption(record, options.configId, options.value);
1659
+ record.acpx = applyConfigOptionSelection(record.acpx, options.configId, options.value, response);
1662
1660
  return response;
1663
1661
  }));
1664
1662
  return {
@@ -1670,7 +1668,6 @@ async function runSessionSetConfigOptionDirect(options) {
1670
1668
  }
1671
1669
  //#endregion
1672
1670
  //#region src/cli/session/session-control.ts
1673
- const execFileAsync = promisify(execFile);
1674
1671
  async function cancelSessionPrompt(options) {
1675
1672
  const cancelled = await tryCancelOnRunningOwner(options);
1676
1673
  return {
@@ -1705,9 +1702,7 @@ async function setSessionModel(options) {
1705
1702
  const submittedToOwner = await trySetModelOnRunningOwner(options.sessionId, options.modelId, options.timeoutMs, options.verbose);
1706
1703
  if (submittedToOwner) {
1707
1704
  const record = await resolveSessionRecord(options.sessionId);
1708
- applyConfigOptionsToRecord(record, submittedToOwner.response);
1709
- setDesiredModelId(record, options.modelId, advertisedModelState(record.acpx)?.configId);
1710
- setCurrentModelId(record, currentModelIdFromSetModelResponse(submittedToOwner.response, options.modelId));
1705
+ record.acpx = applyModelSelection(record.acpx, options.modelId, submittedToOwner.response);
1711
1706
  await writeSessionRecord(record);
1712
1707
  return {
1713
1708
  record,
@@ -1732,13 +1727,7 @@ async function setSessionConfigOption(options) {
1732
1727
  const ownerResponse = await trySetConfigOptionOnRunningOwner(options.sessionId, options.configId, options.value, options.timeoutMs, options.verbose);
1733
1728
  if (ownerResponse) {
1734
1729
  const record = await resolveSessionRecord(options.sessionId);
1735
- const modelConfigId = advertisedModelState(record.acpx)?.configId;
1736
- applyConfigOptionsToRecord(record, ownerResponse);
1737
- if (options.configId === modelConfigId) {
1738
- setDesiredModelId(record, options.value, options.configId);
1739
- setCurrentModelId(record, currentModelIdFromSetModelResponse(ownerResponse, options.value));
1740
- } else if (options.configId === "mode") setDesiredModeId(record, options.value);
1741
- else setDesiredConfigOption(record, options.configId, options.value);
1730
+ record.acpx = applyConfigOptionSelection(record.acpx, options.configId, options.value, ownerResponse);
1742
1731
  await writeSessionRecord(record);
1743
1732
  return {
1744
1733
  record,
@@ -1790,26 +1779,24 @@ async function readProcCmdline(pid) {
1790
1779
  }
1791
1780
  async function readPosixCommandLine(pid) {
1792
1781
  try {
1793
- const { stdout } = await execFileAsync("ps", [
1782
+ return (await runTimedExecFile("ps", [
1794
1783
  "-p",
1795
1784
  String(pid),
1796
1785
  "-o",
1797
1786
  "command="
1798
- ]);
1799
- return stdout.trim() || void 0;
1787
+ ])).trim() || void 0;
1800
1788
  } catch {
1801
1789
  return;
1802
1790
  }
1803
1791
  }
1804
1792
  async function readWindowsCommandLine(pid) {
1805
1793
  try {
1806
- const { stdout } = await execFileAsync("powershell.exe", [
1794
+ return (await runTimedExecFile("powershell.exe", [
1807
1795
  "-NoProfile",
1808
1796
  "-NonInteractive",
1809
1797
  "-Command",
1810
1798
  `(Get-CimInstance Win32_Process -Filter "ProcessId = ${pid}").CommandLine`
1811
- ], { windowsHide: true });
1812
- return stdout.trim() || void 0;
1799
+ ], { windowsHide: true })).trim() || void 0;
1813
1800
  } catch {
1814
1801
  return;
1815
1802
  }
@@ -2706,10 +2693,6 @@ function toPromptResult(stopReason, sessionId, client) {
2706
2693
  function requestedModelId(value) {
2707
2694
  return typeof value === "string" ? value.trim() : "";
2708
2695
  }
2709
- function applyConfigOptionResponseToState(state, response) {
2710
- if (!response?.configOptions) return state;
2711
- return applyConfigOptionsToState(state, response.configOptions);
2712
- }
2713
2696
  function mergeConnectedModelState(state, connectedState) {
2714
2697
  if (!connectedState) return state;
2715
2698
  const nextState = cloneSessionAcpxState(state) ?? {};
@@ -2731,29 +2714,21 @@ function mergeConnectedModelPreferences(nextState, connectedState) {
2731
2714
  if (connectedState.session_options) nextState.session_options = cloneSessionAcpxState(connectedState)?.session_options;
2732
2715
  if (connectedState.desired_mode_id !== void 0) nextState.desired_mode_id = connectedState.desired_mode_id;
2733
2716
  if (connectedState.desired_config_options) nextState.desired_config_options = { ...connectedState.desired_config_options };
2717
+ else delete nextState.desired_config_options;
2734
2718
  }
2735
2719
  async function applyPromptModelIfAdvertised(params) {
2736
2720
  const requestedModel = requestedModelId(params.requestedModel);
2737
2721
  if (!requestedModel) return;
2738
- const models = advertisedModelState(params.record.acpx);
2739
- emitModelSupportWarning(assertRequestedModelSupported({
2722
+ const result = await applyRequestedModelIfAdvertised({
2723
+ client: params.client,
2724
+ sessionId: params.sessionId,
2740
2725
  requestedModel,
2741
- models,
2726
+ models: advertisedModelState(params.record.acpx),
2742
2727
  agentCommand: params.record.agentCommand,
2743
- context: "apply"
2744
- }), params.suppressWarnings);
2745
- if (!models) return;
2746
- if (params.record.acpx?.current_model_id === requestedModel) {
2747
- setDesiredModelId(params.record, requestedModel, models.configId);
2748
- return;
2749
- }
2750
- const response = await withTimeout(params.client.setSessionModel(params.sessionId, requestedModel, models), params.timeoutMs);
2751
- applyConfigOptionsToRecord(params.record, response);
2752
- setDesiredModelId(params.record, requestedModel, models.configId);
2753
- setCurrentModelId(params.record, currentModelIdFromSetModelResponse(response, requestedModel));
2754
- }
2755
- function emitModelSupportWarning(warning, suppressWarnings) {
2756
- if (warning && !suppressWarnings) process.stderr.write(`[acpx] warning: ${warning}\n`);
2728
+ timeoutMs: params.timeoutMs,
2729
+ onWarning: params.suppressWarnings ? void 0 : (message) => process.stderr.write(`[acpx] warning: ${message}\n`)
2730
+ });
2731
+ if (result.applied) params.record.acpx = applyModelSelection(params.record.acpx, requestedModel, result.response);
2757
2732
  }
2758
2733
  function jsonRpcIdKey$1(value) {
2759
2734
  if (typeof value === "string") return `s:${value}`;
@@ -2976,7 +2951,7 @@ async function runSessionPrompt(options) {
2976
2951
  if (options.verbose) process.stderr.write("[acpx] live session checkpoint failed: " + formatErrorMessage(error) + "\n");
2977
2952
  }
2978
2953
  });
2979
- const ownClient = options.client == null;
2954
+ let closeClientOnExit = options.client == null;
2980
2955
  const client = options.client ?? new AcpClient({
2981
2956
  agentCommand: record.agentCommand,
2982
2957
  agentArgv: record.agentArgv,
@@ -3047,34 +3022,13 @@ async function runSessionPrompt(options) {
3047
3022
  setSessionModel: async (modelId) => {
3048
3023
  const models = advertisedModelState(acpxState);
3049
3024
  const response = await client.setSessionModel(activeSessionIdForControl, modelId, models);
3050
- acpxState = applyConfigOptionResponseToState(acpxState, response);
3051
- const nextState = cloneSessionAcpxState(acpxState) ?? {};
3052
- nextState.session_options = {
3053
- ...nextState.session_options,
3054
- model: modelId
3055
- };
3056
- nextState.current_model_id = currentModelIdFromSetModelResponse(response, modelId);
3057
- clearDesiredConfigOption(nextState, models?.configId);
3058
- acpxState = nextState;
3025
+ acpxState = applyModelSelection(acpxState, modelId, response);
3059
3026
  return response;
3060
3027
  },
3061
3028
  setSessionConfigOption: async (configId, value) => {
3029
+ const modelConfigId = advertisedModelState(acpxState)?.configId;
3062
3030
  const response = await client.setSessionConfigOption(activeSessionIdForControl, configId, value);
3063
- acpxState = applyConfigOptionResponseToState(acpxState, response);
3064
- const nextState = cloneSessionAcpxState(acpxState) ?? {};
3065
- if (configId === modelStateFromConfigOptions(nextState.config_options)?.configId) {
3066
- nextState.session_options = {
3067
- ...nextState.session_options,
3068
- model: value
3069
- };
3070
- nextState.current_model_id = currentModelIdFromSetModelResponse(response, value);
3071
- clearDesiredConfigOption(nextState, configId);
3072
- } else if (configId === "mode") nextState.desired_mode_id = value;
3073
- else nextState.desired_config_options = {
3074
- ...nextState.desired_config_options,
3075
- [configId]: value
3076
- };
3077
- acpxState = nextState;
3031
+ acpxState = applyConfigOptionSelection(acpxState, configId, value, response, modelConfigId);
3078
3032
  return response;
3079
3033
  }
3080
3034
  };
@@ -3092,6 +3046,7 @@ async function runSessionPrompt(options) {
3092
3046
  client,
3093
3047
  record,
3094
3048
  resumePolicy: options.resumePolicy,
3049
+ replacingConfigOption: requestedModelId(options.sessionOptions?.model) ? { key: "model" } : void 0,
3095
3050
  timeoutMs: options.timeoutMs,
3096
3051
  verbose: options.verbose,
3097
3052
  suppressWarnings: options.suppressSdkConsoleErrors,
@@ -3113,6 +3068,7 @@ async function runSessionPrompt(options) {
3113
3068
  emitConnectPerfMetric(connectStartedAt, options.verbose);
3114
3069
  return connected;
3115
3070
  } catch (error) {
3071
+ closeClientOnExit = true;
3116
3072
  flushConnectOutput();
3117
3073
  throw error;
3118
3074
  }
@@ -3200,7 +3156,7 @@ async function runSessionPrompt(options) {
3200
3156
  await applyPromptModelIfAdvertised({
3201
3157
  client,
3202
3158
  sessionId: activeSessionId,
3203
- requestedModel: sessionOptions?.model,
3159
+ requestedModel: options.sessionOptions?.model,
3204
3160
  record,
3205
3161
  timeoutMs: options.timeoutMs,
3206
3162
  suppressWarnings: options.suppressSdkConsoleErrors
@@ -3224,7 +3180,7 @@ async function runSessionPrompt(options) {
3224
3180
  applyConversation(record, conversation);
3225
3181
  record.acpx = acpxState;
3226
3182
  await flushPendingMessages(false).catch(() => {});
3227
- if (ownClient) await client.close();
3183
+ if (closeClientOnExit) await client.close();
3228
3184
  };
3229
3185
  try {
3230
3186
  return await runWithOptionalInterrupt({
@@ -3242,7 +3198,7 @@ async function runSessionPrompt(options) {
3242
3198
  else stopTotalTimer();
3243
3199
  if (notifiedClientAvailable) options.onClientClosed?.();
3244
3200
  client.clearEventHandlers();
3245
- if (ownClient) await client.close();
3201
+ if (closeClientOnExit) await client.close();
3246
3202
  applyLifecycleSnapshotToRecord(record, client.getAgentLifecycleSnapshot());
3247
3203
  applyConversation(record, conversation);
3248
3204
  record.acpx = acpxState;
@@ -4374,7 +4330,7 @@ function limitOutputBlock(value) {
4374
4330
  const hidden = lines.length - visible.length;
4375
4331
  result += `\n... (${hidden} more lines)`;
4376
4332
  }
4377
- if (result.length > MAX_OUTPUT_CHARS) result = `${result.slice(0, MAX_OUTPUT_CHARS - 3)}...`;
4333
+ if (result.length > MAX_OUTPUT_CHARS) result = `${result.slice(0, 1997)}...`;
4378
4334
  return result;
4379
4335
  }
4380
4336
  var TextOutputFormatter = class {
@@ -4722,4 +4678,4 @@ function createOutputFormatter(format, options = {}) {
4722
4678
  //#endregion
4723
4679
  export { runSessionQueueOwner as a, buildQueueOwnerArgOverride as c, createSessionWithClient as d, cancelSessionPrompt as f, __exportAll as g, isProcessAlive as h, session_exports as i, flushPerfMetricsCapture as l, DEFAULT_QUEUE_OWNER_TTL_MS as m, getTextErrorRemediationHints as n, runOnce as o, probeQueueOwnerHealth as p, output_exports as r, sendSessionDirect as s, createOutputFormatter as t, installPerfMetricsCapture as u };
4724
4680
 
4725
- //# sourceMappingURL=output-CzN8vLdE.js.map
4681
+ //# sourceMappingURL=output-DiPPprGk.js.map