@songsid/agend 2.4.0-beta.24 → 2.4.0-beta.25

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 (395) hide show
  1. package/README.md +1 -1
  2. package/README.zh-TW.md +1 -1
  3. package/dist/agend-home.js +5 -5
  4. package/dist/agend-home.js.map +1 -1
  5. package/dist/agent-endpoint.js +10 -0
  6. package/dist/agent-endpoint.js.map +1 -1
  7. package/dist/agent-workspace.d.ts +18 -2
  8. package/dist/agent-workspace.js +15 -4
  9. package/dist/agent-workspace.js.map +1 -1
  10. package/dist/backend/antigravity.js +8 -6
  11. package/dist/backend/antigravity.js.map +1 -1
  12. package/dist/backend/claude-code.js +17 -0
  13. package/dist/backend/claude-code.js.map +1 -1
  14. package/dist/backend/claude-usage-credits.d.ts +8 -0
  15. package/dist/backend/claude-usage-credits.js +121 -0
  16. package/dist/backend/claude-usage-credits.js.map +1 -0
  17. package/dist/backend/types.d.ts +30 -0
  18. package/dist/backend/types.js.map +1 -1
  19. package/dist/build-provenance.json +1 -1
  20. package/dist/channel/adapters/discord.js +7 -1
  21. package/dist/channel/adapters/discord.js.map +1 -1
  22. package/dist/channel/tool-router.js +1 -0
  23. package/dist/channel/tool-router.js.map +1 -1
  24. package/dist/cli-audited.js +9 -4
  25. package/dist/cli-audited.js.map +1 -1
  26. package/dist/cli.js +184 -21
  27. package/dist/cli.js.map +1 -1
  28. package/dist/config-validator.js +11 -1
  29. package/dist/config-validator.js.map +1 -1
  30. package/dist/config.js +2 -0
  31. package/dist/config.js.map +1 -1
  32. package/dist/contact-auth-store.d.ts +18 -0
  33. package/dist/contact-auth-store.js +55 -8
  34. package/dist/contact-auth-store.js.map +1 -1
  35. package/dist/contact-auth-types.d.ts +3 -0
  36. package/dist/contact-auth-types.js.map +1 -1
  37. package/dist/contact-change-proposals.d.ts +34 -0
  38. package/dist/contact-change-proposals.js +1 -1
  39. package/dist/contact-change-proposals.js.map +1 -1
  40. package/dist/cross-instance-notice.d.ts +1 -0
  41. package/dist/cross-instance-notice.js +9 -8
  42. package/dist/cross-instance-notice.js.map +1 -1
  43. package/dist/daemon.d.ts +35 -0
  44. package/dist/daemon.js +234 -19
  45. package/dist/daemon.js.map +1 -1
  46. package/dist/delivery-outbox.d.ts +42 -1
  47. package/dist/delivery-outbox.js +194 -20
  48. package/dist/delivery-outbox.js.map +1 -1
  49. package/dist/fleet-context.d.ts +8 -0
  50. package/dist/fleet-lock.d.ts +67 -2
  51. package/dist/fleet-lock.js +236 -2
  52. package/dist/fleet-lock.js.map +1 -1
  53. package/dist/fleet-manager.d.ts +163 -6
  54. package/dist/fleet-manager.js +1136 -75
  55. package/dist/fleet-manager.js.map +1 -1
  56. package/dist/fleet-windows-runtime.d.ts +20 -1
  57. package/dist/fleet-windows-runtime.js +98 -18
  58. package/dist/fleet-windows-runtime.js.map +1 -1
  59. package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +7 -0
  60. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +14 -4
  61. package/dist/home-update-lock.d.ts +35 -0
  62. package/dist/home-update-lock.js +81 -0
  63. package/dist/home-update-lock.js.map +1 -0
  64. package/dist/hub/compose/member.d.ts +5 -1
  65. package/dist/hub/compose/member.js +9 -5
  66. package/dist/hub/compose/member.js.map +1 -1
  67. package/dist/hub/member/room-ask.d.ts +5 -0
  68. package/dist/hub/member/room-ask.js +43 -16
  69. package/dist/hub/member/room-ask.js.map +1 -1
  70. package/dist/hub/member/room-mention-feedback.d.ts +2 -0
  71. package/dist/hub/member/room-mention-feedback.js +1 -1
  72. package/dist/hub/member/room-mention-feedback.js.map +1 -1
  73. package/dist/hub/member/room-post-answers.d.ts +2 -0
  74. package/dist/hub/member/room-post-answers.js +1 -1
  75. package/dist/hub/member/room-post-answers.js.map +1 -1
  76. package/dist/hub/member/room-post.d.ts +5 -0
  77. package/dist/hub/member/room-post.js +4 -1
  78. package/dist/hub/member/room-post.js.map +1 -1
  79. package/dist/hub/member/updates.d.ts +7 -1
  80. package/dist/hub/member/updates.js +7 -1
  81. package/dist/hub/member/updates.js.map +1 -1
  82. package/dist/hub/representative.d.ts +7 -0
  83. package/dist/hub/representative.js +38 -5
  84. package/dist/hub/representative.js.map +1 -1
  85. package/dist/install-lock.d.ts +15 -1
  86. package/dist/install-lock.js +16 -8
  87. package/dist/install-lock.js.map +1 -1
  88. package/dist/install-ownership.d.ts +165 -0
  89. package/dist/install-ownership.js +404 -0
  90. package/dist/install-ownership.js.map +1 -0
  91. package/dist/instance-config-impact.js +2 -0
  92. package/dist/instance-config-impact.js.map +1 -1
  93. package/dist/instructions.d.ts +4 -0
  94. package/dist/instructions.js +4 -0
  95. package/dist/instructions.js.map +1 -1
  96. package/dist/local-pane-endpoint.d.ts +4 -1
  97. package/dist/local-pane-endpoint.js +12 -2
  98. package/dist/local-pane-endpoint.js.map +1 -1
  99. package/dist/locale.js +160 -4
  100. package/dist/locale.js.map +1 -1
  101. package/dist/native-agent-admission.d.ts +7 -0
  102. package/dist/native-agent-admission.js +46 -3
  103. package/dist/native-agent-admission.js.map +1 -1
  104. package/dist/native-mcp.d.ts +16 -1
  105. package/dist/native-mcp.js +38 -5
  106. package/dist/native-mcp.js.map +1 -1
  107. package/dist/native-pane-lifecycle.d.ts +9 -0
  108. package/dist/native-pane-lifecycle.js +23 -0
  109. package/dist/native-pane-lifecycle.js.map +1 -1
  110. package/dist/native-pane-manager.d.ts +19 -6
  111. package/dist/native-pane-manager.js +79 -4
  112. package/dist/native-pane-manager.js.map +1 -1
  113. package/dist/needs-you.d.ts +8 -0
  114. package/dist/needs-you.js +1 -0
  115. package/dist/needs-you.js.map +1 -1
  116. package/dist/outbound-handlers.d.ts +12 -0
  117. package/dist/outbound-handlers.js +30 -2
  118. package/dist/outbound-handlers.js.map +1 -1
  119. package/dist/package-preimage.js +4 -0
  120. package/dist/package-preimage.js.map +1 -1
  121. package/dist/pane-port.d.ts +1 -0
  122. package/dist/plist-args.d.ts +9 -0
  123. package/dist/plist-args.js +22 -0
  124. package/dist/plist-args.js.map +1 -0
  125. package/dist/public-preview.d.ts +4 -6
  126. package/dist/public-preview.js +5 -2
  127. package/dist/public-preview.js.map +1 -1
  128. package/dist/public-web-gateway.js +8 -3
  129. package/dist/public-web-gateway.js.map +1 -1
  130. package/dist/public-web-link.d.ts +13 -1
  131. package/dist/public-web-link.js +28 -1
  132. package/dist/public-web-link.js.map +1 -1
  133. package/dist/recover.cjs +2452 -0
  134. package/dist/remote-card-prompt.d.ts +6 -2
  135. package/dist/remote-card-prompt.js +12 -3
  136. package/dist/remote-card-prompt.js.map +1 -1
  137. package/dist/reply-draft.d.ts +12 -0
  138. package/dist/reply-draft.js +81 -0
  139. package/dist/reply-draft.js.map +1 -0
  140. package/dist/request-contact-api.d.ts +15 -0
  141. package/dist/request-contact-api.js +120 -0
  142. package/dist/request-contact-api.js.map +1 -0
  143. package/dist/request-contact-card.d.ts +36 -0
  144. package/dist/request-contact-card.js +206 -0
  145. package/dist/request-contact-card.js.map +1 -0
  146. package/dist/request-contact-gate.d.ts +79 -0
  147. package/dist/request-contact-gate.js +262 -0
  148. package/dist/request-contact-gate.js.map +1 -0
  149. package/dist/request-contact-native.d.ts +52 -0
  150. package/dist/request-contact-native.js +83 -0
  151. package/dist/request-contact-native.js.map +1 -0
  152. package/dist/request-contact-types.d.ts +86 -0
  153. package/dist/request-contact-types.js +7 -0
  154. package/dist/request-contact-types.js.map +1 -0
  155. package/dist/request-context-call-protocol.d.ts +12 -0
  156. package/dist/request-context-call-protocol.js +14 -0
  157. package/dist/request-context-call-protocol.js.map +1 -0
  158. package/dist/request-context-call.d.ts +22 -0
  159. package/dist/request-context-call.js +35 -0
  160. package/dist/request-context-call.js.map +1 -0
  161. package/dist/request-context-drain.d.ts +39 -0
  162. package/dist/request-context-drain.js +159 -0
  163. package/dist/request-context-drain.js.map +1 -0
  164. package/dist/request-context-fence.d.ts +28 -0
  165. package/dist/request-context-fence.js +58 -0
  166. package/dist/request-context-fence.js.map +1 -0
  167. package/dist/request-context-migration.d.ts +64 -0
  168. package/dist/request-context-migration.js +158 -0
  169. package/dist/request-context-migration.js.map +1 -0
  170. package/dist/request-context-pane.d.ts +25 -0
  171. package/dist/request-context-pane.js +48 -0
  172. package/dist/request-context-pane.js.map +1 -0
  173. package/dist/request-context-policy.d.ts +74 -0
  174. package/dist/request-context-policy.js +116 -0
  175. package/dist/request-context-policy.js.map +1 -0
  176. package/dist/request-context-recovery.d.ts +14 -0
  177. package/dist/request-context-recovery.js +56 -0
  178. package/dist/request-context-recovery.js.map +1 -0
  179. package/dist/request-context-relay.d.ts +19 -0
  180. package/dist/request-context-relay.js +63 -0
  181. package/dist/request-context-relay.js.map +1 -0
  182. package/dist/request-context-returns.d.ts +67 -0
  183. package/dist/request-context-returns.js +211 -0
  184. package/dist/request-context-returns.js.map +1 -0
  185. package/dist/request-context-store.d.ts +2 -1
  186. package/dist/request-context-store.js +8 -1
  187. package/dist/request-context-store.js.map +1 -1
  188. package/dist/request-context-turns.d.ts +99 -0
  189. package/dist/request-context-turns.js +215 -0
  190. package/dist/request-context-turns.js.map +1 -0
  191. package/dist/request-context-view.d.ts +33 -0
  192. package/dist/request-context-view.js +36 -0
  193. package/dist/request-context-view.js.map +1 -0
  194. package/dist/request-hub-context.d.ts +130 -0
  195. package/dist/request-hub-context.js +89 -0
  196. package/dist/request-hub-context.js.map +1 -0
  197. package/dist/request-hub-output.d.ts +11 -0
  198. package/dist/request-hub-output.js +21 -0
  199. package/dist/request-hub-output.js.map +1 -0
  200. package/dist/runtime-cli-install.js +13 -11
  201. package/dist/runtime-cli-install.js.map +1 -1
  202. package/dist/runtime-client.d.ts +2 -0
  203. package/dist/runtime-client.js +17 -4
  204. package/dist/runtime-client.js.map +1 -1
  205. package/dist/runtime-coordinator.d.ts +4 -1
  206. package/dist/runtime-coordinator.js +10 -3
  207. package/dist/runtime-coordinator.js.map +1 -1
  208. package/dist/runtime-pane-assets.d.ts +1 -1
  209. package/dist/runtime-pane-assets.js +1 -1
  210. package/dist/runtime-pane-assets.js.map +1 -1
  211. package/dist/runtime-pane-host.d.ts +3 -0
  212. package/dist/runtime-pane-host.js +39 -21
  213. package/dist/runtime-pane-host.js.map +1 -1
  214. package/dist/runtime-pane-link.d.ts +6 -2
  215. package/dist/runtime-pane-link.js +17 -4
  216. package/dist/runtime-pane-link.js.map +1 -1
  217. package/dist/runtime-pane-mcp-relay.d.ts +11 -1
  218. package/dist/runtime-pane-mcp-relay.js +69 -3
  219. package/dist/runtime-pane-mcp-relay.js.map +1 -1
  220. package/dist/runtime-pane-mcp.d.ts +28 -1
  221. package/dist/runtime-pane-mcp.js +92 -15
  222. package/dist/runtime-pane-mcp.js.map +1 -1
  223. package/dist/runtime-pane-port.d.ts +6 -0
  224. package/dist/runtime-pane-port.js +23 -4
  225. package/dist/runtime-pane-port.js.map +1 -1
  226. package/dist/runtime-pane-protocol.d.ts +4 -0
  227. package/dist/runtime-pane-protocol.js +11 -4
  228. package/dist/runtime-pane-protocol.js.map +1 -1
  229. package/dist/runtime-pane-service.d.ts +1 -0
  230. package/dist/runtime-pane-service.js +25 -9
  231. package/dist/runtime-pane-service.js.map +1 -1
  232. package/dist/runtime-pane-stdio-protocol.d.ts +4 -0
  233. package/dist/runtime-pane-stdio-protocol.js +12 -5
  234. package/dist/runtime-pane-stdio-protocol.js.map +1 -1
  235. package/dist/runtime-pane-stdio.js +5 -5
  236. package/dist/runtime-pane-stdio.js.map +1 -1
  237. package/dist/runtime-protocol.d.ts +3 -0
  238. package/dist/runtime-protocol.js.map +1 -1
  239. package/dist/scheduler/scheduler.d.ts +6 -0
  240. package/dist/scheduler/scheduler.js +19 -1
  241. package/dist/scheduler/scheduler.js.map +1 -1
  242. package/dist/scheduler/task-board.d.ts +4 -0
  243. package/dist/scheduler/task-board.js +6 -0
  244. package/dist/scheduler/task-board.js.map +1 -1
  245. package/dist/scheduler/types.d.ts +1 -1
  246. package/dist/service-activation.js +3 -13
  247. package/dist/service-activation.js.map +1 -1
  248. package/dist/service-lock.d.ts +28 -0
  249. package/dist/service-lock.js +85 -0
  250. package/dist/service-lock.js.map +1 -0
  251. package/dist/settings-api.d.ts +6 -0
  252. package/dist/settings-api.js +35 -0
  253. package/dist/settings-api.js.map +1 -1
  254. package/dist/settings-change.js +1 -1
  255. package/dist/settings-change.js.map +1 -1
  256. package/dist/state-lease.d.ts +24 -0
  257. package/dist/state-lease.js +103 -0
  258. package/dist/state-lease.js.map +1 -0
  259. package/dist/tmux-binary.js +1 -1
  260. package/dist/tmux-binary.js.map +1 -1
  261. package/dist/tool-receipt-output.d.ts +2 -0
  262. package/dist/topic-commands.js +21 -1
  263. package/dist/topic-commands.js.map +1 -1
  264. package/dist/transcript-monitor.js +3 -0
  265. package/dist/transcript-monitor.js.map +1 -1
  266. package/dist/tunnel/named-link-test.d.ts +27 -0
  267. package/dist/tunnel/named-link-test.js +41 -0
  268. package/dist/tunnel/named-link-test.js.map +1 -1
  269. package/dist/types.d.ts +7 -0
  270. package/dist/ui/chat-store.js +5 -4
  271. package/dist/ui/fleet-office-card.js +15 -2
  272. package/dist/ui/fleet-office-skin.js +33 -9
  273. package/dist/ui/fleet-office-zones.js +8 -3
  274. package/dist/ui/fleet-office.js +136 -18
  275. package/dist/ui/fleet-task-files.js +1 -1
  276. package/dist/ui/panel-chat.js +15 -2
  277. package/dist/ui/panel-needs.js +22 -2
  278. package/dist/ui/panel-settings.js +22 -8
  279. package/dist/ui/settings-preview-address.js +156 -0
  280. package/dist/ui/settings-registry.js +2 -0
  281. package/dist/ui/settings-strings.js +6 -6
  282. package/dist/ui/shared/app.css +76 -2
  283. package/dist/ui/shared/chat-strings.js +6 -2
  284. package/dist/ui/shared/chat-thread.js +7 -1
  285. package/dist/ui/shared/preview-panel.js +1 -1
  286. package/dist/ui/shared/preview.js +11 -2
  287. package/dist/ui/shared/tokens.css +18 -3
  288. package/dist/ui/shared/ui-confirm.js +5 -4
  289. package/dist/ui/shared/workspace.css +7 -0
  290. package/dist/ui/usage-credits-card.js +84 -0
  291. package/dist/ui/workspace-ignored-strings.js +16 -0
  292. package/dist/ui/workspace-panel.js +15 -6
  293. package/dist/update-card.d.ts +193 -0
  294. package/dist/update-card.js +620 -0
  295. package/dist/update-card.js.map +1 -0
  296. package/dist/update-dispatch.d.ts +16 -1
  297. package/dist/update-dispatch.js +12 -4
  298. package/dist/update-dispatch.js.map +1 -1
  299. package/dist/update-forward.d.ts +73 -0
  300. package/dist/update-forward.js +283 -0
  301. package/dist/update-forward.js.map +1 -0
  302. package/dist/update-idle.d.ts +1 -0
  303. package/dist/update-idle.js +12 -3
  304. package/dist/update-idle.js.map +1 -1
  305. package/dist/update-install.d.ts +2 -1
  306. package/dist/update-install.js +18 -10
  307. package/dist/update-install.js.map +1 -1
  308. package/dist/update-journal.d.ts +351 -0
  309. package/dist/update-journal.js +717 -0
  310. package/dist/update-journal.js.map +1 -0
  311. package/dist/update-launch.js +1 -1
  312. package/dist/update-launch.js.map +1 -1
  313. package/dist/update-npm-env.d.ts +45 -12
  314. package/dist/update-npm-env.js +48 -0
  315. package/dist/update-npm-env.js.map +1 -1
  316. package/dist/update-package-restore.d.ts +75 -0
  317. package/dist/update-package-restore.js +318 -0
  318. package/dist/update-package-restore.js.map +1 -0
  319. package/dist/update-quiescence.d.ts +192 -0
  320. package/dist/update-quiescence.js +330 -0
  321. package/dist/update-quiescence.js.map +1 -0
  322. package/dist/update-readiness-host.d.ts +61 -0
  323. package/dist/update-readiness-host.js +297 -0
  324. package/dist/update-readiness-host.js.map +1 -0
  325. package/dist/update-readiness.d.ts +83 -0
  326. package/dist/update-readiness.js +459 -0
  327. package/dist/update-readiness.js.map +1 -0
  328. package/dist/update-recovery/kit.d.ts +35 -0
  329. package/dist/update-recovery/kit.js +99 -0
  330. package/dist/update-recovery/kit.js.map +1 -0
  331. package/dist/update-recovery/pre-start.d.ts +34 -0
  332. package/dist/update-recovery/pre-start.js +103 -0
  333. package/dist/update-recovery/pre-start.js.map +1 -0
  334. package/dist/update-recovery/recover-main.d.ts +1 -0
  335. package/dist/update-recovery/recover-main.js +4 -0
  336. package/dist/update-recovery/recover-main.js.map +1 -0
  337. package/dist/update-recovery/recover.d.ts +22 -0
  338. package/dist/update-recovery/recover.js +124 -0
  339. package/dist/update-recovery/recover.js.map +1 -0
  340. package/dist/update-recovery/route.d.ts +53 -0
  341. package/dist/update-recovery/route.js +262 -0
  342. package/dist/update-recovery/route.js.map +1 -0
  343. package/dist/update-recovery/runner.d.ts +58 -0
  344. package/dist/update-recovery/runner.js +196 -0
  345. package/dist/update-recovery/runner.js.map +1 -0
  346. package/dist/update-recovery/service-manager.d.ts +39 -0
  347. package/dist/update-recovery/service-manager.js +57 -0
  348. package/dist/update-recovery/service-manager.js.map +1 -0
  349. package/dist/update-restore.d.ts +44 -0
  350. package/dist/update-restore.js +355 -0
  351. package/dist/update-restore.js.map +1 -0
  352. package/dist/update-retained.d.ts +38 -0
  353. package/dist/update-retained.js +91 -0
  354. package/dist/update-retained.js.map +1 -0
  355. package/dist/update-rollback.d.ts +74 -0
  356. package/dist/update-rollback.js +221 -0
  357. package/dist/update-rollback.js.map +1 -0
  358. package/dist/update-settings.d.ts +36 -0
  359. package/dist/update-settings.js +122 -0
  360. package/dist/update-settings.js.map +1 -0
  361. package/dist/update-snapshot-manifest.d.ts +32 -0
  362. package/dist/update-snapshot-manifest.js +65 -0
  363. package/dist/update-snapshot-manifest.js.map +1 -0
  364. package/dist/update-snapshot-scope.d.ts +67 -0
  365. package/dist/update-snapshot-scope.js +172 -0
  366. package/dist/update-snapshot-scope.js.map +1 -0
  367. package/dist/update-snapshot.d.ts +34 -0
  368. package/dist/update-snapshot.js +246 -0
  369. package/dist/update-snapshot.js.map +1 -0
  370. package/dist/update-writers.d.ts +71 -0
  371. package/dist/update-writers.js +235 -0
  372. package/dist/update-writers.js.map +1 -0
  373. package/dist/web-api.d.ts +3 -0
  374. package/dist/web-api.js +43 -8
  375. package/dist/web-api.js.map +1 -1
  376. package/dist/web-chat-history.d.ts +7 -0
  377. package/dist/web-chat-history.js +15 -0
  378. package/dist/web-chat-history.js.map +1 -1
  379. package/dist/web-preview.d.ts +5 -0
  380. package/dist/web-preview.js +1 -1
  381. package/dist/web-preview.js.map +1 -1
  382. package/dist/web-update.d.ts +6 -0
  383. package/dist/windows-agents.d.ts +12 -0
  384. package/dist/windows-agents.js +5 -0
  385. package/dist/windows-agents.js.map +1 -1
  386. package/launcher/agend +4 -1
  387. package/launcher/agend-agent +4 -1
  388. package/launcher/agend-install.cjs +16 -8
  389. package/launcher/install-admission.d.cts +8 -0
  390. package/launcher/npm-allow-scripts.cjs +72 -0
  391. package/launcher/npm-global-prefix.cjs +81 -0
  392. package/launcher/postinstall.cjs +9 -8
  393. package/launcher/runtime-select.cjs +8 -2
  394. package/package.json +3 -2
  395. package/scripts/preinstall-guard.cjs +1 -1
