@songsid/agend 2.4.0-beta.27 → 2.4.0-beta.28

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 (141) hide show
  1. package/dist/agent-cli-instructions.md +2 -1
  2. package/dist/agent-cli.js +6 -0
  3. package/dist/agent-cli.js.map +1 -1
  4. package/dist/build-provenance.json +1 -1
  5. package/dist/channel/mcp-tools.js +1 -1
  6. package/dist/channel/mcp-tools.js.map +1 -1
  7. package/dist/claude-turn-boundaries.d.ts +15 -0
  8. package/dist/claude-turn-boundaries.js +88 -0
  9. package/dist/claude-turn-boundaries.js.map +1 -0
  10. package/dist/contact-auth-service.js +3 -0
  11. package/dist/contact-auth-service.js.map +1 -1
  12. package/dist/contact-auth-store.d.ts +16 -0
  13. package/dist/contact-auth-store.js +61 -1
  14. package/dist/contact-auth-store.js.map +1 -1
  15. package/dist/daemon.d.ts +12 -1
  16. package/dist/daemon.js +130 -19
  17. package/dist/daemon.js.map +1 -1
  18. package/dist/delivery-outbox.d.ts +38 -0
  19. package/dist/delivery-outbox.js +81 -1
  20. package/dist/delivery-outbox.js.map +1 -1
  21. package/dist/fleet-manager.d.ts +17 -1
  22. package/dist/fleet-manager.js +239 -16
  23. package/dist/fleet-manager.js.map +1 -1
  24. package/dist/general-knowledge/skills/concepts/SKILL.md +5 -0
  25. package/dist/general-knowledge/skills/task-board/SKILL.md +14 -0
  26. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +1 -1
  27. package/dist/hub/group-policy/resources.d.ts +1 -1
  28. package/dist/hub/roles/clock.d.ts +1 -1
  29. package/dist/hub/roles/clock.js +3 -2
  30. package/dist/hub/roles/clock.js.map +1 -1
  31. package/dist/hub/roles/read.d.ts +2 -0
  32. package/dist/hub/roles/read.js +15 -6
  33. package/dist/hub/roles/read.js.map +1 -1
  34. package/dist/hub/settings-directory-decision.js +11 -5
  35. package/dist/hub/settings-directory-decision.js.map +1 -1
  36. package/dist/hub/settings-member-address-decision.js +1 -1
  37. package/dist/hub/settings-member-address-decision.js.map +1 -1
  38. package/dist/hub/store.d.ts +4 -0
  39. package/dist/hub/store.js +19 -4
  40. package/dist/hub/store.js.map +1 -1
  41. package/dist/locale.js +17 -1
  42. package/dist/locale.js.map +1 -1
  43. package/dist/outbound-schemas.d.ts +3 -0
  44. package/dist/outbound-schemas.js +4 -2
  45. package/dist/outbound-schemas.js.map +1 -1
  46. package/dist/request-context-activation.js +14 -3
  47. package/dist/request-context-activation.js.map +1 -1
  48. package/dist/request-context-call.d.ts +1 -0
  49. package/dist/request-context-call.js.map +1 -1
  50. package/dist/request-context-compatibility.js +10 -2
  51. package/dist/request-context-compatibility.js.map +1 -1
  52. package/dist/request-context-control-api.d.ts +18 -0
  53. package/dist/request-context-control-api.js +4 -2
  54. package/dist/request-context-control-api.js.map +1 -1
  55. package/dist/request-context-drain-projection.d.ts +8 -0
  56. package/dist/request-context-drain-projection.js +40 -0
  57. package/dist/request-context-drain-projection.js.map +1 -0
  58. package/dist/request-context-drain.d.ts +9 -0
  59. package/dist/request-context-drain.js +63 -4
  60. package/dist/request-context-drain.js.map +1 -1
  61. package/dist/request-context-human.d.ts +6 -0
  62. package/dist/request-context-human.js +24 -1
  63. package/dist/request-context-human.js.map +1 -1
  64. package/dist/request-context-migration.d.ts +11 -0
  65. package/dist/request-context-migration.js +16 -3
  66. package/dist/request-context-migration.js.map +1 -1
  67. package/dist/request-context-reply-pending.d.ts +16 -0
  68. package/dist/request-context-reply-pending.js +77 -0
  69. package/dist/request-context-reply-pending.js.map +1 -0
  70. package/dist/request-context-resolution.d.ts +35 -0
  71. package/dist/request-context-resolution.js +86 -0
  72. package/dist/request-context-resolution.js.map +1 -0
  73. package/dist/request-context-retirement.d.ts +2 -0
  74. package/dist/request-context-retirement.js.map +1 -1
  75. package/dist/runtime-build-info.js +1 -1
  76. package/dist/runtime-build-info.js.map +1 -1
  77. package/dist/scheduler/db.js +9 -0
  78. package/dist/scheduler/db.js.map +1 -1
  79. package/dist/scheduler/task-board-text.d.ts +3 -6
  80. package/dist/scheduler/task-board-text.js +15 -10
  81. package/dist/scheduler/task-board-text.js.map +1 -1
  82. package/dist/scheduler/task-board-unread.d.ts +90 -0
  83. package/dist/scheduler/task-board-unread.js +192 -0
  84. package/dist/scheduler/task-board-unread.js.map +1 -0
  85. package/dist/scheduler/task-board.d.ts +324 -6
  86. package/dist/scheduler/task-board.js +786 -47
  87. package/dist/scheduler/task-board.js.map +1 -1
  88. package/dist/settings-effect.js +17 -2
  89. package/dist/settings-effect.js.map +1 -1
  90. package/dist/task-board-tool.js +24 -3
  91. package/dist/task-board-tool.js.map +1 -1
  92. package/dist/task-board-waker.d.ts +53 -2
  93. package/dist/task-board-waker.js +183 -12
  94. package/dist/task-board-waker.js.map +1 -1
  95. package/dist/transcript-monitor.d.ts +6 -1
  96. package/dist/transcript-monitor.js +59 -4
  97. package/dist/transcript-monitor.js.map +1 -1
  98. package/dist/transcript-turns.d.ts +3 -0
  99. package/dist/transcript-turns.js +5 -0
  100. package/dist/transcript-turns.js.map +1 -1
  101. package/dist/ui/fleet-task-activity.js +164 -24
  102. package/dist/ui/fleet-task-card.js +77 -13
  103. package/dist/ui/fleet-task-common.js +14 -0
  104. package/dist/ui/fleet-task-flow.js +353 -0
  105. package/dist/ui/fleet-task-md.js +1 -1
  106. package/dist/ui/fleet-task-run.js +98 -22
  107. package/dist/ui/fleet-task-thread.js +245 -0
  108. package/dist/ui/fleet-task-unread.js +100 -0
  109. package/dist/ui/fleet-task-view.js +6 -5
  110. package/dist/ui/fleet-task-wake.js +140 -0
  111. package/dist/ui/fleet-tasks.js +13 -6
  112. package/dist/ui/panel-windows-cli.js +2 -2
  113. package/dist/ui/request-context-control.js +51 -13
  114. package/dist/ui/shared/access-overview.css +1 -1
  115. package/dist/ui/shared/app-i18n.js +2 -2
  116. package/dist/ui/shared/app-shell.js +4 -1
  117. package/dist/ui/shared/app-stream.js +3 -1
  118. package/dist/ui/shared/app.css +8 -2
  119. package/dist/ui/shared/app.js +3 -0
  120. package/dist/ui/shared/task-board.css +164 -0
  121. package/dist/ui/shared/ui-icons.js +3 -0
  122. package/dist/ui/task-unread.js +70 -0
  123. package/dist/ui/windows-cli-catalog.js +33 -6
  124. package/dist/update-goback.js +3 -1
  125. package/dist/update-goback.js.map +1 -1
  126. package/dist/web-api.d.ts +45 -1
  127. package/dist/web-api.js +184 -6
  128. package/dist/web-api.js.map +1 -1
  129. package/dist/windows-cli-api.js +4 -2
  130. package/dist/windows-cli-api.js.map +1 -1
  131. package/dist/windows-cli.d.ts +40 -1
  132. package/dist/windows-cli.js +93 -11
  133. package/dist/windows-cli.js.map +1 -1
  134. package/dist/windows-shortcuts.d.ts +3 -22
  135. package/dist/windows-shortcuts.js +5 -45
  136. package/dist/windows-shortcuts.js.map +1 -1
  137. package/dist/workflow-templates/default.md +3 -2
  138. package/dist/wsl-host.d.ts +52 -0
  139. package/dist/wsl-host.js +97 -0
  140. package/dist/wsl-host.js.map +1 -0
  141. package/package.json +1 -1
