@ycodium-ai/agent-acp 0.2.4343 → 0.2.4368

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.
Files changed (2) hide show
  1. package/dist/index.js +119 -27
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ var __export = (target, all) => {
8
8
  import { definePlugin } from "@ycodium-ai/plugin-api";
9
9
 
10
10
  // ../../packages/plugin-api/src/version.ts
11
- var PLUGIN_API_VERSION = 109;
11
+ var PLUGIN_API_VERSION = 112;
12
12
 
13
13
  // src/acpInstance.ts
14
14
  import * as NodeOS3 from "node:os";
@@ -156,9 +156,11 @@ var AcpExecutorRequestError = class extends AcpExecutorError {
156
156
  }
157
157
  };
158
158
  var AcpConnectionClosedError = class extends Error {
159
+ reason;
159
160
  constructor(message = "ACP connection closed", options) {
160
- super(message, options);
161
+ super(message, options?.cause === void 0 ? void 0 : { cause: options.cause });
161
162
  this.name = "AcpConnectionClosedError";
163
+ this.reason = options?.reason ?? "closed";
162
164
  }
163
165
  };
164
166
  async function withStartupStderr(error62, stderrTail) {
@@ -168,9 +170,65 @@ async function withStartupStderr(error62, stderrTail) {
168
170
  return new AcpConnectionClosedError(`${error62.message}
169
171
  Agent stderr (last lines):
170
172
  ${tail}`, {
171
- cause: error62
173
+ cause: error62,
174
+ reason: error62.reason
172
175
  });
173
176
  }
177
+ var AGENT_EXIT_STDERR_MAX_CHARS = 800;
178
+ var AGENT_EXIT_SETTLE_MS = 500;
179
+ var AcpAgentExitedError = class extends AcpConnectionClosedError {
180
+ exitCode;
181
+ constructor(message, exitCode, cause) {
182
+ super(message, { cause, reason: "input-ended" });
183
+ this.name = "AcpAgentExitedError";
184
+ this.exitCode = exitCode;
185
+ }
186
+ };
187
+ var REDACTION_MARKERS = ["[redacted]", "[pairing-url]"];
188
+ var lastLines = (text, maxChars) => {
189
+ if (text.length <= maxChars) return text;
190
+ let start = text.length - maxChars;
191
+ if (text[start - 1] !== "\n") {
192
+ const lineEnd = text.indexOf("\n", start);
193
+ if (lineEnd !== -1 && lineEnd < text.length - 1) return text.slice(lineEnd + 1);
194
+ const code = text.charCodeAt(start);
195
+ if (code >= 56320 && code <= 57343) start += 1;
196
+ for (const marker of REDACTION_MARKERS) {
197
+ const at = text.lastIndexOf(marker, start);
198
+ if (at !== -1 && at < start && start < at + marker.length) start = at + marker.length;
199
+ }
200
+ }
201
+ return text.slice(start);
202
+ };
203
+ var settledExitCode = async (exited) => {
204
+ if (exited === void 0) return void 0;
205
+ let timer;
206
+ try {
207
+ return await Promise.race([
208
+ exited.catch(() => void 0),
209
+ new Promise((resolve2) => {
210
+ timer = setTimeout(() => resolve2(void 0), AGENT_EXIT_SETTLE_MS);
211
+ })
212
+ ]);
213
+ } finally {
214
+ clearTimeout(timer);
215
+ }
216
+ };
217
+ async function describeAgentExit(input2) {
218
+ const [exitCode, tail] = await Promise.all([
219
+ settledExitCode(input2.exited),
220
+ input2.stderrTail === void 0 ? "" : Promise.resolve().then(input2.stderrTail).catch(() => "")
221
+ ]);
222
+ const head = exitCode === void 0 ? "The agent closed its connection." : exitCode === null ? "The agent process exited without an exit code." : `The agent process exited with code ${exitCode}.`;
223
+ const excerpt = lastLines(tail.trim(), AGENT_EXIT_STDERR_MAX_CHARS);
224
+ return new AcpAgentExitedError(
225
+ excerpt.length === 0 ? head : `${head}
226
+ Agent stderr (last lines):
227
+ ${excerpt}`,
228
+ exitCode,
229
+ input2.cause
230
+ );
231
+ }
174
232
 
175
233
  // ../../packages/ycodium-acp-executor/src/event-stream.ts
176
234
  var UnboundedEventStream = class {
@@ -25151,7 +25209,8 @@ function createAcpConnection(options) {
25151
25209
  options.onInboundFailure?.(error62);
25152
25210
  void shutdown(
25153
25211
  new AcpConnectionClosedError(
25154
- `ACP inbound handling failed: ${error62 instanceof Error ? error62.message : String(error62)}`
25212
+ `ACP inbound handling failed: ${error62 instanceof Error ? error62.message : String(error62)}`,
25213
+ { reason: "inbound-failed" }
25155
25214
  )
25156
25215
  );
25157
25216
  };
@@ -25196,19 +25255,21 @@ function createAcpConnection(options) {
25196
25255
  } finally {
25197
25256
  endInboundBatch();
25198
25257
  }
25199
- await shutdown(new AcpConnectionClosedError("ACP input stream ended"));
25258
+ await shutdown(
25259
+ new AcpConnectionClosedError("ACP input stream ended", { reason: "input-ended" })
25260
+ );
25200
25261
  });
