@songsid/agend 2.3.2-beta.9 → 2.3.3-beta.1

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 (285) hide show
  1. package/README.md +6 -0
  2. package/README.zh-TW.md +6 -0
  3. package/dist/agent-cli-instructions.md +2 -2
  4. package/dist/agent-cli.js +48 -0
  5. package/dist/agent-cli.js.map +1 -1
  6. package/dist/agent-endpoint.js +6 -0
  7. package/dist/agent-endpoint.js.map +1 -1
  8. package/dist/agent-whats-new.d.ts +21 -0
  9. package/dist/agent-whats-new.js +53 -21
  10. package/dist/agent-whats-new.js.map +1 -1
  11. package/dist/auth-api.js +2 -0
  12. package/dist/auth-api.js.map +1 -1
  13. package/dist/backend/claude-code.d.ts +13 -1
  14. package/dist/backend/claude-code.js +43 -2
  15. package/dist/backend/claude-code.js.map +1 -1
  16. package/dist/backend/codex-session-lookup.d.ts +15 -0
  17. package/dist/backend/codex-session-lookup.js +58 -0
  18. package/dist/backend/codex-session-lookup.js.map +1 -1
  19. package/dist/backend/codex.js +15 -4
  20. package/dist/backend/codex.js.map +1 -1
  21. package/dist/backend/kiro-classic-archive.d.ts +57 -0
  22. package/dist/backend/kiro-classic-archive.js +622 -0
  23. package/dist/backend/kiro-classic-archive.js.map +1 -0
  24. package/dist/backend/kiro-classic-links.d.ts +24 -0
  25. package/dist/backend/kiro-classic-links.js +135 -0
  26. package/dist/backend/kiro-classic-links.js.map +1 -0
  27. package/dist/backend/kiro-identity.d.ts +100 -1
  28. package/dist/backend/kiro-identity.js +262 -31
  29. package/dist/backend/kiro-identity.js.map +1 -1
  30. package/dist/backend/kiro-migration-verify.d.ts +10 -0
  31. package/dist/backend/kiro-migration-verify.js +52 -0
  32. package/dist/backend/kiro-migration-verify.js.map +1 -0
  33. package/dist/backend/kiro-reconcile-store.d.ts +27 -0
  34. package/dist/backend/kiro-reconcile-store.js +351 -0
  35. package/dist/backend/kiro-reconcile-store.js.map +1 -0
  36. package/dist/backend/kiro-v2-store-worker.js +35 -1
  37. package/dist/backend/kiro-v2-store-worker.js.map +1 -1
  38. package/dist/backend/kiro-v2-store.d.ts +31 -1
  39. package/dist/backend/kiro-v2-store.js +22 -12
  40. package/dist/backend/kiro-v2-store.js.map +1 -1
  41. package/dist/backend/kiro.d.ts +124 -6
  42. package/dist/backend/kiro.js +553 -39
  43. package/dist/backend/kiro.js.map +1 -1
  44. package/dist/backend/types.d.ts +109 -4
  45. package/dist/backend/types.js +9 -0
  46. package/dist/backend/types.js.map +1 -1
  47. package/dist/cache-service.d.ts +13 -1
  48. package/dist/cache-service.js +45 -2
  49. package/dist/cache-service.js.map +1 -1
  50. package/dist/channel/ipc-timeouts.js +3 -0
  51. package/dist/channel/ipc-timeouts.js.map +1 -1
  52. package/dist/channel/mcp-tools.js +40 -5
  53. package/dist/channel/mcp-tools.js.map +1 -1
  54. package/dist/channel/tool-router.js +2 -1
  55. package/dist/channel/tool-router.js.map +1 -1
  56. package/dist/classic-channel-manager.d.ts +6 -0
  57. package/dist/classic-channel-manager.js +25 -0
  58. package/dist/classic-channel-manager.js.map +1 -1
  59. package/dist/cli.js +52 -6
  60. package/dist/cli.js.map +1 -1
  61. package/dist/config-validator.d.ts +7 -1
  62. package/dist/config-validator.js +20 -9
  63. package/dist/config-validator.js.map +1 -1
  64. package/dist/config.js +2 -0
  65. package/dist/config.js.map +1 -1
  66. package/dist/cross-instance-envelope.d.ts +10 -5
  67. package/dist/cross-instance-envelope.js +20 -17
  68. package/dist/cross-instance-envelope.js.map +1 -1
  69. package/dist/daemon.d.ts +125 -63
  70. package/dist/daemon.js +694 -330
  71. package/dist/daemon.js.map +1 -1
  72. package/dist/dashboard-permissions.d.ts +15 -4
  73. package/dist/dashboard-permissions.js +49 -23
  74. package/dist/dashboard-permissions.js.map +1 -1
  75. package/dist/delivery-outbox.d.ts +27 -22
  76. package/dist/delivery-outbox.js +109 -161
  77. package/dist/delivery-outbox.js.map +1 -1
  78. package/dist/delivery-outbox.test.js +10 -25
  79. package/dist/delivery-outbox.test.js.map +1 -1
  80. package/dist/doctor.js +2 -1
  81. package/dist/doctor.js.map +1 -1
  82. package/dist/fleet-control-audit.d.ts +1 -1
  83. package/dist/fleet-control-audit.js +3 -0
  84. package/dist/fleet-control-audit.js.map +1 -1
  85. package/dist/fleet-manager.d.ts +94 -15
  86. package/dist/fleet-manager.js +597 -133
  87. package/dist/fleet-manager.js.map +1 -1
  88. package/dist/forged-envelope-scan.d.ts +9 -0
  89. package/dist/forged-envelope-scan.js +30 -5
  90. package/dist/forged-envelope-scan.js.map +1 -1
  91. package/dist/general-instance.d.ts +24 -0
  92. package/dist/general-instance.js +53 -0
  93. package/dist/general-instance.js.map +1 -1
  94. package/dist/general-knowledge/skills/delegation-playbook/SKILL.md +1 -1
  95. package/dist/general-knowledge/skills/docker-install/SKILL.md +25 -0
  96. package/dist/general-knowledge/skills/fleet-config/SKILL.md +5 -3
  97. package/dist/general-knowledge/skills/fleet-restart/SKILL.md +1 -1
  98. package/dist/general-knowledge/skills/kiro-engine-migration/SKILL.md +34 -0
  99. package/dist/general-knowledge/skills/session-management/SKILL.md +2 -2
  100. package/dist/general-knowledge/skills/tui-effort/SKILL.md +1 -1
  101. package/dist/general-knowledge/skills/web-appearance/SKILL.canvas-worker-off.md +32 -0
  102. package/dist/general-knowledge/skills/web-appearance/SKILL.md +32 -0
  103. package/dist/general-knowledge/skills/web-dashboard/SKILL.canvas-worker-off.md +57 -17
  104. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +57 -17
  105. package/dist/instance-config-impact.js +3 -2
  106. package/dist/instance-config-impact.js.map +1 -1
  107. package/dist/instance-lifecycle.d.ts +4 -0
  108. package/dist/instance-lifecycle.js +28 -5
  109. package/dist/instance-lifecycle.js.map +1 -1
  110. package/dist/instructions.js +6 -7
  111. package/dist/instructions.js.map +1 -1
  112. package/dist/kiro-migrate.d.ts +19 -2
  113. package/dist/kiro-migrate.js +133 -35
  114. package/dist/kiro-migrate.js.map +1 -1
  115. package/dist/kiro-reconcile.d.ts +21 -0
  116. package/dist/kiro-reconcile.js +88 -0
  117. package/dist/kiro-reconcile.js.map +1 -0
  118. package/dist/kiro-session-proof.d.ts +41 -0
  119. package/dist/kiro-session-proof.js +89 -0
  120. package/dist/kiro-session-proof.js.map +1 -0
  121. package/dist/kiro-tui-forensic.d.ts +19 -0
  122. package/dist/kiro-tui-forensic.js +124 -0
  123. package/dist/kiro-tui-forensic.js.map +1 -0
  124. package/dist/locale.js +202 -16
  125. package/dist/locale.js.map +1 -1
  126. package/dist/log-service.js +3 -3
  127. package/dist/log-service.js.map +1 -1
  128. package/dist/needs-you.d.ts +3 -1
  129. package/dist/needs-you.js +4 -2
  130. package/dist/needs-you.js.map +1 -1
  131. package/dist/office-levels.d.ts +64 -0
  132. package/dist/office-levels.js +66 -0
  133. package/dist/office-levels.js.map +1 -0
  134. package/dist/office-share-page.d.ts +3 -1
  135. package/dist/office-share-page.js +8 -3
  136. package/dist/office-share-page.js.map +1 -1
  137. package/dist/office-share-service.d.ts +6 -3
  138. package/dist/office-share-service.js +12 -8
  139. package/dist/office-share-service.js.map +1 -1
  140. package/dist/office-share.d.ts +45 -8
  141. package/dist/office-share.js +75 -15
  142. package/dist/office-share.js.map +1 -1
  143. package/dist/outbound-handlers.js +21 -2
  144. package/dist/outbound-handlers.js.map +1 -1
  145. package/dist/outbound-schemas.d.ts +47 -2
  146. package/dist/outbound-schemas.js +42 -3
  147. package/dist/outbound-schemas.js.map +1 -1
  148. package/dist/public-web-gateway.js +1 -1
  149. package/dist/public-web-gateway.js.map +1 -1
  150. package/dist/quickstart-api.d.ts +39 -1
  151. package/dist/quickstart-api.js +115 -17
  152. package/dist/quickstart-api.js.map +1 -1
  153. package/dist/remote-card-answer.d.ts +83 -0
  154. package/dist/remote-card-answer.js +208 -0
  155. package/dist/remote-card-answer.js.map +1 -0
  156. package/dist/remote-card-prompt.d.ts +38 -0
  157. package/dist/remote-card-prompt.js +86 -0
  158. package/dist/remote-card-prompt.js.map +1 -0
  159. package/dist/scheduler/task-board.d.ts +44 -17
  160. package/dist/scheduler/task-board.js +95 -36
  161. package/dist/scheduler/task-board.js.map +1 -1
  162. package/dist/sd-notify.d.ts +13 -14
  163. package/dist/sd-notify.js +62 -28
  164. package/dist/sd-notify.js.map +1 -1
  165. package/dist/service-installer.d.ts +13 -0
  166. package/dist/service-installer.js +15 -0
  167. package/dist/service-installer.js.map +1 -1
  168. package/dist/service-owner.d.ts +25 -0
  169. package/dist/service-owner.js +43 -2
  170. package/dist/service-owner.js.map +1 -1
  171. package/dist/settings-api.d.ts +2 -1
  172. package/dist/settings-api.js +19 -26
  173. package/dist/settings-api.js.map +1 -1
  174. package/dist/settings-change.js +10 -5
  175. package/dist/settings-change.js.map +1 -1
  176. package/dist/settings-effect.js +7 -6
  177. package/dist/settings-effect.js.map +1 -1
  178. package/dist/settings-instance-patch.js +1 -1
  179. package/dist/settings-instance-patch.js.map +1 -1
  180. package/dist/setup-form.d.ts +2 -2
  181. package/dist/setup-form.js +139 -93
  182. package/dist/setup-form.js.map +1 -1
  183. package/dist/setup-i18n.d.ts +25 -0
  184. package/dist/setup-i18n.js +226 -0
  185. package/dist/setup-i18n.js.map +1 -0
  186. package/dist/task-board-waker.d.ts +40 -1
  187. package/dist/task-board-waker.js +115 -9
  188. package/dist/task-board-waker.js.map +1 -1
  189. package/dist/tmux-control.d.ts +1 -1
  190. package/dist/tmux-control.js +3 -2
  191. package/dist/tmux-control.js.map +1 -1
  192. package/dist/tmux-manager.js +18 -16
  193. package/dist/tmux-manager.js.map +1 -1
  194. package/dist/tmux-read.d.ts +2 -0
  195. package/dist/tmux-read.js +7 -1
  196. package/dist/tmux-read.js.map +1 -1
  197. package/dist/tool-permissions.js +18 -0
  198. package/dist/tool-permissions.js.map +1 -1
  199. package/dist/topic-commands.d.ts +2 -0
  200. package/dist/topic-commands.js +2 -1
  201. package/dist/topic-commands.js.map +1 -1
  202. package/dist/transcript-sources.d.ts +1 -0
  203. package/dist/transcript-sources.js +20 -3
  204. package/dist/transcript-sources.js.map +1 -1
  205. package/dist/types.d.ts +11 -5
  206. package/dist/ui/backend-signin.js +4 -3
  207. package/dist/ui/chat-store.js +3 -2
  208. package/dist/ui/chat-strings.js +2 -2
  209. package/dist/ui/fleet-office-card.js +114 -0
  210. package/dist/ui/fleet-office-editor.js +81 -9
  211. package/dist/ui/fleet-office-layout.js +56 -11
  212. package/dist/ui/fleet-office-levels.js +105 -0
  213. package/dist/ui/fleet-office-model.js +9 -1
  214. package/dist/ui/fleet-office-pack.d.ts +15 -3
  215. package/dist/ui/fleet-office-pack.js +177 -23
  216. package/dist/ui/fleet-office-skin.js +39 -3
  217. package/dist/ui/fleet-office-store.js +74 -3
  218. package/dist/ui/fleet-office-view.js +8 -0
  219. package/dist/ui/fleet-office-zones.js +102 -19
  220. package/dist/ui/fleet-office.js +308 -44
  221. package/dist/ui/fleet-org.js +2 -0
  222. package/dist/ui/fleet-task-card.js +2 -2
  223. package/dist/ui/fleet-task-common.js +30 -7
  224. package/dist/ui/fleet-task-work.js +2 -2
  225. package/dist/ui/fleet-tasks.js +10 -11
  226. package/dist/ui/office-share-dialog.js +31 -7
  227. package/dist/ui/office-share-page.js +1 -0
  228. package/dist/ui/panel-chat.js +14 -2
  229. package/dist/ui/panel-log.js +6 -6
  230. package/dist/ui/panel-needs.js +1 -1
  231. package/dist/ui/panel-settings.js +16 -8
  232. package/dist/ui/settings-appearance.js +3 -35
  233. package/dist/ui/settings-discord.js +3 -2
  234. package/dist/ui/settings-guests.js +17 -7
  235. package/dist/ui/settings-model.js +17 -9
  236. package/dist/ui/settings-registry.js +1 -1
  237. package/dist/ui/settings-strings.js +18 -6
  238. package/dist/ui/settings-token.js +3 -2
  239. package/dist/ui/settings-wizard.js +25 -9
  240. package/dist/ui/shared/app-i18n.js +2 -2
  241. package/dist/ui/shared/app-stream.js +1 -1
  242. package/dist/ui/shared/app.css +70 -2
  243. package/dist/ui/shared/setup-host-text.js +107 -0
  244. package/dist/ui/structured-signin.js +89 -38
  245. package/dist/update-check.d.ts +13 -4
  246. package/dist/update-check.js +17 -4
  247. package/dist/update-check.js.map +1 -1
  248. package/dist/usage-rollup.d.ts +34 -3
  249. package/dist/usage-rollup.js +56 -3
  250. package/dist/usage-rollup.js.map +1 -1
  251. package/dist/web-api.d.ts +10 -1
  252. package/dist/web-api.js +207 -17
  253. package/dist/web-api.js.map +1 -1
  254. package/dist/web-auth.js +1 -1
  255. package/dist/web-auth.js.map +1 -1
  256. package/dist/web-experimental.d.ts +6 -2
  257. package/dist/web-experimental.js +8 -4
  258. package/dist/web-experimental.js.map +1 -1
  259. package/dist/web-office-acts.d.ts +5 -2
  260. package/dist/web-office-acts.js +9 -4
  261. package/dist/web-office-acts.js.map +1 -1
  262. package/dist/web-office-pack-read.d.ts +35 -0
  263. package/dist/web-office-pack-read.js +252 -0
  264. package/dist/web-office-pack-read.js.map +1 -0
  265. package/dist/web-office-pack-tools.d.ts +241 -0
  266. package/dist/web-office-pack-tools.js +785 -0
  267. package/dist/web-office-pack-tools.js.map +1 -0
  268. package/dist/web-office-skins.d.ts +68 -4
  269. package/dist/web-office-skins.js +324 -33
  270. package/dist/web-office-skins.js.map +1 -1
  271. package/dist/web-office-store.d.ts +47 -4
  272. package/dist/web-office-store.js +124 -23
  273. package/dist/web-office-store.js.map +1 -1
  274. package/dist/web-settings-patch.d.ts +3 -2
  275. package/dist/web-settings-patch.js +7 -5
  276. package/dist/web-settings-patch.js.map +1 -1
  277. package/dist/workflow-templates/default.md +3 -3
  278. package/dist/working-recovery.d.ts +0 -2
  279. package/dist/working-recovery.js +2 -23
  280. package/dist/working-recovery.js.map +1 -1
  281. package/package.json +2 -2
  282. package/templates/windows-shortcuts.ps1 +18 -17
  283. package/dist/upgrade-notices.d.ts +0 -17
  284. package/dist/upgrade-notices.js +0 -93
  285. package/dist/upgrade-notices.js.map +0 -1