@@ -1,3 +1,5 @@
1
+ import { cacheRetainedUnavailable } from "./update-retained.js";
2
+ import { projectRequestContextWork } from "./request-context-drain-projection.js";
1
3
  import { createRequire } from "node:module";
2
4
  import { RequestContextController } from "./request-context-controller.js";
3
5
  import { captureRequestContextEnableOffer } from "./request-context-enable-offer.js";
@@ -16,6 +18,7 @@ import { makeRequestDeliveryInputResolver } from "./request-context-delivery-res
16
18
  import { makeRequestHumanInputResolver, requestHumanReplyTarget } from "./request-context-human-resolver.js";
17
19
  import { markRetainedHumanControl, retainedHumanControl } from "./retained-human-control.js";
18
20
  import { requestContextDigest } from "./request-context-store.js";
21
+ import { RETIRABLE_LEGACY_DISPOSITIONS } from "./request-context-migration.js";
19
22
  import { RequestContextBoot, readRequestContextBootState } from "./request-context-boot.js";
20
23
  import { RequestContextPreparedWork } from "./request-context-work.js";
21
24
  import { requestContextSkillText, requestContextSteeringText } from "./request-context-knowledge.js";
@@ -197,7 +200,7 @@ import { processAttachments } from "./channel/attachment-handler.js";
197
200
  import { routeToolCall } from "./channel/tool-router.js";