25201
25262
  };
25202
25263
  const onError = (error62) => {
25203
25264
  enqueueInbound(async () => {
25204
25265
  await shutdown(
25205
- error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP input stream error")
25266
+ error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP input stream error", { reason: "stream-error" })
25206
25267
  );
25207
25268
  });
25208
25269
  };
25209
25270
  const onWritableError = (error62) => {
25210
25271
  void shutdown(
25211
- error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP output stream error")
25272
+ error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP output stream error", { reason: "stream-error" })
25212
25273
  );
25213
25274
  };
25214
25275
  options.readable.on("data", onData);
@@ -25271,7 +25332,8 @@ function createAcpConnection(options) {
25271
25332
  awaitInboundIdle,
25272
25333
  abandonPending,
25273
25334
  close,
25274
- closed
25335
+ closed,
25336
+ closeError: () => closedError
25275
25337
  };
25276
25338
  }
25277
25339
 
@@ -25680,7 +25742,8 @@ var ACP_FAILURE_CATEGORIES = [
25680
25742
  "auth",
25681
25743
  "model-unavailable",
25682
25744
  "transport",
25683
- "unknown"
25745
+ "unknown",
25746
+ "process-exit"
25684
25747
  ];
25685
25748
  var isAcpFailureCategory = (value) => ACP_FAILURE_CATEGORIES.some((category) => category === value);
