@songsid/agend 2.4.0-beta.30 → 2.4.0-beta.32

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 (71) hide show
  1. package/dist/backend/antigravity.js +39 -0
  2. package/dist/backend/antigravity.js.map +1 -1
  3. package/dist/build-provenance.json +1 -1
  4. package/dist/channel/mcp-tools.js +1 -1
  5. package/dist/channel/mcp-tools.js.map +1 -1
  6. package/dist/daemon.d.ts +11 -1
  7. package/dist/daemon.js +121 -26
  8. package/dist/daemon.js.map +1 -1
  9. package/dist/fleet-context.d.ts +2 -0
  10. package/dist/fleet-manager.d.ts +9 -0
  11. package/dist/fleet-manager.js +84 -9
  12. package/dist/fleet-manager.js.map +1 -1
  13. package/dist/general-knowledge/skills/concepts/SKILL.md +21 -2
  14. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +9 -4
  15. package/dist/general-knowledge/skills/hub/SKILL.md +6 -0
  16. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +2 -0
  17. package/dist/hub/admission.d.ts +2 -0
  18. package/dist/hub/admission.js +13 -0
  19. package/dist/hub/admission.js.map +1 -1
  20. package/dist/hub/client.d.ts +10 -0
  21. package/dist/hub/client.js +126 -4
  22. package/dist/hub/client.js.map +1 -1
  23. package/dist/hub/compose/member.d.ts +13 -1
  24. package/dist/hub/compose/member.js +34 -5
  25. package/dist/hub/compose/member.js.map +1 -1
  26. package/dist/hub/identity.d.ts +2 -0
  27. package/dist/hub/identity.js +5 -2
  28. package/dist/hub/identity.js.map +1 -1
  29. package/dist/hub/member/room-ask.d.ts +1 -0
  30. package/dist/hub/member/room-ask.js +11 -4
  31. package/dist/hub/member/room-ask.js.map +1 -1
  32. package/dist/hub/member-journal.d.ts +8 -0
  33. package/dist/hub/member-journal.js +41 -0
  34. package/dist/hub/member-journal.js.map +1 -1
  35. package/dist/hub/policy.d.ts +3 -1
  36. package/dist/hub/policy.js +3 -1
  37. package/dist/hub/policy.js.map +1 -1
  38. package/dist/hub/protocol.d.ts +7 -0
  39. package/dist/hub/protocol.js +8 -1
  40. package/dist/hub/protocol.js.map +1 -1
  41. package/dist/hub/representative.d.ts +6 -0
  42. package/dist/hub/representative.js +39 -5
  43. package/dist/hub/representative.js.map +1 -1
  44. package/dist/hub/server.js +6 -2
  45. package/dist/hub/server.js.map +1 -1
  46. package/dist/hub-reply-route.d.ts +36 -0
  47. package/dist/hub-reply-route.js +67 -0
  48. package/dist/hub-reply-route.js.map +1 -0
  49. package/dist/hub-report-target.d.ts +4 -0
  50. package/dist/locale.js +2 -2
  51. package/dist/locale.js.map +1 -1
  52. package/dist/outbound-handlers.d.ts +2 -0
  53. package/dist/outbound-handlers.js +22 -7
  54. package/dist/outbound-handlers.js.map +1 -1
  55. package/dist/outbound-schemas.d.ts +1 -0
  56. package/dist/outbound-schemas.js +1 -0
  57. package/dist/outbound-schemas.js.map +1 -1
  58. package/dist/topic-commands.js +6 -4
  59. package/dist/topic-commands.js.map +1 -1
  60. package/dist/turn-reply-guard.d.ts +3 -1
  61. package/dist/turn-reply-guard.js +3 -2
  62. package/dist/turn-reply-guard.js.map +1 -1
  63. package/dist/ui/hub-chat-store.js +9 -6
  64. package/dist/ui/hub-chat-strings.js +4 -2
  65. package/dist/ui/hub-room-strings.js +2 -2
  66. package/dist/ui/hub-room-thread.js +9 -3
  67. package/dist/ui/panel-chat.js +18 -5
  68. package/dist/ui/panel-hub.js +2 -2
  69. package/dist/ui/report-columns.js +137 -0
  70. package/dist/ui/shared/app.css +28 -2
  71. package/package.json +1 -1
