@openrig/cli 0.7.4 → 0.7.5

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 (316) hide show
  1. package/README.md +5 -5
  2. package/daemon/assets/plugins/openrig-core/.claude-plugin/plugin.json +1 -1
  3. package/daemon/assets/plugins/openrig-core/.codex-plugin/plugin.json +1 -1
  4. package/daemon/assets/plugins/openrig-core/skills/queue-handoff/SKILL.md +5 -1
  5. package/daemon/context-packs/help/manifest.yaml +1 -1
  6. package/daemon/context-packs/onboarding-width/manifest.yaml +1 -1
  7. package/daemon/context-packs/onboarding-width/public-what-you-can-do.md +20 -6
  8. package/daemon/context-packs/reference/getting-started.md +12 -2
  9. package/daemon/context-packs/reference/manifest.yaml +1 -1
  10. package/daemon/context-packs/reference/rig-spec.md +5 -1
  11. package/daemon/context-packs/reference/whats-new.md +153 -116
  12. package/daemon/context-packs/skills/agent-operated-software/manifest.yaml +1 -1
  13. package/daemon/context-packs/skills/agent-operated-workflows/manifest.yaml +1 -1
  14. package/daemon/context-packs/skills/applying-a-permission-policy/manifest.yaml +1 -1
  15. package/daemon/context-packs/skills/claude-compaction-restore/manifest.yaml +1 -1
  16. package/daemon/context-packs/skills/core/agent-starters/manifest.yaml +1 -1
  17. package/daemon/context-packs/skills/core/agent-startup-and-context-ingestion/manifest.yaml +1 -1
  18. package/daemon/context-packs/skills/core/cross-host-rig-commands/manifest.yaml +1 -1
  19. package/daemon/context-packs/skills/core/human-in-the-loop/manifest.yaml +1 -1
  20. package/daemon/context-packs/skills/core/messaging-the-human/manifest.yaml +1 -1
  21. package/daemon/context-packs/skills/core/openrig-architect/manifest.yaml +1 -1
  22. package/daemon/context-packs/skills/core/openrig-cmux/manifest.yaml +1 -1
  23. package/daemon/context-packs/skills/core/openrig-herdr/manifest.yaml +1 -1
  24. package/daemon/context-packs/skills/core/openrig-skills/manifest.yaml +1 -1
  25. package/daemon/context-packs/skills/core/openrig-software-factory/manifest.yaml +1 -1
  26. package/daemon/context-packs/skills/core/openrig-upgrade/manifest.yaml +1 -1
  27. package/daemon/context-packs/skills/core/rig-bundles-and-shareable-artifacts/SKILL.md +11 -0
  28. package/daemon/context-packs/skills/core/rig-bundles-and-shareable-artifacts/manifest.yaml +1 -1
  29. package/daemon/context-packs/skills/core/rig-lifecycle/manifest.yaml +1 -1
  30. package/daemon/context-packs/skills/core/session-source-fork/manifest.yaml +1 -1
  31. package/daemon/context-packs/skills/core/specification-system/manifest.yaml +1 -1
  32. package/daemon/context-packs/skills/core/topology-mutation-and-seat-management/manifest.yaml +1 -1
  33. package/daemon/context-packs/skills/core/watchdog/manifest.yaml +1 -1
  34. package/daemon/context-packs/skills/delegating-work/manifest.yaml +1 -1
  35. package/daemon/context-packs/skills/forming-an-openrig-mental-model/manifest.yaml +1 -1
  36. package/daemon/context-packs/skills/loading-addressable-markdown/manifest.yaml +1 -1
  37. package/daemon/context-packs/skills/mission-slice-sop/manifest.yaml +1 -1
  38. package/daemon/context-packs/skills/openrig-operating-model/manifest.yaml +1 -1
  39. package/daemon/context-packs/skills/openrig-user/manifest.yaml +1 -1
  40. package/daemon/context-packs/skills/orienting-to-an-inherited-seat/manifest.yaml +1 -1
  41. package/daemon/context-packs/skills/pm/backlog-capture/manifest.yaml +1 -1
  42. package/daemon/context-packs/skills/pm/context-builder/manifest.yaml +1 -1
  43. package/daemon/context-packs/skills/pm/exec-summary/manifest.yaml +1 -1
  44. package/daemon/context-packs/skills/pm/office-hours/manifest.yaml +1 -1
  45. package/daemon/context-packs/skills/pm/plan-review/manifest.yaml +1 -1
  46. package/daemon/context-packs/skills/pm/requirements-writer/manifest.yaml +1 -1
  47. package/daemon/context-packs/skills/pm/ui-mockup/manifest.yaml +1 -1
  48. package/daemon/context-packs/skills/pods/development-team/manifest.yaml +1 -1
  49. package/daemon/context-packs/skills/pods/orchestration-team/manifest.yaml +1 -1
  50. package/daemon/context-packs/skills/pods/oversight-team/manifest.yaml +1 -1
  51. package/daemon/context-packs/skills/pods/review-team/manifest.yaml +1 -1
  52. package/daemon/context-packs/skills/process/agent-browser/manifest.yaml +1 -1
  53. package/daemon/context-packs/skills/process/context-engineering/manifest.yaml +1 -1
  54. package/daemon/context-packs/skills/process/dogfood/manifest.yaml +1 -1
  55. package/daemon/context-packs/skills/process/frontend-design/manifest.yaml +1 -1
  56. package/daemon/context-packs/skills/process/systematic-debugging/manifest.yaml +1 -1
  57. package/daemon/context-packs/skills/process/test-driven-development/manifest.yaml +1 -1
  58. package/daemon/context-packs/skills/process/verification-before-completion/manifest.yaml +1 -1
  59. package/daemon/context-packs/skills/queue-handoff/SKILL.md +5 -1
  60. package/daemon/context-packs/skills/queue-handoff/manifest.yaml +1 -1
  61. package/daemon/context-packs/skills/refocusing/manifest.yaml +1 -1
  62. package/daemon/context-packs/skills/retiring-and-inheriting-a-seat/manifest.yaml +1 -1
  63. package/daemon/context-packs/skills/seat-continuity-and-handover/manifest.yaml +1 -1
  64. package/daemon/context-packs/skills/session-compaction-and-restore/manifest.yaml +1 -1
  65. package/daemon/context-packs/skills/software-for-agents/manifest.yaml +1 -1
  66. package/daemon/context-packs/world-example/manifest.yaml +1 -1
  67. package/daemon/context-packs/world-public/manifest.yaml +1 -1
  68. package/daemon/dist/adapters/claude-code-adapter.d.ts +2 -3
  69. package/daemon/dist/adapters/claude-code-adapter.d.ts.map +1 -1
  70. package/daemon/dist/adapters/claude-code-adapter.js +35 -18
  71. package/daemon/dist/adapters/claude-code-adapter.js.map +1 -1
  72. package/daemon/dist/adapters/tmux.js +1 -1
  73. package/daemon/dist/adapters/tmux.js.map +1 -1
  74. package/daemon/dist/build-info.js +3 -3
  75. package/daemon/dist/db/all-migrations.d.ts.map +1 -1
  76. package/daemon/dist/db/all-migrations.js +2 -0
  77. package/daemon/dist/db/all-migrations.js.map +1 -1
  78. package/daemon/dist/db/migrations/126_escalation_target_refs.d.ts +4 -0
  79. package/daemon/dist/db/migrations/126_escalation_target_refs.d.ts.map +1 -0
  80. package/daemon/dist/db/migrations/126_escalation_target_refs.js +30 -0
  81. package/daemon/dist/db/migrations/126_escalation_target_refs.js.map +1 -0
  82. package/daemon/dist/domain/composer-prompts.d.ts +13 -0
  83. package/daemon/dist/domain/composer-prompts.d.ts.map +1 -1
  84. package/daemon/dist/domain/composer-prompts.js +32 -0
  85. package/daemon/dist/domain/composer-prompts.js.map +1 -1
  86. package/daemon/dist/domain/escalation-owner.d.ts +13 -0
  87. package/daemon/dist/domain/escalation-owner.d.ts.map +1 -0
  88. package/daemon/dist/domain/escalation-owner.js +92 -0
  89. package/daemon/dist/domain/escalation-owner.js.map +1 -0
  90. package/daemon/dist/domain/escalation-target-ref.d.ts +3 -0
  91. package/daemon/dist/domain/escalation-target-ref.d.ts.map +1 -0
  92. package/daemon/dist/domain/escalation-target-ref.js +6 -0
  93. package/daemon/dist/domain/escalation-target-ref.js.map +1 -0
  94. package/daemon/dist/domain/gateway/destination-resolver.d.ts +2 -0
  95. package/daemon/dist/domain/gateway/destination-resolver.d.ts.map +1 -1
  96. package/daemon/dist/domain/gateway/destination-resolver.js +10 -1
  97. package/daemon/dist/domain/gateway/destination-resolver.js.map +1 -1
  98. package/daemon/dist/domain/graph-projection.d.ts.map +1 -1
  99. package/daemon/dist/domain/graph-projection.js +2 -1
  100. package/daemon/dist/domain/graph-projection.js.map +1 -1
  101. package/daemon/dist/domain/mission-control/notification-adapter-ntfy.d.ts.map +1 -1
  102. package/daemon/dist/domain/mission-control/notification-adapter-ntfy.js +2 -0
  103. package/daemon/dist/domain/mission-control/notification-adapter-ntfy.js.map +1 -1
  104. package/daemon/dist/domain/mission-control/notification-adapter-webhook.d.ts.map +1 -1
  105. package/daemon/dist/domain/mission-control/notification-adapter-webhook.js +2 -0
  106. package/daemon/dist/domain/mission-control/notification-adapter-webhook.js.map +1 -1
  107. package/daemon/dist/domain/native-resume-probe.d.ts +3 -0
  108. package/daemon/dist/domain/native-resume-probe.d.ts.map +1 -1
  109. package/daemon/dist/domain/native-resume-probe.js +7 -0
  110. package/daemon/dist/domain/native-resume-probe.js.map +1 -1
  111. package/daemon/dist/domain/node-inventory.d.ts.map +1 -1
  112. package/daemon/dist/domain/node-inventory.js +2 -1
  113. package/daemon/dist/domain/node-inventory.js.map +1 -1
  114. package/daemon/dist/domain/periodic-snapshot-scheduler.d.ts +3 -0
  115. package/daemon/dist/domain/periodic-snapshot-scheduler.d.ts.map +1 -1
  116. package/daemon/dist/domain/periodic-snapshot-scheduler.js +15 -11
  117. package/daemon/dist/domain/periodic-snapshot-scheduler.js.map +1 -1
  118. package/daemon/dist/domain/ps-projection.d.ts +2 -1
  119. package/daemon/dist/domain/ps-projection.d.ts.map +1 -1
  120. package/daemon/dist/domain/ps-projection.js +4 -1
  121. package/daemon/dist/domain/ps-projection.js.map +1 -1
  122. package/daemon/dist/domain/queue-repository.d.ts +3 -0
  123. package/daemon/dist/domain/queue-repository.d.ts.map +1 -1
  124. package/daemon/dist/domain/queue-repository.js +18 -3
  125. package/daemon/dist/domain/queue-repository.js.map +1 -1
  126. package/daemon/dist/domain/queue-stuck-sweep.d.ts.map +1 -1
  127. package/daemon/dist/domain/queue-stuck-sweep.js +131 -16
  128. package/daemon/dist/domain/queue-stuck-sweep.js.map +1 -1
  129. package/daemon/dist/domain/queue-waiting.d.ts +1 -1
  130. package/daemon/dist/domain/queue-waiting.d.ts.map +1 -1
  131. package/daemon/dist/domain/queue-waiting.js +5 -4
  132. package/daemon/dist/domain/queue-waiting.js.map +1 -1
  133. package/daemon/dist/domain/queue-wake-ladder.d.ts +1 -1
  134. package/daemon/dist/domain/queue-wake-ladder.d.ts.map +1 -1
  135. package/daemon/dist/domain/queue-wake-ladder.js +171 -44
  136. package/daemon/dist/domain/queue-wake-ladder.js.map +1 -1
  137. package/daemon/dist/domain/rig-edge-ops.d.ts +1 -1
  138. package/daemon/dist/domain/rig-edge-ops.d.ts.map +1 -1
  139. package/daemon/dist/domain/rig-edge-ops.js +8 -6
  140. package/daemon/dist/domain/rig-edge-ops.js.map +1 -1
  141. package/daemon/dist/domain/rig-repository.d.ts.map +1 -1
  142. package/daemon/dist/domain/rig-repository.js +12 -4
  143. package/daemon/dist/domain/rig-repository.js.map +1 -1
  144. package/daemon/dist/domain/rig-teardown.d.ts +2 -2
  145. package/daemon/dist/domain/rig-teardown.d.ts.map +1 -1
  146. package/daemon/dist/domain/rig-teardown.js +9 -5
  147. package/daemon/dist/domain/rig-teardown.js.map +1 -1
  148. package/daemon/dist/domain/rigspec-exporter.js +3 -3
  149. package/daemon/dist/domain/rigspec-exporter.js.map +1 -1
  150. package/daemon/dist/domain/rigspec-instantiator.d.ts.map +1 -1
  151. package/daemon/dist/domain/rigspec-instantiator.js +8 -7
  152. package/daemon/dist/domain/rigspec-instantiator.js.map +1 -1
  153. package/daemon/dist/domain/rigspec-schema.d.ts.map +1 -1
  154. package/daemon/dist/domain/rigspec-schema.js +8 -1
  155. package/daemon/dist/domain/rigspec-schema.js.map +1 -1
  156. package/daemon/dist/domain/rosters.d.ts +2 -0
  157. package/daemon/dist/domain/rosters.d.ts.map +1 -1
  158. package/daemon/dist/domain/rosters.js +6 -0
  159. package/daemon/dist/domain/rosters.js.map +1 -1
  160. package/daemon/dist/domain/scope/scope-audit.d.ts +1 -0
  161. package/daemon/dist/domain/scope/scope-audit.d.ts.map +1 -1
  162. package/daemon/dist/domain/scope/scope-audit.js +4 -0
  163. package/daemon/dist/domain/scope/scope-audit.js.map +1 -1
  164. package/daemon/dist/domain/seat-delivery-guard.d.ts +1 -1
  165. package/daemon/dist/domain/seat-delivery-guard.d.ts.map +1 -1
  166. package/daemon/dist/domain/seat-delivery-guard.js +11 -2
  167. package/daemon/dist/domain/seat-delivery-guard.js.map +1 -1
  168. package/daemon/dist/domain/session-registry.d.ts +3 -0
  169. package/daemon/dist/domain/session-registry.d.ts.map +1 -1
  170. package/daemon/dist/domain/session-registry.js +5 -0
  171. package/daemon/dist/domain/session-registry.js.map +1 -1
  172. package/daemon/dist/domain/session-transport.d.ts.map +1 -1
  173. package/daemon/dist/domain/session-transport.js +39 -18
  174. package/daemon/dist/domain/session-transport.js.map +1 -1
  175. package/daemon/dist/domain/terminal/herdr-adapter.d.ts +13 -5
  176. package/daemon/dist/domain/terminal/herdr-adapter.d.ts.map +1 -1
  177. package/daemon/dist/domain/terminal/herdr-adapter.js +55 -79
  178. package/daemon/dist/domain/terminal/herdr-adapter.js.map +1 -1
  179. package/daemon/dist/domain/terminal/herdr-follow-view.d.ts +28 -0
  180. package/daemon/dist/domain/terminal/herdr-follow-view.d.ts.map +1 -0
  181. package/daemon/dist/domain/terminal/herdr-follow-view.js +338 -0
  182. package/daemon/dist/domain/terminal/herdr-follow-view.js.map +1 -0
  183. package/daemon/dist/domain/terminal/herdr-sessions.d.ts +2 -1
  184. package/daemon/dist/domain/terminal/herdr-sessions.d.ts.map +1 -1
  185. package/daemon/dist/domain/terminal/herdr-sessions.js +32 -8
  186. package/daemon/dist/domain/terminal/herdr-sessions.js.map +1 -1
  187. package/daemon/dist/domain/terminal/herdr-viewer.d.ts +69 -0
  188. package/daemon/dist/domain/terminal/herdr-viewer.d.ts.map +1 -0
  189. package/daemon/dist/domain/terminal/herdr-viewer.js +285 -0
  190. package/daemon/dist/domain/terminal/herdr-viewer.js.map +1 -0
  191. package/daemon/dist/domain/terminal/task-terminal-view.d.ts +2 -1
  192. package/daemon/dist/domain/terminal/task-terminal-view.d.ts.map +1 -1
  193. package/daemon/dist/domain/terminal/task-terminal-view.js.map +1 -1
  194. package/daemon/dist/domain/terminal/terminal-follow-policy.d.ts +65 -0
  195. package/daemon/dist/domain/terminal/terminal-follow-policy.d.ts.map +1 -0
  196. package/daemon/dist/domain/terminal/terminal-follow-policy.js +93 -0
  197. package/daemon/dist/domain/terminal/terminal-follow-policy.js.map +1 -0
  198. package/daemon/dist/domain/terminal/terminal-following.d.ts +39 -0
  199. package/daemon/dist/domain/terminal/terminal-following.d.ts.map +1 -0
  200. package/daemon/dist/domain/terminal/terminal-following.js +135 -0
  201. package/daemon/dist/domain/terminal/terminal-following.js.map +1 -0
  202. package/daemon/dist/domain/terminal/terminal-provider.d.ts +10 -0
  203. package/daemon/dist/domain/terminal/terminal-provider.d.ts.map +1 -1
  204. package/daemon/dist/domain/terminal/terminal-service.d.ts +20 -0
  205. package/daemon/dist/domain/terminal/terminal-service.d.ts.map +1 -1
  206. package/daemon/dist/domain/terminal/terminal-service.js +108 -34
  207. package/daemon/dist/domain/terminal/terminal-service.js.map +1 -1
  208. package/daemon/dist/domain/terminal/tile-attach.js +1 -1
  209. package/daemon/dist/domain/terminal/tile-attach.js.map +1 -1
  210. package/daemon/dist/domain/terminal/view-composer.js +1 -1
  211. package/daemon/dist/domain/terminal/view-composer.js.map +1 -1
  212. package/daemon/dist/domain/types.d.ts +2 -0
  213. package/daemon/dist/domain/types.d.ts.map +1 -1
  214. package/daemon/dist/domain/types.js.map +1 -1
  215. package/daemon/dist/index.d.ts.map +1 -1
  216. package/daemon/dist/index.js +1 -0
  217. package/daemon/dist/index.js.map +1 -1
  218. package/daemon/dist/routes/scope-audit.d.ts.map +1 -1
  219. package/daemon/dist/routes/scope-audit.js +2 -2
  220. package/daemon/dist/routes/scope-audit.js.map +1 -1
  221. package/daemon/dist/routes/terminal.d.ts +3 -1
  222. package/daemon/dist/routes/terminal.d.ts.map +1 -1
  223. package/daemon/dist/routes/terminal.js +57 -1
  224. package/daemon/dist/routes/terminal.js.map +1 -1
  225. package/daemon/dist/routes/transport.d.ts.map +1 -1
  226. package/daemon/dist/routes/transport.js +3 -0
  227. package/daemon/dist/routes/transport.js.map +1 -1
  228. package/daemon/dist/server.js +1 -1
  229. package/daemon/dist/server.js.map +1 -1
  230. package/daemon/dist/startup.d.ts.map +1 -1
  231. package/daemon/dist/startup.js +9 -2
  232. package/daemon/dist/startup.js.map +1 -1
  233. package/daemon/docs/reference/agent-startup-guide.md +9 -0
  234. package/daemon/docs/reference/community-harness-examples/pi-tui/openrig-pi-tui-launch +100 -0
  235. package/daemon/docs/reference/community-harness-examples/pi-tui/pi-tui.yaml +15 -0
  236. package/daemon/docs/reference/community-harness-presets.md +77 -0
  237. package/daemon/docs/reference/edge-types.md +40 -11
  238. package/daemon/docs/reference/getting-started.md +12 -2
  239. package/daemon/docs/reference/hosted-members.md +5 -1
  240. package/daemon/docs/reference/publishing-a-rig-bundle.md +5 -0
  241. package/daemon/docs/reference/quickstart.md +1 -1
  242. package/daemon/docs/reference/rig-spec.md +5 -1
  243. package/daemon/docs/reference/sdlc-conventions.md +6 -0
  244. package/daemon/docs/reference/seat-delivery.md +6 -0
  245. package/daemon/docs/reference/terminal-sessions.md +109 -2
  246. package/daemon/docs/reference/whats-new.md +153 -116
  247. package/daemon/specs/agents/shared/skills/core/rig-bundles-and-shareable-artifacts/SKILL.md +11 -0
  248. package/dist/build-info.js +3 -3
  249. package/dist/commands/attach.d.ts.map +1 -1
  250. package/dist/commands/attach.js +9 -9
  251. package/dist/commands/attach.js.map +1 -1
  252. package/dist/commands/capture.d.ts.map +1 -1
  253. package/dist/commands/capture.js +12 -4
  254. package/dist/commands/capture.js.map +1 -1
  255. package/dist/commands/edge.d.ts.map +1 -1
  256. package/dist/commands/edge.js +2 -1
  257. package/dist/commands/edge.js.map +1 -1
  258. package/dist/commands/host.d.ts.map +1 -1
  259. package/dist/commands/host.js +17 -2
  260. package/dist/commands/host.js.map +1 -1
  261. package/dist/commands/mcp.d.ts.map +1 -1
  262. package/dist/commands/mcp.js +4 -1
  263. package/dist/commands/mcp.js.map +1 -1
  264. package/dist/commands/scope.js +3 -3
  265. package/dist/commands/scope.js.map +1 -1
  266. package/dist/commands/send.d.ts.map +1 -1
  267. package/dist/commands/send.js +16 -21
  268. package/dist/commands/send.js.map +1 -1
  269. package/dist/commands/start.d.ts.map +1 -1
  270. package/dist/commands/start.js +7 -0
  271. package/dist/commands/start.js.map +1 -1
  272. package/dist/commands/terminal.d.ts +32 -0
  273. package/dist/commands/terminal.d.ts.map +1 -1
  274. package/dist/commands/terminal.js +30 -8
  275. package/dist/commands/terminal.js.map +1 -1
  276. package/dist/commands/transcript.js +1 -1
  277. package/dist/commands/transcript.js.map +1 -1
  278. package/dist/lib/scope/scope-audit.d.ts +1 -0
  279. package/dist/lib/scope/scope-audit.d.ts.map +1 -1
  280. package/dist/lib/scope/scope-audit.js +4 -0
  281. package/dist/lib/scope/scope-audit.js.map +1 -1
  282. package/dist/mcp-server.d.ts +1 -1
  283. package/dist/mcp-server.d.ts.map +1 -1
  284. package/dist/mcp-server.js +4 -3
  285. package/dist/mcp-server.js.map +1 -1
  286. package/dist/terminal-window.d.ts +3 -3
  287. package/dist/terminal-window.d.ts.map +1 -1
  288. package/dist/terminal-window.js +33 -5
  289. package/dist/terminal-window.js.map +1 -1
  290. package/package.json +1 -1
  291. package/tui/dist/daemon-client.d.ts +1 -0
  292. package/tui/dist/daemon-client.d.ts.map +1 -1
  293. package/tui/dist/daemon-client.js +1 -1
  294. package/tui/dist/daemon-client.js.map +1 -1
  295. package/tui/dist/hydrate.d.ts.map +1 -1
  296. package/tui/dist/hydrate.js +3 -0
  297. package/tui/dist/hydrate.js.map +1 -1
  298. package/tui/dist/navigator.d.ts.map +1 -1
  299. package/tui/dist/navigator.js +8 -5
  300. package/tui/dist/navigator.js.map +1 -1
  301. package/tui/dist/render.d.ts.map +1 -1
  302. package/tui/dist/render.js +6 -5
  303. package/tui/dist/render.js.map +1 -1
  304. package/tui/dist/state.d.ts.map +1 -1
  305. package/tui/dist/state.js +2 -1
  306. package/tui/dist/state.js.map +1 -1
  307. package/tui/dist/terminals/open-window.js +2 -2
  308. package/tui/dist/terminals/open-window.js.map +1 -1
  309. package/tui/dist/topology/host-label.d.ts +7 -0
  310. package/tui/dist/topology/host-label.d.ts.map +1 -0
  311. package/tui/dist/topology/host-label.js +34 -0
  312. package/tui/dist/topology/host-label.js.map +1 -0
  313. package/tui/dist/types.d.ts +3 -0
  314. package/tui/dist/types.d.ts.map +1 -1
  315. package/ui/dist/assets/{index-DV0UNxFw.js → index-ozBodLrS.js} +168 -168
  316. package/ui/dist/index.html +1 -1
