@openrig/cli 0.7.10 → 0.7.12

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 (1131) hide show
  1. package/README.md +9 -6
  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/guidance/openrig-context-entry.md +8 -0
  6. package/daemon/assets/herdr-app/mods/rig-cell-header/main.js +15 -0
  7. package/daemon/assets/herdr-app/mods/rig-cell-header/mod.json +1 -0
  8. package/daemon/assets/herdr-app/mods/rig-ended/main.js +14 -0
  9. package/daemon/assets/herdr-app/mods/rig-ended/mod.json +1 -0
  10. package/daemon/assets/herdr-app/mods/rig-pad/main.js +10 -0
  11. package/daemon/assets/herdr-app/mods/rig-pad/mod.json +1 -0
  12. package/daemon/assets/herdr-app/mods/rig-strip/main.js +153 -0
  13. package/daemon/assets/herdr-app/mods/rig-strip/mod.json +1 -0
  14. package/daemon/assets/openshell/README.md +1 -1
  15. package/daemon/assets/pi-account-lock.cjs +39 -0
  16. package/daemon/assets/plugins/openrig/.claude-plugin/marketplace.json +15 -0
  17. package/daemon/assets/plugins/openrig/.claude-plugin/plugin.json +32 -0
  18. package/daemon/assets/plugins/openrig/.codex-plugin/plugin.json +39 -0
  19. package/daemon/assets/plugins/openrig/.cursor-plugin/plugin.json +6 -0
  20. package/daemon/assets/plugins/openrig/LICENSE +200 -0
  21. package/daemon/assets/plugins/openrig/README.md +106 -0
  22. package/daemon/assets/plugins/openrig/assets/logo.svg +1 -0
  23. package/daemon/assets/plugins/openrig/mcp.json +10 -0
  24. package/daemon/assets/plugins/openrig/plugin.json +14 -0
  25. package/daemon/assets/plugins/openrig/skills/working-with-an-openrig-team/SKILL.md +90 -0
  26. package/daemon/assets/plugins/openrig-core/.claude-plugin/plugin.json +1 -1
  27. package/daemon/assets/plugins/openrig-core/.codex-plugin/plugin.json +1 -1
  28. package/daemon/assets/plugins/openrig-core/hooks/scripts/activity-relay.cjs +35 -0
  29. package/daemon/assets/plugins/openrig-core/hooks/scripts/refocus-state.cjs +103 -0
  30. package/daemon/assets/plugins/openrig-core/hooks/scripts/refocus.cjs +177 -86
  31. package/daemon/assets/plugins/openrig-core/skills/agent-operated-software/SKILL.md +5 -1
  32. package/daemon/assets/plugins/openrig-core/skills/claude-compaction-restore/SKILL.md +3 -2
  33. package/daemon/assets/plugins/openrig-core/skills/openrig-skills/SKILL.md +1 -0
  34. package/daemon/assets/plugins/openrig-core/skills/openrig-user/SKILL.md +25 -9
  35. package/daemon/assets/plugins/openrig-core/skills/refocusing/SKILL.md +5 -0
  36. package/daemon/assets/plugins/openrig-core/skills/refocusing/scripts/trace-to-root.py +26 -4
  37. package/daemon/assets/plugins/openrig-core/skills/retiring-and-inheriting-a-seat/SKILL.md +1 -1
  38. package/daemon/assets/plugins/openrig-core/skills/seat-continuity-and-handover/SKILL.md +10 -6
  39. package/daemon/assets/plugins/openrig-core/skills/session-compaction-and-restore/SKILL.md +1 -1
  40. package/daemon/assets/skills/rigs/SKILL.md +37 -2
  41. package/daemon/context-packs/help/help.md +18 -0
  42. package/daemon/context-packs/help/manifest.yaml +1 -1
  43. package/daemon/context-packs/onboarding-width/manifest.yaml +1 -1
  44. package/daemon/context-packs/onboarding-width/public-what-you-can-do.md +104 -14
  45. package/daemon/context-packs/reference/acp-agents.md +68 -0
  46. package/daemon/context-packs/reference/getting-started.md +19 -3
  47. package/daemon/context-packs/reference/manifest.yaml +4 -1
  48. package/daemon/context-packs/reference/rig-spec.md +71 -8
  49. package/daemon/context-packs/reference/tmux-servers.md +214 -0
  50. package/daemon/context-packs/reference/whats-new.md +402 -132
  51. package/daemon/context-packs/skills/agent-operated-software/SKILL.md +5 -1
  52. package/daemon/context-packs/skills/agent-operated-software/manifest.yaml +1 -1
  53. package/daemon/context-packs/skills/agent-operated-workflows/manifest.yaml +1 -1
  54. package/daemon/context-packs/skills/applying-a-permission-policy/manifest.yaml +1 -1
  55. package/daemon/context-packs/skills/claude-compaction-restore/SKILL.md +3 -2
  56. package/daemon/context-packs/skills/claude-compaction-restore/manifest.yaml +1 -1
  57. package/daemon/context-packs/skills/core/agent-starters/manifest.yaml +1 -1
  58. package/daemon/context-packs/skills/core/agent-startup-and-context-ingestion/manifest.yaml +1 -1
  59. package/daemon/context-packs/skills/core/cross-host-rig-commands/SKILL.md +7 -0
  60. package/daemon/context-packs/skills/core/cross-host-rig-commands/manifest.yaml +1 -1
  61. package/daemon/context-packs/skills/core/human-in-the-loop/manifest.yaml +1 -1
  62. package/daemon/context-packs/skills/core/messaging-the-human/manifest.yaml +1 -1
  63. package/daemon/context-packs/skills/core/openrig-architect/manifest.yaml +1 -1
  64. package/daemon/context-packs/skills/core/openrig-cmux/manifest.yaml +1 -1
  65. package/daemon/context-packs/skills/core/openrig-herdr/SKILL.md +1 -0
  66. package/daemon/context-packs/skills/core/openrig-herdr/manifest.yaml +1 -1
  67. package/daemon/context-packs/skills/core/openrig-skills/SKILL.md +1 -0
  68. package/daemon/context-packs/skills/core/openrig-skills/manifest.yaml +1 -1
  69. package/daemon/context-packs/skills/core/openrig-software-factory/manifest.yaml +1 -1
  70. package/daemon/context-packs/skills/core/openrig-upgrade/manifest.yaml +1 -1
  71. package/daemon/context-packs/skills/core/rig-bundles-and-shareable-artifacts/manifest.yaml +1 -1
  72. package/daemon/context-packs/skills/core/rig-lifecycle/manifest.yaml +1 -1
  73. package/daemon/context-packs/skills/core/session-source-fork/manifest.yaml +1 -1
  74. package/daemon/context-packs/skills/core/specification-system/manifest.yaml +1 -1
  75. package/daemon/context-packs/skills/core/topology-mutation-and-seat-management/manifest.yaml +1 -1
  76. package/daemon/context-packs/skills/core/watchdog/manifest.yaml +1 -1
  77. package/daemon/context-packs/skills/core/working-with-an-openrig-team/SKILL.md +90 -0
  78. package/daemon/context-packs/skills/core/working-with-an-openrig-team/manifest.yaml +10 -0
  79. package/daemon/context-packs/skills/delegating-work/manifest.yaml +1 -1
  80. package/daemon/context-packs/skills/forming-an-openrig-mental-model/manifest.yaml +1 -1
  81. package/daemon/context-packs/skills/loading-addressable-markdown/manifest.yaml +1 -1
  82. package/daemon/context-packs/skills/mission-slice-sop/manifest.yaml +1 -1
  83. package/daemon/context-packs/skills/openrig-operating-model/manifest.yaml +1 -1
  84. package/daemon/context-packs/skills/openrig-user/SKILL.md +25 -9
  85. package/daemon/context-packs/skills/openrig-user/manifest.yaml +1 -1
  86. package/daemon/context-packs/skills/orienting-to-an-inherited-seat/manifest.yaml +1 -1
  87. package/daemon/context-packs/skills/pm/backlog-capture/manifest.yaml +1 -1
  88. package/daemon/context-packs/skills/pm/context-builder/manifest.yaml +1 -1
  89. package/daemon/context-packs/skills/pm/exec-summary/manifest.yaml +1 -1
  90. package/daemon/context-packs/skills/pm/office-hours/manifest.yaml +1 -1
  91. package/daemon/context-packs/skills/pm/plan-review/manifest.yaml +1 -1
  92. package/daemon/context-packs/skills/pm/requirements-writer/manifest.yaml +1 -1
  93. package/daemon/context-packs/skills/pm/ui-mockup/manifest.yaml +1 -1
  94. package/daemon/context-packs/skills/pods/development-team/manifest.yaml +1 -1
  95. package/daemon/context-packs/skills/pods/orchestration-team/manifest.yaml +1 -1
  96. package/daemon/context-packs/skills/pods/oversight-team/manifest.yaml +1 -1
  97. package/daemon/context-packs/skills/pods/review-team/SKILL.md +2 -0
  98. package/daemon/context-packs/skills/pods/review-team/manifest.yaml +1 -1
  99. package/daemon/context-packs/skills/process/agent-browser/manifest.yaml +1 -1
  100. package/daemon/context-packs/skills/process/context-engineering/manifest.yaml +1 -1
  101. package/daemon/context-packs/skills/process/dogfood/manifest.yaml +1 -1
  102. package/daemon/context-packs/skills/process/frontend-design/manifest.yaml +1 -1
  103. package/daemon/context-packs/skills/process/systematic-debugging/manifest.yaml +1 -1
  104. package/daemon/context-packs/skills/process/test-driven-development/manifest.yaml +1 -1
  105. package/daemon/context-packs/skills/process/verification-before-completion/manifest.yaml +1 -1
  106. package/daemon/context-packs/skills/queue-handoff/manifest.yaml +1 -1
  107. package/daemon/context-packs/skills/refocusing/SKILL.md +5 -0
  108. package/daemon/context-packs/skills/refocusing/manifest.yaml +1 -1
  109. package/daemon/context-packs/skills/refocusing/scripts/trace-to-root.py +26 -4
  110. package/daemon/context-packs/skills/retiring-and-inheriting-a-seat/SKILL.md +1 -1
  111. package/daemon/context-packs/skills/retiring-and-inheriting-a-seat/manifest.yaml +1 -1
  112. package/daemon/context-packs/skills/seat-continuity-and-handover/SKILL.md +10 -6
  113. package/daemon/context-packs/skills/seat-continuity-and-handover/manifest.yaml +1 -1
  114. package/daemon/context-packs/skills/session-compaction-and-restore/SKILL.md +1 -1
  115. package/daemon/context-packs/skills/session-compaction-and-restore/manifest.yaml +1 -1
  116. package/daemon/context-packs/skills/software-for-agents/manifest.yaml +1 -1
  117. package/daemon/context-packs/world-example/manifest.yaml +1 -1
  118. package/daemon/context-packs/world-public/manifest.yaml +1 -1
  119. package/daemon/dist/adapters/claude-code-adapter.d.ts +3 -1
  120. package/daemon/dist/adapters/claude-code-adapter.d.ts.map +1 -1
  121. package/daemon/dist/adapters/claude-code-adapter.js +59 -15
  122. package/daemon/dist/adapters/claude-code-adapter.js.map +1 -1
  123. package/daemon/dist/adapters/claude-resume.d.ts +2 -1
  124. package/daemon/dist/adapters/claude-resume.d.ts.map +1 -1
  125. package/daemon/dist/adapters/claude-resume.js +28 -6
  126. package/daemon/dist/adapters/claude-resume.js.map +1 -1
  127. package/daemon/dist/adapters/codex-resume.d.ts +1 -1
  128. package/daemon/dist/adapters/codex-resume.d.ts.map +1 -1
  129. package/daemon/dist/adapters/codex-resume.js +6 -2
  130. package/daemon/dist/adapters/codex-resume.js.map +1 -1
  131. package/daemon/dist/adapters/codex-runtime-adapter.d.ts +2 -0
  132. package/daemon/dist/adapters/codex-runtime-adapter.d.ts.map +1 -1
  133. package/daemon/dist/adapters/codex-runtime-adapter.js +54 -13
  134. package/daemon/dist/adapters/codex-runtime-adapter.js.map +1 -1
  135. package/daemon/dist/adapters/community-harness-runtime-adapter.d.ts +10 -6
  136. package/daemon/dist/adapters/community-harness-runtime-adapter.d.ts.map +1 -1
  137. package/daemon/dist/adapters/community-harness-runtime-adapter.js +78 -24
  138. package/daemon/dist/adapters/community-harness-runtime-adapter.js.map +1 -1
  139. package/daemon/dist/adapters/kernel-authority.d.ts +2 -4
  140. package/daemon/dist/adapters/kernel-authority.d.ts.map +1 -1
  141. package/daemon/dist/adapters/kernel-authority.js +10 -41
  142. package/daemon/dist/adapters/kernel-authority.js.map +1 -1
  143. package/daemon/dist/adapters/openshell-podman-observer.d.ts.map +1 -1
  144. package/daemon/dist/adapters/openshell-podman-observer.js +5 -3
  145. package/daemon/dist/adapters/openshell-podman-observer.js.map +1 -1
  146. package/daemon/dist/adapters/pi-community-runtime-adapter.d.ts +27 -0
  147. package/daemon/dist/adapters/pi-community-runtime-adapter.d.ts.map +1 -0
  148. package/daemon/dist/adapters/pi-community-runtime-adapter.js +38 -0
  149. package/daemon/dist/adapters/pi-community-runtime-adapter.js.map +1 -0
  150. package/daemon/dist/adapters/pi-resume.d.ts +4 -1
  151. package/daemon/dist/adapters/pi-resume.d.ts.map +1 -1
  152. package/daemon/dist/adapters/pi-resume.js +38 -9
  153. package/daemon/dist/adapters/pi-resume.js.map +1 -1
  154. package/daemon/dist/adapters/pi-runner-protocol.d.ts +9 -3
  155. package/daemon/dist/adapters/pi-runner-protocol.d.ts.map +1 -1
  156. package/daemon/dist/adapters/pi-runner-protocol.js +13 -1
  157. package/daemon/dist/adapters/pi-runner-protocol.js.map +1 -1
  158. package/daemon/dist/adapters/pi-runner.d.ts +14 -4
  159. package/daemon/dist/adapters/pi-runner.d.ts.map +1 -1
  160. package/daemon/dist/adapters/pi-runner.js +174 -29
  161. package/daemon/dist/adapters/pi-runner.js.map +1 -1
  162. package/daemon/dist/adapters/pi-runtime-adapter.d.ts +37 -14
  163. package/daemon/dist/adapters/pi-runtime-adapter.d.ts.map +1 -1
  164. package/daemon/dist/adapters/pi-runtime-adapter.js +97 -31
  165. package/daemon/dist/adapters/pi-runtime-adapter.js.map +1 -1
  166. package/daemon/dist/adapters/tmux-control.d.ts +32 -1
  167. package/daemon/dist/adapters/tmux-control.d.ts.map +1 -1
  168. package/daemon/dist/adapters/tmux-control.js +149 -9
  169. package/daemon/dist/adapters/tmux-control.js.map +1 -1
  170. package/daemon/dist/adapters/tmux-exec.d.ts.map +1 -1
  171. package/daemon/dist/adapters/tmux-exec.js +13 -4
  172. package/daemon/dist/adapters/tmux-exec.js.map +1 -1
  173. package/daemon/dist/adapters/tmux-server.d.ts +11 -0
  174. package/daemon/dist/adapters/tmux-server.d.ts.map +1 -1
  175. package/daemon/dist/adapters/tmux-server.js +13 -1
  176. package/daemon/dist/adapters/tmux-server.js.map +1 -1
  177. package/daemon/dist/adapters/tmux.d.ts +32 -1
  178. package/daemon/dist/adapters/tmux.d.ts.map +1 -1
  179. package/daemon/dist/adapters/tmux.js +241 -27
  180. package/daemon/dist/adapters/tmux.js.map +1 -1
  181. package/daemon/dist/attention-surface.d.ts +7 -0
  182. package/daemon/dist/attention-surface.d.ts.map +1 -1
  183. package/daemon/dist/attention-surface.js.map +1 -1
  184. package/daemon/dist/build-info.js +3 -3
  185. package/daemon/dist/db/all-migrations.d.ts.map +1 -1
  186. package/daemon/dist/db/all-migrations.js +20 -0
  187. package/daemon/dist/db/all-migrations.js.map +1 -1
  188. package/daemon/dist/db/migrations/150_node_launch_wrapper.d.ts +3 -0
  189. package/daemon/dist/db/migrations/150_node_launch_wrapper.d.ts.map +1 -0
  190. package/daemon/dist/db/migrations/150_node_launch_wrapper.js +5 -0
  191. package/daemon/dist/db/migrations/150_node_launch_wrapper.js.map +1 -0
  192. package/daemon/dist/db/migrations/151_pi_account_switches.d.ts +4 -0
  193. package/daemon/dist/db/migrations/151_pi_account_switches.d.ts.map +1 -0
  194. package/daemon/dist/db/migrations/151_pi_account_switches.js +44 -0
  195. package/daemon/dist/db/migrations/151_pi_account_switches.js.map +1 -0
  196. package/daemon/dist/db/migrations/152_workflow_instance_spec.d.ts +8 -0
  197. package/daemon/dist/db/migrations/152_workflow_instance_spec.d.ts.map +1 -0
  198. package/daemon/dist/db/migrations/152_workflow_instance_spec.js +13 -0
  199. package/daemon/dist/db/migrations/152_workflow_instance_spec.js.map +1 -0
  200. package/daemon/dist/db/migrations/153_events_retention_marks.d.ts +7 -0
  201. package/daemon/dist/db/migrations/153_events_retention_marks.d.ts.map +1 -0
  202. package/daemon/dist/db/migrations/153_events_retention_marks.js +17 -0
  203. package/daemon/dist/db/migrations/153_events_retention_marks.js.map +1 -0
  204. package/daemon/dist/db/migrations/154_workflow_instance_root_objective.d.ts +7 -0
  205. package/daemon/dist/db/migrations/154_workflow_instance_root_objective.d.ts.map +1 -0
  206. package/daemon/dist/db/migrations/154_workflow_instance_root_objective.js +11 -0
  207. package/daemon/dist/db/migrations/154_workflow_instance_root_objective.js.map +1 -0
  208. package/daemon/dist/db/migrations/155_queue_erasure.d.ts +12 -0
  209. package/daemon/dist/db/migrations/155_queue_erasure.d.ts.map +1 -0
  210. package/daemon/dist/db/migrations/155_queue_erasure.js +28 -0
  211. package/daemon/dist/db/migrations/155_queue_erasure.js.map +1 -0
  212. package/daemon/dist/db/migrations/156_queue_erasure_link_indexes.d.ts +4 -0
  213. package/daemon/dist/db/migrations/156_queue_erasure_link_indexes.d.ts.map +1 -0
  214. package/daemon/dist/db/migrations/156_queue_erasure_link_indexes.js +14 -0
  215. package/daemon/dist/db/migrations/156_queue_erasure_link_indexes.js.map +1 -0
  216. package/daemon/dist/db/migrations/157_queue_erasure_batches.d.ts +9 -0
  217. package/daemon/dist/db/migrations/157_queue_erasure_batches.d.ts.map +1 -0
  218. package/daemon/dist/db/migrations/157_queue_erasure_batches.js +18 -0
  219. package/daemon/dist/db/migrations/157_queue_erasure_batches.js.map +1 -0
  220. package/daemon/dist/db/migrations/158_queue_inbox_checkins.d.ts +8 -0
  221. package/daemon/dist/db/migrations/158_queue_inbox_checkins.d.ts.map +1 -0
  222. package/daemon/dist/db/migrations/158_queue_inbox_checkins.js +15 -0
  223. package/daemon/dist/db/migrations/158_queue_inbox_checkins.js.map +1 -0
  224. package/daemon/dist/db/migrations/159_queue_items_handed_off_from_index.d.ts +5 -0
  225. package/daemon/dist/db/migrations/159_queue_items_handed_off_from_index.d.ts.map +1 -0
  226. package/daemon/dist/db/migrations/159_queue_items_handed_off_from_index.js +9 -0
  227. package/daemon/dist/db/migrations/159_queue_items_handed_off_from_index.js.map +1 -0
  228. package/daemon/dist/domain/activity-taxonomy.d.ts +9 -0
  229. package/daemon/dist/domain/activity-taxonomy.d.ts.map +1 -1
  230. package/daemon/dist/domain/activity-taxonomy.js.map +1 -1
  231. package/daemon/dist/domain/agent-activity-store.d.ts +4 -2
  232. package/daemon/dist/domain/agent-activity-store.d.ts.map +1 -1
  233. package/daemon/dist/domain/agent-activity-store.js +11 -7
  234. package/daemon/dist/domain/agent-activity-store.js.map +1 -1
  235. package/daemon/dist/domain/agent-manifest.d.ts.map +1 -1
  236. package/daemon/dist/domain/agent-manifest.js +11 -1
  237. package/daemon/dist/domain/agent-manifest.js.map +1 -1
  238. package/daemon/dist/domain/builtin-startup-files.d.ts +8 -0
  239. package/daemon/dist/domain/builtin-startup-files.d.ts.map +1 -1
  240. package/daemon/dist/domain/builtin-startup-files.js +37 -11
  241. package/daemon/dist/domain/builtin-startup-files.js.map +1 -1
  242. package/daemon/dist/domain/claude-compaction-enforcer.d.ts +73 -20
  243. package/daemon/dist/domain/claude-compaction-enforcer.d.ts.map +1 -1
  244. package/daemon/dist/domain/claude-compaction-enforcer.js +442 -84
  245. package/daemon/dist/domain/claude-compaction-enforcer.js.map +1 -1
  246. package/daemon/dist/domain/claude-continuation-launch.d.ts +16 -0
  247. package/daemon/dist/domain/claude-continuation-launch.d.ts.map +1 -0
  248. package/daemon/dist/domain/claude-continuation-launch.js +110 -0
  249. package/daemon/dist/domain/claude-continuation-launch.js.map +1 -0
  250. package/daemon/dist/domain/claude-git-trust-root.d.ts +11 -0
  251. package/daemon/dist/domain/claude-git-trust-root.d.ts.map +1 -0
  252. package/daemon/dist/domain/claude-git-trust-root.js +72 -0
  253. package/daemon/dist/domain/claude-git-trust-root.js.map +1 -0
  254. package/daemon/dist/domain/claude-managed-launch.d.ts +3 -0
  255. package/daemon/dist/domain/claude-managed-launch.d.ts.map +1 -1
  256. package/daemon/dist/domain/claude-managed-launch.js +17 -7
  257. package/daemon/dist/domain/claude-managed-launch.js.map +1 -1
  258. package/daemon/dist/domain/community-harness-presets.d.ts +5 -0
  259. package/daemon/dist/domain/community-harness-presets.d.ts.map +1 -1
  260. package/daemon/dist/domain/community-harness-presets.js +33 -6
  261. package/daemon/dist/domain/community-harness-presets.js.map +1 -1
  262. package/daemon/dist/domain/compaction-restore-notice.d.ts +3 -1
  263. package/daemon/dist/domain/compaction-restore-notice.d.ts.map +1 -1
  264. package/daemon/dist/domain/compaction-restore-notice.js +37 -6
  265. package/daemon/dist/domain/compaction-restore-notice.js.map +1 -1
  266. package/daemon/dist/domain/context-monitor.d.ts.map +1 -1
  267. package/daemon/dist/domain/context-monitor.js +3 -0
  268. package/daemon/dist/domain/context-monitor.js.map +1 -1
  269. package/daemon/dist/domain/context-usage-store.d.ts.map +1 -1
  270. package/daemon/dist/domain/context-usage-store.js +10 -1
  271. package/daemon/dist/domain/context-usage-store.js.map +1 -1
  272. package/daemon/dist/domain/current-work.d.ts +52 -0
  273. package/daemon/dist/domain/current-work.d.ts.map +1 -1
  274. package/daemon/dist/domain/current-work.js +215 -0
  275. package/daemon/dist/domain/current-work.js.map +1 -1
  276. package/daemon/dist/domain/default-receiver.d.ts +40 -0
  277. package/daemon/dist/domain/default-receiver.d.ts.map +1 -0
  278. package/daemon/dist/domain/default-receiver.js +70 -0
  279. package/daemon/dist/domain/default-receiver.js.map +1 -0
  280. package/daemon/dist/domain/desired-claude-activity-hooks.d.ts +4 -3
  281. package/daemon/dist/domain/desired-claude-activity-hooks.d.ts.map +1 -1
  282. package/daemon/dist/domain/desired-claude-activity-hooks.js +49 -15
  283. package/daemon/dist/domain/desired-claude-activity-hooks.js.map +1 -1
  284. package/daemon/dist/domain/draft-aware-delivery.d.ts.map +1 -1
  285. package/daemon/dist/domain/draft-aware-delivery.js +6 -2
  286. package/daemon/dist/domain/draft-aware-delivery.js.map +1 -1
  287. package/daemon/dist/domain/escalation-owner.d.ts.map +1 -1
  288. package/daemon/dist/domain/escalation-owner.js +8 -3
  289. package/daemon/dist/domain/escalation-owner.js.map +1 -1
  290. package/daemon/dist/domain/event-bus.d.ts +47 -8
  291. package/daemon/dist/domain/event-bus.d.ts.map +1 -1
  292. package/daemon/dist/domain/event-bus.js +137 -17
  293. package/daemon/dist/domain/event-bus.js.map +1 -1
  294. package/daemon/dist/domain/execution-view.d.ts +9 -0
  295. package/daemon/dist/domain/execution-view.d.ts.map +1 -1
  296. package/daemon/dist/domain/execution-view.js +41 -3
  297. package/daemon/dist/domain/execution-view.js.map +1 -1
  298. package/daemon/dist/domain/gateway/connections-projection.d.ts +13 -1
  299. package/daemon/dist/domain/gateway/connections-projection.d.ts.map +1 -1
  300. package/daemon/dist/domain/gateway/connections-projection.js +38 -10
  301. package/daemon/dist/domain/gateway/connections-projection.js.map +1 -1
  302. package/daemon/dist/domain/gateway/dispatcher.d.ts +2 -0
  303. package/daemon/dist/domain/gateway/dispatcher.d.ts.map +1 -1
  304. package/daemon/dist/domain/gateway/dispatcher.js +14 -1
  305. package/daemon/dist/domain/gateway/dispatcher.js.map +1 -1
  306. package/daemon/dist/domain/gateway/gateway-subsystem.d.ts +5 -0
  307. package/daemon/dist/domain/gateway/gateway-subsystem.d.ts.map +1 -1
  308. package/daemon/dist/domain/gateway/gateway-subsystem.js +10 -0
  309. package/daemon/dist/domain/gateway/gateway-subsystem.js.map +1 -1
  310. package/daemon/dist/domain/gateway/human-quiet-windows.d.ts +2 -1
  311. package/daemon/dist/domain/gateway/human-quiet-windows.d.ts.map +1 -1
  312. package/daemon/dist/domain/gateway/human-quiet-windows.js +2 -1
  313. package/daemon/dist/domain/gateway/human-quiet-windows.js.map +1 -1
  314. package/daemon/dist/domain/gateway/human-readiness.d.ts +7 -0
  315. package/daemon/dist/domain/gateway/human-readiness.d.ts.map +1 -1
  316. package/daemon/dist/domain/gateway/human-readiness.js +45 -0
  317. package/daemon/dist/domain/gateway/human-readiness.js.map +1 -1
  318. package/daemon/dist/domain/gateway/human-registry.d.ts +35 -4
  319. package/daemon/dist/domain/gateway/human-registry.d.ts.map +1 -1
  320. package/daemon/dist/domain/gateway/human-registry.js +130 -42
  321. package/daemon/dist/domain/gateway/human-registry.js.map +1 -1
  322. package/daemon/dist/domain/gateway/operator-delivery-engine.d.ts.map +1 -1
  323. package/daemon/dist/domain/gateway/operator-delivery-engine.js +8 -2
  324. package/daemon/dist/domain/gateway/operator-delivery-engine.js.map +1 -1
  325. package/daemon/dist/domain/gateway/relay-config.d.ts +83 -0
  326. package/daemon/dist/domain/gateway/relay-config.d.ts.map +1 -0
  327. package/daemon/dist/domain/gateway/relay-config.js +321 -0
  328. package/daemon/dist/domain/gateway/relay-config.js.map +1 -0
  329. package/daemon/dist/domain/gateway/relay-inbound.d.ts +85 -0
  330. package/daemon/dist/domain/gateway/relay-inbound.d.ts.map +1 -0
  331. package/daemon/dist/domain/gateway/relay-inbound.js +981 -0
  332. package/daemon/dist/domain/gateway/relay-inbound.js.map +1 -0
  333. package/daemon/dist/domain/gateway/relay-outbound.d.ts +218 -0
  334. package/daemon/dist/domain/gateway/relay-outbound.d.ts.map +1 -0
  335. package/daemon/dist/domain/gateway/relay-outbound.js +801 -0
  336. package/daemon/dist/domain/gateway/relay-outbound.js.map +1 -0
  337. package/daemon/dist/domain/gateway/slack/config.d.ts +21 -0
  338. package/daemon/dist/domain/gateway/slack/config.d.ts.map +1 -1
  339. package/daemon/dist/domain/gateway/slack/config.js +30 -3
  340. package/daemon/dist/domain/gateway/slack/config.js.map +1 -1
  341. package/daemon/dist/domain/gateway/slack/message.d.ts +4 -0
  342. package/daemon/dist/domain/gateway/slack/message.d.ts.map +1 -1
  343. package/daemon/dist/domain/gateway/slack/message.js +7 -2
  344. package/daemon/dist/domain/gateway/slack/message.js.map +1 -1
  345. package/daemon/dist/domain/gateway/slack/open-asks.d.ts +13 -1
  346. package/daemon/dist/domain/gateway/slack/open-asks.d.ts.map +1 -1
  347. package/daemon/dist/domain/gateway/slack/open-asks.js +72 -8
  348. package/daemon/dist/domain/gateway/slack/open-asks.js.map +1 -1
  349. package/daemon/dist/domain/gateway/slack/outbound-driver.d.ts +9 -0
  350. package/daemon/dist/domain/gateway/slack/outbound-driver.d.ts.map +1 -1
  351. package/daemon/dist/domain/gateway/slack/outbound-driver.js.map +1 -1
  352. package/daemon/dist/domain/gateway/slack/settled-asks.d.ts.map +1 -1
  353. package/daemon/dist/domain/gateway/slack/settled-asks.js +19 -1
  354. package/daemon/dist/domain/gateway/slack/settled-asks.js.map +1 -1
  355. package/daemon/dist/domain/gateway/slack/slack-api.d.ts +3 -0
  356. package/daemon/dist/domain/gateway/slack/slack-api.d.ts.map +1 -1
  357. package/daemon/dist/domain/gateway/slack/slack-api.js +12 -4
  358. package/daemon/dist/domain/gateway/slack/slack-api.js.map +1 -1
  359. package/daemon/dist/domain/gateway/slack/slack-delivery.d.ts +2 -0
  360. package/daemon/dist/domain/gateway/slack/slack-delivery.d.ts.map +1 -1
  361. package/daemon/dist/domain/gateway/slack/slack-delivery.js +38 -12
  362. package/daemon/dist/domain/gateway/slack/slack-delivery.js.map +1 -1
  363. package/daemon/dist/domain/gateway/slack/slack-recovery.d.ts +12 -1
  364. package/daemon/dist/domain/gateway/slack/slack-recovery.d.ts.map +1 -1
  365. package/daemon/dist/domain/gateway/slack/slack-recovery.js +68 -10
  366. package/daemon/dist/domain/gateway/slack/slack-recovery.js.map +1 -1
  367. package/daemon/dist/domain/gateway/slack/slack-subsystem.d.ts.map +1 -1
  368. package/daemon/dist/domain/gateway/slack/slack-subsystem.js +363 -67
  369. package/daemon/dist/domain/gateway/slack/slack-subsystem.js.map +1 -1
  370. package/daemon/dist/domain/gateway/slack/socket-inbound.d.ts +1 -0
  371. package/daemon/dist/domain/gateway/slack/socket-inbound.d.ts.map +1 -1
  372. package/daemon/dist/domain/gateway/slack/socket-inbound.js +5 -0
  373. package/daemon/dist/domain/gateway/slack/socket-inbound.js.map +1 -1
  374. package/daemon/dist/domain/gateway/slack/state-store.d.ts +4 -0
  375. package/daemon/dist/domain/gateway/slack/state-store.d.ts.map +1 -1
  376. package/daemon/dist/domain/gateway/slack/state-store.js +4 -1
  377. package/daemon/dist/domain/gateway/slack/state-store.js.map +1 -1
  378. package/daemon/dist/domain/gateway/slack/thread-recovery.d.ts +23 -3
  379. package/daemon/dist/domain/gateway/slack/thread-recovery.d.ts.map +1 -1
  380. package/daemon/dist/domain/gateway/slack/thread-recovery.js +52 -10
  381. package/daemon/dist/domain/gateway/slack/thread-recovery.js.map +1 -1
  382. package/daemon/dist/domain/gateway/slack/thread-seat-map.d.ts +4 -1
  383. package/daemon/dist/domain/gateway/slack/thread-seat-map.d.ts.map +1 -1
  384. package/daemon/dist/domain/gateway/slack/thread-seat-map.js +7 -4
  385. package/daemon/dist/domain/gateway/slack/thread-seat-map.js.map +1 -1
  386. package/daemon/dist/domain/guidance-projection.d.ts +39 -0
  387. package/daemon/dist/domain/guidance-projection.d.ts.map +1 -0
  388. package/daemon/dist/domain/guidance-projection.js +91 -0
  389. package/daemon/dist/domain/guidance-projection.js.map +1 -0
  390. package/daemon/dist/domain/health-passive-ceremony.d.ts.map +1 -1
  391. package/daemon/dist/domain/health-passive-ceremony.js +31 -12
  392. package/daemon/dist/domain/health-passive-ceremony.js.map +1 -1
  393. package/daemon/dist/domain/hosted-wake.d.ts +5 -1
  394. package/daemon/dist/domain/hosted-wake.d.ts.map +1 -1
  395. package/daemon/dist/domain/hosted-wake.js +13 -3
  396. package/daemon/dist/domain/hosted-wake.js.map +1 -1
  397. package/daemon/dist/domain/hosts/pairing-ask.d.ts +10 -0
  398. package/daemon/dist/domain/hosts/pairing-ask.d.ts.map +1 -0
  399. package/daemon/dist/domain/hosts/pairing-ask.js +9 -0
  400. package/daemon/dist/domain/hosts/pairing-ask.js.map +1 -0
  401. package/daemon/dist/domain/launch-wrapper.d.ts +29 -0
  402. package/daemon/dist/domain/launch-wrapper.d.ts.map +1 -0
  403. package/daemon/dist/domain/launch-wrapper.js +97 -0
  404. package/daemon/dist/domain/launch-wrapper.js.map +1 -0
  405. package/daemon/dist/domain/managed-blocks.d.ts +3 -0
  406. package/daemon/dist/domain/managed-blocks.d.ts.map +1 -1
  407. package/daemon/dist/domain/managed-blocks.js +5 -0
  408. package/daemon/dist/domain/managed-blocks.js.map +1 -1
  409. package/daemon/dist/domain/markdown-address.d.ts.map +1 -1
  410. package/daemon/dist/domain/markdown-address.js +12 -1
  411. package/daemon/dist/domain/markdown-address.js.map +1 -1
  412. package/daemon/dist/domain/mission-control/mission-control-write-contract.d.ts +1 -1
  413. package/daemon/dist/domain/mission-control/mission-control-write-contract.d.ts.map +1 -1
  414. package/daemon/dist/domain/mission-control/mission-control-write-contract.js +116 -28
  415. package/daemon/dist/domain/mission-control/mission-control-write-contract.js.map +1 -1
  416. package/daemon/dist/domain/model-divergence/current-model-reader.d.ts.map +1 -1
  417. package/daemon/dist/domain/model-divergence/current-model-reader.js +14 -3
  418. package/daemon/dist/domain/model-divergence/current-model-reader.js.map +1 -1
  419. package/daemon/dist/domain/native-process-arguments.d.ts +5 -0
  420. package/daemon/dist/domain/native-process-arguments.d.ts.map +1 -1
  421. package/daemon/dist/domain/native-process-arguments.js +60 -5
  422. package/daemon/dist/domain/native-process-arguments.js.map +1 -1
  423. package/daemon/dist/domain/native-process-lineage.d.ts.map +1 -1
  424. package/daemon/dist/domain/native-process-lineage.js +32 -9
  425. package/daemon/dist/domain/native-process-lineage.js.map +1 -1
  426. package/daemon/dist/domain/node-inventory.d.ts.map +1 -1
  427. package/daemon/dist/domain/node-inventory.js +9 -2
  428. package/daemon/dist/domain/node-inventory.js.map +1 -1
  429. package/daemon/dist/domain/node-launcher.d.ts.map +1 -1
  430. package/daemon/dist/domain/node-launcher.js +9 -2
  431. package/daemon/dist/domain/node-launcher.js.map +1 -1
  432. package/daemon/dist/domain/outbox-handler.d.ts +53 -3
  433. package/daemon/dist/domain/outbox-handler.d.ts.map +1 -1
  434. package/daemon/dist/domain/outbox-handler.js +101 -6
  435. package/daemon/dist/domain/outbox-handler.js.map +1 -1
  436. package/daemon/dist/domain/package-manifest.d.ts.map +1 -1
  437. package/daemon/dist/domain/package-manifest.js +10 -5
  438. package/daemon/dist/domain/package-manifest.js.map +1 -1
  439. package/daemon/dist/domain/parent-session-env.d.ts +2 -1
  440. package/daemon/dist/domain/parent-session-env.d.ts.map +1 -1
  441. package/daemon/dist/domain/parent-session-env.js +9 -1
  442. package/daemon/dist/domain/parent-session-env.js.map +1 -1
  443. package/daemon/dist/domain/parked-query.d.ts +6 -0
  444. package/daemon/dist/domain/parked-query.d.ts.map +1 -1
  445. package/daemon/dist/domain/parked-query.js +1 -0
  446. package/daemon/dist/domain/parked-query.js.map +1 -1
  447. package/daemon/dist/domain/pi-account-state.d.ts +6 -0
  448. package/daemon/dist/domain/pi-account-state.d.ts.map +1 -0
  449. package/daemon/dist/domain/pi-account-state.js +14 -0
  450. package/daemon/dist/domain/pi-account-state.js.map +1 -0
  451. package/daemon/dist/domain/policies/delivery-digest-flush.d.ts.map +1 -1
  452. package/daemon/dist/domain/policies/delivery-digest-flush.js +9 -1
  453. package/daemon/dist/domain/policies/delivery-digest-flush.js.map +1 -1
  454. package/daemon/dist/domain/policies/mode-scheduled-end.d.ts +4 -1
  455. package/daemon/dist/domain/policies/mode-scheduled-end.d.ts.map +1 -1
  456. package/daemon/dist/domain/policies/mode-scheduled-end.js +19 -10
  457. package/daemon/dist/domain/policies/mode-scheduled-end.js.map +1 -1
  458. package/daemon/dist/domain/policies/parked-owner-consumer.d.ts +6 -0
  459. package/daemon/dist/domain/policies/parked-owner-consumer.d.ts.map +1 -1
  460. package/daemon/dist/domain/policies/parked-owner-consumer.js +13 -3
  461. package/daemon/dist/domain/policies/parked-owner-consumer.js.map +1 -1
  462. package/daemon/dist/domain/policies/quiet-release.d.ts +19 -6
  463. package/daemon/dist/domain/policies/quiet-release.d.ts.map +1 -1
  464. package/daemon/dist/domain/policies/quiet-release.js +50 -10
  465. package/daemon/dist/domain/policies/quiet-release.js.map +1 -1
  466. package/daemon/dist/domain/projection-planner.d.ts +4 -1
  467. package/daemon/dist/domain/projection-planner.d.ts.map +1 -1
  468. package/daemon/dist/domain/projection-planner.js +3 -0
  469. package/daemon/dist/domain/projection-planner.js.map +1 -1
  470. package/daemon/dist/domain/proof/judgments.d.ts +11 -0
  471. package/daemon/dist/domain/proof/judgments.d.ts.map +1 -1
  472. package/daemon/dist/domain/proof/judgments.js +61 -38
  473. package/daemon/dist/domain/proof/judgments.js.map +1 -1
  474. package/daemon/dist/domain/queue-blocker.d.ts +5 -0
  475. package/daemon/dist/domain/queue-blocker.d.ts.map +1 -0
  476. package/daemon/dist/domain/queue-blocker.js +12 -0
  477. package/daemon/dist/domain/queue-blocker.js.map +1 -0
  478. package/daemon/dist/domain/queue-erasure.d.ts +173 -0
  479. package/daemon/dist/domain/queue-erasure.d.ts.map +1 -0
  480. package/daemon/dist/domain/queue-erasure.js +885 -0
  481. package/daemon/dist/domain/queue-erasure.js.map +1 -0
  482. package/daemon/dist/domain/queue-owner.d.ts +6 -0
  483. package/daemon/dist/domain/queue-owner.d.ts.map +1 -1
  484. package/daemon/dist/domain/queue-owner.js +13 -4
  485. package/daemon/dist/domain/queue-owner.js.map +1 -1
  486. package/daemon/dist/domain/queue-pickup.d.ts +20 -1
  487. package/daemon/dist/domain/queue-pickup.d.ts.map +1 -1
  488. package/daemon/dist/domain/queue-pickup.js +38 -6
  489. package/daemon/dist/domain/queue-pickup.js.map +1 -1
  490. package/daemon/dist/domain/queue-recovery.d.ts +14 -0
  491. package/daemon/dist/domain/queue-recovery.d.ts.map +1 -1
  492. package/daemon/dist/domain/queue-recovery.js +33 -1
  493. package/daemon/dist/domain/queue-recovery.js.map +1 -1
  494. package/daemon/dist/domain/queue-repository.d.ts +226 -20
  495. package/daemon/dist/domain/queue-repository.d.ts.map +1 -1
  496. package/daemon/dist/domain/queue-repository.js +786 -91
  497. package/daemon/dist/domain/queue-repository.js.map +1 -1
  498. package/daemon/dist/domain/queue-retention.d.ts +82 -0
  499. package/daemon/dist/domain/queue-retention.d.ts.map +1 -1
  500. package/daemon/dist/domain/queue-retention.js +168 -0
  501. package/daemon/dist/domain/queue-retention.js.map +1 -1
  502. package/daemon/dist/domain/queue-stuck-sweep.d.ts +38 -4
  503. package/daemon/dist/domain/queue-stuck-sweep.d.ts.map +1 -1
  504. package/daemon/dist/domain/queue-stuck-sweep.js +763 -190
  505. package/daemon/dist/domain/queue-stuck-sweep.js.map +1 -1
  506. package/daemon/dist/domain/queue-transition-log.d.ts +52 -1
  507. package/daemon/dist/domain/queue-transition-log.d.ts.map +1 -1
  508. package/daemon/dist/domain/queue-transition-log.js +241 -3
  509. package/daemon/dist/domain/queue-transition-log.js.map +1 -1
  510. package/daemon/dist/domain/queue-waiting.d.ts +49 -3
  511. package/daemon/dist/domain/queue-waiting.d.ts.map +1 -1
  512. package/daemon/dist/domain/queue-waiting.js +73 -13
  513. package/daemon/dist/domain/queue-waiting.js.map +1 -1
  514. package/daemon/dist/domain/queue-wake-ladder.d.ts.map +1 -1
  515. package/daemon/dist/domain/queue-wake-ladder.js +86 -30
  516. package/daemon/dist/domain/queue-wake-ladder.js.map +1 -1
  517. package/daemon/dist/domain/quiet-hold-custody.d.ts.map +1 -1
  518. package/daemon/dist/domain/quiet-hold-custody.js +7 -3
  519. package/daemon/dist/domain/quiet-hold-custody.js.map +1 -1
  520. package/daemon/dist/domain/rebuild-priming-chain.d.ts +3 -1
  521. package/daemon/dist/domain/rebuild-priming-chain.d.ts.map +1 -1
  522. package/daemon/dist/domain/rebuild-priming-chain.js +3 -1
  523. package/daemon/dist/domain/rebuild-priming-chain.js.map +1 -1
  524. package/daemon/dist/domain/refocus-record.d.ts +17 -0
  525. package/daemon/dist/domain/refocus-record.d.ts.map +1 -0
  526. package/daemon/dist/domain/refocus-record.js +94 -0
  527. package/daemon/dist/domain/refocus-record.js.map +1 -0
  528. package/daemon/dist/domain/restore-check-service.js +1 -1
  529. package/daemon/dist/domain/restore-check-service.js.map +1 -1
  530. package/daemon/dist/domain/restore-guidance.d.ts.map +1 -1
  531. package/daemon/dist/domain/restore-guidance.js +5 -6
  532. package/daemon/dist/domain/restore-guidance.js.map +1 -1
  533. package/daemon/dist/domain/restore-orchestrator.d.ts +15 -2
  534. package/daemon/dist/domain/restore-orchestrator.d.ts.map +1 -1
  535. package/daemon/dist/domain/restore-orchestrator.js +100 -42
  536. package/daemon/dist/domain/restore-orchestrator.js.map +1 -1
  537. package/daemon/dist/domain/restore-plan-preview.d.ts.map +1 -1
  538. package/daemon/dist/domain/restore-plan-preview.js +2 -1
  539. package/daemon/dist/domain/restore-plan-preview.js.map +1 -1
  540. package/daemon/dist/domain/resume-token-validation.d.ts +7 -0
  541. package/daemon/dist/domain/resume-token-validation.d.ts.map +1 -1
  542. package/daemon/dist/domain/resume-token-validation.js +13 -3
  543. package/daemon/dist/domain/resume-token-validation.js.map +1 -1
  544. package/daemon/dist/domain/rig-repository.d.ts +3 -0
  545. package/daemon/dist/domain/rig-repository.d.ts.map +1 -1
  546. package/daemon/dist/domain/rig-repository.js +46 -1
  547. package/daemon/dist/domain/rig-repository.js.map +1 -1
  548. package/daemon/dist/domain/rig-teardown.d.ts.map +1 -1
  549. package/daemon/dist/domain/rig-teardown.js +2 -1
  550. package/daemon/dist/domain/rig-teardown.js.map +1 -1
  551. package/daemon/dist/domain/rigs-being-built.d.ts +5 -0
  552. package/daemon/dist/domain/rigs-being-built.d.ts.map +1 -0
  553. package/daemon/dist/domain/rigs-being-built.js +18 -0
  554. package/daemon/dist/domain/rigs-being-built.js.map +1 -0
  555. package/daemon/dist/domain/rigspec-codec.d.ts.map +1 -1
  556. package/daemon/dist/domain/rigspec-codec.js +4 -0
  557. package/daemon/dist/domain/rigspec-codec.js.map +1 -1
  558. package/daemon/dist/domain/rigspec-exporter.d.ts.map +1 -1
  559. package/daemon/dist/domain/rigspec-exporter.js +5 -0
  560. package/daemon/dist/domain/rigspec-exporter.js.map +1 -1
  561. package/daemon/dist/domain/rigspec-instantiator.d.ts +20 -1
  562. package/daemon/dist/domain/rigspec-instantiator.d.ts.map +1 -1
  563. package/daemon/dist/domain/rigspec-instantiator.js +100 -22
  564. package/daemon/dist/domain/rigspec-instantiator.js.map +1 -1
  565. package/daemon/dist/domain/rigspec-preflight.d.ts.map +1 -1
  566. package/daemon/dist/domain/rigspec-preflight.js +13 -0
  567. package/daemon/dist/domain/rigspec-preflight.js.map +1 -1
  568. package/daemon/dist/domain/rigspec-schema.d.ts.map +1 -1
  569. package/daemon/dist/domain/rigspec-schema.js +26 -1
  570. package/daemon/dist/domain/rigspec-schema.js.map +1 -1
  571. package/daemon/dist/domain/runner-permissions.d.ts +16 -0
  572. package/daemon/dist/domain/runner-permissions.d.ts.map +1 -1
  573. package/daemon/dist/domain/runner-permissions.js +95 -14
  574. package/daemon/dist/domain/runner-permissions.js.map +1 -1
  575. package/daemon/dist/domain/runtime-adapter.d.ts +2 -0
  576. package/daemon/dist/domain/runtime-adapter.d.ts.map +1 -1
  577. package/daemon/dist/domain/runtime-adapter.js.map +1 -1
  578. package/daemon/dist/domain/runtime-switch-materials.d.ts +1 -1
  579. package/daemon/dist/domain/runtime-switch-materials.d.ts.map +1 -1
  580. package/daemon/dist/domain/runtime-switch-materials.js +2 -2
  581. package/daemon/dist/domain/runtime-switch-materials.js.map +1 -1
  582. package/daemon/dist/domain/scope/logical-checkbox.d.ts.map +1 -1
  583. package/daemon/dist/domain/scope/logical-checkbox.js +14 -0
  584. package/daemon/dist/domain/scope/logical-checkbox.js.map +1 -1
  585. package/daemon/dist/domain/seat-activity-service.d.ts +50 -1
  586. package/daemon/dist/domain/seat-activity-service.d.ts.map +1 -1
  587. package/daemon/dist/domain/seat-activity-service.js +144 -5
  588. package/daemon/dist/domain/seat-activity-service.js.map +1 -1
  589. package/daemon/dist/domain/seat-attention-reconciler.d.ts +13 -0
  590. package/daemon/dist/domain/seat-attention-reconciler.d.ts.map +1 -1
  591. package/daemon/dist/domain/seat-attention-reconciler.js +45 -1
  592. package/daemon/dist/domain/seat-attention-reconciler.js.map +1 -1
  593. package/daemon/dist/domain/seat-handover-service.d.ts +8 -0
  594. package/daemon/dist/domain/seat-handover-service.d.ts.map +1 -1
  595. package/daemon/dist/domain/seat-handover-service.js +61 -19
  596. package/daemon/dist/domain/seat-handover-service.js.map +1 -1
  597. package/daemon/dist/domain/seat-kinds.d.ts +21 -0
  598. package/daemon/dist/domain/seat-kinds.d.ts.map +1 -0
  599. package/daemon/dist/domain/seat-kinds.js +27 -0
  600. package/daemon/dist/domain/seat-kinds.js.map +1 -0
  601. package/daemon/dist/domain/seat-launch-environment.d.ts +14 -0
  602. package/daemon/dist/domain/seat-launch-environment.d.ts.map +1 -1
  603. package/daemon/dist/domain/seat-launch-environment.js +64 -16
  604. package/daemon/dist/domain/seat-launch-environment.js.map +1 -1
  605. package/daemon/dist/domain/seat-lifecycle-service.d.ts +12 -0
  606. package/daemon/dist/domain/seat-lifecycle-service.d.ts.map +1 -1
  607. package/daemon/dist/domain/seat-lifecycle-service.js +59 -14
  608. package/daemon/dist/domain/seat-lifecycle-service.js.map +1 -1
  609. package/daemon/dist/domain/seat-restart-in-place.d.ts +2 -1
  610. package/daemon/dist/domain/seat-restart-in-place.d.ts.map +1 -1
  611. package/daemon/dist/domain/seat-restart-in-place.js +19 -1
  612. package/daemon/dist/domain/seat-restart-in-place.js.map +1 -1
  613. package/daemon/dist/domain/seat-runtime-home.d.ts +4 -1
  614. package/daemon/dist/domain/seat-runtime-home.d.ts.map +1 -1
  615. package/daemon/dist/domain/seat-runtime-home.js +6 -4
  616. package/daemon/dist/domain/seat-runtime-home.js.map +1 -1
  617. package/daemon/dist/domain/seat-runtime-switch-service.d.ts.map +1 -1
  618. package/daemon/dist/domain/seat-runtime-switch-service.js +87 -13
  619. package/daemon/dist/domain/seat-runtime-switch-service.js.map +1 -1
  620. package/daemon/dist/domain/seat-skill-apply.d.ts +2 -0
  621. package/daemon/dist/domain/seat-skill-apply.d.ts.map +1 -1
  622. package/daemon/dist/domain/seat-skill-apply.js +5 -2
  623. package/daemon/dist/domain/seat-skill-apply.js.map +1 -1
  624. package/daemon/dist/domain/seat-skill-storage.d.ts +57 -4
  625. package/daemon/dist/domain/seat-skill-storage.d.ts.map +1 -1
  626. package/daemon/dist/domain/seat-skill-storage.js +339 -9
  627. package/daemon/dist/domain/seat-skill-storage.js.map +1 -1
  628. package/daemon/dist/domain/seat-status-service.d.ts +12 -2
  629. package/daemon/dist/domain/seat-status-service.d.ts.map +1 -1
  630. package/daemon/dist/domain/seat-status-service.js +39 -4
  631. package/daemon/dist/domain/seat-status-service.js.map +1 -1
  632. package/daemon/dist/domain/seat-structural-activity-service.d.ts +8 -0
  633. package/daemon/dist/domain/seat-structural-activity-service.d.ts.map +1 -1
  634. package/daemon/dist/domain/seat-structural-activity-service.js +8 -2
  635. package/daemon/dist/domain/seat-structural-activity-service.js.map +1 -1
  636. package/daemon/dist/domain/self-attach-service.d.ts.map +1 -1
  637. package/daemon/dist/domain/self-attach-service.js +11 -4
  638. package/daemon/dist/domain/self-attach-service.js.map +1 -1
  639. package/daemon/dist/domain/session-jsonl.d.ts +4 -2
  640. package/daemon/dist/domain/session-jsonl.d.ts.map +1 -1
  641. package/daemon/dist/domain/session-jsonl.js +56 -22
  642. package/daemon/dist/domain/session-jsonl.js.map +1 -1
  643. package/daemon/dist/domain/session-registry.d.ts +20 -3
  644. package/daemon/dist/domain/session-registry.d.ts.map +1 -1
  645. package/daemon/dist/domain/session-registry.js +39 -3
  646. package/daemon/dist/domain/session-registry.js.map +1 -1
  647. package/daemon/dist/domain/session-transport.d.ts +52 -5
  648. package/daemon/dist/domain/session-transport.d.ts.map +1 -1
  649. package/daemon/dist/domain/session-transport.js +434 -85
  650. package/daemon/dist/domain/session-transport.js.map +1 -1
  651. package/daemon/dist/domain/skill-catalog.d.ts +37 -0
  652. package/daemon/dist/domain/skill-catalog.d.ts.map +1 -1
  653. package/daemon/dist/domain/skill-catalog.js +152 -3
  654. package/daemon/dist/domain/skill-catalog.js.map +1 -1
  655. package/daemon/dist/domain/slices/slice-detail-projector.d.ts +1 -1
  656. package/daemon/dist/domain/slices/slice-detail-projector.d.ts.map +1 -1
  657. package/daemon/dist/domain/slices/slice-detail-projector.js +11 -13
  658. package/daemon/dist/domain/slices/slice-detail-projector.js.map +1 -1
  659. package/daemon/dist/domain/slices/slice-indexer.d.ts +41 -0
  660. package/daemon/dist/domain/slices/slice-indexer.d.ts.map +1 -1
  661. package/daemon/dist/domain/slices/slice-indexer.js +463 -22
  662. package/daemon/dist/domain/slices/slice-indexer.js.map +1 -1
  663. package/daemon/dist/domain/startup-orchestrator.d.ts.map +1 -1
  664. package/daemon/dist/domain/startup-orchestrator.js +12 -3
  665. package/daemon/dist/domain/startup-orchestrator.js.map +1 -1
  666. package/daemon/dist/domain/startup-submission-evidence.d.ts +1 -0
  667. package/daemon/dist/domain/startup-submission-evidence.d.ts.map +1 -1
  668. package/daemon/dist/domain/startup-submission-evidence.js +18 -4
  669. package/daemon/dist/domain/startup-submission-evidence.js.map +1 -1
  670. package/daemon/dist/domain/successor-session-launcher.d.ts +1 -0
  671. package/daemon/dist/domain/successor-session-launcher.d.ts.map +1 -1
  672. package/daemon/dist/domain/successor-session-launcher.js +1 -0
  673. package/daemon/dist/domain/successor-session-launcher.js.map +1 -1
  674. package/daemon/dist/domain/terminal/earlier-tile-attach-0711.d.ts +2 -0
  675. package/daemon/dist/domain/terminal/earlier-tile-attach-0711.d.ts.map +1 -0
  676. package/daemon/dist/domain/terminal/earlier-tile-attach-0711.js +146 -0
  677. package/daemon/dist/domain/terminal/earlier-tile-attach-0711.js.map +1 -0
  678. package/daemon/dist/domain/terminal/earlier-tile-attach.d.ts +1 -0
  679. package/daemon/dist/domain/terminal/earlier-tile-attach.d.ts.map +1 -1
  680. package/daemon/dist/domain/terminal/earlier-tile-attach.js +42 -1
  681. package/daemon/dist/domain/terminal/earlier-tile-attach.js.map +1 -1
  682. package/daemon/dist/domain/terminal/herdr-adapter.d.ts.map +1 -1
  683. package/daemon/dist/domain/terminal/herdr-adapter.js +3 -2
  684. package/daemon/dist/domain/terminal/herdr-adapter.js.map +1 -1
  685. package/daemon/dist/domain/terminal/herdr-app-install.d.ts +28 -0
  686. package/daemon/dist/domain/terminal/herdr-app-install.d.ts.map +1 -0
  687. package/daemon/dist/domain/terminal/herdr-app-install.js +170 -0
  688. package/daemon/dist/domain/terminal/herdr-app-install.js.map +1 -0
  689. package/daemon/dist/domain/terminal/herdr-app-layout.d.ts +79 -0
  690. package/daemon/dist/domain/terminal/herdr-app-layout.d.ts.map +1 -0
  691. package/daemon/dist/domain/terminal/herdr-app-layout.js +134 -0
  692. package/daemon/dist/domain/terminal/herdr-app-layout.js.map +1 -0
  693. package/daemon/dist/domain/terminal/herdr-app-provider.d.ts +123 -0
  694. package/daemon/dist/domain/terminal/herdr-app-provider.d.ts.map +1 -0
  695. package/daemon/dist/domain/terminal/herdr-app-provider.js +681 -0
  696. package/daemon/dist/domain/terminal/herdr-app-provider.js.map +1 -0
  697. package/daemon/dist/domain/terminal/herdr-app-state.d.ts +91 -0
  698. package/daemon/dist/domain/terminal/herdr-app-state.d.ts.map +1 -0
  699. package/daemon/dist/domain/terminal/herdr-app-state.js +140 -0
  700. package/daemon/dist/domain/terminal/herdr-app-state.js.map +1 -0
  701. package/daemon/dist/domain/terminal/herdr-app-transport.d.ts +68 -0
  702. package/daemon/dist/domain/terminal/herdr-app-transport.d.ts.map +1 -0
  703. package/daemon/dist/domain/terminal/herdr-app-transport.js +133 -0
  704. package/daemon/dist/domain/terminal/herdr-app-transport.js.map +1 -0
  705. package/daemon/dist/domain/terminal/herdr-follow-view.d.ts.map +1 -1
  706. package/daemon/dist/domain/terminal/herdr-follow-view.js +43 -19
  707. package/daemon/dist/domain/terminal/herdr-follow-view.js.map +1 -1
  708. package/daemon/dist/domain/terminal/herdr-viewer.d.ts +7 -4
  709. package/daemon/dist/domain/terminal/herdr-viewer.d.ts.map +1 -1
  710. package/daemon/dist/domain/terminal/herdr-viewer.js +101 -47
  711. package/daemon/dist/domain/terminal/herdr-viewer.js.map +1 -1
  712. package/daemon/dist/domain/terminal/terminal-following.js +3 -3
  713. package/daemon/dist/domain/terminal/terminal-following.js.map +1 -1
  714. package/daemon/dist/domain/terminal/terminal-provider.d.ts +18 -0
  715. package/daemon/dist/domain/terminal/terminal-provider.d.ts.map +1 -1
  716. package/daemon/dist/domain/terminal/terminal-service.d.ts +28 -3
  717. package/daemon/dist/domain/terminal/terminal-service.d.ts.map +1 -1
  718. package/daemon/dist/domain/terminal/terminal-service.js +56 -8
  719. package/daemon/dist/domain/terminal/terminal-service.js.map +1 -1
  720. package/daemon/dist/domain/terminal/tile-attach.d.ts +6 -3
  721. package/daemon/dist/domain/terminal/tile-attach.d.ts.map +1 -1
  722. package/daemon/dist/domain/terminal/tile-attach.js +11 -46
  723. package/daemon/dist/domain/terminal/tile-attach.js.map +1 -1
  724. package/daemon/dist/domain/terminal/view-composer.d.ts.map +1 -1
  725. package/daemon/dist/domain/terminal/view-composer.js +1 -0
  726. package/daemon/dist/domain/terminal/view-composer.js.map +1 -1
  727. package/daemon/dist/domain/time-bound-advisory.js +3 -3
  728. package/daemon/dist/domain/time-bound-advisory.js.map +1 -1
  729. package/daemon/dist/domain/tmux-server-selection.d.ts.map +1 -1
  730. package/daemon/dist/domain/tmux-server-selection.js +8 -2
  731. package/daemon/dist/domain/tmux-server-selection.js.map +1 -1
  732. package/daemon/dist/domain/types.d.ts +69 -1
  733. package/daemon/dist/domain/types.d.ts.map +1 -1
  734. package/daemon/dist/domain/types.js.map +1 -1
  735. package/daemon/dist/domain/user-settings/settings-browser.d.ts +2 -1
  736. package/daemon/dist/domain/user-settings/settings-browser.d.ts.map +1 -1
  737. package/daemon/dist/domain/user-settings/settings-browser.js +22 -3
  738. package/daemon/dist/domain/user-settings/settings-browser.js.map +1 -1
  739. package/daemon/dist/domain/user-settings/settings-store.d.ts +1 -1
  740. package/daemon/dist/domain/user-settings/settings-store.d.ts.map +1 -1
  741. package/daemon/dist/domain/user-settings/settings-store.js +83 -0
  742. package/daemon/dist/domain/user-settings/settings-store.js.map +1 -1
  743. package/daemon/dist/domain/view-event-bridge.js +1 -1
  744. package/daemon/dist/domain/view-event-bridge.js.map +1 -1
  745. package/daemon/dist/domain/view-projector.d.ts +4 -1
  746. package/daemon/dist/domain/view-projector.d.ts.map +1 -1
  747. package/daemon/dist/domain/view-projector.js +9 -4
  748. package/daemon/dist/domain/view-projector.js.map +1 -1
  749. package/daemon/dist/domain/wake-recovery.d.ts.map +1 -1
  750. package/daemon/dist/domain/wake-recovery.js +10 -2
  751. package/daemon/dist/domain/wake-recovery.js.map +1 -1
  752. package/daemon/dist/domain/whoami-service.d.ts +6 -0
  753. package/daemon/dist/domain/whoami-service.d.ts.map +1 -1
  754. package/daemon/dist/domain/whoami-service.js +9 -1
  755. package/daemon/dist/domain/whoami-service.js.map +1 -1
  756. package/daemon/dist/domain/workflow-exception-escalation.d.ts +3 -2
  757. package/daemon/dist/domain/workflow-exception-escalation.d.ts.map +1 -1
  758. package/daemon/dist/domain/workflow-exception-escalation.js +1 -1
  759. package/daemon/dist/domain/workflow-exception-escalation.js.map +1 -1
  760. package/daemon/dist/domain/workflow-instance-store.d.ts +8 -1
  761. package/daemon/dist/domain/workflow-instance-store.d.ts.map +1 -1
  762. package/daemon/dist/domain/workflow-instance-store.js +21 -3
  763. package/daemon/dist/domain/workflow-instance-store.js.map +1 -1
  764. package/daemon/dist/domain/workflow-projector.js +1 -1
  765. package/daemon/dist/domain/workflow-projector.js.map +1 -1
  766. package/daemon/dist/domain/workflow-reconciliation.d.ts.map +1 -1
  767. package/daemon/dist/domain/workflow-reconciliation.js +2 -1
  768. package/daemon/dist/domain/workflow-reconciliation.js.map +1 -1
  769. package/daemon/dist/domain/workflow-runtime.d.ts +4 -1
  770. package/daemon/dist/domain/workflow-runtime.d.ts.map +1 -1
  771. package/daemon/dist/domain/workflow-runtime.js +24 -11
  772. package/daemon/dist/domain/workflow-runtime.js.map +1 -1
  773. package/daemon/dist/domain/workflow-spec-cache.d.ts +38 -4
  774. package/daemon/dist/domain/workflow-spec-cache.d.ts.map +1 -1
  775. package/daemon/dist/domain/workflow-spec-cache.js +115 -14
  776. package/daemon/dist/domain/workflow-spec-cache.js.map +1 -1
  777. package/daemon/dist/domain/workflow-spec-unregister.d.ts +36 -0
  778. package/daemon/dist/domain/workflow-spec-unregister.d.ts.map +1 -0
  779. package/daemon/dist/domain/workflow-spec-unregister.js +105 -0
  780. package/daemon/dist/domain/workflow-spec-unregister.js.map +1 -0
  781. package/daemon/dist/domain/workflow-types.d.ts +14 -0
  782. package/daemon/dist/domain/workflow-types.d.ts.map +1 -1
  783. package/daemon/dist/index.d.ts +3 -1
  784. package/daemon/dist/index.d.ts.map +1 -1
  785. package/daemon/dist/index.js +31 -5
  786. package/daemon/dist/index.js.map +1 -1
  787. package/daemon/dist/learned-host-bindings-surface.d.ts +2 -0
  788. package/daemon/dist/learned-host-bindings-surface.d.ts.map +1 -0
  789. package/daemon/dist/learned-host-bindings-surface.js +4 -0
  790. package/daemon/dist/learned-host-bindings-surface.js.map +1 -0
  791. package/daemon/dist/lib/pane-envelope.d.ts +3 -0
  792. package/daemon/dist/lib/pane-envelope.d.ts.map +1 -1
  793. package/daemon/dist/lib/pane-envelope.js +3 -1
  794. package/daemon/dist/lib/pane-envelope.js.map +1 -1
  795. package/daemon/dist/routes/activity.d.ts.map +1 -1
  796. package/daemon/dist/routes/activity.js +147 -25
  797. package/daemon/dist/routes/activity.js.map +1 -1
  798. package/daemon/dist/routes/adapters.d.ts.map +1 -1
  799. package/daemon/dist/routes/adapters.js +4 -0
  800. package/daemon/dist/routes/adapters.js.map +1 -1
  801. package/daemon/dist/routes/attention.d.ts.map +1 -1
  802. package/daemon/dist/routes/attention.js +2 -0
  803. package/daemon/dist/routes/attention.js.map +1 -1
  804. package/daemon/dist/routes/compaction.js +2 -0
  805. package/daemon/dist/routes/compaction.js.map +1 -1
  806. package/daemon/dist/routes/config.d.ts.map +1 -1
  807. package/daemon/dist/routes/config.js +9 -1
  808. package/daemon/dist/routes/config.js.map +1 -1
  809. package/daemon/dist/routes/events.js +11 -2
  810. package/daemon/dist/routes/events.js.map +1 -1
  811. package/daemon/dist/routes/gateway.d.ts +3 -0
  812. package/daemon/dist/routes/gateway.d.ts.map +1 -1
  813. package/daemon/dist/routes/gateway.js +87 -8
  814. package/daemon/dist/routes/gateway.js.map +1 -1
  815. package/daemon/dist/routes/hosts.d.ts.map +1 -1
  816. package/daemon/dist/routes/hosts.js +400 -37
  817. package/daemon/dist/routes/hosts.js.map +1 -1
  818. package/daemon/dist/routes/provider.js +1 -1
  819. package/daemon/dist/routes/provider.js.map +1 -1
  820. package/daemon/dist/routes/queue.d.ts +19 -0
  821. package/daemon/dist/routes/queue.d.ts.map +1 -1
  822. package/daemon/dist/routes/queue.js +242 -46
  823. package/daemon/dist/routes/queue.js.map +1 -1
  824. package/daemon/dist/routes/seat.d.ts.map +1 -1
  825. package/daemon/dist/routes/seat.js +4 -3
  826. package/daemon/dist/routes/seat.js.map +1 -1
  827. package/daemon/dist/routes/skills.d.ts.map +1 -1
  828. package/daemon/dist/routes/skills.js +8 -2
  829. package/daemon/dist/routes/skills.js.map +1 -1
  830. package/daemon/dist/routes/slices.d.ts.map +1 -1
  831. package/daemon/dist/routes/slices.js +156 -28
  832. package/daemon/dist/routes/slices.js.map +1 -1
  833. package/daemon/dist/routes/terminal-ws.d.ts +1 -0
  834. package/daemon/dist/routes/terminal-ws.d.ts.map +1 -1
  835. package/daemon/dist/routes/terminal-ws.js +1 -1
  836. package/daemon/dist/routes/terminal-ws.js.map +1 -1
  837. package/daemon/dist/routes/terminal.d.ts.map +1 -1
  838. package/daemon/dist/routes/terminal.js +40 -3
  839. package/daemon/dist/routes/terminal.js.map +1 -1
  840. package/daemon/dist/routes/transport.d.ts.map +1 -1
  841. package/daemon/dist/routes/transport.js +0 -1
  842. package/daemon/dist/routes/transport.js.map +1 -1
  843. package/daemon/dist/routes/workflow.d.ts.map +1 -1
  844. package/daemon/dist/routes/workflow.js +24 -0
  845. package/daemon/dist/routes/workflow.js.map +1 -1
  846. package/daemon/dist/server.d.ts +2 -0
  847. package/daemon/dist/server.d.ts.map +1 -1
  848. package/daemon/dist/server.js +7 -2
  849. package/daemon/dist/server.js.map +1 -1
  850. package/daemon/dist/startup.d.ts +34 -0
  851. package/daemon/dist/startup.d.ts.map +1 -1
  852. package/daemon/dist/startup.js +255 -25
  853. package/daemon/dist/startup.js.map +1 -1
  854. package/daemon/dist/terminal/TerminalSessionBroker.d.ts +18 -13
  855. package/daemon/dist/terminal/TerminalSessionBroker.d.ts.map +1 -1
  856. package/daemon/dist/terminal/TerminalSessionBroker.js +113 -76
  857. package/daemon/dist/terminal/TerminalSessionBroker.js.map +1 -1
  858. package/daemon/dist/terminal/window-pin.d.ts +3 -3
  859. package/daemon/dist/terminal/window-pin.d.ts.map +1 -1
  860. package/daemon/dist/terminal/window-pin.js +2 -2
  861. package/daemon/dist/terminal/window-pin.js.map +1 -1
  862. package/daemon/docs/reference/acp-agents.md +68 -0
  863. package/daemon/docs/reference/agent-spec.md +51 -1
  864. package/daemon/docs/reference/agent-startup-guide.md +52 -2
  865. package/daemon/docs/reference/agent-state-taxonomy.md +7 -0
  866. package/daemon/docs/reference/community-harness-examples/omo/omo.yaml +14 -0
  867. package/daemon/docs/reference/community-harness-presets.md +56 -2
  868. package/daemon/docs/reference/daemon-http-clients.md +31 -8
  869. package/daemon/docs/reference/edge-types.md +6 -4
  870. package/daemon/docs/reference/gateway-participants.md +23 -1
  871. package/daemon/docs/reference/gateway-relay.md +268 -0
  872. package/daemon/docs/reference/getting-started.md +19 -3
  873. package/daemon/docs/reference/harness-runner-contract.md +61 -12
  874. package/daemon/docs/reference/health-diagnosis.md +5 -1
  875. package/daemon/docs/reference/help.md +18 -0
  876. package/daemon/docs/reference/herdr-app.md +148 -0
  877. package/daemon/docs/reference/hosted-members.md +56 -7
  878. package/daemon/docs/reference/keeping-a-watch.md +3 -1
  879. package/daemon/docs/reference/project-workspace.md +4 -0
  880. package/daemon/docs/reference/queue-erasure.md +161 -0
  881. package/daemon/docs/reference/quickstart.md +1 -1
  882. package/daemon/docs/reference/reconstructions.md +90 -0
  883. package/daemon/docs/reference/rig-spec.md +71 -8
  884. package/daemon/docs/reference/runner-conformance/README.md +3 -0
  885. package/daemon/docs/reference/runner-conformance/check-runner.mjs +27 -6
  886. package/daemon/docs/reference/runner-conformance/fake-acp-agent.mjs +1 -1
  887. package/daemon/docs/reference/sdlc-conventions.md +16 -1
  888. package/daemon/docs/reference/seat-delivery.md +30 -3
  889. package/daemon/docs/reference/slack-app-setup.md +37 -12
  890. package/daemon/docs/reference/terminal-sessions.md +101 -26
  891. package/daemon/docs/reference/tmux-servers.md +50 -2
  892. package/daemon/docs/reference/whats-new.md +402 -132
  893. package/daemon/specs/agents/shared/skills/core/cross-host-rig-commands/SKILL.md +7 -0
  894. package/daemon/specs/agents/shared/skills/core/openrig-herdr/SKILL.md +1 -0
  895. package/daemon/specs/agents/shared/skills/core/openrig-skills/SKILL.md +1 -0
  896. package/daemon/specs/agents/shared/skills/core/working-with-an-openrig-team/SKILL.md +90 -0
  897. package/daemon/specs/agents/shared/skills/pods/review-team/SKILL.md +2 -0
  898. package/daemon/specs/rigs/launch/kernel/agents/operator/agent/guidance/role.md +24 -0
  899. package/daemon/specs/rigs/launch/kernel/culture/CULTURE.md +7 -4
  900. package/daemon/specs/rigs/launch/kernel/rig.yaml +6 -3
  901. package/daemon/specs/rigs/launch/starter/guidance/lead-first-move.md +3 -1
  902. package/dist/acp/agent-server.d.ts +126 -0
  903. package/dist/acp/agent-server.d.ts.map +1 -0
  904. package/dist/acp/agent-server.js +449 -0
  905. package/dist/acp/agent-server.js.map +1 -0
  906. package/dist/acp/json-rpc-stdio.d.ts +24 -10
  907. package/dist/acp/json-rpc-stdio.d.ts.map +1 -1
  908. package/dist/acp/json-rpc-stdio.js +58 -36
  909. package/dist/acp/json-rpc-stdio.js.map +1 -1
  910. package/dist/bin-wrapper.d.ts.map +1 -1
  911. package/dist/bin-wrapper.js +3 -1
  912. package/dist/bin-wrapper.js.map +1 -1
  913. package/dist/build-info.js +3 -3
  914. package/dist/client.d.ts +4 -0
  915. package/dist/client.d.ts.map +1 -1
  916. package/dist/client.js +9 -2
  917. package/dist/client.js.map +1 -1
  918. package/dist/commands/acp.d.ts +14 -0
  919. package/dist/commands/acp.d.ts.map +1 -1
  920. package/dist/commands/acp.js +189 -2
  921. package/dist/commands/acp.js.map +1 -1
  922. package/dist/commands/attach.js +1 -1
  923. package/dist/commands/attach.js.map +1 -1
  924. package/dist/commands/capture.js +6 -6
  925. package/dist/commands/capture.js.map +1 -1
  926. package/dist/commands/compact.d.ts.map +1 -1
  927. package/dist/commands/compact.js +14 -2
  928. package/dist/commands/compact.js.map +1 -1
  929. package/dist/commands/config.d.ts.map +1 -1
  930. package/dist/commands/config.js +46 -7
  931. package/dist/commands/config.js.map +1 -1
  932. package/dist/commands/context-reconstruction.d.ts +5 -0
  933. package/dist/commands/context-reconstruction.d.ts.map +1 -0
  934. package/dist/commands/context-reconstruction.js +69 -0
  935. package/dist/commands/context-reconstruction.js.map +1 -0
  936. package/dist/commands/context.d.ts.map +1 -1
  937. package/dist/commands/context.js +46 -4
  938. package/dist/commands/context.js.map +1 -1
  939. package/dist/commands/daemon.d.ts.map +1 -1
  940. package/dist/commands/daemon.js +22 -5
  941. package/dist/commands/daemon.js.map +1 -1
  942. package/dist/commands/doctor.d.ts.map +1 -1
  943. package/dist/commands/doctor.js +61 -0
  944. package/dist/commands/doctor.js.map +1 -1
  945. package/dist/commands/gateway.d.ts.map +1 -1
  946. package/dist/commands/gateway.js +36 -11
  947. package/dist/commands/gateway.js.map +1 -1
  948. package/dist/commands/host.d.ts.map +1 -1
  949. package/dist/commands/host.js +68 -12
  950. package/dist/commands/host.js.map +1 -1
  951. package/dist/commands/launch.d.ts +1 -0
  952. package/dist/commands/launch.d.ts.map +1 -1
  953. package/dist/commands/launch.js +1 -1
  954. package/dist/commands/launch.js.map +1 -1
  955. package/dist/commands/mcp.d.ts.map +1 -1
  956. package/dist/commands/mcp.js +29 -5
  957. package/dist/commands/mcp.js.map +1 -1
  958. package/dist/commands/proof.d.ts.map +1 -1
  959. package/dist/commands/proof.js +18 -6
  960. package/dist/commands/proof.js.map +1 -1
  961. package/dist/commands/provider.d.ts.map +1 -1
  962. package/dist/commands/provider.js +4 -1
  963. package/dist/commands/provider.js.map +1 -1
  964. package/dist/commands/ps.d.ts +11 -1
  965. package/dist/commands/ps.d.ts.map +1 -1
  966. package/dist/commands/ps.js +26 -3
  967. package/dist/commands/ps.js.map +1 -1
  968. package/dist/commands/queue.d.ts +3 -0
  969. package/dist/commands/queue.d.ts.map +1 -1
  970. package/dist/commands/queue.js +429 -75
  971. package/dist/commands/queue.js.map +1 -1
  972. package/dist/commands/scope.d.ts +2 -0
  973. package/dist/commands/scope.d.ts.map +1 -1
  974. package/dist/commands/scope.js +15 -0
  975. package/dist/commands/scope.js.map +1 -1
  976. package/dist/commands/seat.d.ts.map +1 -1
  977. package/dist/commands/seat.js +79 -13
  978. package/dist/commands/seat.js.map +1 -1
  979. package/dist/commands/send.d.ts +2 -0
  980. package/dist/commands/send.d.ts.map +1 -1
  981. package/dist/commands/send.js +16 -6
  982. package/dist/commands/send.js.map +1 -1
  983. package/dist/commands/setup.js +1 -1
  984. package/dist/commands/setup.js.map +1 -1
  985. package/dist/commands/skill.d.ts.map +1 -1
  986. package/dist/commands/skill.js +5 -0
  987. package/dist/commands/skill.js.map +1 -1
  988. package/dist/commands/slack.d.ts +1 -1
  989. package/dist/commands/slack.d.ts.map +1 -1
  990. package/dist/commands/slack.js +5 -1
  991. package/dist/commands/slack.js.map +1 -1
  992. package/dist/commands/status.d.ts.map +1 -1
  993. package/dist/commands/status.js +11 -1
  994. package/dist/commands/status.js.map +1 -1
  995. package/dist/commands/stream.d.ts.map +1 -1
  996. package/dist/commands/stream.js +24 -1
  997. package/dist/commands/stream.js.map +1 -1
  998. package/dist/commands/terminal.d.ts +22 -0
  999. package/dist/commands/terminal.d.ts.map +1 -1
  1000. package/dist/commands/terminal.js +117 -8
  1001. package/dist/commands/terminal.js.map +1 -1
  1002. package/dist/commands/up.d.ts.map +1 -1
  1003. package/dist/commands/up.js +22 -0
  1004. package/dist/commands/up.js.map +1 -1
  1005. package/dist/commands/whoami.d.ts.map +1 -1
  1006. package/dist/commands/whoami.js +13 -2
  1007. package/dist/commands/whoami.js.map +1 -1
  1008. package/dist/commands/workflow-errors.js +1 -1
  1009. package/dist/commands/workflow-errors.js.map +1 -1
  1010. package/dist/commands/workflow-render.d.ts +4 -0
  1011. package/dist/commands/workflow-render.d.ts.map +1 -1
  1012. package/dist/commands/workflow-render.js +7 -0
  1013. package/dist/commands/workflow-render.js.map +1 -1
  1014. package/dist/commands/workflow.d.ts.map +1 -1
  1015. package/dist/commands/workflow.js +70 -2
  1016. package/dist/commands/workflow.js.map +1 -1
  1017. package/dist/config-store.d.ts +15 -1
  1018. package/dist/config-store.d.ts.map +1 -1
  1019. package/dist/config-store.js +112 -1
  1020. package/dist/config-store.js.map +1 -1
  1021. package/dist/daemon-lifecycle.d.ts +2 -0
  1022. package/dist/daemon-lifecycle.d.ts.map +1 -1
  1023. package/dist/daemon-lifecycle.js +38 -5
  1024. package/dist/daemon-lifecycle.js.map +1 -1
  1025. package/dist/daemon-reachability.d.ts +1 -1
  1026. package/dist/daemon-reachability.d.ts.map +1 -1
  1027. package/dist/daemon-reachability.js +4 -2
  1028. package/dist/daemon-reachability.js.map +1 -1
  1029. package/dist/daemon-start-lock.d.ts +24 -2
  1030. package/dist/daemon-start-lock.d.ts.map +1 -1
  1031. package/dist/daemon-start-lock.js +125 -4
  1032. package/dist/daemon-start-lock.js.map +1 -1
  1033. package/dist/lib/reconstruction-reader.d.ts +122 -0
  1034. package/dist/lib/reconstruction-reader.d.ts.map +1 -0
  1035. package/dist/lib/reconstruction-reader.js +481 -0
  1036. package/dist/lib/reconstruction-reader.js.map +1 -0
  1037. package/dist/lib/scope/logical-checkbox.d.ts.map +1 -1
  1038. package/dist/lib/scope/logical-checkbox.js +14 -0
  1039. package/dist/lib/scope/logical-checkbox.js.map +1 -1
  1040. package/dist/lib/scope/scope-fs.d.ts.map +1 -1
  1041. package/dist/lib/scope/scope-fs.js +36 -2
  1042. package/dist/lib/scope/scope-fs.js.map +1 -1
  1043. package/dist/lib/work-install.d.ts +28 -0
  1044. package/dist/lib/work-install.d.ts.map +1 -1
  1045. package/dist/lib/work-install.js +80 -20
  1046. package/dist/lib/work-install.js.map +1 -1
  1047. package/dist/mcp-http.d.ts +7 -0
  1048. package/dist/mcp-http.d.ts.map +1 -1
  1049. package/dist/mcp-http.js +30 -6
  1050. package/dist/mcp-http.js.map +1 -1
  1051. package/dist/mcp-server.d.ts +33 -3
  1052. package/dist/mcp-server.d.ts.map +1 -1
  1053. package/dist/mcp-server.js +489 -57
  1054. package/dist/mcp-server.js.map +1 -1
  1055. package/dist/queue-artifact.d.ts +57 -0
  1056. package/dist/queue-artifact.d.ts.map +1 -0
  1057. package/dist/queue-artifact.js +70 -0
  1058. package/dist/queue-artifact.js.map +1 -0
  1059. package/dist/queue-receipt.d.ts.map +1 -1
  1060. package/dist/queue-receipt.js +4 -3
  1061. package/dist/queue-receipt.js.map +1 -1
  1062. package/dist/recap-seat.d.ts +28 -0
  1063. package/dist/recap-seat.d.ts.map +1 -0
  1064. package/dist/recap-seat.js +41 -0
  1065. package/dist/recap-seat.js.map +1 -0
  1066. package/dist/seat-attention.d.ts +24 -0
  1067. package/dist/seat-attention.d.ts.map +1 -0
  1068. package/dist/seat-attention.js +119 -0
  1069. package/dist/seat-attention.js.map +1 -0
  1070. package/dist/system-preflight.d.ts.map +1 -1
  1071. package/dist/system-preflight.js +15 -7
  1072. package/dist/system-preflight.js.map +1 -1
  1073. package/dist/terminal-window.d.ts.map +1 -1
  1074. package/dist/terminal-window.js +16 -13
  1075. package/dist/terminal-window.js.map +1 -1
  1076. package/package.json +1 -1
  1077. package/tui/dist/attention/attention-model.d.ts +2 -1
  1078. package/tui/dist/attention/attention-model.d.ts.map +1 -1
  1079. package/tui/dist/attention/attention-model.js +21 -4
  1080. package/tui/dist/attention/attention-model.js.map +1 -1
  1081. package/tui/dist/config/config-model.d.ts.map +1 -1
  1082. package/tui/dist/config/config-model.js +7 -1
  1083. package/tui/dist/config/config-model.js.map +1 -1
  1084. package/tui/dist/config/pairing.d.ts +49 -0
  1085. package/tui/dist/config/pairing.d.ts.map +1 -0
  1086. package/tui/dist/config/pairing.js +98 -0
  1087. package/tui/dist/config/pairing.js.map +1 -0
  1088. package/tui/dist/daemon-client.d.ts +18 -1
  1089. package/tui/dist/daemon-client.d.ts.map +1 -1
  1090. package/tui/dist/daemon-client.js +33 -9
  1091. package/tui/dist/daemon-client.js.map +1 -1
  1092. package/tui/dist/demo-data.js +2 -2
  1093. package/tui/dist/demo-data.js.map +1 -1
  1094. package/tui/dist/detail.d.ts +3 -0
  1095. package/tui/dist/detail.d.ts.map +1 -1
  1096. package/tui/dist/detail.js +6 -1
  1097. package/tui/dist/detail.js.map +1 -1
  1098. package/tui/dist/execution/execution-model.d.ts +2 -0
  1099. package/tui/dist/execution/execution-model.d.ts.map +1 -1
  1100. package/tui/dist/execution/execution-model.js +10 -3
  1101. package/tui/dist/execution/execution-model.js.map +1 -1
  1102. package/tui/dist/health/health-model.d.ts.map +1 -1
  1103. package/tui/dist/health/health-model.js +27 -11
  1104. package/tui/dist/health/health-model.js.map +1 -1
  1105. package/tui/dist/hydrate.d.ts.map +1 -1
  1106. package/tui/dist/hydrate.js +4 -2
  1107. package/tui/dist/hydrate.js.map +1 -1
  1108. package/tui/dist/main.js +11 -2
  1109. package/tui/dist/main.js.map +1 -1
  1110. package/tui/dist/scopes/scopes-model.d.ts +9 -0
  1111. package/tui/dist/scopes/scopes-model.d.ts.map +1 -1
  1112. package/tui/dist/scopes/scopes-model.js +27 -1
  1113. package/tui/dist/scopes/scopes-model.js.map +1 -1
  1114. package/tui/dist/state.d.ts.map +1 -1
  1115. package/tui/dist/state.js +4 -3
  1116. package/tui/dist/state.js.map +1 -1
  1117. package/tui/dist/terminals/open-window.d.ts +21 -1
  1118. package/tui/dist/terminals/open-window.d.ts.map +1 -1
  1119. package/tui/dist/terminals/open-window.js +46 -9
  1120. package/tui/dist/terminals/open-window.js.map +1 -1
  1121. package/tui/dist/terminals/terminal-model.d.ts +8 -1
  1122. package/tui/dist/terminals/terminal-model.d.ts.map +1 -1
  1123. package/tui/dist/terminals/terminal-model.js +25 -8
  1124. package/tui/dist/terminals/terminal-model.js.map +1 -1
  1125. package/tui/dist/types.d.ts +18 -2
  1126. package/tui/dist/types.d.ts.map +1 -1
  1127. package/ui/dist/assets/index-BOYrLyfQ.js +623 -0
  1128. package/ui/dist/assets/index-DqSRu4OY.css +32 -0
  1129. package/ui/dist/index.html +2 -2
  1130. package/ui/dist/assets/index-BFOs3ejL.css +0 -32
  1131. 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";
