@openrig/cli 0.7.9 → 0.7.11

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 (793) hide show
  1. package/README.md +5 -5
  2. package/daemon/assets/claude-permission-policies.cjs +41 -0
  3. package/daemon/assets/claude-permission-policies.d.cts +3 -0
  4. package/daemon/assets/claude-team-permissions.cjs +13 -3
  5. package/daemon/assets/openshell/README.md +1 -1
  6. package/daemon/assets/openshell/guest.py +3 -2
  7. package/daemon/assets/pi-account-lock.cjs +39 -0
  8. package/daemon/assets/plugins/openrig/.claude-plugin/marketplace.json +15 -0
  9. package/daemon/assets/plugins/openrig/.claude-plugin/plugin.json +32 -0
  10. package/daemon/assets/plugins/openrig/.codex-plugin/plugin.json +39 -0
  11. package/daemon/assets/plugins/openrig/.cursor-plugin/plugin.json +6 -0
  12. package/daemon/assets/plugins/openrig/LICENSE +200 -0
  13. package/daemon/assets/plugins/openrig/README.md +106 -0
  14. package/daemon/assets/plugins/openrig/assets/logo.svg +1 -0
  15. package/daemon/assets/plugins/openrig/mcp.json +10 -0
  16. package/daemon/assets/plugins/openrig/plugin.json +14 -0
  17. package/daemon/assets/plugins/openrig/skills/working-with-an-openrig-team/SKILL.md +90 -0
  18. package/daemon/assets/plugins/openrig-core/.claude-plugin/plugin.json +1 -1
  19. package/daemon/assets/plugins/openrig-core/.codex-plugin/plugin.json +1 -1
  20. package/daemon/assets/plugins/openrig-core/hooks/claude.json +11 -0
  21. package/daemon/assets/plugins/openrig-core/hooks/scripts/activity-relay.cjs +39 -0
  22. package/daemon/assets/plugins/openrig-core/hooks/scripts/permission-stop-descriptor.cjs +221 -0
  23. package/daemon/assets/plugins/openrig-core/hooks/scripts/refocus.cjs +16 -2
  24. package/daemon/assets/plugins/openrig-core/skills/openrig-skills/SKILL.md +1 -0
  25. package/daemon/assets/plugins/openrig-core/skills/openrig-user/SKILL.md +24 -8
  26. package/daemon/assets/plugins/openrig-core/skills/refocusing/SKILL.md +5 -0
  27. package/daemon/assets/plugins/openrig-core/skills/refocusing/scripts/trace-to-root.py +39 -4
  28. package/daemon/assets/skills/rigs/SKILL.md +10 -3
  29. package/daemon/context-packs/help/manifest.yaml +1 -1
  30. package/daemon/context-packs/onboarding-width/manifest.yaml +1 -1
  31. package/daemon/context-packs/onboarding-width/public-what-you-can-do.md +122 -17
  32. package/daemon/context-packs/reference/acp-agents.md +176 -2
  33. package/daemon/context-packs/reference/getting-started.md +23 -4
  34. package/daemon/context-packs/reference/manifest.yaml +4 -1
  35. package/daemon/context-packs/reference/rig-spec.md +64 -7
  36. package/daemon/context-packs/reference/tmux-servers.md +214 -0
  37. package/daemon/context-packs/reference/whats-new.md +484 -76
  38. package/daemon/context-packs/skills/agent-operated-software/manifest.yaml +1 -1
  39. package/daemon/context-packs/skills/agent-operated-workflows/manifest.yaml +1 -1
  40. package/daemon/context-packs/skills/applying-a-permission-policy/manifest.yaml +1 -1
  41. package/daemon/context-packs/skills/claude-compaction-restore/manifest.yaml +1 -1
  42. package/daemon/context-packs/skills/core/agent-starters/manifest.yaml +1 -1
  43. package/daemon/context-packs/skills/core/agent-startup-and-context-ingestion/manifest.yaml +1 -1
  44. package/daemon/context-packs/skills/core/cross-host-rig-commands/SKILL.md +7 -0
  45. package/daemon/context-packs/skills/core/cross-host-rig-commands/manifest.yaml +1 -1
  46. package/daemon/context-packs/skills/core/human-in-the-loop/manifest.yaml +1 -1
  47. package/daemon/context-packs/skills/core/messaging-the-human/manifest.yaml +1 -1
  48. package/daemon/context-packs/skills/core/openrig-architect/manifest.yaml +1 -1
  49. package/daemon/context-packs/skills/core/openrig-cmux/manifest.yaml +1 -1
  50. package/daemon/context-packs/skills/core/openrig-herdr/manifest.yaml +1 -1
  51. package/daemon/context-packs/skills/core/openrig-skills/SKILL.md +1 -0
  52. package/daemon/context-packs/skills/core/openrig-skills/manifest.yaml +1 -1
  53. package/daemon/context-packs/skills/core/openrig-software-factory/manifest.yaml +1 -1
  54. package/daemon/context-packs/skills/core/openrig-upgrade/manifest.yaml +1 -1
  55. package/daemon/context-packs/skills/core/rig-bundles-and-shareable-artifacts/manifest.yaml +1 -1
  56. package/daemon/context-packs/skills/core/rig-lifecycle/manifest.yaml +1 -1
  57. package/daemon/context-packs/skills/core/session-source-fork/manifest.yaml +1 -1
  58. package/daemon/context-packs/skills/core/specification-system/manifest.yaml +1 -1
  59. package/daemon/context-packs/skills/core/topology-mutation-and-seat-management/manifest.yaml +1 -1
  60. package/daemon/context-packs/skills/core/watchdog/manifest.yaml +1 -1
  61. package/daemon/context-packs/skills/core/working-with-an-openrig-team/SKILL.md +90 -0
  62. package/daemon/context-packs/skills/core/working-with-an-openrig-team/manifest.yaml +10 -0
  63. package/daemon/context-packs/skills/delegating-work/manifest.yaml +1 -1
  64. package/daemon/context-packs/skills/forming-an-openrig-mental-model/manifest.yaml +1 -1
  65. package/daemon/context-packs/skills/loading-addressable-markdown/manifest.yaml +1 -1
  66. package/daemon/context-packs/skills/mission-slice-sop/manifest.yaml +1 -1
  67. package/daemon/context-packs/skills/openrig-operating-model/manifest.yaml +1 -1
  68. package/daemon/context-packs/skills/openrig-user/SKILL.md +24 -8
  69. package/daemon/context-packs/skills/openrig-user/manifest.yaml +1 -1
  70. package/daemon/context-packs/skills/orienting-to-an-inherited-seat/manifest.yaml +1 -1
  71. package/daemon/context-packs/skills/pm/backlog-capture/manifest.yaml +1 -1
  72. package/daemon/context-packs/skills/pm/context-builder/manifest.yaml +1 -1
  73. package/daemon/context-packs/skills/pm/exec-summary/manifest.yaml +1 -1
  74. package/daemon/context-packs/skills/pm/office-hours/manifest.yaml +1 -1
  75. package/daemon/context-packs/skills/pm/plan-review/manifest.yaml +1 -1
  76. package/daemon/context-packs/skills/pm/requirements-writer/manifest.yaml +1 -1
  77. package/daemon/context-packs/skills/pm/ui-mockup/manifest.yaml +1 -1
  78. package/daemon/context-packs/skills/pods/development-team/manifest.yaml +1 -1
  79. package/daemon/context-packs/skills/pods/orchestration-team/manifest.yaml +1 -1
  80. package/daemon/context-packs/skills/pods/oversight-team/manifest.yaml +1 -1
  81. package/daemon/context-packs/skills/pods/review-team/manifest.yaml +1 -1
  82. package/daemon/context-packs/skills/process/agent-browser/manifest.yaml +1 -1
  83. package/daemon/context-packs/skills/process/context-engineering/manifest.yaml +1 -1
  84. package/daemon/context-packs/skills/process/dogfood/manifest.yaml +1 -1
  85. package/daemon/context-packs/skills/process/frontend-design/manifest.yaml +1 -1
  86. package/daemon/context-packs/skills/process/systematic-debugging/manifest.yaml +1 -1
  87. package/daemon/context-packs/skills/process/test-driven-development/manifest.yaml +1 -1
  88. package/daemon/context-packs/skills/process/verification-before-completion/manifest.yaml +1 -1
  89. package/daemon/context-packs/skills/queue-handoff/manifest.yaml +1 -1
  90. package/daemon/context-packs/skills/refocusing/SKILL.md +5 -0
  91. package/daemon/context-packs/skills/refocusing/manifest.yaml +1 -1
  92. package/daemon/context-packs/skills/refocusing/scripts/trace-to-root.py +39 -4
  93. package/daemon/context-packs/skills/retiring-and-inheriting-a-seat/manifest.yaml +1 -1
  94. package/daemon/context-packs/skills/seat-continuity-and-handover/manifest.yaml +1 -1
  95. package/daemon/context-packs/skills/session-compaction-and-restore/manifest.yaml +1 -1
  96. package/daemon/context-packs/skills/software-for-agents/manifest.yaml +1 -1
  97. package/daemon/context-packs/world-example/manifest.yaml +1 -1
  98. package/daemon/context-packs/world-public/manifest.yaml +1 -1
  99. package/daemon/dist/adapters/claude-code-adapter.d.ts +3 -1
  100. package/daemon/dist/adapters/claude-code-adapter.d.ts.map +1 -1
  101. package/daemon/dist/adapters/claude-code-adapter.js +53 -12
  102. package/daemon/dist/adapters/claude-code-adapter.js.map +1 -1
  103. package/daemon/dist/adapters/claude-resume.d.ts +1 -1
  104. package/daemon/dist/adapters/claude-resume.d.ts.map +1 -1
  105. package/daemon/dist/adapters/claude-resume.js +17 -3
  106. package/daemon/dist/adapters/claude-resume.js.map +1 -1
  107. package/daemon/dist/adapters/codex-resume.d.ts +3 -1
  108. package/daemon/dist/adapters/codex-resume.d.ts.map +1 -1
  109. package/daemon/dist/adapters/codex-resume.js +8 -4
  110. package/daemon/dist/adapters/codex-resume.js.map +1 -1
  111. package/daemon/dist/adapters/codex-runtime-adapter.d.ts +6 -0
  112. package/daemon/dist/adapters/codex-runtime-adapter.d.ts.map +1 -1
  113. package/daemon/dist/adapters/codex-runtime-adapter.js +49 -19
  114. package/daemon/dist/adapters/codex-runtime-adapter.js.map +1 -1
  115. package/daemon/dist/adapters/kernel-authority.d.ts +2 -4
  116. package/daemon/dist/adapters/kernel-authority.d.ts.map +1 -1
  117. package/daemon/dist/adapters/kernel-authority.js +10 -41
  118. package/daemon/dist/adapters/kernel-authority.js.map +1 -1
  119. package/daemon/dist/adapters/openshell-podman-observer.d.ts.map +1 -1
  120. package/daemon/dist/adapters/openshell-podman-observer.js +25 -20
  121. package/daemon/dist/adapters/openshell-podman-observer.js.map +1 -1
  122. package/daemon/dist/adapters/pi-resume.d.ts +4 -1
  123. package/daemon/dist/adapters/pi-resume.d.ts.map +1 -1
  124. package/daemon/dist/adapters/pi-resume.js +38 -9
  125. package/daemon/dist/adapters/pi-resume.js.map +1 -1
  126. package/daemon/dist/adapters/pi-runner-protocol.d.ts +4 -0
  127. package/daemon/dist/adapters/pi-runner-protocol.d.ts.map +1 -1
  128. package/daemon/dist/adapters/pi-runner-protocol.js +7 -0
  129. package/daemon/dist/adapters/pi-runner-protocol.js.map +1 -1
  130. package/daemon/dist/adapters/pi-runner.d.ts +5 -0
  131. package/daemon/dist/adapters/pi-runner.d.ts.map +1 -1
  132. package/daemon/dist/adapters/pi-runner.js +79 -8
  133. package/daemon/dist/adapters/pi-runner.js.map +1 -1
  134. package/daemon/dist/adapters/pi-runtime-adapter.d.ts +6 -0
  135. package/daemon/dist/adapters/pi-runtime-adapter.d.ts.map +1 -1
  136. package/daemon/dist/adapters/pi-runtime-adapter.js +58 -23
  137. package/daemon/dist/adapters/pi-runtime-adapter.js.map +1 -1
  138. package/daemon/dist/adapters/tmux-control.d.ts +32 -1
  139. package/daemon/dist/adapters/tmux-control.d.ts.map +1 -1
  140. package/daemon/dist/adapters/tmux-control.js +149 -9
  141. package/daemon/dist/adapters/tmux-control.js.map +1 -1
  142. package/daemon/dist/adapters/tmux-server.d.ts +9 -0
  143. package/daemon/dist/adapters/tmux-server.d.ts.map +1 -1
  144. package/daemon/dist/adapters/tmux-server.js +12 -0
  145. package/daemon/dist/adapters/tmux-server.js.map +1 -1
  146. package/daemon/dist/adapters/tmux.d.ts +21 -1
  147. package/daemon/dist/adapters/tmux.d.ts.map +1 -1
  148. package/daemon/dist/adapters/tmux.js +184 -14
  149. package/daemon/dist/adapters/tmux.js.map +1 -1
  150. package/daemon/dist/build-info.js +3 -3
  151. package/daemon/dist/db/all-migrations.d.ts.map +1 -1
  152. package/daemon/dist/db/all-migrations.js +10 -0
  153. package/daemon/dist/db/all-migrations.js.map +1 -1
  154. package/daemon/dist/db/migrations/150_node_launch_wrapper.d.ts +3 -0
  155. package/daemon/dist/db/migrations/150_node_launch_wrapper.d.ts.map +1 -0
  156. package/daemon/dist/db/migrations/150_node_launch_wrapper.js +5 -0
  157. package/daemon/dist/db/migrations/150_node_launch_wrapper.js.map +1 -0
  158. package/daemon/dist/db/migrations/151_pi_account_switches.d.ts +4 -0
  159. package/daemon/dist/db/migrations/151_pi_account_switches.d.ts.map +1 -0
  160. package/daemon/dist/db/migrations/151_pi_account_switches.js +44 -0
  161. package/daemon/dist/db/migrations/151_pi_account_switches.js.map +1 -0
  162. package/daemon/dist/db/migrations/152_workflow_instance_spec.d.ts +8 -0
  163. package/daemon/dist/db/migrations/152_workflow_instance_spec.d.ts.map +1 -0
  164. package/daemon/dist/db/migrations/152_workflow_instance_spec.js +13 -0
  165. package/daemon/dist/db/migrations/152_workflow_instance_spec.js.map +1 -0
  166. package/daemon/dist/db/migrations/153_events_retention_marks.d.ts +7 -0
  167. package/daemon/dist/db/migrations/153_events_retention_marks.d.ts.map +1 -0
  168. package/daemon/dist/db/migrations/153_events_retention_marks.js +17 -0
  169. package/daemon/dist/db/migrations/153_events_retention_marks.js.map +1 -0
  170. package/daemon/dist/db/migrations/154_workflow_instance_root_objective.d.ts +7 -0
  171. package/daemon/dist/db/migrations/154_workflow_instance_root_objective.d.ts.map +1 -0
  172. package/daemon/dist/db/migrations/154_workflow_instance_root_objective.js +11 -0
  173. package/daemon/dist/db/migrations/154_workflow_instance_root_objective.js.map +1 -0
  174. package/daemon/dist/domain/activity-taxonomy.d.ts +9 -0
  175. package/daemon/dist/domain/activity-taxonomy.d.ts.map +1 -1
  176. package/daemon/dist/domain/activity-taxonomy.js.map +1 -1
  177. package/daemon/dist/domain/agent-activity-store.d.ts +14 -0
  178. package/daemon/dist/domain/agent-activity-store.d.ts.map +1 -1
  179. package/daemon/dist/domain/agent-activity-store.js +33 -0
  180. package/daemon/dist/domain/agent-activity-store.js.map +1 -1
  181. package/daemon/dist/domain/agent-manifest.d.ts.map +1 -1
  182. package/daemon/dist/domain/agent-manifest.js +47 -9
  183. package/daemon/dist/domain/agent-manifest.js.map +1 -1
  184. package/daemon/dist/domain/agent-resolver.d.ts +8 -0
  185. package/daemon/dist/domain/agent-resolver.d.ts.map +1 -1
  186. package/daemon/dist/domain/agent-resolver.js +6 -1
  187. package/daemon/dist/domain/agent-resolver.js.map +1 -1
  188. package/daemon/dist/domain/claude-compaction-enforcer.d.ts +55 -3
  189. package/daemon/dist/domain/claude-compaction-enforcer.d.ts.map +1 -1
  190. package/daemon/dist/domain/claude-compaction-enforcer.js +339 -31
  191. package/daemon/dist/domain/claude-compaction-enforcer.js.map +1 -1
  192. package/daemon/dist/domain/claude-managed-launch.d.ts +2 -0
  193. package/daemon/dist/domain/claude-managed-launch.d.ts.map +1 -1
  194. package/daemon/dist/domain/claude-managed-launch.js +12 -2
  195. package/daemon/dist/domain/claude-managed-launch.js.map +1 -1
  196. package/daemon/dist/domain/compaction-restore-notice.d.ts +1 -1
  197. package/daemon/dist/domain/compaction-restore-notice.d.ts.map +1 -1
  198. package/daemon/dist/domain/compaction-restore-notice.js +2 -1
  199. package/daemon/dist/domain/compaction-restore-notice.js.map +1 -1
  200. package/daemon/dist/domain/context-monitor.d.ts.map +1 -1
  201. package/daemon/dist/domain/context-monitor.js +3 -0
  202. package/daemon/dist/domain/context-monitor.js.map +1 -1
  203. package/daemon/dist/domain/context-usage-store.d.ts.map +1 -1
  204. package/daemon/dist/domain/context-usage-store.js +10 -1
  205. package/daemon/dist/domain/context-usage-store.js.map +1 -1
  206. package/daemon/dist/domain/desired-claude-activity-hooks.d.ts +4 -3
  207. package/daemon/dist/domain/desired-claude-activity-hooks.d.ts.map +1 -1
  208. package/daemon/dist/domain/desired-claude-activity-hooks.js +49 -15
  209. package/daemon/dist/domain/desired-claude-activity-hooks.js.map +1 -1
  210. package/daemon/dist/domain/draft-aware-delivery.d.ts.map +1 -1
  211. package/daemon/dist/domain/draft-aware-delivery.js +5 -1
  212. package/daemon/dist/domain/draft-aware-delivery.js.map +1 -1
  213. package/daemon/dist/domain/event-bus.d.ts +31 -0
  214. package/daemon/dist/domain/event-bus.d.ts.map +1 -1
  215. package/daemon/dist/domain/event-bus.js +88 -2
  216. package/daemon/dist/domain/event-bus.js.map +1 -1
  217. package/daemon/dist/domain/execution-view.d.ts +9 -0
  218. package/daemon/dist/domain/execution-view.d.ts.map +1 -1
  219. package/daemon/dist/domain/execution-view.js +91 -50
  220. package/daemon/dist/domain/execution-view.js.map +1 -1
  221. package/daemon/dist/domain/gateway/connections-projection.d.ts +13 -1
  222. package/daemon/dist/domain/gateway/connections-projection.d.ts.map +1 -1
  223. package/daemon/dist/domain/gateway/connections-projection.js +38 -10
  224. package/daemon/dist/domain/gateway/connections-projection.js.map +1 -1
  225. package/daemon/dist/domain/gateway/dispatcher.d.ts +2 -0
  226. package/daemon/dist/domain/gateway/dispatcher.d.ts.map +1 -1
  227. package/daemon/dist/domain/gateway/dispatcher.js +14 -1
  228. package/daemon/dist/domain/gateway/dispatcher.js.map +1 -1
  229. package/daemon/dist/domain/gateway/gateway-subsystem.d.ts +2 -0
  230. package/daemon/dist/domain/gateway/gateway-subsystem.d.ts.map +1 -1
  231. package/daemon/dist/domain/gateway/gateway-subsystem.js +1 -0
  232. package/daemon/dist/domain/gateway/gateway-subsystem.js.map +1 -1
  233. package/daemon/dist/domain/gateway/human-readiness.d.ts +7 -0
  234. package/daemon/dist/domain/gateway/human-readiness.d.ts.map +1 -1
  235. package/daemon/dist/domain/gateway/human-readiness.js +45 -0
  236. package/daemon/dist/domain/gateway/human-readiness.js.map +1 -1
  237. package/daemon/dist/domain/gateway/human-registry.d.ts +23 -3
  238. package/daemon/dist/domain/gateway/human-registry.d.ts.map +1 -1
  239. package/daemon/dist/domain/gateway/human-registry.js +66 -34
  240. package/daemon/dist/domain/gateway/human-registry.js.map +1 -1
  241. package/daemon/dist/domain/gateway/operator-delivery-engine.d.ts.map +1 -1
  242. package/daemon/dist/domain/gateway/operator-delivery-engine.js +8 -2
  243. package/daemon/dist/domain/gateway/operator-delivery-engine.js.map +1 -1
  244. package/daemon/dist/domain/gateway/relay-config.d.ts +80 -0
  245. package/daemon/dist/domain/gateway/relay-config.d.ts.map +1 -0
  246. package/daemon/dist/domain/gateway/relay-config.js +290 -0
  247. package/daemon/dist/domain/gateway/relay-config.js.map +1 -0
  248. package/daemon/dist/domain/gateway/relay-inbound.d.ts +74 -0
  249. package/daemon/dist/domain/gateway/relay-inbound.d.ts.map +1 -0
  250. package/daemon/dist/domain/gateway/relay-inbound.js +739 -0
  251. package/daemon/dist/domain/gateway/relay-inbound.js.map +1 -0
  252. package/daemon/dist/domain/gateway/relay-outbound.d.ts +215 -0
  253. package/daemon/dist/domain/gateway/relay-outbound.d.ts.map +1 -0
  254. package/daemon/dist/domain/gateway/relay-outbound.js +770 -0
  255. package/daemon/dist/domain/gateway/relay-outbound.js.map +1 -0
  256. package/daemon/dist/domain/gateway/slack/inbound.d.ts +4 -0
  257. package/daemon/dist/domain/gateway/slack/inbound.d.ts.map +1 -1
  258. package/daemon/dist/domain/gateway/slack/inbound.js +14 -2
  259. package/daemon/dist/domain/gateway/slack/inbound.js.map +1 -1
  260. package/daemon/dist/domain/gateway/slack/open-asks.d.ts.map +1 -1
  261. package/daemon/dist/domain/gateway/slack/open-asks.js +14 -1
  262. package/daemon/dist/domain/gateway/slack/open-asks.js.map +1 -1
  263. package/daemon/dist/domain/gateway/slack/slack-subsystem.d.ts.map +1 -1
  264. package/daemon/dist/domain/gateway/slack/slack-subsystem.js +225 -32
  265. package/daemon/dist/domain/gateway/slack/slack-subsystem.js.map +1 -1
  266. package/daemon/dist/domain/hosts/pairing-ask.d.ts +10 -0
  267. package/daemon/dist/domain/hosts/pairing-ask.d.ts.map +1 -0
  268. package/daemon/dist/domain/hosts/pairing-ask.js +9 -0
  269. package/daemon/dist/domain/hosts/pairing-ask.js.map +1 -0
  270. package/daemon/dist/domain/launch-wrapper.d.ts +28 -0
  271. package/daemon/dist/domain/launch-wrapper.d.ts.map +1 -0
  272. package/daemon/dist/domain/launch-wrapper.js +93 -0
  273. package/daemon/dist/domain/launch-wrapper.js.map +1 -0
  274. package/daemon/dist/domain/mission-control/mission-control-write-contract.d.ts +1 -1
  275. package/daemon/dist/domain/mission-control/mission-control-write-contract.d.ts.map +1 -1
  276. package/daemon/dist/domain/mission-control/mission-control-write-contract.js +85 -28
  277. package/daemon/dist/domain/mission-control/mission-control-write-contract.js.map +1 -1
  278. package/daemon/dist/domain/model-divergence/current-model-reader.d.ts.map +1 -1
  279. package/daemon/dist/domain/model-divergence/current-model-reader.js +14 -3
  280. package/daemon/dist/domain/model-divergence/current-model-reader.js.map +1 -1
  281. package/daemon/dist/domain/native-process-lineage.d.ts.map +1 -1
  282. package/daemon/dist/domain/native-process-lineage.js +32 -9
  283. package/daemon/dist/domain/native-process-lineage.js.map +1 -1
  284. package/daemon/dist/domain/native-resume-probe.d.ts +5 -0
  285. package/daemon/dist/domain/native-resume-probe.d.ts.map +1 -1
  286. package/daemon/dist/domain/native-resume-probe.js +5 -0
  287. package/daemon/dist/domain/native-resume-probe.js.map +1 -1
  288. package/daemon/dist/domain/node-inventory.d.ts.map +1 -1
  289. package/daemon/dist/domain/node-inventory.js +7 -0
  290. package/daemon/dist/domain/node-inventory.js.map +1 -1
  291. package/daemon/dist/domain/node-launcher.d.ts.map +1 -1
  292. package/daemon/dist/domain/node-launcher.js +9 -2
  293. package/daemon/dist/domain/node-launcher.js.map +1 -1
  294. package/daemon/dist/domain/outbox-handler.d.ts +53 -3
  295. package/daemon/dist/domain/outbox-handler.d.ts.map +1 -1
  296. package/daemon/dist/domain/outbox-handler.js +101 -6
  297. package/daemon/dist/domain/outbox-handler.js.map +1 -1
  298. package/daemon/dist/domain/parent-session-env.d.ts +2 -1
  299. package/daemon/dist/domain/parent-session-env.d.ts.map +1 -1
  300. package/daemon/dist/domain/parent-session-env.js +9 -1
  301. package/daemon/dist/domain/parent-session-env.js.map +1 -1
  302. package/daemon/dist/domain/parked-query.d.ts +6 -0
  303. package/daemon/dist/domain/parked-query.d.ts.map +1 -1
  304. package/daemon/dist/domain/parked-query.js +1 -0
  305. package/daemon/dist/domain/parked-query.js.map +1 -1
  306. package/daemon/dist/domain/permission-stop-observation.d.ts +50 -0
  307. package/daemon/dist/domain/permission-stop-observation.d.ts.map +1 -0
  308. package/daemon/dist/domain/permission-stop-observation.js +163 -0
  309. package/daemon/dist/domain/permission-stop-observation.js.map +1 -0
  310. package/daemon/dist/domain/pi-account-state.d.ts +6 -0
  311. package/daemon/dist/domain/pi-account-state.d.ts.map +1 -0
  312. package/daemon/dist/domain/pi-account-state.js +14 -0
  313. package/daemon/dist/domain/pi-account-state.js.map +1 -0
  314. package/daemon/dist/domain/policies/parked-owner-consumer.d.ts +6 -0
  315. package/daemon/dist/domain/policies/parked-owner-consumer.d.ts.map +1 -1
  316. package/daemon/dist/domain/policies/parked-owner-consumer.js +10 -1
  317. package/daemon/dist/domain/policies/parked-owner-consumer.js.map +1 -1
  318. package/daemon/dist/domain/policies/quiet-release.d.ts.map +1 -1
  319. package/daemon/dist/domain/policies/quiet-release.js +6 -3
  320. package/daemon/dist/domain/policies/quiet-release.js.map +1 -1
  321. package/daemon/dist/domain/profile-resolver.d.ts.map +1 -1
  322. package/daemon/dist/domain/profile-resolver.js +3 -0
  323. package/daemon/dist/domain/profile-resolver.js.map +1 -1
  324. package/daemon/dist/domain/projection-planner.d.ts +4 -1
  325. package/daemon/dist/domain/projection-planner.d.ts.map +1 -1
  326. package/daemon/dist/domain/projection-planner.js +3 -0
  327. package/daemon/dist/domain/projection-planner.js.map +1 -1
  328. package/daemon/dist/domain/queue-pickup.d.ts +20 -1
  329. package/daemon/dist/domain/queue-pickup.d.ts.map +1 -1
  330. package/daemon/dist/domain/queue-pickup.js +38 -6
  331. package/daemon/dist/domain/queue-pickup.js.map +1 -1
  332. package/daemon/dist/domain/queue-recovery.d.ts +19 -0
  333. package/daemon/dist/domain/queue-recovery.d.ts.map +1 -1
  334. package/daemon/dist/domain/queue-recovery.js +80 -2
  335. package/daemon/dist/domain/queue-recovery.js.map +1 -1
  336. package/daemon/dist/domain/queue-repository.d.ts +81 -10
  337. package/daemon/dist/domain/queue-repository.d.ts.map +1 -1
  338. package/daemon/dist/domain/queue-repository.js +381 -48
  339. package/daemon/dist/domain/queue-repository.js.map +1 -1
  340. package/daemon/dist/domain/queue-retention.d.ts +68 -0
  341. package/daemon/dist/domain/queue-retention.d.ts.map +1 -1
  342. package/daemon/dist/domain/queue-retention.js +133 -0
  343. package/daemon/dist/domain/queue-retention.js.map +1 -1
  344. package/daemon/dist/domain/queue-stuck-sweep.d.ts +22 -1
  345. package/daemon/dist/domain/queue-stuck-sweep.d.ts.map +1 -1
  346. package/daemon/dist/domain/queue-stuck-sweep.js +586 -157
  347. package/daemon/dist/domain/queue-stuck-sweep.js.map +1 -1
  348. package/daemon/dist/domain/queue-transition-log.d.ts +49 -1
  349. package/daemon/dist/domain/queue-transition-log.d.ts.map +1 -1
  350. package/daemon/dist/domain/queue-transition-log.js +216 -3
  351. package/daemon/dist/domain/queue-transition-log.js.map +1 -1
  352. package/daemon/dist/domain/queue-waiting.d.ts +1 -1
  353. package/daemon/dist/domain/queue-waiting.d.ts.map +1 -1
  354. package/daemon/dist/domain/queue-wake-ladder.d.ts.map +1 -1
  355. package/daemon/dist/domain/queue-wake-ladder.js +7 -2
  356. package/daemon/dist/domain/queue-wake-ladder.js.map +1 -1
  357. package/daemon/dist/domain/quiet-hold-custody.d.ts.map +1 -1
  358. package/daemon/dist/domain/quiet-hold-custody.js +7 -3
  359. package/daemon/dist/domain/quiet-hold-custody.js.map +1 -1
  360. package/daemon/dist/domain/restore-check-service.d.ts +1 -0
  361. package/daemon/dist/domain/restore-check-service.d.ts.map +1 -1
  362. package/daemon/dist/domain/restore-check-service.js +7 -2
  363. package/daemon/dist/domain/restore-check-service.js.map +1 -1
  364. package/daemon/dist/domain/restore-orchestrator.d.ts +13 -2
  365. package/daemon/dist/domain/restore-orchestrator.d.ts.map +1 -1
  366. package/daemon/dist/domain/restore-orchestrator.js +63 -26
  367. package/daemon/dist/domain/restore-orchestrator.js.map +1 -1
  368. package/daemon/dist/domain/rig-repository.d.ts +3 -0
  369. package/daemon/dist/domain/rig-repository.d.ts.map +1 -1
  370. package/daemon/dist/domain/rig-repository.js +46 -1
  371. package/daemon/dist/domain/rig-repository.js.map +1 -1
  372. package/daemon/dist/domain/rigspec-codec.d.ts.map +1 -1
  373. package/daemon/dist/domain/rigspec-codec.js +4 -0
  374. package/daemon/dist/domain/rigspec-codec.js.map +1 -1
  375. package/daemon/dist/domain/rigspec-exporter.d.ts.map +1 -1
  376. package/daemon/dist/domain/rigspec-exporter.js +5 -0
  377. package/daemon/dist/domain/rigspec-exporter.js.map +1 -1
  378. package/daemon/dist/domain/rigspec-instantiator.d.ts +20 -2
  379. package/daemon/dist/domain/rigspec-instantiator.d.ts.map +1 -1
  380. package/daemon/dist/domain/rigspec-instantiator.js +76 -20
  381. package/daemon/dist/domain/rigspec-instantiator.js.map +1 -1
  382. package/daemon/dist/domain/rigspec-preflight.d.ts.map +1 -1
  383. package/daemon/dist/domain/rigspec-preflight.js +13 -1
  384. package/daemon/dist/domain/rigspec-preflight.js.map +1 -1
  385. package/daemon/dist/domain/rigspec-schema.d.ts.map +1 -1
  386. package/daemon/dist/domain/rigspec-schema.js +26 -1
  387. package/daemon/dist/domain/rigspec-schema.js.map +1 -1
  388. package/daemon/dist/domain/runtime-adapter.d.ts +1 -0
  389. package/daemon/dist/domain/runtime-adapter.d.ts.map +1 -1
  390. package/daemon/dist/domain/runtime-adapter.js.map +1 -1
  391. package/daemon/dist/domain/runtime-switch-materials.d.ts +1 -1
  392. package/daemon/dist/domain/runtime-switch-materials.d.ts.map +1 -1
  393. package/daemon/dist/domain/runtime-switch-materials.js +2 -2
  394. package/daemon/dist/domain/runtime-switch-materials.js.map +1 -1
  395. package/daemon/dist/domain/seat-activity-service.d.ts +38 -1
  396. package/daemon/dist/domain/seat-activity-service.d.ts.map +1 -1
  397. package/daemon/dist/domain/seat-activity-service.js +59 -1
  398. package/daemon/dist/domain/seat-activity-service.js.map +1 -1
  399. package/daemon/dist/domain/seat-attention-reconciler.d.ts +13 -0
  400. package/daemon/dist/domain/seat-attention-reconciler.d.ts.map +1 -1
  401. package/daemon/dist/domain/seat-attention-reconciler.js +45 -1
  402. package/daemon/dist/domain/seat-attention-reconciler.js.map +1 -1
  403. package/daemon/dist/domain/seat-handover-service.d.ts +1 -0
  404. package/daemon/dist/domain/seat-handover-service.d.ts.map +1 -1
  405. package/daemon/dist/domain/seat-handover-service.js +38 -11
  406. package/daemon/dist/domain/seat-handover-service.js.map +1 -1
  407. package/daemon/dist/domain/seat-launch-environment.d.ts +10 -0
  408. package/daemon/dist/domain/seat-launch-environment.d.ts.map +1 -1
  409. package/daemon/dist/domain/seat-launch-environment.js +62 -15
  410. package/daemon/dist/domain/seat-launch-environment.js.map +1 -1
  411. package/daemon/dist/domain/seat-lifecycle-service.d.ts +3 -0
  412. package/daemon/dist/domain/seat-lifecycle-service.d.ts.map +1 -1
  413. package/daemon/dist/domain/seat-lifecycle-service.js +30 -8
  414. package/daemon/dist/domain/seat-lifecycle-service.js.map +1 -1
  415. package/daemon/dist/domain/seat-restart-in-place.d.ts +2 -1
  416. package/daemon/dist/domain/seat-restart-in-place.d.ts.map +1 -1
  417. package/daemon/dist/domain/seat-restart-in-place.js +22 -2
  418. package/daemon/dist/domain/seat-restart-in-place.js.map +1 -1
  419. package/daemon/dist/domain/seat-runtime-home.d.ts +4 -1
  420. package/daemon/dist/domain/seat-runtime-home.d.ts.map +1 -1
  421. package/daemon/dist/domain/seat-runtime-home.js +6 -4
  422. package/daemon/dist/domain/seat-runtime-home.js.map +1 -1
  423. package/daemon/dist/domain/seat-runtime-switch-service.d.ts.map +1 -1
  424. package/daemon/dist/domain/seat-runtime-switch-service.js +75 -11
  425. package/daemon/dist/domain/seat-runtime-switch-service.js.map +1 -1
  426. package/daemon/dist/domain/seat-skill-storage.d.ts +57 -4
  427. package/daemon/dist/domain/seat-skill-storage.d.ts.map +1 -1
  428. package/daemon/dist/domain/seat-skill-storage.js +338 -8
  429. package/daemon/dist/domain/seat-skill-storage.js.map +1 -1
  430. package/daemon/dist/domain/seat-status-service.d.ts +9 -2
  431. package/daemon/dist/domain/seat-status-service.d.ts.map +1 -1
  432. package/daemon/dist/domain/seat-status-service.js +17 -2
  433. package/daemon/dist/domain/seat-status-service.js.map +1 -1
  434. package/daemon/dist/domain/self-attach-service.d.ts.map +1 -1
  435. package/daemon/dist/domain/self-attach-service.js +11 -4
  436. package/daemon/dist/domain/self-attach-service.js.map +1 -1
  437. package/daemon/dist/domain/session-transport.d.ts +33 -4
  438. package/daemon/dist/domain/session-transport.d.ts.map +1 -1
  439. package/daemon/dist/domain/session-transport.js +225 -37
  440. package/daemon/dist/domain/session-transport.js.map +1 -1
  441. package/daemon/dist/domain/skill-catalog.d.ts +37 -0
  442. package/daemon/dist/domain/skill-catalog.d.ts.map +1 -1
  443. package/daemon/dist/domain/skill-catalog.js +152 -3
  444. package/daemon/dist/domain/skill-catalog.js.map +1 -1
  445. package/daemon/dist/domain/slices/slice-detail-projector.d.ts +1 -1
  446. package/daemon/dist/domain/slices/slice-detail-projector.d.ts.map +1 -1
  447. package/daemon/dist/domain/slices/slice-detail-projector.js +11 -13
  448. package/daemon/dist/domain/slices/slice-detail-projector.js.map +1 -1
  449. package/daemon/dist/domain/spec-validation-service.d.ts +1 -0
  450. package/daemon/dist/domain/spec-validation-service.d.ts.map +1 -1
  451. package/daemon/dist/domain/startup-orchestrator.d.ts.map +1 -1
  452. package/daemon/dist/domain/startup-orchestrator.js +7 -1
  453. package/daemon/dist/domain/startup-orchestrator.js.map +1 -1
  454. package/daemon/dist/domain/successor-session-launcher.d.ts +1 -0
  455. package/daemon/dist/domain/successor-session-launcher.d.ts.map +1 -1
  456. package/daemon/dist/domain/successor-session-launcher.js +1 -0
  457. package/daemon/dist/domain/successor-session-launcher.js.map +1 -1
  458. package/daemon/dist/domain/terminal/earlier-tile-attach-0711.d.ts +2 -0
  459. package/daemon/dist/domain/terminal/earlier-tile-attach-0711.d.ts.map +1 -0
  460. package/daemon/dist/domain/terminal/earlier-tile-attach-0711.js +146 -0
  461. package/daemon/dist/domain/terminal/earlier-tile-attach-0711.js.map +1 -0
  462. package/daemon/dist/domain/terminal/earlier-tile-attach.d.ts +4 -0
  463. package/daemon/dist/domain/terminal/earlier-tile-attach.d.ts.map +1 -0
  464. package/daemon/dist/domain/terminal/earlier-tile-attach.js +131 -0
  465. package/daemon/dist/domain/terminal/earlier-tile-attach.js.map +1 -0
  466. package/daemon/dist/domain/terminal/herdr-follow-view.d.ts.map +1 -1
  467. package/daemon/dist/domain/terminal/herdr-follow-view.js +47 -17
  468. package/daemon/dist/domain/terminal/herdr-follow-view.js.map +1 -1
  469. package/daemon/dist/domain/terminal/herdr-viewer.d.ts +7 -4
  470. package/daemon/dist/domain/terminal/herdr-viewer.d.ts.map +1 -1
  471. package/daemon/dist/domain/terminal/herdr-viewer.js +105 -41
  472. package/daemon/dist/domain/terminal/herdr-viewer.js.map +1 -1
  473. package/daemon/dist/domain/terminal/terminal-following.js +3 -3
  474. package/daemon/dist/domain/terminal/terminal-following.js.map +1 -1
  475. package/daemon/dist/domain/terminal/terminal-service.d.ts.map +1 -1
  476. package/daemon/dist/domain/terminal/terminal-service.js +16 -1
  477. package/daemon/dist/domain/terminal/terminal-service.js.map +1 -1
  478. package/daemon/dist/domain/terminal/tile-attach.d.ts +8 -1
  479. package/daemon/dist/domain/terminal/tile-attach.d.ts.map +1 -1
  480. package/daemon/dist/domain/terminal/tile-attach.js +20 -50
  481. package/daemon/dist/domain/terminal/tile-attach.js.map +1 -1
  482. package/daemon/dist/domain/terminal/view-composer.js +1 -1
  483. package/daemon/dist/domain/terminal/view-composer.js.map +1 -1
  484. package/daemon/dist/domain/tmux-server-selection.d.ts.map +1 -1
  485. package/daemon/dist/domain/tmux-server-selection.js +8 -2
  486. package/daemon/dist/domain/tmux-server-selection.js.map +1 -1
  487. package/daemon/dist/domain/types.d.ts +18 -1
  488. package/daemon/dist/domain/types.d.ts.map +1 -1
  489. package/daemon/dist/domain/types.js.map +1 -1
  490. package/daemon/dist/domain/user-settings/settings-store.d.ts +1 -1
  491. package/daemon/dist/domain/user-settings/settings-store.d.ts.map +1 -1
  492. package/daemon/dist/domain/user-settings/settings-store.js +52 -0
  493. package/daemon/dist/domain/user-settings/settings-store.js.map +1 -1
  494. package/daemon/dist/domain/view-event-bridge.js +1 -1
  495. package/daemon/dist/domain/view-event-bridge.js.map +1 -1
  496. package/daemon/dist/domain/view-projector.d.ts +4 -1
  497. package/daemon/dist/domain/view-projector.d.ts.map +1 -1
  498. package/daemon/dist/domain/view-projector.js +9 -4
  499. package/daemon/dist/domain/view-projector.js.map +1 -1
  500. package/daemon/dist/domain/wake-recovery.d.ts.map +1 -1
  501. package/daemon/dist/domain/wake-recovery.js +9 -2
  502. package/daemon/dist/domain/wake-recovery.js.map +1 -1
  503. package/daemon/dist/domain/workflow-exception-escalation.d.ts +3 -2
  504. package/daemon/dist/domain/workflow-exception-escalation.d.ts.map +1 -1
  505. package/daemon/dist/domain/workflow-exception-escalation.js +1 -1
  506. package/daemon/dist/domain/workflow-exception-escalation.js.map +1 -1
  507. package/daemon/dist/domain/workflow-instance-store.d.ts +8 -1
  508. package/daemon/dist/domain/workflow-instance-store.d.ts.map +1 -1
  509. package/daemon/dist/domain/workflow-instance-store.js +21 -3
  510. package/daemon/dist/domain/workflow-instance-store.js.map +1 -1
  511. package/daemon/dist/domain/workflow-reconciliation.d.ts.map +1 -1
  512. package/daemon/dist/domain/workflow-reconciliation.js +2 -1
  513. package/daemon/dist/domain/workflow-reconciliation.js.map +1 -1
  514. package/daemon/dist/domain/workflow-runtime.d.ts +4 -1
  515. package/daemon/dist/domain/workflow-runtime.d.ts.map +1 -1
  516. package/daemon/dist/domain/workflow-runtime.js +20 -7
  517. package/daemon/dist/domain/workflow-runtime.js.map +1 -1
  518. package/daemon/dist/domain/workflow-spec-cache.d.ts +24 -4
  519. package/daemon/dist/domain/workflow-spec-cache.d.ts.map +1 -1
  520. package/daemon/dist/domain/workflow-spec-cache.js +87 -7
  521. package/daemon/dist/domain/workflow-spec-cache.js.map +1 -1
  522. package/daemon/dist/domain/workflow-spec-unregister.d.ts +36 -0
  523. package/daemon/dist/domain/workflow-spec-unregister.d.ts.map +1 -0
  524. package/daemon/dist/domain/workflow-spec-unregister.js +105 -0
  525. package/daemon/dist/domain/workflow-spec-unregister.js.map +1 -0
  526. package/daemon/dist/domain/workflow-types.d.ts +14 -0
  527. package/daemon/dist/domain/workflow-types.d.ts.map +1 -1
  528. package/daemon/dist/index.d.ts +2 -1
  529. package/daemon/dist/index.d.ts.map +1 -1
  530. package/daemon/dist/index.js +23 -5
  531. package/daemon/dist/index.js.map +1 -1
  532. package/daemon/dist/learned-host-bindings-surface.d.ts +2 -0
  533. package/daemon/dist/learned-host-bindings-surface.d.ts.map +1 -0
  534. package/daemon/dist/learned-host-bindings-surface.js +4 -0
  535. package/daemon/dist/learned-host-bindings-surface.js.map +1 -0
  536. package/daemon/dist/middleware/auth-bearer-token.d.ts +2 -0
  537. package/daemon/dist/middleware/auth-bearer-token.d.ts.map +1 -1
  538. package/daemon/dist/middleware/auth-bearer-token.js +12 -8
  539. package/daemon/dist/middleware/auth-bearer-token.js.map +1 -1
  540. package/daemon/dist/routes/activity.d.ts.map +1 -1
  541. package/daemon/dist/routes/activity.js +59 -4
  542. package/daemon/dist/routes/activity.js.map +1 -1
  543. package/daemon/dist/routes/adapters.d.ts.map +1 -1
  544. package/daemon/dist/routes/adapters.js +4 -0
  545. package/daemon/dist/routes/adapters.js.map +1 -1
  546. package/daemon/dist/routes/compaction.js +3 -1
  547. package/daemon/dist/routes/compaction.js.map +1 -1
  548. package/daemon/dist/routes/events.js +4 -0
  549. package/daemon/dist/routes/events.js.map +1 -1
  550. package/daemon/dist/routes/gateway.d.ts +3 -0
  551. package/daemon/dist/routes/gateway.d.ts.map +1 -1
  552. package/daemon/dist/routes/gateway.js +58 -8
  553. package/daemon/dist/routes/gateway.js.map +1 -1
  554. package/daemon/dist/routes/hosts.d.ts.map +1 -1
  555. package/daemon/dist/routes/hosts.js +298 -35
  556. package/daemon/dist/routes/hosts.js.map +1 -1
  557. package/daemon/dist/routes/queue.d.ts.map +1 -1
  558. package/daemon/dist/routes/queue.js +10 -3
  559. package/daemon/dist/routes/queue.js.map +1 -1
  560. package/daemon/dist/routes/seat.d.ts.map +1 -1
  561. package/daemon/dist/routes/seat.js +8 -5
  562. package/daemon/dist/routes/seat.js.map +1 -1
  563. package/daemon/dist/routes/sessions.js +1 -1
  564. package/daemon/dist/routes/sessions.js.map +1 -1
  565. package/daemon/dist/routes/terminal-ws.d.ts +1 -0
  566. package/daemon/dist/routes/terminal-ws.d.ts.map +1 -1
  567. package/daemon/dist/routes/terminal-ws.js +1 -1
  568. package/daemon/dist/routes/terminal-ws.js.map +1 -1
  569. package/daemon/dist/routes/terminal.js +2 -2
  570. package/daemon/dist/routes/terminal.js.map +1 -1
  571. package/daemon/dist/routes/transport.js +1 -1
  572. package/daemon/dist/routes/transport.js.map +1 -1
  573. package/daemon/dist/routes/workflow.d.ts.map +1 -1
  574. package/daemon/dist/routes/workflow.js +24 -0
  575. package/daemon/dist/routes/workflow.js.map +1 -1
  576. package/daemon/dist/server.d.ts +2 -0
  577. package/daemon/dist/server.d.ts.map +1 -1
  578. package/daemon/dist/server.js +7 -2
  579. package/daemon/dist/server.js.map +1 -1
  580. package/daemon/dist/startup.d.ts.map +1 -1
  581. package/daemon/dist/startup.js +74 -17
  582. package/daemon/dist/startup.js.map +1 -1
  583. package/daemon/dist/terminal/TerminalSessionBroker.d.ts +18 -13
  584. package/daemon/dist/terminal/TerminalSessionBroker.d.ts.map +1 -1
  585. package/daemon/dist/terminal/TerminalSessionBroker.js +113 -76
  586. package/daemon/dist/terminal/TerminalSessionBroker.js.map +1 -1
  587. package/daemon/dist/terminal/window-pin.d.ts +3 -3
  588. package/daemon/dist/terminal/window-pin.d.ts.map +1 -1
  589. package/daemon/dist/terminal/window-pin.js +2 -2
  590. package/daemon/dist/terminal/window-pin.js.map +1 -1
  591. package/daemon/docs/reference/acp-agents.md +176 -2
  592. package/daemon/docs/reference/agent-spec.md +73 -6
  593. package/daemon/docs/reference/agent-startup-guide.md +28 -0
  594. package/daemon/docs/reference/agent-state-taxonomy.md +7 -0
  595. package/daemon/docs/reference/author-contracts.md +1 -1
  596. package/daemon/docs/reference/community-harness-examples/dsh/dsh.yaml +2 -2
  597. package/daemon/docs/reference/daemon-http-clients.md +16 -7
  598. package/daemon/docs/reference/gateway-participants.md +4 -1
  599. package/daemon/docs/reference/gateway-relay.md +239 -0
  600. package/daemon/docs/reference/getting-started.md +23 -4
  601. package/daemon/docs/reference/harness-runner-contract.md +20 -3
  602. package/daemon/docs/reference/hosted-members.md +38 -1
  603. package/daemon/docs/reference/project-workspace.md +4 -0
  604. package/daemon/docs/reference/quickstart.md +1 -1
  605. package/daemon/docs/reference/reconstructions.md +90 -0
  606. package/daemon/docs/reference/rig-spec.md +64 -7
  607. package/daemon/docs/reference/seat-delivery.md +83 -0
  608. package/daemon/docs/reference/slack-app-setup.md +1 -2
  609. package/daemon/docs/reference/telemetry.md +64 -0
  610. package/daemon/docs/reference/terminal-sessions.md +88 -26
  611. package/daemon/docs/reference/tmux-servers.md +48 -0
  612. package/daemon/docs/reference/whats-new.md +484 -76
  613. package/daemon/specs/agents/shared/skills/core/cross-host-rig-commands/SKILL.md +7 -0
  614. package/daemon/specs/agents/shared/skills/core/openrig-skills/SKILL.md +1 -0
  615. package/daemon/specs/agents/shared/skills/core/working-with-an-openrig-team/SKILL.md +90 -0
  616. package/dist/acp/agent-server.d.ts +126 -0
  617. package/dist/acp/agent-server.d.ts.map +1 -0
  618. package/dist/acp/agent-server.js +449 -0
  619. package/dist/acp/agent-server.js.map +1 -0
  620. package/dist/acp/connector.d.ts +27 -1
  621. package/dist/acp/connector.d.ts.map +1 -1
  622. package/dist/acp/connector.js +38 -5
  623. package/dist/acp/connector.js.map +1 -1
  624. package/dist/acp/json-rpc-stdio.d.ts +24 -10
  625. package/dist/acp/json-rpc-stdio.d.ts.map +1 -1
  626. package/dist/acp/json-rpc-stdio.js +58 -36
  627. package/dist/acp/json-rpc-stdio.js.map +1 -1
  628. package/dist/acp/run-processes.d.ts +3 -2
  629. package/dist/acp/run-processes.d.ts.map +1 -1
  630. package/dist/acp/run-processes.js +4 -3
  631. package/dist/acp/run-processes.js.map +1 -1
  632. package/dist/bin-wrapper.d.ts.map +1 -1
  633. package/dist/bin-wrapper.js +3 -1
  634. package/dist/bin-wrapper.js.map +1 -1
  635. package/dist/build-info.js +3 -3
  636. package/dist/client.d.ts +4 -0
  637. package/dist/client.d.ts.map +1 -1
  638. package/dist/client.js +7 -0
  639. package/dist/client.js.map +1 -1
  640. package/dist/commands/acp.d.ts +16 -0
  641. package/dist/commands/acp.d.ts.map +1 -1
  642. package/dist/commands/acp.js +191 -4
  643. package/dist/commands/acp.js.map +1 -1
  644. package/dist/commands/agent.d.ts.map +1 -1
  645. package/dist/commands/agent.js +3 -0
  646. package/dist/commands/agent.js.map +1 -1
  647. package/dist/commands/attach.js +1 -1
  648. package/dist/commands/attach.js.map +1 -1
  649. package/dist/commands/broadcast.js +4 -0
  650. package/dist/commands/broadcast.js.map +1 -1
  651. package/dist/commands/capture.js +6 -6
  652. package/dist/commands/capture.js.map +1 -1
  653. package/dist/commands/compact.d.ts.map +1 -1
  654. package/dist/commands/compact.js +14 -2
  655. package/dist/commands/compact.js.map +1 -1
  656. package/dist/commands/config.d.ts.map +1 -1
  657. package/dist/commands/config.js +42 -6
  658. package/dist/commands/config.js.map +1 -1
  659. package/dist/commands/context-reconstruction.d.ts +5 -0
  660. package/dist/commands/context-reconstruction.d.ts.map +1 -0
  661. package/dist/commands/context-reconstruction.js +69 -0
  662. package/dist/commands/context-reconstruction.js.map +1 -0
  663. package/dist/commands/context.d.ts.map +1 -1
  664. package/dist/commands/context.js +2 -0
  665. package/dist/commands/context.js.map +1 -1
  666. package/dist/commands/daemon.d.ts.map +1 -1
  667. package/dist/commands/daemon.js +5 -2
  668. package/dist/commands/daemon.js.map +1 -1
  669. package/dist/commands/doctor.d.ts +1 -1
  670. package/dist/commands/doctor.d.ts.map +1 -1
  671. package/dist/commands/doctor.js +97 -7
  672. package/dist/commands/doctor.js.map +1 -1
  673. package/dist/commands/exec.d.ts +102 -0
  674. package/dist/commands/exec.d.ts.map +1 -0
  675. package/dist/commands/exec.js +562 -0
  676. package/dist/commands/exec.js.map +1 -0
  677. package/dist/commands/gateway.d.ts.map +1 -1
  678. package/dist/commands/gateway.js +15 -7
  679. package/dist/commands/gateway.js.map +1 -1
  680. package/dist/commands/host.d.ts.map +1 -1
  681. package/dist/commands/host.js +59 -12
  682. package/dist/commands/host.js.map +1 -1
  683. package/dist/commands/mcp.d.ts.map +1 -1
  684. package/dist/commands/mcp.js +29 -5
  685. package/dist/commands/mcp.js.map +1 -1
  686. package/dist/commands/provider.d.ts.map +1 -1
  687. package/dist/commands/provider.js +4 -1
  688. package/dist/commands/provider.js.map +1 -1
  689. package/dist/commands/ps.d.ts +2 -0
  690. package/dist/commands/ps.d.ts.map +1 -1
  691. package/dist/commands/ps.js +3 -1
  692. package/dist/commands/ps.js.map +1 -1
  693. package/dist/commands/queue.d.ts +3 -0
  694. package/dist/commands/queue.d.ts.map +1 -1
  695. package/dist/commands/queue.js +203 -67
  696. package/dist/commands/queue.js.map +1 -1
  697. package/dist/commands/roster.d.ts +1 -1
  698. package/dist/commands/roster.d.ts.map +1 -1
  699. package/dist/commands/roster.js +14 -2
  700. package/dist/commands/roster.js.map +1 -1
  701. package/dist/commands/seat.d.ts.map +1 -1
  702. package/dist/commands/seat.js +48 -5
  703. package/dist/commands/seat.js.map +1 -1
  704. package/dist/commands/send.d.ts.map +1 -1
  705. package/dist/commands/send.js +7 -11
  706. package/dist/commands/send.js.map +1 -1
  707. package/dist/commands/slack.d.ts.map +1 -1
  708. package/dist/commands/slack.js +2 -0
  709. package/dist/commands/slack.js.map +1 -1
  710. package/dist/commands/stream.d.ts.map +1 -1
  711. package/dist/commands/stream.js +24 -1
  712. package/dist/commands/stream.js.map +1 -1
  713. package/dist/commands/terminal.js +1 -1
  714. package/dist/commands/workflow-render.d.ts +4 -0
  715. package/dist/commands/workflow-render.d.ts.map +1 -1
  716. package/dist/commands/workflow-render.js +7 -0
  717. package/dist/commands/workflow-render.js.map +1 -1
  718. package/dist/commands/workflow.d.ts.map +1 -1
  719. package/dist/commands/workflow.js +69 -1
  720. package/dist/commands/workflow.js.map +1 -1
  721. package/dist/config-store.d.ts +9 -1
  722. package/dist/config-store.d.ts.map +1 -1
  723. package/dist/config-store.js +57 -3
  724. package/dist/config-store.js.map +1 -1
  725. package/dist/cross-host-target.d.ts +2 -0
  726. package/dist/cross-host-target.d.ts.map +1 -1
  727. package/dist/cross-host-target.js +1 -1
  728. package/dist/cross-host-target.js.map +1 -1
  729. package/dist/daemon-lifecycle.d.ts +2 -0
  730. package/dist/daemon-lifecycle.d.ts.map +1 -1
  731. package/dist/daemon-lifecycle.js +38 -5
  732. package/dist/daemon-lifecycle.js.map +1 -1
  733. package/dist/daemon-reachability.d.ts +1 -1
  734. package/dist/daemon-reachability.d.ts.map +1 -1
  735. package/dist/daemon-reachability.js +4 -2
  736. package/dist/daemon-reachability.js.map +1 -1
  737. package/dist/index.d.ts +2 -0
  738. package/dist/index.d.ts.map +1 -1
  739. package/dist/index.js +2 -0
  740. package/dist/index.js.map +1 -1
  741. package/dist/lazy-program.d.ts.map +1 -1
  742. package/dist/lazy-program.js +1 -0
  743. package/dist/lazy-program.js.map +1 -1
  744. package/dist/lib/reconstruction-reader.d.ts +122 -0
  745. package/dist/lib/reconstruction-reader.d.ts.map +1 -0
  746. package/dist/lib/reconstruction-reader.js +481 -0
  747. package/dist/lib/reconstruction-reader.js.map +1 -0
  748. package/dist/lib/work-install.d.ts +28 -0
  749. package/dist/lib/work-install.d.ts.map +1 -1
  750. package/dist/lib/work-install.js +80 -20
  751. package/dist/lib/work-install.js.map +1 -1
  752. package/dist/mcp-http.d.ts +7 -0
  753. package/dist/mcp-http.d.ts.map +1 -1
  754. package/dist/mcp-http.js +30 -6
  755. package/dist/mcp-http.js.map +1 -1
  756. package/dist/mcp-server.d.ts +33 -3
  757. package/dist/mcp-server.d.ts.map +1 -1
  758. package/dist/mcp-server.js +443 -52
  759. package/dist/mcp-server.js.map +1 -1
  760. package/dist/queue-artifact.d.ts +57 -0
  761. package/dist/queue-artifact.d.ts.map +1 -0
  762. package/dist/queue-artifact.js +70 -0
  763. package/dist/queue-artifact.js.map +1 -0
  764. package/dist/queue-receipt.d.ts.map +1 -1
  765. package/dist/queue-receipt.js +4 -3
  766. package/dist/queue-receipt.js.map +1 -1
  767. package/dist/system-preflight.d.ts.map +1 -1
  768. package/dist/system-preflight.js +15 -7
  769. package/dist/system-preflight.js.map +1 -1
  770. package/dist/terminal-window.d.ts.map +1 -1
  771. package/dist/terminal-window.js +13 -10
  772. package/dist/terminal-window.js.map +1 -1
  773. package/package.json +1 -1
  774. package/tui/dist/attention/attention-model.d.ts +2 -1
  775. package/tui/dist/attention/attention-model.d.ts.map +1 -1
  776. package/tui/dist/attention/attention-model.js +18 -4
  777. package/tui/dist/attention/attention-model.js.map +1 -1
  778. package/tui/dist/config/config-model.d.ts.map +1 -1
  779. package/tui/dist/config/config-model.js +2 -1
  780. package/tui/dist/config/config-model.js.map +1 -1
  781. package/tui/dist/daemon-client.d.ts +7 -0
  782. package/tui/dist/daemon-client.d.ts.map +1 -1
  783. package/tui/dist/daemon-client.js +19 -5
  784. package/tui/dist/daemon-client.js.map +1 -1
  785. package/tui/dist/demo-data.js +2 -2
  786. package/tui/dist/demo-data.js.map +1 -1
  787. package/tui/dist/main.js +5 -1
  788. package/tui/dist/main.js.map +1 -1
  789. package/ui/dist/assets/index-BOYrLyfQ.js +623 -0
  790. package/ui/dist/assets/index-DqSRu4OY.css +32 -0
  791. package/ui/dist/index.html +2 -2
  792. package/ui/dist/assets/index-BFOs3ejL.css +0 -32
  793. package/ui/dist/assets/index-CdkFwtld.js +0 -623