@@ -1,3 +1,4 @@
1
+ import { resolveEscalationOwner, ESCALATION_HOP_TAG, hasConsumedEscalationHop } from "./escalation-owner.js";
1
2
  import { seatRuntimeHomeBySession } from "./seat-runtime-home.js";
2
3
  import { quietHoldCustody } from "./quiet-hold-custody.js";
3
4
  import { latestHookMovedOn, latestHookPermissionPending, latestHookWaitsOnPerson } from "./agent-activity-store.js";
@@ -9,7 +10,7 @@ import { USAGE_LIMIT_BLOCKER_TAG, USAGE_LIMIT_POOL_TAG_PREFIX, } from "./queue-w
9
10
  import { SettingsStore } from "./user-settings/settings-store.js";
10
11
  import { loadHumanRegistry, resolveRegisteredHumanAddress } from "./gateway/human-registry.js";
11
12
  import { parseSessionName } from "./session-name.js";
12
- import { LADDER_ATTEMPT_PREFIX, LADDER_RUNG_PREFIX, LADDER_EXHAUSTED_PREFIX, defaultResolveOrchestrator, resolveOperatorSeat, resolveSessionNodeId, } from "./queue-stuck-sweep.js";
13
+ import { LADDER_ATTEMPT_PREFIX, LADDER_RUNG_PREFIX, LADDER_EXHAUSTED_PREFIX, resolveOperatorSeat, resolveSessionNodeId, } from "./queue-stuck-sweep.js";
13
14
  export const WAKE_RETRY_INTERVAL_KEY = "queue.wake_retry_interval_seconds";