@@ -35,10 +35,9 @@ import * as path from "node:path";
35
35
  * second one (`recoverAfterRestart`). A prompt or /compact is marked in
36
36
  * flight at its write, so a restart never sends it again. A restart between
37
37
  * a post-compact stage's send and its record can send that one stage again.
38
- * - A /compact whose outcome is unknown owes its restore steps, with or
39
- * without a restart. Its text may wait unsubmitted in the input box, where
40
- * any Enter would submit it, so each step goes only into an empty box and
41
- * is held, visibly, while the box holds text or can't be read.
38
+ * - A /compact whose outcome is unknown is never replayed, with or without
39
+ * a restart. Only its first owed step waits until the recorded possible
40
+ * write clears; subsequent input follows ordinary draft-delivery settings.
42
41
  * - Definite pre-write prep failures retry at most three times. Uncertain
43
42
  * delivery never replays. Unfinished preparation stops visibly until an
44
43
  * explicit retry. A completed automatic map keeps its bounded idle grace.
@@ -65,6 +64,11 @@ export const AUTO_PREP_WAIT_MS_DEFAULT = 25 * 60_000;
65
64
  // How long a stopped attempt holds automatic compaction off for its seat before a fresh attempt may begin. Without it one
66
65
  // failed preparation turned automatic compaction off for the seat until someone noticed. Operational, not measured.