@@ -1,6 +1,6 @@
1
1
  import { currentParkedOwnerNoInputFailure } from "./policies/parked-owner-consumer.js";
2
2
  import { resolveEscalationOwner, ESCALATION_HOP_TAG, hasConsumedEscalationHop } from "./escalation-owner.js";
3
- import { findQueueRecovery, recoveryId, recoveryTag } from "./queue-recovery.js";
3
+ import { createRecoveryLookup, recoveryId, recoveryTag } from "./queue-recovery.js";
4
4
  import { quietHoldCustody } from "./quiet-hold-custody.js";
5
5
  import { queueWaitNotice } from "./queue-wait-backoff.js";
6
6
  import { lastMeaningfulTransition, pendingSince } from "./queue-waiting.js";
@@ -28,7 +28,7 @@ import { resolvePickupThresholdMinutes } from "./queue-pickup.js";
28
28
  import { resolveOperatorSeat, resolveRecoveryAgentSeat, resolveSessionNodeId } from "./queue-owner.js";
29
29
  import { nodeExecutorStoppedReason } from "./node-inventory.js";
30
30
  import { isBoundTerminalSeat } from "./terminal-seat.js";
31
- import { deriveCrossHostSuccessorId, hasLinkedSuccessor, matchesRecordedHandoffTarget, QueueRepositoryError } from "./queue-repository.js";
31
+ import { createLinkedSuccessorLookup, deriveCrossHostSuccessorId, hasLinkedSuccessor, matchesRecordedHandoffTarget, QueueRepositoryError } from "./queue-repository.js";
32
32
  import { stalledPickupFinding } from "./queue-pickup.js";
