@agentproto/runtime 5.8.0 → 5.10.0

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.
@@ -182,6 +182,27 @@ declare function decideRestartStrategy(prev: RestartCandidate, opts?: DecideRest
182
182
  * this module's own header comment on why that matters).
183
183
  */
184
184
  declare const RESUME_ID_REJECTED_RE: RegExp;
185
+ /**
186
+ * Matches the OTHER way a resume attempt dies: the freshly-spawned adapter
187
+ * took its transport down while the resume RPC was still in flight, so the
188
+ * ACP SDK rejected the pending `session/load` with its connection-close
189
+ * error instead of a protocol-level answer.
190
+ *
191
+ * This is what a `session_restart` of a transport-dead session looked like
192
+ * in the field (2026-09-25, `sess_950d1251`): the restart spawned a new
193
+ * wrapper, the wrapper died mid-`loadSession`, and the operator got a bare
194
+ * "ACP connection closed" — no fallback, because the message says nothing
195
+ * about the id being rejected, which is all {@link RESUME_ID_REJECTED_RE}
196
+ * looks for.
197
+ *
198
+ * Treated as a fallback trigger for the same reason a rejected id is: the
199
+ * stored conversation could not be rehydrated, and a fresh spawn (plus the
200
+ * daemon-transcript digest) is strictly better than handing the operator an
201
+ * error and no session. It costs exactly one retry — if the adapter is
202
+ * broken in general rather than on this id, the retry fails too and the real
203
+ * error propagates.
204
+ */
205
+ declare const RESUME_CONNECTION_LOST_RE: RegExp;
185
206
  /**
186
207
  * Generic filesystem-fallback: for each known adapter strategy that
187
208
  * defines an `fsProbe`, run it against this session's cwd. If a
@@ -255,4 +276,4 @@ declare function describeResumePath(prev: RestartCandidate, opts?: DecideRestart
255
276
  */
256
277
  declare function tokenizeCommand(s: string): string[];
257
278
 
258
- export { type DecideRestartStrategyOptions, type FsProbeCandidate, type NativeTranscriptProbe, RESUME_ID_REJECTED_RE, RESUME_STRATEGIES, type RestartCandidate, type RestartStrategy, type ResumeMetadataKey, type ResumeStrategy, augmentWithFsResume, decideRestartStrategy, describeResumePath, hasResumeStrategy, probeNativeTranscript, tokenizeCommand };
279
+ export { type DecideRestartStrategyOptions, type FsProbeCandidate, type NativeTranscriptProbe, RESUME_CONNECTION_LOST_RE, RESUME_ID_REJECTED_RE, RESUME_STRATEGIES, type RestartCandidate, type RestartStrategy, type ResumeMetadataKey, type ResumeStrategy, augmentWithFsResume, decideRestartStrategy, describeResumePath, hasResumeStrategy, probeNativeTranscript, tokenizeCommand };
@@ -19,6 +19,15 @@ var __export = (target, all) => {
19
19
  __defProp(target, name, { get: all[name], enumerable: true });
20
20
  };
21
21
 
22
+ // src/handoff-markers.ts
23
+ var HANDOFF_PROMPT_SOURCE, HANDOFF_PROMPT_OPENER;
24
+ var init_handoff_markers = __esm({
25
+ "src/handoff-markers.ts"() {
26
+ HANDOFF_PROMPT_SOURCE = "daemon:handoff";
27
+ HANDOFF_PROMPT_OPENER = "[handoff request from the agentproto daemon]";
28
+ }
29
+ });
30
+
22
31
  // src/tool-presenter.ts
23
32
  function isRecord(value) {
24
33
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -611,6 +620,15 @@ Either the session never drove an agent-cli turn, or it predates this feature.`
611
620
  asmToolCalls = [];
612
621
  asmTs = void 0;
613
622
  };
623
+ let handoffStart;
624
+ const closeHandoffTurn = () => {
625
+ if (handoffStart === void 0) return;
626
+ for (let i = handoffStart; i < messages.length; i++) {
627
+ const m = messages[i];
628
+ if (m) m.internal = "handoff";
629
+ }
630
+ handoffStart = void 0;
631
+ };
614
632
  const rl = createInterface({ input: stream, crlfDelay: Infinity });
615
633
  for await (const line of rl) {
616
634
  const trimmed = line.trim();
@@ -657,10 +675,15 @@ ${rec.stderr}`);
657
675
  switch (rec.kind) {
658
676
  case "user-prompt":
659
677
  flushAssistant();
678
+ closeHandoffTurn();
679
+ if (rec.source === HANDOFF_PROMPT_SOURCE || rec.text?.startsWith(HANDOFF_PROMPT_OPENER)) {
680
+ handoffStart = messages.length;
681
+ }
660
682
  messages.push({ role: "user", text: rec.text ?? "", ...tsOrUndefined !== void 0 ? { ts: tsOrUndefined } : {} });
661
683
  break;
662
684
  case "session-message": {
663
685
  flushAssistant();
686
+ closeHandoffTurn();
664
687
  const m = rec.message;
665
688
  if (!m) break;
666
689
  const relation = m.from?.relation ?? "system";
@@ -680,7 +703,13 @@ ${rec.stderr}`);
680
703
  }
681
704
  case "system-prompt":
682
705
  flushAssistant();
683
- messages.push({ role: "system", text: rec.text ?? "", ...tsOrUndefined !== void 0 ? { ts: tsOrUndefined } : {} });
706
+ closeHandoffTurn();
707
+ messages.push({
708
+ role: "system",
709
+ text: rec.text ?? "",
710
+ internal: "preamble",
711
+ ...tsOrUndefined !== void 0 ? { ts: tsOrUndefined } : {}
712
+ });
684
713
  break;
685
714
  case "text-delta":
686
715
  if (asmTs === void 0) asmTs = tsOrUndefined;
@@ -740,6 +769,7 @@ ${rec.stderr}`);
740
769
  }
741
770
  }
