@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 { TerminalPolicyRefusal } from "./terminal-policy.js";
2
2
  import { DeliveryGuardError } from "./seat-delivery-guard.js";
3
- import { CAPTURE_READABLE_BUDGET_MS } from "./session-transport.js";
3
+ import { CAPTURE_READABLE_BUDGET_MS, SEND_READINESS_FRESHNESS_MS } from "./session-transport.js";
4
4
  import { postCompactExtraSetting } from "./managed-restore-read-access.js";
5
5
  import * as fs from "node:fs";
6
6
  import { randomUUID } from "node:crypto";
@@ -65,6 +65,11 @@ export const AUTO_PREP_WAIT_MS_DEFAULT = 25 * 60_000;
65
65
  // How long a stopped attempt holds automatic compaction off for its seat before a fresh attempt may begin. Without it one
66
66
  // failed preparation turned automatic compaction off for the seat until someone noticed. Operational, not measured.
67
67
  export const AUTO_RETRY_AFTER_STOP_MS_DEFAULT = 10 * 60_000;
68
+ /** A held map retires once usage has risen this many points since its request (#2682). Operational, not measured: with the
69
+ * default 80% threshold, 95% is still reachable. */
70
+ export const PREPARED_MAP_MAX_GROWTH_PERCENT = 15;
71
+ /** A held map retires this long after it was first seen ready (#2682). Operational, not measured. */
72
+ export const PREPARED_MAP_MAX_AGE_MS = 2 * 60 * 60_000;
68
73
  const PREP_SEND_ATTEMPTS_MAX = 3;
69
74
  // Slices 13–14 fix — each post-compact back-half send (turn_boundary → restore →
70
75
  // audit) is idle-gated so it cannot be injected into the busy pane right after
@@ -270,6 +275,9 @@ export function buildPostCompactTurnBoundaryPrompt() {
270
275
  "Do not restore yet; the next normal user message will contain the restore instructions.",
271
276
  ].join(" ");
272
277
  }
278
+ /** #2575: after this many consecutive idle polls that can't read the box, a post-compaction step goes ahead; a typed
279
+ * draft still holds it. Waiting doesn't show the box is empty, so the delivery is recorded as over an unreadable box. */
280
+ export const UNREADABLE_POLLS_BEFORE_DELIVERY = 2;
273
281
  /** The file, beside an attempt's restore map, where the daemon records what it last did for that attempt. The agent
274
282
  * never writes it. A restarted daemon reads it to pick the attempt up again. */
275
283
  export const COMPACTION_RECORD_FILE = "COMPACTION-STATE.json";
@@ -278,6 +286,11 @@ export const COMPACTION_RECORD_FILE = "COMPACTION-STATE.json";
278
286
  export const RESTART_RECOVERY_WINDOW_MS_DEFAULT = 6 * 60 * 60_000;
279
287
  /** This daemon process. A record this process wrote is its own state, never something to recover. */
280
288
  const DAEMON_PROCESS_ID = randomUUID();
289
+ /** What an automatic attempt returns while it is held, its map complete, until a window opens (#2682). */
290
+ const PREPARED_AWAITING_WINDOW = "prepared_awaiting_window";
291
+ /** Refusals of the /compact before any input that hold a completed map instead of stopping it: a draft in the box (in
292
+ * the receipt or thrown by the guard) and a pane in a tmux mode. Every other refusal stops as before. */
293
+ const HOLD_REASONS = new Set(["draft_input_busy", "draft_input_unknown", "draft_input_changed", "pane_in_mode"]);
281
294
  const RECORD_PHASES = new Set(["preparing", "turn_boundary", "restore_prompt", "compliance_prompt", "compact_uncertain", "done", "ended"]);
282
295
  const RECORD_DELIVERIES = new Set(["pending", "not_sent", "delivered", "uncertain"]);
283
296
  /** A record only in the shape this daemon writes. Any other (a newer daemon's after a rollback, a damaged file) is ignored,
@@ -294,6 +307,12 @@ function readCompactionRecord(file) {
294
307
  && text(r.mapPath) && text(r.marker) && text(r.compactInstruction) && textOrNull(r.preparationRoot) && Number.isFinite(r.updatedAt)
295
308
  && (r.operatorInitiated === undefined || typeof r.operatorInitiated === "boolean") && (r.compactSending === undefined || r.compactSending === true)
296
309
  && (r.uncertainCompact === undefined || r.uncertainCompact === true)
310
+ && (r.prepared === undefined || r.prepared === true) && (r.preparedAt === undefined || Number.isFinite(r.preparedAt))
311
+ && (r.preparedReason === undefined || text(r.preparedReason)) && (r.belowSince === undefined || Number.isFinite(r.belowSince))
312
+ && (r.mapReadyAt === undefined || Number.isFinite(r.mapReadyAt)) && (r.mapUsedPercentage === undefined || Number.isFinite(r.mapUsedPercentage))
313
+ && (r.sessionId === undefined || text(r.sessionId)) && (r.endedAt === undefined || Number.isFinite(r.endedAt))
314
+ && (r.afterEnded === undefined || Number.isFinite(r.afterEnded))
315
+ && (r.afterEndedSessionId === undefined || textOrNull(r.afterEndedSessionId))
297
316
  && (carry === undefined || (typeof carry === "object" && carry !== null && textOrNull(carry.mapPath) && textOrNull(carry.compactInstruction)
298
317
  && (carry.skipMap === undefined || (text(carry.skipMap?.mapPath) && text(carry.skipMap?.marker)))));
299
318
  return valid ? r : null;
@@ -327,6 +346,9 @@ export class ClaudeCompactionEnforcer {
327
346
  postCompactRestoreCooldownUntil = new Map();
328
347
  triggeredAboveThreshold = new Set();
329
348
  pendingPreCompactPrep = new Map();
349
+ /** The seat's last attempt that ended with its request delivered (or possibly delivered) and no /compact (#2682): a fresh
350
+ * automatic preparation for the same occupant and conversation waits for an idle seat. Kept across a restart by the record. */
351
+ lastEnded = new Map();
330
352
  pendingPostCompactRestore = new Map();
331
353
  // OPR.0.4.3.14 — per-seat manual-trigger surfaced state (AC-3). In-memory,
332
354
  // non-persisted (a daemon restart reset is the safe-failure direction).