198
201
  import { Scheduler } from "./scheduler/index.js";
199
202
  import { boardActivity, boardCardLimit, boardCommentWakesOn, boardLeader, boardProgressWakesOn, boardToolAction } from "./task-board-tool.js";
200
- import { TaskBoardWaker } from "./task-board-waker.js";
203
+ import { TaskBoardWaker, cardsOfKey } from "./task-board-waker.js";
201
204
  import { DispatcherLiveness, LIVENESS_STARTUP_GRACE_MS, livenessSettings, questionNotices, turnQuestion } from "./dispatcher-liveness.js";
202
205
  import { TaskBoardError, waitsForPerson, wrapUpGap } from "./scheduler/task-board.js";
203
206
  import { escapeTelegramHtml, scheduleClock, scheduleRetryLabel } from "./scheduler/retry-label.js";
@@ -7593,11 +7596,13 @@ export class FleetManager {
7593
7596
  const row = event.deliveryId ? outbox.get(event.deliveryId) : undefined;
7594
7597
  if (row)
7595
7598
  this.publishTraffic(row);
7599
+ this.noteTaskWakeDelivery(event.deliveryId);
7596
7600
  });
7597
7601
  outbox.on("consumed", (event) => {
7598
7602
  const row = event.deliveryId ? outbox.get(event.deliveryId) : undefined;
7599
7603
  if (row)
7600
7604
  this.publishTraffic(row, "consumed");
7605
+ this.noteTaskWakeDelivery(event.deliveryId);
7601
7606
  });
7602
7607
  outbox.on("generation_recovered", () => this.scheduleDeliveryOutboxPump());
7603
7608
  this.sweepContactAuthorizationOutcomes();