package/dist/daemon.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { HubReplyInputs, hubReplyRecoveryPrompt } from "./hub-reply-route.js";
1
2
  import { RequestContextPendingReplies } from "./request-context-reply-pending.js";
2
3
  import { expandCompositeCall as expandReplyWaitCall } from "./channel/mcp-tools.js";
3
4
  import { RequestContextHelperAdmission } from "./request-context-helper.js";
@@ -1524,6 +1525,39 @@ export class Daemon extends EventEmitter {
1524
1525
  // It also supplies the older dead-MCP/malformed-call recovery paths, so those
1525
1526
  // paths cannot disagree about whether the turn already spoke to the channel.
1526
1527
  turnReplyGuard = new TurnReplyGuard();
1528
+ _hubReplyInputs;
1529
+ get hubReplyInputs() { return this._hubReplyInputs ??= new HubReplyInputs(() => JSON.stringify([this.bootId, this.spawnGeneration, this.launchFenceEpoch, this.deliveryEpoch])); }
1530
+ /** Same-process accepted Hub delivery owner only; never dispatched as a tool or metadata command. */
1531
+ registerHubReplyInput(id, accepted, cid, body, questionBeginning) {
1532
+ if (accepted.destination.agent !== this.name)
1533
+ throw Error("Hub reply destination changed");
1534
+ this.hubReplyInputs.register(id, accepted, cid, body, questionBeginning);
1535
+ }
1536
+ releaseHubReplyInput(id) { this.hubReplyInputs.release(id); }
1537
+ hubReplyTarget(snapshot) { return this.hubReplyInputs.targetForContext(snapshot); }
1538
+ /** Capture the exact obligation before awaiting the Hub's answer ACK. */
1539
+ captureHubReplyCompletion(cid, recordsAttempt = true) {
1540
+ const route = this.hubReplyInputs.routeForCid(cid);
1541
+ if (!route)
1542
+ return null;
1543
+ if (recordsAttempt)
1544
+ this.hubReplyInputs.attempt(route);
1545
+ const turn = this.turnReplyGuard.snapshot();
1546
+ const attempt = turn?.target.hubRoute?.binding === route.binding ? this.turnReplyGuard.beginToolAttempt(recordsAttempt, recordsAttempt) : null;
1547
+ return outcome => {
1548
+ if (this.hubReplyInputs.current(route)) {
1549
+ const confirmed = outcome.ok && outcome.confirmed?.messageId === route.messageId && outcome.confirmed.correlationId === route.correlationId;
1550
+ if (confirmed) {
1551
+ this.hubReplyInputs.attempt(route);
1552
+ this.hubReplyInputs.confirm(route);
1553
+ }
1554
+ else if (!outcome.ok && recordsAttempt)
1555
+ this.hubReplyInputs.fail(route);
1556
+ if (attempt && (confirmed || !outcome.ok && recordsAttempt))
1557
+ this.turnReplyGuard.settleToolAttempt(confirmed ? { ...attempt, reply: true, completionAction: true } : attempt, confirmed);
1558
+ }
1559
+ };
1560
+ }
1527
1561
  /** #1510: turn boundaries from the CLI's transcript, for a backend whose guard reads its turn end there. */
1528
1562
  transcriptTurns = new TranscriptTurnLedger();
1529
1563
  /** #1641: when this launch's transcript monitor last read anything (a turn boundary, a tool, assistant text); performance.now(). */
@@ -2802,7 +2836,12 @@ export class Daemon extends EventEmitter {
2802
2836
  // finished turn can never resume after a later restart. reset() is
2803
2837
  // deliberately NOT hooked: stop/spawn abandon the in-memory turn while
2804
2838
  // the on-disk interruption must survive for the resume gate.
2805
- this.turnReplyGuard.onComplete = () => {
2839
+ this.turnReplyGuard.onComplete = completed => {
2840
+ const route = completed?.target?.hubRoute;
2841
+ if (route) {
2842
+ this.hubReplyInputs.release(route.binding);
2843
+ this.endHubAnswerTurn(route.correlationId);
2844
+ }
2806
2845
  this.replyDraft.reset();
2807
2846
  clearInFlightTurnMarker(this.instanceDir);
2808
2847
  this.publishWorkingState("turn_closed");
@@ -5568,6 +5607,7 @@ export class Daemon extends EventEmitter {
5568
5607
  const message = this.resolveErrorMessage(pane, ep);
5569
5608
  this.logger.warn({ errorType: ep.type, action: ep.action }, `PTY error detected: ${message}`);
5570
5609
  this.lastErrorEpisode = { key, pattern: ep.pattern, pane, spawn: this.spawnGeneration, fence: this.launchFenceEpoch };
5610
+ this.noteHubAnswerFailure();
5571
5611
  const { notice: noticeOf, ...rest } = ep;
5572
5612
  const notice = noticeOf ? this.resolveErrorNotice(pane, ep, noticeOf) : undefined;
5573
5613
  this.emit("pty_error", { name: this.name, ...rest, message, ...(notice ? { notice } : {}) });
@@ -5645,6 +5685,7 @@ export class Daemon extends EventEmitter {
5645
5685
  // FleetManager calls this synchronously before sendEscape. Cancel only the
5646
5686
  // current human turn; leave already-forwarded tool requests to settle.
5647
5687
  this.recoveryCancelled = true;
5688
+ this.noteHubAnswerFailure();
5648
5689
  this.turnReplyGuard.cancelByUser();
5649
5690
  this.replyDraft.reset();
5650
5691
  // #1241: a cancelled turn never confirms — its next edge completes it as
@@ -6820,7 +6861,10 @@ export class Daemon extends EventEmitter {
6820
6861
  return;
6821
6862
  }
6822
6863
  const inputId = this.requestContextLifecycle && isHubQuestionMeta(meta) && typeof msg.request_context_input_id === "string" ? msg.request_context_input_id : undefined;
6823
- if (inputId)
6864
+ const hubReplyId = typeof msg.hub_reply_input_id === "string" ? msg.hub_reply_input_id : undefined;
6865
+ if (hubReplyId)
6866
+ this.pushChannelMessage(msg.content, meta, targetSession, deliveryEpoch, inputId, hubReplyId);
6867
+ else if (inputId)
6824
6868
  this.pushChannelMessage(msg.content, meta, targetSession, deliveryEpoch, inputId);
6825
6869
  else
6826
6870
  this.pushChannelMessage(msg.content, meta, targetSession, deliveryEpoch);
@@ -7402,7 +7446,7 @@ export class Daemon extends EventEmitter {
7402
7446
  * message can arrive mid-turn and sit queued, and marking at arrival would let
7403
7447
  * the PREVIOUS turn's idle edge consume (and reset) the new turn's state.
7404
7448
  */
7405
- markTurnStarted(meta, deliveredText, deliveryEpoch = this.deliveryEpoch, queuedHandoff = false, verdict) {
7449
+ markTurnStarted(meta, deliveredText, deliveryEpoch = this.deliveryEpoch, queuedHandoff = false, verdict, hubReply) {
7406
7450
  // Cancel may have interrupted an in-flight paste before its promise settled.
7407
7451
  // Its late success must not re-arm the turn that the user just cancelled.
7408
7452
  if (!this.isDeliveryEpochCurrent(deliveryEpoch))
@@ -7418,7 +7462,10 @@ export class Daemon extends EventEmitter {
7418
7462
  // fleet's web-only sink), but it is a person waiting for an answer all the
7419
7463
  // same: the guard arms for it (alpha.2).
7420
7464
  const requestContext = this.requestContextTurnSnapshot();
7421
- const ownedReplyTarget = requestContext ? this.requestContextLifecycle?.replyTarget?.(requestContext) : null;
7465
+ const ownedReplyTarget = hubReply && !queuedHandoff ? this.hubReplyInputs.target(hubReply) : requestContext ? this.requestContextLifecycle?.replyTarget?.(requestContext) : null;
7466
+ const prior = this.turnReplyGuard?.snapshot();
7467
+ if (prior && (ownedReplyTarget?.hubRoute || prior.target?.hubRoute) && prior.target?.hubRoute?.binding !== ownedReplyTarget?.hubRoute?.binding)
7468
+ this.turnReplyGuard.complete(prior.generation);
7422
7469
  if (!turnExpectsPersonReply(meta) && !ownedReplyTarget) {
7423
7470
  this.logger.debug({
7424
7471
  source: meta.source || null,
@@ -7451,7 +7498,14 @@ export class Daemon extends EventEmitter {
7451
7498
  else
7452
7499
  verdict.pendingReply.refuse();
7453
7500
  }
7501
+ if (hubReply && this.hubReplyInputs.attempted(hubReply)) {
7502
+ const attempt = this.turnReplyGuard.beginToolAttempt(true, true);
7503
+ if (this.hubReplyInputs.answered(hubReply) || this.hubReplyInputs.failed(hubReply))
7504
+ this.turnReplyGuard.settleToolAttempt(attempt, this.hubReplyInputs.answered(hubReply));
7505
+ }
7454
7506
  const armed = this.turnReplyGuard.snapshot();
7507
+ if (hubReply && this.hubReplyInputs.current(hubReply))
7508
+ this.broadcastFleetMessage({ type: "hub_question_delivered", correlationId: hubReply.correlationId });
7455
7509
  this.workingTurnDelivery = { generation: armed.generation, deliveryId: meta.delivery_id || null };
7456
7510
  this.workingTurnRequestContext = requestContext ? { generation: armed.generation, snapshot: requestContext } : null;
7457
7511
  this.publishWorkingState("turn_started");
@@ -7466,7 +7520,7 @@ export class Daemon extends EventEmitter {
7466
7520
  // writing a marker would re-inject a continuation for a finished turn.
7467
7521
  // #3030: a message only queued in the busy CLI has not started a turn: the interrupted turn is still the running one,
7468
7522
  // and a queued message lost to a restart is the hand-off record's to redeliver, not a continuation's.
7469
- if (!this.nativePaneLifecycle && !meta.resumedContinuationOf && !armed.completionDelivered && !queuedHandoff) {
7523
+ if (!armed.target.hubRoute && !this.nativePaneLifecycle && !meta.resumedContinuationOf && !armed.completionDelivered && !queuedHandoff) {
7470
7524
  const resumeBackend = this.config.backend ?? this.backend?.binaryName ?? this.runtimeIdentity?.backend;
7471
7525
  const resumeCwd = this.config.working_directory ?? "";
7472
7526
  writeInFlightTurnMarker(this.instanceDir, {
@@ -7657,7 +7711,7 @@ export class Daemon extends EventEmitter {
7657
7711
  // Claude sometimes prints a broken XML tool call as plain text and returns
7658
7712
  // idle without ever invoking `reply`. This is independent of MCP liveness:
7659
7713
  // the model malformed the call before the server could receive it.
7660
- if (this.isClaudeCodeBackend() && pane) {
7714
+ if (!turn.target.hubRoute && this.isClaudeCodeBackend() && pane) {
7661
7715
  const malformed = detectMalformedClaudeToolCall(pane, { inboundMarker: turn.target.inboundMarker });
7662
7716
  if (malformed) {
7663
7717
  const stale = malformed.signature === this.lastMalformedToolCallSignature;
@@ -7697,7 +7751,7 @@ export class Daemon extends EventEmitter {
7697
7751
  // Preserve the dead-MCP proxy path and its explicit opt-in. Any verified
7698
7752
  // outbound action suppresses a duplicate proxy; only a delivered
7699
7753
  // human-facing channel action satisfies the completion guard below.
7700
- if (!turn.outboundDelivered && this.config.mcp_proxy_reply === true
7754
+ if (!turn.target.hubRoute && !turn.outboundDelivered && this.config.mcp_proxy_reply === true
7701
7755
  && (this.nativePaneLifecycle ? this.nativePaneLifecycle.mcpProof() === "dead" : mcpServerState(this.instanceDir).state === "dead")) {
7702
7756
  this.turnReplyGuard.complete(turn.generation);
7703
7757
  void this.sendProxyReply(pane, turn.target);
@@ -7879,12 +7933,24 @@ export class Daemon extends EventEmitter {
7879
7933
  if (correlationId === undefined)
7880
7934
  return;
7881
7935
  // Throws when the turn cannot be recorded: the question is then not written, and its delivery fails (reported).
7882
- this.setHubAnswerTurn({ correlationId, contactLimit, sawWorking: false, restored: false });
7936
+ this.setHubAnswerTurn({ correlationId, contactLimit, sawWorking: false, restored: false, startedAt: Date.now() });
7883
7937
  this.broadcastFleetMessage({ type: "hub_question_input", correlationId, contactLimit });
7884
7938
  }
7885
- endHubAnswerTurn() {
7939
+ /** Fresh current-source error or explicit cancel is turn evidence, but the next input still needs a proven idle pane. */
7940
+ noteHubAnswerFailure(at) {
7886
7941
  const turn = this.hubAnswerTurn;
7887
- if (!turn)
7942
+ if (at !== undefined && (!Number.isFinite(at) || turn?.startedAt === undefined || at < turn.startedAt))
7943
+ return;
7944
+ if (turn) {
7945
+ turn.failed = true;
7946
+ turn.sawWorking = true;
7947
+ if (this.instanceState === "idle")
7948
+ this.noteTurnEdge("idle");
7949
+ }
7950
+ }
7951
+ endHubAnswerTurn(expectedCid) {
7952
+ const turn = this.hubAnswerTurn;
7953
+ if (!turn || expectedCid !== undefined && turn.correlationId !== expectedCid)
7888
7954
  return;
7889
7955
  this.setHubAnswerTurn(null);
7890
7956
  this.broadcastFleetMessage({ type: "hub_question_turn_ended", correlationId: turn.correlationId });
@@ -7958,11 +8024,12 @@ export class Daemon extends EventEmitter {
7958
8024
  // working edge AND transcript activity since it, so a flicker leaves the turn running until real work then idle) —
7959
8025
  // or, taken up again after a daemon restart, on the first idle edge.
7960
8026
  const hubTurn = this.hubAnswerTurn;
7961
- if (hubTurn?.sawWorking && (realWork || hubTurn.restored))
8027
+ const guardedHub = this.turnReplyGuard?.snapshot()?.target?.hubRoute;
8028
+ if (hubTurn?.sawWorking && (realWork || hubTurn.restored || hubTurn.failed) && guardedHub?.correlationId !== hubTurn.correlationId)
7962
8029
  this.endHubAnswerTurn();
7963
8030
  else if (!hubTurn)
7964
8031
  this.resolveUnknownHubAnswerTurn(); // an unreadable record: the pane is idle now, nothing runs
7965
- if (turn && realWork && roomGeneration && roomGeneration === this.roomConversationGeneration() && roomInputEpoch === this.hubRoomInputEpoch)
8032
+ if (!guardedHub && turn && realWork && roomGeneration && roomGeneration === this.roomConversationGeneration() && roomInputEpoch === this.hubRoomInputEpoch)
7966
8033
  this.broadcastFleetMessage({ type: "hub_room_turn_ended", generation: roomGeneration, turn: `${this.hubRoomTurnBoot}:${++this.hubRoomTurnSequence}` });
7967
8034
  if (!turn || turn.messaged || !turn.text.trim() || !this.turnEvidence())
7968
8035
  return;
@@ -8079,6 +8146,8 @@ export class Daemon extends EventEmitter {
8079
8146
  });
8080
8147
  for (const event of ["tool_use", "tool_result", "assistant_text"])
8081
8148
  monitor.on(event, touch);
8149
+ monitor.on("api_error", (_text, _status, at) => { if (at !== null && this.transcriptMonitor === monitor && owner === launchIdentity(this.interactionOwner()))
8150
+ this.noteHubAnswerFailure(at); });
8082
8151
  // M-3239: the turn as the transcript tells it — progress for the board's quiet clock, and the question a turn ends on.
8083
8152
  const mine = () => this.transcriptMonitor === monitor;
8084
8153
  monitor.on("tool_use", (name, input) => { if (mine()) {
@@ -8218,19 +8287,31 @@ export class Daemon extends EventEmitter {
8218
8287
  });
8219
8288
  return;
8220
8289
  }
8221
- let prompt = REPLY_RECOVERY_PROMPT;
8290
+ let prompt = current.target?.hubRoute ? hubReplyRecoveryPrompt(current.target.hubRoute) : REPLY_RECOVERY_PROMPT;
8222
8291
  try {
8223
- prompt = this.replyDraft.recoveryPrompt(current, REPLY_RECOVERY_PROMPT);
8292
+ if (!current.target?.hubRoute)
8293
+ prompt = this.replyDraft.recoveryPrompt(current, REPLY_RECOVERY_PROMPT);
8224
8294
  }
8225
8295
  catch { /* Draft evidence is best-effort; keep the existing generic recovery. */ }
8296
+ const recoveryRoute = current.target?.hubRoute;
8226
8297
  const recoveryText = parent && this.requestContextLifecycle ? `[agend-request-input:${recoveryInputId}]\n${prompt}` : prompt;
8227
8298
  const delivered = await this.deliverMessage(recoveryText, undefined, {
8228
8299
  deliveryEpoch,
8300
+ ...(recoveryRoute ? { hubReplyRecovery: () => {
8301
+ const latest = this.currentReplyRecovery(turn.generation, deliveryEpoch);
8302
+ return !!latest && !latest.completionDelivered && latest.target?.hubRoute === recoveryRoute
8303
+ && this.hubReplyInputs.current(recoveryRoute);
8304
+ } } : {}),
8229
8305
  ...(parent ? { requestContextRecovery: { inputId: recoveryInputId, parent,
8230
8306
  current: () => !!this.currentReplyRecovery(turn.generation, deliveryEpoch) } } : {}),
8231
8307
  });
8232
- if (!this.currentReplyRecovery(turn.generation, deliveryEpoch))
8308
+ const after = this.currentReplyRecovery(turn.generation, deliveryEpoch);
8309
+ if (!after)
8233
8310
  return;
8311
+ if (after.completionDelivered) {
8312
+ this.turnReplyGuard.complete(turn.generation);
8313
+ return;
8314
+ }
8234
8315
  if (!delivered) {
8235
8316
  this.turnReplyGuard.complete(turn.generation);
8236
8317
  this.reportUnrecoveredReplyDrop(turn, "recovery_prompt_delivery_failed");
@@ -8338,7 +8419,7 @@ export class Daemon extends EventEmitter {
8338
8419
  deliverDaemonReply(body, requestPrefix, logLabel, target) {
8339
8420
  // System proxy text has no originating call lease. Until its final-output generation proof is
8340
8421
  // installed, it cannot borrow a live turn or lastChat; proven-parent model recovery uses C instead.
8341
- if (this.requestContextLifecycle)
8422
+ if (target?.hubRoute || this.requestContextLifecycle)
8342
8423
  return Promise.resolve(false);
8343
8424
  const args = { text: body };
8344
8425
  const chatId = target?.chatId ?? this.lastChatId;
@@ -9626,7 +9707,12 @@ export class Daemon extends EventEmitter {
9626
9707
  * If targetSession is provided, only send to the matching socket.
9627
9708
  * Otherwise send to the instance's own session (this.name).
9628
9709
  */
9629
- pushChannelMessage(content, meta, _targetSession, deliveryEpoch = this.deliveryEpoch, requestContextInputId) {
9710
+ pushChannelMessage(content, meta, _targetSession, deliveryEpoch = this.deliveryEpoch, requestContextInputId, hubReplyInputId) {
9711
+ const ownedHubReply = this.hubReplyInputs.capture(hubReplyInputId, content, meta);
9712
+ if (hubReplyInputId && !ownedHubReply) {
9713
+ this.logger.warn("Hub reply input unavailable or already submitted");
9714
+ return;
9715
+ }
9630
9716
  if (requestContextInputId && !/^hub-input:[a-f0-9-]{36}$/.test(requestContextInputId))
9631
9717
  throw Error("Hub request input id is unavailable");
9632
9718
  if (!this.isDeliveryEpochCurrent(deliveryEpoch)) {
@@ -9770,7 +9856,7 @@ export class Daemon extends EventEmitter {
9770
9856
  if (sent) {
9771
9857
  delivered = true;
9772
9858
  this.finishDurableSubmission(durable, verdict);
9773
- this.markTurnStarted(meta, formatted, deliveryEpoch, !!verdict.handoff, verdict);
9859
+ this.markTurnStarted(meta, formatted, deliveryEpoch, !!verdict.handoff, verdict, ownedHubReply ?? undefined);
9774
9860
  }
9775
9861
  else if (durableAttempt && verdict.paneWriteStarted) {
9776
9862
  this.finishDurableDelivery(durable, "uncertain", `${verdict.phase ?? "post-submit"}:${verdict.proof ?? "unproven"}`, verdict);
@@ -9813,6 +9899,8 @@ export class Daemon extends EventEmitter {
9813
9899
  this.logger.warn({ err: err.message }, "Durable pane delivery deferred after exception");
9814
9900
  }
9815
9901
  finally {
9902
+ if (ownedHubReply && !delivered)
9903
+ this.hubReplyInputs.release(ownedHubReply.binding);
9816
9904
  this.finishHumanReceipt(meta, verdict);
9817
9905
  if (!delivered && !verdict.paneWriteStarted && !this.isDeliveryEpochCurrent(deliveryEpoch))
9818
9906
  this.noteCancelledHuman(meta);
@@ -9849,7 +9937,8 @@ export class Daemon extends EventEmitter {
9849
9937
  if (opts?.durableAttempt)
9850
9938
  verdict.durableAttempt = true;
9851
9939
  const cancelled = () => (opts?.deliveryEpoch !== undefined && !this.isDeliveryEpochCurrent(opts.deliveryEpoch))
9852
- || (!!opts?.roomContextGeneration && opts.roomContextGeneration !== this.roomConversationGeneration());
9940
+ || (!!opts?.roomContextGeneration && opts.roomContextGeneration !== this.roomConversationGeneration())
9941
+ || (!!opts?.hubReplyRecovery && !opts.hubReplyRecovery());
9853
9942
  if (cancelled() || this.stormWindow?.isStopped())
9854
9943
  return false;
9855
9944
  const admittedReceiptId = opts?.humanMeta?.verification_id ?? opts?.humanVerificationId;
@@ -10094,6 +10183,8 @@ export class Daemon extends EventEmitter {
10094
10183
  const written = await this.writeMessageToPane(formatted, windowId, handingOffToNativeQueue, status, opts?.submissionId, verdict, opts?.durableAttempt, opts?.steer === true, writeCurrent, opts?.humanVerificationId,
10095
10184
  // M-3660: written into an idle pane, so whatever Hub answer turn ran is over; a Hub question begins its own.
10096
10185
  (wireText) => {
10186
+ if (cancelled())
10187
+ throw new Error("Delivery continuation is no longer current");
10097
10188
  const receiptId = opts?.humanMeta?.verification_id ?? opts?.humanVerificationId;
10098
10189
  const inputId = opts?.requestContextInputId ?? (receiptId ? `human:${receiptId}` : opts?.durableAttempt
10099
10190
  ? `delivery:${opts.durableAttempt.deliveryId}:${opts.durableAttempt.attemptNo}` : null);
@@ -10108,10 +10199,10 @@ export class Daemon extends EventEmitter {
10108
10199
  if (humanId && verdict.pendingReply)
10109
10200
  this.requestContextHumanReplies.set(humanId, { pending: verdict.pendingReply, accepted: false });
10110
10201
  }
10111
- if (!handingOffToNativeQueue)
10202
+ if (!handingOffToNativeQueue && !opts?.hubReplyRecovery)
10112
10203
  this.hubAnswerTurnBegins(opts?.hubQuestion, opts?.hubContactLimit !== false);
10113
10204
  opts?.beforePaneWrite?.();
10114
- }, opts?.lookBeforePaneWrite, opts?.humanMeta);
10205
+ }, opts?.lookBeforePaneWrite, opts?.humanMeta, !!opts?.hubReplyRecovery);
10115
10206
  if (written === false && newlyBound && this.nativePaneLifecycle?.lastInputWasNotSent?.()) {
10116
10207
  const owner = this.requestContextOwner();
10117
10208
  if (owner && this.requestContextLifecycle.turns.ended(newlyBound, owner))
@@ -12293,7 +12384,9 @@ export class Daemon extends EventEmitter {
12293
12384
  // Board 003648ac: called synchronously right before each paste — after the last await and fence of that attempt.
12294
12385
  beforePaste,
12295
12386
  // Board 907c7899: awaited each attempt after its last capture, begin and fence; the fence is asked again after it.
12296
- lookBeforePaste, humanMeta) {
12387
+ lookBeforePaste, humanMeta,
12388
+ /** Carry this internal continuation's currentness through every Enter, including on tmux. */
12389
+ hubReplyRecovery = false) {
12297
12390
  if (humanMeta?.human_prepare_token) {
12298
12391
  if (stillCurrent && !stillCurrent())
12299
12392
  return false;
@@ -12356,8 +12449,9 @@ export class Daemon extends EventEmitter {
12356
12449
  const steerCurrent = () => (!stillCurrent || stillCurrent()) && !this.deliveryWritesStopping
12357
12450
  && this.tmux === tmuxAtWrite && this.spawnGeneration === spawnAtWrite;
12358
12451
  // Alpha (S-36, Prism #2989 P2): a NATIVE pane keeps #2958's pre-paste owner fence through the initial Enter and every
12359
- // retry Enter (a pane replaced while the paste awaits never takes this delivery's Enter); a tmux pane follows main.
12360
- const nativeOwner = this.nativePaneLifecycle ? steerCurrent : undefined;
12452
+ // retry Enter (a pane replaced while the paste awaits never takes this delivery's Enter). An exact Hub reply
12453
+ // recovery keeps that same caller fence on tmux too: an ACK or cancellation during paste-settle retires its Enter.
12454
+ const nativeOwner = this.nativePaneLifecycle || hubReplyRecovery ? steerCurrent : undefined;
12361
12455
  // Bug A: paste with backoff. Transient failures are usually a stale window id
12362
12456
  // after a crash/respawn — recover by name and retry (max 3 attempts, 2s apart).
12363
12457
  const maxAttempts = 3;
@@ -12626,7 +12720,7 @@ export class Daemon extends EventEmitter {
12626
12720
  verdict.phase = "submit-enter";
12627
12721
  // The merge of #2957/M-2290 (main) and the alpha's native holds: a tmux mode, a recognised dialog on a Linux pane,
12628
12722
  // and each native safety check say which.
12629
- verdict.proof = inputHeld === "pane-in-mode" ? "pane-in-mode-held" : nativeOwner ? `native-input-${inputHeld}`
12723
+ verdict.proof = inputHeld === "pane-in-mode" ? "pane-in-mode-held" : this.nativePaneLifecycle ? `native-input-${inputHeld}`
12630
12724
  : inputHeld === "dialog" ? "dialog-on-pane" : `input-held-${inputHeld}`;
12631
12725
  return false;
12632
12726
  }
@@ -13896,8 +13990,9 @@ export class Daemon extends EventEmitter {
13896
13990
  // an unmapped socket is retained for legacy/tests where mcp_ready was not
13897
13991
  // observed before the first tool call.
13898
13992
  const sourceSession = peer ? this.name : socket ? this.socketSessionNames.get(socket) : undefined;
13993
+ const hubObligation = !!this.turnReplyGuard?.snapshot()?.target?.hubRoute;
13899
13994
  const replyAttempt = TURN_OUTBOUND_TOOLS.has(tool) && (!sourceSession || sourceSession === this.name)
13900
- ? this.turnReplyGuard.beginToolAttempt(tool === "reply", TURN_COMPLETION_TOOLS.has(tool))
13995
+ ? this.turnReplyGuard.beginToolAttempt(!hubObligation && tool === "reply", !hubObligation && TURN_COMPLETION_TOOLS.has(tool))
13901
13996
  : null;
13902
13997
  // For now, log and respond. Full adapter routing will be wired in fleet manager.
13903
13998
  const respond = (result, error, errorCode) => {