@ycodium-ai/agent-grok 0.2.4321 → 0.2.4351

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 +91 -15
  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 = 110;
12
12
 
13
13
  // src/index.ts
14
14
  import {
@@ -479,9 +479,11 @@ var AcpExecutorRequestError = class extends AcpExecutorError {
479
479
  }
480
480
  };
481
481
  var AcpConnectionClosedError = class extends Error {
482
+ reason;
482
483
  constructor(message = "ACP connection closed", options) {
483
- super(message, options);
484
+ super(message, options?.cause === void 0 ? void 0 : { cause: options.cause });
484
485
  this.name = "AcpConnectionClosedError";
486
+ this.reason = options?.reason ?? "closed";
485
487
  }
486
488
  };
487
489
  async function withStartupStderr(error62, stderrTail) {
@@ -491,9 +493,65 @@ async function withStartupStderr(error62, stderrTail) {
491
493
  return new AcpConnectionClosedError(`${error62.message}
492
494
  Agent stderr (last lines):
493
495
  ${tail}`, {
494
- cause: error62
496
+ cause: error62,
497
+ reason: error62.reason
495
498
  });
496
499
  }
500
+ var AGENT_EXIT_STDERR_MAX_CHARS = 800;
501
+ var AGENT_EXIT_SETTLE_MS = 500;
502
+ var AcpAgentExitedError = class extends AcpConnectionClosedError {
503
+ exitCode;
504
+ constructor(message, exitCode, cause) {
505
+ super(message, { cause, reason: "input-ended" });
506
+ this.name = "AcpAgentExitedError";
507
+ this.exitCode = exitCode;
508
+ }
509
+ };
510
+ var REDACTION_MARKERS = ["[redacted]", "[pairing-url]"];
511
+ var lastLines = (text4, maxChars) => {
512
+ if (text4.length <= maxChars) return text4;
513
+ let start = text4.length - maxChars;
514
+ if (text4[start - 1] !== "\n") {
515
+ const lineEnd = text4.indexOf("\n", start);
516
+ if (lineEnd !== -1 && lineEnd < text4.length - 1) return text4.slice(lineEnd + 1);
517
+ const code = text4.charCodeAt(start);
518
+ if (code >= 56320 && code <= 57343) start += 1;
519
+ for (const marker of REDACTION_MARKERS) {
520
+ const at = text4.lastIndexOf(marker, start);
521
+ if (at !== -1 && at < start && start < at + marker.length) start = at + marker.length;
522
+ }
523
+ }
524
+ return text4.slice(start);
525
+ };
526
+ var settledExitCode = async (exited) => {
527
+ if (exited === void 0) return void 0;
528
+ let timer;
529
+ try {
530
+ return await Promise.race([
531
+ exited.catch(() => void 0),
532
+ new Promise((resolve2) => {
533
+ timer = setTimeout(() => resolve2(void 0), AGENT_EXIT_SETTLE_MS);
534
+ })
535
+ ]);
536
+ } finally {
537
+ clearTimeout(timer);
538
+ }
539
+ };
540
+ async function describeAgentExit(input2) {
541
+ const [exitCode, tail] = await Promise.all([
542
+ settledExitCode(input2.exited),
543
+ input2.stderrTail === void 0 ? "" : Promise.resolve().then(input2.stderrTail).catch(() => "")
544
+ ]);
545
+ 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}.`;
546
+ const excerpt = lastLines(tail.trim(), AGENT_EXIT_STDERR_MAX_CHARS);
547
+ return new AcpAgentExitedError(
548
+ excerpt.length === 0 ? head : `${head}
549
+ Agent stderr (last lines):
550
+ ${excerpt}`,
551
+ exitCode,
552
+ input2.cause
553
+ );
554
+ }
497
555
 
498
556
  // ../../packages/ycodium-acp-executor/src/event-stream.ts
499
557
  var UnboundedEventStream = class {
@@ -25428,7 +25486,8 @@ function createAcpConnection(options) {
25428
25486
  options.onInboundFailure?.(error62);
25429
25487
  void shutdown(
25430
25488
  new AcpConnectionClosedError(
25431
- `ACP inbound handling failed: ${error62 instanceof Error ? error62.message : String(error62)}`
25489
+ `ACP inbound handling failed: ${error62 instanceof Error ? error62.message : String(error62)}`,
25490
+ { reason: "inbound-failed" }
25432
25491
  )
25433
25492
  );
25434
25493
  };
@@ -25473,19 +25532,21 @@ function createAcpConnection(options) {
25473
25532
  } finally {
25474
25533
  endInboundBatch();
25475
25534
  }
25476
- await shutdown(new AcpConnectionClosedError("ACP input stream ended"));
25535
+ await shutdown(
25536
+ new AcpConnectionClosedError("ACP input stream ended", { reason: "input-ended" })
25537
+ );
25477
25538
  });
25478
25539
  };
25479
25540
  const onError = (error62) => {
25480
25541
  enqueueInbound(async () => {
25481
25542
  await shutdown(
25482
- error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP input stream error")
25543
+ error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP input stream error", { reason: "stream-error" })
25483
25544
  );
25484
25545
  });
25485
25546
  };
25486
25547
  const onWritableError = (error62) => {
25487
25548
  void shutdown(
25488
- error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP output stream error")
25549
+ error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP output stream error", { reason: "stream-error" })
25489
25550
  );
25490
25551
  };
25491
25552
  options.readable.on("data", onData);
@@ -25548,7 +25609,8 @@ function createAcpConnection(options) {
25548
25609
  awaitInboundIdle,
25549
25610
  abandonPending,
25550
25611
  close,
25551
- closed
25612
+ closed,
25613
+ closeError: () => closedError
25552
25614
  };
25553
25615
  }
25554
25616
 
@@ -25957,7 +26019,8 @@ var ACP_FAILURE_CATEGORIES = [
25957
26019
  "auth",
25958
26020
  "model-unavailable",
25959
26021
  "transport",
25960
- "unknown"
26022
+ "unknown",
26023
+ "process-exit"
25961
26024
  ];
25962
26025
  var isAcpFailureCategory = (value) => ACP_FAILURE_CATEGORIES.some((category) => category === value);
25963
26026
  var readAcpFailureCategory = (error62) => {
@@ -25967,11 +26030,14 @@ var readAcpFailureCategory = (error62) => {
25967
26030
  };
25968
26031
  var withFailureCategory = (error62, category) => category === void 0 ? error62 : Object.assign(error62, { failureCategory: category });
25969
26032
  var failureCategoryField = (category) => category === void 0 ? {} : { failureCategory: category };
25970
- var acpTransportIfEstablished = (sessionEstablished, disposed) => sessionEstablished && !disposed ? "transport" : void 0;
26033
+ var acpClosedConnectionCategory = (closeError, sessionEstablished, disposed) => {
26034
+ if (!sessionEstablished || disposed) return void 0;
26035
+ return closeError instanceof AcpConnectionClosedError && closeError.reason === "input-ended" ? "process-exit" : "transport";
26036
+ };
25971
26037
  var acpPromptFailureCategory = (error62, input2) => {
25972
26038
  const signaled = readAcpFailureCategory(error62);
25973
26039
  if (signaled !== void 0) return signaled;
25974
- return error62 instanceof AcpConnectionClosedError ? acpTransportIfEstablished(input2.sessionEstablished, input2.disposed) : void 0;
26040
+ return error62 instanceof AcpConnectionClosedError ? acpClosedConnectionCategory(error62, input2.sessionEstablished, input2.disposed) : void 0;
25975
26041
  };
25976
26042
 
25977
26043
  // ../../packages/ycodium-acp-executor/src/tool-subagents.ts
@@ -25986,7 +26052,7 @@ var sealedHidden = (entry) => ({
25986
26052
  });
25987
26053
  function toolSubagentSettlementOfTurn(state, failureCategory) {
25988
26054
  if (state === "cancelled") return "turn-interrupted";
25989
- return state === "failed" && failureCategory === "transport" ? "session-ended" : "turn-ended";
26055
+ return state === "failed" && failureCategory === "process-exit" ? "session-ended" : "turn-ended";
25990
26056
  }
25991
26057
  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;
25992
26058
  function linkage(taskId, toolCallId, facts) {
@@ -26603,14 +26669,19 @@ function createExecutorPrompt({
26603
26669
  },
26604
26670
  record4
26605
26671
  );
26606
- } catch (error62) {
26672
+ } catch (caught) {
26607
26673
  if (shared.disposed) {
26608
26674
  throw new AcpExecutorDisposedError();
26609
26675
  }
26610
- const failureCategory = acpPromptFailureCategory(error62, {
26676
+ const failureCategory = acpPromptFailureCategory(caught, {
26611
26677
  sessionEstablished: shared.startResult !== void 0,
26612
26678
  disposed: shared.disposed
26613
26679
  });
26680
+ const error62 = failureCategory === "process-exit" && !interruptedTurnIds.has(turnId) ? await describeAgentExit({
26681
+ cause: caught,
26682
+ exited: options.exited,
26683
+ stderrTail: options.stderrTail
26684
+ }) : caught;
26614
26685
  if (!interruptedTurnIds.has(turnId)) {
26615
26686
  const errorMessage = error62 instanceof Error && error62.message.trim() || "ACP prompt failed";
26616
26687
  if (settle2({
@@ -28435,7 +28506,11 @@ function createAcpExecutor(options) {
28435
28506
  settleAllUserInputs();
28436
28507
  abortPendingSettlement(
28437
28508
  "connection closed",
28438
- acpTransportIfEstablished(shared.startResult !== void 0, shared.disposed)
28509
+ acpClosedConnectionCategory(
28510
+ connection.closeError(),
28511
+ shared.startResult !== void 0,
28512
+ shared.disposed
28513
+ )
28439
28514
  );
28440
28515
  shared.promptWaiters.splice(0).forEach((wake) => wake());
28441
28516
  },
@@ -30773,6 +30848,7 @@ var createGrokInstance = (config2, host) => {
30773
30848
  readable,
30774
30849
  writable,
30775
30850
  stderrTail,
30851
+ exited: handle.exited,
30776
30852
  cwd,
30777
30853
  threadId: input2.threadId,
30778
30854
  provider: GROK_DRIVER_KIND,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-grok",
3
- "version": "0.2.4321",
3
+ "version": "0.2.4351",
4
4
  "description": "Grok executor: grok CLI over Agent Client Protocol stdio.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -21,9 +21,9 @@
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.4321",
24
+ "@ycodium-ai/plugin-api": "0.2.4351",
25
25
  "ycodium-executor-testing": "0.0.0",
26
- "ycodium-acp-executor": "0.2.4321"
26
+ "ycodium-acp-executor": "0.2.4351"
27
27
  },
28
28
  "ycodium": {
29
29
  "plugin": "./dist/index.js",