14
15
  export const DEFAULT_WAKE_RETRY_INTERVAL_SECONDS = 300;
15
16
  export const WAKE_RETRY_CAP_KEY = "queue.wake_retry_cap";
@@ -326,14 +327,16 @@ function suspensionReason(db, destination, graceSeconds, now) {
326
327
  /** Read the existing ladder's next eligible action; never create an intent,
327
328
  * reserve a retry, consume provider state or change its policy. The scheduler
328
329
  * still makes the final live-state decision at delivery time. */
329
- export function readWakeLadderBackstop(db, qitemId) {
330
+ export function readWakeLadderBackstop(db, qitemId, acceptsDestination) {
330
331
  const row = db.prepare(`SELECT qitem_id AS qitemId, state, source_session AS sourceSession,
331
332
  destination_session AS destinationSession, claimed_at AS claimedAt, handed_off_from AS handedOffFrom,
332
333
  last_heartbeat AS lastHeartbeat, last_nudge_result AS lastNudgeResult,
333
- last_nudge_attempt AS lastNudgeAttempt, ts_created AS tsCreated FROM queue_items WHERE qitem_id = ?`)
334
+ last_nudge_attempt AS lastNudgeAttempt, ts_created AS tsCreated, tags AS tagsJson FROM queue_items WHERE qitem_id = ?`)
334
335
  .get(qitemId);
335
336
  if (!row || !["pending", "in-progress"].includes(row.state))
336
337
  return null;
338
+ const escalationOwner = () => hasConsumedEscalationHop(db, qitemId)
339
+ ? null : resolveEscalationOwner(db, row.destinationSession, acceptsDestination).owner;
337
340
  const recovery = findWakeRecovery(db, qitemId);
338
341
  const disposition = recovery ? db.prepare("SELECT destination_session, tags FROM queue_items WHERE qitem_id = ?")
339
342
  .get(recovery.qitemId) : null;
@@ -354,7 +357,7 @@ export function readWakeLadderBackstop(db, qitemId) {
354
357
  const ladder = readLadder(db, qitemId);
355
358
  if (ladder.exhausted)
356
359
  return recovery ? recoveryBackstop() : {
357
- owner: defaultResolveOrchestrator(db, row.destinationSession) ?? row.destinationSession,
360
+ owner: escalationOwner() ?? row.destinationSession,
358
361
  mechanism: "queue-wake-ladder:exhausted; queue-stuck-sweep:undelivered", dueAt: null, intervalSeconds: null,
359
362
  note: "No further ladder retry. Inspect the retained exhaustion and delivery evidence; the stuck sweep is the safety net.",
360
363
  };
@@ -381,7 +384,7 @@ export function readWakeLadderBackstop(db, qitemId) {
381
384
  const suspension = readSuspension(db, row.destinationSession, resolveWakeSwapGraceSeconds(), now);
382
385
  if (suspension)
383
386
  due = Math.max(due, Date.parse(suspension.until));
384
- const orch = defaultResolveOrchestrator(db, row.destinationSession);
387
+ const orch = disposition?.destination_session ?? escalationOwner();
385
388
  const operator = ladder.orchRung || orch === null || orch === row.destinationSession;
386
389
  return {
387
390
  owner: retry ? row.destinationSession : operator ? resolveOperatorSeat() ?? row.sourceSession : orch,
@@ -481,7 +484,9 @@ export async function runWakeLadderTick(deps) {
481
484
  const cap = deps.retryCap ?? resolveWakeRetryCap();
482
485
  const windowMin = deps.unconfirmedWindowMinutes ?? resolveWakeUnconfirmedWindowMinutes();
483
486
  const graceS = deps.swapGraceSeconds ?? resolveWakeSwapGraceSeconds();
484
- const resolveOrch = deps.resolveOrchestrator ?? ((session) => defaultResolveOrchestrator(deps.db, session));
487
+ const resolveOrch = deps.resolveOrchestrator ?? ((session) => {
488
+ return resolveEscalationOwner(deps.db, session, target => deps.queueRepo.acceptsDestination(target)).owner;
489
+ });
485
490
  const attemptWake = deps.attemptWake ??
486
491
  (async (qitemId, target) => {
487
492
  // A ladder retry is OpenRig's own scheduling on the row, whoever created it.
@@ -657,6 +662,20 @@ export async function runWakeLadderTick(deps) {
657
662
  : mode === "held"
658
663
  ? `held by ${row.destinationSession}'s typing guard for ${minutesSince(row.tsCreated, now)} min: nothing was typed, and it isn't retried`
659
664
  : `unconfirmed delivery with no pickup evidence over ${minutesSince(row.tsCreated, now)} min`;
665
+ if (hasConsumedEscalationHop(deps.db, row.qitemId)) {
666
+ if (!due || suspended)
667
+ continue;
668
+ const consumedReason = `${reason}; escalates_to one-hop delivery already used; existing fallback retained`;
669
+ // Keep this recovery visible without sharing the ordinary destination aggregate or forwarding another hop.
670
+ await ensureEscalationRow(deps, row.destinationSession, resolveOperatorSeat() ?? row.sourceSession, [{ row, reason: consumedReason }], consumedReason, `consumed-hop:${row.qitemId}`, [ESCALATION_HOP_TAG]);
671
+ if (!view.orchRung)
672
+ appendMarker(deps.queueRepo, row, `${LADDER_RUNG_PREFIX} orchestrator self-skip reason=${consumedReason}`);
673
+ if (await operatorRung(deps, row, consumedReason, actions, view)) {
674
+ appendExhausted(deps.queueRepo, row, "consumed escalation hop reached operator fallback");
675
+ exhaustedThisTick += 1;
676
+ }
677
+ continue;
678
+ }
660
679
  const dest = row.destinationSession;
661
680
  if (!escalating.has(dest))
662
681
  escalating.set(dest, []);
@@ -665,7 +684,13 @@ export async function runWakeLadderTick(deps) {
665
684
  // F3 — per-destination aggregation: ONE escalation carrying the row list, refreshed
666
685
  // not duplicated (the S02 idempotency shape), and rung markers on every member baton.
667
686
  for (const [dest, members] of escalating) {
668
- const orch = resolveOrch(dest);
687
+ const orch = openEscalationOwner(deps.db, escalationDedupTag(dest)) ?? resolveOrch(dest);
688
+ const route = !deps.resolveOrchestrator
689
+ ? resolveEscalationOwner(deps.db, dest, target => deps.queueRepo.acceptsDestination(target)) : null;
690
+ const routeReason = route && route.outcome !== "none" && route.outcome !== "parent" ? route.reason : "";
691
+ for (const member of members)
692
+ if (routeReason)
693
+ member.reason += `; ${routeReason}`;
669
694
  // F3 — the aggregate refresh is detection-gated (the S02 idempotency shape): a
670
695
  // live escalation group refreshes its one open row every pass, no wake attached.
671
696
  await refreshEscalationRowIfExists(deps, dest, members);
@@ -692,10 +717,12 @@ export async function runWakeLadderTick(deps) {
692
717
  }
693
718
  else {
694
719
  const escRow = await ensureEscalationRow(deps, dest, orch, members, reason);
695
- const outcome = await attemptWake(escRow.qitemId, orch);
720
+ // An already-open recovery retains its owner, including a claim made before topology changed.
721
+ const recoveryOwner = deps.queueRepo.getById(escRow.qitemId)?.destinationSession ?? orch;
722
+ const outcome = await attemptWake(escRow.qitemId, recoveryOwner);
696
723
  for (const m of needsOrchRung) {
697
- appendMarker(deps.queueRepo, m.row, `${LADDER_RUNG_PREFIX} orchestrator -> ${orch} outcome=${outcome} reason=${m.reason}`);
698
- actions.push({ qitemId: m.row.qitemId, action: "escalate-orchestrator", target: orch });
724
+ appendMarker(deps.queueRepo, m.row, `${LADDER_RUNG_PREFIX} orchestrator -> ${recoveryOwner} outcome=${outcome} reason=${m.reason}`);
725
+ actions.push({ qitemId: m.row.qitemId, action: "escalate-orchestrator", target: recoveryOwner });
699
726
  if (!outcome.startsWith("failed:")) {
700
727
  // Delivered (or durable-unconfirmed — the aggregate row itself is now the
701
728
  // orchestrator's durable obligation; S02 nets it if it sits unclaimed).
@@ -833,6 +860,17 @@ function postedPromptAlert(db, except) {
833
860
  ORDER BY ts_created LIMIT 1`).get(except, PROMPT_ALERT_TAG, PROMPT_CHOICE_TAG, `${LADDER_RUNG_PREFIX} operator dispatched-to-engine%`);
834
861
  return row?.qitem_id ?? null;
835
862
  }
863
+ /** Keep both ordinary and consumed-recovery choice alerts behind the same durable gate. */
864
+ function waitsOnPostedPromptAlert(deps, row, choiceOnly) {
865
+ const posted = choiceOnly && deps.deliveryEngine ? postedPromptAlert(deps.db, row.qitemId) : null;
866
+ if (!posted)
867
+ return false;
868
+ const waiting = `${LADDER_RUNG_PREFIX} operator waiting on ${posted}`;
869
+ if (!deps.queueRepo.listTransitions(row.qitemId).some(t => t.transitionNote?.startsWith(waiting))) {
870
+ appendMarker(deps.queueRepo, row, `${waiting} reason=one person alert at a time for seats blocked at a prompt`);
871
+ }
872
+ return true;
873
+ }
836
874
  /** Positive refusals enter the existing rungs without ever retrying the blocked
837
875
  * seat. One aggregate carries the episode's obligations and notification key;
838
876
  * original work remains owned by its current recipient. */
@@ -891,16 +929,14 @@ async function advancePromptRefusals(deps, now, intervalS, graceS, resolveOrch,
891
929
  for (const episode of openPromptRefusals(deps.queueRepo.listTransitions(qitem_id))) {
892
930
  if (!episode.key.startsWith(`${primary.destinationSession}|`))
893
931
  continue;
894
- // A closed disposition for this exact episode is final, even while the
895
- // original work remains open. Only a new refusal key can start again.
896
- if (closedEpisode(`${PROMPT_EPISODE_TAG}${episode.key}`))
897
- continue;
898
- const rows = episode.ids.map(id => readCandidate(id, primary.destinationSession)).filter((row) => Boolean(row && row.destinationSession === primary.destinationSession && ["pending", "in-progress", "blocked"].includes(row.state)));
932
+ // Ordinary work shares an episode; consumed recoveries retain independent dispositions.
933
+ const rows = episode.ids.map(id => readCandidate(id, primary.destinationSession)).filter((row) => Boolean(row && row.destinationSession === primary.destinationSession && ["pending", "in-progress", "blocked"].includes(row.state)
934
+ && !closedEpisode(`${PROMPT_EPISODE_TAG}${episode.key}${hasConsumedEscalationHop(deps.db, row.qitemId) ? `|consumed:${row.qitemId}` : ""}`)));
899
935
  if (!rows.length)
900
936
  continue;
901
937
  let group = groups.get(primary.destinationSession);
902
938
  if (!group) {
903
- group = { keys: [], rows: new Map(), jobs: new Map(), refusedAt: episode.refusedAt };
939
+ group = { keys: [], rowKeys: new Map(), jobKeys: new Set(), rows: new Map(), jobs: new Map(), refusedAt: episode.refusedAt };
904
940
  groups.set(primary.destinationSession, group);
905
941
  }
906
942
  if (Date.parse(episode.refusedAt) > Date.parse(group.refusedAt))
@@ -918,9 +954,15 @@ async function advancePromptRefusals(deps, now, intervalS, graceS, resolveOrch,
918
954
  && (!group.choiceSince || Date.parse(episode.refusedAt) < Date.parse(group.choiceSince)))
919
955
  group.choiceSince = episode.refusedAt;
920
956
  }
921
- group.keys.push(`${PROMPT_EPISODE_TAG}${episode.key}`);
922
- for (const row of rows)
957
+ for (const row of rows) {
958
+ const key = `${PROMPT_EPISODE_TAG}${episode.key}${hasConsumedEscalationHop(deps.db, row.qitemId) ? `|consumed:${row.qitemId}` : ""}`;
959
+ if (!group.keys.includes(key))
960
+ group.keys.push(key);
961
+ if (!group.rowKeys.has(row.qitemId))
962
+ group.rowKeys.set(row.qitemId, new Set());
963
+ group.rowKeys.get(row.qitemId).add(key);
923
964
  group.rows.set(row.qitemId, row);
965
+ }
924
966
  }
925
967
  }