@@ -7950,14 +7955,33 @@ export class FleetManager {
7950
7955
  out.push({ id: "legacy-pending", kind: "legacy", labels: pending.slice(0, 64), action: "inspect" });
7951
7956
  if (inflight.length)
7952
7957
  out.push({ id: "legacy-inflight", kind: "legacy", labels: inflight.slice(0, 64) });
7953
- if (unsettled.length)
7954
- out.push({ id: "legacy-unsettled", kind: "legacy", labels: unsettled.slice(0, 64) });
7958
+ // M-3897: each one an owner can retire (its exact image is readable) gets its own blocker and Retire; an oversized one
7959
+ // that cannot be bound to an image stays named, with no action.
7960
+ const retirable = new Set(shadow.tickets.filter(row => unsettled.includes(row.id) && row.sha256).map(row => row.id));
7961
+ for (const id of unsettled.filter(id => retirable.has(id)).slice(0, 32))
7962
+ out.push({ id: `legacy-retire:${id}`, kind: "legacy", labels: [id], action: "retire" });
7963
+ const unbound = unsettled.filter(id => !retirable.has(id));
7964
+ if (unbound.length)
7965
+ out.push({ id: "legacy-unsettled", kind: "legacy", labels: unbound.slice(0, 64) });
7955
7966
  const rest = shadow.blockers.map(row => row.id).filter(id => !named.has(id));
7956
7967
  if (rest.length || !shadow.complete && !named.size)
7957
7968
  out.push({ id: "legacy", kind: "legacy", labels: rest.slice(0, 64), action: "inspect" });
7958
7969
  const inventory = box.requestContextControlInventory(), legacy = inventory.deliveries.filter(row => !row.root);
7959
- if (legacy.length)
7960
- out.push({ id: "legacy-deliveries", kind: "legacy", labels: legacy.map(row => `${label(row.source)} → ${label(row.target)}`).slice(0, 64) });
7970
+ // M-3897: an earlier delivery still queued (or waiting to retry) can be withdrawn by its exact image; one being sent
7971
+ // waits for its own outcome; an uncertain one never changes by itself and is named as such (no guess, no relabel).
7972
+ const pair = (row) => `${label(row.source)} → ${label(row.target)}`;
7973
+ for (const row of legacy.filter(row => ["queued", "retry_wait"].includes(row.state)).slice(0, 32))
7974
+ out.push({ id: `legacy-withdraw:${row.id}`, kind: "legacy", labels: [pair(row)], action: "withdraw" });
7975
+ const sending = legacy.filter(row => ["delivering", "submission_started"].includes(row.state));
7976
+ if (sending.length)
7977
+ out.push({ id: "legacy-deliveries", kind: "legacy", labels: sending.map(pair).slice(0, 64) });
7978
+ const needsTicketRetirement = new Set(shadow.tickets.filter(row => ["legacy-unconfirmed", "missing-receipt", "malformed"].includes(row.disposition)).map(row => `contact:${row.id}`));
7979
+ for (const row of legacy.filter(row => row.state === "uncertain")) {
7980
+ const delivery = box.get(row.id);
7981
+ if (!delivery || needsTicketRetirement.has(delivery.sourceKey))
7982
+ continue;
7983
+ out.push({ id: `legacy-uncertain:${row.id}:${box.requestContextLegacyAcknowledgementImage(row.id)}`, kind: "legacy", labels: [`${label(row.source)} → ${label(row.target)}`], action: "acknowledge" });
7984
+ }
7961
7985
  const busy = [...this.daemons].filter(([name, daemon]) => { const row = daemon.requestContextLaunchObservation(); return row.observation.processStatus !== "running" || row.observation.executionState !== "idle" || row.pendingCalls || row.responseWaiters || row.queuedInputs || row.transcriptOpen || row.starting || row.stopping || this.requestContextPendingWork.count(name); }).map(([name]) => name);
7962
7986
  for (const row of WindowsAgents.requestContextOwnersOnDisk(this.dataDir)) {
7963
7987
  const daemon = row.instance ? this.daemons.get(row.instance) : undefined;
@@ -7984,12 +8008,34 @@ export class FleetManager {
7984
8008
  out.push({ id: `ticket:${row.id}`, kind: "tickets", labels: [`${label(row.source)} → ${label(row.target)}`], action: "decline" });
7985
8009
  for (const row of inventory.deliveries)
7986
8010
  out.push({ id: `delivery:${row.id}`, kind: "work", labels: [`${label(row.source)} → ${label(row.target)}`], action: ["queued", "retry_wait"].includes(row.state) ? "withdraw" : "inspect" });
7987
- if (!out.length && this.requestContextModes)
7988
- for (const root of box.requestContextInstallation().drainRoots())
7989
- if (this.requestContextModes.drain.inspectWork(root).blockers.length) {
7990
- out.push({ id: `work:${root}`, kind: "work", labels: [], action: "inspect" });
7991
- break;
8011
+ if (this.requestContextModes)
8012
+ for (const root of box.requestContextInstallation().drainRoots()) {
8013
+ const view = this.requestContextModes.drain.inspectWork(root), projected = projectRequestContextWork(view.blockers);
8014
+ const recoveryIds = new Set(inventory.recoveries.filter(row => row.root === root).map(row => `recovery:${requestContextDigest(row.pointer)}`));
8015
+ if (!projected.families.length) {
8016
+ if (view.blockers.some(value => value !== "recovery-pointer"))
8017
+ for (const row of out)
8018
+ if (recoveryIds.has(row.id))
8019
+ row.action = "inspect";
8020
+ continue;
7992
8021
  }
8022
+ // One root action names the whole stop. Do not show a second pointer-only
8023
+ // action that could stop the owner and then fail on its human receipt.
8024
+ for (let index = out.length - 1; index >= 0; index--)
8025
+ if (recoveryIds.has(out[index].id))
8026
+ out.splice(index, 1);
8027
+ const context = box.requestContext(root), names = new Set(context ? [context.source.instance] : []);
8028
+ for (const row of inventory.recoveries)
8029
+ if (row.root === root)
8030
+ names.add(row.instance);
8031
+ for (const [name, daemon] of this.daemons)
8032
+ if (daemon.requestContextTurnSnapshot()?.context.ref.rootContextId === root)
8033
+ names.add(name);
8034
+ const receipts = box.requestContextUncertainHumanImages(root), pointers = inventory.recoveries.filter(row => row.root === root).map(row => row.pointer);
8035
+ const sha = requestContextDigest({ root, blockers: view.blockers, revisions: [...view.revisions], receipts, pointers });
8036
+ out.push({ id: `work:${root}:${sha}`, kind: "work", labels: [...names].map(label).slice(0, 64), agents: [...names].map(id => ({ id, label: label(id) })).slice(0, 64),
8037
+ families: projected.families, unknownEnd: projected.unknownEnd, action: projected.stoppable ? "stop-work" : "inspect" });
8038
+ }
7993
8039
  }
7994
8040
  return [...out, ...this.requestContextCutoverErrors].slice(0, 128);
7995
8041
  }
@@ -8163,8 +8209,58 @@ export class FleetManager {
8163
8209
  }, 500);
8164
8210
  this.requestContextDrainTimer.unref?.();
8165
8211
  }