742
771
  flushAssistant();
772
+ closeHandoffTurn();
743
773
  const meta = { source: "daemon-events" };
744
774
  if (desc?.label) meta.title = desc.label;
745
775
  else if (desc?.command) {
@@ -1460,6 +1490,7 @@ Only sessions spawned via claude-code or hermes can be exported.`
1460
1490
  var ROLE_ICON, IGNORED_CLAUDE_TYPES, NODE_SQLITE, EXPORT_STRATEGIES;
1461
1491
  var init_transcript_export = __esm({
1462
1492
  "src/transcript-export.ts"() {
1493
+ init_handoff_markers();
1463
1494
  init_tool_presenter();
1464
1495
  init_transcript_writer();
1465
1496
  init_conversation_store();
@@ -1774,6 +1805,7 @@ function decideRestartStrategy(prev, opts = {}) {
1774
1805
  };
1775
1806
  }
1776
1807
  var RESUME_ID_REJECTED_RE = /not found|does not support|not supported|unsupported/i;
1808
+ var RESUME_CONNECTION_LOST_RE = /connection closed|connection lost|epipe/i;
1777
1809
  async function augmentWithFsResume(prev) {
1778
1810
  const slug = prev.adapterSlug;
1779
1811
  if (!slug) return prev;
@@ -1867,6 +1899,6 @@ function tokenizeCommand(s) {
1867
1899
  return out;
1868
1900
  }
1869
1901
 
1870
- export { RESUME_ID_REJECTED_RE, RESUME_STRATEGIES, augmentWithFsResume, decideRestartStrategy, describeResumePath, hasResumeStrategy, probeNativeTranscript, tokenizeCommand };
1902
+ export { RESUME_CONNECTION_LOST_RE, RESUME_ID_REJECTED_RE, RESUME_STRATEGIES, augmentWithFsResume, decideRestartStrategy, describeResumePath, hasResumeStrategy, probeNativeTranscript, tokenizeCommand };
1871
1903
  //# sourceMappingURL=resume-strategies.mjs.map
1872
1904
  //# sourceMappingURL=resume-strategies.mjs.map