@openrig/cli 0.7.17 → 0.7.18

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 (657) hide show
  1. package/README.md +5 -5
  2. package/daemon/assets/plugins/openrig/.claude-plugin/plugin.json +1 -1
  3. package/daemon/assets/plugins/openrig/.codex-plugin/plugin.json +1 -1
  4. package/daemon/assets/plugins/openrig/.cursor-plugin/plugin.json +1 -1
  5. package/daemon/assets/plugins/openrig/plugin.json +1 -1
  6. package/daemon/assets/plugins/openrig-core/.claude-plugin/plugin.json +1 -1
  7. package/daemon/assets/plugins/openrig-core/.codex-plugin/plugin.json +1 -1
  8. package/daemon/assets/plugins/openrig-core/hooks/scripts/refocus.cjs +5 -0
  9. package/daemon/assets/plugins/openrig-core/skills/messaging-the-human/SKILL.md +23 -0
  10. package/daemon/assets/plugins/openrig-core/skills/openrig-user/SKILL.md +11 -0
  11. package/daemon/assets/plugins/openrig-core/skills/refocusing/scripts/trace-to-root.py +25 -5
  12. package/daemon/assets/skills/rigs/SKILL.md +33 -19
  13. package/daemon/assets/skills/rigs/references/installing-for-someone.md +2 -2
  14. package/daemon/context-packs/help/manifest.yaml +1 -1
  15. package/daemon/context-packs/onboarding-width/manifest.yaml +1 -1
  16. package/daemon/context-packs/onboarding-width/public-what-you-can-do.md +42 -8
  17. package/daemon/context-packs/reference/getting-started.md +4 -4
  18. package/daemon/context-packs/reference/manifest.yaml +1 -1
  19. package/daemon/context-packs/reference/rig-spec.md +166 -0
  20. package/daemon/context-packs/reference/whats-new.md +107 -6
  21. package/daemon/context-packs/skills/agent-operated-software/manifest.yaml +1 -1
  22. package/daemon/context-packs/skills/agent-operated-workflows/manifest.yaml +1 -1
  23. package/daemon/context-packs/skills/applying-a-permission-policy/manifest.yaml +1 -1
  24. package/daemon/context-packs/skills/claude-compaction-restore/manifest.yaml +1 -1
  25. package/daemon/context-packs/skills/core/agent-starters/manifest.yaml +1 -1
  26. package/daemon/context-packs/skills/core/agent-startup-and-context-ingestion/manifest.yaml +1 -1
  27. package/daemon/context-packs/skills/core/cross-host-rig-commands/manifest.yaml +1 -1
  28. package/daemon/context-packs/skills/core/human-in-the-loop/manifest.yaml +1 -1
  29. package/daemon/context-packs/skills/core/messaging-the-human/SKILL.md +23 -0
  30. package/daemon/context-packs/skills/core/messaging-the-human/manifest.yaml +1 -1
  31. package/daemon/context-packs/skills/core/openrig-architect/manifest.yaml +1 -1
  32. package/daemon/context-packs/skills/core/openrig-cmux/manifest.yaml +1 -1
  33. package/daemon/context-packs/skills/core/openrig-herdr/manifest.yaml +1 -1
  34. package/daemon/context-packs/skills/core/openrig-skills/manifest.yaml +1 -1
  35. package/daemon/context-packs/skills/core/openrig-software-factory/manifest.yaml +1 -1
  36. package/daemon/context-packs/skills/core/openrig-upgrade/manifest.yaml +1 -1
  37. package/daemon/context-packs/skills/core/rig-bundles-and-shareable-artifacts/manifest.yaml +1 -1
  38. package/daemon/context-packs/skills/core/rig-lifecycle/manifest.yaml +1 -1
  39. package/daemon/context-packs/skills/core/session-source-fork/manifest.yaml +1 -1
  40. package/daemon/context-packs/skills/core/specification-system/manifest.yaml +1 -1
  41. package/daemon/context-packs/skills/core/topology-mutation-and-seat-management/manifest.yaml +1 -1
  42. package/daemon/context-packs/skills/core/watchdog/manifest.yaml +1 -1
  43. package/daemon/context-packs/skills/core/working-with-an-openrig-team/manifest.yaml +1 -1
  44. package/daemon/context-packs/skills/delegating-work/manifest.yaml +1 -1
  45. package/daemon/context-packs/skills/forming-an-openrig-mental-model/manifest.yaml +1 -1
  46. package/daemon/context-packs/skills/loading-addressable-markdown/manifest.yaml +1 -1
  47. package/daemon/context-packs/skills/mission-slice-sop/manifest.yaml +1 -1
  48. package/daemon/context-packs/skills/openrig-operating-model/manifest.yaml +1 -1
  49. package/daemon/context-packs/skills/openrig-user/SKILL.md +11 -0
  50. package/daemon/context-packs/skills/openrig-user/manifest.yaml +1 -1
  51. package/daemon/context-packs/skills/orienting-to-an-inherited-seat/manifest.yaml +1 -1
  52. package/daemon/context-packs/skills/pm/backlog-capture/manifest.yaml +1 -1
  53. package/daemon/context-packs/skills/pm/context-builder/manifest.yaml +1 -1
  54. package/daemon/context-packs/skills/pm/exec-summary/manifest.yaml +1 -1
  55. package/daemon/context-packs/skills/pm/office-hours/manifest.yaml +1 -1
  56. package/daemon/context-packs/skills/pm/plan-review/manifest.yaml +1 -1
  57. package/daemon/context-packs/skills/pm/requirements-writer/manifest.yaml +1 -1
  58. package/daemon/context-packs/skills/pm/ui-mockup/manifest.yaml +1 -1
  59. package/daemon/context-packs/skills/pods/development-team/manifest.yaml +1 -1
  60. package/daemon/context-packs/skills/pods/orchestration-team/manifest.yaml +1 -1
  61. package/daemon/context-packs/skills/pods/oversight-team/manifest.yaml +1 -1
  62. package/daemon/context-packs/skills/pods/review-team/manifest.yaml +1 -1
  63. package/daemon/context-packs/skills/process/agent-browser/manifest.yaml +1 -1
  64. package/daemon/context-packs/skills/process/context-engineering/manifest.yaml +1 -1
  65. package/daemon/context-packs/skills/process/dogfood/manifest.yaml +1 -1
  66. package/daemon/context-packs/skills/process/frontend-design/manifest.yaml +1 -1
  67. package/daemon/context-packs/skills/process/systematic-debugging/manifest.yaml +1 -1
  68. package/daemon/context-packs/skills/process/test-driven-development/manifest.yaml +1 -1
  69. package/daemon/context-packs/skills/process/verification-before-completion/manifest.yaml +1 -1
  70. package/daemon/context-packs/skills/queue-handoff/manifest.yaml +1 -1
  71. package/daemon/context-packs/skills/refocusing/manifest.yaml +1 -1
  72. package/daemon/context-packs/skills/refocusing/scripts/trace-to-root.py +25 -5
  73. package/daemon/context-packs/skills/retiring-and-inheriting-a-seat/manifest.yaml +1 -1
  74. package/daemon/context-packs/skills/seat-continuity-and-handover/manifest.yaml +1 -1
  75. package/daemon/context-packs/skills/session-compaction-and-restore/manifest.yaml +1 -1
  76. package/daemon/context-packs/skills/software-for-agents/manifest.yaml +1 -1
  77. package/daemon/context-packs/world-example/manifest.yaml +1 -1
  78. package/daemon/context-packs/world-public/manifest.yaml +1 -1
  79. package/daemon/dist/adapters/claude-code-adapter.d.ts.map +1 -1
  80. package/daemon/dist/adapters/claude-code-adapter.js +16 -5
  81. package/daemon/dist/adapters/claude-code-adapter.js.map +1 -1
  82. package/daemon/dist/adapters/claude-resume.d.ts +2 -1
  83. package/daemon/dist/adapters/claude-resume.d.ts.map +1 -1
  84. package/daemon/dist/adapters/claude-resume.js +13 -5
  85. package/daemon/dist/adapters/claude-resume.js.map +1 -1
  86. package/daemon/dist/adapters/kernel-authority.d.ts +1 -1
  87. package/daemon/dist/adapters/kernel-authority.d.ts.map +1 -1
  88. package/daemon/dist/adapters/kernel-authority.js +22 -10
  89. package/daemon/dist/adapters/kernel-authority.js.map +1 -1
  90. package/daemon/dist/adapters/pi-runner-protocol.d.ts +43 -0
  91. package/daemon/dist/adapters/pi-runner-protocol.d.ts.map +1 -1
  92. package/daemon/dist/adapters/pi-runner-protocol.js.map +1 -1
  93. package/daemon/dist/adapters/pi-runner.d.ts +50 -1
  94. package/daemon/dist/adapters/pi-runner.d.ts.map +1 -1
  95. package/daemon/dist/adapters/pi-runner.js +463 -13
  96. package/daemon/dist/adapters/pi-runner.js.map +1 -1
  97. package/daemon/dist/adapters/tmux-credential-env.d.ts +4 -0
  98. package/daemon/dist/adapters/tmux-credential-env.d.ts.map +1 -0
  99. package/daemon/dist/adapters/tmux-credential-env.js +14 -0
  100. package/daemon/dist/adapters/tmux-credential-env.js.map +1 -0
  101. package/daemon/dist/adapters/tmux-exec.d.ts.map +1 -1
  102. package/daemon/dist/adapters/tmux-exec.js +4 -3
  103. package/daemon/dist/adapters/tmux-exec.js.map +1 -1
  104. package/daemon/dist/adapters/tmux-server.d.ts +2 -2
  105. package/daemon/dist/adapters/tmux-server.d.ts.map +1 -1
  106. package/daemon/dist/adapters/tmux-server.js +12 -4
  107. package/daemon/dist/adapters/tmux-server.js.map +1 -1
  108. package/daemon/dist/adapters/tmux.d.ts +220 -12
  109. package/daemon/dist/adapters/tmux.d.ts.map +1 -1
  110. package/daemon/dist/adapters/tmux.js +835 -29
  111. package/daemon/dist/adapters/tmux.js.map +1 -1
  112. package/daemon/dist/attention-surface.d.ts +4 -1
  113. package/daemon/dist/attention-surface.d.ts.map +1 -1
  114. package/daemon/dist/attention-surface.js.map +1 -1
  115. package/daemon/dist/build-info.js +3 -3
  116. package/daemon/dist/db/all-migrations.d.ts.map +1 -1
  117. package/daemon/dist/db/all-migrations.js +8 -0
  118. package/daemon/dist/db/all-migrations.js.map +1 -1
  119. package/daemon/dist/db/migrations/171_claude_auto_mode.d.ts +4 -0
  120. package/daemon/dist/db/migrations/171_claude_auto_mode.d.ts.map +1 -0
  121. package/daemon/dist/db/migrations/171_claude_auto_mode.js +9 -0
  122. package/daemon/dist/db/migrations/171_claude_auto_mode.js.map +1 -0
  123. package/daemon/dist/db/migrations/171_node_input_route.d.ts +4 -0
  124. package/daemon/dist/db/migrations/171_node_input_route.d.ts.map +1 -0
  125. package/daemon/dist/db/migrations/171_node_input_route.js +6 -0
  126. package/daemon/dist/db/migrations/171_node_input_route.js.map +1 -0
  127. package/daemon/dist/db/migrations/172_queue_return_route.d.ts +3 -0
  128. package/daemon/dist/db/migrations/172_queue_return_route.d.ts.map +1 -0
  129. package/daemon/dist/db/migrations/172_queue_return_route.js +13 -0
  130. package/daemon/dist/db/migrations/172_queue_return_route.js.map +1 -0
  131. package/daemon/dist/db/migrations/173_node_process_limits.d.ts +4 -0
  132. package/daemon/dist/db/migrations/173_node_process_limits.d.ts.map +1 -0
  133. package/daemon/dist/db/migrations/173_node_process_limits.js +6 -0
  134. package/daemon/dist/db/migrations/173_node_process_limits.js.map +1 -0
  135. package/daemon/dist/domain/activity-grants.d.ts.map +1 -1
  136. package/daemon/dist/domain/activity-grants.js +2 -0
  137. package/daemon/dist/domain/activity-grants.js.map +1 -1
  138. package/daemon/dist/domain/agent-activity-store.d.ts +36 -1
  139. package/daemon/dist/domain/agent-activity-store.d.ts.map +1 -1
  140. package/daemon/dist/domain/agent-activity-store.js +192 -3
  141. package/daemon/dist/domain/agent-activity-store.js.map +1 -1
  142. package/daemon/dist/domain/agent-images/resume-token-discovery.d.ts +10 -0
  143. package/daemon/dist/domain/agent-images/resume-token-discovery.d.ts.map +1 -1
  144. package/daemon/dist/domain/agent-images/resume-token-discovery.js +21 -0
  145. package/daemon/dist/domain/agent-images/resume-token-discovery.js.map +1 -1
  146. package/daemon/dist/domain/applied-launch-observation-store.d.ts +5 -0
  147. package/daemon/dist/domain/applied-launch-observation-store.d.ts.map +1 -1
  148. package/daemon/dist/domain/applied-launch-observation-store.js +57 -21
  149. package/daemon/dist/domain/applied-launch-observation-store.js.map +1 -1
  150. package/daemon/dist/domain/builtin-startup-files.d.ts +26 -12
  151. package/daemon/dist/domain/builtin-startup-files.d.ts.map +1 -1
  152. package/daemon/dist/domain/builtin-startup-files.js +73 -34
  153. package/daemon/dist/domain/builtin-startup-files.js.map +1 -1
  154. package/daemon/dist/domain/claude-auto-mode.d.ts +64 -0
  155. package/daemon/dist/domain/claude-auto-mode.d.ts.map +1 -0
  156. package/daemon/dist/domain/claude-auto-mode.js +114 -0
  157. package/daemon/dist/domain/claude-auto-mode.js.map +1 -0
  158. package/daemon/dist/domain/claude-compaction-enforcer.d.ts +2 -0
  159. package/daemon/dist/domain/claude-compaction-enforcer.d.ts.map +1 -1
  160. package/daemon/dist/domain/claude-compaction-enforcer.js +11 -4
  161. package/daemon/dist/domain/claude-compaction-enforcer.js.map +1 -1
  162. package/daemon/dist/domain/claude-continuation-launch.d.ts +5 -1
  163. package/daemon/dist/domain/claude-continuation-launch.d.ts.map +1 -1
  164. package/daemon/dist/domain/claude-continuation-launch.js +51 -2
  165. package/daemon/dist/domain/claude-continuation-launch.js.map +1 -1
  166. package/daemon/dist/domain/claude-core-plugin-env.d.ts +7 -3
  167. package/daemon/dist/domain/claude-core-plugin-env.d.ts.map +1 -1
  168. package/daemon/dist/domain/claude-core-plugin-env.js +11 -8
  169. package/daemon/dist/domain/claude-core-plugin-env.js.map +1 -1
  170. package/daemon/dist/domain/codex-daemon-support.d.ts.map +1 -1
  171. package/daemon/dist/domain/codex-daemon-support.js +6 -1
  172. package/daemon/dist/domain/codex-daemon-support.js.map +1 -1
  173. package/daemon/dist/domain/community-harness-launch-result.d.ts +2 -0
  174. package/daemon/dist/domain/community-harness-launch-result.d.ts.map +1 -1
  175. package/daemon/dist/domain/community-harness-launch-result.js +5 -1
  176. package/daemon/dist/domain/community-harness-launch-result.js.map +1 -1
  177. package/daemon/dist/domain/connection-contract.d.ts +91 -0
  178. package/daemon/dist/domain/connection-contract.d.ts.map +1 -1
  179. package/daemon/dist/domain/connection-contract.js +73 -0
  180. package/daemon/dist/domain/connection-contract.js.map +1 -1
  181. package/daemon/dist/domain/context-usage-store.d.ts +5 -0
  182. package/daemon/dist/domain/context-usage-store.d.ts.map +1 -1
  183. package/daemon/dist/domain/context-usage-store.js +37 -2
  184. package/daemon/dist/domain/context-usage-store.js.map +1 -1
  185. package/daemon/dist/domain/current-work.d.ts +6 -1
  186. package/daemon/dist/domain/current-work.d.ts.map +1 -1
  187. package/daemon/dist/domain/current-work.js +41 -8
  188. package/daemon/dist/domain/current-work.js.map +1 -1
  189. package/daemon/dist/domain/cwd-resolution.d.ts +2 -0
  190. package/daemon/dist/domain/cwd-resolution.d.ts.map +1 -1
  191. package/daemon/dist/domain/cwd-resolution.js +7 -2
  192. package/daemon/dist/domain/cwd-resolution.js.map +1 -1
  193. package/daemon/dist/domain/draft-aware-delivery.d.ts.map +1 -1
  194. package/daemon/dist/domain/draft-aware-delivery.js +5 -1
  195. package/daemon/dist/domain/draft-aware-delivery.js.map +1 -1
  196. package/daemon/dist/domain/errors.d.ts +4 -0
  197. package/daemon/dist/domain/errors.d.ts.map +1 -1
  198. package/daemon/dist/domain/errors.js +7 -0
  199. package/daemon/dist/domain/errors.js.map +1 -1
  200. package/daemon/dist/domain/execution-view.d.ts.map +1 -1
  201. package/daemon/dist/domain/execution-view.js +8 -1
  202. package/daemon/dist/domain/execution-view.js.map +1 -1
  203. package/daemon/dist/domain/existing-rig-restore.d.ts +2 -0
  204. package/daemon/dist/domain/existing-rig-restore.d.ts.map +1 -1
  205. package/daemon/dist/domain/existing-rig-restore.js +1 -0
  206. package/daemon/dist/domain/existing-rig-restore.js.map +1 -1
  207. package/daemon/dist/domain/gateway/operator-delivery-engine.d.ts.map +1 -1
  208. package/daemon/dist/domain/gateway/operator-delivery-engine.js +107 -3
  209. package/daemon/dist/domain/gateway/operator-delivery-engine.js.map +1 -1
  210. package/daemon/dist/domain/gateway/slack/capabilities.d.ts +9 -1
  211. package/daemon/dist/domain/gateway/slack/capabilities.d.ts.map +1 -1
  212. package/daemon/dist/domain/gateway/slack/capabilities.js +6 -1
  213. package/daemon/dist/domain/gateway/slack/capabilities.js.map +1 -1
  214. package/daemon/dist/domain/gateway/slack/inbound-admission.js +1 -1
  215. package/daemon/dist/domain/gateway/slack/inbound-admission.js.map +1 -1
  216. package/daemon/dist/domain/gateway/slack/inbound.d.ts +4 -0
  217. package/daemon/dist/domain/gateway/slack/inbound.d.ts.map +1 -1
  218. package/daemon/dist/domain/gateway/slack/inbound.js +15 -1
  219. package/daemon/dist/domain/gateway/slack/inbound.js.map +1 -1
  220. package/daemon/dist/domain/gateway/slack/manifest.d.ts +5 -1
  221. package/daemon/dist/domain/gateway/slack/manifest.d.ts.map +1 -1
  222. package/daemon/dist/domain/gateway/slack/manifest.js +12 -3
  223. package/daemon/dist/domain/gateway/slack/manifest.js.map +1 -1
  224. package/daemon/dist/domain/gateway/slack/message.d.ts +1 -0
  225. package/daemon/dist/domain/gateway/slack/message.d.ts.map +1 -1
  226. package/daemon/dist/domain/gateway/slack/message.js +4 -1
  227. package/daemon/dist/domain/gateway/slack/message.js.map +1 -1
  228. package/daemon/dist/domain/gateway/slack/queue-access.d.ts +2 -0
  229. package/daemon/dist/domain/gateway/slack/queue-access.d.ts.map +1 -1
  230. package/daemon/dist/domain/gateway/slack/queue-access.js +1 -0
  231. package/daemon/dist/domain/gateway/slack/queue-access.js.map +1 -1
  232. package/daemon/dist/domain/gateway/slack/settled-asks.d.ts.map +1 -1
  233. package/daemon/dist/domain/gateway/slack/settled-asks.js +6 -5
  234. package/daemon/dist/domain/gateway/slack/settled-asks.js.map +1 -1
  235. package/daemon/dist/domain/gateway/slack/slack-api.d.ts +1 -0
  236. package/daemon/dist/domain/gateway/slack/slack-api.d.ts.map +1 -1
  237. package/daemon/dist/domain/gateway/slack/slack-api.js +7 -2
  238. package/daemon/dist/domain/gateway/slack/slack-api.js.map +1 -1
  239. package/daemon/dist/domain/harness-not-started-notice.d.ts +36 -0
  240. package/daemon/dist/domain/harness-not-started-notice.d.ts.map +1 -0
  241. package/daemon/dist/domain/harness-not-started-notice.js +81 -0
  242. package/daemon/dist/domain/harness-not-started-notice.js.map +1 -0
  243. package/daemon/dist/domain/hot-potato-enforcer.d.ts +1 -1
  244. package/daemon/dist/domain/input-read-diagnostic.js +1 -1
  245. package/daemon/dist/domain/input-read-diagnostic.js.map +1 -1
  246. package/daemon/dist/domain/instance-initialization.d.ts +2 -0
  247. package/daemon/dist/domain/instance-initialization.d.ts.map +1 -1
  248. package/daemon/dist/domain/instance-initialization.js +2 -1
  249. package/daemon/dist/domain/instance-initialization.js.map +1 -1
  250. package/daemon/dist/domain/member-connection.d.ts +14 -0
  251. package/daemon/dist/domain/member-connection.d.ts.map +1 -0
  252. package/daemon/dist/domain/member-connection.js +34 -0
  253. package/daemon/dist/domain/member-connection.js.map +1 -0
  254. package/daemon/dist/domain/model-divergence/current-model-reader.d.ts +3 -1
  255. package/daemon/dist/domain/model-divergence/current-model-reader.d.ts.map +1 -1
  256. package/daemon/dist/domain/model-divergence/current-model-reader.js +32 -7
  257. package/daemon/dist/domain/model-divergence/current-model-reader.js.map +1 -1
  258. package/daemon/dist/domain/native-permission-store.d.ts +6 -2
  259. package/daemon/dist/domain/native-permission-store.d.ts.map +1 -1
  260. package/daemon/dist/domain/native-permission-store.js +12 -5
  261. package/daemon/dist/domain/native-permission-store.js.map +1 -1
  262. package/daemon/dist/domain/native-resume-probe.d.ts +5 -0
  263. package/daemon/dist/domain/native-resume-probe.d.ts.map +1 -1
  264. package/daemon/dist/domain/native-resume-probe.js +94 -10
  265. package/daemon/dist/domain/native-resume-probe.js.map +1 -1
  266. package/daemon/dist/domain/network/network-connector.d.ts.map +1 -1
  267. package/daemon/dist/domain/network/network-connector.js +11 -2
  268. package/daemon/dist/domain/network/network-connector.js.map +1 -1
  269. package/daemon/dist/domain/node-inventory.d.ts.map +1 -1
  270. package/daemon/dist/domain/node-inventory.js +28 -0
  271. package/daemon/dist/domain/node-inventory.js.map +1 -1
  272. package/daemon/dist/domain/node-launcher.d.ts +8 -0
  273. package/daemon/dist/domain/node-launcher.d.ts.map +1 -1
  274. package/daemon/dist/domain/node-launcher.js +19 -4
  275. package/daemon/dist/domain/node-launcher.js.map +1 -1
  276. package/daemon/dist/domain/outbox-handler.d.ts +50 -0
  277. package/daemon/dist/domain/outbox-handler.d.ts.map +1 -1
  278. package/daemon/dist/domain/outbox-handler.js +255 -1
  279. package/daemon/dist/domain/outbox-handler.js.map +1 -1
  280. package/daemon/dist/domain/parked-query.d.ts.map +1 -1
  281. package/daemon/dist/domain/parked-query.js +3 -1
  282. package/daemon/dist/domain/parked-query.js.map +1 -1
  283. package/daemon/dist/domain/permission-account.d.ts +28 -1
  284. package/daemon/dist/domain/permission-account.d.ts.map +1 -1
  285. package/daemon/dist/domain/permission-account.js +55 -11
  286. package/daemon/dist/domain/permission-account.js.map +1 -1
  287. package/daemon/dist/domain/permission-drift.d.ts +2 -0
  288. package/daemon/dist/domain/permission-drift.d.ts.map +1 -1
  289. package/daemon/dist/domain/permission-drift.js.map +1 -1
  290. package/daemon/dist/domain/pi-compaction-request-store.d.ts +16 -0
  291. package/daemon/dist/domain/pi-compaction-request-store.d.ts.map +1 -0
  292. package/daemon/dist/domain/pi-compaction-request-store.js +40 -0
  293. package/daemon/dist/domain/pi-compaction-request-store.js.map +1 -0
  294. package/daemon/dist/domain/pi-compaction-service.d.ts +82 -0
  295. package/daemon/dist/domain/pi-compaction-service.d.ts.map +1 -0
  296. package/daemon/dist/domain/pi-compaction-service.js +229 -0
  297. package/daemon/dist/domain/pi-compaction-service.js.map +1 -0
  298. package/daemon/dist/domain/process-limits.d.ts +37 -0
  299. package/daemon/dist/domain/process-limits.d.ts.map +1 -0
  300. package/daemon/dist/domain/process-limits.js +69 -0
  301. package/daemon/dist/domain/process-limits.js.map +1 -0
  302. package/daemon/dist/domain/process-table.d.ts +9 -0
  303. package/daemon/dist/domain/process-table.d.ts.map +1 -1
  304. package/daemon/dist/domain/process-table.js +21 -4
  305. package/daemon/dist/domain/process-table.js.map +1 -1
  306. package/daemon/dist/domain/proof/judgments.d.ts +7 -0
  307. package/daemon/dist/domain/proof/judgments.d.ts.map +1 -1
  308. package/daemon/dist/domain/proof/judgments.js +27 -1
  309. package/daemon/dist/domain/proof/judgments.js.map +1 -1
  310. package/daemon/dist/domain/ps-projection.d.ts +2 -1
  311. package/daemon/dist/domain/ps-projection.d.ts.map +1 -1
  312. package/daemon/dist/domain/ps-projection.js +6 -1
  313. package/daemon/dist/domain/ps-projection.js.map +1 -1
  314. package/daemon/dist/domain/queue-erasure.d.ts +11 -6
  315. package/daemon/dist/domain/queue-erasure.d.ts.map +1 -1
  316. package/daemon/dist/domain/queue-erasure.js +44 -21
  317. package/daemon/dist/domain/queue-erasure.js.map +1 -1
  318. package/daemon/dist/domain/queue-repository.d.ts +62 -14
  319. package/daemon/dist/domain/queue-repository.d.ts.map +1 -1
  320. package/daemon/dist/domain/queue-repository.js +270 -65
  321. package/daemon/dist/domain/queue-repository.js.map +1 -1
  322. package/daemon/dist/domain/queue-stuck-sweep.d.ts +3 -0
  323. package/daemon/dist/domain/queue-stuck-sweep.d.ts.map +1 -1
  324. package/daemon/dist/domain/queue-stuck-sweep.js +45 -13
  325. package/daemon/dist/domain/queue-stuck-sweep.js.map +1 -1
  326. package/daemon/dist/domain/queue-transition-log.d.ts +5 -3
  327. package/daemon/dist/domain/queue-transition-log.d.ts.map +1 -1
  328. package/daemon/dist/domain/queue-transition-log.js +9 -6
  329. package/daemon/dist/domain/queue-transition-log.js.map +1 -1
  330. package/daemon/dist/domain/queue-wake-ladder.d.ts +8 -0
  331. package/daemon/dist/domain/queue-wake-ladder.d.ts.map +1 -1
  332. package/daemon/dist/domain/queue-wake-ladder.js +155 -17
  333. package/daemon/dist/domain/queue-wake-ladder.js.map +1 -1
  334. package/daemon/dist/domain/queue-wake-repository.d.ts +2 -1
  335. package/daemon/dist/domain/queue-wake-repository.d.ts.map +1 -1
  336. package/daemon/dist/domain/queue-wake-repository.js +31 -4
  337. package/daemon/dist/domain/queue-wake-repository.js.map +1 -1
  338. package/daemon/dist/domain/restore-check-service.d.ts +10 -0
  339. package/daemon/dist/domain/restore-check-service.d.ts.map +1 -1
  340. package/daemon/dist/domain/restore-check-service.js +76 -3
  341. package/daemon/dist/domain/restore-check-service.js.map +1 -1
  342. package/daemon/dist/domain/restore-orchestrator.d.ts +60 -2
  343. package/daemon/dist/domain/restore-orchestrator.d.ts.map +1 -1
  344. package/daemon/dist/domain/restore-orchestrator.js +241 -50
  345. package/daemon/dist/domain/restore-orchestrator.js.map +1 -1
  346. package/daemon/dist/domain/restore-plan-preview.d.ts +28 -1
  347. package/daemon/dist/domain/restore-plan-preview.d.ts.map +1 -1
  348. package/daemon/dist/domain/restore-plan-preview.js +17 -5
  349. package/daemon/dist/domain/restore-plan-preview.js.map +1 -1
  350. package/daemon/dist/domain/restore-preconditions.d.ts +24 -0
  351. package/daemon/dist/domain/restore-preconditions.d.ts.map +1 -1
  352. package/daemon/dist/domain/restore-preconditions.js +61 -1
  353. package/daemon/dist/domain/restore-preconditions.js.map +1 -1
  354. package/daemon/dist/domain/resume-token-validation.d.ts +3 -1
  355. package/daemon/dist/domain/resume-token-validation.d.ts.map +1 -1
  356. package/daemon/dist/domain/resume-token-validation.js +6 -3
  357. package/daemon/dist/domain/resume-token-validation.js.map +1 -1
  358. package/daemon/dist/domain/return-route.d.ts +73 -0
  359. package/daemon/dist/domain/return-route.d.ts.map +1 -0
  360. package/daemon/dist/domain/return-route.js +124 -0
  361. package/daemon/dist/domain/return-route.js.map +1 -0
  362. package/daemon/dist/domain/rig-expansion-service.js +1 -1
  363. package/daemon/dist/domain/rig-expansion-service.js.map +1 -1
  364. package/daemon/dist/domain/rig-repository.d.ts +12 -0
  365. package/daemon/dist/domain/rig-repository.d.ts.map +1 -1
  366. package/daemon/dist/domain/rig-repository.js +73 -0
  367. package/daemon/dist/domain/rig-repository.js.map +1 -1
  368. package/daemon/dist/domain/rig-teardown.d.ts +4 -2
  369. package/daemon/dist/domain/rig-teardown.d.ts.map +1 -1
  370. package/daemon/dist/domain/rig-teardown.js +32 -13
  371. package/daemon/dist/domain/rig-teardown.js.map +1 -1
  372. package/daemon/dist/domain/rigspec-codec.d.ts.map +1 -1
  373. package/daemon/dist/domain/rigspec-codec.js +9 -0
  374. package/daemon/dist/domain/rigspec-codec.js.map +1 -1
  375. package/daemon/dist/domain/rigspec-exporter.d.ts +6 -0
  376. package/daemon/dist/domain/rigspec-exporter.d.ts.map +1 -1
  377. package/daemon/dist/domain/rigspec-exporter.js +30 -0
  378. package/daemon/dist/domain/rigspec-exporter.js.map +1 -1
  379. package/daemon/dist/domain/rigspec-instantiator.d.ts +22 -2
  380. package/daemon/dist/domain/rigspec-instantiator.d.ts.map +1 -1
  381. package/daemon/dist/domain/rigspec-instantiator.js +82 -23
  382. package/daemon/dist/domain/rigspec-instantiator.js.map +1 -1
  383. package/daemon/dist/domain/rigspec-schema.d.ts.map +1 -1
  384. package/daemon/dist/domain/rigspec-schema.js +44 -1
  385. package/daemon/dist/domain/rigspec-schema.js.map +1 -1
  386. package/daemon/dist/domain/rosters.d.ts +12 -0
  387. package/daemon/dist/domain/rosters.d.ts.map +1 -1
  388. package/daemon/dist/domain/rosters.js +17 -4
  389. package/daemon/dist/domain/rosters.js.map +1 -1
  390. package/daemon/dist/domain/runner-channel.d.ts +33 -0
  391. package/daemon/dist/domain/runner-channel.d.ts.map +1 -0
  392. package/daemon/dist/domain/runner-channel.js +179 -0
  393. package/daemon/dist/domain/runner-channel.js.map +1 -0
  394. package/daemon/dist/domain/runner-grant-launch.js +2 -2
  395. package/daemon/dist/domain/runtime-adapter.d.ts +2 -0
  396. package/daemon/dist/domain/runtime-adapter.d.ts.map +1 -1
  397. package/daemon/dist/domain/runtime-adapter.js.map +1 -1
  398. package/daemon/dist/domain/runtime-switch-materials.d.ts.map +1 -1
  399. package/daemon/dist/domain/runtime-switch-materials.js +4 -3
  400. package/daemon/dist/domain/runtime-switch-materials.js.map +1 -1
  401. package/daemon/dist/domain/scope/scope-audit.d.ts.map +1 -1
  402. package/daemon/dist/domain/scope/scope-audit.js +55 -3
  403. package/daemon/dist/domain/scope/scope-audit.js.map +1 -1
  404. package/daemon/dist/domain/seat-attention-reconciler.d.ts +6 -4
  405. package/daemon/dist/domain/seat-attention-reconciler.d.ts.map +1 -1
  406. package/daemon/dist/domain/seat-attention-reconciler.js +17 -10
  407. package/daemon/dist/domain/seat-attention-reconciler.js.map +1 -1
  408. package/daemon/dist/domain/seat-delivery-guard.d.ts.map +1 -1
  409. package/daemon/dist/domain/seat-delivery-guard.js +2 -1
  410. package/daemon/dist/domain/seat-delivery-guard.js.map +1 -1
  411. package/daemon/dist/domain/seat-handover-service.d.ts +27 -4
  412. package/daemon/dist/domain/seat-handover-service.d.ts.map +1 -1
  413. package/daemon/dist/domain/seat-handover-service.js +203 -63
  414. package/daemon/dist/domain/seat-handover-service.js.map +1 -1
  415. package/daemon/dist/domain/seat-identity-reconciler.d.ts +8 -1
  416. package/daemon/dist/domain/seat-identity-reconciler.d.ts.map +1 -1
  417. package/daemon/dist/domain/seat-identity-reconciler.js +52 -12
  418. package/daemon/dist/domain/seat-identity-reconciler.js.map +1 -1
  419. package/daemon/dist/domain/seat-lifecycle-service.d.ts +21 -4
  420. package/daemon/dist/domain/seat-lifecycle-service.d.ts.map +1 -1
  421. package/daemon/dist/domain/seat-lifecycle-service.js +68 -2
  422. package/daemon/dist/domain/seat-lifecycle-service.js.map +1 -1
  423. package/daemon/dist/domain/seat-restart-in-place.d.ts +9 -2
  424. package/daemon/dist/domain/seat-restart-in-place.d.ts.map +1 -1
  425. package/daemon/dist/domain/seat-restart-in-place.js +34 -2
  426. package/daemon/dist/domain/seat-restart-in-place.js.map +1 -1
  427. package/daemon/dist/domain/seat-runtime-switch-service.d.ts +4 -0
  428. package/daemon/dist/domain/seat-runtime-switch-service.d.ts.map +1 -1
  429. package/daemon/dist/domain/seat-runtime-switch-service.js +9 -3
  430. package/daemon/dist/domain/seat-runtime-switch-service.js.map +1 -1
  431. package/daemon/dist/domain/seat-status-service.d.ts +4 -0
  432. package/daemon/dist/domain/seat-status-service.d.ts.map +1 -1
  433. package/daemon/dist/domain/seat-status-service.js +31 -6
  434. package/daemon/dist/domain/seat-status-service.js.map +1 -1
  435. package/daemon/dist/domain/session-transport.d.ts +16 -3
  436. package/daemon/dist/domain/session-transport.d.ts.map +1 -1
  437. package/daemon/dist/domain/session-transport.js +134 -9
  438. package/daemon/dist/domain/session-transport.js.map +1 -1
  439. package/daemon/dist/domain/shared-conversation.d.ts +58 -0
  440. package/daemon/dist/domain/shared-conversation.d.ts.map +1 -0
  441. package/daemon/dist/domain/shared-conversation.js +98 -0
  442. package/daemon/dist/domain/shared-conversation.js.map +1 -0
  443. package/daemon/dist/domain/startup-phase-timing.d.ts +19 -0
  444. package/daemon/dist/domain/startup-phase-timing.d.ts.map +1 -0
  445. package/daemon/dist/domain/startup-phase-timing.js +23 -0
  446. package/daemon/dist/domain/startup-phase-timing.js.map +1 -0
  447. package/daemon/dist/domain/successor-session-launcher.d.ts +9 -0
  448. package/daemon/dist/domain/successor-session-launcher.d.ts.map +1 -1
  449. package/daemon/dist/domain/successor-session-launcher.js +24 -7
  450. package/daemon/dist/domain/successor-session-launcher.js.map +1 -1
  451. package/daemon/dist/domain/team-operations.d.ts +6 -6
  452. package/daemon/dist/domain/team-operations.d.ts.map +1 -1
  453. package/daemon/dist/domain/team-operations.js +2 -4
  454. package/daemon/dist/domain/team-operations.js.map +1 -1
  455. package/daemon/dist/domain/terminal/herdr-app-provider.d.ts +6 -0
  456. package/daemon/dist/domain/terminal/herdr-app-provider.d.ts.map +1 -1
  457. package/daemon/dist/domain/terminal/herdr-app-provider.js +23 -1
  458. package/daemon/dist/domain/terminal/herdr-app-provider.js.map +1 -1
  459. package/daemon/dist/domain/terminal-policy.js +1 -1
  460. package/daemon/dist/domain/terminal-policy.js.map +1 -1
  461. package/daemon/dist/domain/types.d.ts +82 -5
  462. package/daemon/dist/domain/types.d.ts.map +1 -1
  463. package/daemon/dist/domain/types.js.map +1 -1
  464. package/daemon/dist/domain/watchdog-delivery.d.ts +1 -1
  465. package/daemon/dist/domain/watchdog-delivery.d.ts.map +1 -1
  466. package/daemon/dist/domain/watchdog-delivery.js +6 -3
  467. package/daemon/dist/domain/watchdog-delivery.js.map +1 -1
  468. package/daemon/dist/domain/watchdog-jobs-repository.d.ts.map +1 -1
  469. package/daemon/dist/domain/watchdog-jobs-repository.js +1 -0
  470. package/daemon/dist/domain/watchdog-jobs-repository.js.map +1 -1
  471. package/daemon/dist/domain/watchdog-policy-engine.d.ts +5 -0
  472. package/daemon/dist/domain/watchdog-policy-engine.d.ts.map +1 -1
  473. package/daemon/dist/domain/watchdog-policy-engine.js +14 -4
  474. package/daemon/dist/domain/watchdog-policy-engine.js.map +1 -1
  475. package/daemon/dist/domain/workflow-runtime.d.ts +1 -1
  476. package/daemon/dist/domain/workflow-runtime.d.ts.map +1 -1
  477. package/daemon/dist/domain/workflow-runtime.js +4 -2
  478. package/daemon/dist/domain/workflow-runtime.js.map +1 -1
  479. package/daemon/dist/domain/workspace/default-workspace-scaffold.d.ts +7 -1
  480. package/daemon/dist/domain/workspace/default-workspace-scaffold.d.ts.map +1 -1
  481. package/daemon/dist/domain/workspace/default-workspace-scaffold.js +35 -7
  482. package/daemon/dist/domain/workspace/default-workspace-scaffold.js.map +1 -1
  483. package/daemon/dist/gateway-slack-surface.d.ts +2 -2
  484. package/daemon/dist/gateway-slack-surface.d.ts.map +1 -1
  485. package/daemon/dist/gateway-slack-surface.js +1 -1
  486. package/daemon/dist/gateway-slack-surface.js.map +1 -1
  487. package/daemon/dist/index.d.ts.map +1 -1
  488. package/daemon/dist/index.js +13 -2
  489. package/daemon/dist/index.js.map +1 -1
  490. package/daemon/dist/routes/activity.d.ts.map +1 -1
  491. package/daemon/dist/routes/activity.js +105 -2
  492. package/daemon/dist/routes/activity.js.map +1 -1
  493. package/daemon/dist/routes/agent-images.d.ts.map +1 -1
  494. package/daemon/dist/routes/agent-images.js +6 -1
  495. package/daemon/dist/routes/agent-images.js.map +1 -1
  496. package/daemon/dist/routes/attention.d.ts.map +1 -1
  497. package/daemon/dist/routes/attention.js +2 -1
  498. package/daemon/dist/routes/attention.js.map +1 -1
  499. package/daemon/dist/routes/compaction.d.ts.map +1 -1
  500. package/daemon/dist/routes/compaction.js +46 -7
  501. package/daemon/dist/routes/compaction.js.map +1 -1
  502. package/daemon/dist/routes/queue.d.ts +4 -1
  503. package/daemon/dist/routes/queue.d.ts.map +1 -1
  504. package/daemon/dist/routes/queue.js +232 -34
  505. package/daemon/dist/routes/queue.js.map +1 -1
  506. package/daemon/dist/routes/require-sender-identity.d.ts +4 -3
  507. package/daemon/dist/routes/require-sender-identity.d.ts.map +1 -1
  508. package/daemon/dist/routes/require-sender-identity.js.map +1 -1
  509. package/daemon/dist/routes/restore-check.d.ts.map +1 -1
  510. package/daemon/dist/routes/restore-check.js +1 -0
  511. package/daemon/dist/routes/restore-check.js.map +1 -1
  512. package/daemon/dist/routes/rigspec.d.ts.map +1 -1
  513. package/daemon/dist/routes/rigspec.js +24 -4
  514. package/daemon/dist/routes/rigspec.js.map +1 -1
  515. package/daemon/dist/routes/seat.d.ts.map +1 -1
  516. package/daemon/dist/routes/seat.js +107 -6
  517. package/daemon/dist/routes/seat.js.map +1 -1
  518. package/daemon/dist/routes/sessions.js +14 -3
  519. package/daemon/dist/routes/sessions.js.map +1 -1
  520. package/daemon/dist/routes/startup.js +7 -1
  521. package/daemon/dist/routes/startup.js.map +1 -1
  522. package/daemon/dist/routes/up.d.ts.map +1 -1
  523. package/daemon/dist/routes/up.js +14 -4
  524. package/daemon/dist/routes/up.js.map +1 -1
  525. package/daemon/dist/routes/watchdog.d.ts.map +1 -1
  526. package/daemon/dist/routes/watchdog.js +18 -1
  527. package/daemon/dist/routes/watchdog.js.map +1 -1
  528. package/daemon/dist/server.d.ts +3 -0
  529. package/daemon/dist/server.d.ts.map +1 -1
  530. package/daemon/dist/server.js +11 -0
  531. package/daemon/dist/server.js.map +1 -1
  532. package/daemon/dist/startup.d.ts.map +1 -1
  533. package/daemon/dist/startup.js +51 -16
  534. package/daemon/dist/startup.js.map +1 -1
  535. package/daemon/docs/reference/agent-startup-guide.md +2 -1
  536. package/daemon/docs/reference/community-harness-examples/dsh/README.md +8 -0
  537. package/daemon/docs/reference/community-harness-examples/dsh/openrig-dsh-runner.mjs +139 -5
  538. package/daemon/docs/reference/community-harness-presets.md +2 -0
  539. package/daemon/docs/reference/daemon-http-clients.md +61 -12
  540. package/daemon/docs/reference/getting-started.md +4 -4
  541. package/daemon/docs/reference/harness-runner-contract.md +91 -1
  542. package/daemon/docs/reference/herdr-app.md +6 -0
  543. package/daemon/docs/reference/quickstart.md +2 -2
  544. package/daemon/docs/reference/rig-spec.md +166 -0
  545. package/daemon/docs/reference/rosters.md +9 -0
  546. package/daemon/docs/reference/sdlc-conventions.md +5 -1
  547. package/daemon/docs/reference/slack-app-setup.md +39 -21
  548. package/daemon/docs/reference/whats-new.md +107 -6
  549. package/daemon/specs/agents/shared/skills/core/messaging-the-human/SKILL.md +23 -0
  550. package/daemon/specs/rigs/launch/factory/guidance/lead-first-move.md +26 -5
  551. package/daemon/specs/rigs/launch/kernel/agents/operator/agent/guidance/role.md +19 -5
  552. package/daemon/specs/rigs/launch/kernel/agents/operator/agent/startup/context.md +1 -1
  553. package/daemon/specs/rigs/launch/kernel/culture/CULTURE.md +12 -0
  554. package/daemon/specs/rigs/launch/starter/guidance/lead-first-move.md +26 -5
  555. package/dist/acp/connector.js +1 -1
  556. package/dist/acp/connector.js.map +1 -1
  557. package/dist/build-info.js +3 -3
  558. package/dist/cli-error.d.ts.map +1 -1
  559. package/dist/cli-error.js +7 -1
  560. package/dist/cli-error.js.map +1 -1
  561. package/dist/client.d.ts +2 -1
  562. package/dist/client.d.ts.map +1 -1
  563. package/dist/client.js +3 -2
  564. package/dist/client.js.map +1 -1
  565. package/dist/commands/ask.d.ts.map +1 -1
  566. package/dist/commands/ask.js +92 -11
  567. package/dist/commands/ask.js.map +1 -1
  568. package/dist/commands/broadcast.js +9 -5
  569. package/dist/commands/broadcast.js.map +1 -1
  570. package/dist/commands/compact.d.ts +3 -4
  571. package/dist/commands/compact.d.ts.map +1 -1
  572. package/dist/commands/compact.js +76 -16
  573. package/dist/commands/compact.js.map +1 -1
  574. package/dist/commands/config-init-workspace.d.ts.map +1 -1
  575. package/dist/commands/config-init-workspace.js +3 -0
  576. package/dist/commands/config-init-workspace.js.map +1 -1
  577. package/dist/commands/down.d.ts.map +1 -1
  578. package/dist/commands/down.js +3 -1
  579. package/dist/commands/down.js.map +1 -1
  580. package/dist/commands/export.d.ts.map +1 -1
  581. package/dist/commands/export.js +2 -1
  582. package/dist/commands/export.js.map +1 -1
  583. package/dist/commands/fork.d.ts.map +1 -1
  584. package/dist/commands/fork.js +2 -0
  585. package/dist/commands/fork.js.map +1 -1
  586. package/dist/commands/launch.d.ts.map +1 -1
  587. package/dist/commands/launch.js +11 -3
  588. package/dist/commands/launch.js.map +1 -1
  589. package/dist/commands/ps.d.ts +28 -0
  590. package/dist/commands/ps.d.ts.map +1 -1
  591. package/dist/commands/ps.js +76 -2
  592. package/dist/commands/ps.js.map +1 -1
  593. package/dist/commands/queue.d.ts.map +1 -1
  594. package/dist/commands/queue.js +309 -21
  595. package/dist/commands/queue.js.map +1 -1
  596. package/dist/commands/rig.d.ts +2 -0
  597. package/dist/commands/rig.d.ts.map +1 -1
  598. package/dist/commands/rig.js +36 -2
  599. package/dist/commands/rig.js.map +1 -1
  600. package/dist/commands/roster.d.ts +3 -0
  601. package/dist/commands/roster.d.ts.map +1 -1
  602. package/dist/commands/seat.d.ts.map +1 -1
  603. package/dist/commands/seat.js +126 -7
  604. package/dist/commands/seat.js.map +1 -1
  605. package/dist/commands/send.d.ts.map +1 -1
  606. package/dist/commands/send.js +47 -6
  607. package/dist/commands/send.js.map +1 -1
  608. package/dist/commands/setup.js +2 -2
  609. package/dist/commands/setup.js.map +1 -1
  610. package/dist/commands/slack.d.ts +2 -1
  611. package/dist/commands/slack.d.ts.map +1 -1
  612. package/dist/commands/slack.js +38 -2
  613. package/dist/commands/slack.js.map +1 -1
  614. package/dist/commands/terminal.d.ts.map +1 -1
  615. package/dist/commands/terminal.js +5 -5
  616. package/dist/commands/terminal.js.map +1 -1
  617. package/dist/commands/up.d.ts.map +1 -1
  618. package/dist/commands/up.js +3 -0
  619. package/dist/commands/up.js.map +1 -1
  620. package/dist/commands/workflow.d.ts.map +1 -1
  621. package/dist/commands/workflow.js +4 -0
  622. package/dist/commands/workflow.js.map +1 -1
  623. package/dist/daemon-lifecycle.d.ts.map +1 -1
  624. package/dist/daemon-lifecycle.js +1 -0
  625. package/dist/daemon-lifecycle.js.map +1 -1
  626. package/dist/lib/model-observation.d.ts.map +1 -1
  627. package/dist/lib/model-observation.js +9 -3
  628. package/dist/lib/model-observation.js.map +1 -1
  629. package/dist/lib/scope/scope-audit.d.ts.map +1 -1
  630. package/dist/lib/scope/scope-audit.js +55 -3
  631. package/dist/lib/scope/scope-audit.js.map +1 -1
  632. package/dist/local-db.d.ts +5 -0
  633. package/dist/local-db.d.ts.map +1 -0
  634. package/dist/local-db.js +23 -0
  635. package/dist/local-db.js.map +1 -0
  636. package/dist/local-origin.d.ts.map +1 -1
  637. package/dist/local-origin.js +2 -17
  638. package/dist/local-origin.js.map +1 -1
  639. package/dist/mcp-server.d.ts.map +1 -1
  640. package/dist/mcp-server.js +122 -18
  641. package/dist/mcp-server.js.map +1 -1
  642. package/dist/sender-identity.d.ts +18 -6
  643. package/dist/sender-identity.d.ts.map +1 -1
  644. package/dist/sender-identity.js +67 -7
  645. package/dist/sender-identity.js.map +1 -1
  646. package/dist/terminal-window-rex.d.ts +1 -1
  647. package/dist/terminal-window-rex.d.ts.map +1 -1
  648. package/dist/terminal-window-rex.js +3 -2
  649. package/dist/terminal-window-rex.js.map +1 -1
  650. package/dist/terminal-window.js +3 -3
  651. package/dist/terminal-window.js.map +1 -1
  652. package/package.json +1 -1
  653. package/tui/dist/daemon-client.d.ts.map +1 -1
  654. package/tui/dist/daemon-client.js +2 -1
  655. package/tui/dist/daemon-client.js.map +1 -1
  656. package/ui/dist/assets/{index-BvUEh33d.js → index-1O1f3A7K.js} +55 -55
  657. package/ui/dist/index.html +1 -1