8212
+ /**
8213
+ * M-3897 (Sentinel's settlement split): before the first On, an owner settles an earlier ticket or delivery nothing else
8214
+ * can. Retire: a ticket the shadow names retirable (no readable delivery record), bound to the exact image it shows;
8215
+ * the retirement is appended and nothing is relabelled. Withdraw: an earlier delivery still queued or waiting to retry,
8216
+ * by its exact image (withdrawRequestContextDelivery's own CAS). Never after activation: those blockers are the drain's.
8217
+ */
8218
+ resolveLegacyBlocker(blocker, actor, current) {
8219
+ const box = this.deliveryOutbox;
8220
+ if (!box || box.requestContextInstallation().read() !== null || !current())
8221
+ throw Error("stale");
8222
+ // Sentinel's Go back contract: the same home-update exclusion the first On and Stop hold, so a retirement or a
8223
+ // withdrawal can never land between Go back's check and its restore.
8224
+ const update = this.requestContextActivationLease();
8225
+ if (!update)
8226
+ throw Error("update-lock");
8227
+ try {
8228
+ this.resolveLegacyBlockerHeld(blocker, actor, () => current() && update.current());
8229
+ }
8230
+ finally {
8231
+ update.release();
8232
+ }
8233
+ }
8234
+ resolveLegacyBlockerHeld(blocker, actor, current) {
8235
+ const box = this.deliveryOutbox;
8236
+ if (blocker.id.startsWith("legacy-retire:")) {
8237
+ if (!actor.person)
8238
+ throw Error("owner-required");
8239
+ const id = blocker.id.slice("legacy-retire:".length), entry = this.requestContextShadow().tickets.find(row => row.id === id);
8240
+ if (!entry?.sha256 || !RETIRABLE_LEGACY_DISPOSITIONS.includes(entry.disposition))
8241
+ throw Error("stale");
8242
+ const person = actor.person, image = entry.sha256, disposition = entry.disposition;
8243
+ actor.execution.mutate(() => box.contactAuthorizations.retireLegacy(id, image, disposition, person, current, (deliveryId, by) => box.acknowledge(deliveryId, by)));
8244
+ return;
8245
+ }
8246
+ const id = blocker.id.slice("legacy-withdraw:".length), row = box.get(id);
8247
+ if (!row || !box.requestContextControlInventory().deliveries.some(value => value.id === id && !value.root && ["queued", "retry_wait"].includes(value.state)))
8248
+ throw Error("stale");
8249
+ actor.execution.mutate(() => box.withdrawRequestContextDelivery(id, requestContextDigest(row), current));
8250
+ }
8166
8251
  async resolveRequestContextBlocker(blocker, actor, current) {
8252
+ if (blocker.id.startsWith("legacy-retire:") || blocker.id.startsWith("legacy-withdraw:")) {
8253
+ this.resolveLegacyBlocker(blocker, actor, current);
8254
+ return;
8255
+ }
8167
8256
  const box = this.deliveryOutbox, modes = this.requestContextModes, state = box?.requestContextInstallation().read();
8257
+ if (box && !state && blocker.id.startsWith("legacy-uncertain:") && blocker.action === "acknowledge") {
8258
+ const match = /^legacy-uncertain:([A-Za-z0-9._:-]{1,128}):([a-f0-9]{64})$/.exec(blocker.id);
8259
+ if (!match || !actor.verified || !actor.execution || !current())
8260
+ throw Error("stale");
8261
+ actor.execution.mutate(() => box.acknowledgeRequestContextLegacyDelivery(match[1], match[2], actor.binding, current));
8262
+ return;
8263
+ }
8168
8264
  if (!box || !modes?.current() || state?.mode !== "draining" || !current())
8169
8265
  throw Error("stale");
8170
8266
  const inventory = box.requestContextControlInventory(box.requestContextInstallation().drainRoots());
@@ -8188,40 +8284,112 @@ export class FleetManager {
8188
8284
  actor.execution.mutate(() => box.closeRequestContextReturn(id, requestContextDigest(row), getLocale() === "zh-TW" ? "擁有者已結束這次等候;不再等候這則回覆。" : "The owner stopped waiting for this reply.", () => current() && this.contactGeneration(row.requester.instance) === row.requester.incarnation));
8189
8285
  this.scheduleDeliveryOutboxPump();
8190
8286
  }
8287
+ else if (blocker.id.startsWith("work:")) {
8288
+ const match = /^work:([a-f0-9-]{36}):([a-f0-9]{64})$/.exec(blocker.id);
8289
+ if (!match || blocker.action !== "stop-work")
8290
+ throw Error("stale");
8291
+ const update = this.requestContextActivationLease();
8292
+ if (!update)
8293
+ throw Error("unavailable");
8294
+ try {
8295
+ const decisionCurrent = () => current() && update.current();
8296
+ if (!decisionCurrent())
8297
+ throw Error("stale");
8298
+ const stopOffer = captureRequestContextEnableOffer(this.dataDir);
8299
+ const root = match[1], view = modes.drain.inspectWork(root), receipts = box.requestContextUncertainHumanImages(root), pointers = inventory.recoveries.filter(row => row.root === root).map(row => row.pointer);
8300
+ if (!projectRequestContextWork(view.blockers).stoppable || requestContextDigest({ root, blockers: view.blockers, revisions: [...view.revisions], receipts, pointers }) !== match[2])
8301
+ throw Error("stale");
8302
+ const saved = modes.drain.retainedEpoch(root);
8303
+ // A prior crash can leave the root fence durable. Rotate its epoch under
8304
+ // this owned coordinator before re-running the positive stop proof.
8305
+ let epoch;
8306
+ actor.execution.mutate(() => { epoch = saved ? modes.drain.resume(root, saved) : modes.drain.fence(root); });
8307
+ const retired = await this.stopRequestContextWork(root, actor, decisionCurrent);
8308
+ actor.execution.mutate(() => box.resolveRequestContextStoppedWork(root, epoch, { ownerBinding: actor.binding, blockerSha256: match[2], receipts, pointers }, modes.drain, retired, decisionCurrent));
8309
+ this.cacheStoppedWorkGoBack(stopOffer.invalidates);
8310
+ }
8311
+ finally {
8312
+ update.release();
8313
+ }
8314
+ }
8191
8315
  else if (blocker.id.startsWith("recovery:")) {
8192
8316
  const row = inventory.recoveries.find(value => `recovery:${requestContextDigest(value.pointer)}` === blocker.id);
8193
8317
  if (!row)
8194
8318
  throw Error("stale");
8195
- await this.stopRequestContextWork(row.root, actor, current);
8196
- actor.execution.mutate(() => box.requestContextRecovery.clear(row.pointer, () => current() && modes.drain.inspectWork(row.root).blockers.every(value => value === "recovery-pointer")));
8319
+ const update = this.requestContextActivationLease();
8320
+ if (!update)
8321
+ throw Error("unavailable");
8322
+ try {
8323
+ const decisionCurrent = () => current() && update.current();
8324
+ if (!decisionCurrent())
8325
+ throw Error("stale");
8326
+ const stopOffer = captureRequestContextEnableOffer(this.dataDir);
8327
+ const saved = modes.drain.retainedEpoch(row.root);
8328
+ let epoch;
8329
+ actor.execution.mutate(() => { epoch = saved ? modes.drain.resume(row.root, saved) : modes.drain.fence(row.root); });
8330
+ const retired = await this.stopRequestContextWork(row.root, actor, decisionCurrent);
8331
+ actor.execution.mutate(() => box.resolveRequestContextStoppedWork(row.root, epoch, { ownerBinding: actor.binding, blockerSha256: requestContextDigest(blocker), receipts: [], pointers: [row.pointer] }, modes.drain, retired, decisionCurrent));
8332
+ this.cacheStoppedWorkGoBack(stopOffer.invalidates);
8333
+ }
8334
+ finally {
8335
+ update.release();
8336
+ }
8197
8337
  }
8198
8338
  else
8199
8339
  throw Error("invalid-request");
8200
8340
  this.scheduleRequestContextDrain();
8201
8341
  }