@@ -365,7 +387,8 @@ export class ClaudeCompactionEnforcer {
365
387
  this.now = opts?.now ?? (() => Date.now());
366
388
  this.sleep = opts?.sleep ?? (ms => new Promise(resolve => setTimeout(resolve, ms)));
367
389
  this.postCompactSendWaitMs = opts?.postCompactSendWaitMs ?? POST_COMPACT_SEND_WAIT_MS_DEFAULT;
368
- this.compactSendIdleWaitMs = opts?.compactSendIdleWaitMs ?? 1000;
390
+ // A fresh preparation hook can veto even a visibly idle pane for the full send-readiness window.
391
+ this.compactSendIdleWaitMs = opts?.compactSendIdleWaitMs ?? SEND_READINESS_FRESHNESS_MS;
369
392
  this.restartRecoveryWindowMs = opts?.restartRecoveryWindowMs ?? RESTART_RECOVERY_WINDOW_MS_DEFAULT;
370
393
  this.daemonInstance = opts?.daemonInstance ?? DAEMON_PROCESS_ID;
371
394
  this.resolveOccupantGeneration = opts?.resolveOccupantGeneration;
@@ -378,8 +401,69 @@ export class ClaudeCompactionEnforcer {
378
401
  */
379
402
  async maybeAutoCompact(input) {
380
403
  this.reconcilePreparations();
404
+ const gated = await this.endedAttemptGate(input);
405
+ if (gated)
406
+ return gated;
381
407
  return this.withDeliveryGuard(input, () => this.maybeAutoCompactUnchecked(input));
382
408
  }
409
+ liveGeneration(session) {
410
+ return this.resolveOccupantGeneration?.(session) ?? this.sessionTransport.deliveryGuard?.maybeTarget(session)?.occupant ?? null;
411
+ }
412
+ /** #2682: before a fresh automatic preparation after an attempt that ended with its request delivered, for the same
413
+ * occupant and conversation, the seat must read idle. Runs outside the delivery lease, as the manual path's idle wait. */
414
+ async endedAttemptGate(input) {
415
+ const session = input.sessionName;
416
+ if (input.runtime !== "claude-code" || input.usedPercentage == null)
417
+ return null;
418
+ this.recoverSeat(input);
419
+ const ended = this.lastEnded.get(session);
420
+ if (!ended)
421
+ return null;
422
+ const live = this.liveGeneration(session);
423
+ // A generation that reads unknown for a moment is not another occupant: the ended attempt is kept (below).
424
+ if (ended.occupantGeneration === null || (live !== null && live !== ended.occupantGeneration)
425
+ || (ended.sessionId && input.sessionId && ended.sessionId !== input.sessionId)
426
+ || this.now() - ended.endedAt >= this.restartRecoveryWindowMs) {
427
+ this.lastEnded.delete(session);
428
+ return null;
429
+ }
430
+ let policy;
431
+ try {
432
+ policy = this.settingsStore.resolveClaudeCompactionPolicy();
433
+ }
434
+ catch {
435
+ return null;
436
+ }
437
+ if (!policy.enabled || !isValidThresholdPercent(policy.thresholdPercent) || input.usedPercentage < policy.thresholdPercent)
438
+ return null;
439
+ if (this.pendingPostCompactRestore.has(session))
440
+ return null;
441
+ const attempt = this.pendingPreCompactPrep.get(session);
442
+ // The replacement whose request hasn't gone out yet (a busy send refused it) stays behind the gate.
443
+ const unsentReplacement = attempt?.mode === "automatic" && attempt.status === "sending" && attempt.afterEnded !== undefined;
444
+ if (attempt && !unsentReplacement && (attempt.status !== "stopped" || attempt.cancelled || attempt.compact !== "not_sent"))
445
+ return null;
446
+ // The stopped attempt's cooldown holds after a restart too.
447
+ if (this.now() - ended.endedAt < this.autoRetryAfterStopMs)
448
+ return { triggered: false, reason: "preparation_stopped" };
449
+ // With no occupant to name, no attempt could begin (it would stop as occupant_generation_unavailable and drop this one).
450
+ if (live === null)
451
+ return { triggered: false, reason: "occupant_generation_unavailable" };
452
+ // One readiness read, with no wait after it: this runs inside the monitor's serial poll, so a busy seat must not hold
453
+ // the other seats' polls. A busy seat, or a read that fails, waits for a later poll.
454
+ let idle;
455
+ try {
456
+ idle = await this.sessionTransport.waitUntilIdle(session, CAPTURE_READABLE_BUDGET_MS, undefined, { singleObservation: true });
457
+ }
458
+ catch {
459
+ idle = { ok: false };
460
+ }
461
+ if (!idle.ok)
462
+ return { triggered: false, reason: "waiting_for_idle" };
463
+ // The gate is used up only when the replacement request goes out (deliverPreparation), and that send checks idle
464
+ // again: an observation refused as stale, or a peer's turn starting before the send, keeps it.
465
+ return null;
466
+ }
383
467
  /**
384
468
  * What this enforcer has recorded about a managed compaction of `sessionName`, for a sender's context, or null when
385
469
  * none is under way. Read-only: it reports the enforcer's own state (the preparation attempt and the post-compact
@@ -418,6 +502,11 @@ export class ClaudeCompactionEnforcer {
418
502
  this.recoverSeat({ sessionName, ...seat });
419
503
  return this.pendingPostCompactRestore.has(sessionName);
420
504
  }
505
+ /** #2661 (c): since when (epoch ms) a post-compact stage has been owed to this seat — the /compact this daemon sent,
506
+ * or this daemon's recovery of one recorded before a restart (a lower bound then) — or null when none is owed. */
507
+ postCompactStageOwedSince(sessionName) {
508
+ return this.pendingPostCompactRestore.has(sessionName) ? this.lastAutoCompactAt.get(sessionName) ?? null : null;
509
+ }
421
510
  /** The first time this daemon reaches a seat (a poll, a manual request, a state read): pick up its record from before a
422
511
  * restart, with the policy's preparation root (`recoverAfterRestart`). */
423
512
  recoverSeat(seat) {
@@ -440,8 +529,12 @@ export class ClaudeCompactionEnforcer {
440
529
  const lastDelivery = this.records.get(sessionName)?.record.lastDelivery;
441
530
  const failed = !!lastDelivery && lastDelivery.failures > 0;
442
531
  const last = lastDelivery ? { lastDelivery } : {};
443
- const failure = lastDelivery ? ` ${failed ? "Last delivery" : "waiting: seat busy"} at ${lastDelivery.at}: ${[lastDelivery.reason, lastDelivery.activity?.reason, lastDelivery.errorClass, lastDelivery.noticeErrorClass && `owner notice failed (${lastDelivery.noticeErrorClass})`].filter(Boolean).join("; ")}. OpenRig will retry on its existing polls.` : "";
444
- const step = { turn_boundary: "post-compaction turn boundary", restore_prompt: "restore request", compliance_prompt: "post-restore audit" }[stage];
532
+ const steps = { turn_boundary: "post-compaction turn boundary", restore_prompt: "restore request", compliance_prompt: "post-restore audit" };
533
+ const failure = !lastDelivery ? "" : lastDelivery.reason === "delivered_over_unreadable_input_box"
534
+ ? ` The ${steps[lastDelivery.stage]} went in at ${lastDelivery.at} over an input box OpenRig couldn't read (it read ${lastDelivery.inputBox ?? "unknown"}); a draft there, if any, may hold its text.`
535
+ : ` ${failed ? "Last delivery" : "waiting: seat busy"} at ${lastDelivery.at}: ${[lastDelivery.reason, lastDelivery.activity?.reason, lastDelivery.errorClass, lastDelivery.noticeErrorClass && `owner notice failed (${lastDelivery.noticeErrorClass})`].filter(Boolean).join("; ")}. OpenRig will retry on its existing polls.${lastDelivery.unreadable
536
+ ? ` After ${UNREADABLE_POLLS_BEFORE_DELIVERY} idle polls that can't read the input box, the step goes in anyway; a typed draft still holds it.` : ""}`;
537
+ const step = steps[stage];
445
538
  if (!this.afterUncertainCompact.has(sessionName)) {
446
539
  return { stage, held: failed, ...last, detail: `OpenRig owes this seat its ${step} next, sent on a poll once the pane is idle.${failure}` };
447
540
  }
@@ -481,20 +574,51 @@ export class ClaudeCompactionEnforcer {
481
574
  return (await this.drainPendingStage(unsampled, policy)) ?? { triggered: false, reason: "no_pending_stage" };
482
575
  });
483
576
  }
484
- /** Finish only an already-armed automatic map when usage has gone stale; never request another preparation. */
577
+ /** Finish only an already-armed automatic map when usage has gone stale; never request another preparation.
578
+ * `lastUsedPercentage` and `sessionId` are the seat's newest sample, however old: a map whose context has since dropped
579
+ * below the threshold, or whose conversation changed (Claude Code's own compaction, a person's /compact or /clear, also
580
+ * while the daemon was down), never compacts (#2682). */
485
581
  async drainPendingPreparedCompact(input) {
486
- const unsampled = { ...input, usedPercentage: null };
582
+ const { lastUsedPercentage, ...rest } = input;
583
+ const unsampled = { ...rest, usedPercentage: null };
487
584
  this.recoverSeat(input);
488
585
  this.reconcilePreparations();
489
586
  const attempt = this.pendingPreCompactPrep.get(input.sessionName);
490
587
  if (input.runtime !== "claude-code" || attempt?.mode !== "automatic" || attempt.status !== "waiting"
491
- || attempt.delivery === "pending" || !this.mapReady(attempt))
588
+ || attempt.delivery === "pending")
492
589
  return { triggered: false, reason: "no_pending_stage" };
493
- if (!isValidThresholdPercent(this.settingsStore.resolveClaudeCompactionPolicy().thresholdPercent))
590
+ const threshold = this.settingsStore.resolveClaudeCompactionPolicy().thresholdPercent;
591
+ if (!isValidThresholdPercent(threshold))
494
592
  return { triggered: false, reason: "invalid_policy" };
593
+ const otherConversation = !!attempt.sessionId && !!input.sessionId && attempt.sessionId !== input.sessionId;
594
+ // Another conversation, known on both sides, ends an armed or held map, as on the fresh path, also one whose map isn't
595
+ // complete yet: a later sample whose conversation reads unknown must not compact with it.
596
+ if (otherConversation && !attempt.compactInFlight) {
597
+ this.stopPreparation(input.sessionName, "below_threshold_while_prepared", attempt);
598
+ return { triggered: false, reason: "preparation_stopped" };
599
+ }
600
+ if (!this.mapReady(attempt))
601
+ return { triggered: false, reason: "no_pending_stage" };
602
+ const dropped = lastUsedPercentage != null && lastUsedPercentage < threshold;
603
+ if (dropped && !attempt.compactInFlight) {
604
+ // A held map ends, as on a fresh dip. An attempt not held keeps its deadline (and a later fresh sample above may
605
+ // still use its map), but a stale sample never compacts it.
606
+ if (attempt.prepared) {
607
+ this.stopPreparation(input.sessionName, "below_threshold_while_prepared", attempt);
608
+ return { triggered: false, reason: "preparation_stopped" };
609
+ }
610
+ return { triggered: false, reason: "below_threshold" };
611
+ }
612
+ // The same growth rule as on a fresh sample: a stale sample (a restart, a slow sidecar) that usage has carried
613
+ // PREPARED_MAP_MAX_GROWTH_PERCENT above the map retires it instead of compacting with it.
614
+ if (attempt.prepared && !attempt.compactInFlight && lastUsedPercentage != null && attempt.mapUsedPercentage !== undefined
615
+ && lastUsedPercentage - attempt.mapUsedPercentage >= PREPARED_MAP_MAX_GROWTH_PERCENT) {
616
+ this.stopPreparation(input.sessionName, "prepared_map_stale", attempt);
617
+ return { triggered: false, reason: "preparation_stopped" };
618
+ }
495
619
  return this.withDeliveryGuard(unsampled, async () => {
496
620
  const result = await this.sendPreparedCompact(unsampled, attempt, false);
497
- return result.ok ? { triggered: true } : { triggered: false, reason: result.reason === "waiting_for_idle" ? "waiting_for_idle" : "send_failed" };
621
+ return result.ok ? { triggered: true } : { triggered: false, reason: result.reason === "waiting_for_idle" || result.reason === PREPARED_AWAITING_WINDOW ? result.reason : "send_failed" };
498
622
  });
499
623
  }
500
624
  terminalPolicyReason(input, actor) {
@@ -545,7 +669,8 @@ export class ClaudeCompactionEnforcer {
545
669
  void Promise.resolve().then(() => {
546
670
  if (this.records.get(input.sessionName) !== record || record.record.lastDelivery !== lastDelivery || this.pendingPostCompactRestore.get(input.sessionName) !== stage)
547
671
  return;
548
- return this.onRestoreDeliveryFailure({ sessionName: input.sessionName, attemptId: record.record.attemptId, mapPath: record.record.mapPath, lastDelivery });
672
+ return this.onRestoreDeliveryFailure({ sessionName: input.sessionName, attemptId: record.record.attemptId, mapPath: record.record.mapPath,
673
+ markerPath: path.join(this.openrigHome, "compaction", "restore-pending", `${sanitizeSessionKey(input.sessionName)}.json`), lastDelivery });
549
674
  }).catch(error => {
550
675
  if (this.records.get(input.sessionName) === record && record.record.lastDelivery === lastDelivery && this.pendingPostCompactRestore.get(input.sessionName) === stage) {
551
676
  lastDelivery.noticeErrorClass = error instanceof Error ? error.name : typeof error;
@@ -561,11 +686,17 @@ export class ClaudeCompactionEnforcer {
561
686
  const prior = record.record.lastDelivery;
562
687
  // Active work is the expected wait between restore steps, not an undeliverable stage.
563
688
  const waiting = result.reason === "wait_for_idle_timeout" && result.activity?.state === "running";
689
+ // The idle wait passed and the box read neither empty nor typed. A recognised draft, a hold with no reading, or any
690
+ // other result breaks the run.
691
+ const held = result.heldInputBox;
692
+ const unreadable = !result.ok && result.reason === "draft_input_unknown" && held && held !== "typed" && held !== "typed-with-suggestion"
693
+ ? (prior && prior.stage === stage ? prior.unreadable ?? 0 : 0) + 1 : 0;
564
694
  const lastDelivery = {
565
695
  stage, at: new Date(this.now()).toISOString(), ok: result.ok, reason: result.reason ?? "send_failed",
566
696
  ...(result.outcome ? { outcome: result.outcome } : {}),
567
697
  ...(result.activity ? { activity: { state: result.activity.state, reason: result.activity.reason, evidenceSource: result.activity.evidenceSource } } : {}),
568
698
  ...(errorClass ? { errorClass } : {}), failures: waiting ? 0 : (prior?.failures ?? 0) + 1,
699
+ ...(held ? { inputBox: held } : {}), ...(unreadable ? { unreadable } : {}),
569
700
  };
570
701
  this.persist(session, record.record.attemptId, { lastDelivery });
571
702
  }
@@ -587,9 +718,14 @@ export class ClaudeCompactionEnforcer {
587
718
  const attempt = this.pendingPreCompactPrep.get(input.sessionName);
588
719
  const isCurrent = () => this.pendingPostCompactRestore.get(input.sessionName) === pendingStage
589
720
  && this.pendingPreCompactPrep.get(input.sessionName) === attempt;
721
+ // #2575: after enough idle polls that couldn't read the box for this step, the step goes in unless the box reads typed.
722
+ // Not after a /compact whose result was lost: there an Enter could submit /compact, so that check below stays strict.
723
+ const last = this.records.get(input.sessionName)?.record.lastDelivery;
724
+ const overUnreadable = !this.afterUncertainCompact.has(input.sessionName) && !!last && last.stage === pendingStage && !last.ok
725
+ && (last.unreadable ?? 0) >= UNREADABLE_POLLS_BEFORE_DELIVERY;
590
726
  const sendOpts = {
591
727
  openrigNotice: true,
592
- preserveInput: true,
728
+ preserveInput: overUnreadable ? "typed" : true,
593
729
  beforeWrite: () => {
594
730
  if (!isCurrent())
595
731
  throw new DeliveryGuardError("compaction_cancelled", "Managed compaction was cancelled or replaced; no further input is authorized.");
@@ -645,7 +781,7 @@ export class ClaudeCompactionEnforcer {
645
781
  return { triggered: false, reason: "send_failed" };
646
782
  }
647
783
  this.pendingPostCompactRestore.set(input.sessionName, "restore_prompt");
648
- this.persistStage(input.sessionName, "restore_prompt");
784
+ this.persistStage(input.sessionName, "restore_prompt", undefined, this.overUnreadableDelivery("turn_boundary", boundary));
649
785
  return { triggered: true };
650
786
  }
651
787
  if (pendingStage === "restore_prompt") {
@@ -672,7 +808,7 @@ export class ClaudeCompactionEnforcer {
672
808
  return { triggered: false, reason: "send_failed" };
673
809
  }
674
810
  this.pendingPostCompactRestore.set(input.sessionName, "compliance_prompt");
675
- this.persistStage(input.sessionName, "compliance_prompt");
811
+ this.persistStage(input.sessionName, "compliance_prompt", undefined, this.overUnreadableDelivery("restore_prompt", restore));
676
812
  this.restoreCarry.delete(input.sessionName);
677
813
  // OPR.0.4.3.14 — surface manual-trigger progress (no-op for auto seats).
678
814
  this.advanceManualStage(input.sessionName, "compact-sent", "restore-sent");
@@ -702,7 +838,7 @@ export class ClaudeCompactionEnforcer {
702
838
  if (!isCurrent())
703
839
  return { triggered: false, reason: "preparation_stopped" };
704
840
  this.pendingPostCompactRestore.delete(input.sessionName);
705
- this.persistStage(input.sessionName, "done");
841
+ this.persistStage(input.sessionName, "done", undefined, this.overUnreadableDelivery("compliance_prompt", compliance));
706
842
  this.records.delete(input.sessionName);
707
843
  this.afterUncertainCompact.delete(input.sessionName);
708
844
  this.lastInputBox.delete(input.sessionName);
@@ -747,6 +883,31 @@ export class ClaudeCompactionEnforcer {
747
883
  const drained = await this.drainPendingStage(input, policy);
748
884
  if (drained)
749
885
  return drained;
886
+ // Another conversation, proved by both sample and attempt naming theirs, ends an armed or held automatic attempt, on a
887
+ // low sample as on a high one, as in the stale-sample drain: the map is of a context that is gone, and a later sample
888
+ // whose conversation reads unknown must not compact with it.
889
+ // A conversation that reads unknown on either side is not a mismatch.
890
+ const armed = this.pendingPreCompactPrep.get(input.sessionName);
891
+ // A request that never went out was made in no conversation: the attempt takes the sample's, and only a request
892
+ // delivered (or possibly delivered) in another conversation stops it.
893
+ if (armed?.mode === "automatic" && armed.status === "sending" && armed.delivery === "not_sent"
894
+ && !!input.sessionId && armed.sessionId !== input.sessionId) {
895
+ // A replacement moving to another conversation drops the gate it was replacing only when that gate fell in memory on
896
+ // this same sample (endedAttemptGate ran first), so a restart must not bring it back for the new conversation. An
897
+ // ended attempt whose conversation read unknown keeps its gate, and so does the replacement.
898
+ const dropGate = armed.afterEnded !== undefined && !this.lastEnded.has(input.sessionName);
899
+ if (dropGate) {
900
+ armed.afterEnded = undefined;
901
+ armed.afterEndedSessionId = undefined;
902
+ }
903
+ armed.sessionId = input.sessionId;
904
+ this.persist(input.sessionName, armed.attemptId, { sessionId: input.sessionId, ...(dropGate ? { afterEnded: undefined, afterEndedSessionId: undefined } : {}) });
905
+ }
906
+ if (armed?.mode === "automatic" && armed.status === "waiting" && armed.compact === "not_sent" && !armed.compactInFlight
907
+ && !!armed.sessionId && !!input.sessionId && armed.sessionId !== input.sessionId) {
908
+ this.stopPreparation(input.sessionName, "below_threshold_while_prepared", armed);
909
+ return { triggered: false, reason: "preparation_stopped" };
910
+ }
750
911
  if (input.usedPercentage < policy.thresholdPercent) {
751
912
  this.triggeredAboveThreshold.delete(input.sessionName);
752
913
  const preparation = this.pendingPreCompactPrep.get(input.sessionName);
@@ -754,8 +915,20 @@ export class ClaudeCompactionEnforcer {
754
915
  this.pendingPreCompactPrep.delete(input.sessionName);
755
916
  // A usage dip is not cancellation: retain an unfinished attempt and its
756
917
  // deadline so a later high sample can use its map without another prep.
918
+ // A held attempt ends on a fresh sample below the threshold (#2682): the context already dropped, by Claude Code's own
919
+ // compaction or a person's /compact or /clear, so its map would restore a context that is gone. On any other armed
920
+ // automatic attempt the dip is recorded, and such an attempt is never held later: it stops at its deadline as before.
921
+ if (preparation?.prepared && preparation.status === "waiting" && !preparation.compactInFlight) {
922
+ this.stopPreparation(input.sessionName, "below_threshold_while_prepared", preparation);
923
+ }
924
+ else if (preparation?.mode === "automatic" && preparation.status === "waiting" && preparation.compact === "not_sent"
925
+ && preparation.belowSince === undefined) {
926
+ preparation.belowSince = this.now();
927
+ this.persist(input.sessionName, preparation.attemptId, { belowSince: preparation.belowSince });
928
+ }
757
929
  return { triggered: false, reason: "below_threshold" };
758
930
  }
931
+ // A climb back above the threshold keeps the dip's mark (belowSince): the attempt that dipped is never held (#2682).
759
932
  // No new automatic compaction while disabled. An already-owed stage above uses
760
933
  // drainPendingStage's existing operator-initiated manual exemption.
761
934
  if (!policy.enabled) {
@@ -817,9 +990,15 @@ export class ClaudeCompactionEnforcer {
817
990
  }
818
991
  if (attempt.delivery === "pending" || !this.mapReady(attempt))
819
992
  return { triggered: false, reason: "preparation_pending" };
993
+ // A held map that usage has outgrown retires; the next idle window prepares afresh (#2682).
994
+ if (attempt.prepared && attempt.mapUsedPercentage !== undefined
995
+ && input.usedPercentage - attempt.mapUsedPercentage >= PREPARED_MAP_MAX_GROWTH_PERCENT) {
996
+ this.stopPreparation(input.sessionName, "prepared_map_stale", attempt);
997
+ return { triggered: false, reason: "preparation_stopped" };
998
+ }
820
999
  const compact = await this.sendPreparedCompact(input, attempt, false);
821
1000
  if (!compact.ok)
822
- return { triggered: false, reason: compact.reason === "waiting_for_idle" ? "waiting_for_idle" : "send_failed" };
1001
+ return { triggered: false, reason: compact.reason === "waiting_for_idle" || compact.reason === PREPARED_AWAITING_WINDOW ? compact.reason : "send_failed" };
823
1002
  return { triggered: true };
824
1003
  }
825
1004
  /**
@@ -952,6 +1131,17 @@ export class ClaudeCompactionEnforcer {
952
1131
  const stranded = this.stranded.get(input.sessionName);
953
1132
  if (stranded)
954
1133
  attempt.supersedes = strandedSummary(stranded);
1134
+ if (input.sessionId)
1135
+ attempt.sessionId = input.sessionId;
1136
+ // A manual compaction is explicit and replaces the ended attempt at once. An automatic one keeps the gate until its
1137
+ // request goes out (deliverPreparation).
1138
+ if (mode === "manual")
1139
+ this.lastEnded.delete(input.sessionName);
1140
+ else if (this.lastEnded.has(input.sessionName)) {
1141
+ const ended = this.lastEnded.get(input.sessionName);
1142
+ attempt.afterEnded = ended.endedAt;
1143
+ attempt.afterEndedSessionId = ended.sessionId;
1144
+ }
955
1145
  this.pendingPreCompactPrep.set(input.sessionName, attempt);
956
1146
  this.stranded.delete(input.sessionName);
957
1147
  // A map cannot satisfy an unknown occupant. Keep the failed attempt visible and
@@ -1025,8 +1215,10 @@ export class ClaudeCompactionEnforcer {
1025
1215
  }
1026
1216
  };
1027
1217
  // Preserve maps already published by agents using the older protocol.
1028
- if (complete(attempt.mapPath))
1218
+ if (complete(attempt.mapPath)) {
1219
+ this.noteMapReady(attempt);
1029
1220
  return true;
1221
+ }
1030
1222
  const temporary = attempt.mapPath + ".tmp";
1031
1223
  if (!complete(temporary))
1032
1224
  return false;
@@ -1040,8 +1232,19 @@ export class ClaudeCompactionEnforcer {
1040
1232
  return false;
1041
1233
  }
1042
1234
  }
1235
+ this.noteMapReady(attempt);
1043
1236
  return true;
1044
1237
  }
1238
+ /** The first time an attempt's map is seen ready, on any path (#2682): a held map's age counts from here. */
1239
+ noteMapReady(attempt) {
1240
+ if (attempt.mapReadyAt !== undefined)
1241
+ return;
1242
+ attempt.mapReadyAt = this.now();
1243
+ for (const [session, current] of this.pendingPreCompactPrep) {
1244
+ if (current === attempt)
1245
+ this.persist(session, attempt.attemptId, { mapReadyAt: attempt.mapReadyAt });
1246
+ }
1247
+ }
1045
1248
  async deliverPreparation(input, attempt) {
1046
1249
  if (attempt.sends >= PREP_SEND_ATTEMPTS_MAX) {
1047
1250
  this.stopPreparation(input.sessionName, "send_failed");
@@ -1051,6 +1254,9 @@ export class ClaudeCompactionEnforcer {
1051
1254
  // Mark waiting BEFORE the await: concurrent polls cannot replay an in-flight delivery.
1052
1255
  attempt.status = "waiting";
1053
1256
  const policy = this.settingsStore.resolveClaudeCompactionPolicy();
1257
+ // After an ended attempt, the replacement request goes only to a seat the send itself reads idle (a live pane read),
1258
+ // within the /compact send's short wait, so a turn that began after the gate's idle read gets no request (#2682).
1259
+ const idleGate = attempt.afterEnded !== undefined ? { waitForIdleMs: this.compactSendIdleWaitMs + CAPTURE_READABLE_BUDGET_MS, readinessFromPaneOnly: true } : {};
1054
1260
  let prep;
1055
1261
  let marked = false;
1056
1262
  try {
@@ -1059,7 +1265,7 @@ export class ClaudeCompactionEnforcer {
1059
1265
  overflowCompactInstruction: composed.instructionInCommand ? null : attempt.compactInstruction,
1060
1266
  usedPercentage: input.usedPercentage, thresholdPercent: policy.thresholdPercent,
1061
1267
  preCompactInstruction: policy.preCompactInstruction, preparation: attempt, constructedAt: this.now(),
1062
- }), { openrigNotice: true, preserveInput: true, beforeWrite: () => {
1268
+ }), { openrigNotice: true, preserveInput: true, ...idleGate, beforeWrite: () => {
1063
1269
  this.reconcilePreparations();
1064
1270
  if (this.pendingPreCompactPrep.get(input.sessionName) !== attempt || attempt.controller.signal.aborted || attempt.status === "stopped")
1065
1271
  throw new DeliveryGuardError("preparation_stopped", "This compaction attempt ended before preparation input.");
@@ -1090,6 +1296,9 @@ export class ClaudeCompactionEnforcer {
1090
1296
  // Neither a failed response nor its loss proves no paste/Enter. Never replay uncertainty.
1091
1297
  attempt.delivery = prep?.ok && prep.outcome !== "retained" ? "delivered" : notSent ? "not_sent" : "uncertain";
1092
1298
  this.persist(input.sessionName, attempt.attemptId, { delivery: attempt.delivery, sends: attempt.sends });
1299
+ // The replacement request went out (or may have): the ended attempt's gate is used up.
1300
+ if (!notSent && attempt.afterEnded !== undefined && this.pendingPreCompactPrep.get(input.sessionName) === attempt)
1301
+ this.lastEnded.delete(input.sessionName);
1093
1302
  if (this.pendingPreCompactPrep.get(input.sessionName) !== attempt || attempt.controller.signal.aborted)
1094
1303
  return;
1095
1304
  if (notSent) {
@@ -1100,7 +1309,10 @@ export class ClaudeCompactionEnforcer {
1100
1309
  }
1101
1310
  if (attempt.mode === "automatic")
1102
1311
  attempt.deadlineAt = this.now() + AUTO_PREP_WAIT_MS_DEFAULT;
1103
- this.persist(input.sessionName, attempt.attemptId, { deadlineAt: attempt.deadlineAt });
1312
+ // The usage the map is written at: a held map retires once usage has outgrown it (#2682).
1313
+ if (input.usedPercentage != null)
1314
+ attempt.mapUsedPercentage = input.usedPercentage;
1315
+ this.persist(input.sessionName, attempt.attemptId, { deadlineAt: attempt.deadlineAt, mapUsedPercentage: attempt.mapUsedPercentage });
1104
1316
  this.reconcilePreparations();
1105
1317
  }
1106
1318
  async sendPreparedCompact(input, attempt, skipMap) {
@@ -1128,15 +1340,18 @@ export class ClaudeCompactionEnforcer {
1128
1340
  check();
1129
1341
  if (!marked) {
1130
1342
  marked = true;
1343
+ attempt.compactInFlight = true;
1131
1344
  this.persist(input.sessionName, attempt.attemptId, { compactSending: true, restoreCarry: carry, operatorInitiated });
1132
1345
  }
1133
1346
  };
1134
1347
  const send = async () => {
1135
1348
  check();
1136
1349
  // Both paths send only to an idle seat. Include the readable observation's budget in the wait,
1137
- // still bounded by the attempt's existing deadline.
1350
+ // still bounded by the attempt's existing deadline, except for a held attempt: its deadline has no effect
1351
+ // any more, and a capped wait would discard every idle read that ends after it, so the window would never open.
1138
1352
  // Idle comes from a live pane read: the newest hook can predate the rest of the preparation turn.
1139
- return this.sessionTransport.send(input.sessionName, composed.command, { openrigNotice: true, preserveInput: true, beforeWrite, ...(attempt.deadlineAt !== null ? { waitForIdleMs: Math.max(1, Math.min(this.compactSendIdleWaitMs + CAPTURE_READABLE_BUDGET_MS, this.compactDeadline(attempt) - this.now())), readinessFromPaneOnly: true } : {}) });
1353
+ const idleWait = this.compactSendIdleWaitMs + CAPTURE_READABLE_BUDGET_MS;
1354
+ return this.sessionTransport.send(input.sessionName, composed.command, { openrigNotice: true, preserveInput: true, beforeWrite, ...(attempt.deadlineAt !== null ? { waitForIdleMs: attempt.prepared ? idleWait : Math.max(1, Math.min(idleWait, this.compactDeadline(attempt) - this.now())), readinessFromPaneOnly: true } : {}) });
1140
1355
  };
1141
1356
  let result;
1142
1357
  let guardRefused = false;
@@ -1152,6 +1367,9 @@ export class ClaudeCompactionEnforcer {
1152
1367
  result = { ok: false, reason: error instanceof DeliveryGuardError ? error.code : "delivery_uncertain",
1153
1368
  ...(written ? { sent: true, inputPhase: "written" } : attempted ? { inputPhase: "attempted" } : {}) };
1154
1369
  }
1370
+ finally {
1371
+ delete attempt.compactInFlight;
1372
+ }
1155
1373
  if (!result.ok || result.outcome === "retained") {
1156
1374
  const phase = result.inputPhase;
1157
1375
  // A write that was issued, or text already in the input, is never "nothing sent".
@@ -1161,6 +1379,11 @@ export class ClaudeCompactionEnforcer {
1161
1379
  const notSent = !writeAttempted && (guardRefused || result.outcome === "retained" || result.sent === false);
1162
1380
  if (notSent && marked)
1163
1381
  this.persist(input.sessionName, attempt.attemptId, { compactSending: undefined });
1382
+ // A completed map whose /compact was refused before any input, for a window that isn't open yet, is held with the
1383
+ // same map instead of stopped and asked for again after the retry cooldown (#2682).
1384
+ if (notSent && typeof result.reason === "string" && HOLD_REASONS.has(result.reason) && this.holdPrepared(input.sessionName, attempt, result.reason)) {
1385
+ return { ok: false, reason: PREPARED_AWAITING_WINDOW };
1386
+ }
1164
1387
  // Only a known pre-input idle deferral keeps the automatic attempt armed for a later poll; the transport
1165
1388
  // marks those `not_reached`. Reconciliation still bounds the idle grace and stops on an occupant change.
1166
1389
  // A typing-guard draft hold (`draft_*`) is `not_reached` too, but it is a refusal, not an idle wait: it stops
@@ -1210,6 +1433,7 @@ export class ClaudeCompactionEnforcer {
1210
1433
  this.restoreCarry.delete(sessionName);
1211
1434
  this.lastAutoCompactAt.set(sessionName, this.now());
1212
1435
  this.triggeredAboveThreshold.add(sessionName);
1436
+ this.lastEnded.delete(sessionName);
1213
1437
  this.pendingPostCompactRestore.set(sessionName, "turn_boundary");
1214
1438
  this.pendingStageGeneration.set(sessionName, attempt.occupantGeneration);
1215
1439
  }
@@ -1251,20 +1475,49 @@ export class ClaudeCompactionEnforcer {
1251
1475
  this.stopPreparation(session, "stale_generation");
1252
1476
  else if (!enabled && (attempt.mode === "automatic" || attempt.policyWasEnabled))
1253
1477
  this.stopPreparation(session, "disabled");
1254
- else if (attempt.deadlineAt !== null && this.now() >= this.compactDeadline(attempt)) {
1255
- this.stopPreparation(session, this.mapReady(attempt) ? "map_complete_seat_never_idle" : "preparation_incomplete");
1478
+ // A held map that stopped reading ready (its file or marker gone) stops the attempt (#2682).
1479
+ else if (attempt.prepared && !attempt.compactInFlight && !this.mapReady(attempt))
1480
+ this.stopPreparation(session, "preparation_incomplete");
1481
+ // A held map retires after a long while; a /compact already being written is never stopped (#2682).
1482
+ else if (attempt.prepared && !attempt.compactInFlight && this.now() - (attempt.mapReadyAt ?? attempt.preparedAt ?? this.now()) >= PREPARED_MAP_MAX_AGE_MS) {
1483
+ this.stopPreparation(session, "prepared_map_stale");
1484
+ }
1485
+ // A held attempt's deadline has no effect: it ends only as above, on a fresh dip, a stale map or a cancel (#2682).
1486
+ else if (!attempt.prepared && attempt.deadlineAt !== null && this.now() >= this.compactDeadline(attempt)) {
1487
+ const ready = this.mapReady(attempt);
1488
+ if (!(ready && this.holdPrepared(session, attempt, "map_complete_seat_never_idle"))) {
1489
+ this.stopPreparation(session, ready ? "map_complete_seat_never_idle" : "preparation_incomplete");
1490
+ }
1256
1491
  }
1257
1492
  if (enabled)
1258
1493
  attempt.policyWasEnabled = true;
1259
1494
  }
1260
1495
  }
1496
+ /** Hold an automatic attempt whose map is complete until a window opens, instead of stopping it (#2682). Only the
1497
+ * attempt that is current, armed and untouched: never one cancelled, stopped, manual, or with a /compact sent or in
1498
+ * flight. It keeps its controller, map and deadline, and is persisted only on the transition. */
1499
+ holdPrepared(session, attempt, reason) {
1500
+ if (attempt.mode !== "automatic" || attempt.status !== "waiting" || attempt.compact !== "not_sent" || attempt.compactInFlight
1501
+ || attempt.controller.signal.aborted || attempt.cancelled || attempt.reason !== undefined || attempt.belowSince !== undefined
1502
+ || this.pendingPreCompactPrep.get(session) !== attempt || !this.mapReady(attempt))
1503
+ return false;
1504
+ if (!attempt.prepared) {
1505
+ attempt.prepared = true;
1506
+ attempt.preparedAt = this.now();
1507
+ attempt.preparedReason = reason;
1508
+ this.persist(session, attempt.attemptId, { prepared: true, preparedAt: attempt.preparedAt, preparedReason: reason });
1509
+ }
1510
+ return true;
1511
+ }
1261
1512
  /** Start the record for a new attempt, beside its map. */
1262
1513
  startRecord(sessionName, attempt) {
1263
1514
  this.records.set(sessionName, { file: path.join(path.dirname(attempt.mapPath), COMPACTION_RECORD_FILE), record: {
1264
1515
  daemon: this.daemonInstance, attemptId: attempt.attemptId, session: sessionName, occupantGeneration: attempt.occupantGeneration, mode: attempt.mode,
1265
1516
  phase: "preparing", delivery: attempt.delivery, deadlineAt: attempt.deadlineAt, sends: attempt.sends,
1266
1517
  mapPath: attempt.mapPath, marker: attempt.marker, compactInstruction: attempt.compactInstruction,
1267
- preparationRoot: attempt.preparationRoot, updatedAt: this.now(),
1518
+ preparationRoot: attempt.preparationRoot, ...(attempt.sessionId ? { sessionId: attempt.sessionId } : {}),
1519
+ ...(attempt.afterEnded !== undefined ? { afterEnded: attempt.afterEnded, afterEndedSessionId: attempt.afterEndedSessionId ?? null } : {}),
1520
+ updatedAt: this.now(),
1268
1521
  } });
1269
1522
  this.persist(sessionName, attempt.attemptId, {});
1270
1523
  }
@@ -1287,10 +1540,15 @@ export class ClaudeCompactionEnforcer {
1287
1540
  catch { /* nothing to clean */ }
1288
1541
  }
1289
1542
  }
1290
- persistStage(sessionName, phase, reason) {
1543
+ persistStage(sessionName, phase, reason, lastDelivery) {
1291
1544
  const current = this.records.get(sessionName);
1292
1545
  if (current)
1293
- this.persist(sessionName, current.record.attemptId, { phase, ...(reason !== undefined ? { reason } : {}), lastDelivery: undefined });
1546
+ this.persist(sessionName, current.record.attemptId, { phase, ...(reason !== undefined ? { reason } : {}), lastDelivery });
1547
+ }
1548
+ /** A step that went in over a box OpenRig couldn't read stays on the record as that (#2575); any other advance clears it. */
1549
+ overUnreadableDelivery(stage, result) {
1550
+ return result.pastedOverInputBox ? { stage, at: new Date(this.now()).toISOString(), ok: true,
1551
+ reason: "delivered_over_unreadable_input_box", inputBox: result.pastedOverInputBox, failures: 0 } : undefined;
1294
1552
  }
1295
1553
  /**
1296
1554
  * After a daemon restart, pick up the seat's managed compaction from the record beside its newest attempt, when an
@@ -1338,9 +1596,30 @@ export class ClaudeCompactionEnforcer {
1338
1596
  return;
1339
1597
  const { record } = newest;
1340
1598
  // This process's own record (another enforcer in it) is live state, not a predecessor's.
1341
- if (record.daemon === this.daemonInstance || record.phase === "done" || record.phase === "ended")
1599
+ if (record.daemon === this.daemonInstance || record.phase === "done")
1342
1600
  return;
1343
1601
  const live = this.resolveOccupantGeneration?.(session) ?? this.sessionTransport.deliveryGuard?.maybeTarget(session)?.occupant ?? null;
1602
+ if (record.phase === "ended") {
1603
+ // An ended automatic attempt of this occupant whose request was delivered and whose /compact was never sent keeps a
1604
+ // busy seat from a fresh request (#2682), as in memory. Only a stop writes endedAt; a /compact that was sent (and then
1605
+ // cancelled) never stopped, and one whose result was lost is marked uncertainCompact.
1606
+ const endedAt = record.endedAt;
1607
+ if (endedAt !== undefined && !record.uncertainCompact && !record.compactSending
1608
+ && record.mode === "automatic" && (record.delivery === "delivered" || record.delivery === "uncertain")
1609
+ // An occupant that reads unknown at this first look keeps the record, inert: the gate compares the generation once
1610
+ // it can be read, and a different occupant then discards it.
1611
+ && record.occupantGeneration !== null && (live === null || live === record.occupantGeneration)
1612
+ && this.now() - endedAt < this.restartRecoveryWindowMs)
1613
+ this.lastEnded.set(session, { endedAt, occupantGeneration: record.occupantGeneration, sessionId: record.sessionId ?? null });
1614
+ // A replacement that stopped with its request never sent keeps the gate of the attempt it replaced, as in memory and
1615
+ // as a replacement still preparing does below.
1616
+ else if (record.mode === "automatic" && record.afterEnded !== undefined && record.delivery === "not_sent"
1617
+ && record.occupantGeneration !== null && (live === null || live === record.occupantGeneration)
1618
+ && this.now() - record.afterEnded < this.restartRecoveryWindowMs) {
1619
+ this.lastEnded.set(session, { endedAt: record.afterEnded, occupantGeneration: record.occupantGeneration, sessionId: record.afterEndedSessionId ?? null });
1620
+ }
1621
+ return;
1622
+ }
1344
1623
  if (record.occupantGeneration !== null && live !== null && live !== record.occupantGeneration)
1345
1624
  return;
1346
1625
  const stale = this.now() - record.updatedAt > this.restartRecoveryWindowMs;
@@ -1349,8 +1628,13 @@ export class ClaudeCompactionEnforcer {
1349
1628
  const phase = (record.phase === "preparing" && record.compactSending) || record.phase === "compact_uncertain" ? "turn_boundary" : record.phase;
1350
1629
  const inFlight = phase !== record.phase;
1351
1630
  if (phase === "preparing") {
1352
- if (stale)
1353
- return; // Its preparation deadline passed long ago; a fresh attempt may begin.
1631
+ // Its preparation deadline passed long ago; a fresh attempt may begin. A held attempt of this same occupant has no
1632
+ // deadline that matters: it is picked up as it was, however old, and the reconcile below retires its map once it is
1633
+ // too old (#2682). One whose context dropped before it was held never comes back held.
1634
+ const held = record.prepared === true && record.mode === "automatic" && record.deadlineAt !== null && record.belowSince === undefined;
1635
+ const heldHere = held && record.occupantGeneration !== null && live === record.occupantGeneration;
1636
+ if (stale && !heldHere)
1637
+ return;
1354
1638
  this.records.set(session, newest);
1355
1639
  this.pendingPreCompactPrep.set(session, {
1356
1640
  policyActor: { source: "openrig" }, attemptId: record.attemptId, occupantGeneration: record.occupantGeneration,
@@ -1361,9 +1645,24 @@ export class ClaudeCompactionEnforcer {
1361
1645
  deadlineAt: record.deadlineAt ?? (record.delivery === "not_sent" ? null : record.updatedAt + AUTO_PREP_WAIT_MS_DEFAULT),
1362
1646
  policyWasEnabled: true, preparationRoot: record.preparationRoot, controller: new AbortController(),
1363
1647
  compactInstruction: record.compactInstruction,
1648
+ // A held attempt comes back held, with its recorded hold (never stamped again) and its map's age and usage.
1649
+ ...(held ? { prepared: true, preparedAt: record.preparedAt ?? record.updatedAt, preparedReason: record.preparedReason ?? "map_complete_seat_never_idle" } : {}),
1650
+ ...(held ? { mapReadyAt: record.mapReadyAt ?? record.preparedAt ?? record.updatedAt } : record.mapReadyAt !== undefined ? { mapReadyAt: record.mapReadyAt } : {}),
1651
+ ...(record.mapUsedPercentage !== undefined ? { mapUsedPercentage: record.mapUsedPercentage } : {}),
1652
+ ...(record.sessionId !== undefined ? { sessionId: record.sessionId } : {}),
1653
+ ...(record.mode === "automatic" && record.belowSince !== undefined ? { belowSince: record.belowSince } : {}),
1654
+ ...(record.mode === "automatic" && record.afterEnded !== undefined ? { afterEnded: record.afterEnded, afterEndedSessionId: record.afterEndedSessionId ?? null } : {}),
1364
1655
  });
1656
+ // A replacement whose request never went out keeps the ended attempt's gate, as in memory.
1657
+ if (record.mode === "automatic" && record.afterEnded !== undefined && record.delivery === "not_sent" && record.occupantGeneration !== null
1658
+ && this.now() - record.afterEnded < this.restartRecoveryWindowMs) {
1659
+ this.lastEnded.set(session, { endedAt: record.afterEnded, occupantGeneration: record.occupantGeneration, sessionId: record.afterEndedSessionId ?? null });
1660
+ }
1365
1661
  if (record.mode === "manual")
1366
1662
  this.stopPreparation(session, "daemon_restarted");
1663
+ // A held map of any age is checked at once, without waiting for a send's checks (#2682).
1664
+ else
1665
+ this.reconcilePreparations();
1367
1666
  return;
1368
1667
  }
1369
1668
  if (stale) {
@@ -1394,7 +1693,14 @@ export class ClaudeCompactionEnforcer {
1394
1693
  attempt.reason = reason;
1395
1694
  attempt.stoppedAt = this.now();
1396
1695
  attempt.controller.abort();
1397
- this.persist(session, attempt.attemptId, { phase: attempt.compact === "uncertain" ? "compact_uncertain" : "ended", reason });
1696
+ // A stopped attempt is no longer held (#2682).
1697
+ const wasPrepared = attempt.prepared === true;
1698
+ delete attempt.prepared;
1699
+ this.persist(session, attempt.attemptId, { phase: attempt.compact === "uncertain" ? "compact_uncertain" : "ended", reason, endedAt: attempt.stoppedAt,
1700
+ ...(wasPrepared ? { prepared: undefined } : {}) });
1701
+ if (attempt.mode === "automatic" && (attempt.delivery === "delivered" || attempt.delivery === "uncertain") && attempt.compact === "not_sent") {
1702
+ this.lastEnded.set(session, { endedAt: attempt.stoppedAt, occupantGeneration: attempt.occupantGeneration, sessionId: attempt.sessionId ?? null });
1703
+ }
1398
1704
  if (attempt.mode === "manual")
1399
1705
  this.setManualStage(session, "skipped-or-failed", reason);
1400
1706
  }
@@ -1432,8 +1738,9 @@ export class ClaudeCompactionEnforcer {
1432
1738
  const attempt = this.pendingPreCompactPrep.get(session);
1433
1739
  if (!attempt)
1434
1740
  return null;
1435
- const { controller: _controller, sends: _sends, policyWasEnabled: _enabled, preparationRoot: _preparationRoot, compactInstruction: _instruction, stoppedAt: _stoppedAt, cancelled: _cancelled, ...state } = attempt;
1436
- return { ...state, ...(attempt.mode === "automatic" && attempt.deadlineAt !== null && this.mapReady(attempt)
1741
+ const { controller: _controller, sends: _sends, policyWasEnabled: _enabled, preparationRoot: _preparationRoot, compactInstruction: _instruction, stoppedAt: _stoppedAt, cancelled: _cancelled, belowSince: _belowSince, compactInFlight: _inFlight, sessionId: _sessionId, afterEnded: _afterEnded, afterEndedSessionId: _afterEndedSessionId, ...state } = attempt;
1742
+ // A held attempt has no idle deadline left to show: it waits for its window.
1743
+ return { ...state, ...(attempt.mode === "automatic" && !attempt.prepared && attempt.deadlineAt !== null && this.mapReady(attempt)
1437
1744
  ? { idleDeadlineAt: this.compactDeadline(attempt) } : {}) };
1438
1745
  }
1439
1746
  /** OPR.0.4.3.14 — read the surfaced manual-trigger state for a seat (AC-3). */
@@ -1450,6 +1757,7 @@ export class ClaudeCompactionEnforcer {
1450
1757
  */
1451
1758
  invalidateOccupant(sessionName) {
1452
1759
  this.stopPreparation(sessionName, "stale_generation");
1760
+ this.lastEnded.delete(sessionName);
1453
1761
  this.persistStage(sessionName, "ended");
1454
1762
  this.records.delete(sessionName);
1455
1763
  this.stranded.delete(sessionName);