67
66
  export const AUTO_RETRY_AFTER_STOP_MS_DEFAULT = 10 * 60_000;
67
+ /** A held map retires once usage has risen this many points since its request (#2682). Operational, not measured: with the
68
+ * default 80% threshold, 95% is still reachable. */
69
+ export const PREPARED_MAP_MAX_GROWTH_PERCENT = 15;
70
+ /** A held map retires this long after it was first seen ready (#2682). Operational, not measured. */
71
+ export const PREPARED_MAP_MAX_AGE_MS = 2 * 60 * 60_000;
68
72
  const PREP_SEND_ATTEMPTS_MAX = 3;
69
73
  // Slices 13–14 fix — each post-compact back-half send (turn_boundary → restore →
70
74
  // audit) is idle-gated so it cannot be injected into the busy pane right after
@@ -270,9 +274,21 @@ export function buildPostCompactTurnBoundaryPrompt() {
270
274
  "Do not restore yet; the next normal user message will contain the restore instructions.",
271
275
  ].join(" ");
272
276
  }
273
- /** #2575: after this many consecutive idle polls that can't read the box, a post-compaction step goes ahead; a typed
274
- * draft still holds it. Waiting doesn't show the box is empty, so the delivery is recorded as over an unreadable box. */
277
+ /** Legacy #2575 threshold for old diagnostics. Managed input now follows ordinary draft-delivery defaults. */
275
278
  export const UNREADABLE_POLLS_BEFORE_DELIVERY = 2;