@@ -1,10 +1,12 @@
1
1
  import { DeliveryGuardError } from "../domain/seat-delivery-guard.js";
2
- import { writeFile as fsWriteFile, unlink as fsUnlink } from "node:fs/promises";
2
+ import { writeFile as fsWriteFile, unlink as fsUnlink, readFile as fsReadFile } from "node:fs/promises";
3
+ import { accessSync, statSync, constants as fsConstants } from "node:fs";
3
4
  import { tmpdir } from "node:os";
4
- import { join as pathJoin } from "node:path";
5
+ import { join as pathJoin, isAbsolute as pathIsAbsolute } from "node:path";
5
6
  import { randomUUID } from "node:crypto";
6
7
  import { inspectComposerInput } from "../domain/session-transport.js";
7
8
  import { parentSessionEnvKeys, removeParentSessionEnv } from "../domain/parent-session-env.js";
9
+ import { isTmuxCredentialEnvKey } from "./tmux-credential-env.js";
8
10
  import { addSeatRuntimeDir, seatRuntimeDir } from "../domain/seat-runtime-dir.js";
9
11
  import { tmuxOnDaemonServer } from "./tmux-server.js";
10
12
  import { TMUX_SERVER_LIMIT_PREFIX } from "../tmux-server-start.js";
@@ -33,6 +35,13 @@ export function defaultTmuxFileOps() {
33
35
  bufferName: () => `openrig_${process.pid}_${randomUUID().replace(/-/g, "")}`,
34
36
  };