33
33
  import { SettingsStore } from "./user-settings/settings-store.js";
34
34
  import { loadHostRegistry } from "./hosts/hosts-registry-reader.js";
@@ -86,6 +86,12 @@ export function resolveLadderSuppressionMinutes() {
86
86
  export function findingDedupTag(kind, qitemId) {
87
87
  return `stuck-sweep:${kind}:${qitemId}`;
88
88
  }
89
+ /** Idempotency key of a seat's standing unclaimed-backlog notice: one open notice per seat. */
90
+ export function unclaimedBacklogTag(seat) {
91
+ return `stuck-sweep:unclaimed-backlog:${seat}`;
92
+ }
93
+ /** How many of a seat's unclaimed rows its standing notice lists by id; the rest are counted. */
94
+ export const UNCLAIMED_BACKLOG_LISTED_ROWS = 20;
89
95
  /** The loop's observable heartbeat — surfaced on /healthz so a quiet sweep is cheap but
90
96
  * never invisible, and a failing sweep is loud without needing a row. */
91
97
  export function createStuckSweepStatus() {
@@ -95,6 +101,8 @@ export function createStuckSweepStatus() {
95
101
  lastError: null,
96
102
  consecutiveFailures: 0,
97
103
  findingsRouted: 0,
104
+ runningSince: null,
105
+ skippedTicks: 0,
98
106
  };
99
107
  return {
100
108
  record(outcome, detail) {
@@ -105,6 +113,10 @@ export function createStuckSweepStatus() {
105
113
  if (detail?.findings)
106
114
  state.findingsRouted += detail.findings;
107
115
  },
116
+ pass(pass) {
117
+ state.runningSince = pass.runningSince;
118
+ state.skippedTicks = pass.skippedTicks;
119
+ },
108
120
  snapshot() {
109
121
  return { ...state };
110
122
  },
@@ -345,6 +357,9 @@ function deliveryResolutionEvidence(deps, kind, qitemId, now) {
345
357
  if (quiet && !quiet.unreadable && (quiet.state === "held" || quiet.state === "released")) {
346
358
  return `source held by quiet-release job for window ${quiet.windowId}`;
347
359
  }
360
+ if (kind === "unclaimed-obligation" && !quiet && deps.queueRepo.isRegisteredHumanUpdate(row) && !deps.queueRepo.deliveryOutcomeFor(qitemId)) {
361
+ return "informational update to a registered human requires no claim";
362
+ }
348
363
  if (kind !== "undelivered-human-notice" && row.lastNudgeResult === "retained:typing_guard") {
349
364
  return "source wake held by the seat typing guard";
350
365
  }
@@ -407,17 +422,84 @@ function evidenceBody(db, c) {
407
422
  `why: ${c.why}\n` +
408
423
  `Resolve the underlying row; the sweep closes this finding itself once the row is no longer stuck.`);
409
424
  }
425
+ /** The last line of a standing notice's body: every row it stands for, so the sweep knows what it covered. */
426
+ const BACKLOG_ROWS_PREFIX = "Every row this notice stands for: ";
427
+ /** A seat's standing unclaimed-backlog notice: its rows by id, how to list them, and how to send their findings to a seat
428
+ * that watches this one. Built only from the rows' fixed facts, so a pass rewrites it only when the rows change. */
429
+ function unclaimedBacklogText(seat, rows, thresholdMinutes, node) {
430
+ const sorted = [...rows].sort((a, b) => a.since.localeCompare(b.since) || a.qitemId.localeCompare(b.qitemId));
431
+ const listed = sorted.slice(0, UNCLAIMED_BACKLOG_LISTED_ROWS).map((r) => {
432
+ const about = r.summary ? `: ${r.summary.replace(/\s+/g, " ").trim().slice(0, 120)}` : "";
433
+ return `- ${r.qitemId}, unclaimed since ${r.since}, from ${r.from}${about}`;
434
+ });
435
+ if (sorted.length > listed.length)
436
+ listed.push(`- and ${sorted.length - listed.length} more`);
437
+ const count = `${rows.length} ${rows.length === 1 ? "row" : "rows"}`;
438
+ const edge = node ? `rig edge add ${node.rig} ${node.logicalId} <watching seat> --kind escalates_to` : "an escalates_to edge from this seat";
439
+ return {
440
+ summary: `Stuck sweep: unclaimed-backlog on ${seat} (${count})`,
441
+ body: `STUCK SWEEP FINDING (unclaimed-backlog)\n` +
442
+ `seat: ${seat}\n` +
443
+ `unclaimed: ${count} (the threshold is ${thresholdMinutes} min)\n` +
444
+ `${listed.join("\n")}\n` +
445
+ `why: nobody has claimed these rows, and this seat has no delegation parent and no escalates_to route, so this one ` +
446
+ `notice stands for them instead of a finding per row. It follows the rows as they come and go.\n` +
447
+ `List them: rig queue list --destination ${seat} --state pending\n` +
448
+ `To send these findings to a seat that watches this one, one finding per row: ${edge}\n` +
449
+ `The sweep closes this notice itself once every row it stands for is claimed, parked or closed.\n` +
450
+ `${BACKLOG_ROWS_PREFIX}${JSON.stringify(sorted.map((r) => r.qitemId))}`,
451
+ };
452
+ }
453
+ /** The rows a standing notice's body says it stands for, or null when the line is missing or unreadable: unknown, which is
454
+ * never read as "none". */
455
+ function backlogRowsOf(body) {
456
+ const line = body.split("\n").reverse().find((l) => l.startsWith(BACKLOG_ROWS_PREFIX));
457
+ if (!line)
458
+ return null;
459
+ try {
460
+ const ids = JSON.parse(line.slice(BACKLOG_ROWS_PREFIX.length));
461
+ return Array.isArray(ids) ? new Set(ids.filter((id) => typeof id === "string")) : null;
462
+ }
463
+ catch {
464
+ return null;
465
+ }
466
+ }
410
467
  /**
411
468
  * One sweep pass. Instance-wide (no rig scope — the loop is the net for every rig the
412
469
  * daemon carries). Never throws: a sweep that cannot run reports outcome=failed loudly
413
470
  * on the status surface and the log, because a silent skip is exactly the class this
414
471
  * slice exists to kill.
415
472
  */
473
+ /** Rows a sweep pass handles between two yields of the event loop. A pass over a large queue used to hold the loop
474
+ * for its whole length (seconds on a queue of tens of thousands of rows, with healthz and every request waiting);
475
+ * every this many rows it now lets timers and requests run. */
476
+ export const STUCK_SWEEP_YIELD_EVERY_ROWS = 50;
416
477
  export async function runStuckSweep(deps) {
417
478
  const log = deps.log ?? ((line) => console.error(line));
418
479
  const status = deps.status;
419
480
  try {
420
481
  const now = deps.now ?? new Date();
482
+ // One recovery index and one linked-successor read per stretch of the pass, instead of one json_each scan per
483
+ // candidate and per custody row. Each is a snapshot that is only valid while no other code runs, so both are
484
+ // dropped (and rebuilt on the next lookup) after every yield and every awaited write.
485
+ const recoveries = createRecoveryLookup(deps.db);
486
+ let successors = null;
487
+ // Every yield and every awaited write lets other code run: indexes read before it are dropped, and `othersRan`
488
+ // tells a list read before it that its rows need a fresh read.
489
+ let othersRan = 0;
490
+ const othersMayHaveRun = () => { othersRan++; recoveries.invalidate(); successors?.invalidate(); };
491
+ // A synchronous read with both indexes lent to what it calls deep inside (a getById's waiting view and handoff
492
+ // advisory ask the same questions per row). Never spans an await: the lend ends when fn returns.
493
+ const indexed = (fn) => recoveries.run(() => (successors ? successors.run(fn) : fn()));
494
+ // `if (dueToYield()) await yieldLoop();` and never a bare await per row: even an await that does not yield lets
495
+ // queued microtasks (other requests' continuations) run and write between two rows the snapshot still covers.
496
+ let rowsSinceYield = 0;
497
+ const dueToYield = () => ++rowsSinceYield >= STUCK_SWEEP_YIELD_EVERY_ROWS;
498
+ const yieldLoop = async () => {
499
+ rowsSinceYield = 0;
500
+ await new Promise((resolve) => setImmediate(resolve));
501
+ othersMayHaveRun();
502
+ };
421
503
  const suppressionMinutes = deps.ladderSuppressionMinutes ?? resolveLadderSuppressionMinutes();
422
504
  /** The dedup tags of the candidates the LADDER suppressed in this pass, and only those:
423
505
  * a row the ladder alone would have stopped. A finding for such a row stays open,
@@ -443,42 +525,42 @@ export async function runStuckSweep(deps) {
443
525
  };
444
526
  const isRegisteredHost = deps.isRegisteredHost ?? defaultIsRegisteredHost(log);
445
527
  const candidates = [];
528
+ const nowIso = now.toISOString();
529
+ // SQLite's LIKE ignores ASCII case; the per-row rules below match the queries they stand in for.
530
+ const startsWithCI = (value, prefix) => (value ?? "").toLowerCase().startsWith(prefix);
531
+ // Each kind's rule for ONE row, applied to the row as it is now. The loops below enumerate the rows; the same
532
+ // rules run again on a fresh read right before a finding is created (stillStuck), because a pass that yields
533
+ // cannot trust what it read before the yield: a claim, a delivered wake, a moved deadline, a note or a new
534
+ // successor may have landed since.
446
535
  // Half 1 — claimed-never-closed. The claimant holds the obligation; the finding
447
536
  // routes to them.
448
- for (const row of deps.queueRepo.findOverdue({ now: now.toISOString() })) {
537
+ const overdueCandidate = (row) => {
449
538
  if (isFindingRow(row))
450
- continue;
451
- candidates.push({
539
+ return null;
540
+ return {
452
541
  kind: "overdue-claim",
453
542
  row,
454
543
  route: row.destinationSession,
455
544
  ageMinutes: minutesSince(row.closureRequiredAt ?? row.claimedAt, now),
456
545
  evidenceAt: latestIso(lastMeaningfulTransition(deps.db, row.qitemId)?.at, row.closureRequiredAt, row.claimedAt),
457
546
  why: "claimed and past closure_required_at with no closure",
458
- });
459
- try {
460
- deps.queueRepo.recordClosureOverdue(row.qitemId, { now: now.toISOString() });
461
- }
462
- catch (err) {
463
- log(`[stuck-sweep] failed to record closure-overdue for ${row.qitemId}: ${err instanceof Error ? err.message : String(err)}`);
464
- }
465
- }
547
+ };
548
+ };
466
549
  // S04 seam — a claimed row with no later motion past the pickup threshold. The
467
- // pickup module remains the ONE derivation rule; this loop only enumerates and routes.
468
- const claimedRows = deps.db
469
- .prepare("SELECT qitem_id FROM queue_items WHERE state IN ('pending', 'in-progress') AND claimed_at IS NOT NULL")
470
- .all();
471
- for (const { qitem_id } of claimedRows) {
472
- const row = deps.queueRepo.getById(qitem_id);
550
+ // pickup module remains the ONE derivation rule; this only enumerates and routes.
551
+ const stalledCandidate = (qitemId) => {
552
+ const row = indexed(() => deps.queueRepo.getById(qitemId));
473
553
  if (!row || isFindingRow(row))
474
- continue;
554
+ return null;
555
+ if ((row.state !== "pending" && row.state !== "in-progress") || !row.claimedAt)
556
+ return null;
475
557
  const stalled = stalledPickupFinding(row);
476
558
  if (!stalled)
477
- continue;
559
+ return null;
478
560
  // Keep this null arm for the 0.5.7 mechanized-pull turn-end hook that knows the in-flight row;
479
561
  // it is the first honest row-scoped writer, and wiring reopens only in that slice.
480
562
  const evidenceAt = latestIso(lastMeaningfulTransition(deps.db, row.qitemId)?.at, row.lastHeartbeat, row.claimedAt);
481
- candidates.push({
563
+ return {
482
564
  kind: stalled.kind,
483
565
  row,
484
566
  route: resolveOrch(stalled.target, row) ?? stalled.target,
@@ -487,69 +569,85 @@ export async function runStuckSweep(deps) {
487
569
  ageMinutes: wholeMinutesSince(evidenceAt, now),
488
570
  evidenceAt,
489
571
  why: stalled.evidence,
490
- });
491
- }
572
+ };
573
+ };
492
574
  // The timer delivered one transition-specific notice (or recorded a failed
493
575
  // attempt). This existing sweep owns its bounded recovery, not another full
494
576
  // packet or a parked-owner replay. A real owner response ends the occurrence.
495
- const waitJobs = deps.db.prepare("SELECT job_id, spec_yaml FROM watchdog_jobs WHERE state = 'active' AND policy = 'periodic-reminder'").all();
496
- for (const job of waitJobs) {
497
- const notice = queueWaitNotice(job.spec_yaml);
577
+ const waitCandidate = (jobId) => {
578
+ const job = deps.db.prepare("SELECT spec_yaml FROM watchdog_jobs WHERE job_id = ? AND state = 'active' AND policy = 'periodic-reminder'")
579
+ .get(jobId);
580
+ const notice = job ? queueWaitNotice(job.spec_yaml) : null;
498
581
  if (!notice || now.getTime() - Date.parse(notice.at) <= resolvePickupThresholdMinutes() * 60_000)
499
- continue;
500
- const binding = deps.db.prepare("SELECT qitem_id FROM queue_transition_wakes WHERE wake_ref = ? AND phase = 'armed' ORDER BY transition_id DESC LIMIT 1").get(job.job_id);
501
- const row = binding ? deps.queueRepo.getById(binding.qitem_id) : null;
502
- if (!row || row.state !== "blocked" || deps.queueRepo.getParkWakeStatus(row.qitemId)?.ref !== job.job_id)
503
- continue;
582
+ return null;
583
+ const binding = deps.db.prepare("SELECT qitem_id FROM queue_transition_wakes WHERE wake_ref = ? AND phase = 'armed' ORDER BY transition_id DESC LIMIT 1").get(jobId);
584
+ const row = binding ? indexed(() => deps.queueRepo.getById(binding.qitem_id)) : null;
585
+ if (!row || row.state !== "blocked" || deps.queueRepo.getParkWakeStatus(row.qitemId)?.ref !== jobId)
586
+ return null;
504
587
  const response = lastMeaningfulTransition(deps.db, row.qitemId);
505
588
  if (response && Date.parse(response.at) > Date.parse(notice.at))
506
- continue;
589
+ return null;
507
590
  const ownerActivity = deps.queueRepo.ownerActivity(row.destinationSession);
508
591
  if (ownerActivity?.activity === "working" && !ownerActivity.needsInput.count && notice.deliveryStatus === "ok")
509
- continue;
510
- candidates.push({ kind: "unconsumed-wait", row, route: resolveOrch(row.destinationSession, row) ?? row.sourceSession,
511
- ageMinutes: minutesSince(notice.at, now), evidenceAt: notice.at,
512
- why: `wait notice delivery=${notice.deliveryStatus}; no later owner response; activity=${ownerActivity?.activity ?? "unknown"}; inspect exact blocker ${row.blockedOn}` });
513
- }
592
+ return null;
593
+ return { kind: "unconsumed-wait", row, route: resolveOrch(row.destinationSession, row) ?? row.sourceSession,
594
+ ageMinutes: minutesSince(notice.at, now), evidenceAt: notice.at, jobId,
595
+ why: `wait notice delivery=${notice.deliveryStatus}; no later owner response; activity=${ownerActivity?.activity ?? "unknown"}; inspect exact blocker ${row.blockedOn}` };
596
+ };
514
597
  // The parked policy stops repeating a positively no-input failure. Unhealthy blocked rows
515
598
  // have no retry ladder: the same sweep/recovery route owns their actionable disposition.
516
- const blockedFailures = deps.db.prepare("SELECT qitem_id FROM queue_items WHERE state='blocked' AND last_nudge_result LIKE 'failed:%'").all();
517
- for (const { qitem_id } of blockedFailures) {
518
- const row = deps.queueRepo.getById(qitem_id);
599
+ const parkedCandidate = (qitemId) => {
600
+ const row = indexed(() => deps.queueRepo.getById(qitemId));
519
601
  if (!row || isFindingRow(row))
520
- continue;
521
- const wake = deps.queueRepo.getParkWakeStatus(qitem_id);
602
+ return null;
603
+ if (row.state !== "blocked" || !startsWithCI(row.lastNudgeResult, "failed:"))
604
+ return null;
605
+ const wake = deps.queueRepo.getParkWakeStatus(qitemId);
522
606
  if ((wake?.live === true && (!wake.unconsumed || wake.recoveryOwner === "queue-stuck-sweep"))
523
- || deps.queueRepo.parkWakeServedByOwnReminder(qitem_id))
524
- continue;
525
- const transitions = deps.queueRepo.listTransitions(qitem_id);
607
+ || deps.queueRepo.parkWakeServedByOwnReminder(qitemId))
608
+ return null;
609
+ const transitions = deps.queueRepo.listTransitions(qitemId);
526
610
  const failure = currentParkedOwnerNoInputFailure(transitions);
527
611
  if (!failure)
528
- continue;
612
+ return null;
529
613
  // Another seat's incidental note is not the owner's response. This kind follows
530
614
  // the parked policy's owner-or-state-change rule, leaving other sweep kinds alone.
531
615
  if (transitions.some((t, i) => t.transitionId > (failure.transitionId ?? Number.POSITIVE_INFINITY)
532
616
  && (t.actorSession === row.destinationSession || t.state !== transitions[i - 1]?.state)))
533
- continue;
534
- candidates.push({ kind: "parked-owner-no-input", row, route: resolveOrch(row.destinationSession, row) ?? row.sourceSession,
617
+ return null;
618
+ return { kind: "parked-owner-no-input", row, route: resolveOrch(row.destinationSession, row) ?? row.sourceSession,
535
619
  ageMinutes: minutesSince(failure.ts, now), evidenceAt: failure.ts,
536
- why: `Automated parked-owner reminder refused before input (${failure.code}); repeated input stopped. Inspect the retained quota/guard or route terminal work to an agent. Original blocker remains ${row.blockedOn}` });
537
- }
620
+ why: `Automated parked-owner reminder refused before input (${failure.code}); repeated input stopped. Inspect the retained quota/guard or route terminal work to an agent. Original blocker remains ${row.blockedOn}` };
621
+ };
538
622
  // Half 2 — sender-believed-delivered-never-woken. Nobody holds it (the wake failed),
539
623
  // so it routes to the destination's orchestrator when one is derivable. Rows with a
540
624
  // live S01 ladder are S01's territory; an exhausted ladder is the handback and lands
541
625
  // here exactly once (the dedup tag keeps it to one finding).
542
- for (const row of deps.queueRepo.findUndelivered()) {
626
+ // A wake recorded unroutable because the seat's pane wasn't bound yet (#2151). Once its binding exists, deliver the
627
+ // row's own wake intent instead of reporting it: the intent is claimed and settled, so a startup drain doesn't send it
628
+ // again, and one already in flight or settled isn't sent twice. The next tick reads the new result, so a failed send
629
+ // is reported then. A row with a live retry ladder is left to the ladder.
630
+ const wakeToRetry = (row, humanNotice) => !humanNotice
631
+ && startsWithCI(row.lastNudgeResult, "unroutable:")
632
+ && !hasLiveLadder(deps.db, row.qitemId, now, suppressionMinutes)
633
+ && deps.queueRepo.classifyDestinationOf(row.destinationSession).class === "pane-bound";
634
+ const isHumanNotice = (row) => row.deliveryOutcome === "never-posted" || row.deliveryOutcome === "transport-failed";
635
+ /** The checks that run before the wake retry, as in the loop this replaces: a row they exclude is never woken. */
636
+ const wakeRetryEligible = (row) => !row.claimedAt
637
+ && !deps.queueRepo.isLocalHumanDecisionWithoutGateway(row)
638
+ && !["held", "released"].includes(quietHoldCustody(deps.db, row.qitemId, now)?.state ?? "");
639
+ /** `row` comes from findUndelivered (it carries the delivery verdict). Call it after any wake retry the row needs. */
640
+ const undeliveredCandidate = (row, recordSuppression) => {
543
641
  if (isFindingRow(row))
544
- continue;
545
- const humanNotice = row.deliveryOutcome === "never-posted" || row.deliveryOutcome === "transport-failed";
642
+ return null;
643
+ const humanNotice = isHumanNotice(row);
546
644
  // A claim supersedes a retained failed wake, including on a row returned to
547
645
  // pending. Its pickup finding must not be replaced by that historical failure;
548
646
  // a separate human notification still needs its own delivery evidence.
549
647
  if (!humanNotice && row.claimedAt)
550
- continue;
648
+ return null;
551
649
  if (!humanNotice && deps.queueRepo.isLocalHumanDecisionWithoutGateway(row))
552
- continue;
650
+ return null;
553
651
  const notification = humanNotice ? deps.queueRepo.transitionLog.latestOwnerNotificationForQitem(row.qitemId) : null;
554
652
  const resolutionNotice = notification?.ownerNotificationKind === "human-decision-resolved";
555
653
  // Match the notification source in slack/queue-access.ts, not the agent wake's escalator.
@@ -563,26 +661,16 @@ export async function runStuckSweep(deps) {
563
661
  // live release job is orphaned: both stay findings, with their own reason.
564
662
  const quiet = quietHoldCustody(deps.db, row.qitemId, now);
565
663
  if (quiet && (quiet.state === "held" || quiet.state === "released"))
566
- continue;
567
- // A wake recorded unroutable because the seat's pane wasn't bound yet (#2151). Once its binding exists, deliver the
568
- // row's own wake intent instead of reporting it: the intent is claimed and settled, so a startup drain doesn't send it
569
- // again, and one already in flight or settled isn't sent twice. The next tick reads the new result, so a failed send
570
- // is reported then. A row with a live retry ladder is left to the ladder.
571
- if (!humanNotice && row.lastNudgeResult?.startsWith("unroutable:")
572
- && !hasLiveLadder(deps.db, row.qitemId, now, suppressionMinutes)
573
- && deps.queueRepo.classifyDestinationOf(row.destinationSession).class === "pane-bound") {
574
- await deps.queueRepo.deliverWakeForSuccessor(row.qitemId, row.destinationSession, true, row.sourceSession);
575
- if (!deps.queueRepo.getById(row.qitemId)?.lastNudgeResult?.startsWith("unroutable:"))
576
- continue;
577
- }
664
+ return null;
578
665
  // The ladder check runs LAST, so only a row the ladder ALONE would have stopped counts
579
666
  // as ladder-suppressed (#1419). Agent wake retries do not own the separate notice to a
580
667
  // person: a human notice is never the ladder's to suppress.
581
668
  if (!humanNotice && hasLiveLadder(deps.db, row.qitemId, now, suppressionMinutes)) {
582
- suppressedTags.add(findingDedupTag("undelivered-wake", row.qitemId));
583
- continue;
669
+ if (recordSuppression)
670
+ suppressedTags.add(findingDedupTag("undelivered-wake", row.qitemId));
671
+ return null;
584
672
  }
585
- candidates.push({
673
+ return {
586
674
  kind: humanNotice ? "undelivered-human-notice" : "undelivered-wake",
587
675
  row,
588
676
  route: humanNotice ? noticeOwner : resolveOrch(row.destinationSession, row) ?? row.destinationSession,
@@ -595,54 +683,56 @@ export async function runStuckSweep(deps) {
595
683
  : humanNotice
596
684
  ? `${failure}; check human-notification delivery rather than retrying the agent wake`
597
685
  : `${failure} and nothing retried it`,
598
- });
599
- }
686
+ };
687
+ };
688
+ const undeliveredNow = (qitemId) => indexed(() => deps.queueRepo.findUndelivered({ qitemId }))[0];
600
689
  // The A1 net — created-with-destination rows carrying real obligations, unclaimed past
601
690
  // the config-keyed age. Parks (state=blocked) legitimately wait and never appear here;
602
691
  // failed-nudge rows already surfaced in half 2; laddered rows are S01's.
603
692
  const cutoff = new Date(now.getTime() - ageMinutes * 60_000).toISOString();
604
- const unclaimedRows = deps.db
605
- .prepare(`SELECT qitem_id FROM queue_items
606
- WHERE state = 'pending'
607
- AND claimed_at IS NULL
608
- AND destination_session IS NOT NULL AND destination_session != ''
609
- AND ts_created <= ?
610
- AND (last_nudge_result IS NULL OR last_nudge_result NOT LIKE 'failed:%')`)
611
- .all(cutoff);
612
- for (const { qitem_id } of unclaimedRows) {
613
- const row = deps.queueRepo.getById(qitem_id);
693
+ const unclaimedCandidate = (qitemId, recordSuppression) => {
694
+ const row = indexed(() => deps.queueRepo.getById(qitemId));
614
695
  if (!row || isFindingRow(row))
615
- continue;
696
+ return null;
697
+ // The query's own predicate, on the row as it is now.
698
+ if (row.state !== "pending" || row.claimedAt || !row.destinationSession || row.tsCreated > cutoff
699
+ || startsWithCI(row.lastNudgeResult, "failed:"))
700
+ return null;
616
701
  if (deps.queueRepo.isLocalHumanDecisionWithoutGateway(row))
617
- continue;
702
+ return null;
618
703
  const actionableAt = pendingSince(deps.db, row.qitemId) ?? row.tsCreated;
619
704
  if (actionableAt > cutoff)
620
- continue;
705
+ return null;
621
706
  // #514 — an ask already posted to its registered human in the current delivery episode waits on
622
707
  // that human; it is not stuck, and a finding would post the human again. Unposted, failed,
623
708
  // legacy and non-human rows keep this net.
624
709
  if (deps.queueRepo.humanNotificationPostedThisEpisode(row.qitemId))
625
- continue;
710
+ return null;
626
711
  // An ask placed on Steering without an alert waits on its person there by design; a finding would alert them.
627
712
  if (deps.queueRepo.humanAskWithoutAlert(row.qitemId))
628
- continue;
713
+ return null;
629
714
  // Quiet hours: a held ask whose window's release job is live waits on that job, and one already released waits on
630
715
  // its post; neither is stuck. A release whose post failed is reported once, by the undelivered-wake loop above. A
631
716
  // hold with no live release job is stuck: nothing will ever release it.
632
717
  const quiet = quietHoldCustody(deps.db, row.qitemId, now);
633
718
  if (quiet && quiet.state !== "orphaned")
634
- continue;
719
+ return null;
720
+ // An explicit informational update to a currently registered human is for reading, not an obligation to claim,
721
+ // unless its quiet-hours hold has been orphaned before release.
722
+ if (!quiet && deps.queueRepo.isRegisteredHumanUpdate(row))
723
+ return null;
635
724
  // The seat's typing guard or interruption level held its wake on purpose: it's held and readable at the seat, not
636
725
  // stuck. (A handed-off baton's one held notice is the wake ladder's.)
637
726
  if (row.lastNudgeResult === "retained:typing_guard")
638
- continue;
727
+ return null;
639
728
  // The ladder check runs LAST here too: a row the ladder alone would have stopped is
640
729
  // ladder-suppressed, and its finding stays open (#1419).
641
730
  if (hasLiveLadder(deps.db, row.qitemId, now, suppressionMinutes)) {
642
- suppressedTags.add(findingDedupTag("unclaimed-obligation", row.qitemId));
643
- continue;
731
+ if (recordSuppression)
732
+ suppressedTags.add(findingDedupTag("unclaimed-obligation", row.qitemId));
733
+ return null;
644
734
  }
645
- candidates.push({
735
+ return {
646
736
  kind: "unclaimed-obligation",
647
737
  row,
648
738
  route: resolveOrch(row.destinationSession, row) ?? row.destinationSession,
@@ -651,8 +741,8 @@ export async function runStuckSweep(deps) {
651
741
  why: quiet?.state === "orphaned"
652
742
  ? `held for quiet hours (window ${quiet.windowId}) for ${minutesSince(actionableAt, now)} min, but no release job is live for that window: nothing will release it`
653
743
  : `actionable with a destination and unclaimed for ${minutesSince(actionableAt, now)} min (threshold ${ageMinutes})`,
654
- });
655
- }
744
+ };
745
+ };
656
746
  // The custody class — a terminal row whose closure names one or more successor
657
747
  // qitems or seat-address targets (closure_reason = 'handed_off_to'). A local miss is
658
748
  // never proof of absence: the successor may live in another registered host's database.
@@ -675,48 +765,21 @@ export async function runStuckSweep(deps) {
675
765
  // owner, so skip only recorded handoffs whose current target still matches (#341).
676
766
  // Closures outside the recent 24-hour window without open findings are skipped so upgrading
677
767
  // a real queue history does not raise a flood of historical findings.
678
- const custodyHours = deps.custodyWindowHours ?? STUCK_SWEEP_CUSTODY_WINDOW_HOURS;
679
- const custodyCutoff = new Date(now.getTime() - custodyHours * 3_600_000).toISOString();
680
- const openDanglingIds = [];
681
- const danglingPrefix = "stuck-sweep:dangling-closure:";
682
- for (const { tags } of deps.db
683
- .prepare(`SELECT tags FROM queue_items WHERE state IN ('pending', 'in-progress', 'blocked') AND tags LIKE ?`)
684
- .all(`%"${danglingPrefix}%`)) {
685
- try {
686
- for (const tag of JSON.parse(tags)) {
687
- if (tag.startsWith(danglingPrefix)) {
688
- openDanglingIds.push(tag.slice(danglingPrefix.length));
689
- }
690
- }
691
- }
692
- catch {
693
- // Skip malformed tags
694
- }
695
- }
696
- const custodyRows = deps.db
697
- .prepare(
698
- // Bound candidates before checking state: including handed-off in the
699
- // state index scan would otherwise revisit all historical atomic handoffs.
700
- `WITH custody_candidates AS MATERIALIZED (
701
- SELECT qitem_id, state, handed_off_to, closure_target, closure_reason
702
- FROM queue_items WHERE ts_updated >= ?
703
- UNION
704
- SELECT qitem_id, state, handed_off_to, closure_target, closure_reason
705
- FROM queue_items WHERE qitem_id IN (SELECT value FROM json_each(?))
706
- )
707
- SELECT q.qitem_id FROM custody_candidates q
708
- WHERE (q.state IN ('done', 'canceled') OR (q.state = 'handed-off'
709
- AND (q.handed_off_to IS NULL OR q.closure_target IS NOT q.handed_off_to)))
710
- AND (q.closure_target LIKE 'qitem-%' OR q.closure_reason = 'handed_off_to')`)
711
- .all(custodyCutoff, JSON.stringify(openDanglingIds));
712
- for (const { qitem_id } of custodyRows) {
713
- const row = deps.queueRepo.getById(qitem_id);
768
+ /** `recheck`: read live without the lent indexes, and don't log the registry fallback a second time. */
769
+ const custodyCandidate = (qitemId, hasSuccessor, recheck = false) => {
770
+ // A recheck reads live, without the lent indexes: one row's own queries cost less than a rebuilt successor index.
771
+ const row = recheck ? deps.queueRepo.getById(qitemId) : indexed(() => deps.queueRepo.getById(qitemId));
714
772
  if (!row || isFindingRow(row))
715
- continue;
773
+ return null;
774
+ // The query's own predicate, on the row as it is now.
775
+ const closed = row.state === "done" || row.state === "canceled"
776
+ || (row.state === "handed-off" && (row.handedOffTo == null || (row.closureTarget ?? null) !== row.handedOffTo));
777
+ if (!closed || !(startsWithCI(row.closureTarget, "qitem-") || row.closureReason === "handed_off_to"))
778
+ return null;
716
779
  // Local recorded targets were filtered in SQL; remote keys use the same
717
780
  // derivation as the cross-host close, without reading successor history.
718
781
  if (row.state === "handed-off" && matchesRecordedHandoffTarget(row.qitemId, row.handedOffTo, row.closureTarget))
719
- continue;
782
+ return null;
720
783
  const targets = (row.closureTarget ?? row.handedOffTo ?? "")
721
784
  .split(",")
722
785
  .map((target) => target.trim())
@@ -739,17 +802,17 @@ export async function runStuckSweep(deps) {
739
802
  }
740
803
  if (target === row.qitemId)
741
804
  return true;
742
- return !deps.queueRepo.getById(target);
805
+ return !indexed(() => deps.queueRepo.getById(target));
743
806
  }
744
807
  try {
745
- return !hasLinkedSuccessor(deps.db, row.qitemId, target);
808
+ return !hasSuccessor(row.qitemId, target);
746
809
  }
747
810
  catch {
748
811
  return true;
749
812
  }
750
813
  });
751
814
  if (verificationTargets.length === 0)
752
- continue;
815
+ return null;
753
816
  let route = row.destinationSession;
754
817
  try {
755
818
  route = custodyFindingRoute(deps.db, deps.queueRepo, row);
@@ -759,9 +822,10 @@ export async function runStuckSweep(deps) {
759
822
  throw err;
760
823
  // The registry may not exist before the first human is registered. Losing
761
824
  // owner refinement must not stop unrelated findings or their resolution.
762
- log(`[stuck-sweep] keeping custody route for ${row.qitemId} at ${row.destinationSession}: ${err.message}`);
825
+ if (!recheck)
826
+ log(`[stuck-sweep] keeping custody route for ${row.qitemId} at ${row.destinationSession}: ${err.message}`);
763
827
  }
764
- candidates.push({
828
+ return {
765
829
  kind: "dangling-closure",
766
830
  row,
767
831
  route,
@@ -769,7 +833,174 @@ export async function runStuckSweep(deps) {
769
833
  evidenceAt: latestIso(row.tsUpdated),
770
834
  why: `closed (${row.closureReason ?? "?"}) with successor custody that this local store cannot fully verify`,
771
835
  verificationTargets,
772
- });
836
+ };
837
+ };
838
+ const armedJobOf = (qitemId) => deps.db.prepare("SELECT wake_ref FROM queue_transition_wakes WHERE qitem_id = ? AND phase = 'armed' ORDER BY transition_id DESC LIMIT 1").get(qitemId)?.wake_ref;
839
+ /** A kind's rule, again, on the row as it is now (read live, without the lent indexes): the candidate it makes now,
840
+ * with its current route, reason and targets, or null when it no longer holds. */
841
+ const freshCandidate = (kind, id, jobId) => {
842
+ switch (kind) {
843
+ case "overdue-claim": {
844
+ const row = deps.queueRepo.findOverdue({ now: nowIso, qitemId: id })[0];
845
+ return row ? overdueCandidate(row) : null;
846
+ }
847
+ case "stalled-after-claim": return stalledCandidate(id);
848
+ case "unconsumed-wait": {
849
+ const job = jobId ?? armedJobOf(id);
850
+ const c = job ? waitCandidate(job) : null;
851
+ return c?.row.qitemId === id ? c : null;
852
+ }
853
+ case "parked-owner-no-input": return parkedCandidate(id);
854
+ case "undelivered-wake":
855
+ case "undelivered-human-notice": {
856
+ const row = undeliveredNow(id);
857
+ // the wake retry already ran in this pass; a row that still needs it now was not woken by it
858
+ const c = row ? undeliveredCandidate(row, false) : null;
859
+ return c?.kind === kind ? c : null;
860
+ }
861
+ case "unclaimed-obligation": return unclaimedCandidate(id, false);
862
+ case "dangling-closure": return custodyCandidate(id, (source, target) => hasLinkedSuccessor(deps.db, source, target), true);
863
+ default: return null;
864
+ }
865
+ };
866
+ /** Whether a kind's rule still holds now, leaving the routing notes (routeNotes, routed) as they were. */
867
+ const ruleHolds = (kind, id, jobId) => {
868
+ const notes = new Map(routeNotes);
869
+ const wasRouted = new Set(routed);
870
+ try {
871
+ return !!freshCandidate(kind, id, jobId);
872
+ }
873
+ finally {
874
+ routeNotes.clear();
875
+ for (const [k, v] of notes)
876
+ routeNotes.set(k, v);
877
+ routed.clear();
878
+ for (const k of wasRouted)
879
+ routed.add(k);
880
+ }
881
+ };
882
+ const stillStuck = (c) => ruleHolds(c.kind, c.row.qitemId, c.jobId);
883
+ /** The kinds the resolution closes on "no longer detected" alone (the others need source evidence). */
884
+ const resolvedByRule = new Set(["overdue-claim", "stalled-after-claim", "unconsumed-wait", "parked-owner-no-input", "dangling-closure"]);
885
+ // The rows each rule looks at. The id lists are judged on a fresh getById per row; the two finders return whole
886
+ // rows, which are read again by id once other code may have run since the list was read.
887
+ let listedAt = othersRan;
888
+ for (const listed of indexed(() => deps.queueRepo.findOverdue({ now: nowIso }))) {
889
+ if (dueToYield())
890
+ await yieldLoop();
891
+ const row = listedAt !== othersRan ? indexed(() => deps.queueRepo.findOverdue({ now: nowIso, qitemId: listed.qitemId }))[0] : listed;
892
+ const c = row ? overdueCandidate(row) : null;
893
+ if (!c)
894
+ continue;
895
+ candidates.push(c);
896
+ try {
897
+ // Only a transition and an event: no index or listed row changes.
898
+ deps.queueRepo.recordClosureOverdue(row.qitemId, { now: nowIso });
899
+ }
900
+ catch (err) {
901
+ log(`[stuck-sweep] failed to record closure-overdue for ${row.qitemId}: ${err instanceof Error ? err.message : String(err)}`);
902
+ }
903
+ }
904
+ for (const { qitem_id } of deps.db
905
+ .prepare("SELECT qitem_id FROM queue_items WHERE state IN ('pending', 'in-progress') AND claimed_at IS NOT NULL")
906
+ .all()) {
907
+ if (dueToYield())
908
+ await yieldLoop();
909
+ const c = stalledCandidate(qitem_id);
910
+ if (c)
911
+ candidates.push(c);
912
+ }
913
+ for (const { job_id } of deps.db.prepare("SELECT job_id FROM watchdog_jobs WHERE state = 'active' AND policy = 'periodic-reminder'")
914
+ .all()) {
915
+ if (dueToYield())
916
+ await yieldLoop();
917
+ const c = waitCandidate(job_id);
918
+ if (c)
919
+ candidates.push(c);
920
+ }
921
+ for (const { qitem_id } of deps.db.prepare("SELECT qitem_id FROM queue_items WHERE state='blocked' AND last_nudge_result LIKE 'failed:%'")
922
+ .all()) {
923
+ if (dueToYield())
924
+ await yieldLoop();
925
+ const c = parkedCandidate(qitem_id);
926
+ if (c)
927
+ candidates.push(c);
928
+ }
929
+ listedAt = othersRan;
930
+ for (const listed of indexed(() => deps.queueRepo.findUndelivered())) {
931
+ if (dueToYield())
932
+ await yieldLoop();
933
+ let row = listedAt !== othersRan ? undeliveredNow(listed.qitemId) : listed;
934
+ if (!row || isFindingRow(row))
935
+ continue;
936
+ if (wakeRetryEligible(row) && wakeToRetry(row, isHumanNotice(row))) {
937
+ await deps.queueRepo.deliverWakeForSuccessor(row.qitemId, row.destinationSession, true, row.sourceSession);
938
+ othersMayHaveRun();
939
+ // judged again on the row as the send (and anyone else during it) left it
940
+ row = undeliveredNow(row.qitemId);
941
+ if (!row || !startsWithCI(row.lastNudgeResult, "unroutable:"))
942
+ continue;
943
+ }
944
+ const c = undeliveredCandidate(row, true);
945
+ if (c)
946
+ candidates.push(c);
947
+ }
948
+ for (const { qitem_id } of deps.db
949
+ .prepare(`SELECT qitem_id FROM queue_items
950
+ WHERE state = 'pending'
951
+ AND claimed_at IS NULL
952
+ AND destination_session IS NOT NULL AND destination_session != ''
953
+ AND ts_created <= ?
954
+ AND (last_nudge_result IS NULL OR last_nudge_result NOT LIKE 'failed:%')`)
955
+ .all(cutoff)) {
956
+ if (dueToYield())
957
+ await yieldLoop();
958
+ const c = unclaimedCandidate(qitem_id, true);
959
+ if (c)
960
+ candidates.push(c);
961
+ }
962
+ const custodyHours = deps.custodyWindowHours ?? STUCK_SWEEP_CUSTODY_WINDOW_HOURS;
963
+ const custodyCutoff = new Date(now.getTime() - custodyHours * 3_600_000).toISOString();
964
+ const openDanglingIds = [];
965
+ const danglingPrefix = "stuck-sweep:dangling-closure:";
966
+ for (const { tags } of deps.db
967
+ .prepare(`SELECT tags FROM queue_items WHERE state IN ('pending', 'in-progress', 'blocked') AND tags LIKE ?`)
968
+ .all(`%"${danglingPrefix}%`)) {
969
+ try {
970
+ for (const tag of JSON.parse(tags)) {
971
+ if (tag.startsWith(danglingPrefix)) {
972
+ openDanglingIds.push(tag.slice(danglingPrefix.length));
973
+ }
974
+ }
975
+ }
976
+ catch {
977
+ // Skip malformed tags
978
+ }
979
+ }
980
+ const custodyRows = deps.db
981
+ .prepare(
982
+ // Bound candidates before checking state: including handed-off in the
983
+ // state index scan would otherwise revisit all historical atomic handoffs.
984
+ `WITH custody_candidates AS MATERIALIZED (
985
+ SELECT qitem_id, state, handed_off_to, closure_target, closure_reason
986
+ FROM queue_items WHERE ts_updated >= ?
987
+ UNION
988
+ SELECT qitem_id, state, handed_off_to, closure_target, closure_reason
989
+ FROM queue_items WHERE qitem_id IN (SELECT value FROM json_each(?))
990
+ )
991
+ SELECT q.qitem_id FROM custody_candidates q
992
+ WHERE (q.state IN ('done', 'canceled') OR (q.state = 'handed-off'
993
+ AND (q.handed_off_to IS NULL OR q.closure_target IS NOT q.handed_off_to)))
994
+ AND (q.closure_target LIKE 'qitem-%' OR q.closure_reason = 'handed_off_to')`)
995
+ .all(custodyCutoff, JSON.stringify(openDanglingIds));
996
+ successors = createLinkedSuccessorLookup(deps.db, custodyRows.map((r) => r.qitem_id));
997
+ const lookup = successors;
998
+ for (const { qitem_id } of custodyRows) {
999
+ if (dueToYield())
1000
+ await yieldLoop();
1001
+ const c = custodyCandidate(qitem_id, (source, target) => lookup.has(source, target));
1002
+ if (c)
1003
+ candidates.push(c);
773
1004
  }
774
1005
  // A finding for a confirmed-missing session goes to a live recovery seat when one is available,
775
1006
  // since nothing would ever wake the missing one (the ladder covers handed-off batons only): the
@@ -783,9 +1014,9 @@ export async function runStuckSweep(deps) {
783
1014
  };
784
1015
  const sessionMissing = deps.sessionConfirmedMissing ?? ((session) => stoppedReason(session) !== null);
785
1016
  let recoverySeats;
786
- for (const c of candidates) {
1017
+ const routeAroundMissing = (c) => {
787
1018
  if (!sessionMissing(c.route))
788
- continue;
1019
+ return;
789
1020
  const stoppedDescription = stoppedReason(c.route) === "pane_exited"
790
1021
  ? "has a confirmed exited pane (pane_exited)" : "is confirmed missing (session_missing)";
791
1022
  recoverySeats ??= [(deps.resolveRecoveryAgentSeat ?? resolveRecoveryAgentSeat)(), (deps.resolveOperatorSeat ?? resolveOperatorSeat)()];
@@ -794,12 +1025,12 @@ export async function runStuckSweep(deps) {
794
1025
  const floor = chosen < 0 ? null : choices[chosen];
795
1026
  if (!floor) {
796
1027
  c.why += `; ${c.route} ${stoppedDescription} and no live recovery seat is available (operator agent, operator seat and creator are each unset, missing or this seat; an operator agent setting that's unreadable or isn't an agent's session counts as unset), so this finding stays addressed to it`;
797
- continue;
1028
+ return;
798
1029
  }
799
1030
  // Name the rule that chose it, so whoever receives the finding knows why, and which setting to change.
800
1031
  c.why += `; ${c.route} ${stoppedDescription}, so this finding goes to ${floor}, ${RECOVERY_SEAT_RULES[chosen]}`;
801
1032
  c.route = floor;
802
- }
1033
+ };
803
1034
  // A destination its own wake found unroutable, and still is (no terminal, not a person: a hosted member, or a
804
1035
  // mistyped address), can't hear its finding either; a seat launched since its wake keeps its own. A hosted member
805
1036
  // OpenRig rings, whose work is still unclaimed (its ring failed, or it didn't pick the work up by the unclaimed
@@ -809,14 +1040,14 @@ export async function runStuckSweep(deps) {
809
1040
  // unroutable or a terminal seat itself. A bound terminal seat goes the same way: the queue wake types nothing into
810
1041
  // it, and nothing there can claim work.
811
1042
  const classOf = (seat) => deps.queueRepo.classifyDestinationOf(seat).class;
812
- for (const c of candidates) {
1043
+ const routeAroundNoWake = (c) => {
813
1044
  if (c.route !== c.row.destinationSession)
814
- continue;
1045
+ return;
815
1046
  const destination = classOf(c.row.destinationSession);
816
1047
  const noRoute = destination === "unroutable" && !!c.row.lastNudgeResult?.startsWith("unroutable:");
817
1048
  const terminalSeat = destination === "pane-bound" && isBoundTerminalSeat(deps.db, c.row.destinationSession);
818
1049
  if (!noRoute && !terminalSeat && !(destination === "hosted" && !c.row.claimedAt))
819
- continue;
1050
+ return;
820
1051
  const operatorSeat = (deps.resolveOperatorSeat ?? resolveOperatorSeat)();
821
1052
  const person = operatorSeat && classOf(operatorSeat) === "gateway-routable" ? operatorSeat : null;
822
1053
  const choices = [person, c.row.sourceSession, (deps.resolveRecoveryAgentSeat ?? resolveRecoveryAgentSeat)()];
@@ -829,22 +1060,76 @@ export async function runStuckSweep(deps) {
829
1060
  : `; ${c.route} is a hosted member. OpenRig rang its trigger (${c.row.lastNudgeResult ?? "no ring recorded"}), and it hasn't claimed this work. It sees work only when it checks, so ask it to`;
830
1061
  if (chosen < 0) {
831
1062
  c.why += `. No person, creator or operator agent that can be reached is available, so this finding stays addressed to it`;
832
- continue;
1063
+ return;
833
1064
  }
834
1065
  c.why += `. This finding goes to ${choices[chosen]}, ${NO_WAKE_ROUTE_RULES[chosen]}`;
835
1066
  c.route = choices[chosen];
1067
+ };
1068
+ /** The two re-routes, in order, for one candidate. */
1069
+ const routeCandidate = (c) => { routeAroundMissing(c); routeAroundNoWake(c); };
1070
+ for (const c of candidates) {
1071
+ if (dueToYield())
1072
+ await yieldLoop();
1073
+ routeAroundMissing(c);
1074
+ }
1075
+ for (const c of candidates) {
1076
+ if (dueToYield())
1077
+ await yieldLoop();
1078
+ routeAroundNoWake(c);
836
1079
  }
837
1080
  // Route: idempotent per (row, kind). An existing open finding refreshes its age; a
838
1081
  // new one is created durable + waking (the create path's default nudge).
839
1082
  const findings = [];
840
1083
  const liveDedupTags = new Set();
1084
+ const candidateIds = new Set(candidates.map((c) => c.row.qitemId));
841
1085
  // A finding that could not be created (a row whose destination no longer resolves, say) must not
842
1086
  // stop the others: it is reported, its row stays detected, and the pass is still a failure.
843
1087
  const failedCreates = [];
1088
+ // #2430: an unclaimed row whose finding would go back to its own agent seat (no delegation parent and no escalates_to
1089
+ // route declared) tells that seat nothing: it already holds the row. A seat that reads its rows without claiming
1090
+ // them, a person's front door, got one such finding per row. Those rows share one standing notice per seat instead
1091
+ // (below). A finding per row stays for a person's address or a terminal seat, for a declared route that failed (its
1092
+ // finding names why, and a declared delegation parent with no session is one), and for a row that already has a
1093
+ // recovery.
1094
+ const agentSeats = new Map();
1095
+ /** An agent seat's node: one whose runtime isn't a terminal, with no declared delegation parent, at an address that
1096
+ * isn't a person's. An address the human registry can't classify counts as a person's. null for anything else. Read
1097
+ * once per seat per pass. */
1098
+ const agentSeatNode = (session) => {
1099
+ if (agentSeats.has(session))
1100
+ return agentSeats.get(session);
1101
+ const nodeId = resolveSessionNodeId(deps.db, session);
1102
+ const node = nodeId ? deps.db.prepare(`SELECT n.logical_id AS logicalId, n.runtime AS runtime, r.name AS rig,
1103
+ EXISTS (SELECT 1 FROM edges e WHERE e.target_id = n.id AND e.kind = 'delegates_to') AS parent
1104
+ FROM nodes n JOIN rigs r ON r.id = n.rig_id WHERE n.id = ?`)
1105
+ .get(nodeId) : undefined;
1106
+ let agent = null;
1107
+ try {
1108
+ if (node && node.runtime !== "terminal" && !node.parent && !deps.queueRepo.isHumanDestination(session)) {
1109
+ agent = { logicalId: node.logicalId, rig: node.rig };
1110
+ }
1111
+ }
1112
+ catch { /* unclassifiable: a person's, as above */ }
1113
+ agentSeats.set(session, agent);
1114
+ return agent;
1115
+ };
1116
+ const selfRoutedUnclaimed = (c) => c.kind === "unclaimed-obligation"
1117
+ && c.route === c.row.destinationSession && !routeNotes.has(c.row.qitemId) && agentSeatNode(c.route) !== null;
1118
+ const unclaimedBacklog = new Map();
844
1119
  for (const c of [...new Map(candidates.map(c => [c.row.qitemId, c])).values()]) {
1120
+ if (dueToYield())
1121
+ await yieldLoop();
845
1122
  const dedupTag = findingDedupTag(c.kind, c.row.qitemId);
846
- const shared = findQueueRecovery(deps.db, c.row.qitemId);
847
- const sharedRow = shared ? deps.queueRepo.getById(shared.qitemId) : null;
1123
+ const shared = recoveries.find(c.row.qitemId);
1124
+ if (!shared && selfRoutedUnclaimed(c)) {
1125
+ const rows = unclaimedBacklog.get(c.route);
1126
+ if (rows)
1127
+ rows.push(c);
1128
+ else
1129
+ unclaimedBacklog.set(c.route, [c]);
1130
+ continue;
1131
+ }
1132
+ const sharedRow = shared ? indexed(() => deps.queueRepo.getById(shared.qitemId)) : null;
848
1133
  // A later accepted deadline can expire after the previous finding closed.
849
1134
  // Its newer time is fresh evidence even when the pickup candidate wins this row.
850
1135
  // An OPEN recovery still owns custody.
@@ -864,7 +1149,11 @@ export async function runStuckSweep(deps) {
864
1149
  if (sharedRow && isFindingRow(sharedRow) && sharedRow.summary?.startsWith("Stuck sweep: ")) {
865
1150
  const currentKind = sharedRow.summary.match(/^Stuck sweep: ([a-z-]+) on /)?.[1];
866
1151
  const pickupOrDeadline = (kind) => kind === "stalled-after-claim" || kind === "overdue-claim";
867
- if (currentKind && currentKind !== c.kind && pickupOrDeadline(currentKind) && pickupOrDeadline(c.kind)) {
1152
+ const humanUpdateNotice = currentKind === "unclaimed-obligation"
1153
+ && c.kind === "undelivered-human-notice"
1154
+ && deps.queueRepo.isRegisteredHumanUpdate(c.row);
1155
+ if (currentKind && currentKind !== c.kind && ((pickupOrDeadline(currentKind) && pickupOrDeadline(c.kind)) || humanUpdateNotice)
1156
+ && stillStuck(c)) { // the new reason must still hold on the row as it is now
868
1157
  const marker = "\n\n--- Original finding (historical) ---\n";
869
1158
  const original = sharedRow.body.includes(marker) ? sharedRow.body.split(marker, 2)[1] : sharedRow.body;
870
1159
  const body = evidenceBody(deps.db, c) + marker + original;
@@ -894,33 +1183,155 @@ export async function runStuckSweep(deps) {
894
1183
  findings.push({ kind: c.kind, qitemId: c.row.qitemId, findingQitemId: existing.qitem_id, action: "refreshed" });
895
1184
  }
896
1185
  else if (renewedDeadline || !existing || evidenceIsNewer(c.evidenceAt, existing.ts_updated)) {
1186
+ // The row was found stuck before the pass's later yields and awaited writes: its rule runs again on the row as
1187
+ // it is now, and a row that no longer qualifies gets no new finding (its dedup tag stays live this pass).
1188
+ // the escalation note and hop recorded at listing belong to that route; keep only what this run records
1189
+ routeNotes.delete(c.row.qitemId);
1190
+ routed.delete(c.row.qitemId);
1191
+ const now_ = freshCandidate(c.kind, c.row.qitemId, c.jobId);
1192
+ if (!now_)
1193
+ continue;
1194
+ routeCandidate(now_); // its destination, reason and targets as they are now
897
1195
  const input = {
898
1196
  qitemId: recoveryId(deps.db, c.row.qitemId, renewedDeadline ? c.row.closureRequiredAt : undefined),
899
1197
  // The detector is machinery, not a seat: the obligation's own creator is the
900
1198
  // finding's source (the workflow-exception precedent).
901
1199
  sourceSession: c.row.sourceSession,
902
- destinationSession: c.route,
903
- body: evidenceBody(deps.db, c) + (routeNotes.has(c.row.qitemId) ? `\nescalation route: ${routeNotes.get(c.row.qitemId)}` : ""),
904
- summary: c.verificationTargets
905
- ? custodyHeadline(c.row.qitemId, c.verificationTargets, c.ageMinutes)
906
- : `Stuck sweep: ${c.kind} on ${c.row.qitemId} (${c.ageMinutes} min)`,
1200
+ destinationSession: now_.route,
1201
+ body: evidenceBody(deps.db, now_) + (routeNotes.has(c.row.qitemId) ? `\nescalation route: ${routeNotes.get(c.row.qitemId)}` : ""),
1202
+ summary: now_.verificationTargets
1203
+ ? custodyHeadline(c.row.qitemId, now_.verificationTargets, now_.ageMinutes)
1204
+ : `Stuck sweep: ${c.kind} on ${c.row.qitemId} (${now_.ageMinutes} min)`,
907
1205
  evidenceRef: `rig queue show ${c.row.qitemId}`,
908
1206
  tags: [STUCK_SWEEP_FINDING_TAG, dedupTag, recoveryTag(c.row.qitemId),
909
- ...(routed.has(c.row.qitemId) || c.row.tags?.includes(ESCALATION_HOP_TAG) ? [ESCALATION_HOP_TAG] : [])],
1207
+ ...(routed.has(c.row.qitemId) || now_.row.tags?.includes(ESCALATION_HOP_TAG) ? [ESCALATION_HOP_TAG] : [])],
910
1208
  // OpenRig's own finding, whoever created the stuck row.
911
1209
  wakeTrigger: "openrig",
912
1210
  };
913
1211
  try {
914
1212
  const created = await deps.queueRepo.create(input);
1213
+ othersMayHaveRun();
915
1214
  findings.push({ kind: c.kind, qitemId: c.row.qitemId, findingQitemId: created.qitemId, action: "created" });
916
1215
  }
917
1216
  catch (err) {
918
- const message = `${c.kind} finding for ${c.row.qitemId} to ${c.route} not created: ${err instanceof Error ? err.message : String(err)}`;
1217
+ const message = `${c.kind} finding for ${c.row.qitemId} to ${now_.route} not created: ${err instanceof Error ? err.message : String(err)}`;
1218
+ othersMayHaveRun();
919
1219
  log(`[stuck-sweep] ${message}`);
920
1220
  failedCreates.push(message);
921
1221
  }
922
1222
  }
923
1223
  }
1224
+ // A seat's standing notice for those rows. It stands for every row it has listed until that row is resolved at its
1225
+ // source (the evidence a finding per row needs to close: claimed, parked, closed) or gets a finding of its own, so a
1226
+ // detection filter (a raised threshold, the wake ladder) never reads as done. While any is left it stays open and is
1227
+ // rewritten in place; once none is, the sweep closes it. A closed notice, dismissed or resolved, holds back only the
1228
+ // rows it stood for, each only until it has newer evidence than the close: any other row files a new notice. It wakes
1229
+ // the seat once, when it's filed.
1230
+ const backlogRow = (c) => ({ qitemId: c.row.qitemId, since: c.evidenceAt, from: c.row.sourceSession, summary: c.row.summary });
1231
+ const backlogPrefix = unclaimedBacklogTag("");
1232
+ const backlogSeats = new Set(unclaimedBacklog.keys());
1233
+ for (const { tags } of deps.db.prepare(`SELECT tags FROM queue_items WHERE state IN ('pending', 'in-progress', 'blocked')
1234
+ AND (tags LIKE '%"stuck-sweep:%') AND tags LIKE ?`).all(`%"${backlogPrefix}%`)) {
1235
+ try {
1236
+ for (const tag of JSON.parse(tags))
1237
+ if (tag.startsWith(backlogPrefix))
1238
+ backlogSeats.add(tag.slice(backlogPrefix.length));
1239
+ }
1240
+ catch { /* Skip malformed tags */ }
1241
+ }
1242
+ for (const seat of backlogSeats) {
1243
+ if (dueToYield())
1244
+ await yieldLoop();
1245
+ const rows = unclaimedBacklog.get(seat) ?? [];
1246
+ const tag = unclaimedBacklogTag(seat);
1247
+ liveDedupTags.add(tag);
1248
+ const node = agentSeatNode(seat);
1249
+ const last = deps.db
1250
+ .prepare(
1251
+ // The first term lets the planner use idx_queue_items_recovery_tags, as the finding lookup above does.
1252
+ `SELECT qitem_id, state, ts_updated, summary, body FROM queue_items
1253
+ WHERE (tags LIKE '%"stuck-sweep:%') AND tags LIKE ? ESCAPE '\\'
1254
+ ORDER BY CASE WHEN state IN ('pending', 'in-progress', 'blocked') THEN 0 ELSE 1 END,
1255
+ ts_updated DESC, ts_created DESC, qitem_id DESC
1256
+ LIMIT 1`)
1257
+ .get(`%"${tag.replace(/[\\%_]/g, (ch) => `\\${ch}`)}"%`);
1258
+ if (last && ["pending", "in-progress", "blocked"].includes(last.state)) {
1259
+ const listedNow = new Set(rows.map((c) => c.row.qitemId));
1260
+ const stoodFor = backlogRowsOf(last.body);
1261
+ const still = [...(stoodFor ?? [])].filter((id) => !listedNow.has(id)).flatMap((id) => {
1262
+ const row = indexed(() => deps.queueRepo.getById(id));
1263
+ // Gone, someone else's now, resolved at its source, or held by a finding or recovery of its own: one actually
1264
+ // written, so a create that failed this pass leaves the row here.
1265
+ if (!row || row.destinationSession !== seat || recoveries.find(id)
1266
+ || deliveryResolutionEvidence(deps, "unclaimed-obligation", id, now))
1267
+ return [];
1268
+ return [{ qitemId: id, since: pendingSince(deps.db, id) ?? row.tsCreated, from: row.sourceSession, summary: row.summary }];
1269
+ });
1270
+ const standsFor = [...rows.map(backlogRow), ...still];
1271
+ // With its list unreadable, the notice may still stand for rows: it's left as it is, never closed.
1272
+ if (standsFor.length === 0 && !stoodFor) {
1273
+ findings.push({ kind: "unclaimed-backlog", qitemId: seat, findingQitemId: last.qitem_id, action: "refreshed" });
1274
+ continue;
1275
+ }
1276
+ if (standsFor.length === 0) {
1277
+ await deps.queueRepo.update({
1278
+ qitemId: last.qitem_id,
1279
+ actorSession: "stuck-sweep@system",
1280
+ state: "done",
1281
+ closureReason: "no-follow-on",
1282
+ transitionNote: `stuck-sweep resolved: unclaimed-backlog on ${seat}: every row it stood for is claimed, parked, closed or has its own finding`,
1283
+ });
1284
+ othersMayHaveRun();
1285
+ findings.push({ kind: "unclaimed-backlog", qitemId: seat, findingQitemId: last.qitem_id, action: "closed" });
1286
+ continue;
1287
+ }
1288
+ const text = unclaimedBacklogText(seat, standsFor, ageMinutes, node);
1289
+ if (text.summary !== last.summary || text.body !== last.body) {
1290
+ deps.db.prepare("UPDATE queue_items SET body = ?, summary = ? WHERE qitem_id = ? AND body = ? AND summary IS ? AND state IN ('pending', 'in-progress', 'blocked')")
1291
+ .run(text.body, text.summary, last.qitem_id, last.body, last.summary);
1292
+ }
1293
+ findings.push({ kind: "unclaimed-backlog", qitemId: seat, findingQitemId: last.qitem_id, action: "refreshed" });
1294
+ continue;
1295
+ }
1296
+ if (rows.length === 0)
1297
+ continue;
1298
+ // Each row's rule again, on the row as it is now, as a finding per row is checked right before it's created.
1299
+ const current = rows.flatMap((c) => {
1300
+ routeNotes.delete(c.row.qitemId);
1301
+ routed.delete(c.row.qitemId);
1302
+ const now_ = freshCandidate(c.kind, c.row.qitemId);
1303
+ if (now_)
1304
+ routeCandidate(now_);
1305
+ return now_ && selfRoutedUnclaimed(now_) && now_.route === seat && !recoveries.find(now_.row.qitemId) ? [now_] : [];
1306
+ });
1307
+ if (current.length === 0)
1308
+ continue;
1309
+ // A closed notice whose list is unreadable holds back every row, each until it has newer evidence than the close.
1310
+ const covered = last ? backlogRowsOf(last.body) : null;
1311
+ if (last && !current.some((c) => (covered !== null && !covered.has(c.row.qitemId)) || evidenceIsNewer(c.evidenceAt, last.ts_updated)))
1312
+ continue;
1313
+ const text = unclaimedBacklogText(seat, current.map(backlogRow), ageMinutes, node);
1314
+ try {
1315
+ const created = await deps.queueRepo.create({
1316
+ // A notice to a seat about its own rows comes from that seat, as a restore notice does; OpenRig wakes it.
1317
+ sourceSession: seat,
1318
+ destinationSession: seat,
1319
+ body: text.body,
1320
+ summary: text.summary,
1321
+ evidenceRef: `rig queue list --destination ${seat} --state pending`,
1322
+ tags: [STUCK_SWEEP_FINDING_TAG, tag],
1323
+ wakeTrigger: "openrig",
1324
+ });
1325
+ othersMayHaveRun();
1326
+ findings.push({ kind: "unclaimed-backlog", qitemId: seat, findingQitemId: created.qitemId, action: "created" });
1327
+ }
1328
+ catch (err) {
1329
+ const message = `unclaimed-backlog notice for ${seat} not created: ${err instanceof Error ? err.message : String(err)}`;
1330
+ othersMayHaveRun();
1331
+ log(`[stuck-sweep] ${message}`);
1332
+ failedCreates.push(message);
1333
+ }
1334
+ }
924
1335
  // Resolution: an open finding whose underlying condition is no longer detected closes
925
1336
  // with its reason — the sweep cleans up after itself, no human unwind.
926
1337
  const openFindings = deps.db
@@ -929,6 +1340,8 @@ export async function runStuckSweep(deps) {
929
1340
  AND tags LIKE ?`)
930
1341
  .all(`%"${STUCK_SWEEP_FINDING_TAG}"%`);
931
1342
  for (const f of openFindings) {
1343
+ if (dueToYield())
1344
+ await yieldLoop();
932
1345
  let tags = [];
933
1346
  try {
934
1347
  tags = JSON.parse(f.tags);
@@ -945,6 +1358,10 @@ export async function runStuckSweep(deps) {
945
1358
  // prove resolution either: delivery/pickup findings need source evidence.
946
1359
  if (suppressedTags.has(dedupTag))
947
1360
  continue;
1361
+ // #2661: a claim working only on a grace (a background shell, a pending managed restore) is not resolved: the
1362
+ // grace stops new detection, and an open stall recovery stays open, so the ceiling's expiry stays actionable.
1363
+ if (kind === "stalled-after-claim" && stuckId && deps.queueRepo.getById(stuckId)?.pickup?.grace)
1364
+ continue;
948
1365
  let resolution = "no longer detected";
949
1366
  if (stuckId && (kind === "undelivered-wake" || kind === "undelivered-human-notice" || kind === "unclaimed-obligation")) {
950
1367
  const evidence = deliveryResolutionEvidence(deps, kind, stuckId, now);
@@ -952,6 +1369,17 @@ export async function runStuckSweep(deps) {
952
1369
  continue;
953
1370
  resolution = evidence;
954
1371
  }
1372
+ // The list was read before this loop's yields: the finding's owner may have closed it since (done -> done is
1373
+ // refused, and would fail the whole pass).
1374
+ const current = deps.db.prepare("SELECT state FROM queue_items WHERE qitem_id = ?").get(f.qitem_id);
1375
+ if (!current || !["pending", "in-progress", "blocked"].includes(current.state))
1376
+ continue;
1377
+ // "No longer detected" rests on lists read before this loop's yields: a row that came back (blocked, then
1378
+ // in-progress past its deadline) during the pass still holds, so its rule runs again on the row as it is now.
1379
+ // (A row this pass did find, whose finding isn't live because another recovery now holds its custody, closes as
1380
+ // the base closed it.)
1381
+ if (kind && stuckId && resolvedByRule.has(kind) && !candidateIds.has(stuckId) && ruleHolds(kind, stuckId))
1382
+ continue;
955
1383
  await deps.queueRepo.update({
956
1384
  qitemId: f.qitem_id,
957
1385
  // The sweep performed this transition; ownership stays on the existing row.
@@ -960,6 +1388,7 @@ export async function runStuckSweep(deps) {
960
1388
  closureReason: "no-follow-on",
961
1389
  transitionNote: `stuck-sweep resolved: ${kind ?? "finding"} on ${stuckId ?? "row"} ${resolution}`,
962
1390
  });
1391
+ othersMayHaveRun();
963
1392
  if (kind && stuckId) {
964
1393
  findings.push({
965
1394
  kind: kind,