@@ -1,8 +1,16 @@
1
+ import { RequestContextReturns } from "./request-context-returns.js";
2
+ import type { PreparedRequestContextInput, RequestContextRuntimeOwner } from "./request-context-turns.js";
3
+ import type { QuiescenceGate } from "./update-quiescence.js";
4
+ import { RequestContactCards, type RequestContactCardsHost } from "./request-contact-card.js";
5
+ import { RequestContextDrain } from "./request-context-drain.js";
6
+ import { RequestContextMigrationShadow, type RequestMigrationHost } from "./request-context-migration.js";
7
+ import { RequestContactGate, type RequestContactGateHost } from "./request-contact-gate.js";
1
8
  import { WorkingRecoveryStore, type RecoveryEpisode } from "./working-recovery.js";
2
9
  import { type SeenPerson } from "./guest-seen-people.js";
3
10
  import { EventEmitter } from "node:events";
4
11
  import type { QueueResumePolicy } from "./delivery-queue-evidence.js";
5
12
  import { ContactAuthStore } from "./contact-auth-store.js";
13
+ import { RequestContextRecoveryStore } from "./request-context-recovery.js";
6
14
  import { type RequestContextV1, type RequestOperationBindingV1 } from "./request-context-protocol.js";
7
15
  import { type RequestContextCompatibilityOptions } from "./request-context-compatibility.js";