8342
+ /** Projection only, after the authoritative root COMMIT. A crash here cannot permit a restore. */
8343
+ cacheStoppedWorkGoBack(attempts) {
8344
+ for (const id of attempts)
8345
+ try {
8346
+ const cached = cacheRetainedUnavailable(this.dataDir, id, t("request_context_control.goBackStopped"));
8347
+ if (!cached.ok)
8348
+ this.logger.warn({ reason: cached.reason }, "Could not refresh stopped-work Go back availability");
8349
+ }
8350
+ catch (err) {
8351
+ this.logger.warn({ err }, "Could not refresh stopped-work Go back availability");
8352
+ }
8353
+ }
8202
8354
  async stopRequestContextWork(root, actor, current) {
8203
8355
  const modes = this.requestContextModes;
8204
8356
  if (!modes?.current() || !current())
8205
8357
  throw Error("stale");
8206
- const nativeStops = this.fleetWindowsRuntime?.requestContextStops(root) ?? [];
8358
+ const nativeStops = this.fleetWindowsRuntime?.requestContextStops(root) ?? [], owners = [];
8207
8359
  for (const stop of nativeStops) {
8208
8360
  if (!current())
8209
8361
  throw Error("stale");
8210
8362
  actor.execution.mutate(() => stop.stop(current));
8211
8363
  }
8212
8364
  for (const [name, daemon] of [...this.daemons]) {
8213
- if (daemon.requestContextTurnSnapshot()?.context.ref.rootContextId !== root)
8365
+ const snapshot = daemon.requestContextTurnSnapshot();
8366
+ if (snapshot?.context.ref.rootContextId !== root)
8214
8367
  continue;
8368
+ const owner = daemon.captureRequestContextOwner();
8369
+ if (!owner || requestContextDigest(owner) !== requestContextDigest(snapshot.owner))
8370
+ throw Error("Request root owner changed");
8215
8371
  const retirement = await daemon.captureRequestContextRetirement();
8216
8372
  if (!current() || this.daemons.get(name) !== daemon)
8217
8373
  throw Error("stale");
8218
- await actor.execution.stopTarget(name, advance => this.lifecycle.stopIfCurrent(name, daemon, advance));
8374
+ if (retirement.daemonBootId !== owner.daemonBootId || retirement.spawnGeneration !== owner.spawnGeneration || retirement.launchFenceEpoch !== owner.launchFenceEpoch)
8375
+ throw Error("Request launch owner changed");
8376
+ const sameTurn = () => daemon.requestContextTurnSnapshot()?.token === snapshot.token;
8377
+ if (!sameTurn())
8378
+ throw Error("Request root turn changed");
8379
+ await actor.execution.stopTarget(name, advance => this.lifecycle.stopIfCurrent(name, daemon, (before, after) => {
8380
+ advance?.(before, after);
8381
+ if (!current() || !sameTurn())
8382
+ throw Error("Request root turn changed");
8383
+ }));
8219
8384
  if (!current() || !await retirement.retired())
8220
8385
  throw Error("unavailable");
8221
8386
  // The future-start factory keeps the stored work/context; it removes only this positively retired live owner.
8222
8387
  if (!this.requestContextRetireOwner)
8223
8388
  throw Error("unavailable");
8224
8389
  await this.requestContextRetireOwner(name, daemon, retirement.retired);
8390
+ // C's identity has been disposed. Only the pre-stop physical receipt can
8391
+ // keep its own positive retirement current; a replacement is never adopted.
8392
+ owners.push(() => !this.daemons.has(name) && retirement.retiredCurrent());
8225
8393
  }
8226
8394
  // The wait bounds the HTTP action; only the owned run's positive completion can clear its pointer.
8227
8395
  const until = performance.now() + 30_000;
@@ -8232,6 +8400,12 @@ export class FleetManager {
8232
8400
  throw Error("unavailable");
8233
8401
  await new Promise(resolve => setTimeout(resolve, 25));
8234
8402
  }
8403
+ return () => { try {
8404
+ return current() && nativeStops.every(stop => stop.retired()) && owners.every(check => check());
8405
+ }
8406
+ catch {
8407
+ return false;
8408
+ } };
8235
8409
  }