279
+ const UNKNOWN_READINESS_POLLS_BEFORE_DELIVERY = 2;
280
+ /** Under --skip-map, a map the seat completed at the attempt path anyway, or null. Nothing publishes the .tmp under
281
+ * --skip-map, so the final path is checked first, then the .tmp, and whichever ends with the marker is named. */
282
+ function completedSkippedMap({ mapPath, marker }) {
283
+ return [mapPath, `${mapPath}.tmp`].find((file) => {
284
+ try {
285
+ return fs.readFileSync(file, "utf8").trimEnd().endsWith(marker);
286
+ }
287
+ catch {
288
+ return false;
289
+ }
290
+ }) ?? null;
291
+ }
276
292
  /** The file, beside an attempt's restore map, where the daemon records what it last did for that attempt. The agent
277
293
  * never writes it. A restarted daemon reads it to pick the attempt up again. */
278
294
  export const COMPACTION_RECORD_FILE = "COMPACTION-STATE.json";
@@ -281,6 +297,11 @@ export const COMPACTION_RECORD_FILE = "COMPACTION-STATE.json";
281
297
  export const RESTART_RECOVERY_WINDOW_MS_DEFAULT = 6 * 60 * 60_000;
282
298
  /** This daemon process. A record this process wrote is its own state, never something to recover. */