8
16
  import { type RuntimeTranscriptReference } from "./runtime-pane-transcript-protocol.js";
@@ -134,6 +142,7 @@ export declare const SYSTEM_NOTICE_KIND = "system_notice";
134
142
  */
135
143
  export declare const SYSTEM_NOTICE_MAX_AGE_MS: number;
136
144
  export interface DeliveryStatusItem {
145
+ request_provenance?: import("./request-context-view.js").RequestProvenanceView;
137
146
  delivery_id: string;
138
147
  operation_id: string;
139
148
  correlation_id: string | null;
@@ -298,6 +307,9 @@ export declare class DeliveryOutbox extends EventEmitter {
298
307
  get workingRecovery(): WorkingRecoveryStore;
299
308
  admitWorkingRecovery(episode: RecoveryEpisode, content: string, advisory?: boolean): boolean;
300
309
  readonly managerBootId: string;
310
+ /** S-244: while the barrier flag is up, claimNext journals references and claims nothing. Unset: today's claim. */
311
+ private quiescence;
312
+ setQuiescence(gate: QuiescenceGate | null): void;
301
313
  /** Observational extension: its failure never participates in delivery admission. */
302
314
  observeWorkingState(instance: string, snapshot: Omit<WorkingStateSnapshot, "managerBootId">): import("./working-state-journal.js").WorkingStateEntry | null;
303
315
  getWorkingState(instance: string): import("./working-state-journal.js").WorkingStateEntry | undefined;
@@ -330,7 +342,11 @@ export declare class DeliveryOutbox extends EventEmitter {
330
342
  latestSentAt(source: string): number | null;
331
343
  private noteWorkingReferences;
332
344
  private readonly requestContextDispatchVersion;
333
- constructor(dbPath: string, managerBootId?: string, compatibility?: RequestContextCompatibilityOptions);
345
+ private readonly requestContextRelayVersion;
346
+ private requestContextReturnsOwner?;
347
+ constructor(dbPath: string, managerBootId?: string, compatibility?: RequestContextCompatibilityOptions & {
348
+ requestContextRelayVersion?: 0 | 1;
349
+ });
334
350
  /** Future slice L cutover port; all existing production constructors remain capability 0. */
335
351
  activateRequestContextBarrier(): void;
336
352
  private initialize;
@@ -383,11 +399,28 @@ export declare class DeliveryOutbox extends EventEmitter {
383
399
  /** Rows admitted before #856 get the same message_id / digest a new row would. */
384
400
  private backfillMessageEvidence;
385
401
  private ensureColumn;
402
+ /** Internal same-card service; no production host installs it before L. */
403
+ requestContactCards(host: RequestContactCardsHost): RequestContactCards;
404
+ /** Scratch/cutover assembly only; a certificate is process-bound and never persisted as authority. */
405
+ /** Stable Fleet identity while its exclusive coordinator lease is current; never a boot id. */
406
+ requestContextDrain(owner: () => string | null): RequestContextDrain;
407
+ /** Read-only shadow is safe before activation; never initializes contact/context artifacts. */
408
+ requestContextMigrationShadow(host: RequestMigrationHost): RequestContextMigrationShadow;
409
+ /** Dormant central gate; no production caller until the controlled cutover. */
410
+ requestContactGate(host: RequestContactGateHost): RequestContactGate;
411
+ /** H owner assembly only. The ordinary E factory keeps the pre-H hold semantics. */
412
+ requestHubContactGate(host: RequestContactGateHost): RequestContactGate;
386
413
  /** Internal future-dispatch port only; no production ingress calls this before slice L. */
387
414
  admitWithRequestContext(input: NewOutboxDelivery, context: RequestContextV1, bindingInput: RequestOperationBindingV1): {
388
415
  delivery: OutboxDelivery;
389
416
  inserted: boolean;
390
417
  };
418
+ private requireRequestContextRelay;
419
+ /** One dormant B-owned return manager, initialized only behind the active barrier and explicit H capability. */
420
+ get requestContextReturns(): RequestContextReturns;
421
+ prepareRequestContextDeliveryInput(deliveryId: string, attemptNo: number, owner: RequestContextRuntimeOwner, wireSha256: string, currentConsumption: () => boolean): PreparedRequestContextInput;
422
+ /** Internal dormant local-turn persistence; the record alone grants no turn or authority. */
423
+ get requestContextRecovery(): RequestContextRecoveryStore;
391
424
  requestContextForDelivery(deliveryId: string): import("./request-context-store.js").RequestContextOperationRecord | null;
392
425
  requestContext(id: string): RequestContextV1 | null;
393
426
  requestContextOperation(source: string, operationId: string): import("./request-context-store.js").RequestContextOperationRecord | null;
@@ -451,6 +484,11 @@ export declare class DeliveryOutbox extends EventEmitter {
451
484
  /** Claim the earliest eligible target row; one caller owns each target lane. */
452
485
  claimNext(managerBootId: string, targetBootIdFor: (target: string) => string | null, blockedTargets: ReadonlySet<string>, eligible?: (delivery: OutboxDelivery) => boolean): ClaimedOutboxDelivery | undefined;
453
486
  private claimNextSync;
487
+ /**
488
+ * Hand-back claims one referenced row and no other (M-3770 §2.6). The update is conditional, so a second claim
489
+ * does not land. A retry still inside its backoff is `ineligible` and is left queued.
490
+ */
491
+ claimExact(deliveryId: string, managerBootId: string, targetBootId: string, now?: string): "claimed" | "ineligible" | "missing" | "settled";
454
492
  /**
455
493
  * #2785 (b): a message still waiting while a newer one from the same sender to the same target on the same thread
456
494
  * (correlation_id) waits behind it is not delivered — the newer one replaces it (a review round for an older PR head, a
@@ -526,6 +564,9 @@ export declare class DeliveryOutbox extends EventEmitter {
526
564
  * `delivery_status` can return "expired" for a pruned row — but only to the
527
565
  * original source or target (ownership check, #1340 P2 🔒).
528
566
  */
567
+ private pruneDeliveryRows;
568
+ /** Dormant lifecycle port: only drained, terminal roots older than 30 days may retire atomically. */
569
+ private retireRequestContextRoot;
529
570
  prune(days: number): Promise<{
530
571
  pruned: number;
531
572
  durationMs: number;
@@ -1,3 +1,9 @@
1
+ import { assertRequestHubContactImage } from "./request-context-policy.js";
2
+ import { RequestContextReturns, requestContextDeliveryChildId, requestContextReturnBlockers, registerRequestContextReturnDispatcher, assertRequestContextReturnsCompatibility, REQUEST_CONTEXT_RETURNS_TABLE } from "./request-context-returns.js";
3
+ import { RequestContactCards } from "./request-contact-card.js";
4
+ import { RequestContextDrain } from "./request-context-drain.js";
5
+ import { RequestContextMigrationShadow } from "./request-context-migration.js";
6
+ import { RequestContactGate } from "./request-contact-gate.js";
1
7
  import { WorkingRecoveryStore, WORKING_RECOVERY_KIND } from "./working-recovery.js";
2
8
  import { initializeSeenPeople, isSeenPerson, listSeenPeople, noteSeenPerson, pruneSeenPeople, SEEN_PEOPLE_KEEP_DAYS } from "./guest-seen-people.js";
3
9
  import { measureSyncWork } from "./sync-work-attribution.js";
@@ -9,6 +15,7 @@ import { dirname } from "node:path";
9
15
  import { t } from "./locale.js";
10
16
  import { ContactAuthStore } from "./contact-auth-store.js";
11
17
  import { RequestContextStore, requestContextDigest, requestContextJson } from "./request-context-store.js";
18
+ import { RequestContextRecoveryStore } from "./request-context-recovery.js";
12
19
  import { RequestOperationBindingV1Schema } from "./request-context-protocol.js";
13
20
  import { registerRequestContextDispatcher, assertRequestContextCompatibility, activateRequestContextBarrier } from "./request-context-compatibility.js";
14
21
  import { validateRuntimeTranscriptReference } from "./runtime-pane-transcript-protocol.js";
@@ -357,6 +364,9 @@ export class DeliveryOutbox extends EventEmitter {
357
364
  return inserted;
358
365
  }
359
366
  managerBootId;
367
+ /** S-244: while the barrier flag is up, claimNext journals references and claims nothing. Unset: today's claim. */
368
+ quiescence = null;
369
+ setQuiescence(gate) { this.quiescence = gate; }
360
370
  /** Observational extension: its failure never participates in delivery admission. */
361
371
  observeWorkingState(instance, snapshot) {
362
372
  const timeout = this.db.pragma("busy_timeout", { simple: true });
@@ -454,15 +464,22 @@ export class DeliveryOutbox extends EventEmitter {
454
464
  catch { /* observation only */ }
455
465
  }
456
466
  requestContextDispatchVersion;
467
+ requestContextRelayVersion;
468
+ requestContextReturnsOwner;
457
469
  constructor(dbPath, managerBootId = randomUUID(), compatibility = {}) {
458
470
  super();
459
471
  this.managerBootId = managerBootId;
460
472
  this.requestContextDispatchVersion = compatibility.requestContextDispatchVersion ?? 0;
473
+ this.requestContextRelayVersion = compatibility.requestContextRelayVersion ?? 0;
461
474
  mkdirSync(dirname(dbPath), { recursive: true, mode: 0o700 });
462
475
  this.db = new Database(dbPath);
463
476
  try {
464
477
  registerRequestContextDispatcher(this.db, this.requestContextDispatchVersion);
465
478
  assertRequestContextCompatibility(this.db, this.requestContextDispatchVersion);
479
+ registerRequestContextReturnDispatcher(this.db, this.requestContextRelayVersion);
480
+ assertRequestContextReturnsCompatibility(this.db, this.requestContextRelayVersion);
481
+ if (hasTable(this.db, REQUEST_CONTEXT_RETURNS_TABLE))
482
+ this.requestContextReturnsOwner = new RequestContextReturns(this.db, () => this.requireRequestContextRelay());
466
483
  this.initialize(dbPath);
467
484
  }
468
485
  catch (error) {
@@ -895,6 +912,38 @@ export class DeliveryOutbox extends EventEmitter {
895
912
  return;
896
913
  this.db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
897
914
  }
915
+ /** Internal same-card service; no production host installs it before L. */
916
+ requestContactCards(host) {
917
+ return new RequestContactCards(this.db, this.contactAuthorizations, () => this.requestContactGate(host), host);
918
+ }
919
+ /** Scratch/cutover assembly only; a certificate is process-bound and never persisted as authority. */
920
+ /** Stable Fleet identity while its exclusive coordinator lease is current; never a boot id. */
921
+ requestContextDrain(owner) {
922
+ const ready = () => { if (this.requestContextDispatchVersion !== 1 || assertRequestContextCompatibility(this.db, 1) !== "active")
923
+ throw Error("request-context dispatcher is not ready"); };
924
+ ready();
925
+ return new RequestContextDrain(this.db, ready, owner);
926
+ }
927
+ /** Read-only shadow is safe before activation; never initializes contact/context artifacts. */
928
+ requestContextMigrationShadow(host) {
929
+ return new RequestContextMigrationShadow(this.db, host);
930
+ }
931
+ /** Dormant central gate; no production caller until the controlled cutover. */
932
+ requestContactGate(host) {
933
+ const ready = () => {
934
+ if (this.requestContextDispatchVersion !== 1 || assertRequestContextCompatibility(this.db, 1) !== "active")
935
+ throw Error("request-context dispatcher is not ready");
936
+ };
937
+ ready();
938
+ return new RequestContactGate(this.db, this.contactAuthorizations, { ready,
939
+ admit: (input, context, binding) => this.admitWithRequestContext(input, context, binding),
940
+ retire: (root, proof) => this.retireRequestContextRoot(root, proof) }, host);
941
+ }
942
+ /** H owner assembly only. The ordinary E factory keeps the pre-H hold semantics. */
943
+ requestHubContactGate(host) {
944
+ this.requireRequestContextRelay();
945
+ return this.requestContactGate({ ...host, hubRelayAllowed: (context, binding, delivery) => assertRequestHubContactImage(context, binding, delivery) });
946
+ }
898
947
  /** Internal future-dispatch port only; no production ingress calls this before slice L. */
899
948
  admitWithRequestContext(input, context, bindingInput) {
900
949
  if (this.requestContextDispatchVersion !== 1 || assertRequestContextCompatibility(this.db, 1) !== "active") {
@@ -903,6 +952,8 @@ export class DeliveryOutbox extends EventEmitter {
903
952
  const admitted = this.db.transaction(() => {
904
953
  const store = new RequestContextStore(this.db), binding = RequestOperationBindingV1Schema.parse(bindingInput);
905
954
  const stored = store.recordContext(context);
955
+ if (this.requestContextRelayVersion === 1)
956
+ assertRequestHubContactImage(stored, binding, input);
906
957
  if (binding.operationId !== input.operationId || binding.source.instance !== input.sourceInstance
907
958
  || binding.target.instance !== input.targetInstance || binding.contextId !== stored.ref.contextId
908
959
  || binding.rootContextId !== stored.ref.rootContextId || binding.source.instance !== stored.source.instance
@@ -919,6 +970,8 @@ export class DeliveryOutbox extends EventEmitter {
919
970
  const delivery = this.get(prior.deliveryId);
920
971
  if (!delivery || requestContextDigest(delivery.payload) !== binding.payloadSha256)
921
972
  throw Error("request-context delivery unavailable");
973
+ if (this.requestContextRelayVersion === 1)
974
+ this.requestContextReturns.admitted(prior, stored, false);
922
975
  return { delivery, inserted: false };
923
976
  }
924
977
  if (this.db.prepare("SELECT 1 FROM deliveries WHERE source_key=? OR (source_instance=? AND operation_id=?) LIMIT 1")
@@ -928,12 +981,48 @@ export class DeliveryOutbox extends EventEmitter {
928
981
  if (requestContextDigest(admitted.delivery.payload) !== binding.payloadSha256)
929
982
  throw Error("request-context admitted payload changed");
930
983
  store.recordOperation({ binding, sourceKey: input.sourceKey, deliveryId: admitted.delivery.deliveryId, admissionSha256 });
984
+ if (this.requestContextRelayVersion === 1)
985
+ this.requestContextReturns.admitted(store.operation(input.sourceInstance, input.operationId), stored, admitted.inserted);
931
986
  return admitted;
932
987
  })();
933
988
  if (admitted.inserted)
934
989
  this.noteWorkingReferences([input.sourceInstance, input.targetInstance]);
935
990
  return admitted;
936
991
  }
992
+ requireRequestContextRelay() {
993
+ if (this.requestContextRelayVersion !== 1 || this.requestContextDispatchVersion !== 1 || assertRequestContextCompatibility(this.db, 1) !== "active")
994
+ throw Error("request-context relay dispatcher is not ready");
995
+ }
996
+ /** One dormant B-owned return manager, initialized only behind the active barrier and explicit H capability. */
997
+ get requestContextReturns() { this.requireRequestContextRelay(); return this.requestContextReturnsOwner ??= new RequestContextReturns(this.db, () => this.requireRequestContextRelay()); }
998
+ prepareRequestContextDeliveryInput(deliveryId, attemptNo, owner, wireSha256, currentConsumption) {
999
+ this.requireRequestContextRelay();
1000
+ if (!currentConsumption())
1001
+ throw Error("request-context delivery attempt is no longer current");
1002
+ if (!/^[a-f0-9]{64}$/.test(wireSha256) || !Number.isSafeInteger(attemptNo) || attemptNo < 1)
1003
+ throw Error("request-context delivery attempt unavailable");
1004
+ return this.db.transaction(() => {
1005
+ const store = new RequestContextStore(this.db), operation = store.forDelivery(deliveryId), delivery = this.get(deliveryId);
1006
+ if (!operation || !delivery || operation.binding.target.instance !== owner.instance || operation.binding.target.incarnation !== owner.incarnation || delivery.targetSession && delivery.targetSession !== owner.instance)
1007
+ throw Error("request-context delivery target unavailable");
1008
+ const returned = this.requestContextReturns.parentForResponse(deliveryId), parent = store.context(returned?.requesterContextId ?? operation.binding.contextId);
1009
+ if (!parent || parent.ref.rootContextId !== operation.binding.rootContextId)
1010
+ throw Error("request-context delivery parent unavailable");
1011
+ const context = { ...parent, ref: { version: 1, contextId: requestContextDeliveryChildId(deliveryId, operation.binding.target), rootContextId: parent.ref.rootContextId, parentContextId: parent.ref.contextId }, source: { instance: owner.instance, incarnation: owner.incarnation } };
1012
+ const retained = store.recordContext(context), sender = { kind: "peer", ...operation.binding.source };
1013
+ if (!currentConsumption())
1014
+ throw Error("request-context delivery attempt is no longer current");
1015
+ return { inputId: `delivery:${deliveryId}:${attemptNo}`, wireSha256, owner: structuredClone(owner), context: retained,
1016
+ proof: returned ? { kind: "expected-return", parentContextId: parent.ref.contextId, expectedSender: { kind: "peer", ...returned.responder }, actualSender: sender } : { kind: "admitted-delivery", parentContextId: parent.ref.contextId, deliveryId, sender } };
1017
+ })();
1018
+ }
1019
+ /** Internal dormant local-turn persistence; the record alone grants no turn or authority. */
1020
+ get requestContextRecovery() {
1021
+ return new RequestContextRecoveryStore(this.db, () => {
1022
+ if (this.requestContextDispatchVersion !== 1 || assertRequestContextCompatibility(this.db, 1) !== "active")
1023
+ throw Error("request-context dispatcher is not ready");
1024
+ });
1025
+ }
937
1026
  requestContextForDelivery(deliveryId) { return new RequestContextStore(this.db).forDelivery(deliveryId); }
938
1027
  requestContext(id) { return new RequestContextStore(this.db).context(id); }
939
1028
  requestContextOperation(source, operationId) { return new RequestContextStore(this.db).operation(source, operationId); }
@@ -1195,6 +1284,13 @@ export class DeliveryOutbox extends EventEmitter {
1195
1284
  return measureSyncWork("outbox.claimNext", () => this.claimNextSync(managerBootId, targetBootIdFor, blockedTargets, eligible));
1196
1285
  }
1197
1286
  claimNextSync(managerBootId, targetBootIdFor, blockedTargets, eligible) {
1287
+ const gate = this.quiescence;
1288
+ if (gate?.armed()) {
1289
+ const held = this.db.prepare(`SELECT delivery_id, created_seq FROM deliveries WHERE state IN ('queued','retry_wait') ORDER BY created_seq`).all();
1290
+ for (const row of held)
1291
+ gate.holdOutboxClaim(row.delivery_id, row.created_seq);
1292
+ return undefined;
1293
+ }
1198
1294
  const now = new Date().toISOString();
1199
1295
  const pending = this.db.prepare(`
1200
1296
  SELECT * FROM deliveries WHERE state IN ('queued','retry_wait')
@@ -1240,6 +1336,26 @@ export class DeliveryOutbox extends EventEmitter {
1240
1336
  }
1241
1337
  return undefined;
1242
1338
  }
1339
+ /**
1340
+ * Hand-back claims one referenced row and no other (M-3770 §2.6). The update is conditional, so a second claim
1341
+ * does not land. A retry still inside its backoff is `ineligible` and is left queued.
1342
+ */
1343
+ claimExact(deliveryId, managerBootId, targetBootId, now = new Date().toISOString()) {
1344
+ const row = this.get(deliveryId);
1345
+ if (!row)
1346
+ return "missing";
1347
+ if (row.state !== "queued" && row.state !== "retry_wait")
1348
+ return "settled";
1349
+ if (row.state === "retry_wait" && row.nextAttemptAt && row.nextAttemptAt > now)
1350
+ return "ineligible";
1351
+ const result = this.db.prepare(`
1352
+ UPDATE deliveries
1353
+ SET state='delivering', target_daemon_boot_id=?, manager_boot_id=?,
1354
+ attempt_no=attempt_no+1, updated_at=?, last_error=NULL, next_attempt_at=NULL
1355
+ WHERE delivery_id=? AND state IN ('queued','retry_wait')
1356
+ `).run(targetBootId, managerBootId, now, deliveryId);
1357
+ return result.changes === 1 ? "claimed" : "settled";
1358
+ }
1243
1359
  /**
1244
1360
  * #2785 (b): a message still waiting while a newer one from the same sender to the same target on the same thread
1245
1361
  * (correlation_id) waits behind it is not delivered — the newer one replaces it (a review round for an older PR head, a
@@ -1766,6 +1882,82 @@ export class DeliveryOutbox extends EventEmitter {
1766
1882
  * `delivery_status` can return "expired" for a pruned row — but only to the
1767
1883
  * original source or target (ownership check, #1340 P2 🔒).
1768
1884
  */
1885
+ pruneDeliveryRows(rows, now) {
1886
+ const ids = rows.map(row => row.delivery_id);
1887
+ if (!ids.length)
1888
+ return;
1889
+ const placeholders = ids.map(() => "?").join(",");
1890
+ // Record (delivery_id, source, target) so delivery_status can return
1891
+ // "expired" to the row's own source/target (ownership-gated).
1892
+ const insertPruned = this.db.prepare("INSERT OR IGNORE INTO pruned_ids(delivery_id, source_instance, target_instance, pruned_at) VALUES (?, ?, ?, ?)");
1893
+ for (const row of rows)
1894
+ insertPruned.run(row.delivery_id, row.source_instance, row.target_instance, now);
1895
+ // Delete child rows first.
1896
+ this.db.prepare(`DELETE FROM delivery_attempts WHERE delivery_id IN (${placeholders})`).run(...ids);
1897
+ // Only closed reply_obligations (answered/expired): open ones were excluded above.
1898
+ if (hasTable(this.db, "reply_obligations")) {
1899
+ this.db.prepare(`
1900
+ DELETE FROM reply_obligations
1901
+ WHERE request_delivery_id IN (${placeholders}) AND state IN ('answered','expired')
1902
+ `).run(...ids);
1903
+ }
1904
+ this.db.prepare(`DELETE FROM outcome_notices WHERE notice_delivery_id IN (${placeholders})`).run(...ids);
1905
+ this.db.prepare(`DELETE FROM failure_notices WHERE parent_delivery_id IN (${placeholders}) OR notice_delivery_id IN (${placeholders})`).run(...ids, ...ids);
1906
+ this.db.prepare(`DELETE FROM delivery_forward_edges WHERE reference_kind='delivery' AND reference_id IN (${placeholders})`).run(...ids);
1907
+ this.db.prepare(`DELETE FROM deliveries WHERE delivery_id IN (${placeholders})`).run(...ids);
1908
+ }
1909
+ /** Dormant lifecycle port: only drained, terminal roots older than 30 days may retire atomically. */
1910
+ retireRequestContextRoot(root, retired) {
1911
+ if (this.requestContextDispatchVersion !== 1 || assertRequestContextCompatibility(this.db, 1) !== "active")
1912
+ throw Error("request-context dispatcher is not ready");
1913
+ return this.db.transaction(() => {
1914
+ const store = new RequestContextStore(this.db), context = store.context(root);
1915
+ if (!context || context.ref.rootContextId !== root || context.ref.parentContextId || !retired())
1916
+ throw Error("request-context root is not drained");
1917
+ const ids = this.db.prepare("SELECT context_id FROM request_contexts_v1 WHERE json_extract(context_json,'$.ref.rootContextId')=?").all(root).map(row => row.context_id);
1918
+ const slots = "SELECT context_id FROM request_contexts_v1 WHERE json_extract(context_json,'$.ref.rootContextId')=?", cutoff = new Date(Date.now() - 30 * 24 * 60 * 60_000).toISOString();
1919
+ const rows = this.db.prepare(`SELECT d.delivery_id,d.source_instance,d.target_instance,d.state,COALESCE(d.finished_at,d.updated_at) AS at
1920
+ FROM deliveries d JOIN request_context_operations_v1 o ON o.delivery_id=d.delivery_id WHERE o.context_id IN (${slots})`).all(root);
1921
+ if (rows.some(row => !["delivered", "failed", "cancelled"].includes(row.state) || !Number.isFinite(Date.parse(row.at)) || Date.parse(row.at) >= Date.parse(cutoff)))
1922
+ throw Error("request-context root retention not elapsed");
1923
+ if (this.db.prepare(`SELECT 1 FROM reply_obligations WHERE state='open' AND request_delivery_id IN (SELECT delivery_id FROM request_context_operations_v1 WHERE context_id IN (${slots})) LIMIT 1`).get(root))
1924
+ throw Error("request-context root has open reply");
1925
+ if (hasTable(this.db, "request_context_recovery_v1") && this.db.prepare(`SELECT 1 FROM request_context_recovery_v1 WHERE json_extract(pointer_json,'$.contextId') IN (${slots}) LIMIT 1`).get(root))
1926
+ throw Error("request-context root has recovery reference");
1927
+ if (hasTable(this.db, "request_context_contacts_v1")) {
1928
+ const tickets = this.db.prepare("SELECT t.id,t.ticket_json FROM contact_auth_tickets t JOIN request_context_contacts_v1 c ON c.ticket_id=t.id WHERE c.root_id=?").all(root);
1929
+ const resolved = tickets.map(row => this.contactAuthorizations.get(row.id));
1930
+ if (resolved.some(t => { if (!t)
1931
+ return true; const at = Date.parse(t.decidedAt ?? t.expiresAt ?? t.createdAt); return !['approved', 'delivered', 'declined', 'expired'].includes(t.state) || !Number.isFinite(at) || at >= Date.parse(cutoff); }))
1932
+ throw Error("request-context root has retained ticket");
1933
+ for (const ticket of tickets) {
1934
+ this.db.prepare("DELETE FROM contact_auth_outcome_notices WHERE ticket_id=?").run(ticket.id);
1935
+ this.db.prepare("DELETE FROM contact_auth_approval_notices WHERE ticket_id=?").run(ticket.id);
1936
+ }
1937
+ this.db.prepare("DELETE FROM request_context_contacts_v1 WHERE root_id=?").run(root);
1938
+ for (const ticket of tickets)
1939
+ this.db.prepare("DELETE FROM contact_auth_tickets WHERE id=?").run(ticket.id);
1940
+ }
1941
+ if (hasTable(this.db, REQUEST_CONTEXT_RETURNS_TABLE)) {
1942
+ this.requestContextReturns.closeNonDelivery(root);
1943
+ if (requestContextReturnBlockers(this.db, root).length)
1944
+ throw Error("request-context root has expected return");
1945
+ this.db.prepare(`DELETE FROM ${REQUEST_CONTEXT_RETURNS_TABLE} WHERE root_context_id=?`).run(root);
1946
+ }
1947
+ this.db.prepare(`DELETE FROM request_context_operations_v1 WHERE context_id IN (${slots})`).run(root);
1948
+ this.pruneDeliveryRows(rows, new Date().toISOString());
1949
+ // Single-parent contexts are deleted leaves first; no dependent recovery/ledger/work may remain.
1950
+ for (let left = ids.length; left > 0;) {
1951
+ const changed = this.db.prepare(`DELETE FROM request_contexts_v1 WHERE context_id IN (${slots}) AND context_id NOT IN (SELECT parent_id FROM request_contexts_v1 WHERE parent_id IS NOT NULL)`).run(root).changes;
1952
+ if (!changed)
1953
+ throw Error("request-context root has external descendant");
1954
+ left -= changed;
1955
+ }
1956
+ if (!retired())
1957
+ throw Error("request-context root retirement changed");
1958
+ return rows.length;
1959
+ })();
1960
+ }
1769
1961
  async prune(days) {
1770
1962
  const { performance } = await import("node:perf_hooks");
1771
1963
  const t0 = performance.now();
@@ -1787,6 +1979,7 @@ export class DeliveryOutbox extends EventEmitter {
1787
1979
  FROM deliveries
1788
1980
  WHERE state IN ${PRUNABLE}
1789
1981
  AND COALESCE(finished_at, updated_at) < ?
1982
+ ${hasTable(this.db, "request_context_operations_v1") ? "AND delivery_id NOT IN (SELECT delivery_id FROM request_context_operations_v1)" : ""}
1790
1983
  AND (
1791
1984
  NOT EXISTS (SELECT 1 FROM reply_obligations WHERE request_delivery_id = delivery_id AND state = 'open')
1792
1985
  )
@@ -1795,27 +1988,8 @@ export class DeliveryOutbox extends EventEmitter {
1795
1988
  `).all(cutoff);
1796
1989
  if (rows.length === 0)
1797
1990
  break;
1798
- const ids = rows.map(r => r.delivery_id);
1799
- const placeholders = ids.map(() => "?").join(",");
1800
1991
  this.db.transaction(() => {
1801
- // Record (delivery_id, source, target) so delivery_status can return
1802
- // "expired" to the row's own source/target (ownership-gated).
1803
- const insertPruned = this.db.prepare("INSERT OR IGNORE INTO pruned_ids(delivery_id, source_instance, target_instance, pruned_at) VALUES (?, ?, ?, ?)");
1804
- for (const row of rows)
1805
- insertPruned.run(row.delivery_id, row.source_instance, row.target_instance, now);
1806
- // Delete child rows first.
1807
- this.db.prepare(`DELETE FROM delivery_attempts WHERE delivery_id IN (${placeholders})`).run(...ids);
1808
- // Only closed reply_obligations (answered/expired): open ones were excluded above.
1809
- if (hasTable(this.db, "reply_obligations")) {
1810
- this.db.prepare(`
1811
- DELETE FROM reply_obligations
1812
- WHERE request_delivery_id IN (${placeholders}) AND state IN ('answered','expired')
1813
- `).run(...ids);
1814
- }
1815
- this.db.prepare(`DELETE FROM outcome_notices WHERE notice_delivery_id IN (${placeholders})`).run(...ids);
1816
- this.db.prepare(`DELETE FROM failure_notices WHERE parent_delivery_id IN (${placeholders}) OR notice_delivery_id IN (${placeholders})`).run(...ids, ...ids);
1817
- this.db.prepare(`DELETE FROM delivery_forward_edges WHERE reference_kind='delivery' AND reference_id IN (${placeholders})`).run(...ids);
1818
- this.db.prepare(`DELETE FROM deliveries WHERE delivery_id IN (${placeholders})`).run(...ids);
1992
+ this.pruneDeliveryRows(rows, now);
1819
1993
  })();
1820
1994
  total += rows.length;
1821
1995
  if (rows.length < CHUNK)