@@ -13,18 +13,6 @@ export const DURABLE_DELIVERY_MAX_ATTEMPTS = 8;
13
13
  export const DURABLE_DELIVERY_MAX_AGE_MS = 24 * 60 * 60_000;
14
14
  export const DURABLE_DELIVERY_ABORT_BACKOFF_MS = 5_000;
15
15
  export const DEFAULT_REPLY_OBLIGATION_TTL_MS = 24 * 60 * 60_000;
16
- const RESTART_REPLY_DISPLAY_LIMIT = 10;
17
- /** Keep each preview on one physical line and bound even an arbitrary correlation ID. */
18
- function replyPreview(value) {
19
- const escaped = value.replace(/[\u0000-\u001f\u007f]/g, c => JSON.stringify(c).slice(1, -1));
20
- const bytes = Buffer.from(escaped);
21
- if (bytes.length <= 256)
22
- return escaped;
23
- let end = 253;
24
- while ((bytes[end] & 0xc0) === 0x80)
25
- end--;
26
- return bytes.subarray(0, end).toString("utf8") + "…";
27
- }
28
16
  /** The one mapping from validated tool/CLI arguments to a selector. */
29
17
  export function deliveryStatusSelector(args) {
30
18
  const page = { ...(args.limit !== undefined ? { limit: args.limit } : {}), ...(args.cursor ? { cursor: args.cursor } : {}) };
@@ -66,6 +54,15 @@ function payloadRequiresReply(payload) {
66
54
  const meta = payload && typeof payload === "object" ? payload.meta : undefined;
67
55
  return !!meta && typeof meta === "object" && meta.requires_reply === "true";
68
56
  }
57
+ /** Whether a row's payload asks for a reply (an unreadable payload: no). */
58
+ function rowRequiresReply(row) {
59
+ try {
60
+ return payloadRequiresReply(JSON.parse(row.payload_json));
61
+ }
62
+ catch {
63
+ return false;
64
+ }
65
+ }
69
66
  function payloadMessageId(payload) {
70
67
  const meta = payload && typeof payload === "object" ? payload.meta : undefined;
71
68
  const id = meta && typeof meta === "object" ? meta.message_id : undefined;
@@ -354,6 +351,27 @@ export class DeliveryOutbox extends EventEmitter {
354
351
  if (changed)
355
352
  this.emit("state", { deliveryId, state: "cancelled" });
356
353
  }
354
+ /**
355
+ * #2801: AgEnD's own notices with a key starting `prefix` that are still waiting, never begun (as #2797: an aborted
356
+ * attempt wrote nothing), and that `stale(sourceKey, createdAt)` says are overtaken, are not delivered — `cancelled`
357
+ * with `reason`, still readable (delivery_status, Fleet traffic). Returns the ids dropped.
358
+ */
359
+ withdrawWaitingNotices(prefix, stale, reason) {
360
+ const rows = this.db.prepare(`SELECT delivery_id, source_key, created_at FROM deliveries
361
+ WHERE kind=? AND state IN ('queued','retry_wait') AND substr(source_key,1,?)=? ORDER BY created_seq`)
362
+ .all(SYSTEM_NOTICE_KIND, prefix.length, prefix);
363
+ const picked = rows.filter((r) => stale(r.source_key, r.created_at));
364
+ if (!picked.length)
365
+ return [];
366
+ const begun = this.db.prepare("SELECT 1 FROM delivery_attempts WHERE delivery_id=? AND state<>'aborted' LIMIT 1");
367
+ const now = new Date().toISOString();
368
+ const cancel = this.db.prepare(`UPDATE deliveries SET state='cancelled',finished_at=?,updated_at=?,last_error=?,next_attempt_at=NULL
369
+ WHERE delivery_id=? AND state IN ('queued','retry_wait')`);
370
+ const done = this.db.transaction(() => picked.filter((r) => !begun.get(r.delivery_id) && cancel.run(now, now, reason, r.delivery_id).changes === 1).map((r) => r.delivery_id))();
371
+ for (const deliveryId of done)
372
+ this.emit("state", { deliveryId, state: "cancelled" });
373
+ return done;
374
+ }
357
375
  noteWorkingReferences(instances) {
358
376
  // The transaction has committed. Telemetry must not change its result.
359
377
  try {
@@ -470,8 +488,7 @@ export class DeliveryOutbox extends EventEmitter {
470
488
  PRIMARY KEY (correlation_id, requester_instance, owner_instance)
471
489
  );
472
490
  CREATE INDEX IF NOT EXISTS idx_reply_obligation_owner_state ON reply_obligations(owner_instance, state);
473
- -- A notice can be pruned while its boot is still alive. Keep the claim
474
- -- independently: no notice FK/cascade and no request or message content.
491
+ -- #2802: no longer written (the per-boot restart reminder is gone); kept so existing databases keep their schema.
475
492
  CREATE TABLE IF NOT EXISTS reply_restart_markers (
476
493
  owner_instance TEXT NOT NULL,
477
494
  restart_id TEXT NOT NULL,
@@ -635,47 +652,16 @@ export class DeliveryOutbox extends EventEmitter {
635
652
  `).run(now, answer.delivery_id, answer.correlation_id, answer.source_instance, answer.target_instance);
636
653
  }
637
654
  /**
638
- * #926 safety net 1: remind an owner that has not answered. `turn-ended`
639
- * reminds once per ask, after the grace (a reply seconds after the ask is
640
- * normal); `restart` batches once per daemon boot, because the interrupted
641
- * turn does not resume on its own. Marked in the same transaction as the notice.
655
+ * #926 safety net 1: remind an owner that has not answered, once per ask, after the grace (a reply seconds after the
656
+ * ask is normal). Marked in the same transaction as the notice. #2802: the only reply reminder — the per-boot restart
657
+ * batch is gone (an owner idle after a restart gets this one, per ask, unless it was already reminded), and so are the
658
+ * requester's overdue and expiry notices.
642
659
  */
643
660
  remindReplyObligations(ownerInstance, opts) {
644
661
  const now = opts.now ?? new Date();
645
662
  const nowIso = now.toISOString();
646
663
  const graceCutoff = new Date(now.getTime() - opts.graceMs).toISOString();
647
- const sinceIso = (opts.since ?? now).toISOString();
648
664
  const inserted = this.db.transaction(() => {
649
- if (opts.reason === "restart") {
650
- const restartId = opts.restartId ?? sinceIso;
651
- const key = `reply-pending:restart:${JSON.stringify([ownerInstance, restartId])}`;
652
- if (this.db.prepare("SELECT 1 FROM reply_restart_markers WHERE owner_instance=? AND restart_id=?")
653
- .get(ownerInstance, restartId))
654
- return 0;
655
- // Adopt an existing notice from the earlier implementation/rollback
656
- // without stamping a new ask or producing another notice.
657
- const prior = this.db.prepare("SELECT created_at FROM deliveries WHERE source_key=?").get(key);
658
- if (prior) {
659
- this.recordReplyRestart(ownerInstance, restartId, prior.created_at);
660
- return 0;
661
- }
662
- const total = this.db.prepare("SELECT count(*) n FROM reply_obligations WHERE owner_instance=? AND state='open'")
663
- .get(ownerInstance).n;
664
- if (!total)
665
- return 0;
666
- const preview = this.db.prepare(`SELECT requester_instance,correlation_id,last_asked_at FROM reply_obligations
667
- WHERE owner_instance=? AND state='open' ORDER BY last_asked_at,correlation_id,requester_instance LIMIT ?`)
668
- .all(ownerInstance, RESTART_REPLY_DISPLAY_LIMIT);
669
- const lines = preview.map(row => `${replyPreview(row.requester_instance)}; correlation_id=${replyPreview(row.correlation_id)}; asked=${replyPreview(row.last_asked_at)}`);
670
- if (total > preview.length)
671
- lines.push(t("delivery.reply_restart_more", total - preview.length));
672
- const content = t("delivery.reply_restart") + "\n" + lines.join("\n");
673
- if (!this.insertReplyObligationNotice(ownerInstance, null, key, content, nowIso))
674
- return 0;
675
- this.recordReplyRestart(ownerInstance, restartId, nowIso);
676
- this.db.prepare("UPDATE reply_obligations SET nudged_at=? WHERE owner_instance=? AND state='open'").run(nowIso, ownerInstance);
677
- return 1;
678
- }
679
665
  const due = this.db.prepare("SELECT * FROM reply_obligations WHERE owner_instance=? AND state='open' AND nudged_at IS NULL AND last_asked_at <= ?")
680
666
  .all(ownerInstance, graceCutoff);
681
667
  let count = 0;
@@ -694,11 +680,7 @@ export class DeliveryOutbox extends EventEmitter {
694
680
  this.emit("admitted");
695
681
  return inserted;
696
682
  }
697
- recordReplyRestart(owner, restartId, now) {
698
- this.db.prepare("INSERT INTO reply_restart_markers(owner_instance,restart_id,reminded_at) VALUES (?,?,?)")
699
- .run(owner, restartId, now);
700
- }
701
- /** Expiry is terminal for this ask; a later delivered re-ask can reopen the same tuple. */
683
+ /** Expiry is terminal for this ask; a later delivered re-ask can reopen the same tuple. #2802: logged, no notice. */
702
684
  expireReplyObligations(opts = {}) {
703
685
  const now = opts.now ?? new Date();
704
686
  const ttl = opts.ttlMs !== undefined && Number.isFinite(opts.ttlMs) && opts.ttlMs > 0 ? opts.ttlMs : DEFAULT_REPLY_OBLIGATION_TTL_MS;
@@ -708,58 +690,19 @@ export class DeliveryOutbox extends EventEmitter {
708
690
  const due = this.db.prepare("SELECT * FROM reply_obligations WHERE state='open' AND last_asked_at<=? ORDER BY last_asked_at")
709
691
  .all(cutoff);
710
692
  for (const row of due) {
711
- if (!row.overdue_notified_at) {
712
- const key = `reply-overdue:${row.correlation_id}:${row.requester_instance}:${row.owner_instance}:${row.last_asked_at}`;
713
- this.insertReplyObligationNotice(row.requester_instance, row.correlation_id, key, t("delivery.reply_expired", row.owner_instance, row.correlation_id, row.last_asked_at), nowIso);
714
- }
715
- this.db.prepare(`UPDATE reply_obligations SET state='expired',expired_at=?,overdue_notified_at=COALESCE(overdue_notified_at,?)
693
+ this.db.prepare(`UPDATE reply_obligations SET state='expired',expired_at=?
716
694
  WHERE correlation_id=? AND requester_instance=? AND owner_instance=? AND state='open'`)
717
- .run(nowIso, nowIso, row.correlation_id, row.requester_instance, row.owner_instance);
695
+ .run(nowIso, row.correlation_id, row.requester_instance, row.owner_instance);
718
696
  row.state = "expired";
719
697
  row.expired_at = nowIso;
720
- row.overdue_notified_at ??= nowIso;
721
698
  }
722
699
  return due.map(mapObligation);
723
700
  })();
724
701
  if (expired.length) {
725
- this.emit("admitted");
726
702
  this.noteWorkingReferences(expired.flatMap(row => [row.ownerInstance, row.requesterInstance]));
727
703
  }
728
704
  return expired;
729
705
  }
730
- /**
731
- * #926 safety net 2 (poll-on-timeout, in code): tell the requester once when
732
- * the owner is not working and nothing has come back for `overdueMs` since
733
- * the last ask or reminder. A still-working owner is never reported.
734
- */
735
- notifyOverdueReplyObligations(opts) {
736
- if (!(opts.overdueMs > 0))
737
- return 0;
738
- const now = opts.now ?? new Date();
739
- const nowIso = now.toISOString();
740
- const inserted = this.db.transaction(() => {
741
- const open = this.db.prepare(`
742
- SELECT * FROM reply_obligations WHERE state='open' AND overdue_notified_at IS NULL ORDER BY opened_at
743
- `).all();
744
- let count = 0;
745
- for (const row of open) {
746
- const quietSince = Math.max(Date.parse(row.last_asked_at), row.nudged_at ? Date.parse(row.nudged_at) : 0);
747
- if (now.getTime() - quietSince < opts.overdueMs || !opts.ownerIdle(row.owner_instance))
748
- continue;
749
- const content = t("delivery.reply_overdue", row.owner_instance, row.correlation_id, row.last_asked_at, row.nudged_at ? t("delivery.reply_reminded", row.nudged_at) : "");
750
- const key = `reply-overdue:${row.correlation_id}:${row.requester_instance}:${row.owner_instance}:${row.last_asked_at}`;
751
- if (this.insertReplyObligationNotice(row.requester_instance, row.correlation_id, key, content, nowIso))
752
- count++;
753
- this.db.prepare(`
754
- UPDATE reply_obligations SET overdue_notified_at=? WHERE correlation_id=? AND requester_instance=? AND owner_instance=? AND state='open'
755
- `).run(nowIso, row.correlation_id, row.requester_instance, row.owner_instance);
756
- }
757
- return count;
758
- })();
759
- if (inserted > 0)
760
- this.emit("admitted");
761
- return inserted;
762
- }
763
706
  /** A system notice as a durable row, like #929's outcome notices; the key makes it idempotent. */
764
707
  insertReplyObligationNotice(target, correlationId, sourceKey, content, now) {
765
708
  const noticeId = randomUUID();
@@ -1089,6 +1032,31 @@ export class DeliveryOutbox extends EventEmitter {
1089
1032
  `).run(atIso, by, deliveryId);
1090
1033
  return result.changes === 1;
1091
1034
  }
1035
+ /**
1036
+ * #2785 (c): the texts `source` sent `target` (fleet_inbound / steer) admitted at or after `sinceIso`, newest first,
1037
+ * looked for among the target's newest `scan` rows only. The rows are found by the target index alone and read one by
1038
+ * one: a filter on source or time over the table would read every row's payload (both columns follow it).
1039
+ */
1040
+ recentTextsFrom(target, source, sinceIso, scan = 30) {
1041
+ const rows = this.db.prepare("SELECT rowid AS r FROM deliveries WHERE target_instance=? ORDER BY created_seq DESC LIMIT ?")
1042
+ .all(target, scan);
1043
+ const read = this.db.prepare("SELECT source_instance, kind, created_at, payload_json FROM deliveries WHERE rowid=?");
1044
+ const texts = [];
1045
+ for (const { r } of rows) {
1046
+ const row = read.get(r);
1047
+ if (!row || row.created_at < sinceIso)
1048
+ continue;
1049
+ if (row.source_instance !== source || (row.kind !== "fleet_inbound" && row.kind !== "steer"))
1050
+ continue;
1051
+ try {
1052
+ const content = JSON.parse(row.payload_json).content;
1053
+ if (typeof content === "string")
1054
+ texts.push(content);
1055
+ }
1056
+ catch { /* an unreadable payload says nothing */ }
1057
+ }
1058
+ return texts;
1059
+ }
1092
1060
  countForTarget(target, states) {
1093
1061
  if (states.length === 0)
1094
1062
  return 0;
@@ -1111,10 +1079,12 @@ export class DeliveryOutbox extends EventEmitter {
1111
1079
  }
1112
1080
  claimNextSync(managerBootId, targetBootIdFor, blockedTargets, eligible) {
1113
1081
  const now = new Date().toISOString();
1114
- const rows = this.db.prepare(`
1082
+ const pending = this.db.prepare(`
1115
1083
  SELECT * FROM deliveries WHERE state IN ('queued','retry_wait')
1116
1084
  ORDER BY created_seq
1117
1085
  `).all();
1086
+ const superseded = this.supersedeThreadRows(pending, now);
1087
+ const rows = superseded.size ? pending.filter(row => !superseded.has(row.delivery_id)) : pending;
1118
1088
  // The oldest pending row owns its target lane even while it is in retry
1119
1089
  // backoff or the target is temporarily unavailable. Later rows must not
1120
1090
  // pass it merely because they happen to be eligible first.
@@ -1153,6 +1123,48 @@ export class DeliveryOutbox extends EventEmitter {
1153
1123
  }
1154
1124
  return undefined;
1155
1125
  }
1126
+ /**
1127
+ * #2785 (b): a message still waiting while a newer one from the same sender to the same target on the same thread
1128
+ * (correlation_id) waits behind it is not delivered — the newer one replaces it (a review round for an older PR head, a
1129
+ * CI result since overtaken). Only agents' messages (fleet_inbound, steer) that never began: a row with any attempt
1130
+ * other than an aborted one keeps its place. The dropped row is `cancelled`, its reason naming the newer delivery, and
1131
+ * stays readable (delivery_status, Fleet traffic). A reply obligation opens only on delivery, from the delivered row's own
1132
+ * payload: a row that requires a reply is replaced only by one that requires one too, else it keeps its place (#2797
1133
+ * review — an update without requires_reply must not swallow the request it follows).
1134
+ */
1135
+ supersedeThreadRows(pending, now) {
1136
+ const newest = new Map();
1137
+ const keyOf = (row) => (row.kind === "fleet_inbound" || row.kind === "steer") && row.correlation_id
1138
+ ? `${row.source_instance}\u0000${row.target_instance}\u0000${row.correlation_id}` : null;
1139
+ for (const row of pending) {
1140
+ const key = keyOf(row);
1141
+ if (key)
1142
+ newest.set(key, row);
1143
+ } // ascending: the last wins
1144
+ const candidates = pending.filter(row => { const key = keyOf(row); return key !== null && newest.get(key).delivery_id !== row.delivery_id; });
1145
+ if (!candidates.length)
1146
+ return new Set();
1147
+ const begun = this.db.prepare("SELECT 1 FROM delivery_attempts WHERE delivery_id=? AND state<>'aborted' LIMIT 1");
1148
+ const cancel = this.db.prepare(`UPDATE deliveries SET state='cancelled',finished_at=?,updated_at=?,last_error=?,next_attempt_at=NULL
1149
+ WHERE delivery_id=? AND state IN ('queued','retry_wait')`);
1150
+ const done = this.db.transaction(() => {
1151
+ const out = [];
1152
+ for (const row of candidates) {
1153
+ if (begun.get(row.delivery_id))
1154
+ continue;
1155
+ const newer = newest.get(keyOf(row));
1156
+ if (rowRequiresReply(row) && !rowRequiresReply(newer))
1157
+ continue;
1158
+ const by = newer.delivery_id;
1159
+ if (cancel.run(now, now, `superseded by ${by}`, row.delivery_id).changes === 1)
1160
+ out.push(row.delivery_id);
1161
+ }
1162
+ return out;
1163
+ })();
1164
+ for (const deliveryId of done)
1165
+ this.emit("state", { deliveryId, state: "cancelled" });
1166
+ return new Set(done);
1167
+ }
1156
1168
  /** Idempotent begin permit, committed immediately before the pane side effect. */
1157
1169
  begin(deliveryId, targetBootId, attemptNo, evidence) {
1158
1170
  const now = new Date().toISOString();
@@ -1508,60 +1520,6 @@ export class DeliveryOutbox extends EventEmitter {
1508
1520
  });
1509
1521
  return transaction();
1510
1522
  }
1511
- /** Atomically create a post-restart notice for an accepted operation whose response was not recorded. */
1512
- admitPostRestartOutcomeNotice(parent, currentSourceBootId) {
1513
- const sourceKey = `post-restart:${parent.sourceInstance}:${parent.sourceDaemonBootId}:${parent.operationId}:${parent.targetInstance}`;
1514
- const operationId = `notice:${parent.sourceDaemonBootId}:${parent.operationId}:${parent.targetInstance}`;
1515
- const now = new Date().toISOString();
1516
- const deliveryId = randomUUID();
1517
- const noticeText = t("delivery.post_restart", parent.targetInstance, statusSummary(parent.state), parent.operationId, parent.state);
1518
- const payload = {
1519
- type: "fleet_inbound",
1520
- content: noticeText,
1521
- meta: {
1522
- user: "AgEnD recovery",
1523
- user_id: "agend-system",
1524
- message_id: `delivery-notice-${parent.operationId}-${parent.targetInstance}`,
1525
- chat_id: "",
1526
- thread_id: "",
1527
- source: "delivery-outbox",
1528
- },
1529
- };
1530
- const transaction = this.db.transaction(() => {
1531
- const prior = this.db.prepare(`
1532
- SELECT d.* FROM outcome_notices n JOIN deliveries d ON d.delivery_id=n.notice_delivery_id
1533
- WHERE n.source_instance=? AND n.source_daemon_boot_id=? AND n.operation_id=? AND n.target_instance=?
1534
- `).get(parent.sourceInstance, parent.sourceDaemonBootId, parent.operationId, parent.targetInstance);
1535
- if (prior)
1536
- return mapRow(prior);
1537
- const terminalNotice = this.db.prepare(`
1538
- SELECT d.* FROM failure_notices n JOIN deliveries d ON d.delivery_id=n.notice_delivery_id
1539
- WHERE n.parent_delivery_id=?
1540
- `).get(parent.deliveryId);
1541
- if (terminalNotice)
1542
- return mapRow(terminalNotice);
1543
- const reserved = this.db.prepare(`
1544
- INSERT OR IGNORE INTO outcome_notices
1545
- (source_instance,source_daemon_boot_id,operation_id,target_instance,notice_delivery_id,created_at)
1546
- VALUES (?,?,?,?,?,?)
1547
- `).run(parent.sourceInstance, parent.sourceDaemonBootId, parent.operationId, parent.targetInstance, deliveryId, now);
1548
- if (reserved.changes !== 1)
1549
- return undefined;
1550
- this.db.prepare(`
1551
- INSERT INTO deliveries (
1552
- delivery_id,operation_id,source_key,source_instance,source_daemon_boot_id,
1553
- target_instance,target_session,kind,correlation_id,payload_json,state,
1554
- attempt_no,created_seq,manager_boot_id,created_at,updated_at,accepted_at
1555
- ) VALUES (?,?,?,?,?,?,NULL,'post_restart_outcome_notice',NULL,?,'queued',0,
1556
- (SELECT COALESCE(MAX(created_seq),0)+1 FROM deliveries),NULL,?,?,?)
1557
- `).run(deliveryId, operationId, sourceKey, "agend-system", currentSourceBootId, parent.sourceInstance, JSON.stringify(payload), now, now, now);
1558
- return mapRow(this.db.prepare("SELECT * FROM deliveries WHERE delivery_id=?").get(deliveryId));
1559
- });
1560
- const notice = transaction();
1561
- if (notice)
1562
- this.emit("admitted", notice);
1563
- return notice;
1564
- }
1565
1523
  recoverTargetGeneration(targetInstance, currentTargetBootId) {
1566
1524
  const now = new Date().toISOString();
1567
1525
  const transaction = this.db.transaction(() => {
@@ -1655,17 +1613,6 @@ export class DeliveryOutbox extends EventEmitter {
1655
1613
  this.emit("state", { deliveryId, state: outcome });
1656
1614
  return changed;
1657
1615
  }
1658
- getUnansweredAccepted(sourceInstance, currentBootId) {
1659
- const rows = this.db.prepare(`
1660
- SELECT * FROM deliveries
1661
- WHERE source_instance=? AND source_daemon_boot_id<>? AND response_delivered_at IS NULL
1662
- -- Scheduler admission has no waiting source-agent tool response; its
1663
- -- stable run key and durable row are the recovery/lookup contract.
1664
- AND kind NOT IN ('raw_paste')
1665
- ORDER BY created_seq
1666
- `).all(sourceInstance, currentBootId);
1667
- return rows.map(mapRow);
1668
- }
1669
1616
  close() {
1670
1617
  this.db.close();
1671
1618
  }
@@ -1796,6 +1743,7 @@ export class DeliveryOutbox extends EventEmitter {
1796
1743
  }
1797
1744
  /** Must be called inside the same SQLite transaction as the terminal transition. */
1798
1745
  insertFailureNotice(parent, outcome, reason, now) {
1746
+ // post_restart_outcome_notice: no longer written (#2802), but a row from before may still be queued.
1799
1747
  if (parent.kind === "delivery_outcome_notice" || parent.kind === "post_restart_outcome_notice"
1800
1748
  || parent.kind === REPLY_OBLIGATION_NOTICE_KIND || parent.kind === SYSTEM_NOTICE_KIND || parent.kind === WORKING_RECOVERY_KIND)
1801
1749
  return;