283
299
  const DAEMON_PROCESS_ID = randomUUID();
300
+ /** What an automatic attempt returns while it is held, its map complete, until a window opens (#2682). */
301
+ const PREPARED_AWAITING_WINDOW = "prepared_awaiting_window";
302
+ /** Refusals of the /compact before any input that hold a completed map instead of stopping it: a draft in the box (in
303
+ * the receipt or thrown by the guard) and a pane in a tmux mode. Every other refusal stops as before. */
304
+ const HOLD_REASONS = new Set(["draft_input_busy", "draft_input_unknown", "draft_input_changed", "pane_in_mode"]);
284
305
  const RECORD_PHASES = new Set(["preparing", "turn_boundary", "restore_prompt", "compliance_prompt", "compact_uncertain", "done", "ended"]);
285
306
  const RECORD_DELIVERIES = new Set(["pending", "not_sent", "delivered", "uncertain"]);
286
307
  /** A record only in the shape this daemon writes. Any other (a newer daemon's after a rollback, a damaged file) is ignored,
@@ -297,6 +318,12 @@ function readCompactionRecord(file) {
297
318
  && text(r.mapPath) && text(r.marker) && text(r.compactInstruction) && textOrNull(r.preparationRoot) && Number.isFinite(r.updatedAt)
298
319
  && (r.operatorInitiated === undefined || typeof r.operatorInitiated === "boolean") && (r.compactSending === undefined || r.compactSending === true)
299
320
  && (r.uncertainCompact === undefined || r.uncertainCompact === true)
321
+ && (r.prepared === undefined || r.prepared === true) && (r.preparedAt === undefined || Number.isFinite(r.preparedAt))
322
+ && (r.preparedReason === undefined || text(r.preparedReason)) && (r.belowSince === undefined || Number.isFinite(r.belowSince))
323
+ && (r.mapReadyAt === undefined || Number.isFinite(r.mapReadyAt)) && (r.mapUsedPercentage === undefined || Number.isFinite(r.mapUsedPercentage))
324
+ && (r.sessionId === undefined || text(r.sessionId)) && (r.endedAt === undefined || Number.isFinite(r.endedAt))
325
+ && (r.afterEnded === undefined || Number.isFinite(r.afterEnded))
326
+ && (r.afterEndedSessionId === undefined || textOrNull(r.afterEndedSessionId))
300
327
  && (carry === undefined || (typeof carry === "object" && carry !== null && textOrNull(carry.mapPath) && textOrNull(carry.compactInstruction)
301
328
  && (carry.skipMap === undefined || (text(carry.skipMap?.mapPath) && text(carry.skipMap?.marker)))));
302
329
  return valid ? r : null;
@@ -305,8 +332,6 @@ function readCompactionRecord(file) {
305
332
  return null;
306
333
  }
307
334
  }
308
- /** Input-box readings that hold nothing typed: an owed step after an uncertain /compact may go in. A harness suggestion isn't input. */
309
- const INPUT_BOX_CLEAR = new Set(["empty", "likely-suggestion"]);
310
335
  function strandedSummary(record) {
311
336
  return { attemptId: record.attemptId, mapPath: record.mapPath, phase: record.phase, recordedAt: new Date(record.updatedAt).toISOString() };
312
337
  }