926
968
  // A watchdog reminder refused twice at the same prompt joins its seat's episode; the row carries the job ids. The
@@ -942,7 +984,7 @@ async function advancePromptRefusals(deps, now, intervalS, graceS, resolveOrch,
942
984
  continue;
943
985
  let group = groups.get(job.dest);
944
986
  if (!group) {
945
- group = { keys: [], rows: new Map(), jobs: new Map(), refusedAt: job.refusedAt };
987
+ group = { keys: [], rowKeys: new Map(), jobKeys: new Set(), rows: new Map(), jobs: new Map(), refusedAt: job.refusedAt };
946
988
  groups.set(job.dest, group);
947
989
  }
948
990
  if (Date.parse(job.refusedAt) > Date.parse(group.refusedAt))
@@ -950,12 +992,40 @@ async function advancePromptRefusals(deps, now, intervalS, graceS, resolveOrch,
950
992
  if (job.refusedAt === group.refusedAt)
951
993
  group.latestChoice = job.choice;
952
994
  group.keys.push(tag);
995
+ group.jobKeys.add(tag);
953
996
  group.jobs.set(job.jobId, job.registeredBy);
954
997
  if (job.choice)
955
998
  group.choice = true;
956
999
  else
957
1000
  group.other = true;
958
1001
  }
1002
+ // A recovery returned to the blocked seat inherits only its source row's episodes.
1003
+ // Reconstruct this membership before retirement, even when the recovery has no refusal of its own.
1004
+ for (const [dest, group] of groups) {
1005
+ for (const row of [...group.rows.values()]) {
1006
+ if (hasConsumedEscalationHop(deps.db, row.qitemId))
1007
+ continue;
1008
+ // The newer ordinary alert must not hide the underlying returned recovery on the next tick.
1009
+ const recovery = findQueueRecovery(deps.db, row.qitemId, PROMPT_ALERT_TAG);
1010
+ if (!recovery || !["pending", "in-progress", "blocked"].includes(recovery.state))
1011
+ continue;
1012
+ const held = readCandidate(recovery.qitemId, dest);
1013
+ if (!held || held.destinationSession !== dest || held.tags?.includes(PROMPT_ALERT_TAG))
1014
+ continue;
1015
+ const suffix = hasConsumedEscalationHop(deps.db, held.qitemId) ? `|consumed:${held.qitemId}` : "";
1016
+ for (const sourceKey of group.rowKeys.get(row.qitemId) ?? []) {
1017
+ const key = `${sourceKey}${suffix}`;
1018
+ if (closedEpisode(key))
1019
+ continue;
1020
+ if (!group.keys.includes(key))
1021
+ group.keys.push(key);
1022
+ if (!group.rowKeys.has(held.qitemId))
1023
+ group.rowKeys.set(held.qitemId, new Set());
1024
+ group.rowKeys.get(held.qitemId).add(key);
1025
+ group.rows.set(held.qitemId, held);
1026
+ }
1027
+ }
1028
+ }
959
1029
  const promptState = (dest) => {
960
1030
  const group = groups.get(dest);
961
1031
  const state = readAt(dest, group?.refusedAt ?? now.toISOString());
@@ -974,8 +1044,10 @@ async function advancePromptRefusals(deps, now, intervalS, graceS, resolveOrch,
974
1044
  const aggregate = deps.queueRepo.getById(qitem_id);
975
1045
  if (!aggregate || !Array.isArray(aggregate.tags))
976
1046
  continue;
977
- const destinationTag = aggregate.tags.find(t => typeof t === "string" && t.startsWith("prompt-destination:"));
978
- const dest = destinationTag?.slice("prompt-destination:".length);
1047
+ const destinationTag = aggregate.tags.find(t => typeof t === "string"
1048
+ && (t.startsWith("prompt-destination:") || t.startsWith("consumed-prompt-destination:")));
1049
+ const dest = destinationTag?.slice(destinationTag.startsWith("consumed-")
1050
+ ? "consumed-prompt-destination:".length : "prompt-destination:".length);
979
1051
  if (!dest)
980
1052
  continue;
981
1053
  // Incomplete membership is not evidence that an episode ended.
@@ -1010,8 +1082,9 @@ async function advancePromptRefusals(deps, now, intervalS, graceS, resolveOrch,
1010
1082
  // Recovery owned elsewhere already has a route. A fallback finding sent
1011
1083
  // into this same blocked seat does not: include it in the aggregate while
1012
1084
  // retaining its original body/custody, rather than treating it as delivery.
1013
- const selfRecoveries = new Map();
1014
1085
  const ownedElsewhere = members.some(({ row }) => {
1086
+ if (hasConsumedEscalationHop(deps.db, row.qitemId))
1087
+ return false;
1015
1088
  const recovery = findQueueRecovery(deps.db, row.qitemId);
1016
1089
  if (!recovery || !["pending", "in-progress", "blocked"].includes(recovery.state))
1017
1090
  return false;
@@ -1020,29 +1093,78 @@ async function advancePromptRefusals(deps, now, intervalS, graceS, resolveOrch,
1020
1093
  return false;
1021
1094
  if (held.tags?.includes(PROMPT_ALERT_TAG))
1022
1095
  return false;
1023
- if (held.destinationSession !== dest)
1024
- return true;
1025
- selfRecoveries.set(held.qitemId, held);
1026
- return false;
1096
+ return held.destinationSession !== dest;
1027
1097
  });
1028
1098
  if (ownedElsewhere)
1029
1099
  continue;
1030
- for (const row of selfRecoveries.values()) {
1031
- if (!group.rows.has(row.qitemId))
1032
- members.push({ row, reason: "recovery fallback also targets the prompt-blocked seat" });
1100
+ // A consumed recovery owns its own operator continuation. It must not change
1101
+ // the route or one-hop marker of unrelated work/watchdogs at the same prompt.
1102
+ for (let i = members.length - 1; i >= 0; i--) {
1103
+ const member = members[i];
1104
+ if (!hasConsumedEscalationHop(deps.db, member.row.qitemId))
1105
+ continue;
1106
+ const recovery = findQueueRecovery(deps.db, member.row.qitemId);
1107
+ const heldRecovery = recovery ? deps.queueRepo.getById(recovery.qitemId) : null;
1108
+ if (recovery && ["pending", "in-progress", "blocked"].includes(recovery.state)
1109
+ && heldRecovery?.destinationSession !== dest
1110
+ && !heldRecovery?.tags?.includes(`consumed-hop:${member.row.qitemId}`)) {
1111
+ members.splice(i, 1);
1112
+ continue;
1113
+ }
1114
+ const view = readLadder(deps.db, member.row.qitemId, 0);
1115
+ if (!view.exhausted && (view.lastMarkerTs === null || now.getTime() - view.lastMarkerTs >= intervalS * 1000)) {
1116
+ const reason = "interactive prompt blocks recovery; escalates_to one-hop delivery already used; existing fallback retained";
1117
+ const choiceOnly = Boolean(group.choice && !group.other);
1118
+ const promptTags = choiceOnly ? [PROMPT_ALERT_TAG, PROMPT_CHOICE_TAG, `consumed-prompt-destination:${dest}`,
1119
+ ...(group.rowKeys.get(member.row.qitemId) ?? [])] : [];
1120
+ const continuation = await ensureEscalationRow(deps, dest, resolveOperatorSeat() ?? member.row.sourceSession, [{ row: member.row, reason }], reason, `consumed-hop:${member.row.qitemId}`, [ESCALATION_HOP_TAG, ...promptTags]);
1121
+ if (!view.orchRung)
1122
+ appendMarker(deps.queueRepo, member.row, `${LADDER_RUNG_PREFIX} orchestrator self-skip reason=${reason}`);
1123
+ // A choice alert's tags and dispatch marker must live on the same durable row the shared gate reads.
1124
+ const operatorRow = choiceOnly ? deps.queueRepo.getById(continuation.qitemId) : member.row;
1125
+ if (choiceOnly) {
1126
+ const missing = promptTags.filter(tag => !operatorRow.tags?.includes(tag));
1127
+ if (missing.length)
1128
+ deps.db.prepare("UPDATE queue_items SET tags=? WHERE qitem_id=?")
1129
+ .run(JSON.stringify([...(operatorRow.tags ?? []), ...missing]), operatorRow.qitemId);
1130
+ }
1131
+ if (waitsOnPostedPromptAlert(deps, operatorRow, choiceOnly)) {
1132
+ members.splice(i, 1);
1133
+ continue;
1134
+ }
1135
+ const operatorView = choiceOnly ? readLadder(deps.db, operatorRow.qitemId, 0) : view;
1136
+ if (choiceOnly && operatorView.exhausted) {
1137
+ members.splice(i, 1);
1138
+ continue;
1139
+ }
1140
+ if (await operatorRung(deps, operatorRow, reason, actions, operatorView, choiceOnly)) {
1141
+ // Choice custody stays on the alert until it closes; exhausting its source now would retire the alert next tick.
1142
+ if (!choiceOnly)
1143
+ appendExhausted(deps.queueRepo, member.row, "consumed escalation hop reached operator fallback");
1144
+ if (choiceOnly)
1145
+ appendExhausted(deps.queueRepo, operatorRow, "operator rung resolved");
1146
+ }
1147
+ }
1148
+ members.splice(i, 1);
1033
1149
  }
1034
- const orch = resolveOrch(dest);
1150
+ if (!members.length && !group.jobs.size)
1151
+ continue;
1152
+ const orch = openEscalationOwner(deps.db, `prompt-destination:${dest}`) ?? resolveOrch(dest);
1035
1153
  const toOperator = orch === null || orch === dest;
1036
- const reason = "interactive prompt blocks outstanding work; no input was sent";
1154
+ const route = !deps.resolveOrchestrator
1155
+ ? resolveEscalationOwner(deps.db, dest, target => deps.queueRepo.acceptsDestination(target)) : null;
1156
+ const reason = "interactive prompt blocks outstanding work; no input was sent"
1157
+ + (route && route.outcome !== "none" && route.outcome !== "parent" ? `; ${route.reason}` : "");
1037
1158
  // Every refusal at a choice prompt: the alert follows queue.wake_human_rung and holds for other choice alerts. Any other
1038
1159
  // prompt keeps the permission-prompt route.
1039
1160
  const choiceOnly = Boolean(group.choice && !group.other);
1040
1161
  const kindTags = choiceOnly ? [PROMPT_CHOICE_TAG] : [];
1041
- const aggregate = await ensureEscalationRow(deps, dest, toOperator ? resolveOperatorSeat() ?? members[0]?.row.sourceSession ?? [...group.jobs.values()][0] : orch, members, reason, `prompt-destination:${dest}`, [PROMPT_ALERT_TAG, ...kindTags, ...group.keys], group.jobs);
1162
+ const keys = group.keys.filter(key => group.jobKeys.has(key) || members.some(m => group.rowKeys.get(m.row.qitemId)?.has(key)));
1163
+ const aggregate = await ensureEscalationRow(deps, dest, toOperator ? resolveOperatorSeat() ?? members[0]?.row.sourceSession ?? [...group.jobs.values()][0] : orch, members, reason, `prompt-destination:${dest}`, [PROMPT_ALERT_TAG, ...kindTags, ...keys], group.jobs);
1042
1164
  const row = deps.queueRepo.getById(aggregate.qitemId);
1043
1165
  if (!row)
1044
1166
  continue;
1045
- const addedKeys = group.keys.filter(key => !row.tags?.includes(key));
1167
+ const addedKeys = keys.filter(key => !row.tags?.includes(key));
1046
1168
  // A reminder's run keeps its key while its latest refusal changes kind, so the kind is recomputed on its own too.
1047
1169
  const kindChanged = choiceOnly !== Boolean(row.tags?.includes(PROMPT_CHOICE_TAG));
1048
1170
  if (addedKeys.length || kindChanged) {
@@ -1079,9 +1201,10 @@ async function advancePromptRefusals(deps, now, intervalS, graceS, resolveOrch,
1079
1201
  continue;
1080
1202
  if (!view.orchRung) {
1081
1203
  if (!toOperator) {
1082
- const outcome = await attemptWake(row.qitemId, orch);
1083
- appendMarker(deps.queueRepo, row, `${LADDER_RUNG_PREFIX} orchestrator -> ${orch} outcome=${outcome} reason=${reason}`);
1084
- actions.push({ qitemId: row.qitemId, action: "escalate-orchestrator", target: orch });
1204
+ const recoveryOwner = row.destinationSession;
1205
+ const outcome = await attemptWake(row.qitemId, recoveryOwner);
1206
+ appendMarker(deps.queueRepo, row, `${LADDER_RUNG_PREFIX} orchestrator -> ${recoveryOwner} outcome=${outcome} reason=${reason}`);
1207
+ actions.push({ qitemId: row.qitemId, action: "escalate-orchestrator", target: recoveryOwner });
1085
1208
  if (!outcome.startsWith("failed:"))
1086
1209
  appendExhausted(deps.queueRepo, row, `escalated to orchestrator (${outcome})`);
1087
1210
  continue;
@@ -1091,14 +1214,8 @@ async function advancePromptRefusals(deps, now, intervalS, graceS, resolveOrch,
1091
1214
  // One choice-prompt alert to a person at a time on this machine: a prompt many seats hit together, such as a shared usage
1092
1215
  // limit, posts once. Each other choice alert stays open, names the alert it waits on, and posts after that one retires.
1093
1216
  // A permission prompt, which only a person can approve, never waits behind it.
1094
- const posted = choiceOnly && deps.deliveryEngine ? postedPromptAlert(deps.db, row.qitemId) : null;
1095
- if (posted) {
1096
- const waiting = `${LADDER_RUNG_PREFIX} operator waiting on ${posted}`;
1097
- if (!deps.queueRepo.listTransitions(row.qitemId).some(t => t.transitionNote?.startsWith(waiting))) {
1098
- appendMarker(deps.queueRepo, row, `${waiting} reason=one person alert at a time for seats blocked at a prompt`);
1099
- }
1217
+ if (waitsOnPostedPromptAlert(deps, row, choiceOnly))
1100
1218
  continue;
1101
- }
1102
1219
  if (await operatorRung(deps, row, reason, actions, view, choiceOnly)) {
1103
1220
  const floor = deps.queueRepo.listTransitions(row.qitemId).at(-1)?.transitionNote?.includes("human rung explicit-only");
1104
1221
  appendExhausted(deps.queueRepo, row, floor ? PROMPT_FLOOR_EXHAUSTED : "operator rung resolved");
@@ -1190,6 +1307,12 @@ async function refreshEscalationRowIfExists(deps, dest, members, dedupTag = esca
1190
1307
  closureTarget: row.state === "in-progress" ? deps.queueRepo.retainedClaimBlocker(existing.qitem_id) : undefined });
1191
1308
  })();
1192
1309
  }
1310
+ /** Existing recovery custody takes precedence over a newly resolved topology fallback. */
1311
+ function openEscalationOwner(db, dedupTag) {
1312
+ return db.prepare(`SELECT destination_session FROM queue_items WHERE state IN ('pending','in-progress','blocked')
1313
+ AND json_valid(tags) AND EXISTS (SELECT 1 FROM json_each(tags) WHERE value = ?) LIMIT 1`)
1314
+ .get(dedupTag)?.destination_session ?? null;
1315
+ }
1193
1316
  async function ensureEscalationRow(deps, dest, orch, members, reason, dedupTag = escalationDedupTag(dest), extraTags = [],
1194
1317
  /** Watchdog reminders refused at this seat's prompt: job id to the session that registered it. */
1195
1318
  jobs = new Map()) {
@@ -1208,12 +1331,16 @@ jobs = new Map()) {
1208
1331
  members.map((m) => `- ${m.row.qitemId}: ${m.row.summary ?? "outstanding work"} (${m.reason})`).join("\n") +
1209
1332
  (jobs.size ? `\nwatchdog reminders refused at its prompt (${jobs.size}):\n${[...jobs.keys()].map(id => `- ${id}`).join("\n")}` : "") +
1210
1333
  `\nThe rows above still carry their obligations exactly-once; this escalation is the wake, not the content.`;
1334
+ const route = !deps.resolveOrchestrator
1335
+ ? resolveEscalationOwner(deps.db, dest, target => deps.queueRepo.acceptsDestination(target)) : null;
1336
+ const oneHop = route?.outcome === "routed" && route.owner === orch;
1211
1337
  const created = await deps.queueRepo.create({
1212
1338
  sourceSession: members[0]?.row.sourceSession ?? [...jobs.values()][0],
1213
1339
  destinationSession: orch,
1214
1340
  body,
1215
1341
  summary: `Wake escalation: ${members.length} baton(s)${jobs.size ? ` and ${jobs.size} watchdog reminder(s)` : ""} stuck at ${dest} — ${reason}`,
1216
- tags: [WAKE_ESCALATION_TAG, dedupTag, ...extraTags, ...members.map(m => recoveryTag(m.row.qitemId))],
1342
+ tags: [WAKE_ESCALATION_TAG, dedupTag,
1343
+ ...(oneHop ? [ESCALATION_HOP_TAG] : []), ...extraTags, ...members.map(m => recoveryTag(m.row.qitemId))],
1217
1344
  nudge: false, // delivery is the ladder's own rung attempt, recorded with its outcome
1218
1345
  });
1219
1346
  return { qitemId: created.qitemId };