35
37
  }
38
+ /** How a capped launch sees its seat's scope start: the pane's process is in the seat scope and its command started
39
+ * there (started), or the pane died first, before the command started (systemd-run could not make the scope, also
40
+ * late, after the check passed) or after it (the command ran inside the scope and ended). It looks for longer than
41
+ * systemd-run's own call to the user manager may take (D-Bus's default 25 s timeout), so a late answer either way is
42
+ * seen. */
43
+ const SEAT_SCOPE_START_CHECK_MS = 250;
44
+ const SEAT_SCOPE_START_CHECKS = 120;
36
45
  /** Positive server absence in this adapter's namespace; match the diagnostic line, never a path or command fragment. */
37
46
  export function probeShowsNoServer(probe) {
38
47
  return probe.state === "transport_unavailable" && /^no server running on /.test(tmuxDiagnosticStart(probe.cause ?? ""));
@@ -206,6 +215,9 @@ function execStderrText(error) {
206
215
  const NO_EXPAND_ENVIRONMENT = /(?:unrecognized|unknown) option[^\n]*--expand-environment/i;
207
216
  /** The user manager's refusal of OOMPolicy= for a scope (before 253), read from systemd-run's stderr only. */
208
217
  const NO_OOM_POLICY = /Cannot set property OOMPolicy|Unknown (?:property|assignment)[^\n]*OOMPolicy/i;
218
+ /** A systemd too old for a seat scope: systemctl without --value (before 230) or systemd-run without --collect (before
219
+ * 236), read from their stderr only. */
220
+ const SYSTEMD_TOO_OLD = /(?:unrecognized|unknown) option[^\n]*--(?:value|collect)\b/i;
209
221
  /** What a failed exec said, on one line: its stderr when it kept one apart, else its message past the command. */
210
222
  function execFailureReason(error) {
211
223
  const e = error;
@@ -292,24 +304,611 @@ function usableEnvLine(lines, name) {
292
304
  const prefix = `${name}=`;
293
305
  return lines.some((line) => line.startsWith(prefix) && line.slice(prefix.length).trim().length > 0);
294
306
  }
307
+ /** A fresh launch that asks for a limit it can't get: it is not started, and says why (#3253: never an unlimited start
308
+ * that claims success). */
309
+ export class SeatProcessLimitsNotApplied extends Error {
310
+ problem;
311
+ constructor(problem) {
312
+ super(`process_limits is set for this seat, but ${problemText(problem)}; the seat was not started` +
313
+ (problem.kind === "unverified" ? " (this may be temporary: retry the launch)" : "") + ".");
314
+ this.problem = problem;
315
+ }
316
+ }
317
+ /** One line for a problem, with the age of a cached observation. */
318
+ export function problemText(problem) {
319
+ const what = problem.kind === "invalid" ? "its stored value can't be read"
320
+ : problem.kind === "unsupported" ? "this host can't give the seat its own scope"
321
+ : problem.kind === "setup" ? "this setup can't give the seat its own scope"
322
+ : "whether this host can give the seat its own scope is unverified";
323
+ const age = problem.ageSeconds !== undefined ? `, observed ${problem.ageSeconds}s ago` : "";
324
+ return `${what} (${problem.reason}${age})`;
325
+ }
326
+ /** The structured warning of a recovery that went ahead without the limit. */
327
+ export function notAppliedNotice(problem) {
328
+ return { state: "not_applied", ...problem, retryable: problem.kind === "unverified" };
329
+ }
330
+ /** The structured warning of a recovery that can't tell whether the seat's process is under the limit. */
331
+ export function unknownNotice(problem) {
332
+ return { state: "unknown", ...problem, retryable: problem.kind === "unverified" };
333
+ }
334
+ /** The human line of that warning. */
335
+ export function noticeLine(notice) {
336
+ if (notice.state === "unknown") {
337
+ const age = notice.ageSeconds !== undefined ? `, observed ${notice.ageSeconds}s ago` : "";
338
+ return `process_limits requested; whether the seat runs under the limit is unknown (${notice.reason}${age}); the ` +
339
+ "request stays stored (a fresh launch applies it)";
340
+ }
341
+ return `process_limits requested, not applied: ${problemText(notice)}; the seat went on without the limit, and the ` +
342
+ "request stays stored (a fresh launch applies it)";
343
+ }
344
+ /** The slice a seat scope goes in: seats with process limits leave the terminal server's scope (and any limit an
345
+ * operator put on it) for this slice. No dash: systemd reads a dash in a slice name as nesting, which would put the
346
+ * seats under `openrig.slice` and any limit on it. */
347
+ export const SEAT_SCOPE_SLICE = "openrigseats.slice";
348
+ /** Why a seat with a limit can't start with the inherited tmux environment, with the way out. */
349
+ const INHERIT_TMUX_ENVIRONMENT_REASON = "terminal.inherit_tmux_environment is on: a seat with a limit needs the scoped " +
350
+ "launch environment (set terminal.inherit_tmux_environment to false)";
351
+ /** How long a launch skips asking again after a failed check (it reads as `unverified`, with the observation's age). */
352
+ const SEAT_SCOPE_RETRY_MS = 60_000;
353
+ /** systemd-run reaches the user manager through the runtime directory, not the seat's session bus (which the launch
354
+ * environment turns off on purpose). The command after `--` restores the seat's exact environment (env -i + export). */
355
+ function seatScopeBusEnv(runtimeDir) {
356
+ return ["/usr/bin/env", "-u", "DBUS_SESSION_BUS_ADDRESS", `XDG_RUNTIME_DIR=${runtimeDir}`];
357
+ }
358
+ /** `/usr/bin/env` that gives the command these values back: every `-u` (an unset value) before any assignment, since env
359
+ * reads the first word after an assignment as the command. */
360
+ export function restoreEnvArgv(values) {
361
+ const entries = Object.entries(values);
362
+ return ["/usr/bin/env", ...entries.filter(([, v]) => v === undefined).flatMap(([k]) => ["-u", k]),
363
+ ...entries.filter(([, v]) => v !== undefined).map(([k, v]) => `${k}=${v}`)];
364
+ }
365
+ /** The systemd-run options of a seat scope, up to (not including) the `--` before the command. `systemdRun` is the
366
+ * absolute path the check resolved, so the check and the launch run the same binary whatever PATH the seat has. */
367
+ function seatScopeArgv(opts, unit, description, tasksMax, systemdRun) {
368
+ return [systemdRun, "--user", "--scope", "--quiet", "--collect", "--slice", SEAT_SCOPE_SLICE, "--unit", unit,
369
+ "--description", description,
370
+ // As for the server's scope: the command's arguments must reach /bin/sh exactly as written (254+).
371
+ ...(opts.literal ? ["--expand-environment=no"] : []),
372
+ // As for the server's scope: one OOM kill must not stop every process of the seat (253+).
373
+ ...(opts.oomPolicy ? ["-p", "OOMPolicy=continue"] : []),
374
+ "-p", `TasksMax=${tasksMax}`];
375
+ }
376
+ /** The command that runs first inside a seat scope: it empties the launch's marker file (a builtin and a redirection, no
377
+ * fork, so it works under TasksMax=1), then execs the seat's command. A pane that died with the marker still pending
378
+ * never started the seat's command; one that died with it empty did. */
379
+ function scopeMarkArgv(marker) {
380
+ return ["/bin/sh", "-c", ': > "$0" && exec "$@"', marker];
381
+ }
382
+ const SCOPE_MARKER_PENDING = "pending\n";
383
+ /** The launch result of a fresh seat launch whose limit can't be applied. */
384
+ function processLimitsNotAppliedResult(error, left) {
385
+ // What was observed about the command and what became of its terminal are said apart: a refusal whose command
386
+ // started (or may have) is not "not started", and one whose terminal may still be running has an unknown outcome.
387
+ // Either way a blind retry could repeat the command or start a second one beside it, so none is suggested.
388
+ const started = error.problem.commandStarted;
389
+ const problem = left ? { ...error.problem, possiblyRunning: true } : error.problem;
390
+ let message = error.message;
391
+ if (started || left) {
392
+ message = `process_limits is set for this seat, but ${problemText(error.problem)}; the launch was refused`;
393
+ if (started)
394
+ message += `, after its command ${started === true ? "started" : "may have started"} in the seat's scope`;
395
+ message += left
396
+ ? `, and whether its terminal is running is unknown. ${left} Stop it before launching this seat again.`
397
+ : "; its terminal was removed. Check what the command did before launching this seat again.";
398
+ }
399
+ console.warn(`[seat launch] ${message}`);
400
+ return { ok: false, code: `process_limits_${error.problem.kind}`, message,
401
+ retryable: !left && !started && error.problem.kind === "unverified", processLimits: problem };
402
+ }
403
+ /** What a capped launch's new-session prints: its pane, its session's immutable id and its server (pid, start time). */
404
+ const CREATED_IDENTITY_FORMAT = "#{pane_id} #{session_id} #{pid} #{start_time}";
405
+ /** The identity a capped new-session printed, or null when it printed something else (or nothing). */
406
+ function createdIdentity(printed) {
407
+ const m = /^(%\d+) (\$\d+) (\d+) (\d+)$/.exec(printed);
408
+ return m ? { pane: m[1], session: m[2], server: { pid: m[3], start: m[4] } } : null;
409
+ }
410
+ /** A check's failure, classified (#3253): `unsupported` only on a positive answer that the facility is not there. */
411
+ function classifyScopeFailure(error, what) {
412
+ const reason = execFailureReason(error);
413
+ const code = error.code;
414
+ if (code === 124)
415
+ return { kind: "unverified", reason: `${what} timed out` };
416
+ // systemd's own refusal of an option it predates, read from its stderr only.
417
+ if (SYSTEMD_TOO_OLD.test(execStderrText(error))) {
418
+ return { kind: "unsupported", reason: `${what}: systemd is too old for seat scopes (it needs 236+ for --collect, 230+ for --value): ${reason}` };
419
+ }
420
+ // Only a message that names the tool: an exit status of 127 alone does not say which program was missing.
421
+ if (/(?:systemd-run|systemctl)\S{0,2}: (?:(?:command )?not found|No such file or directory)|No such file or directory[^\n]*(?:systemd-run|systemctl)/i.test(reason)) {
422
+ return { kind: "unsupported", reason: `${what}: systemd-run or systemctl is not installed (${reason})` };
423
+ }
424
+ // No socket at all: no user manager runs for this user (no session and no lingering), a positive answer.
425
+ if (/Failed to connect to (?:user scope )?bus(?: via local transport)?: (?:No such file or directory|No medium found)/i.test(reason)) {
426
+ return { kind: "unsupported", reason: `${what}: no systemd user manager is running for this user (${reason})` };
427
+ }
428
+ // A socket that refuses: a user manager starting or restarting, not known either way.
429
+ if (/Failed to connect to [^:\n]*bus[^:\n]*: Connection refused/i.test(reason)) {
430
+ return { kind: "unverified", reason: `${what}: the user manager's bus refused the connection (starting or restarting?): ${reason}` };
431
+ }
432
+ return { kind: "unverified", reason: `${what} failed: ${reason}` };
433
+ }
434
+ /** The cgroup v2 path of a process, from the `0::` line of /proc/<pid>/cgroup; null on cgroup v1 or no such line. */
435
+ export function cgroupV2Path(procCgroup) {
436
+ const line = procCgroup.split(/\r?\n/).find((l) => l.startsWith("0::"));
437
+ return line ? line.slice(3).trim() || null : null;
438
+ }
295
439
  export class TmuxAdapter {
296
440
  exec;
297
441
  fileOps;
298
442
  argvExec;
299
- /** Read for each new agent/successor. Unconfigured adapters retain legacy behavior. */
443
+ /** Read for each new agent/successor, once per launch. Unconfigured adapters retain legacy behavior. */
300
444
  launchEnvironment;
445
+ /** A seat's process limits by node id (rig spec `process_limits`, #3253), read at each launch. Absent, or undefined
446
+ * for a node: that seat launches exactly as before. It may throw for a malformed stored value: that seat's launch
447
+ * reads it as `invalid`, and no other seat is affected. */
448
+ seatProcessLimits;
449
+ /** Whether a seat runs in an environment guest (its harness is a local viewer of a guest's agent): a scope on this
450
+ * host would hold only the viewer, so a limit can't be applied (#3253). `session` is the seat's session name, for a
451
+ * placement not yet claimed by its node (before the seat's first launch). */
452
+ seatInEnvironmentGuest;
453
+ /** Reads /proc and /sys for the limit's readback, and a launch's scope marker; replaceable in tests. */
454
+ procRead = (path) => fsReadFile(path, "utf8");
455
+ /** An executable's absolute path from the daemon's PATH (absolute entries only), or null; replaceable in tests. */
456
+ resolveExecutable = (name) => {
457
+ for (const dir of (process.env.PATH ?? "").split(":")) {
458
+ if (!pathIsAbsolute(dir))
459
+ continue;
460
+ const candidate = pathJoin(dir, name);
461
+ try {
462
+ accessSync(candidate, fsConstants.X_OK);
463
+ return candidate;
464
+ }
465
+ catch { /* not here */ }
466
+ }
467
+ return null;
468
+ };
469
+ /** Whether a directory exists; replaceable in tests. */
470
+ dirExists = (path) => {
471
+ try {
472
+ return statSync(path).isDirectory();
473
+ }
474
+ catch {
475
+ return false;
476
+ }
477
+ };
478
+ /** systemd-run's options proven by a throwaway scope, per systemd-run binary and task limit (memoized on success only). */
479
+ seatScopeProven = new Map();
480
+ /** The last check that failed without a positive answer (a timeout, an empty probe, an error not recognized), and when,
481
+ * per step ("bus", or the probe of one tasks_max value): a launch within SEAT_SCOPE_RETRY_MS reads it as
482
+ * `unverified`, with its age, never as a fresh result; the first launch after that asks again. A positive answer is
483
+ * not cached: every launch asks again, so a setup fixed since is seen at once. */
484
+ seatScopeFailedAt = new Map();
485
+ /** The last positive inability, for the status only (as `unsupported`, with its age, for SEAT_SCOPE_RETRY_MS). */
486
+ seatScopeLastPositive;
487
+ /** A seat's limits, or the reason its stored value can't be read (kept local to this seat). */
488
+ seatLimitsLookup(nodeId) {
489
+ try {
490
+ const limits = this.seatProcessLimits?.(nodeId);
491
+ return limits ? { limits } : undefined;
492
+ }
493
+ catch (error) {
494
+ return { invalid: error.message };
495
+ }
496
+ }
497
+ /** Whether a seat has a process limits request (a malformed stored one included). */
498
+ seatProcessLimitsSet(nodeId) {
499
+ return this.seatLimitsLookup(nodeId) !== undefined;
500
+ }
501
+ /** The launch policy, read once by each launch or check: undefined when the daemon gives seats none, or what reading it
502
+ * threw. */
503
+ readLaunchPolicy() {
504
+ if (!this.launchEnvironment)
505
+ return undefined;
506
+ try {
507
+ return this.launchEnvironment();
508
+ }
509
+ catch (error) {
510
+ return error instanceof Error ? error : new Error(String(error));
511
+ }
512
+ }
513
+ /** For a seat with a limit, the structured warning of a recovery that keeps a running process whose readback is not
514
+ * `applied` (a restart in place that types into its shell), or null (no limit, or applied). Read only. */
515
+ async seatProcessLimitsNotApplied(nodeId, paneTarget) {
516
+ const lookup = this.seatLimitsLookup(nodeId);
517
+ if (!lookup)
518
+ return null;
519
+ if ("invalid" in lookup)
520
+ return notAppliedNotice({ kind: "invalid", reason: lookup.invalid });
521
+ const report = await this.readSeatProcessLimits(paneTarget, lookup.limits, nodeId);
522
+ if (report.state === "applied")
523
+ return null;
524
+ const requested = { tasksMax: lookup.limits.tasksMax };
525
+ // The restart keeps this process: a readback that failed can't say whether it is under the limit.
526
+ if (report.state === "unknown") {
527
+ return unknownNotice({ kind: "unverified", requested,
528
+ reason: `a restart in place keeps the running process, and whether it is under the limit can't be read back` +
529
+ `${report.reason ? `: ${report.reason}` : ""}` });
530
+ }
531
+ // Known not under the limit is the path's (a fresh launch applies it), and a host that can't make the scope is that.
532
+ return notAppliedNotice({ kind: report.state === "unsupported" ? "unsupported" : "setup",
533
+ reason: `a restart in place keeps the running process, and it is ${report.state === "not_applied" ? "not under the limit" : report.state}` +
534
+ `${report.reason ? `: ${report.reason}` : ""}; a fresh launch applies the limit`,
535
+ requested });
536
+ }
537
+ /** The path a recovery of this seat takes, chosen before anything is stopped (#3253): null when it gets its limit,
538
+ * or the warning it will go ahead with. A recovery never stops for a limit; the respawn it then runs in "recovery"
539
+ * mode never refuses for one either (a scope failure late in the path also ends in this warning). */
540
+ async seatProcessLimitsRecoveryPlan(nodeId) {
541
+ const lookup = this.seatLimitsLookup(nodeId);
542
+ if (!lookup)
543
+ return null;
544
+ if ("invalid" in lookup)
545
+ return notAppliedNotice({ kind: "invalid", reason: lookup.invalid });
546
+ const outcome = await this.seatScope(lookup.limits, { OPENRIG_NODE_ID: nodeId }, this.readLaunchPolicy());
547
+ return outcome.ok ? null : notAppliedNotice(outcome.problem);
548
+ }
549
+ /** For a restart in place that respawns a bare pane (no seat environment), chosen before anything is stopped (#3253):
550
+ * null when the seat has no limit; `keep` when its running process reads back as under the limit and a new scope can
551
+ * be made now (respawnPane with `keepLimitOf` then starts the command in one); otherwise the warning the restart goes
552
+ * ahead with. Read only, apart from the scope check. */
553
+ async seatProcessLimitsKeepPlan(nodeId, paneTarget) {
554
+ const lookup = this.seatLimitsLookup(nodeId);
555
+ if (!lookup)
556
+ return null;
557
+ if ("invalid" in lookup)
558
+ return { keep: false, notice: notAppliedNotice({ kind: "invalid", reason: lookup.invalid }) };
559
+ const requested = { tasksMax: lookup.limits.tasksMax };
560
+ const report = await this.readSeatProcessLimits(paneTarget, lookup.limits, nodeId);
561
+ if (report.state === "applied") {
562
+ const outcome = await this.seatScope(lookup.limits, { OPENRIG_NODE_ID: nodeId }, this.readLaunchPolicy());
563
+ if (outcome.ok)
564
+ return { keep: true };
565
+ return { keep: false, notice: notAppliedNotice({ ...outcome.problem,
566
+ reason: `the seat runs under its limit, but a restart in place respawns it in a new scope, and ${outcome.problem.reason}` }) };
567
+ }
568
+ // The respawned process is known not to be under the limit: only a limit read back as applied is kept.
569
+ const why = report.state === "unknown" ? "its limit can't be read back"
570
+ : report.state === "unsupported" ? "this host can't make the scope" : "it is not under the limit";
571
+ return { keep: false, notice: notAppliedNotice({
572
+ kind: report.state === "unsupported" ? "unsupported" : report.state === "unknown" ? "unverified" : "setup",
573
+ reason: `a restart in place respawns a bare pane and keeps only a limit that reads back as applied; ${why}` +
574
+ `${report.reason ? ` (${report.reason})` : ""}; a fresh launch applies it`,
575
+ requested
576
+ }) };
577
+ }
578
+ /** The user manager's runtime directory: XDG_RUNTIME_DIR when absolute, else /run/user/<uid> when it exists. */
579
+ scopeRuntimeDir() {
580
+ const own = seatRuntimeDir(process.env);
581
+ if (own !== undefined)
582
+ return own;
583
+ const uid = process.getuid?.();
584
+ if (uid === undefined)
585
+ return undefined;
586
+ const fallback = `/run/user/${uid}`;
587
+ return this.dirExists(fallback) ? fallback : undefined;
588
+ }
589
+ /** Why this host (`unsupported`) or this setup (`setup`) positively can't give a seat its own scope, read from the
590
+ * environment only, or null. Unlike the server's scope (userScopeUnavailable), a daemon that is not a systemd user
591
+ * service can still ask the user manager for a seat scope: MANAGERPID unset is no proof, the probe decides. */
592
+ seatScopeStaticProblem(policy, nodeId, session) {
593
+ if (nodeId && this.seatInEnvironmentGuest?.(nodeId, session)) {
594
+ return { kind: "setup", reason: "the seat runs in an environment guest; its processes are outside this host's scope" };
595
+ }
596
+ if (process.platform !== "linux")
597
+ return { kind: "unsupported", reason: "not Linux" };
598
+ if (this.scopeRuntimeDir() === undefined) {
599
+ return { kind: "setup", reason: `XDG_RUNTIME_DIR is unset and /run/user/${process.getuid?.() ?? "<uid>"} does not exist: ` +
600
+ "start the daemon with XDG_RUNTIME_DIR set, or as a systemd user service" };
601
+ }
602
+ if (policy instanceof Error)
603
+ return { kind: "unverified", reason: `the launch environment can't be read: ${policy.message}` };
604
+ if (!policy)
605
+ return { kind: "setup", reason: "this daemon gives seats no launch environment" };
606
+ if (policy.inheritTmuxEnvironment) {
607
+ // A seat scope is set up by systemd-run, which needs the user bus settings in its own environment; the scoped
608
+ // launch environment then rebuilds the seat's exact environment around it. With the inherited tmux environment
609
+ // there is no such rebuild, and the seat would start with systemd-run's bus settings instead of its own.
610
+ return { kind: "setup", reason: INHERIT_TMUX_ENVIRONMENT_REASON };
611
+ }
612
+ return null;
613
+ }
614
+ /** systemd-run, systemctl and timeout, resolved once from the daemon's PATH, or why they can't be. */
615
+ seatScopeTools() {
616
+ const systemdRun = this.resolveExecutable("systemd-run");
617
+ const systemctl = this.resolveExecutable("systemctl");
618
+ if (!systemdRun || !systemctl) {
619
+ return { problem: { kind: "unsupported",
620
+ reason: `${!systemdRun ? "systemd-run" : "systemctl"} is not in the daemon's PATH (${process.env.PATH ?? ""})` } };
621
+ }
622
+ const timeout = this.resolveExecutable("timeout");
623
+ if (!timeout) {
624
+ return { problem: { kind: "setup", reason: "coreutils' timeout is not in the daemon's PATH: install it, or start the " +
625
+ "daemon with a PATH that has it" } };
626
+ }
627
+ return { systemdRun, systemctl, timeout };
628
+ }
629
+ /** The prefix that starts a seat's pane command in a systemd user scope of its own with TasksMax: the tmux server
630
+ * stays where it is, and only this seat's processes are under the limit (#3253). systemd-run registers itself in the
631
+ * new scope and then execs the command, so the pane's process is the seat's. Or why it can't, classified: never a
632
+ * silent start without the limit. */
633
+ async seatScope(limits, seatEnv, policy) {
634
+ const requested = { tasksMax: limits.tasksMax };
635
+ const fail = (problem) => ({ ok: false, problem: { ...problem, requested } });
636
+ const positive = (problem) => {
637
+ if (problem.kind === "unsupported")
638
+ this.seatScopeLastPositive = { at: Date.now(), problem };
639
+ return fail(problem);
640
+ };
641
+ const fixed = this.seatScopeStaticProblem(policy, seatEnv.OPENRIG_NODE_ID, seatEnv.OPENRIG_SESSION_NAME);
642
+ if (fixed)
643
+ return positive(fixed);
644
+ const tools = this.seatScopeTools();
645
+ if ("problem" in tools)
646
+ return positive(tools.problem);
647
+ const runtimeDir = this.scopeRuntimeDir();
648
+ // A systemd-run that changed since (another PATH, an upgrade) is proven again.
649
+ const provenKey = `${tools.systemdRun}\0${limits.tasksMax}`;
650
+ const probeKey = `probe:${provenKey}`;
651
+ for (const key of ["bus", probeKey]) {
652
+ const failed = this.seatScopeFailedAt.get(key);
653
+ if (failed && Date.now() - failed.at < SEAT_SCOPE_RETRY_MS && (key === "bus" || !this.seatScopeProven.has(provenKey))) {
654
+ return fail({ kind: "unverified", reason: `the last check failed: ${failed.problem.reason}`,
655
+ ageSeconds: Math.floor((Date.now() - failed.at) / 1000) });
656
+ }
657
+ }
658
+ // Only a failure that says nothing either way is cached; a positive one is asked again at the next launch.
659
+ const remember = (key, problem) => {
660
+ if (problem.kind === "unverified")
661
+ this.seatScopeFailedAt.set(key, { at: Date.now(), problem });
662
+ return positive(problem);
663
+ };
664
+ // The bus at this launch, not at the first one: a manager that went away since must not start the seat unlimited.
665
+ try {
666
+ await this.exec(posixJoinArgv([...seatScopeBusEnv(runtimeDir), tools.timeout, "5",
667
+ tools.systemctl, "--user", "show", "--property=Version", "--value"]));
668
+ }
669
+ catch (error) {
670
+ return remember("bus", classifyScopeFailure(error, "asking the systemd user manager"));
671
+ }
672
+ this.seatScopeFailedAt.delete("bus");
673
+ let opts = this.seatScopeProven.get(provenKey);
674
+ if (!opts) {
675
+ const proven = await this.proveSeatScope(runtimeDir, limits.tasksMax, tools);
676
+ if (!proven.ok)
677
+ return remember(probeKey, proven.problem);
678
+ opts = proven.opts;
679
+ this.seatScopeProven.set(provenKey, opts);
680
+ }
681
+ this.seatScopeFailedAt.delete(probeKey);
682
+ this.seatScopeLastPositive = undefined;
683
+ const name = seatEnv.OPENRIG_SESSION_NAME || seatEnv.OPENRIG_NODE_ID || "seat";
684
+ // Unit names take ASCII letters, digits and ":-_.\\"; an "@" would read as a template instance.
685
+ const unit = `openrig-seat-${name.replace(/[^A-Za-z0-9_.-]/g, "_").slice(0, 120)}-${randomUUID().slice(0, 8)}`;
686
+ return { ok: true, prefix: [...seatScopeBusEnv(runtimeDir),
687
+ ...seatScopeArgv(opts, unit, `OpenRig seat ${name}`, limits.tasksMax, tools.systemdRun), "--"] };
688
+ }
689
+ /** One throwaway scope with the seat's own options, whose command prints the pids.max of its own cgroup: the limit
690
+ * counts as supported only when that is the requested value. Options this systemd lacks are dropped from its stderr,
691
+ * as for the server's scope. A pids.max that is another value (e.g. "max": TasksMax accepted but the pids controller
692
+ * not delegated) is a positive inability; an empty result or an error not recognized is unverified. */
693
+ async proveSeatScope(runtimeDir, tasksMax, tools) {
694
+ const opts = { literal: true, oomPolicy: true };
695
+ // Shell builtins only: no fork inside the scope, so even TasksMax=1 can be proven (the probe is the scope's one task).
696
+ const readOwnPidsMax = 'p=; while IFS= read -r l; do case $l in 0::*) p=${l#0::};; esac; done < /proc/self/cgroup; ' +
697
+ 'if [ -z "$p" ]; then printf "nocgroup2\\n"; elif [ ! -e "/sys/fs/cgroup$p/pids.max" ]; then printf "nopids\\n"; ' +
698
+ 'else IFS= read -r m < "/sys/fs/cgroup$p/pids.max" && printf "%s\\n" "$m"; fi';
699
+ for (;;) {
700
+ let out;
701
+ try {
702
+ out = await this.exec(posixJoinArgv([...seatScopeBusEnv(runtimeDir), tools.timeout, "10",
703
+ ...seatScopeArgv(opts, `openrig-seat-probe-${randomUUID().slice(0, 8)}`, "OpenRig seat scope probe", tasksMax, tools.systemdRun),
704
+ "--", "/bin/sh", "-c", readOwnPidsMax]));
705
+ }
706
+ catch (error) {
707
+ const stderr = execStderrText(error);
708
+ if (opts.literal && NO_EXPAND_ENVIRONMENT.test(stderr)) {
709
+ opts.literal = false;
710
+ continue;
711
+ }
712
+ if (opts.oomPolicy && NO_OOM_POLICY.test(stderr)) {
713
+ opts.oomPolicy = false;
714
+ continue;
715
+ }
716
+ return { ok: false, problem: classifyScopeFailure(error, "a throwaway seat scope") };
717
+ }
718
+ const got = out.trim();
719
+ if (!got)
720
+ return { ok: false, problem: { kind: "unverified", reason: "a throwaway seat scope read no pids.max" } };
721
+ if (got === "nocgroup2")
722
+ return { ok: false, problem: { kind: "unsupported", reason: "the user manager's scopes have no cgroup v2 path (a cgroup v1 host)" } };
723
+ if (got === "nopids") {
724
+ return { ok: false, problem: { kind: "unsupported", reason: "a throwaway seat scope has no pids.max: the pids controller is not delegated to the user manager" } };
725
+ }
726
+ // Only a readable limit that isn't the one asked for is a positive answer; anything else can't be read.
727
+ if (!/^(\d+|max)$/.test(got)) {
728
+ return { ok: false, problem: { kind: "unverified", reason: `a throwaway seat scope's pids.max read could not be understood ("${got.slice(0, 80)}")` } };
729
+ }
730
+ if (got !== String(tasksMax)) {
731
+ return { ok: false, problem: { kind: "unsupported",
732
+ reason: `a throwaway seat scope got pids.max "${got}" for TasksMax=${tasksMax}: the pids limit is not enforced here (is the pids controller delegated to the user manager?)` } };
733
+ }
734
+ return { ok: true, opts };
735
+ }
736
+ }
737
+ /** Sleep used by the start check; replaceable in tests. */
738
+ scopeStartSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
739
+ /** A new marker file for a capped launch, written "pending" (only this daemon creates it, exclusively): the command
740
+ * that runs first inside the scope empties it (scopeMarkArgv). */
741
+ async scopeMarker() {
742
+ const marker = this.fileOps.tmpName();
743
+ await this.fileOps.writeFile(marker, SCOPE_MARKER_PENDING, { mode: 0o600, flag: "wx" });
744
+ return marker;
745
+ }
746
+ /** Whether a capped launch's command has started inside its scope, from its marker: `ran` (emptied), `pending`, or
747
+ * `unreadable`. */
748
+ async scopeMarkerState(marker) {
749
+ if (!marker)
750
+ return "unreadable";
751
+ try {
752
+ const text = await this.procRead(marker);
753
+ return text === "" ? "ran" : text === SCOPE_MARKER_PENDING ? "pending" : "unreadable";
754
+ }
755
+ catch {
756
+ return "unreadable";
757
+ }
758
+ }
759
+ /** Whether a capped launch's seat scope started: `started` once its command started inside the scope (the marker is
760
+ * emptied) and the pane's process is in a seat scope; `failed_before_command` when the pane died with the marker still
761
+ * pending (systemd-run could not make the scope, also late, after the check passed); `ran_and_ended` when it died
762
+ * after the command started inside the scope; `ran_unconfirmed` when the command started (the marker was emptied)
763
+ * but its process wasn't seen in the scope in time; `unknown` when the time ran out with the pane alive (its wrapper
764
+ * can still enter the scope and start the command after the last look) or the pane or the marker can't be read.
765
+ * The marker is removed at the end. */
766
+ async seatScopeStart(pane, marker) {
767
+ let sawRan = false;
768
+ try {
769
+ for (let i = 0; i < SEAT_SCOPE_START_CHECKS; i++) {
770
+ let dead;
771
+ try {
772
+ dead = await this.isPaneDead(pane);
773
+ }
774
+ catch {
775
+ return sawRan ? "ran_unconfirmed" : "unknown";
776
+ }
777
+ const mark = await this.scopeMarkerState(marker);
778
+ if (mark === "ran")
779
+ sawRan = true;
780
+ if (dead)
781
+ return mark === "ran" ? "ran_and_ended" : mark === "pending" ? "failed_before_command" : sawRan ? "ran_unconfirmed" : "unknown";
782
+ if (mark === "ran") {
783
+ try {
784
+ const pid = await this.getPanePid(pane);
785
+ const path = pid === null ? null : cgroupV2Path(await this.procRead(`/proc/${pid}/cgroup`));
786
+ if (path && /\/openrig-seat-[^/]+\.scope$/.test(path))
787
+ return "started";
788
+ }
789
+ catch { /* not readable at this moment: look again */ }
790
+ }
791
+ await this.scopeStartSleep(SEAT_SCOPE_START_CHECK_MS);
792
+ }
793
+ // Out of time with the pane alive: the wrapper may enter its scope and start the command after the last look.
794
+ return sawRan ? "ran_unconfirmed" : "unknown";
795
+ }
796
+ finally {
797
+ if (marker)
798
+ await this.fileOps.unlink(marker).catch(() => { });
799
+ }
800
+ }
801
+ /** The seat scope a pane's process runs in, read from the kernel: unknown when it can't be read, outside a seat scope,
802
+ * or in one, with its pids.max, pids.current and how many times a fork hit the limit (pids.events `max`). */
803
+ async readPaneScope(paneTarget) {
804
+ const pid = await this.getPanePid(paneTarget);
805
+ if (pid === null)
806
+ return { at: "unknown", reason: "the seat's pane process is not readable (not running?)" };
807
+ let path;
808
+ try {
809
+ path = cgroupV2Path(await this.procRead(`/proc/${pid}/cgroup`));
810
+ }
811
+ catch (error) {
812
+ return { at: "unknown", reason: `cgroup unreadable: ${error.message}` };
813
+ }
814
+ if (!path)
815
+ return { at: "unknown", reason: "no cgroup v2 path for the seat's process" };
816
+ const scope = path.split("/").pop() ?? "";
817
+ if (!/^openrig-seat-.+\.scope$/.test(scope))
818
+ return { at: "outside", scope };
819
+ try {
820
+ const dir = `/sys/fs/cgroup${path}`;
821
+ const pidsMax = (await this.procRead(`${dir}/pids.max`)).trim();
822
+ const pidsCurrent = Number((await this.procRead(`${dir}/pids.current`)).trim());
823
+ const hits = /^max (\d+)$/m.exec(await this.procRead(`${dir}/pids.events`));
824
+ return { at: "seat", scope, pidsMax, pidsCurrent, limitHits: hits ? Number(hits[1]) : 0 };
825
+ }
826
+ catch (error) {
827
+ return { at: "unknown", scope, reason: `scope files unreadable: ${error.message}` };
828
+ }
829
+ }
830
+ /** Where a seat's task limit stands, read back from its pane's process (#3253): its cgroup must be a seat scope whose
831
+ * pids.max is the requested value. pids.events `max` counts the forks the limit refused. `paneTarget` is the seat's
832
+ * pane id (`%N`) when known, else its session (whose active pane is read). With `nodeId`, a seat in an environment
833
+ * guest reads `not_applied` (its pane holds only a local viewer). Read only. */
834
+ async readSeatProcessLimits(paneTarget, requested, nodeId) {
835
+ const base = { requested: { tasksMax: requested.tasksMax } };
836
+ const policy = this.readLaunchPolicy();
837
+ // The running process is read first: a seat already under its limit reads `applied` whatever this daemon could
838
+ // create now. A seat not under it reads `unsupported` only on a positive inability (from the environment, or the
839
+ // last check's own positive answer, with its age); else `not_applied` ("requested, not applied").
840
+ const fixed = this.seatScopeStaticProblem(policy, nodeId);
841
+ // A guest seat's pane holds only a local viewer: its readback says nothing of the agent's processes.
842
+ if (nodeId && this.seatInEnvironmentGuest?.(nodeId))
843
+ return { ...base, state: "not_applied", reason: fixed.reason };
844
+ const last = this.seatScopeLastPositive && Date.now() - this.seatScopeLastPositive.at < SEAT_SCOPE_RETRY_MS
845
+ ? this.seatScopeLastPositive : undefined;
846
+ const unsupported = fixed?.kind === "unsupported" ? fixed.reason
847
+ : last ? `${last.problem.reason}, observed ${Math.floor((Date.now() - last.at) / 1000)}s ago` : null;
848
+ const notUnder = (reason) => unsupported ? { ...base, state: "unsupported", reason: `${reason}; and this host can't make the scope: ${unsupported}` }
849
+ : fixed ? { ...base, state: "not_applied", reason: `${reason}; and this setup can't make the scope: ${fixed.reason}` }
850
+ : { ...base, state: "not_applied", reason };
851
+ const read = await this.readPaneScope(paneTarget);
852
+ if (read.at === "unknown")
853
+ return { ...base, state: "unknown", ...(read.scope ? { scope: read.scope } : {}), reason: read.reason };
854
+ if (read.at === "outside") {
855
+ return notUnder(`the seat's process is not in a seat scope (${read.scope}); the limit applies at its next fresh launch`);
856
+ }
857
+ const { at: _at, ...scopeRead } = read;
858
+ return read.pidsMax === String(requested.tasksMax)
859
+ ? { ...base, state: "applied", ...scopeRead }
860
+ : { ...base, state: "not_applied", ...scopeRead, reason: `pids.max is ${read.pidsMax}, not ${requested.tasksMax}; the limit applies at its next fresh launch` };
861
+ }
301
862
  /** Reset before the selected user shell runs, without changing the server or other sessions.
302
863
  * Multiple tmux command arguments execute directly; only this fixed non-interactive sh runs
303
864
  * before env -i. Generated pane metadata must come from this spawn, never daemon TMUX values.
304
865
  * Keep the configured default-command and default-shell lookup, including rc functions.
305
866
  */
306
- async scopedLaunchCommand(seatEnv, command, warnings = []) {
307
- if (!this.launchEnvironment || !seatEnv.OPENRIG_NODE_ID)
867
+ async scopedLaunchCommand(seatEnv, command, warnings = [], limitsMode = "fresh", notices) {
868
+ // #3253: a seat with a limit gets its scope. Where it can't: a fresh launch is not started and says why; a recovery
869
+ // goes ahead without it, with a structured warning, and the request stays stored.
870
+ const lookup = seatEnv.OPENRIG_NODE_ID ? this.seatLimitsLookup(seatEnv.OPENRIG_NODE_ID) : undefined;
871
+ // Read once: the scope check and the launch below must see the same setting.
872
+ const policy = seatEnv.OPENRIG_NODE_ID ? this.readLaunchPolicy() : undefined;
873
+ let seatScope = [];
874
+ let limited = false;
875
+ const notApplied = (problem) => {
876
+ if (limitsMode === "fresh")
877
+ throw new SeatProcessLimitsNotApplied(problem);
878
+ const notice = notAppliedNotice(problem);
879
+ if (notices) {
880
+ notices.processLimits = notice;
881
+ notices.capped = false;
882
+ }
883
+ // Logged by the launch once it has gone on without the limit.
884
+ warnings.push(noticeLine(notice));
885
+ limited = false;
886
+ };
887
+ if (lookup) {
888
+ if ("invalid" in lookup)
889
+ notApplied({ kind: "invalid", reason: lookup.invalid });
890
+ else if (notices?.failedStart)
891
+ notApplied({ ...notices.failedStart, requested: { tasksMax: lookup.limits.tasksMax } });
892
+ else {
893
+ const outcome = await this.seatScope(lookup.limits, seatEnv, policy);
894
+ if (outcome.ok) {
895
+ seatScope = outcome.prefix;
896
+ limited = true;
897
+ }
898
+ else
899
+ notApplied(outcome.problem);
900
+ }
901
+ }
902
+ if (!policy || !seatEnv.OPENRIG_NODE_ID)
903
+ return null;
904
+ if (!(policy instanceof Error) && policy.inheritTmuxEnvironment) {
905
+ if (limited)
906
+ notApplied({ kind: "setup", reason: INHERIT_TMUX_ENVIRONMENT_REASON, requested: { tasksMax: lookup.limits.tasksMax } });
308
907
  return null;
908
+ }
309
909
  try {
310
- const policy = this.launchEnvironment();
311
- if (policy.inheritTmuxEnvironment)
312
- return null;
910
+ if (policy instanceof Error)
911
+ throw policy;
313
912
  if (process.platform === "win32")
314
913
  throw new Error("POSIX launch boundary unavailable");
315
914
  let shell = await this.getDefaultShell();
@@ -350,9 +949,28 @@ export class TmuxAdapter {
350
949
  await this.fileOps.writeFile(file, `/bin/rm -f -- ${shellQuote(file)}\n${values.join("\n")}\nexec "$@"\n`, { mode: 0o600, flag: "wx" });
351
950
  // tmux supplies its terminal identity per pane; the daemon's terminal may be different.
352
951
  const reset = 'exec /usr/bin/env -i -- TMUX="$TMUX" TMUX_PANE="$TMUX_PANE" TERM="$TERM" TERM_PROGRAM="${TERM_PROGRAM-}" TERM_PROGRAM_VERSION="${TERM_PROGRAM_VERSION-}" SHELL="$SHELL" /bin/sh "$@"';
353
- return ["/bin/sh", "-c", reset, "sh", file, shell, ...(command ? ["-c", command] : ["-l"])];
952
+ // #3253: a seat with a limit enters its scope only after this file has run (its /bin/rm forks, outside the scope),
953
+ // marks that its command started there, and gets back its own bus and runtime directory, which systemd-run's call
954
+ // needed set otherwise.
955
+ const marker = seatScope.length ? await this.scopeMarker() : undefined;
956
+ const restore = seatScope.length ? [...scopeMarkArgv(marker), ...restoreEnvArgv({
957
+ DBUS_SESSION_BUS_ADDRESS: selected.DBUS_SESSION_BUS_ADDRESS, XDG_RUNTIME_DIR: selected.XDG_RUNTIME_DIR
958
+ })] : [];
959
+ if (notices) {
960
+ notices.capped = seatScope.length > 0;
961
+ if (marker) {
962
+ notices.marker = marker;
963
+ notices.tasksMax = lookup.limits.tasksMax;
964
+ }
965
+ }
966
+ return ["/bin/sh", "-c", reset, "sh", file, ...seatScope, ...restore, shell, ...(command ? ["-c", command] : ["-l"])];
354
967
  }
355
- catch {
968
+ catch (error) {
969
+ if (limited) {
970
+ const tasksMax = lookup.limits.tasksMax;
971
+ notApplied({ kind: "unverified", reason: `the scoped launch environment failed: ${error.message}`,
972
+ requested: { tasksMax } });
973
+ }
356
974
  // Keep the working launch, with a diagnostic; this option is not a new admission gate.
357
975
  const warning = "Scoped tmux environment unavailable; retaining the previous environment for this launch.";
358
976
  warnings.push(warning);
@@ -360,6 +978,107 @@ export class TmuxAdapter {
360
978
  return null;
361
979
  }
362
980
  }
981
+ /** A bare-pane respawn that keeps the seat's limit (a restart in place whose process reads back under it, #3253): the
982
+ * command runs as the pane's default shell would run it, inside a new seat scope, with the bus and runtime directory
983
+ * the pane would get from tmux. Recovery only: where the scope can't be made, the respawn goes on without it. */
984
+ async keptScopeCommand(nodeId, pane, command, warnings, notices) {
985
+ const lookup = this.seatLimitsLookup(nodeId);
986
+ if (!lookup)
987
+ return null;
988
+ const notApplied = (problem) => {
989
+ const notice = notAppliedNotice(problem);
990
+ notices.processLimits = notice;
991
+ notices.capped = false;
992
+ warnings.push(noticeLine(notice));
993
+ return null;
994
+ };
995
+ if ("invalid" in lookup)
996
+ return notApplied({ kind: "invalid", reason: lookup.invalid });
997
+ const requested = { tasksMax: lookup.limits.tasksMax };
998
+ if (notices.failedStart)
999
+ return notApplied({ ...notices.failedStart, requested });
1000
+ const outcome = await this.seatScope(lookup.limits, { OPENRIG_NODE_ID: nodeId }, this.readLaunchPolicy());
1001
+ if (!outcome.ok)
1002
+ return notApplied(outcome.problem);
1003
+ try {
1004
+ if (!command)
1005
+ throw new Error("a kept scope needs the respawn's command");
1006
+ const shell = await this.getDefaultShell();
1007
+ if (!shell)
1008
+ throw new Error("Default shell unavailable");
1009
+ const restore = restoreEnvArgv({
1010
+ DBUS_SESSION_BUS_ADDRESS: await this.paneStartEnv(pane, "DBUS_SESSION_BUS_ADDRESS"),
1011
+ XDG_RUNTIME_DIR: await this.paneStartEnv(pane, "XDG_RUNTIME_DIR"),
1012
+ });
1013
+ const marker = await this.scopeMarker();
1014
+ notices.capped = true;
1015
+ notices.marker = marker;
1016
+ notices.tasksMax = requested.tasksMax;
1017
+ return [...outcome.prefix, ...scopeMarkArgv(marker), ...restore, shell, "-c", command];
1018
+ }
1019
+ catch (error) {
1020
+ return notApplied({ kind: "unverified", reason: `the kept scope's launch could not be prepared: ${error.message}`, requested });
1021
+ }
1022
+ }
1023
+ /** The value a new process in this pane's session gets for `key` from tmux: the session's own (undefined when it is
1024
+ * marked removed), else the server's global one. Throws when the environment can't be read. */
1025
+ async paneStartEnv(pane, key) {
1026
+ const lines = await this.sessionEnvLines(pane);
1027
+ if (lines === null)
1028
+ throw new Error("Cannot read the session's launch environment.");
1029
+ if (lines.includes(`-${key}`))
1030
+ return undefined;
1031
+ const own = lines.find((line) => line.startsWith(`${key}=`));
1032
+ if (own !== undefined)
1033
+ return own.slice(key.length + 1);
1034
+ return (await this.globalEnvironment())[key];
1035
+ }
1036
+ /** A launch's success result. A recovery that went on without the limit, or can't tell where it stands, is logged here,
1037
+ * only once the launch has gone on. */
1038
+ launched(warnings, notices) {
1039
+ if (notices.processLimits)
1040
+ console.warn(`[seat launch] ${noticeLine(notices.processLimits)}`);
1041
+ return { ok: true, ...(warnings.length ? { warnings } : {}), ...(notices.processLimits ? { processLimits: notices.processLimits } : {}) };
1042
+ }
1043
+ /** After a capped launch made its pane: whether its scope started. A fresh launch counts only once it has (a command
1044
+ * that started in the scope and ended counts too); otherwise it is refused as `unverified`, never retried without the
1045
+ * limit. A recovery runs the command again without the limit only when it failed before the command started; when
1046
+ * the start can't be told, it goes on with an `unknown` notice and runs nothing again. Null: the launch stands. */
1047
+ async scopeStartOutcome(pane, mode, notices, warnings) {
1048
+ // No pane to watch: whether its command started can't be told.
1049
+ const start = pane ? await this.seatScopeStart(pane, notices.marker) : "unknown";
1050
+ if (!pane && notices.marker)
1051
+ await this.fileOps.unlink(notices.marker).catch(() => { });
1052
+ if (start === "started")
1053
+ return null;
1054
+ const requested = notices.tasksMax !== undefined ? { requested: { tasksMax: notices.tasksMax } } : {};
1055
+ const failedBefore = "the seat's scope did not start: its pane's command exited before entering it";
1056
+ if (mode !== "recovery") {
1057
+ if (start === "ran_and_ended")
1058
+ return null;
1059
+ if (start === "ran_unconfirmed") {
1060
+ return { refuse: { kind: "unverified", ...requested, commandStarted: true,
1061
+ reason: "the seat's command started, but its process was not seen in the seat's scope in time" } };
1062
+ }
1063
+ if (start === "unknown") {
1064
+ return { refuse: { kind: "unverified", ...requested, commandStarted: "unknown",
1065
+ reason: "the seat's scope start was not confirmed in time, so whether its command started is unknown" } };
1066
+ }
1067
+ // Only a pane that died with the marker still pending failed before the command.
1068
+ return { refuse: { kind: "unverified", ...requested, reason: failedBefore } };
1069
+ }
1070
+ if (start === "failed_before_command")
1071
+ return { retryUncapped: { kind: "unverified", reason: failedBefore } };
1072
+ const notice = unknownNotice({ kind: "unverified", ...requested,
1073
+ reason: start === "ran_and_ended"
1074
+ ? "the seat's command started in its scope and ended before it was seen running; it was not run again"
1075
+ : start === "ran_unconfirmed"
1076
+ ? "the seat's command started, but its process was not seen in the seat's scope in time; it was not run again"
1077
+ : "the seat's scope start was not confirmed in time; the seat was not started again" });
1078
+ notices.processLimits = notice;
1079
+ warnings.push(noticeLine(notice));
1080
+ return null;
1081
+ }
363
1082
  inputGuard;
364
1083
  get deliveryGuard() { return this.inputGuard; }
365
1084
  set deliveryGuard(guard) {
@@ -810,11 +1529,11 @@ export class TmuxAdapter {
810
1529
  const probe = await this.probeSession(name);
811
1530
  return probe.state === "present";
812
1531
  }
813
- async createSession(name, cwd, env) {
1532
+ async createSession(name, cwd, env, launchOpts) {
814
1533
  if (this.deliveryGuard && (!env?.OPENRIG_NODE_ID || !this.deliveryGuard.ownsLifecycle(env.OPENRIG_NODE_ID))) {
815
1534
  return { ok: false, code: "guard_lease_required", message: "Managed launch requires a lifecycle lease before terminal creation." };
816
1535
  }
817
- const result = await this.createSessionUnchecked(name, cwd, env);
1536
+ const result = await this.createSessionUnchecked(name, cwd, env, launchOpts);
818
1537
  if (result.ok && this.deliveryGuard && env?.OPENRIG_NODE_ID) {
819
1538
  try {
820
1539
  const panes = await this.listPanes(name);
@@ -912,7 +1631,7 @@ export class TmuxAdapter {
912
1631
  }
913
1632
  });
914
1633
  }
915
- async createSessionUnchecked(name, cwd, env) {
1634
+ async createSessionUnchecked(name, cwd, env, launchOpts) {
916
1635
  // These are the daemon's resolved capture settings, not seat overrides.
917
1636
  // An empty per-session value prevents the tmux server's inherited values
918
1637
  // from pinning an old policy over config.json inside a newly launched seat.
@@ -927,35 +1646,80 @@ export class TmuxAdapter {
927
1646
  argv.push("-c", cwd);
928
1647
  for (const [k, v] of Object.entries(seatEnv))
929
1648
  argv.push("-e", `${k}=${v}`);
930
- // The pane new-session itself made: an after-new-session hook may select another window.
931
- argv.push("-P", "-F", "#{pane_id}");
932
1649
  const legacyParts = ["tmux", "new-session", "-d", "-s", tmuxConfigQuote(name)];
933
1650
  if (cwd != null)
934
1651
  legacyParts.push("-c", tmuxConfigQuote(cwd));
935
1652
  for (const [k, v] of Object.entries(seatEnv))
936
1653
  legacyParts.push("-e", tmuxConfigQuote(`${k}=${v}`));
937
- legacyParts.push("-P", "-F", tmuxConfigQuote("#{pane_id}"));
938
1654
  const warnings = [];
939
- const scopedCommand = await this.scopedLaunchCommand(seatEnv, undefined, warnings);
1655
+ let scopedCommand;
1656
+ const notices = launchOpts?.failedStart ? { failedStart: launchOpts.failedStart } : {};
1657
+ try {
1658
+ scopedCommand = await this.scopedLaunchCommand(seatEnv, undefined, warnings, launchOpts?.processLimitsMode, notices);
1659
+ }
1660
+ catch (error) {
1661
+ if (error instanceof SeatProcessLimitsNotApplied)
1662
+ return processLimitsNotAppliedResult(error);
1663
+ throw error;
1664
+ }
1665
+ // The pane new-session itself made: an after-new-session hook may select another window. A capped launch also
1666
+ // prints, from the same command, the session it made and its server (pid and start time), so a refusal below
1667
+ // removes that session and no other: a server that exits and comes back reuses pane and session ids.
1668
+ const printFormat = notices.capped ? CREATED_IDENTITY_FORMAT : "#{pane_id}";
1669
+ argv.push("-P", "-F", printFormat);
1670
+ legacyParts.push("-P", "-F", tmuxConfigQuote(printFormat));
940
1671
  if (scopedCommand) {
941
1672
  argv.push(...scopedCommand);
942
1673
  legacyParts.push(...scopedCommand.map(tmuxConfigQuote));
943
1674
  }
944
- let created;
1675
+ let printed;
945
1676
  try {
946
- created = (await this.runEnvironmentCommand(argv, legacyParts.join(" "), true)).trim();
1677
+ printed = (await this.runEnvironmentCommand(argv, legacyParts.join(" "), true)).trim();
947
1678
  }
948
1679
  catch (err) {
949
1680
  return classifyWriteError(err);
950
1681
  }
1682
+ // A capped launch reads its pane and identity from the same, first, printed line (a hook may print more after it).
1683
+ const firstLine = notices.capped ? (printed.split("\n")[0] ?? "").trim() : printed;
1684
+ const made = notices.capped ? createdIdentity(firstLine) : null;
1685
+ const created = notices.capped ? (firstLine.split(" ")[0] ?? "") : printed;
951
1686
  // tmux can exit 0 having made nothing: a server that can't create its socket prints its error and quits, and the
952
1687
  // client still exits 0. new-session prints the pane it made; with none, the session must be read back before the
953
1688
  // launch counts as created.
954
1689
  if (!/^%\d+$/.test(created)) {
955
1690
  const unconfirmed = await this.sessionUnconfirmedAfterCreate(name);
1691
+ // #3253: a capped launch whose session can't be read back may be running uncapped: the possibly-running refusal
1692
+ // (no retry, how to look and stop it). A session positively absent stays session_not_created.
1693
+ // Only a fresh launch: a recovery never stops for the limit, and keeps the plain session_unconfirmed.
1694
+ if (unconfirmed?.code === "session_unconfirmed" && notices.capped && launchOpts?.processLimitsMode !== "recovery") {
1695
+ if (notices.marker)
1696
+ await this.fileOps.unlink(notices.marker).catch(() => { });
1697
+ return processLimitsNotAppliedResult(new SeatProcessLimitsNotApplied({ kind: "unverified", commandStarted: "unknown",
1698
+ ...(notices.tasksMax !== undefined ? { requested: { tasksMax: notices.tasksMax } } : {}),
1699
+ reason: `tmux printed no pane for the launch and its session couldn't be read back (${unconfirmed.message})` }), await this.removeRefusedSession(name, null));
1700
+ }
956
1701
  if (unconfirmed)
957
1702
  return { ok: false, ...unconfirmed };
958
1703
  }
1704
+ // #3253: a capped launch counts only once its scope is seen to start. A fresh one that isn't is refused and the
1705
+ // session it made is removed (never a retry without the limit). A recovery (a provider switch's staged successor)
1706
+ // never stops for the limit: when systemd-run fails after the check passed, the pane's command exits before
1707
+ // entering the scope, and the seat starts again without the limit, with the warning (in the same pane when tmux
1708
+ // kept it, else in a new session of the same name); when the start can't be told, nothing is run again.
1709
+ if (notices.capped) {
1710
+ const outcome = await this.scopeStartOutcome(/^%\d+$/.test(created) ? created : null, launchOpts?.processLimitsMode, notices, warnings);
1711
+ if (outcome && "refuse" in outcome) {
1712
+ return processLimitsNotAppliedResult(new SeatProcessLimitsNotApplied(outcome.refuse), await this.removeRefusedSession(name, made));
1713
+ }
1714
+ if (outcome) {
1715
+ const failedStart = outcome.retryUncapped;
1716
+ const kept = await this.probeSession(name).catch(() => ({ state: "unknown" }));
1717
+ return kept.state === "present"
1718
+ ? this.respawnPaneUnchecked(created, undefined, { ...(cwd != null ? { cwd } : {}), env: seatEnv,
1719
+ processLimitsMode: "recovery", failedStart })
1720
+ : this.createSessionUnchecked(name, cwd, env, { processLimitsMode: "recovery", failedStart });
1721
+ }
1722
+ }
959
1723
  // A tmux server started from a Claude Code session or Herdr pane hands
960
1724
  // their identity to every new pane. Mark it removed for this session only
961
1725
  // and restart the fresh pane so its shell starts without it. The session
@@ -969,10 +1733,10 @@ export class TmuxAdapter {
969
1733
  respawn.push("-c", cwd);
970
1734
  await this.run(respawn, posixJoinArgv(respawn));
971
1735
  }
972
- return warnings.length ? { ok: true, warnings } : { ok: true };
1736
+ return this.launched(warnings, notices);
973
1737
  }
974
1738
  catch (err) {
975
- return { ok: true, warnings: [...warnings, parentSessionEnvWarning(name, err)] };
1739
+ return this.launched([...warnings, parentSessionEnvWarning(name, err)], notices);
976
1740
  }
977
1741
  }
978
1742
  /** When new-session printed no pane: why the launch can't count as created, or null when the session is there. Only a
@@ -1285,6 +2049,26 @@ export class TmuxAdapter {
1285
2049
  return classifyWriteError(err);
1286
2050
  }
1287
2051
  }
2052
+ /** #3253: removes the session a refused fresh launch made, by the identity its new-session printed, and only while
2053
+ * that id is that session on that server. Null when it is gone (removed now, or already gone with its pane or its
2054
+ * server); otherwise the sentence the refusal adds: the session may still be running, and how to look and stop it.
2055
+ * Without a printed identity nothing is removed, never by name (a same-named session may not be this launch's). */
2056
+ async removeRefusedSession(name, made) {
2057
+ const look = ` Look with \`${tmuxOnDaemonServer()} attach -t ${shellQuote(`=${name}`)}\` and stop it with `
2058
+ + `\`${tmuxOnDaemonServer()} kill-session -t ${shellQuote(`=${name}`)}\` if it is this launch's.`;
2059
+ if (!made)
2060
+ return `Its session "${name}" may still be running: tmux didn't print the session it made, so it was not removed.${look}`;
2061
+ const removed = await this.killSessionUnchecked(made.session, undefined, undefined, made.server)
2062
+ .catch((err) => classifyWriteError(err));
2063
+ // Gone either way: removed now, no longer there (session_not_found), or its server was replaced (guard_target_changed:
2064
+ // the id names another terminal now, and the server that held this session is gone with it).
2065
+ if (removed.ok || removed.code === "session_not_found" || removed.code === "guard_target_changed")
2066
+ return null;
2067
+ // tmux's own words, without an exec wrapper's "Command failed: <command>" line.
2068
+ const said = removed.message.split("\n").map(line => line.trim()).filter(line => line && !line.startsWith("Command failed:")).join(" ")
2069
+ || removed.message.trim();
2070
+ return `Its session "${name}" (${made.session}) may still be running: it could not be removed (${said}).${look}`;
2071
+ }
1288
2072
  /** With a delivery guard, terminate by immutable tmux session ID; checked callers validate before detach and kill.
1289
2073
  * A seat's session is stopped only when it carries that seat's OpenRig marker, and each effect runs only while that
1290
2074
  * id still names a session on the server it was read from: a replaced server reuses ids for other terminals. */
@@ -1428,7 +2212,18 @@ export class TmuxAdapter {
1428
2212
  for (const [k, v] of Object.entries(opts.env))
1429
2213
  argv.push("-e", `${k}=${v}`);
1430
2214
  const warnings = [];
1431
- const scopedCommand = await this.scopedLaunchCommand(opts?.env ?? {}, command, warnings);
2215
+ let scopedCommand;
2216
+ const notices = opts?.failedStart ? { failedStart: opts.failedStart } : {};
2217
+ try {
2218
+ scopedCommand = opts?.keepLimitOf && !opts.env
2219
+ ? await this.keptScopeCommand(opts.keepLimitOf, exact, command, warnings, notices)
2220
+ : await this.scopedLaunchCommand(opts?.env ?? {}, command, warnings, opts?.processLimitsMode, notices);
2221
+ }
2222
+ catch (error) {
2223
+ if (error instanceof SeatProcessLimitsNotApplied)
2224
+ return processLimitsNotAppliedResult(error);
2225
+ throw error;
2226
+ }
1432
2227
  // Legacy commands remain one argument; the scoped wrapper executes directly before the user shell.
1433
2228
  if (scopedCommand)
1434
2229
  argv.push(...scopedCommand);
@@ -1459,7 +2254,19 @@ export class TmuxAdapter {
1459
2254
  await this.runEnvironmentCommand(argv, legacyRespawn.join(" "));
1460
2255
  else
1461
2256
  await this.run(argv, legacyRespawn.join(" "));
1462
- return warnings.length ? { ok: true, warnings } : { ok: true };
2257
+ // #3253: a capped respawn counts only once its scope is seen to start. A fresh one that isn't is refused (the pane
2258
+ // is not this launch's to remove). A recovery never stops for the limit, also when systemd-run fails at this
2259
+ // moment (after the check passed): its pane's command exits before the seat's command starts in the scope, and
2260
+ // the recovery starts it again without the limit, with the warning; when the start can't be told, it runs
2261
+ // nothing again.
2262
+ if (notices.capped) {
2263
+ const outcome = await this.scopeStartOutcome(exact, opts?.keepLimitOf ? "recovery" : opts?.processLimitsMode, notices, warnings);
2264
+ if (outcome && "refuse" in outcome)
2265
+ return processLimitsNotAppliedResult(new SeatProcessLimitsNotApplied(outcome.refuse));
2266
+ if (outcome)
2267
+ return this.respawnPaneUnchecked(paneTarget, command, { ...opts, failedStart: outcome.retryUncapped });
2268
+ }
2269
+ return this.launched(warnings, notices);
1463
2270
  }
1464
2271
  catch (err) {
1465
2272
  return classifyWriteError(err);
@@ -1701,16 +2508,15 @@ export class TmuxAdapter {
1701
2508
  const target = exactTarget(session, "session");
1702
2509
  await this.runEnvironmentCommand(["tmux", "set-environment", "-t", target, key, value], `tmux set-environment -t ${tmuxConfigQuote(target)} ${tmuxConfigQuote(key)} ${tmuxConfigQuote(value)}`);
1703
2510
  }
1704
- /** Remove one variable from a session's environment, so a process spawned there afterwards
1705
- * inherits the server's value for it, or none. A name that is the launching session's own
1706
- * identity in the server's environment (see parent-session-env) is marked removed instead, as a
1707
- * launch does, so the server's value does not come back. */
2511
+ /** Remove one variable from a session's environment. Ordinary names inherit the server's value
2512
+ * afterwards, if any. Credentials and the launching session's own identity are marked removed
2513
+ * instead, so they cannot come back from the server's global environment. */
1708
2514
  async unsetSessionEnv(session, key) {
1709
2515
  if (!/^[A-Z_][A-Z0-9_]*$/.test(key))
1710
2516
  throw new Error("Invalid session environment key.");
1711
2517
  const target = exactTarget(session, "session");
1712
- const parentIdentity = parentSessionEnvKeys(await this.globalEnvironment()).includes(key);
1713
- const flag = parentIdentity ? "-r" : "-u";
2518
+ const mustNotInherit = isTmuxCredentialEnvKey(key) || parentSessionEnvKeys(await this.globalEnvironment()).includes(key);
2519
+ const flag = mustNotInherit ? "-r" : "-u";
1714
2520
  await this.run(["tmux", "set-environment", "-t", target, flag, key], `tmux set-environment -t ${shellQuote(target)} ${flag} ${shellQuote(key)}`);
1715
2521
  }
1716
2522
  async globalEnvironment() {