@@ -330,6 +355,9 @@ export class ClaudeCompactionEnforcer {
330
355
  postCompactRestoreCooldownUntil = new Map();
331
356
  triggeredAboveThreshold = new Set();
332
357
  pendingPreCompactPrep = new Map();
358
+ /** The seat's last attempt that ended with its request delivered (or possibly delivered) and no /compact (#2682): a fresh
359
+ * automatic preparation for the same occupant and conversation waits for an idle seat. Kept across a restart by the record. */
360
+ lastEnded = new Map();
333
361
  pendingPostCompactRestore = new Map();
334
362
  // OPR.0.4.3.14 — per-seat manual-trigger surfaced state (AC-3). In-memory,
335
363
  // non-persisted (a daemon restart reset is the safe-failure direction).
@@ -344,19 +372,19 @@ export class ClaudeCompactionEnforcer {
344
372
  recovered = new Set();
345
373
  /** Open records too old to resume: the seat's restore may still be owed. */
346
374
  stranded = new Map();
347
- /** Seats whose owed restore steps follow a /compact whose outcome is unknown: its text may wait unsubmitted in the input
348
- * box, where any Enter would submit it, so each step goes only into an empty box. */
375
+ /** Seats whose owed restore steps follow a /compact whose outcome is unknown; never replay that command. */
349
376
  afterUncertainCompact = new Set();
350
- /** What the input box last read for such a seat, before an owed step (absent until the first check). */
351
377
  lastInputBox = new Map();
352
378
  restartRecoveryWindowMs;
353
379
  daemonInstance;
354
380
  resolveOccupantGeneration;
355
381
  onPostRestoreComplete;
382
+ onPreparationFailure;
356
383
  onRestoreDeliveryFailure;
357
384
  terminalPolicies;
358
385
  constructor(settingsStore, sessionTransport, opts) {
359
386
  this.onRestoreDeliveryFailure = opts?.onRestoreDeliveryFailure;
387
+ this.onPreparationFailure = opts?.onPreparationFailure;
360
388
  this.terminalPolicies = opts?.terminalPolicies;
361
389
  this.settingsStore = settingsStore;
362
390
  this.sessionTransport = sessionTransport;
@@ -368,7 +396,8 @@ export class ClaudeCompactionEnforcer {
368
396
  this.now = opts?.now ?? (() => Date.now());
369
397
  this.sleep = opts?.sleep ?? (ms => new Promise(resolve => setTimeout(resolve, ms)));
370
398
  this.postCompactSendWaitMs = opts?.postCompactSendWaitMs ?? POST_COMPACT_SEND_WAIT_MS_DEFAULT;
371
- this.compactSendIdleWaitMs = opts?.compactSendIdleWaitMs ?? 1000;
399
+ // A fresh preparation hook can veto even a visibly idle pane for the full send-readiness window.
400
+ this.compactSendIdleWaitMs = opts?.compactSendIdleWaitMs ?? SEND_READINESS_FRESHNESS_MS;
372
401
  this.restartRecoveryWindowMs = opts?.restartRecoveryWindowMs ?? RESTART_RECOVERY_WINDOW_MS_DEFAULT;
373
402
  this.daemonInstance = opts?.daemonInstance ?? DAEMON_PROCESS_ID;
374
403
  this.resolveOccupantGeneration = opts?.resolveOccupantGeneration;
@@ -381,8 +410,69 @@ export class ClaudeCompactionEnforcer {
381
410
  */
382
411
  async maybeAutoCompact(input) {
383
412
  this.reconcilePreparations();
413
+ const gated = await this.endedAttemptGate(input);
414
+ if (gated)
415
+ return gated;
384
416
  return this.withDeliveryGuard(input, () => this.maybeAutoCompactUnchecked(input));
385
417
  }
418
+ liveGeneration(session) {
419
+ return this.resolveOccupantGeneration?.(session) ?? this.sessionTransport.deliveryGuard?.maybeTarget(session)?.occupant ?? null;
420
+ }
421
+ /** #2682: before a fresh automatic preparation after an attempt that ended with its request delivered, for the same
422
+ * occupant and conversation, the seat must read idle. Runs outside the delivery lease, as the manual path's idle wait. */
423
+ async endedAttemptGate(input) {
424
+ const session = input.sessionName;
425
+ if (input.runtime !== "claude-code" || input.usedPercentage == null)
426
+ return null;
427
+ this.recoverSeat(input);
428
+ const ended = this.lastEnded.get(session);
429
+ if (!ended)
430
+ return null;
431
+ const live = this.liveGeneration(session);
432
+ // A generation that reads unknown for a moment is not another occupant: the ended attempt is kept (below).
433
+ if (ended.occupantGeneration === null || (live !== null && live !== ended.occupantGeneration)
434
+ || (ended.sessionId && input.sessionId && ended.sessionId !== input.sessionId)
435
+ || this.now() - ended.endedAt >= this.restartRecoveryWindowMs) {
436
+ this.lastEnded.delete(session);
437
+ return null;
438
+ }
439
+ let policy;
440
+ try {
441
+ policy = this.settingsStore.resolveClaudeCompactionPolicy();
442
+ }
443
+ catch {
444
+ return null;
445
+ }
446
+ if (!policy.enabled || !isValidThresholdPercent(policy.thresholdPercent) || input.usedPercentage < policy.thresholdPercent)
447
+ return null;
448
+ if (this.pendingPostCompactRestore.has(session))
449
+ return null;
450
+ const attempt = this.pendingPreCompactPrep.get(session);
451
+ // The replacement whose request hasn't gone out yet (a busy send refused it) stays behind the gate.
452
+ const unsentReplacement = attempt?.mode === "automatic" && attempt.status === "sending" && attempt.afterEnded !== undefined;
453
+ if (attempt && !unsentReplacement && (attempt.status !== "stopped" || attempt.cancelled || attempt.compact !== "not_sent"))
454
+ return null;
455
+ // The stopped attempt's cooldown holds after a restart too.
456
+ if (this.now() - ended.endedAt < this.autoRetryAfterStopMs)
457
+ return { triggered: false, reason: "preparation_stopped" };
458
+ // With no occupant to name, no attempt could begin (it would stop as occupant_generation_unavailable and drop this one).
459
+ if (live === null)
460
+ return { triggered: false, reason: "occupant_generation_unavailable" };
461
+ // One readiness read, with no wait after it: this runs inside the monitor's serial poll, so a busy seat must not hold
462
+ // the other seats' polls. A busy seat, or a read that fails, waits for a later poll.
463
+ let idle;
464
+ try {
465
+ idle = await this.sessionTransport.waitUntilIdle(session, CAPTURE_READABLE_BUDGET_MS, undefined, { singleObservation: true, allowDraft: true });
466
+ }
467
+ catch {
468
+ idle = { ok: false };
469
+ }
470
+ if (!idle.ok)
471
+ return { triggered: false, reason: "waiting_for_idle" };
472
+ // The gate is used up only when the replacement request goes out (deliverPreparation), and that send checks idle
473
+ // again: an observation refused as stale, or a peer's turn starting before the send, keeps it.
474
+ return null;
475
+ }
386
476
  /**
387
477
  * What this enforcer has recorded about a managed compaction of `sessionName`, for a sender's context, or null when
388
478
  * none is under way. Read-only: it reports the enforcer's own state (the preparation attempt and the post-compact
@@ -421,6 +511,11 @@ export class ClaudeCompactionEnforcer {
421
511
  this.recoverSeat({ sessionName, ...seat });
422
512
  return this.pendingPostCompactRestore.has(sessionName);
423
513
  }
514
+ /** #2661 (c): since when (epoch ms) a post-compact stage has been owed to this seat — the /compact this daemon sent,
515
+ * or this daemon's recovery of one recorded before a restart (a lower bound then) — or null when none is owed. */
516
+ postCompactStageOwedSince(sessionName) {
517
+ return this.pendingPostCompactRestore.has(sessionName) ? this.lastAutoCompactAt.get(sessionName) ?? null : null;
518
+ }
424
519
  /** The first time this daemon reaches a seat (a poll, a manual request, a state read): pick up its record from before a
425
520
  * restart, with the policy's preparation root (`recoverAfterRestart`). */
426
521
  recoverSeat(seat) {
@@ -435,28 +530,35 @@ export class ClaudeCompactionEnforcer {
435
530
  }
436
531
  /** The restore step OpenRig owes this seat next, or null. After a /compact whose outcome is unknown (see
437
532
  * `afterUncertainCompact`) it also gives what the input box last read (`not_checked` before the first check) and
438
- * whether the step is held for it. */
533
+ * whether the step is held for it. It names the attempt's restore map, which a person's restore notice leaves out. */
439
534
  getOwedRestore(sessionName) {
440
535
  const stage = this.pendingPostCompactRestore.get(sessionName);
441
536
  if (!stage)
442
537
  return null;
443
- const lastDelivery = this.records.get(sessionName)?.record.lastDelivery;
538
+ const record = this.records.get(sessionName)?.record;
539
+ const lastDelivery = record?.lastDelivery;
444
540
  const failed = !!lastDelivery && lastDelivery.failures > 0;
445
- const last = lastDelivery ? { lastDelivery } : {};
541
+ // The map the restore request names: under --skip-map only one the seat completed anyway, never a path with no map.
542
+ // The record keeps the --skip-map choice through every owed stage; the in-memory carry ends once the request lands.
543
+ const skipMap = record?.restoreCarry?.skipMap;
544
+ const mapPath = skipMap ? completedSkippedMap(skipMap) : record?.mapPath;
545
+ const last = { ...(lastDelivery ? { lastDelivery } : {}), ...(mapPath ? { mapPath } : {}) };
446
546
  const steps = { turn_boundary: "post-compaction turn boundary", restore_prompt: "restore request", compliance_prompt: "post-restore audit" };
447
547
  const failure = !lastDelivery ? "" : lastDelivery.reason === "delivered_over_unreadable_input_box"
448
548
  ? ` 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.`
449
- : ` ${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
450
- ? ` 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.` : ""}`;
549
+ : lastDelivery.reason === "delivered_over_unreadable_pane"
550
+ ? ` The ${steps[lastDelivery.stage]} went in at ${lastDelivery.at} over a pane OpenRig couldn't read; its activity remained unknown.`
551
+ : ` ${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
552
+ ? " The operator’s draft-protection settings still apply." : ""}`;
451
553
  const step = steps[stage];
452
554
  if (!this.afterUncertainCompact.has(sessionName)) {
453
- return { stage, held: failed, ...last, detail: `OpenRig owes this seat its ${step} next, sent on a poll once the pane is idle.${failure}` };
555
+ return { stage, held: failed, ...last, detail: `OpenRig owes this seat its ${step} next, sent once the pane is idle or after two consecutive polls cannot determine its activity.${failure}` };
454
556
  }
455
- const inputBox = this.lastInputBox.get(sessionName) ?? "not_checked";
456
- const held = inputBox !== "not_checked" && !INPUT_BOX_CLEAR.has(inputBox);
457
- return { stage, held: held || failed, inputBox, ...last, detail: (held
458
- ? `held: OpenRig owes this seat its restore steps after a /compact whose result was lost, and waits while its input box isn't empty (it reads ${inputBox}). The seat may have /compact text waiting, which any Enter would submit, so check the pane. A seat whose own status line keeps the box unreadable stays held.`
459
- : `OpenRig owes this seat its ${step} next, after a /compact whose result was lost. Each step goes only into an empty input box, sent on a poll once the pane is idle (the box last read ${inputBox}).`) + failure };
557
+ const inputBox = lastDelivery?.inputBox ?? this.lastInputBox.get(sessionName) ?? "not_checked";
558
+ const held = failed || (inputBox !== "not_checked" && inputBox !== "empty" && inputBox !== "likely-suggestion");
559
+ return { stage, held, inputBox, ...last, detail: held
560
+ ? `held: OpenRig may have /compact text waiting from this attempt's uncertain write; any Enter could submit it. The input box reads ${inputBox}; check the pane and reconcile that effect. No command or restore input is replayed.${failure}`
561
+ : `OpenRig owes this seat its ${step} after an uncertain /compact. The outstanding write is checked before any restore Enter; unrelated delivery keeps ordinary draft settings.${failure}` };
460
562
  }
461
563
  /** An open record from before a restart that was too old to resume, while no later attempt has replaced it. */
462
564
  getStrandedCompaction(sessionName) {
@@ -488,20 +590,51 @@ export class ClaudeCompactionEnforcer {
488
590
  return (await this.drainPendingStage(unsampled, policy)) ?? { triggered: false, reason: "no_pending_stage" };
489
591
  });
490
592
  }
491
- /** Finish only an already-armed automatic map when usage has gone stale; never request another preparation. */
593
+ /** Finish only an already-armed automatic map when usage has gone stale; never request another preparation.
594
+ * `lastUsedPercentage` and `sessionId` are the seat's newest sample, however old: a map whose context has since dropped
595
+ * below the threshold, or whose conversation changed (Claude Code's own compaction, a person's /compact or /clear, also
596
+ * while the daemon was down), never compacts (#2682). */
492
597
  async drainPendingPreparedCompact(input) {
493
- const unsampled = { ...input, usedPercentage: null };
598
+ const { lastUsedPercentage, ...rest } = input;
599
+ const unsampled = { ...rest, usedPercentage: null };
494
600
  this.recoverSeat(input);
495
601
  this.reconcilePreparations();
496
602
  const attempt = this.pendingPreCompactPrep.get(input.sessionName);
497
603
  if (input.runtime !== "claude-code" || attempt?.mode !== "automatic" || attempt.status !== "waiting"
498
- || attempt.delivery === "pending" || !this.mapReady(attempt))
604
+ || attempt.delivery === "pending")
499
605
  return { triggered: false, reason: "no_pending_stage" };
500
- if (!isValidThresholdPercent(this.settingsStore.resolveClaudeCompactionPolicy().thresholdPercent))
606
+ const threshold = this.settingsStore.resolveClaudeCompactionPolicy().thresholdPercent;
607
+ if (!isValidThresholdPercent(threshold))
501
608
  return { triggered: false, reason: "invalid_policy" };
609
+ const otherConversation = !!attempt.sessionId && !!input.sessionId && attempt.sessionId !== input.sessionId;
610
+ // Another conversation, known on both sides, ends an armed or held map, as on the fresh path, also one whose map isn't
611
+ // complete yet: a later sample whose conversation reads unknown must not compact with it.
612
+ if (otherConversation && !attempt.compactInFlight) {
613
+ this.stopPreparation(input.sessionName, "below_threshold_while_prepared", attempt);
614
+ return { triggered: false, reason: "preparation_stopped" };
615
+ }
616
+ if (!this.mapReady(attempt))
617
+ return { triggered: false, reason: "no_pending_stage" };
618
+ const dropped = lastUsedPercentage != null && lastUsedPercentage < threshold;
619
+ if (dropped && !attempt.compactInFlight) {
620
+ // A held map ends, as on a fresh dip. An attempt not held keeps its deadline (and a later fresh sample above may
621
+ // still use its map), but a stale sample never compacts it.
622
+ if (attempt.prepared) {
623
+ this.stopPreparation(input.sessionName, "below_threshold_while_prepared", attempt);
624
+ return { triggered: false, reason: "preparation_stopped" };
625
+ }
626
+ return { triggered: false, reason: "below_threshold" };
627
+ }
628
+ // The same growth rule as on a fresh sample: a stale sample (a restart, a slow sidecar) that usage has carried
629
+ // PREPARED_MAP_MAX_GROWTH_PERCENT above the map retires it instead of compacting with it.
630
+ if (attempt.prepared && !attempt.compactInFlight && lastUsedPercentage != null && attempt.mapUsedPercentage !== undefined
631
+ && lastUsedPercentage - attempt.mapUsedPercentage >= PREPARED_MAP_MAX_GROWTH_PERCENT) {
632
+ this.stopPreparation(input.sessionName, "prepared_map_stale", attempt);
633
+ return { triggered: false, reason: "preparation_stopped" };
634
+ }
502
635
  return this.withDeliveryGuard(unsampled, async () => {
503
636
  const result = await this.sendPreparedCompact(unsampled, attempt, false);
504
- return result.ok ? { triggered: true } : { triggered: false, reason: result.reason === "waiting_for_idle" ? "waiting_for_idle" : "send_failed" };
637
+ return result.ok ? { triggered: true } : { triggered: false, reason: result.reason === "waiting_for_idle" || result.reason === PREPARED_AWAITING_WINDOW ? result.reason : "send_failed" };
505
638
  });
506
639
  }
507
640
  terminalPolicyReason(input, actor) {
@@ -548,9 +681,12 @@ export class ClaudeCompactionEnforcer {
548
681
  finally {
549
682
  // The awaited lifecycle has settled: notice work must not inherit its active lease.
550
683
  const lastDelivery = record?.record.lastDelivery;
551
- if (record && lastDelivery && lastDelivery !== previous && lastDelivery.failures >= 2 && this.onRestoreDeliveryFailure) {
684
+ const deliveredUnreadable = lastDelivery?.reason === "delivered_over_unreadable_pane";
685
+ if (record && lastDelivery && lastDelivery !== previous && (lastDelivery.failures >= 2 || deliveredUnreadable) && this.onRestoreDeliveryFailure) {
552
686
  void Promise.resolve().then(() => {
553
- if (this.records.get(input.sessionName) !== record || record.record.lastDelivery !== lastDelivery || this.pendingPostCompactRestore.get(input.sessionName) !== stage)
687
+ const current = this.records.get(input.sessionName);
688
+ if ((current !== record && !(deliveredUnreadable && !current && !this.pendingPostCompactRestore.has(input.sessionName)))
689
+ || record.record.lastDelivery !== lastDelivery || (!deliveredUnreadable && this.pendingPostCompactRestore.get(input.sessionName) !== stage))
554
690
  return;
555
691
  return this.onRestoreDeliveryFailure({ sessionName: input.sessionName, attemptId: record.record.attemptId, mapPath: record.record.mapPath,
556
692
  markerPath: path.join(this.openrigHome, "compaction", "restore-pending", `${sanitizeSessionKey(input.sessionName)}.json`), lastDelivery });
@@ -569,8 +705,9 @@ export class ClaudeCompactionEnforcer {
569
705
  const prior = record.record.lastDelivery;
570
706
  // Active work is the expected wait between restore steps, not an undeliverable stage.
571
707
  const waiting = result.reason === "wait_for_idle_timeout" && result.activity?.state === "running";
572
- // The idle wait passed and the box read neither empty nor typed. A recognised draft, a hold with no reading, or any
573
- // other result breaks the run.
708
+ const unknownReadinessPolls = !result.ok && result.reason === "target_activity_unknown"
709
+ ? (prior?.stage === stage ? prior.unknownReadinessPolls ?? 0 : 0) + 1 : 0;
710
+ // Retain the earlier input-box diagnostic separately from unknown pane readiness.
574
711
  const held = result.heldInputBox;
575
712
  const unreadable = !result.ok && result.reason === "draft_input_unknown" && held && held !== "typed" && held !== "typed-with-suggestion"
576
713
  ? (prior && prior.stage === stage ? prior.unreadable ?? 0 : 0) + 1 : 0;
@@ -580,6 +717,7 @@ export class ClaudeCompactionEnforcer {
580
717
  ...(result.activity ? { activity: { state: result.activity.state, reason: result.activity.reason, evidenceSource: result.activity.evidenceSource } } : {}),
581
718
  ...(errorClass ? { errorClass } : {}), failures: waiting ? 0 : (prior?.failures ?? 0) + 1,
582
719
  ...(held ? { inputBox: held } : {}), ...(unreadable ? { unreadable } : {}),
720
+ ...(unknownReadinessPolls ? { unknownReadinessPolls } : {}),
583
721
  };
584
722
  this.persist(session, record.record.attemptId, { lastDelivery });
585
723
  }
@@ -596,19 +734,18 @@ export class ClaudeCompactionEnforcer {
596
734
  */
597
735
  async drainPendingStage(input, policy) {
598
736
  // A missing or still-high sample need not show that /compact has finished. The newest idle
599
- // hook can predate it, so these drains require a live pane read to establish idle.
737
+ // hook can predate it: require live readiness, then admit only unknown after two consecutive owed-stage polls.
600
738
  const pendingStage = this.pendingPostCompactRestore.get(input.sessionName);
601
739
  const attempt = this.pendingPreCompactPrep.get(input.sessionName);
602
740
  const isCurrent = () => this.pendingPostCompactRestore.get(input.sessionName) === pendingStage
603
741
  && this.pendingPreCompactPrep.get(input.sessionName) === attempt;
604
- // #2575: after enough idle polls that couldn't read the box for this step, the step goes in unless the box reads typed.
605
- // Not after a /compact whose result was lost: there an Enter could submit /compact, so that check below stays strict.
606
- const last = this.records.get(input.sessionName)?.record.lastDelivery;
607
- const overUnreadable = !this.afterUncertainCompact.has(input.sessionName) && !!last && last.stage === pendingStage && !last.ok
608
- && (last.unreadable ?? 0) >= UNREADABLE_POLLS_BEFORE_DELIVERY;
742
+ // Owed input uses the ordinary delivery policy, including the operator's explicit draft protection.
609
743
  const sendOpts = {
610
744
  openrigNotice: true,
611
- preserveInput: overUnreadable ? "typed" : true,
745
+ allowDraftWhileIdle: true,
746
+ ...((this.records.get(input.sessionName)?.record.lastDelivery?.unknownReadinessPolls ?? 0) >= UNKNOWN_READINESS_POLLS_BEFORE_DELIVERY
747
+ ? { allowUnknownWhileIdle: true } : {}),
748
+ ...(pendingStage === "turn_boundary" && this.afterUncertainCompact.has(input.sessionName) ? { preserveInput: true } : {}),
612
749
  beforeWrite: () => {
613
750
  if (!isCurrent())
614
751
  throw new DeliveryGuardError("compaction_cancelled", "Managed compaction was cancelled or replaced; no further input is authorized.");
@@ -643,16 +780,16 @@ export class ClaudeCompactionEnforcer {
643
780
  return { triggered: false, reason: "stale_generation" };
644
781
  }
645
782
  }
646
- // After a /compact whose outcome is unknown, its text may still wait unsubmitted in the input box, and this step's Enter
647
- // would submit it. So each step goes only into a box holding nothing typed (a harness suggestion isn't input); while it
648
- // holds text or can't be read, the step waits for the next poll, and the notice and --state say why.
649
- if (this.afterUncertainCompact.has(input.sessionName)) {
783
+ if (pendingStage === "turn_boundary" && this.afterUncertainCompact.has(input.sessionName)) {
784
+ // Only this attempt's possible /compact write is outstanding. A later Enter must not submit it.
650
785
  const box = await this.inputBoxStatus(input.sessionName);
651
786
  if (!isCurrent())
652
787
  return { triggered: false, reason: "preparation_stopped" };
653
788
  this.lastInputBox.set(input.sessionName, box);
654
- if (!INPUT_BOX_CLEAR.has(box))
789
+ if (box !== "empty" && box !== "likely-suggestion") {
790
+ this.recordRestoreFailure(input.sessionName, pendingStage, this.records.get(input.sessionName), { ok: false, reason: "input_box_not_empty", heldInputBox: box });
655
791
  return { triggered: false, reason: "input_box_not_empty" };
792
+ }
656
793
  }
657
794
  if (pendingStage === "turn_boundary") {
658
795
  // Only this first step after /compact reads past the compaction output that fills the screen above the input box.
@@ -663,6 +800,8 @@ export class ClaudeCompactionEnforcer {
663
800
  // Busy/never-idle → no delivery, no advance; the SAME stage retries next tick.
664
801
  return { triggered: false, reason: "send_failed" };
665
802
  }
803
+ this.afterUncertainCompact.delete(input.sessionName);
804
+ this.lastInputBox.delete(input.sessionName);
666
805
  this.pendingPostCompactRestore.set(input.sessionName, "restore_prompt");
667
806
  this.persistStage(input.sessionName, "restore_prompt", undefined, this.overUnreadableDelivery("turn_boundary", boundary));
668
807
  return { triggered: true };
@@ -724,7 +863,6 @@ export class ClaudeCompactionEnforcer {
724
863
  this.persistStage(input.sessionName, "done", undefined, this.overUnreadableDelivery("compliance_prompt", compliance));
725
864
  this.records.delete(input.sessionName);
726
865
  this.afterUncertainCompact.delete(input.sessionName);
727
- this.lastInputBox.delete(input.sessionName);
728
866
  this.restoreCarry.delete(input.sessionName);
729
867
  // The attempt is finished, including one stopped after a lost /compact result whose restore this was.
730
868
  const finished = this.pendingPreCompactPrep.get(input.sessionName);
@@ -761,11 +899,37 @@ export class ClaudeCompactionEnforcer {
761
899
  return { triggered: false, reason: "invalid_policy" };
762
900
  }
763
901
  this.recoverAfterRestart(input, policy.preparationRoot || null);
902
+ await this.noteEndedPreparation(input, policy);
764
903
  // A trigger sample must not block work already owed to this occupant. Restore reads can
765
904
  // themselves exceed a low threshold; keep the same stage, authorization and idle gates.
766
905
  const drained = await this.drainPendingStage(input, policy);
767
906
  if (drained)
768
907
  return drained;
908
+ // Another conversation, proved by both sample and attempt naming theirs, ends an armed or held automatic attempt, on a
909
+ // 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
910
+ // whose conversation reads unknown must not compact with it.
911
+ // A conversation that reads unknown on either side is not a mismatch.
912
+ const armed = this.pendingPreCompactPrep.get(input.sessionName);
913
+ // A request that never went out was made in no conversation: the attempt takes the sample's, and only a request
914
+ // delivered (or possibly delivered) in another conversation stops it.
915
+ if (armed?.mode === "automatic" && armed.status === "sending" && armed.delivery === "not_sent"
916
+ && !!input.sessionId && armed.sessionId !== input.sessionId) {
917
+ // A replacement moving to another conversation drops the gate it was replacing only when that gate fell in memory on
918
+ // this same sample (endedAttemptGate ran first), so a restart must not bring it back for the new conversation. An
919
+ // ended attempt whose conversation read unknown keeps its gate, and so does the replacement.
920
+ const dropGate = armed.afterEnded !== undefined && !this.lastEnded.has(input.sessionName);
921
+ if (dropGate) {
922
+ armed.afterEnded = undefined;
923
+ armed.afterEndedSessionId = undefined;
924
+ }
925
+ armed.sessionId = input.sessionId;
926
+ this.persist(input.sessionName, armed.attemptId, { sessionId: input.sessionId, ...(dropGate ? { afterEnded: undefined, afterEndedSessionId: undefined } : {}) });
927
+ }
928
+ if (armed?.mode === "automatic" && armed.status === "waiting" && armed.compact === "not_sent" && !armed.compactInFlight
929
+ && !!armed.sessionId && !!input.sessionId && armed.sessionId !== input.sessionId) {
930
+ this.stopPreparation(input.sessionName, "below_threshold_while_prepared", armed);
931
+ return { triggered: false, reason: "preparation_stopped" };
932
+ }
769
933
  if (input.usedPercentage < policy.thresholdPercent) {
770
934
  this.triggeredAboveThreshold.delete(input.sessionName);
771
935
  const preparation = this.pendingPreCompactPrep.get(input.sessionName);
@@ -773,8 +937,20 @@ export class ClaudeCompactionEnforcer {
773
937
  this.pendingPreCompactPrep.delete(input.sessionName);
774
938
  // A usage dip is not cancellation: retain an unfinished attempt and its
775
939
  // deadline so a later high sample can use its map without another prep.
940
+ // A held attempt ends on a fresh sample below the threshold (#2682): the context already dropped, by Claude Code's own
941
+ // compaction or a person's /compact or /clear, so its map would restore a context that is gone. On any other armed
942
+ // automatic attempt the dip is recorded, and such an attempt is never held later: it stops at its deadline as before.
943
+ if (preparation?.prepared && preparation.status === "waiting" && !preparation.compactInFlight) {
944
+ this.stopPreparation(input.sessionName, "below_threshold_while_prepared", preparation);
945
+ }
946
+ else if (preparation?.mode === "automatic" && preparation.status === "waiting" && preparation.compact === "not_sent"
947
+ && preparation.belowSince === undefined) {
948
+ preparation.belowSince = this.now();
949
+ this.persist(input.sessionName, preparation.attemptId, { belowSince: preparation.belowSince });
950
+ }
776
951
  return { triggered: false, reason: "below_threshold" };
777
952
  }
953
+ // A climb back above the threshold keeps the dip's mark (belowSince): the attempt that dipped is never held (#2682).
778
954
  // No new automatic compaction while disabled. An already-owed stage above uses
779
955
  // drainPendingStage's existing operator-initiated manual exemption.
780
956
  if (!policy.enabled) {
@@ -836,9 +1012,15 @@ export class ClaudeCompactionEnforcer {
836
1012
  }
837
1013
  if (attempt.delivery === "pending" || !this.mapReady(attempt))
838
1014
  return { triggered: false, reason: "preparation_pending" };
1015
+ // A held map that usage has outgrown retires; the next idle window prepares afresh (#2682).
1016
+ if (attempt.prepared && attempt.mapUsedPercentage !== undefined
1017
+ && input.usedPercentage - attempt.mapUsedPercentage >= PREPARED_MAP_MAX_GROWTH_PERCENT) {
1018
+ this.stopPreparation(input.sessionName, "prepared_map_stale", attempt);
1019
+ return { triggered: false, reason: "preparation_stopped" };
1020
+ }
839
1021
  const compact = await this.sendPreparedCompact(input, attempt, false);
840
1022
  if (!compact.ok)
841
- return { triggered: false, reason: compact.reason === "waiting_for_idle" ? "waiting_for_idle" : "send_failed" };
1023
+ return { triggered: false, reason: compact.reason === "waiting_for_idle" || compact.reason === PREPARED_AWAITING_WINDOW ? compact.reason : "send_failed" };
842
1024
  return { triggered: true };
843
1025
  }
844
1026
  /**
@@ -919,7 +1101,7 @@ export class ClaudeCompactionEnforcer {
919
1101
  if (remaining <= 0)
920
1102
  return failed(this.mapReady(attempt) ? "map_complete_seat_never_idle" : "preparation_incomplete");
921
1103
  try {
922
- idle = await this.sessionTransport.waitUntilIdle(input.sessionName, remaining, attempt.controller.signal);
1104
+ idle = await this.sessionTransport.waitUntilIdle(input.sessionName, remaining, attempt.controller.signal, { allowDraft: true });
923
1105
  }
924
1106
  catch {
925
1107
  idle = { ok: false, reason: "transport_unavailable" };
@@ -971,6 +1153,17 @@ export class ClaudeCompactionEnforcer {
971
1153
  const stranded = this.stranded.get(input.sessionName);
972
1154
  if (stranded)
973
1155
  attempt.supersedes = strandedSummary(stranded);
1156
+ if (input.sessionId)
1157
+ attempt.sessionId = input.sessionId;
1158
+ // A manual compaction is explicit and replaces the ended attempt at once. An automatic one keeps the gate until its
1159
+ // request goes out (deliverPreparation).
1160
+ if (mode === "manual")
1161
+ this.lastEnded.delete(input.sessionName);
1162
+ else if (this.lastEnded.has(input.sessionName)) {
1163
+ const ended = this.lastEnded.get(input.sessionName);
1164
+ attempt.afterEnded = ended.endedAt;
1165
+ attempt.afterEndedSessionId = ended.sessionId;
1166
+ }
974
1167
  this.pendingPreCompactPrep.set(input.sessionName, attempt);
975
1168
  this.stranded.delete(input.sessionName);
976
1169
  // A map cannot satisfy an unknown occupant. Keep the failed attempt visible and
@@ -1044,8 +1237,10 @@ export class ClaudeCompactionEnforcer {
1044
1237
  }
1045
1238
  };
1046
1239
  // Preserve maps already published by agents using the older protocol.
1047
- if (complete(attempt.mapPath))
1240
+ if (complete(attempt.mapPath)) {
1241
+ this.noteMapReady(attempt);
1048
1242
  return true;
1243
+ }
1049
1244
  const temporary = attempt.mapPath + ".tmp";
1050
1245
  if (!complete(temporary))
1051
1246
  return false;
@@ -1059,8 +1254,19 @@ export class ClaudeCompactionEnforcer {
1059
1254
  return false;
1060
1255
  }
1061
1256
  }
1257
+ this.noteMapReady(attempt);
1062
1258
  return true;
1063
1259
  }
1260
+ /** The first time an attempt's map is seen ready, on any path (#2682): a held map's age counts from here. */
1261
+ noteMapReady(attempt) {
1262
+ if (attempt.mapReadyAt !== undefined)
1263
+ return;
1264
+ attempt.mapReadyAt = this.now();
1265
+ for (const [session, current] of this.pendingPreCompactPrep) {
1266
+ if (current === attempt)
1267
+ this.persist(session, attempt.attemptId, { mapReadyAt: attempt.mapReadyAt });
1268
+ }
1269
+ }
1064
1270
  async deliverPreparation(input, attempt) {
1065
1271
  if (attempt.sends >= PREP_SEND_ATTEMPTS_MAX) {
1066
1272
  this.stopPreparation(input.sessionName, "send_failed");
@@ -1070,6 +1276,9 @@ export class ClaudeCompactionEnforcer {
1070
1276
  // Mark waiting BEFORE the await: concurrent polls cannot replay an in-flight delivery.
1071
1277
  attempt.status = "waiting";
1072
1278
  const policy = this.settingsStore.resolveClaudeCompactionPolicy();
1279
+ // After an ended attempt, the replacement request goes only to a seat the send itself reads idle (a live pane read),
1280
+ // within the /compact send's short wait, so a turn that began after the gate's idle read gets no request (#2682).
1281
+ const idleGate = attempt.afterEnded !== undefined ? { waitForIdleMs: this.compactSendIdleWaitMs + CAPTURE_READABLE_BUDGET_MS, readinessFromPaneOnly: true } : {};
1073
1282
  let prep;
1074
1283
  let marked = false;
1075
1284
  try {
@@ -1078,7 +1287,7 @@ export class ClaudeCompactionEnforcer {
1078
1287
  overflowCompactInstruction: composed.instructionInCommand ? null : attempt.compactInstruction,
1079
1288
  usedPercentage: input.usedPercentage, thresholdPercent: policy.thresholdPercent,
1080
1289
  preCompactInstruction: policy.preCompactInstruction, preparation: attempt, constructedAt: this.now(),
1081
- }), { openrigNotice: true, preserveInput: true, beforeWrite: () => {
1290
+ }), { openrigNotice: true, allowDraftWhileIdle: true, ...idleGate, beforeWrite: () => {
1082
1291
  this.reconcilePreparations();
1083
1292
  if (this.pendingPreCompactPrep.get(input.sessionName) !== attempt || attempt.controller.signal.aborted || attempt.status === "stopped")
1084
1293
  throw new DeliveryGuardError("preparation_stopped", "This compaction attempt ended before preparation input.");
@@ -1108,7 +1317,11 @@ export class ClaudeCompactionEnforcer {
1108
1317
  // Record this attempt's effect even if cancellation/retry happened during the await.
1109
1318
  // Neither a failed response nor its loss proves no paste/Enter. Never replay uncertainty.
1110
1319
  attempt.delivery = prep?.ok && prep.outcome !== "retained" ? "delivered" : notSent ? "not_sent" : "uncertain";
1111
- this.persist(input.sessionName, attempt.attemptId, { delivery: attempt.delivery, sends: attempt.sends });
1320
+ attempt.inputBox = prep?.heldInputBoxReading;
1321
+ this.persist(input.sessionName, attempt.attemptId, { delivery: attempt.delivery, sends: attempt.sends, inputBox: attempt.inputBox });
1322
+ // The replacement request went out (or may have): the ended attempt's gate is used up.
1323
+ if (!notSent && attempt.afterEnded !== undefined && this.pendingPreCompactPrep.get(input.sessionName) === attempt)
1324
+ this.lastEnded.delete(input.sessionName);
1112
1325
  if (this.pendingPreCompactPrep.get(input.sessionName) !== attempt || attempt.controller.signal.aborted)
1113
1326
  return;
1114
1327
  if (notSent) {
@@ -1119,7 +1332,10 @@ export class ClaudeCompactionEnforcer {
1119
1332
  }
1120
1333
  if (attempt.mode === "automatic")
1121
1334
  attempt.deadlineAt = this.now() + AUTO_PREP_WAIT_MS_DEFAULT;
1122
- this.persist(input.sessionName, attempt.attemptId, { deadlineAt: attempt.deadlineAt });
1335
+ // The usage the map is written at: a held map retires once usage has outgrown it (#2682).
1336
+ if (input.usedPercentage != null)
1337
+ attempt.mapUsedPercentage = input.usedPercentage;
1338
+ this.persist(input.sessionName, attempt.attemptId, { deadlineAt: attempt.deadlineAt, mapUsedPercentage: attempt.mapUsedPercentage });
1123
1339
  this.reconcilePreparations();
1124
1340
  }
1125
1341
  async sendPreparedCompact(input, attempt, skipMap) {
@@ -1147,15 +1363,18 @@ export class ClaudeCompactionEnforcer {
1147
1363
  check();
1148
1364
  if (!marked) {
1149
1365
  marked = true;
1366
+ attempt.compactInFlight = true;
1150
1367
  this.persist(input.sessionName, attempt.attemptId, { compactSending: true, restoreCarry: carry, operatorInitiated });
1151
1368
  }
1152
1369
  };
1153
1370
  const send = async () => {
1154
1371
  check();
1155
1372
  // Both paths send only to an idle seat. Include the readable observation's budget in the wait,
1156
- // still bounded by the attempt's existing deadline.
1373
+ // still bounded by the attempt's existing deadline, except for a held attempt: its deadline has no effect
1374
+ // any more, and a capped wait would discard every idle read that ends after it, so the window would never open.
1157
1375
  // Idle comes from a live pane read: the newest hook can predate the rest of the preparation turn.
1158
- 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 } : {}) });
1376
+ const idleWait = this.compactSendIdleWaitMs + CAPTURE_READABLE_BUDGET_MS;
1377
+ return this.sessionTransport.send(input.sessionName, composed.command, { openrigNotice: true, allowDraftWhileIdle: true, beforeWrite, ...(attempt.deadlineAt !== null ? { waitForIdleMs: attempt.prepared ? idleWait : Math.max(1, Math.min(idleWait, this.compactDeadline(attempt) - this.now())), readinessFromPaneOnly: true } : {}) });
1159
1378
  };
1160
1379
  let result;
1161
1380
  let guardRefused = false;
@@ -1171,6 +1390,9 @@ export class ClaudeCompactionEnforcer {
1171
1390
  result = { ok: false, reason: error instanceof DeliveryGuardError ? error.code : "delivery_uncertain",
1172
1391
  ...(written ? { sent: true, inputPhase: "written" } : attempted ? { inputPhase: "attempted" } : {}) };
1173
1392
  }
1393
+ finally {
1394
+ delete attempt.compactInFlight;
1395
+ }
1174
1396
  if (!result.ok || result.outcome === "retained") {
1175
1397
  const phase = result.inputPhase;
1176
1398
  // A write that was issued, or text already in the input, is never "nothing sent".
@@ -1180,11 +1402,20 @@ export class ClaudeCompactionEnforcer {
1180
1402
  const notSent = !writeAttempted && (guardRefused || result.outcome === "retained" || result.sent === false);
1181
1403
  if (notSent && marked)
1182
1404
  this.persist(input.sessionName, attempt.attemptId, { compactSending: undefined });
1405
+ // A completed map whose /compact was refused before any input, for a window that isn't open yet, is held with the
1406
+ // same map instead of stopped and asked for again after the retry cooldown (#2682).
1407
+ // Explicit global draft refusal is reported by the idle preflight, before a draft_* input exception.
1408
+ const policyDraftHold = result.reason === "target_needs_input" && result.activity?.reason === "prompt_draft"
1409
+ && result.activity.evidenceSource === "pane_heuristic" && (result.heldInputBox === "typed" || result.heldInputBox === "typed-with-suggestion");
1410
+ const windowReason = policyDraftHold ? "draft_input_busy" : result.reason;
1411
+ if (notSent && typeof windowReason === "string" && HOLD_REASONS.has(windowReason) && this.holdPrepared(input.sessionName, attempt, windowReason)) {
1412
+ return { ok: false, reason: PREPARED_AWAITING_WINDOW };
1413
+ }
1183
1414
  // Only a known pre-input idle deferral keeps the automatic attempt armed for a later poll; the transport
1184
1415
  // marks those `not_reached`. Reconciliation still bounds the idle grace and stops on an occupant change.
1185
1416
  // A typing-guard draft hold (`draft_*`) is `not_reached` too, but it is a refusal, not an idle wait: it stops
1186
1417
  // as not sent, and a fresh attempt may begin after the retry cooldown.
1187
- const draftHold = typeof result.reason === "string" && result.reason.startsWith("draft_");
1418
+ const draftHold = policyDraftHold || (typeof result.reason === "string" && result.reason.startsWith("draft_"));
1188
1419
  if (attempt.mode === "automatic" && attempt.status === "waiting" && notSent && phase === "not_reached" && !draftHold) {
1189
1420
  return { ok: false, reason: "waiting_for_idle" };
1190
1421
  }
@@ -1209,12 +1440,11 @@ export class ClaudeCompactionEnforcer {
1209
1440
  this.persist(input.sessionName, attempt.attemptId, { phase: "turn_boundary", restoreCarry: carry, operatorInitiated });
1210
1441
  return { ok: true };
1211
1442
  }
1212
- /** What the seat's input box holds now, as `rig capture --json` reads it (`empty`, `likely-suggestion`, `typed`, ...), or
1213
- * why it couldn't be read. Never throws. */
1443
+ /** Reconcile this attempt's possible write using the existing capture path. Unknown is not a resolved write. */
1214
1444
  async inputBoxStatus(sessionName) {
1215
1445
  try {
1216
1446
  const capture = await this.sessionTransport.capture(sessionName, { inputBox: true, readable: { width: 120, height: 40 } });
1217
- return capture.inputBox?.status ?? capture.reason ?? "unknown";
1447
+ return capture.inputBox?.status ?? "unknown";
1218
1448
  }
1219
1449
  catch {
1220
1450
  return "unknown";
@@ -1229,25 +1459,17 @@ export class ClaudeCompactionEnforcer {
1229
1459
  this.restoreCarry.delete(sessionName);
1230
1460
  this.lastAutoCompactAt.set(sessionName, this.now());
1231
1461
  this.triggeredAboveThreshold.add(sessionName);
1462
+ this.lastEnded.delete(sessionName);
1232
1463
  this.pendingPostCompactRestore.set(sessionName, "turn_boundary");
1233
1464
  this.pendingStageGeneration.set(sessionName, attempt.occupantGeneration);
1234
1465
  }
1235
- /** The map the restore request names. With --skip-map: a map the seat completed at the attempt path
1236
- * anyway, or a plain statement that none was required. Nothing publishes the .tmp under --skip-map, so
1237
- * the final path is checked first, then the .tmp, and whichever ends with the marker is named. */
1466
+ /** The map the restore request names. With --skip-map: a map the seat completed anyway (`completedSkippedMap`),
1467
+ * or a plain statement that none was required. */
1238
1468
  restoreMapFields(sessionName) {
1239
1469
  const carry = this.restoreCarry.get(sessionName);
1240
1470
  if (!carry?.skipMap)
1241
1471
  return { attemptMapPath: carry?.mapPath ?? null, noMapRequired: false };
1242
- const { mapPath, marker } = carry.skipMap;
1243
- const completed = [mapPath, `${mapPath}.tmp`].find((file) => {
1244
- try {
1245
- return fs.readFileSync(file, "utf8").trimEnd().endsWith(marker);
1246
- }
1247
- catch {
1248
- return false;
1249
- }
1250
- });
1472
+ const completed = completedSkippedMap(carry.skipMap);
1251
1473
  return completed ? { attemptMapPath: completed, noMapRequired: false } : { attemptMapPath: null, noMapRequired: true };
1252
1474
  }
1253
1475
  /** Reuse the retry interval a new automatic preparation would otherwise wait through. The original deadline stays
@@ -1270,20 +1492,52 @@ export class ClaudeCompactionEnforcer {
1270
1492
  this.stopPreparation(session, "stale_generation");
1271
1493
  else if (!enabled && (attempt.mode === "automatic" || attempt.policyWasEnabled))
1272
1494
  this.stopPreparation(session, "disabled");
1273
- else if (attempt.deadlineAt !== null && this.now() >= this.compactDeadline(attempt)) {
1274
- this.stopPreparation(session, this.mapReady(attempt) ? "map_complete_seat_never_idle" : "preparation_incomplete");
1495
+ // A held map that stopped reading ready (its file or marker gone) stops the attempt (#2682).
1496
+ else if (attempt.prepared && !attempt.compactInFlight && !this.mapReady(attempt))
1497
+ this.stopPreparation(session, "preparation_incomplete");
1498
+ // A held map retires after a long while; a /compact already being written is never stopped (#2682).
1499
+ else if (attempt.prepared && !attempt.compactInFlight && this.now() - (attempt.mapReadyAt ?? attempt.preparedAt ?? this.now()) >= PREPARED_MAP_MAX_AGE_MS) {
1500
+ this.stopPreparation(session, "prepared_map_stale");
1501
+ }
1502
+ // A held attempt's deadline has no effect: it ends only as above, on a fresh dip, a stale map or a cancel (#2682).
1503
+ else if (!attempt.prepared && attempt.deadlineAt !== null && this.now() >= this.compactDeadline(attempt)) {
1504
+ const ready = this.mapReady(attempt);
1505
+ if (!(ready && this.holdPrepared(session, attempt, "map_complete_seat_never_idle"))) {
1506
+ this.stopPreparation(session, ready ? "map_complete_seat_never_idle" : "preparation_incomplete");
1507
+ }
1275
1508
  }
1276
1509
  if (enabled)
1277
1510
  attempt.policyWasEnabled = true;
1278
1511
  }
1279
1512
  }
1513
+ /** Hold an automatic attempt whose map is complete until a window opens, instead of stopping it (#2682). Only the
1514
+ * attempt that is current, armed and untouched: never one cancelled, stopped, manual, or with a /compact sent or in
1515
+ * flight. It keeps its controller, map and deadline, and is persisted only on the transition. */
1516
+ holdPrepared(session, attempt, reason) {
1517
+ if (attempt.mode !== "automatic" || attempt.status !== "waiting" || attempt.compact !== "not_sent" || attempt.compactInFlight
1518
+ || attempt.controller.signal.aborted || attempt.cancelled || attempt.reason !== undefined || attempt.belowSince !== undefined
1519
+ || this.pendingPreCompactPrep.get(session) !== attempt || !this.mapReady(attempt))
1520
+ return false;
1521
+ if (!attempt.prepared) {
1522
+ attempt.prepared = true;
1523
+ attempt.preparedAt = this.now();
1524
+ attempt.preparedReason = reason;
1525
+ this.persist(session, attempt.attemptId, { prepared: true, preparedAt: attempt.preparedAt, preparedReason: reason });
1526
+ }
1527
+ return true;
1528
+ }
1280
1529
  /** Start the record for a new attempt, beside its map. */
1281
1530
  startRecord(sessionName, attempt) {
1531
+ const previous = this.records.get(sessionName)?.record;
1532
+ const preparationFailures = attempt.mode === "automatic" && previous?.occupantGeneration === attempt.occupantGeneration
1533
+ ? previous?.preparationFailures : undefined;
1282
1534
  this.records.set(sessionName, { file: path.join(path.dirname(attempt.mapPath), COMPACTION_RECORD_FILE), record: {
1283
1535
  daemon: this.daemonInstance, attemptId: attempt.attemptId, session: sessionName, occupantGeneration: attempt.occupantGeneration, mode: attempt.mode,
1284
- phase: "preparing", delivery: attempt.delivery, deadlineAt: attempt.deadlineAt, sends: attempt.sends,
1536
+ phase: "preparing", delivery: attempt.delivery, deadlineAt: attempt.deadlineAt, sends: attempt.sends, preparationFailures,
1285
1537
  mapPath: attempt.mapPath, marker: attempt.marker, compactInstruction: attempt.compactInstruction,
1286
- preparationRoot: attempt.preparationRoot, updatedAt: this.now(),
1538
+ preparationRoot: attempt.preparationRoot, ...(attempt.sessionId ? { sessionId: attempt.sessionId } : {}),
1539
+ ...(attempt.afterEnded !== undefined ? { afterEnded: attempt.afterEnded, afterEndedSessionId: attempt.afterEndedSessionId ?? null } : {}),
1540
+ updatedAt: this.now(),
1287
1541
  } });
1288
1542
  this.persist(sessionName, attempt.attemptId, {});
1289
1543
  }
@@ -1311,8 +1565,11 @@ export class ClaudeCompactionEnforcer {
1311
1565
  if (current)
1312
1566
  this.persist(sessionName, current.record.attemptId, { phase, ...(reason !== undefined ? { reason } : {}), lastDelivery });
1313
1567
  }
1314
- /** A step that went in over a box OpenRig couldn't read stays on the record as that (#2575); any other advance clears it. */
1568
+ /** An unreadable pane or input box stays explicit on the delivered step; any other advance clears it. */
1315
1569
  overUnreadableDelivery(stage, result) {
1570
+ if (result.activity?.state === "unknown")
1571
+ return { stage, at: new Date(this.now()).toISOString(), ok: true,
1572
+ reason: "delivered_over_unreadable_pane", activity: { state: "unknown", reason: result.activity.reason, evidenceSource: result.activity.evidenceSource }, failures: 0 };
1316
1573
  return result.pastedOverInputBox ? { stage, at: new Date(this.now()).toISOString(), ok: true,
1317
1574
  reason: "delivered_over_unreadable_input_box", inputBox: result.pastedOverInputBox, failures: 0 } : undefined;
1318
1575
  }
@@ -1362,19 +1619,48 @@ export class ClaudeCompactionEnforcer {
1362
1619
  return;
1363
1620
  const { record } = newest;
1364
1621
  // This process's own record (another enforcer in it) is live state, not a predecessor's.
1365
- if (record.daemon === this.daemonInstance || record.phase === "done" || record.phase === "ended")
1622
+ if (record.daemon === this.daemonInstance || record.phase === "done")
1366
1623
  return;
1367
1624
  const live = this.resolveOccupantGeneration?.(session) ?? this.sessionTransport.deliveryGuard?.maybeTarget(session)?.occupant ?? null;
1625
+ if (record.phase === "ended") {
1626
+ if (record.occupantGeneration !== null && live === record.occupantGeneration
1627
+ && this.now() - (record.endedAt ?? record.updatedAt) < this.restartRecoveryWindowMs)
1628
+ this.records.set(session, newest);
1629
+ // An ended automatic attempt of this occupant whose request was delivered and whose /compact was never sent keeps a
1630
+ // busy seat from a fresh request (#2682), as in memory. Only a stop writes endedAt; a /compact that was sent (and then
1631
+ // cancelled) never stopped, and one whose result was lost is marked uncertainCompact.
1632
+ const endedAt = record.endedAt;
1633
+ if (endedAt !== undefined && !record.uncertainCompact && !record.compactSending
1634
+ && record.mode === "automatic" && (record.delivery === "delivered" || record.delivery === "uncertain")
1635
+ // An occupant that reads unknown at this first look keeps the record, inert: the gate compares the generation once
1636
+ // it can be read, and a different occupant then discards it.
1637
+ && record.occupantGeneration !== null && (live === null || live === record.occupantGeneration)
1638
+ && this.now() - endedAt < this.restartRecoveryWindowMs)
1639
+ this.lastEnded.set(session, { endedAt, occupantGeneration: record.occupantGeneration, sessionId: record.sessionId ?? null });
1640
+ // A replacement that stopped with its request never sent keeps the gate of the attempt it replaced, as in memory and
1641
+ // as a replacement still preparing does below.
1642
+ else if (record.mode === "automatic" && record.afterEnded !== undefined && record.delivery === "not_sent"
1643
+ && record.occupantGeneration !== null && (live === null || live === record.occupantGeneration)
1644
+ && this.now() - record.afterEnded < this.restartRecoveryWindowMs) {
1645
+ this.lastEnded.set(session, { endedAt: record.afterEnded, occupantGeneration: record.occupantGeneration, sessionId: record.afterEndedSessionId ?? null });
1646
+ }
1647
+ return;
1648
+ }
1368
1649
  if (record.occupantGeneration !== null && live !== null && live !== record.occupantGeneration)
1369
1650
  return;
1370
1651
  const stale = this.now() - record.updatedAt > this.restartRecoveryWindowMs;
1371
1652
  // A /compact whose send had begun, or whose outcome was lost, is never sent again; its restore steps are owed in case it
1372
- // ran, each only into an empty input box. The restore request tells a seat that didn't compact to say so and skip.
1653
+ // ran. Only the first step reconciles that possible write; later input follows ordinary delivery settings.
1373
1654
  const phase = (record.phase === "preparing" && record.compactSending) || record.phase === "compact_uncertain" ? "turn_boundary" : record.phase;
1374
1655
  const inFlight = phase !== record.phase;
1375
1656
  if (phase === "preparing") {
1376
- if (stale)
1377
- return; // Its preparation deadline passed long ago; a fresh attempt may begin.
1657
+ // Its preparation deadline passed long ago; a fresh attempt may begin. A held attempt of this same occupant has no
1658
+ // deadline that matters: it is picked up as it was, however old, and the reconcile below retires its map once it is
1659
+ // too old (#2682). One whose context dropped before it was held never comes back held.
1660
+ const held = record.prepared === true && record.mode === "automatic" && record.deadlineAt !== null && record.belowSince === undefined;
1661
+ const heldHere = held && record.occupantGeneration !== null && live === record.occupantGeneration;
1662
+ if (stale && !heldHere)
1663
+ return;
1378
1664
  this.records.set(session, newest);
1379
1665
  this.pendingPreCompactPrep.set(session, {
1380
1666
  policyActor: { source: "openrig" }, attemptId: record.attemptId, occupantGeneration: record.occupantGeneration,
@@ -1384,10 +1670,25 @@ export class ClaudeCompactionEnforcer {
1384
1670
  compact: "not_sent", sends: record.sends,
1385
1671
  deadlineAt: record.deadlineAt ?? (record.delivery === "not_sent" ? null : record.updatedAt + AUTO_PREP_WAIT_MS_DEFAULT),
1386
1672
  policyWasEnabled: true, preparationRoot: record.preparationRoot, controller: new AbortController(),
1387
- compactInstruction: record.compactInstruction,
1673
+ compactInstruction: record.compactInstruction, inputBox: record.inputBox,
1674
+ // A held attempt comes back held, with its recorded hold (never stamped again) and its map's age and usage.
1675
+ ...(held ? { prepared: true, preparedAt: record.preparedAt ?? record.updatedAt, preparedReason: record.preparedReason ?? "map_complete_seat_never_idle" } : {}),
1676
+ ...(held ? { mapReadyAt: record.mapReadyAt ?? record.preparedAt ?? record.updatedAt } : record.mapReadyAt !== undefined ? { mapReadyAt: record.mapReadyAt } : {}),
1677
+ ...(record.mapUsedPercentage !== undefined ? { mapUsedPercentage: record.mapUsedPercentage } : {}),
1678
+ ...(record.sessionId !== undefined ? { sessionId: record.sessionId } : {}),
1679
+ ...(record.mode === "automatic" && record.belowSince !== undefined ? { belowSince: record.belowSince } : {}),
1680
+ ...(record.mode === "automatic" && record.afterEnded !== undefined ? { afterEnded: record.afterEnded, afterEndedSessionId: record.afterEndedSessionId ?? null } : {}),
1388
1681
  });
1682
+ // A replacement whose request never went out keeps the ended attempt's gate, as in memory.
1683
+ if (record.mode === "automatic" && record.afterEnded !== undefined && record.delivery === "not_sent" && record.occupantGeneration !== null
1684
+ && this.now() - record.afterEnded < this.restartRecoveryWindowMs) {
1685
+ this.lastEnded.set(session, { endedAt: record.afterEnded, occupantGeneration: record.occupantGeneration, sessionId: record.afterEndedSessionId ?? null });
1686
+ }
1389
1687
  if (record.mode === "manual")
1390
1688
  this.stopPreparation(session, "daemon_restarted");
1689
+ // A held map of any age is checked at once, without waiting for a send's checks (#2682).
1690
+ else
1691
+ this.reconcilePreparations();
1391
1692
  return;
1392
1693
  }
1393
1694
  if (stale) {
@@ -1398,7 +1699,8 @@ export class ClaudeCompactionEnforcer {
1398
1699
  this.pendingPostCompactRestore.set(session, phase);
1399
1700
  this.pendingStageGeneration.set(session, record.occupantGeneration);
1400
1701
  if (inFlight || record.uncertainCompact) {
1401
- this.afterUncertainCompact.add(session);
1702
+ if (phase === "turn_boundary")
1703
+ this.afterUncertainCompact.add(session);
1402
1704
  this.persist(session, record.attemptId, { uncertainCompact: true });
1403
1705
  }
1404
1706
  if (record.restoreCarry)
@@ -1410,6 +1712,49 @@ export class ClaudeCompactionEnforcer {
1410
1712
  this.setManualStage(session, phase === "compliance_prompt" ? "restore-sent" : "compact-sent", undefined, record.operatorInitiated);
1411
1713
  }
1412
1714
  }
1715
+ /** Count ended attempts, never individual send calls. The current attempt record carries the run across restarts. */
1716
+ async noteEndedPreparation(input, policy) {
1717
+ const current = this.records.get(input.sessionName);
1718
+ if (!current)
1719
+ return;
1720
+ const r = current.record, generation = this.liveGeneration(input.sessionName);
1721
+ const interrupted = this.pendingPreCompactPrep.get(input.sessionName)?.cancelled || !policy.enabled || input.usedPercentage == null || input.usedPercentage < policy.thresholdPercent
1722
+ || r.mode !== "automatic" || generation === null || generation !== r.occupantGeneration
1723
+ || (r.sessionId && input.sessionId && r.sessionId !== input.sessionId)
1724
+ || r.delivery !== "not_sent" || r.belowSince !== undefined || r.compactSending || r.uncertainCompact
1725
+ || ["preparation_cancelled", "preparation_replaced", "stale_generation", "disabled", "daemon_restarted",
1726
+ "below_threshold_while_prepared", "prepared_map_stale", "occupant_generation_unavailable"].includes(r.reason ?? "");
1727
+ if (interrupted) {
1728
+ if (r.preparationFailures)
1729
+ this.persist(input.sessionName, r.attemptId, { preparationFailures: undefined });
1730
+ return;
1731
+ }
1732
+ if (r.phase !== "ended" || r.endedAt === undefined || r.sends === 0)
1733
+ return;
1734
+ const old = r.preparationFailures;
1735
+ const run = old && Number.isSafeInteger(old.endedAttempts) && old.endedAttempts >= 0
1736
+ && typeof old.lastAttemptId === "string" && (old.sessionId === null || typeof old.sessionId === "string")
1737
+ && old.occupantGeneration === generation
1738
+ && (!old.sessionId || !input.sessionId || old.sessionId === input.sessionId) ? old
1739
+ : { occupantGeneration: generation, sessionId: input.sessionId ?? null, endedAttempts: 0, lastAttemptId: "" };
1740
+ if (run.lastAttemptId !== r.attemptId) {
1741
+ run.lastAttemptId = r.attemptId;
1742
+ run.endedAttempts++;
1743
+ this.persist(input.sessionName, r.attemptId, { preparationFailures: run });
1744
+ }
1745
+ if (run.endedAttempts < 3 || run.reportedAttempts === run.endedAttempts || !this.onPreparationFailure)
1746
+ return;
1747
+ try {
1748
+ await this.onPreparationFailure({ sessionName: input.sessionName, occupantGeneration: generation,
1749
+ attemptId: r.attemptId, mapPath: r.mapPath, statePath: current.file, endedAttempts: run.endedAttempts,
1750
+ reason: r.reason ?? "send_failed", ...(r.inputBox ? { inputBox: r.inputBox } : {}) });
1751
+ if (this.records.get(input.sessionName) === current && current.record.preparationFailures === run) {
1752
+ run.reportedAttempts = run.endedAttempts;
1753
+ this.persist(input.sessionName, r.attemptId, { preparationFailures: run });
1754
+ }
1755
+ }
1756
+ catch { /* The same diagnostic stays eligible on existing polls; no input effect or new scheduler. */ }
1757
+ }
1413
1758
  stopPreparation(session, reason, expected) {
1414
1759
  const attempt = this.pendingPreCompactPrep.get(session);
1415
1760
  if ((expected && expected !== attempt) || !attempt || attempt.status === "stopped" || attempt.status === "compact-sent")
@@ -1418,7 +1763,14 @@ export class ClaudeCompactionEnforcer {
1418
1763
  attempt.reason = reason;
1419
1764
  attempt.stoppedAt = this.now();
1420
1765
  attempt.controller.abort();
1421
- this.persist(session, attempt.attemptId, { phase: attempt.compact === "uncertain" ? "compact_uncertain" : "ended", reason });
1766
+ // A stopped attempt is no longer held (#2682).
1767
+ const wasPrepared = attempt.prepared === true;
1768
+ delete attempt.prepared;
1769
+ this.persist(session, attempt.attemptId, { phase: attempt.compact === "uncertain" ? "compact_uncertain" : "ended", reason, endedAt: attempt.stoppedAt,
1770
+ ...(wasPrepared ? { prepared: undefined } : {}) });
1771
+ if (attempt.mode === "automatic" && (attempt.delivery === "delivered" || attempt.delivery === "uncertain") && attempt.compact === "not_sent") {
1772
+ this.lastEnded.set(session, { endedAt: attempt.stoppedAt, occupantGeneration: attempt.occupantGeneration, sessionId: attempt.sessionId ?? null });
1773
+ }
1422
1774
  if (attempt.mode === "manual")
1423
1775
  this.setManualStage(session, "skipped-or-failed", reason);
1424
1776
  }
@@ -1426,6 +1778,10 @@ export class ClaudeCompactionEnforcer {
1426
1778
  const attempt = this.pendingPreCompactPrep.get(session);
1427
1779
  if (attempt)
1428
1780
  attempt.cancelled = true;
1781
+ const record = this.records.get(session)?.record;
1782
+ if (record)
1783
+ this.persist(session, record.attemptId, { preparationFailures: undefined,
1784
+ ...(!attempt && record.phase === "ended" ? { reason: "preparation_cancelled" } : {}) });
1429
1785
  if (attempt?.status === "compact-sent" || this.pendingPostCompactRestore.has(session)) {
1430
1786
  // Abandon management, not the provider command: keep its unconfirmed receipt and map.
1431
1787
  // Do not clear automatic dedup/re-arm state or send any input. A later explicit retry
@@ -1456,8 +1812,9 @@ export class ClaudeCompactionEnforcer {
1456
1812
  const attempt = this.pendingPreCompactPrep.get(session);
1457
1813
  if (!attempt)
1458
1814
  return null;
1459
- const { controller: _controller, sends: _sends, policyWasEnabled: _enabled, preparationRoot: _preparationRoot, compactInstruction: _instruction, stoppedAt: _stoppedAt, cancelled: _cancelled, ...state } = attempt;
1460
- return { ...state, ...(attempt.mode === "automatic" && attempt.deadlineAt !== null && this.mapReady(attempt)
1815
+ 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;
1816
+ // A held attempt has no idle deadline left to show: it waits for its window.
1817
+ return { ...state, ...(attempt.mode === "automatic" && !attempt.prepared && attempt.deadlineAt !== null && this.mapReady(attempt)
1461
1818
  ? { idleDeadlineAt: this.compactDeadline(attempt) } : {}) };
1462
1819
  }
1463
1820
  /** OPR.0.4.3.14 — read the surfaced manual-trigger state for a seat (AC-3). */
@@ -1474,6 +1831,7 @@ export class ClaudeCompactionEnforcer {
1474
1831
  */
1475
1832
  invalidateOccupant(sessionName) {
1476
1833
  this.stopPreparation(sessionName, "stale_generation");
1834
+ this.lastEnded.delete(sessionName);
1477
1835
  this.persistStage(sessionName, "ended");
1478
1836
  this.records.delete(sessionName);
1479
1837
  this.stranded.delete(sessionName);