25686
25749
  var readAcpFailureCategory = (error62) => {
@@ -25690,11 +25753,14 @@ var readAcpFailureCategory = (error62) => {
25690
25753
  };
25691
25754
  var withFailureCategory = (error62, category) => category === void 0 ? error62 : Object.assign(error62, { failureCategory: category });
25692
25755
  var failureCategoryField = (category) => category === void 0 ? {} : { failureCategory: category };
25693
- var acpTransportIfEstablished = (sessionEstablished, disposed) => sessionEstablished && !disposed ? "transport" : void 0;
25756
+ var acpClosedConnectionCategory = (closeError, sessionEstablished, disposed) => {
25757
+ if (!sessionEstablished || disposed) return void 0;
25758
+ return closeError instanceof AcpConnectionClosedError && closeError.reason === "input-ended" ? "process-exit" : "transport";
25759
+ };
25694
25760
  var acpPromptFailureCategory = (error62, input2) => {
25695
25761
  const signaled = readAcpFailureCategory(error62);
25696
25762
  if (signaled !== void 0) return signaled;
25697
- return error62 instanceof AcpConnectionClosedError ? acpTransportIfEstablished(input2.sessionEstablished, input2.disposed) : void 0;
25763
+ return error62 instanceof AcpConnectionClosedError ? acpClosedConnectionCategory(error62, input2.sessionEstablished, input2.disposed) : void 0;
25698
25764
  };
25699
25765
 
25700
25766
  // ../../packages/ycodium-acp-executor/src/tool-subagents.ts
@@ -25709,7 +25775,7 @@ var sealedHidden = (entry) => ({
25709
25775
  });
25710
25776
  function toolSubagentSettlementOfTurn(state, failureCategory) {
25711
25777
  if (state === "cancelled") return "turn-interrupted";
25712
- return state === "failed" && failureCategory === "transport" ? "session-ended" : "turn-ended";
25778
+ return state === "failed" && failureCategory === "process-exit" ? "session-ended" : "turn-ended";
25713
25779
  }
25714
25780
  var sameFacts = (a, b) => a.title === b.title && a.description === b.description && a.summary === b.summary && a.role === b.role && a.model === b.model && a.effort === b.effort && a.rosterKind === b.rosterKind;
25715
25781
  function linkage(taskId, toolCallId, facts) {
@@ -26326,14 +26392,19 @@ function createExecutorPrompt({
26326
26392
  },
26327
26393
  record2
26328
26394
  );
26329
- } catch (error62) {
26395
+ } catch (caught) {
26330
26396
  if (shared.disposed) {
26331
26397
  throw new AcpExecutorDisposedError();
26332
26398
  }
26333
- const failureCategory = acpPromptFailureCategory(error62, {
26399
+ const failureCategory = acpPromptFailureCategory(caught, {
26334
26400
  sessionEstablished: shared.startResult !== void 0,
26335
26401
  disposed: shared.disposed
26336
26402
  });
26403
+ const error62 = failureCategory === "process-exit" && !interruptedTurnIds.has(turnId) ? await describeAgentExit({
26404
+ cause: caught,
26405
+ exited: options.exited,
26406
+ stderrTail: options.stderrTail
26407
+ }) : caught;
26337
26408
  if (!interruptedTurnIds.has(turnId)) {
26338
26409
  const errorMessage = error62 instanceof Error && error62.message.trim() || "ACP prompt failed";
26339
26410
  if (settle2({
@@ -27722,24 +27793,40 @@ function createExecutorUpdates({
27722
27793
  return;
27723
27794
  }
27724
27795
  };
27725
- const emitTaskEvents = (taskEvents) => {
27726
- for (const taskEvent of taskEvents ?? []) {
27796
+ const emitHookEvents = (hookEvents) => {
27797
+ for (const hookEvent of hookEvents ?? []) {
27798
+ if (hookEvent.type === "runtime.warning") {
27799
+ const message = hookEvent.payload.message.trim();
27800
+ if (message.length === 0) continue;
27801
+ emit({
27802
+ type: "runtime.warning",
27803
+ ...stamp(),
27804
+ provider: options.provider,
27805
+ threadId: options.threadId,
27806
+ ...hookEvent.turnId !== void 0 ? { turnId: hookEvent.turnId } : {},
27807
+ payload: {
27808
+ message,
27809
+ ...hookEvent.payload.detail !== void 0 ? { detail: hookEvent.payload.detail } : {}
27810
+ }
27811
+ });
27812
+ continue;
27813
+ }
27727
27814
  emit({
27728
- type: taskEvent.type,
27815
+ type: hookEvent.type,
27729
27816
  ...stamp(),
27730
27817
  provider: options.provider,
27731
27818
  threadId: options.threadId,
27732
- ...taskEvent.turnId !== void 0 ? { turnId: taskEvent.turnId } : {},
27733
- payload: taskEvent.payload
27819
+ ...hookEvent.turnId !== void 0 ? { turnId: hookEvent.turnId } : {},
27820
+ payload: hookEvent.payload
27734
27821
  });
27735
27822
  }
27736
27823
  };
27737
27824
  const toolSubagents = hooks.toolSubagents === void 0 ? void 0 : createToolSubagentTracker(hooks.toolSubagents);
27738
- const settleToolSubagents = (settlement, turnId) => emitTaskEvents(toolSubagents?.settle(settlement, turnId));
27825
+ const settleToolSubagents = (settlement, turnId) => emitHookEvents(toolSubagents?.settle(settlement, turnId));
27739
27826
  const settleSessionEnded = () => {
27740
27827
  settleToolSubagents("session-ended");
27741
- emitTaskEvents(subagentSessions?.settleSessionEnded());
27742
- emitTaskEvents(hooks.onSessionEnded?.());
27828
+ emitHookEvents(subagentSessions?.settleSessionEnded());
27829
+ emitHookEvents(hooks.onSessionEnded?.());
27743
27830
  };
27744
27831
  const observeContext = () => ({
27745
27832
  turnId: shared.activeTurnId,
@@ -27801,7 +27888,7 @@ function createExecutorUpdates({
27801
27888
  };
27802
27889
  const hookResult = call === void 0 ? void 0 : toolSubagents?.onToolCallUpdated(call) ?? hooks.onToolCallUpdated?.(call);
27803
27890
  const handledByHook = hookResult !== void 0 && "events" in hookResult && hookResult.handled === true;
27804
- emitTaskEvents(
27891
+ emitHookEvents(
27805
27892
  hookResult === void 0 ? [] : "events" in hookResult ? hookResult.events : hookResult
27806
27893
  );
27807
27894
  if (nextToolCall.status === "completed" && hookResult && "artifacts" in hookResult)
@@ -27898,7 +27985,7 @@ function createExecutorUpdates({
27898
27985
  };
27899
27986
  const receiveSessionUpdate = (params) => {
27900
27987
  const foreign = !shared.ownSessionIds.has(params.sessionId) && (shared.childSessions.has(params.sessionId) || shared.sessionOpensInFlight === 0 && shared.ownSessionIds.size > 0);
27901
- emitTaskEvents(
27988
+ emitHookEvents(
27902
27989
  subagentSessions?.observe(params, {
27903
27990
  turnId: shared.activeTurnId,
27904
27991
  foreign,
@@ -27908,7 +27995,7 @@ function createExecutorUpdates({
27908
27995
  );
27909
27996
  if (!shared.sessionLoadInFlight) {
27910
27997
  if (hooks.onSessionUpdate) {
27911
- emitTaskEvents(hooks.onSessionUpdate(params, { ...observeContext(), foreign }));
27998
+ emitHookEvents(hooks.onSessionUpdate(params, { ...observeContext(), foreign }));
27912
27999
  }
27913
28000
  }
27914
28001
  if (!foreign) handleSessionUpdate(params);
@@ -27916,7 +28003,7 @@ function createExecutorUpdates({
27916
28003
  const receiveExtensionNotification = (method, params) => {
27917
28004
  if (shared.sessionLoadInFlight || !hooks.onExtensionNotification) return;
27918
28005
  const result = hooks.onExtensionNotification(method, params, observeContext());
27919
- if (Array.isArray(result)) emitTaskEvents(result);
28006
+ if (Array.isArray(result)) emitHookEvents(result);
27920
28007
  };
27921
28008
  return {
27922
28009
  emitCompactionState,
@@ -28211,7 +28298,11 @@ function createAcpExecutor(options) {
28211
28298
  settleAllUserInputs();
28212
28299
  abortPendingSettlement(
28213
28300
  "connection closed",
28214
- acpTransportIfEstablished(shared.startResult !== void 0, shared.disposed)
28301
+ acpClosedConnectionCategory(
28302
+ connection.closeError(),
28303
+ shared.startResult !== void 0,
28304
+ shared.disposed
28305
+ )
28215
28306
  );
28216
28307
  shared.promptWaiters.splice(0).forEach((wake) => wake());
28217
28308
  },
@@ -29125,6 +29216,7 @@ var createAcpInstance = (config2, host) => {
29125
29216
  readable,
29126
29217
  writable,
29127
29218
  stderrTail,
29219
+ exited: handle.exited,
29128
29220
  ...requestedEffort === void 0 ? {} : { requestedEffort },
29129
29221
  cwd,
29130
29222
  threadId: input2.threadId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-acp",
3
- "version": "0.2.4343",
3
+ "version": "0.2.4368",
4
4
  "description": "Generic ACP executor: user-supplied CLI over Agent Client Protocol stdio.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -21,8 +21,8 @@
21
21
  "@types/node": "24.12.4",
22
22
  "esbuild": "0.28.1",
23
23
  "vite-plus": "0.2.2",
24
- "@ycodium-ai/plugin-api": "0.2.4343",
25
- "ycodium-acp-executor": "0.2.4343",
24
+ "@ycodium-ai/plugin-api": "0.2.4368",
25
+ "ycodium-acp-executor": "0.2.4368",
26
26
  "ycodium-executor-testing": "0.0.0"
27
27
  },
28
28
  "ycodium": {