8236
8410
  async requestContextOwnerStopped(name, daemon, retired) {
8237
8411
  if (!this.requestContextRetireOwner)
@@ -30409,6 +30583,8 @@ export class FleetManager {
30409
30583
  // An agent's words reach another instance by the board (a comment, an @mention, a follower's progress) only as its
30410
30584
  // contact rules allow, as a peer message does (M-3160 / M-3384): asked as it writes and again as the notice goes out.
30411
30585
  db.board.setContactGate((source, target) => this.taskBoardMayReach(source, target));
30586
+ // A card's `handedAt` counts a hand-over only while its notice reached the instance (or the outbox has no word of it).
30587
+ db.board.setNoticeProgress((keys) => this.taskWakeProgress(keys));
30412
30588
  const waker = this.taskBoardWaker = new TaskBoardWaker({
30413
30589
  deliver: (instance, message, key, origins) => this.admitTaskBoardNotice(instance, message, key, origins),
30414
30590
  mayReach: (source, target) => this.taskBoardMayReach(source, target),
@@ -30419,7 +30595,18 @@ export class FleetManager {
30419
30595
  const outbox = this.deliveryOutbox;
30420
30596
  return outbox?.isOpen ? outbox.withdrawWaitingNotices(prefix, stale, reason).length : 0;
30421
30597
  },
30598
+ noticeState: (key) => (this.deliveryOutbox?.isOpen ? this.deliveryOutbox.noticeStateByKey(key) : null),
30422
30599
  changedAt: (uuid) => db.board.lastChangeAt(uuid),
30600
+ // The comment status: what became of a card's news for an instance — handed to delivery (its key), or not sent — is kept with
30601
+ // the comments it carried, and the open card pages read it again (the card numbers only: never who or why).
30602
+ // A card's news that handed it to the instance to start is kept the same way (the handoffs under its main task's activity, "Handoffs").
30603
+ settled: ({ uuid, instance, kind, key, skip, replaces }) => {
30604
+ const board = db.board;
30605
+ const touched = kind === "handoff"
30606
+ ? (key ? board.handoffHanded(uuid, instance, key, replaces) : skip ? board.handoffDropped(uuid, instance, skip, replaces) : [])
30607
+ : (key ? board.wakeHanded(uuid, instance, key, replaces) : skip ? board.wakeDropped(uuid, instance, skip, replaces) : []);
30608
+ this.emitTaskWakes(touched);
30609
+ },
30423
30610
  holds: (wake) => db.board.wakeHolds(wake),
30424
30611
  card: (uuid) => db.board.findCard(uuid),
30425
30612
  // #2352: the card's Needs you buttons are in this instance's own channel (it is the card's lane).
@@ -30436,19 +30623,55 @@ export class FleetManager {
30436
30623
  },
30437
30624
  log: (level, message, extra) => this.logger[level](extra ?? {}, message),
30438
30625
  });
30439
- db.board.onChange(({ rev, ids, projects, wakes, changed }) => {
30626
+ db.board.onChange(({ rev, ids, projects, wakes, changed, recalled }) => {
30440
30627
  // Refresh both old and new owners on reassignment; wakes are not an ownership index.
30441
30628
  if (ids.length)
30442
30629
  for (const name of this.daemons.keys())
30443
30630
  this.observeWorkingState(name, "tasks");
30444
30631
  this.emitSseEvent("tasks", { rev, ids, projects });
30445
30632
  waker.changed(changed);
30633
+ // A comment edited or deleted: a notice still waiting that quotes it is withdrawn and told anew with what stands (the waker).
30634
+ if (recalled?.length)
30635
+ waker.recalled(recalled);
30446
30636
  waker.note(this.withWriterOrigins(wakes));
30447
30637
  // step 3: cards waiting for the person are Needs you items; #2355 review: a project's lead routes them too.
30448
30638
  if (ids.length || projects)
30449
30639
  this.needsYou?.poke();
30450
30640
  });
30451
30641
  }
30642
+ /** A card page showing a comment's status reads it again: the card numbers whose comments moved (the page asks for the rest). */
30643
+ emitTaskWakes(ids) {
30644
+ if (ids.length)
30645
+ this.emitSseEvent("task_wakes", { ids: [...ids] });
30646
+ }
30647
+ /** A delivery changed (state or consumed): when it is a task board notice, the cards it names have comments whose status moved. */
30648
+ noteTaskWakeDelivery(deliveryId) {
30649
+ const outbox = this.deliveryOutbox;
30650
+ const board = this.scheduler?.db.board;
30651
+ if (!deliveryId || !outbox || !board)
30652
+ return;
30653
+ const key = outbox.get(deliveryId)?.sourceKey ?? "";
30654
+ const uuids = cardsOfKey(key);
30655
+ if (!uuids.length)
30656
+ return;
30657
+ // The cards the notice names, and their main tasks: a main task's page lists the handoffs of its sub tasks.
30658
+ const codes = new Set();
30659
+ for (const u of uuids) {
30660
+ const card = board.findCard(u);
30661
+ if (!card)
30662
+ continue;
30663
+ codes.add(card.code);
30664
+ const main = card.parent ? board.findCard(card.parent) : undefined;
30665
+ if (main)
30666
+ codes.add(main.code);
30667
+ }
30668
+ this.emitTaskWakes([...codes]);
30669
+ }
30670
+ /** How far the notices carrying comments (the task board's) got in the delivery outbox, by their keys (the card page's comment status). */
30671
+ taskWakeProgress(keys) {
30672
+ const outbox = this.deliveryOutbox;
30673
+ return outbox?.isOpen ? outbox.noticeProgress(keys) : new Map();
30674
+ }
30452
30675
  /**
30453
30676
  * A task board notice, as AgEnD's own: through the delivery outbox, held until delivered. `origins`: the writers whose
30454
30677
  * own words it carries (a comment, a mention, a follower's progress) with their contact origin as they wrote; the