@songsid/agend 2.4.0-beta.25 → 2.4.0-beta.27

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 (523) hide show
  1. package/dist/agent-endpoint.d.ts +1 -0
  2. package/dist/agent-endpoint.js +5 -0
  3. package/dist/agent-endpoint.js.map +1 -1
  4. package/dist/agent-file-read.js +1 -1
  5. package/dist/agent-file-read.js.map +1 -1
  6. package/dist/agent-whats-new.js +4 -0
  7. package/dist/agent-whats-new.js.map +1 -1
  8. package/dist/auth-api.js +3 -1
  9. package/dist/auth-api.js.map +1 -1
  10. package/dist/backend/kiro-auth-store.d.ts +15 -2
  11. package/dist/backend/kiro-auth-store.js +64 -0
  12. package/dist/backend/kiro-auth-store.js.map +1 -1
  13. package/dist/build-provenance.json +1 -1
  14. package/dist/channel/adapters/discord.js +4 -4
  15. package/dist/channel/adapters/discord.js.map +1 -1
  16. package/dist/channel/adapters/telegram.js +3 -3
  17. package/dist/channel/adapters/telegram.js.map +1 -1
  18. package/dist/channel/ipc-bridge.d.ts +7 -0
  19. package/dist/channel/ipc-bridge.js +45 -11
  20. package/dist/channel/ipc-bridge.js.map +1 -1
  21. package/dist/channel/mcp-server.js +3 -1
  22. package/dist/channel/mcp-server.js.map +1 -1
  23. package/dist/channel/mcp-tools.js +6 -4
  24. package/dist/channel/mcp-tools.js.map +1 -1
  25. package/dist/cli.js +35 -2
  26. package/dist/cli.js.map +1 -1
  27. package/dist/daemon.d.ts +64 -3
  28. package/dist/daemon.js +497 -102
  29. package/dist/daemon.js.map +1 -1
  30. package/dist/delivery-outbox.d.ts +107 -7
  31. package/dist/delivery-outbox.js +297 -9
  32. package/dist/delivery-outbox.js.map +1 -1
  33. package/dist/detached-fleet-stop.d.ts +40 -0
  34. package/dist/detached-fleet-stop.js +126 -0
  35. package/dist/detached-fleet-stop.js.map +1 -0
  36. package/dist/fleet-lock.d.ts +21 -0
  37. package/dist/fleet-lock.js +61 -2
  38. package/dist/fleet-lock.js.map +1 -1
  39. package/dist/fleet-manager.d.ts +502 -5
  40. package/dist/fleet-manager.js +2845 -228
  41. package/dist/fleet-manager.js.map +1 -1
  42. package/dist/fleet-windows-runtime.d.ts +39 -3
  43. package/dist/fleet-windows-runtime.js +208 -30
  44. package/dist/fleet-windows-runtime.js.map +1 -1
  45. package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +6 -1
  46. package/dist/general-knowledge/skills/hub/SKILL.md +17 -2
  47. package/dist/general-knowledge/skills/web-appearance/SKILL.md +3 -1
  48. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +102 -25
  49. package/dist/hub/admin-dashboard.js +1 -1
  50. package/dist/hub/admin-dashboard.js.map +1 -1
  51. package/dist/hub/agent-catalog.d.ts +1 -1
  52. package/dist/hub/agent-catalog.js +4 -3
  53. package/dist/hub/agent-catalog.js.map +1 -1
  54. package/dist/hub/agent-intro.d.ts +1 -1
  55. package/dist/hub/agent-intro.js +1 -1
  56. package/dist/hub/agent-intro.js.map +1 -1
  57. package/dist/hub/agent-pictures.d.ts +1 -1
  58. package/dist/hub/agent-pictures.js +4 -3
  59. package/dist/hub/agent-pictures.js.map +1 -1
  60. package/dist/hub/catalog.d.ts +2 -2
  61. package/dist/hub/catalog.js +16 -13
  62. package/dist/hub/catalog.js.map +1 -1
  63. package/dist/hub/client.js +16 -2
  64. package/dist/hub/client.js.map +1 -1
  65. package/dist/hub/compose/member.js +14 -2
  66. package/dist/hub/compose/member.js.map +1 -1
  67. package/dist/hub/compose/server.d.ts +1 -0
  68. package/dist/hub/compose/server.js +6 -3
  69. package/dist/hub/compose/server.js.map +1 -1
  70. package/dist/hub/fleet-updates.d.ts +2 -2
  71. package/dist/hub/fleet-updates.js +7 -5
  72. package/dist/hub/fleet-updates.js.map +1 -1
  73. package/dist/hub/fleet-versions.d.ts +1 -1
  74. package/dist/hub/fleet-versions.js +3 -2
  75. package/dist/hub/fleet-versions.js.map +1 -1
  76. package/dist/hub/group-policy/resources.d.ts +1 -1
  77. package/dist/hub/http/compose.js +59 -31
  78. package/dist/hub/http/compose.js.map +1 -1
  79. package/dist/hub/http/deps.d.ts +1 -0
  80. package/dist/hub/http/schema.js +4 -1
  81. package/dist/hub/http/schema.js.map +1 -1
  82. package/dist/hub/join/service.d.ts +6 -0
  83. package/dist/hub/join/service.js +10 -0
  84. package/dist/hub/join/service.js.map +1 -1
  85. package/dist/hub/member/room-ask.d.ts +7 -8
  86. package/dist/hub/member/room-ask.js +54 -13
  87. package/dist/hub/member/room-ask.js.map +1 -1
  88. package/dist/hub/member/room-post.d.ts +4 -0
  89. package/dist/hub/member/room-post.js +26 -1
  90. package/dist/hub/member/room-post.js.map +1 -1
  91. package/dist/hub/member/room-reaction-acks.d.ts +12 -0
  92. package/dist/hub/member/room-reaction-acks.js +44 -0
  93. package/dist/hub/member/room-reaction-acks.js.map +1 -0
  94. package/dist/hub/protocol.d.ts +62 -0
  95. package/dist/hub/protocol.js +5 -4
  96. package/dist/hub/protocol.js.map +1 -1
  97. package/dist/hub/quota.d.ts +2 -2
  98. package/dist/hub/quota.js +6 -4
  99. package/dist/hub/quota.js.map +1 -1
  100. package/dist/hub/read-statement.d.ts +6 -0
  101. package/dist/hub/read-statement.js +33 -0
  102. package/dist/hub/read-statement.js.map +1 -0
  103. package/dist/hub/recommendations.d.ts +1 -1
  104. package/dist/hub/recommendations.js +3 -2
  105. package/dist/hub/recommendations.js.map +1 -1
  106. package/dist/hub/representative.d.ts +2 -0
  107. package/dist/hub/representative.js +8 -4
  108. package/dist/hub/representative.js.map +1 -1
  109. package/dist/hub/roles/audit-details.d.ts +2 -0
  110. package/dist/hub/roles/audit-details.js +1 -1
  111. package/dist/hub/roles/audit-details.js.map +1 -1
  112. package/dist/hub/roles/authority.d.ts +8 -3
  113. package/dist/hub/roles/authority.js +144 -102
  114. package/dist/hub/roles/authority.js.map +1 -1
  115. package/dist/hub/roles/clock.js +6 -5
  116. package/dist/hub/roles/clock.js.map +1 -1
  117. package/dist/hub/roles/delegation.js +2 -2
  118. package/dist/hub/roles/delegation.js.map +1 -1
  119. package/dist/hub/roles/model.d.ts +5 -2
  120. package/dist/hub/roles/model.js +5 -4
  121. package/dist/hub/roles/model.js.map +1 -1
  122. package/dist/hub/roles/read.d.ts +2 -0
  123. package/dist/hub/roles/read.js +27 -6
  124. package/dist/hub/roles/read.js.map +1 -1
  125. package/dist/hub/roles/review.js +2 -2
  126. package/dist/hub/roles/review.js.map +1 -1
  127. package/dist/hub/room-history-model.d.ts +87 -0
  128. package/dist/hub/room-history-model.js +14 -0
  129. package/dist/hub/room-history-model.js.map +1 -0
  130. package/dist/hub/room-react-ack-model.d.ts +2 -0
  131. package/dist/hub/room-react-ack-model.js +3 -0
  132. package/dist/hub/room-react-ack-model.js.map +1 -0
  133. package/dist/hub/rooms/admin.d.ts +6 -0
  134. package/dist/hub/rooms/admin.js +33 -0
  135. package/dist/hub/rooms/admin.js.map +1 -1
  136. package/dist/hub/rooms/agents.d.ts +3 -1
  137. package/dist/hub/rooms/agents.js +47 -5
  138. package/dist/hub/rooms/agents.js.map +1 -1
  139. package/dist/hub/rooms/history.d.ts +8 -0
  140. package/dist/hub/rooms/history.js +31 -0
  141. package/dist/hub/rooms/history.js.map +1 -0
  142. package/dist/hub/rooms/schema.d.ts +2 -0
  143. package/dist/hub/rooms/schema.js +4 -0
  144. package/dist/hub/rooms/schema.js.map +1 -1
  145. package/dist/hub/rooms/service.d.ts +40 -20
  146. package/dist/hub/rooms/service.js +181 -50
  147. package/dist/hub/rooms/service.js.map +1 -1
  148. package/dist/hub/rooms/types.d.ts +2 -0
  149. package/dist/hub/server.js +15 -3
  150. package/dist/hub/server.js.map +1 -1
  151. package/dist/hub/session-epoch.js +2 -1
  152. package/dist/hub/session-epoch.js.map +1 -1
  153. package/dist/hub/settings-directory-decision.js +3 -2
  154. package/dist/hub/settings-directory-decision.js.map +1 -1
  155. package/dist/hub/settings-member-address-decision.js +2 -1
  156. package/dist/hub/settings-member-address-decision.js.map +1 -1
  157. package/dist/hub/settings-web-address-decision.js +2 -1
  158. package/dist/hub/settings-web-address-decision.js.map +1 -1
  159. package/dist/hub/store.d.ts +1 -0
  160. package/dist/hub/store.js +12 -4
  161. package/dist/hub/store.js.map +1 -1
  162. package/dist/hub/types.d.ts +4 -2
  163. package/dist/hub-agent-incarnation-record.d.ts +24 -0
  164. package/dist/hub-agent-incarnation-record.js +46 -0
  165. package/dist/hub-agent-incarnation-record.js.map +1 -0
  166. package/dist/human-delivery-receipts.d.ts +16 -4
  167. package/dist/human-delivery-receipts.js +26 -5
  168. package/dist/human-delivery-receipts.js.map +1 -1
  169. package/dist/instance-lifecycle.d.ts +9 -3
  170. package/dist/instance-lifecycle.js +27 -10
  171. package/dist/instance-lifecycle.js.map +1 -1
  172. package/dist/instructions.d.ts +1 -1
  173. package/dist/local-pane-endpoint.d.ts +14 -0
  174. package/dist/local-pane-endpoint.js +32 -0
  175. package/dist/local-pane-endpoint.js.map +1 -1
  176. package/dist/locale.js +54 -6
  177. package/dist/locale.js.map +1 -1
  178. package/dist/native-agent-admission.js +9 -0
  179. package/dist/native-agent-admission.js.map +1 -1
  180. package/dist/native-exec-context.d.ts +11 -0
  181. package/dist/native-exec-context.js +18 -0
  182. package/dist/native-exec-context.js.map +1 -0
  183. package/dist/native-exec-input.d.ts +56 -0
  184. package/dist/native-exec-input.js +89 -0
  185. package/dist/native-exec-input.js.map +1 -0
  186. package/dist/native-mcp.d.ts +9 -1
  187. package/dist/native-mcp.js +29 -7
  188. package/dist/native-mcp.js.map +1 -1
  189. package/dist/native-pane-lifecycle.d.ts +3 -0
  190. package/dist/native-pane-lifecycle.js +2 -0
  191. package/dist/native-pane-lifecycle.js.map +1 -1
  192. package/dist/native-pane-manager.d.ts +18 -0
  193. package/dist/native-pane-manager.js +85 -8
  194. package/dist/native-pane-manager.js.map +1 -1
  195. package/dist/needs-you.d.ts +2 -1
  196. package/dist/needs-you.js.map +1 -1
  197. package/dist/outbound-handlers.d.ts +1 -0
  198. package/dist/outbound-handlers.js +9 -3
  199. package/dist/outbound-handlers.js.map +1 -1
  200. package/dist/outbound-schemas.d.ts +5 -0
  201. package/dist/outbound-schemas.js +2 -0
  202. package/dist/outbound-schemas.js.map +1 -1
  203. package/dist/public-web-gateway.js +5 -1
  204. package/dist/public-web-gateway.js.map +1 -1
  205. package/dist/recover.cjs +213 -26
  206. package/dist/reply-buttons-controller.d.ts +1 -0
  207. package/dist/reply-buttons-controller.js +1 -1
  208. package/dist/reply-buttons-controller.js.map +1 -1
  209. package/dist/request-contact-gate.d.ts +2 -0
  210. package/dist/request-contact-gate.js +8 -3
  211. package/dist/request-contact-gate.js.map +1 -1
  212. package/dist/request-contact-native.js +4 -0
  213. package/dist/request-contact-native.js.map +1 -1
  214. package/dist/request-context-activation.d.ts +29 -0
  215. package/dist/request-context-activation.js +74 -0
  216. package/dist/request-context-activation.js.map +1 -0
  217. package/dist/request-context-admission.d.ts +22 -0
  218. package/dist/request-context-admission.js +12 -0
  219. package/dist/request-context-admission.js.map +1 -0
  220. package/dist/request-context-boot.d.ts +35 -0
  221. package/dist/request-context-boot.js +97 -0
  222. package/dist/request-context-boot.js.map +1 -0
  223. package/dist/request-context-call.d.ts +2 -0
  224. package/dist/request-context-call.js.map +1 -1
  225. package/dist/request-context-continuation.d.ts +6 -0
  226. package/dist/request-context-continuation.js +24 -0
  227. package/dist/request-context-continuation.js.map +1 -0
  228. package/dist/request-context-control-api.d.ts +101 -0
  229. package/dist/request-context-control-api.js +177 -0
  230. package/dist/request-context-control-api.js.map +1 -0
  231. package/dist/request-context-control-copy.d.ts +3 -0
  232. package/dist/request-context-control-copy.js +7 -0
  233. package/dist/request-context-control-copy.js.map +1 -0
  234. package/dist/request-context-controller.d.ts +44 -0
  235. package/dist/request-context-controller.js +129 -0
  236. package/dist/request-context-controller.js.map +1 -0
  237. package/dist/request-context-delivery-resolver.d.ts +13 -0
  238. package/dist/request-context-delivery-resolver.js +30 -0
  239. package/dist/request-context-delivery-resolver.js.map +1 -0
  240. package/dist/request-context-drain.d.ts +13 -0
  241. package/dist/request-context-drain.js +79 -6
  242. package/dist/request-context-drain.js.map +1 -1
  243. package/dist/request-context-enable-offer.d.ts +13 -0
  244. package/dist/request-context-enable-offer.js +31 -0
  245. package/dist/request-context-enable-offer.js.map +1 -0
  246. package/dist/request-context-exec-owner.d.ts +39 -0
  247. package/dist/request-context-exec-owner.js +128 -0
  248. package/dist/request-context-exec-owner.js.map +1 -0
  249. package/dist/request-context-go-back-view.d.ts +1 -0
  250. package/dist/request-context-go-back-view.js +17 -0
  251. package/dist/request-context-go-back-view.js.map +1 -0
  252. package/dist/request-context-helper-readiness.d.ts +14 -0
  253. package/dist/request-context-helper-readiness.js +23 -0
  254. package/dist/request-context-helper-readiness.js.map +1 -0
  255. package/dist/request-context-helper.d.ts +20 -0
  256. package/dist/request-context-helper.js +41 -0
  257. package/dist/request-context-helper.js.map +1 -0
  258. package/dist/request-context-hub-resolver.d.ts +29 -0
  259. package/dist/request-context-hub-resolver.js +90 -0
  260. package/dist/request-context-hub-resolver.js.map +1 -0
  261. package/dist/request-context-human-resolver.d.ts +20 -0
  262. package/dist/request-context-human-resolver.js +77 -0
  263. package/dist/request-context-human-resolver.js.map +1 -0
  264. package/dist/request-context-human.d.ts +106 -0
  265. package/dist/request-context-human.js +153 -0
  266. package/dist/request-context-human.js.map +1 -0
  267. package/dist/request-context-inputs.d.ts +21 -0
  268. package/dist/request-context-inputs.js +63 -0
  269. package/dist/request-context-inputs.js.map +1 -0
  270. package/dist/request-context-installation.d.ts +117 -0
  271. package/dist/request-context-installation.js +328 -0
  272. package/dist/request-context-installation.js.map +1 -0
  273. package/dist/request-context-knowledge.d.ts +5 -0
  274. package/dist/request-context-knowledge.js +32 -0
  275. package/dist/request-context-knowledge.js.map +1 -0
  276. package/dist/request-context-native-human.d.ts +20 -0
  277. package/dist/request-context-native-human.js +91 -0
  278. package/dist/request-context-native-human.js.map +1 -0
  279. package/dist/request-context-native-output.d.ts +15 -0
  280. package/dist/request-context-native-output.js +46 -0
  281. package/dist/request-context-native-output.js.map +1 -0
  282. package/dist/request-context-native-result.d.ts +15 -0
  283. package/dist/request-context-native-result.js +46 -0
  284. package/dist/request-context-native-result.js.map +1 -0
  285. package/dist/request-context-off.d.ts +22 -0
  286. package/dist/request-context-off.js +77 -0
  287. package/dist/request-context-off.js.map +1 -0
  288. package/dist/request-context-outside-label.d.ts +5 -0
  289. package/dist/request-context-outside-label.js +28 -0
  290. package/dist/request-context-outside-label.js.map +1 -0
  291. package/dist/request-context-pane.d.ts +8 -0
  292. package/dist/request-context-pane.js +19 -0
  293. package/dist/request-context-pane.js.map +1 -1
  294. package/dist/request-context-pending-work.d.ts +11 -0
  295. package/dist/request-context-pending-work.js +43 -0
  296. package/dist/request-context-pending-work.js.map +1 -0
  297. package/dist/request-context-policy.d.ts +17 -1
  298. package/dist/request-context-policy.js +84 -6
  299. package/dist/request-context-policy.js.map +1 -1
  300. package/dist/request-context-readiness.d.ts +49 -0
  301. package/dist/request-context-readiness.js +64 -0
  302. package/dist/request-context-readiness.js.map +1 -0
  303. package/dist/request-context-recovery.d.ts +6 -2
  304. package/dist/request-context-recovery.js +25 -0
  305. package/dist/request-context-recovery.js.map +1 -1
  306. package/dist/request-context-relay.d.ts +2 -2
  307. package/dist/request-context-relay.js +10 -10
  308. package/dist/request-context-relay.js.map +1 -1
  309. package/dist/request-context-retirement.d.ts +19 -0
  310. package/dist/request-context-retirement.js +16 -0
  311. package/dist/request-context-retirement.js.map +1 -0
  312. package/dist/request-context-start.d.ts +15 -0
  313. package/dist/request-context-start.js +2 -0
  314. package/dist/request-context-start.js.map +1 -0
  315. package/dist/request-context-turns.d.ts +1 -1
  316. package/dist/request-context-turns.js +3 -2
  317. package/dist/request-context-turns.js.map +1 -1
  318. package/dist/request-context-unproved-label.d.ts +4 -0
  319. package/dist/request-context-unproved-label.js +25 -0
  320. package/dist/request-context-unproved-label.js.map +1 -0
  321. package/dist/request-context-update-guard.d.ts +15 -0
  322. package/dist/request-context-update-guard.js +54 -0
  323. package/dist/request-context-update-guard.js.map +1 -0
  324. package/dist/request-context-work.d.ts +50 -0
  325. package/dist/request-context-work.js +178 -0
  326. package/dist/request-context-work.js.map +1 -0
  327. package/dist/request-hub-context.d.ts +1 -0
  328. package/dist/request-hub-output.d.ts +2 -0
  329. package/dist/request-hub-output.js +12 -0
  330. package/dist/request-hub-output.js.map +1 -1
  331. package/dist/retained-human-control.d.ts +11 -0
  332. package/dist/retained-human-control.js +11 -0
  333. package/dist/retained-human-control.js.map +1 -0
  334. package/dist/runtime-build-info.js +1 -1
  335. package/dist/runtime-build-info.js.map +1 -1
  336. package/dist/runtime-cli.js +1 -1
  337. package/dist/runtime-cli.js.map +1 -1
  338. package/dist/runtime-client-store.js +7 -1
  339. package/dist/runtime-client-store.js.map +1 -1
  340. package/dist/runtime-client.js +15 -3
  341. package/dist/runtime-client.js.map +1 -1
  342. package/dist/runtime-coordinator.d.ts +23 -0
  343. package/dist/runtime-coordinator.js +103 -4
  344. package/dist/runtime-coordinator.js.map +1 -1
  345. package/dist/runtime-pane-mcp.d.ts +9 -0
  346. package/dist/runtime-pane-mcp.js +22 -2
  347. package/dist/runtime-pane-mcp.js.map +1 -1
  348. package/dist/runtime-protocol.d.ts +2 -0
  349. package/dist/runtime-protocol.js.map +1 -1
  350. package/dist/runtime-update-controller.js +1 -1
  351. package/dist/runtime-update-controller.js.map +1 -1
  352. package/dist/runtime-windows-bridge.d.ts +8 -0
  353. package/dist/runtime-windows-bridge.js +50 -3
  354. package/dist/runtime-windows-bridge.js.map +1 -1
  355. package/dist/scheduler/scheduler.d.ts +9 -0
  356. package/dist/scheduler/scheduler.js +26 -0
  357. package/dist/scheduler/scheduler.js.map +1 -1
  358. package/dist/scheduler/scheduler.test.js +17 -0
  359. package/dist/scheduler/scheduler.test.js.map +1 -1
  360. package/dist/service-install-handover.d.ts +52 -0
  361. package/dist/service-install-handover.js +50 -0
  362. package/dist/service-install-handover.js.map +1 -0
  363. package/dist/service-installer.d.ts +12 -0
  364. package/dist/service-installer.js +24 -10
  365. package/dist/service-installer.js.map +1 -1
  366. package/dist/settings-api.d.ts +2 -0
  367. package/dist/settings-api.js +76 -0
  368. package/dist/settings-api.js.map +1 -1
  369. package/dist/settings-baseline.d.ts +1 -0
  370. package/dist/settings-baseline.js +5 -4
  371. package/dist/settings-baseline.js.map +1 -1
  372. package/dist/settings-change.js +13 -0
  373. package/dist/settings-change.js.map +1 -1
  374. package/dist/settings-confirmation.d.ts +2 -0
  375. package/dist/settings-confirmation.js +6 -0
  376. package/dist/settings-confirmation.js.map +1 -1
  377. package/dist/settings-effect.d.ts +2 -0
  378. package/dist/settings-effect.js +55 -2
  379. package/dist/settings-effect.js.map +1 -1
  380. package/dist/settings-http-confirmation.d.ts +3 -0
  381. package/dist/settings-http-confirmation.js +29 -0
  382. package/dist/settings-http-confirmation.js.map +1 -1
  383. package/dist/settings-route-lifetime.d.ts +3 -1
  384. package/dist/settings-route-lifetime.js +15 -5
  385. package/dist/settings-route-lifetime.js.map +1 -1
  386. package/dist/settings-transaction.d.ts +3 -2
  387. package/dist/settings-transaction.js.map +1 -1
  388. package/dist/tips.js +1 -1
  389. package/dist/tips.js.map +1 -1
  390. package/dist/tool-permissions.js +3 -3
  391. package/dist/tool-permissions.js.map +1 -1
  392. package/dist/tool-receipt-output.d.ts +6 -6
  393. package/dist/turn-reply-guard.d.ts +16 -1
  394. package/dist/turn-reply-guard.js +20 -2
  395. package/dist/turn-reply-guard.js.map +1 -1
  396. package/dist/ui/app.html +2 -2
  397. package/dist/ui/contact-auth-strings.js +13 -8
  398. package/dist/ui/contact-authorizations.js +19 -1
  399. package/dist/ui/contact-grant-editor.js +71 -11
  400. package/dist/ui/contact-needs.js +27 -8
  401. package/dist/ui/contact-permissions.js +34 -9
  402. package/dist/ui/contact-tool-groups.js +1 -1
  403. package/dist/ui/fleet-office-pack.d.ts +2 -2
  404. package/dist/ui/fleet-office-pack.js +25 -8
  405. package/dist/ui/fleet-office-vehicles.js +28 -11
  406. package/dist/ui/fleet-office-zones.js +2 -2
  407. package/dist/ui/fleet-office.js +25 -5
  408. package/dist/ui/hub-admin-rooms-strings.js +6 -2
  409. package/dist/ui/hub-admin-rooms.js +3 -1
  410. package/dist/ui/hub-client.js +3 -0
  411. package/dist/ui/hub-group-search.js +2 -2
  412. package/dist/ui/hub-notify-keep.js +49 -0
  413. package/dist/ui/hub-role-view.js +1 -1
  414. package/dist/ui/hub-roles-strings.js +14 -10
  415. package/dist/ui/hub-roles.js +1 -1
  416. package/dist/ui/hub-room-members.js +4 -2
  417. package/dist/ui/hub-room-notify.js +2 -1
  418. package/dist/ui/hub-room-settings-strings.js +8 -0
  419. package/dist/ui/hub-room-settings.js +32 -0
  420. package/dist/ui/hub-room-strings.js +3 -3
  421. package/dist/ui/hub-room-thread.js +16 -5
  422. package/dist/ui/icons/hub-apple-touch-icon.png +0 -0
  423. package/dist/ui/icons/hub-favicon.ico +0 -0
  424. package/dist/ui/icons/hub-favicon.svg +10 -0
  425. package/dist/ui/icons/hub-icon-192.png +0 -0
  426. package/dist/ui/icons/hub-icon-512.png +0 -0
  427. package/dist/ui/icons/hub-icon-maskable-192.png +0 -0
  428. package/dist/ui/icons/hub-icon-maskable-512.png +0 -0
  429. package/dist/ui/icons/hub-maskable.svg +12 -0
  430. package/dist/ui/panel-hub.js +17 -5
  431. package/dist/ui/panel-needs.js +15 -6
  432. package/dist/ui/panel-settings.js +2 -1
  433. package/dist/ui/request-contact-card.js +287 -0
  434. package/dist/ui/request-contact-client.js +83 -0
  435. package/dist/ui/request-contact-page.js +78 -0
  436. package/dist/ui/request-context-control.js +171 -0
  437. package/dist/ui/settings-registry.js +2 -0
  438. package/dist/ui/settings-update.js +15 -1
  439. package/dist/ui/shared/app-install.js +123 -0
  440. package/dist/ui/shared/app-shell.js +17 -5
  441. package/dist/ui/shared/app-stream.js +1 -0
  442. package/dist/ui/shared/app-update.js +17 -2
  443. package/dist/ui/shared/app.css +136 -8
  444. package/dist/ui/shared/app.js +19 -2
  445. package/dist/ui/shared/hub-chat.css +6 -0
  446. package/dist/ui/shared/ui-confirm.js +4 -3
  447. package/dist/ui/shared/ui-icons.js +2 -0
  448. package/dist/ui/shared/ui-states.js +6 -0
  449. package/dist/ui/shared/update-card-ui.js +586 -0
  450. package/dist/ui/shared/view-strings.js +18 -0
  451. package/dist/ui/shared/web-authorize.js +1 -1
  452. package/dist/update-abandon.d.ts +26 -0
  453. package/dist/update-abandon.js +111 -0
  454. package/dist/update-abandon.js.map +1 -0
  455. package/dist/update-card.d.ts +1 -1
  456. package/dist/update-card.js +7 -7
  457. package/dist/update-card.js.map +1 -1
  458. package/dist/update-fix.d.ts +66 -0
  459. package/dist/update-fix.js +67 -0
  460. package/dist/update-fix.js.map +1 -0
  461. package/dist/update-forward.d.ts +5 -19
  462. package/dist/update-forward.js +19 -75
  463. package/dist/update-forward.js.map +1 -1
  464. package/dist/update-goback.d.ts +90 -0
  465. package/dist/update-goback.js +270 -0
  466. package/dist/update-goback.js.map +1 -0
  467. package/dist/update-journal.d.ts +8 -0
  468. package/dist/update-journal.js +8 -2
  469. package/dist/update-journal.js.map +1 -1
  470. package/dist/update-package-restore.d.ts +11 -2
  471. package/dist/update-package-restore.js +16 -5
  472. package/dist/update-package-restore.js.map +1 -1
  473. package/dist/update-quiescence.d.ts +38 -9
  474. package/dist/update-quiescence.js +50 -10
  475. package/dist/update-quiescence.js.map +1 -1
  476. package/dist/update-readiness.d.ts +2 -0
  477. package/dist/update-readiness.js +5 -1
  478. package/dist/update-readiness.js.map +1 -1
  479. package/dist/update-recovery/recover.js +10 -0
  480. package/dist/update-recovery/recover.js.map +1 -1
  481. package/dist/update-recovery/runner.d.ts +4 -0
  482. package/dist/update-recovery/runner.js +38 -5
  483. package/dist/update-recovery/runner.js.map +1 -1
  484. package/dist/update-restore.d.ts +7 -1
  485. package/dist/update-restore.js +10 -5
  486. package/dist/update-restore.js.map +1 -1
  487. package/dist/update-retained.d.ts +28 -1
  488. package/dist/update-retained.js +28 -3
  489. package/dist/update-retained.js.map +1 -1
  490. package/dist/update-settings.d.ts +27 -0
  491. package/dist/update-settings.js +40 -0
  492. package/dist/update-settings.js.map +1 -1
  493. package/dist/update-snapshot-scope.js +2 -0
  494. package/dist/update-snapshot-scope.js.map +1 -1
  495. package/dist/usage/i18n-keys.d.ts +1 -1
  496. package/dist/usage/i18n-keys.js +9 -0
  497. package/dist/usage/i18n-keys.js.map +1 -1
  498. package/dist/usage/providers.d.ts +3 -11
  499. package/dist/usage/providers.js +93 -131
  500. package/dist/usage/providers.js.map +1 -1
  501. package/dist/web-api.d.ts +4 -0
  502. package/dist/web-api.js +50 -7
  503. package/dist/web-api.js.map +1 -1
  504. package/dist/web-chat-history.d.ts +2 -0
  505. package/dist/web-chat-history.js.map +1 -1
  506. package/dist/web-icons.d.ts +20 -3
  507. package/dist/web-icons.js +76 -7
  508. package/dist/web-icons.js.map +1 -1
  509. package/dist/web-mentions.d.ts +27 -8
  510. package/dist/web-mentions.js +108 -1
  511. package/dist/web-mentions.js.map +1 -1
  512. package/dist/web-office-acts.js +3 -0
  513. package/dist/web-office-acts.js.map +1 -1
  514. package/dist/web-update.d.ts +9 -0
  515. package/dist/windows-agents.d.ts +24 -2
  516. package/dist/windows-agents.js +110 -4
  517. package/dist/windows-agents.js.map +1 -1
  518. package/dist/windows-cli-worker.js +9 -1
  519. package/dist/windows-cli-worker.js.map +1 -1
  520. package/dist/windows-cli.d.ts +15 -0
  521. package/dist/windows-cli.js +54 -6
  522. package/dist/windows-cli.js.map +1 -1
  523. package/package.json +2 -2
package/dist/daemon.js CHANGED
@@ -1,5 +1,9 @@
1
+ import { RequestContextHelperAdmission } from "./request-context-helper.js";
2
+ import { requestContextDigest } from "./request-context-store.js";
3
+ import { RequestContextPendingWork } from "./request-context-pending-work.js";
4
+ import { requestContextProcessGroupGone } from "./request-context-retirement.js";
1
5
  import { ReplyDraft } from "./reply-draft.js";
2
- import { requireRequestContextPolicy } from "./request-context-policy.js";
6
+ import { requireRequestContextPolicy, requestContextInstructionMode } from "./request-context-policy.js";
3
7
  import { RequestContextReferenceMap } from "./request-context-fence.js";
4
8
  import { managedClaudeBinding } from "./claude-credential-launch.js";
5
9
  import { HUB_REPORT_TARGET } from "./hub-report-target.js";
@@ -74,7 +78,7 @@ import { PaneWriteLock } from "./pane-write-lock.js";
74
78
  import { answerRemoteCard } from "./remote-card-answer.js";
75
79
  import { tmuxPaneHost } from "./tmux-pane-host.js";
76
80
  import { buildFleetInstructions, INBOUND_HEADER_RULE } from "./instructions.js";
77
- import { formatHumanInboundMessage, prepareDeliveryWire, steerInboundEnvelope, BTW_INBOUND_PREFIX, humanBodyHash, humanOwnerObjectId } from "./human-delivery-receipts.js";
81
+ import { formatHumanInboundMessage, prepareDeliveryWire, steerInboundEnvelope, btwInboundEnvelope, humanBodyHash, humanOwnerObjectId } from "./human-delivery-receipts.js";
78
82
  import { formatCrossInstanceInboundMessage, renderCrossInstanceHandoffMetadata, } from "./cross-instance-envelope.js";
79
83
  import { agendMessageInInput, bottomRowIsReady, inputAreaText, inputShowsPastedText, pastedTextSignature, pasteLeftInInput, strandedAgendMessageInInput } from "./pane-input-residue.js";
80
84
  import { TurnReplyGuard, formatReplyDropDetection, turnExpectsPersonReply } from "./turn-reply-guard.js";
@@ -124,7 +128,7 @@ const WEB_THEME_IPC = Object.freeze({
124
128
  });
125
129
  /** The largest picture any slot may take (a card slot's ceiling; the fleet checks the limit in force): read no more. */
126
130
  const WEB_THEME_ASSET_MAX_BYTES = ASSET_UPLOAD_MAX_BYTES;
127
- const CROSS_INSTANCE_TOOLS = new Set(["hub_set_intro", "hub_room_status", "hub_room_list", "hub_room_post", "hub_room_members", "hub_people_search", "send_to_instance", "broadcast", "list_instances", "start_instance", "restart_instance", "create_instance", "delete_instance", "replace_instance", "request_information", "delegate_task", "report_result", "delivery_status", "describe_instance"]);
131
+ const CROSS_INSTANCE_TOOLS = new Set(["hub_set_intro", "hub_room_status", "hub_room_list", "hub_room_post", "hub_room_history", "hub_room_members", "hub_people_search", "send_to_instance", "broadcast", "list_instances", "start_instance", "restart_instance", "create_instance", "delete_instance", "replace_instance", "request_information", "delegate_task", "report_result", "delivery_status", "describe_instance"]);
128
132
  const SCHEDULE_TOOLS = new Set(["create_schedule", "list_schedules", "update_schedule", "delete_schedule"]);
129
133
  const DECISION_TOOLS = new Set(["post_decision", "list_decisions", "update_decision"]);
130
134
  const TASK_TOOL = "task";
@@ -1241,6 +1245,14 @@ export class Daemon extends EventEmitter {
1241
1245
  }
1242
1246
  guardian = null;
1243
1247
  adapter = null;
1248
+ requestContextAdmission;
1249
+ /** Input fencing may attach to a legacy owner; it does not bind C or reinterpret an existing turn. */
1250
+ setRequestContextAdmission(port) {
1251
+ if (this.requestContextAdmission && this.requestContextAdmission !== port)
1252
+ throw Error("Request-context admission owner differs");
1253
+ this.requestContextAdmission = port;
1254
+ }
1255
+ requestContextPendingWork = new RequestContextPendingWork();
1244
1256
  pendingIpcRequests = new Map();
1245
1257
  /**
1246
1258
  * Daemon-global request sequence. MCP request ids are only process-local:
@@ -2258,6 +2270,7 @@ export class Daemon extends EventEmitter {
2258
2270
  guardGeneration: turn?.generation ?? null, guardPhase: turn?.phase ?? null }, "Native pane tool operation failed");
2259
2271
  }
2260
2272
  nativePaneCurrent() { return this.nativePaneLifecycle?.current() ?? false; }
2273
+ nativePaneRequestContextTransportCurrent() { return this.nativePaneLifecycle?.requestContextTransportCurrent?.() === true; }
2261
2274
  nativeEnterHold = null;
2262
2275
  /** Per-launch attention for a native delivery whose bounded input attempts were refused or uncertain, including non-outbox input. */
2263
2276
  nativeDeliveryHold() {
@@ -2376,6 +2389,9 @@ export class Daemon extends EventEmitter {
2376
2389
  bindRequestContextPolicy(policy) { if (this.requestContextPolicy || !this.requestContextLifecycle)
2377
2390
  throw Error("request-context policy requires its owned turn binding"); this.requestContextPolicy = policy; }
2378
2391
  requestContextCalls = new RequestContextReferenceMap(call => call.admission.coverage === "covered" ? call.admission.lease.snapshot.context.ref.rootContextId : null, call => `local-call:${call.id}`);
2392
+ requestContextQueuedWork = new RequestContextReferenceMap(row => row.root, (_row, id) => `queued-recovery:${id}`);
2393
+ get requestContextQueuedWorkDrainRevision() { return this.requestContextQueuedWork.revision; }
2394
+ requestContextQueuedWorkDrainView(rootId) { return this.requestContextQueuedWork.view(rootId); }
2379
2395
  requestContextInterruptedLaunch;
2380
2396
  requestContextLaunch() { return JSON.stringify([this.bootId, this.spawnGeneration, this.nativePaneLifecycle?.snapshot?.()?.launchId ?? null]); }
2381
2397
  /** First local owned hop only. No lookup at a later Fleet receipt may retag this call. */
@@ -2391,11 +2407,28 @@ export class Daemon extends EventEmitter {
2391
2407
  ? { coverage: "covered", lease: captureRequestContextCall(snapshot, captured => this.requestContextTurnCurrent(captured)) }
2392
2408
  : { coverage: "not-covered", reason };
2393
2409
  const call = Object.freeze({ id: randomUUID(), admission: Object.freeze(admission),
2410
+ ...(admission.coverage === "covered" ? { replyRoute: this.captureRequestContextReplyRoute(admission.lease.snapshot) } : {}),
2394
2411
  current: () => !this.deliveryWritesStopping && this.requestContextLaunch() === launch
2395
2412
  && (admission.coverage !== "covered" || admission.lease.current()) });
2396
2413
  this.requestContextCalls.set(call.id, call);
2397
2414
  return call;
2398
2415
  }
2416
+ /** Bind the original call to a delivered target, with the original human admission rechecked at commit. */
2417
+ captureRequestContextReplyRoute(snapshot) {
2418
+ const route = this.turnReplyGuard?.captureReplyRoute(snapshot.token);
2419
+ if (!route)
2420
+ return;
2421
+ const current = () => {
2422
+ try {
2423
+ return route.current() && this.requestContextTurnCurrent(snapshot)
2424
+ && requestContextDigest(this.requestContextLifecycle?.replyTarget?.(snapshot)) === requestContextDigest(route.target);
2425
+ }
2426
+ catch {
2427
+ return false;
2428
+ }
2429
+ };
2430
+ return current() ? Object.freeze({ ...route, current }) : undefined;
2431
+ }
2399
2432
  /** Internal Fleet accessor, paired with the current daemon/IPC connection; returns original scope or nothing. */
2400
2433
  requestContextCall(callId) {
2401
2434
  const call = this.requestContextCalls.get(callId);
@@ -2418,17 +2451,175 @@ export class Daemon extends EventEmitter {
2418
2451
  this.ipcServer?.send(socket, { requestId: message.requestId, result: null, error: "Request context call admission is unavailable" });
2419
2452
  }
2420
2453
  }
2421
- setRequestContextLocalLifecycle(turns, identity) {
2454
+ /** New replacement only; an old launch never acquires C by reseeding its counters. */
2455
+ seedRequestContextReplacement(previous) {
2456
+ if (this.tmux || this.ipcServer || this.nativePaneLifecycle || this.requestContextLifecycle
2457
+ || ![previous.spawnGeneration, previous.launchFenceEpoch].every(n => Number.isSafeInteger(n) && n >= 0 && n < Number.MAX_SAFE_INTEGER)) {
2458
+ throw Error("Request-context replacement must be prepared before startup");
2459
+ }
2460
+ this.spawnGeneration = previous.spawnGeneration + 1;
2461
+ this.launchFenceEpoch = previous.launchFenceEpoch + 1;
2462
+ }
2463
+ /** Read-only first-On inventory. Idle alone is never a legacy-work drain proof. */
2464
+ requestContextLaunchObservation() {
2465
+ return Object.freeze({ daemonBootId: this.bootId, spawnGeneration: this.spawnGeneration,
2466
+ launchFenceEpoch: this.launchFenceEpoch, observation: this.getWorkingStateObservation(),
2467
+ pendingCalls: this.requestContextPendingWork.count(this.name), responseWaiters: this.pendingIpcRequests.size,
2468
+ paneWriteBusy: this.paneWriteLock.isBusy, queuedInputs: this.pasteQueueDepth,
2469
+ transcriptOpen: this.transcriptTurns.openSince() !== null,
2470
+ starting: this.spawning, stopping: this.deliveryWritesStopping || this.startupAborted,
2471
+ replacementRequired: !this.requestContextLifecycle || this.requestContextInterruptedLaunch === this.requestContextLaunch() });
2472
+ }
2473
+ requestContextHelper;
2474
+ requestContextStartupResources;
2475
+ /** Candidate-only physical resource receipt, installed before startup. Used even when startup rejects.
2476
+ * No stop result, timeout, removed metadata or empty supervisor map proves retirement.
2477
+ */
2478
+ prepareRequestContextStartupRetirement() {
2479
+ if (this.tmux || this.ipcServer || this.nativePaneLifecycle || this.requestContextStartupResources)
2480
+ throw Error("Request startup retirement must precede launch");
2481
+ const resources = { pending: 0, unknown: false, windows: [], ipc: new Set(), native: [] };
2482
+ this.requestContextStartupResources = resources;
2483
+ return Object.freeze({ retired: async () => {
2484
+ try {
2485
+ if (this.requestContextStartupResources !== resources || !this.startupAborted && !this.deliveryWritesStopping || this.spawning
2486
+ || resources.pending || resources.unknown || [...resources.ipc].some(ipc => !ipc.retired()))
2487
+ return false;
2488
+ for (const row of resources.native) {
2489
+ const snapshot = row.owner.snapshot?.();
2490
+ if (!snapshot || snapshot.state !== "exited" || JSON.stringify([snapshot.hostBootId, snapshot.paneId, snapshot.launchId, snapshot.agentId, snapshot.instance]) !== row.identity)
2491
+ return false;
2492
+ }
2493
+ for (const row of resources.windows) {
2494
+ const windows = await TmuxManager.listWindowsStrict(row.session);
2495
+ if (resources.pending || resources.unknown || windows.some(window => window.id === row.window) || !requestContextProcessGroupGone(row.pid))
2496
+ return false;
2497
+ }
2498
+ return this.requestContextStartupResources === resources && !resources.pending && !resources.unknown && [...resources.ipc].every(ipc => ipc.retired());
2499
+ }
2500
+ catch {
2501
+ return false;
2502
+ }
2503
+ } });
2504
+ }
2505
+ requestContextHelperReadiness() {
2506
+ if (!this.requestContextLifecycle)
2507
+ return null;
2508
+ if (this.nativePaneLifecycle) {
2509
+ const snapshot = this.nativePaneLifecycle.snapshot?.();
2510
+ if (!snapshot)
2511
+ return null;
2512
+ // Output/sequence changes are observations, not a new admitting launch. Bind the actual owner tuple.
2513
+ return { version: 1, generation: JSON.stringify([this.bootId, this.spawnGeneration, this.launchFenceEpoch, snapshot.hostBootId, snapshot.paneId, snapshot.launchId, snapshot.agentId]),
2514
+ ready: snapshot.state === "running" && this.nativePaneLifecycle.requestContextTransportCurrent?.() === true };
2515
+ }
2516
+ return this.requestContextHelper ? { version: 1, generation: `${this.bootId}:${this.requestContextHelper.revision}`, ready: this.requestContextHelper.ready() } : null;
2517
+ }
2518
+ getRequestContextLaunchSpec() {
2519
+ const kind = this.runtimeIdentity?.kind;
2520
+ if (kind !== "classic" && kind !== "fleet-topic")
2521
+ throw Error("Request launch kind unavailable");
2522
+ return Object.freeze({ config: this.getConfigSnapshot(), topicMode: this.topicMode, kind });
2523
+ }
2524
+ /** First-On uses a real bounded pane read, not the cached idle badge; admission must already be fenced. */
2525
+ async captureRequestContextIdle() {
2526
+ const admission = this.requestContextAdmission;
2527
+ if (!admission || admission.available())
2528
+ return null;
2529
+ // Capture before waiting for the write lock: a replaced/respawned owner cannot inherit this request.
2530
+ const tmux = this.tmux, ipc = this.ipcServer, owner = JSON.stringify(this.interactionOwner());
2531
+ const daemonBootId = this.bootId, spawnGeneration = this.spawnGeneration, launchFenceEpoch = this.launchFenceEpoch, deliveryEpoch = this.deliveryEpoch;
2532
+ const pendingRevision = this.requestContextPendingWork.revision, turn = this.turnReplyGuard.snapshot();
2533
+ return this.paneWriteLock.run(async () => {
2534
+ const stable = () => {
2535
+ const observed = this.requestContextLaunchObservation(), now = this.turnReplyGuard.snapshot();
2536
+ return this.requestContextAdmission === admission && !admission.available()
2537
+ && this.tmux === tmux && this.ipcServer === ipc && JSON.stringify(this.interactionOwner()) === owner
2538
+ && this.deliveryEpoch === deliveryEpoch && this.requestContextPendingWork.revision === pendingRevision
2539
+ && observed.pendingCalls === 0 && observed.responseWaiters === 0 && observed.queuedInputs === 0
2540
+ && !observed.transcriptOpen && !observed.starting && !observed.stopping && !this.runtimeMonitorsFrozen
2541
+ && observed.observation.processStatus === "running" && observed.observation.executionState === "idle"
2542
+ && (!this.backend?.backgroundWorkRunning || observed.observation.backgroundWork !== true)
2543
+ && now?.generation === turn?.generation
2544
+ && (!now || now.cancelledByUser || now.completionDelivered);
2545
+ };
2546
+ if (!tmux || !stable())
2547
+ return null;
2548
+ let pane;
2549
+ try {
2550
+ pane = await tmux.capturePane(2000);
2551
+ }
2552
+ catch {
2553
+ return null;
2554
+ }
2555
+ if (!stable() || !this.paneAuthoritativelyIdle(pane) || this.inputTransientInPane(pane)
2556
+ || this.backend?.backgroundWorkRunning && this.backend.backgroundWorkRunning(pane) !== false)
2557
+ return null;
2558
+ // The owning gate still checks its durable rows and producer revision. A late handler, queue, turn,
2559
+ // IPC replacement or owner change invalidates this proof even if it later looks idle again.
2560
+ return Object.freeze({ daemonBootId, spawnGeneration, launchFenceEpoch, deliveryEpoch,
2561
+ current: () => !this.paneWriteLock.isBusy && stable() });
2562
+ });
2563
+ }
2564
+ /** Capture the exact old resources BEFORE stop removes metadata; this proof never kills or signals anything. */
2565
+ async captureRequestContextRetirement() {
2566
+ const tmux = this.tmux, windowId = tmux?.getWindowId(), native = this.nativePaneLifecycle, ipc = this.ipcServer;
2567
+ const spawnGeneration = this.spawnGeneration, launchFenceEpoch = this.launchFenceEpoch, daemonBootId = this.bootId;
2568
+ if (!tmux || !windowId)
2569
+ throw Error("Owned launch unavailable for retirement");
2570
+ const owned = () => this.bootId === daemonBootId && this.spawnGeneration === spawnGeneration
2571
+ && this.tmux === tmux && tmux.getWindowId() === windowId && this.nativePaneLifecycle === native
2572
+ && (this.ipcServer === ipc || this.ipcServer === null && ipc?.retired() === true);
2573
+ const captured = native?.snapshot?.();
2574
+ const panePid = native ? null : await this.paneHost.getPanePid(this.tmuxSessionName, windowId);
2575
+ if (!owned() || !native && (!panePid || !Number.isSafeInteger(panePid) || panePid <= 1)
2576
+ || native && (!captured || captured.instance !== this.name || captured.paneId !== windowId))
2577
+ throw Error("Owned launch changed during retirement capture");
2578
+ return Object.freeze({ daemonBootId, spawnGeneration, launchFenceEpoch, windowId, panePid, retired: async () => {
2579
+ try {
2580
+ if (!owned() || ipc && !ipc.retired())
2581
+ return false;
2582
+ if (native) {
2583
+ const now = native.snapshot?.();
2584
+ return !!now && now.state === "exited" && ["hostBootId", "paneId", "launchId", "agentId", "instance"].every(k => now[k] === captured[k]) && owned();
2585
+ }
2586
+ const windows = await TmuxManager.listWindowsStrict(this.tmuxSessionName);
2587
+ return owned() && (!ipc || ipc.retired()) && !windows.some(w => w.id === windowId) && requestContextProcessGroupGone(panePid);
2588
+ }
2589
+ catch {
2590
+ return false;
2591
+ }
2592
+ } });
2593
+ }
2594
+ setRequestContextLocalLifecycle(turns, identity, newWork, replyTarget, continuation) {
2422
2595
  if (this.tmux || this.ipcServer || this.requestContextLifecycle || this.nativePaneLifecycle && !this.nativePaneLifecycle.requestContextAvailable?.())
2423
2596
  throw Error("Request context must be bound before a supported daemon startup");
2424
2597
  this.requestContextCalls.installRegistration(turns.registrationGate ?? undefined);
2425
- this.requestContextLifecycle = { turns, identity };
2598
+ this.requestContextQueuedWork.installRegistration(turns.registrationGate ?? undefined);
2599
+ this.requestContextHelper = new RequestContextHelperAdmission();
2600
+ this.requestContextLifecycle = { turns, identity, newWork, replyTarget, continuation };
2601
+ }
2602
+ /** Authoritative fresh-launch boundary only; session discovery and a merely written clear command do not prove it. */
2603
+ requestContextNewWork(reason) {
2604
+ const lifecycle = this.requestContextLifecycle;
2605
+ if (!lifecycle?.newWork)
2606
+ return;
2607
+ const owner = this.requestContextOwner(), previous = owner ? lifecycle.turns.current(owner) : null;
2608
+ lifecycle.newWork(reason);
2609
+ if (owner && previous)
2610
+ lifecycle.turns.ended(previous, owner);
2611
+ this.requestContextWrite = undefined;
2426
2612
  }
2427
2613
  requestContextOwner() {
2428
2614
  const lifecycle = this.requestContextLifecycle;
2429
2615
  return lifecycle ? { ...lifecycle.identity(), instance: this.name, daemonBootId: this.bootId,
2430
2616
  spawnGeneration: this.spawnGeneration, launchFenceEpoch: this.launchFenceEpoch, deliveryEpoch: this.deliveryEpoch } : null;
2431
2617
  }
2618
+ /** Trusted installer/resolver observation only; no turn token or authority is granted. */
2619
+ captureRequestContextOwner() {
2620
+ const owner = this.requestContextOwner();
2621
+ return owner ? Object.freeze(owner) : null;
2622
+ }
2432
2623
  requestContextTurnSnapshot() {
2433
2624
  const owner = this.requestContextOwner();
2434
2625
  return owner ? this.requestContextLifecycle.turns.current(owner) : null;
@@ -2464,6 +2655,7 @@ export class Daemon extends EventEmitter {
2464
2655
  const deliveryId = /^delivery:([^:]+):[0-9]+$/.exec(id)?.[1];
2465
2656
  const endAnchor = !!humanId && /^[A-Za-z0-9_-]+$/.test(humanId) && text.split("\n").some(line => line.startsWith(`[hid:${humanId}]`) || line.startsWith(`[agend-human-id:${humanId}]`))
2466
2657
  || !!deliveryId && text.startsWith(`[agend-delivery-id:${deliveryId}]\n`)
2658
+ || /^hub-input:[a-f0-9-]{36}$/.test(id) && /^\[agend-room-input:hub-room-[a-f0-9-]{36}\]\n/.test(text)
2467
2659
  || /^[A-Za-z0-9:_-]+$/.test(id) && text.startsWith(`[agend-request-input:${id}]\n`);
2468
2660
  this.requestContextWrite = { snapshot, text, at: Date.now(), ledger: new TranscriptTurnLedger(), endAnchor };
2469
2661
  }
@@ -2488,6 +2680,13 @@ export class Daemon extends EventEmitter {
2488
2680
  this.backend = native.backend;
2489
2681
  this.paneTransport = native.host;
2490
2682
  this.controlClient = native.observation;
2683
+ if (this.requestContextStartupResources) {
2684
+ const snapshot = native.snapshot?.();
2685
+ if (!snapshot)
2686
+ this.requestContextStartupResources.unknown = true;
2687
+ else
2688
+ this.requestContextStartupResources.native.push({ owner: native, identity: JSON.stringify([snapshot.hostBootId, snapshot.paneId, snapshot.launchId, snapshot.agentId, snapshot.instance]) });
2689
+ }
2491
2690
  }
2492
2691
  constructor(name, config, instanceDir, topicMode = false, backend, controlClient, rootLogger, runtimeIdentity, spawnGate, stormWindow,
2493
2692
  /** Fleet-level "is this CLI's backend down?" memory — see backend-outage.ts. */
@@ -2623,6 +2822,7 @@ export class Daemon extends EventEmitter {
2623
2822
  if (this.deliveryWritesStopping)
2624
2823
  return;
2625
2824
  this.deliveryWritesStopping = true;
2825
+ this.requestContextAdmission?.changed();
2626
2826
  this.deliveryEpoch++;
2627
2827
  this.replyDraft.reset();
2628
2828
  this.requestContextLifecycle?.turns.fence();
@@ -3422,6 +3622,14 @@ export class Daemon extends EventEmitter {
3422
3622
  // 1. IPC server — bridge between MCP server (Claude's child) and daemon
3423
3623
  const sockPath = join(this.instanceDir, "channel.sock");
3424
3624
  this.ipcServer = new IpcServer(sockPath, this.logger);
3625
+ this.requestContextStartupResources?.ipc.add(this.ipcServer);
3626
+ if (this.requestContextHelper)
3627
+ this.ipcServer.setMessageAdmission((message, socket) => {
3628
+ const admitted = this.requestContextHelper.admit(message, socket);
3629
+ if (!admitted)
3630
+ this.logger.warn({ instance: this.name }, "old_launch_helper_refused");
3631
+ return admitted;
3632
+ });
3425
3633
  // Forward IPC server errors as daemon events (prevents unhandled 'error' crash).
3426
3634
  // Guard: only forward post-listen errors — startup errors are handled by listen() rejection.
3427
3635
  let ipcListening = false;
@@ -3489,6 +3697,11 @@ export class Daemon extends EventEmitter {
3489
3697
  // bounded dialog/readiness scan as local startup. An already-running reattachment may be busy: do not
3490
3698
  // wait for that work to finish or inject a startup key into it.
3491
3699
  if (acquired.disposition === "reattached") {
3700
+ // A surviving process predates this daemon's first-hop binding. Its queued helper bytes
3701
+ // cannot prove a turn, even after a later input installs a new proof on that launch.
3702
+ // Keep the one-contact approval fallback until a genuinely new process is launched.
3703
+ if (this.requestContextLifecycle)
3704
+ this.requestContextInterruptedLaunch = this.requestContextLaunch();
3492
3705
  if (this.backend?.binaryName === "codex") {
3493
3706
  const native = this.nativePaneLifecycle, spawn = this.spawnGeneration, fence = this.launchFenceEpoch, attempt = this.launchAttempt;
3494
3707
  try {
@@ -3571,6 +3784,8 @@ export class Daemon extends EventEmitter {
3571
3784
  }
3572
3785
  if (nativeDisposition)
3573
3786
  this.isNewSession = nativeDisposition === "fresh";
3787
+ if (nativeDisposition === "fresh")
3788
+ this.requestContextNewWork("fresh");
3574
3789
  this.resetRoomConversation(nativeDisposition === "reattached");
3575
3790
  this.settleHubAnswerTurnAtLaunch(nativeDisposition === "reattached");
3576
3791
  // #1209: conditional continuation for the turn interrupted by the last
@@ -6098,6 +6313,7 @@ export class Daemon extends EventEmitter {
6098
6313
  this.logger.info("Stopping daemon instance");
6099
6314
  this.clearQuitRelaunchWatch();
6100
6315
  this.fenceDeliveryWritesForStop();
6316
+ this.requestContextHelper?.revoke();
6101
6317
  this.turnReplyGuard.reset();
6102
6318
  this.clearReplyGuardConfirm();
6103
6319
  this.sawBlockedInput = false;
@@ -6119,6 +6335,7 @@ export class Daemon extends EventEmitter {
6119
6335
  this.healthCheckPaused = true;
6120
6336
  this.saveSessionId();
6121
6337
  await this.nativePaneLifecycle.release(options.nativePane ?? "detach");
6338
+ await this.ipcServer?.close();
6122
6339
  try {
6123
6340
  unlinkSync(join(this.instanceDir, "daemon.pid"));
6124
6341
  }
@@ -6303,13 +6520,17 @@ export class Daemon extends EventEmitter {
6303
6520
  /** Local system work: no user turn, channel reply target, wake or replay of an original request. */
6304
6521
  async deliverWorkingRecovery(content, delivery, admitted) {
6305
6522
  const tmux = this.tmux, owner = JSON.stringify(this.interactionOwner()), epoch = this.deliveryEpoch;
6306
- const current = () => this.tmux === tmux && owner === JSON.stringify(this.interactionOwner())
6523
+ let begun = false;
6524
+ const current = () => (begun || !this.requestContextAdmission || this.requestContextAdmission.available()) && this.tmux === tmux && owner === JSON.stringify(this.interactionOwner())
6307
6525
  && this.deliveryEpoch === epoch && !this.deliveryWritesStopping && !this.runtimeMonitorsFrozen
6308
6526
  && !this.spawning && !this.startupAborted && !this.isPaused && !this.healthCheckPaused
6309
6527
  && this.processStatus === "running" && this.pasteQueueDepth === 0
6310
6528
  && (this.workingRecoveryInputOwner === owner || this.instanceState === "idle" && !this.recoveryNativeWork)
6311
6529
  && this.recoveryBootSettled && !this.recoveryCancelled && !this.isSessionOomStopped() && admitted();
6312
- let begun = false;
6530
+ const heldCurrent = () => this.tmux === tmux && owner === JSON.stringify(this.interactionOwner())
6531
+ && this.deliveryEpoch === epoch && !this.deliveryWritesStopping && !this.startupAborted && admitted();
6532
+ if (this.requestContextAdmission && !await this.requestContextAdmission.wait(heldCurrent))
6533
+ return;
6313
6534
  try {
6314
6535
  await this.paneWriteLock.run(async () => {
6315
6536
  if (!tmux || !current())
@@ -6523,7 +6744,11 @@ export class Daemon extends EventEmitter {
6523
6744
  this.deferDurableDelivery(meta, "native channel owner changed before pane submission");
6524
6745
  return;
6525
6746
  }
6526
- this.pushChannelMessage(msg.content, meta, targetSession, deliveryEpoch);
6747
+ const inputId = this.requestContextLifecycle && isHubQuestionMeta(meta) && typeof msg.request_context_input_id === "string" ? msg.request_context_input_id : undefined;
6748
+ if (inputId)
6749
+ this.pushChannelMessage(msg.content, meta, targetSession, deliveryEpoch, inputId);
6750
+ else
6751
+ this.pushChannelMessage(msg.content, meta, targetSession, deliveryEpoch);
6527
6752
  }).catch(err => {
6528
6753
  this.deferDurableDelivery(meta, `target wake failed before pane submission: ${err.message}`);
6529
6754
  this.logger.error({ err: err.message }, "Wake failed for inbound delivery");
@@ -7117,7 +7342,9 @@ export class Daemon extends EventEmitter {
7117
7342
  // chat platform has no chat_id (its reply goes to the web chat through the
7118
7343
  // fleet's web-only sink), but it is a person waiting for an answer all the
7119
7344
  // same: the guard arms for it (alpha.2).
7120
- if (!turnExpectsPersonReply(meta)) {
7345
+ const requestContext = this.requestContextTurnSnapshot();
7346
+ const ownedReplyTarget = requestContext ? this.requestContextLifecycle?.replyTarget?.(requestContext) : null;
7347
+ if (!turnExpectsPersonReply(meta) && !ownedReplyTarget) {
7121
7348
  this.logger.debug({
7122
7349
  source: meta.source || null,
7123
7350
  user: meta.user || null,
@@ -7137,13 +7364,13 @@ export class Daemon extends EventEmitter {
7137
7364
  threadId: meta.thread_id || undefined,
7138
7365
  messageId: meta.message_id || undefined,
7139
7366
  correlationId: meta.correlation_id || undefined,
7367
+ ...(ownedReplyTarget ?? {}),
7140
7368
  inboundMarker,
7141
7369
  deliveredText,
7142
7370
  deliveredAt,
7143
- }, this.pendingWork.lastInboundTimestamp());
7371
+ }, this.pendingWork.lastInboundTimestamp(), requestContext && ownedReplyTarget ? { binding: requestContext.token, target: ownedReplyTarget } : undefined);
7144
7372
  const armed = this.turnReplyGuard.snapshot();
7145
7373
  this.workingTurnDelivery = { generation: armed.generation, deliveryId: meta.delivery_id || null };
7146
- const requestContext = this.requestContextTurnSnapshot();
7147
7374
  this.workingTurnRequestContext = requestContext ? { generation: armed.generation, snapshot: requestContext } : null;
7148
7375
  this.publishWorkingState("turn_started");
7149
7376
  // #1209: persist the in-flight turn with a seam checkpoint. A marker
@@ -7879,6 +8106,19 @@ export class Daemon extends EventEmitter {
7879
8106
  const deliveryEpoch = this.deliveryEpoch;
7880
8107
  const parent = this.workingTurnRequestContext?.generation === turn.generation ? this.workingTurnRequestContext.snapshot : null;
7881
8108
  const recoveryInputId = `reply-recovery:${this.bootId}:${turn.generation}:${deliveryEpoch}`;
8109
+ const registered = parent && this.requestContextLifecycle ? { root: parent.context.ref.rootContextId } : null;
8110
+ if (registered) {
8111
+ if (this.requestContextQueuedWork.has(recoveryInputId))
8112
+ return;
8113
+ try {
8114
+ this.requestContextQueuedWork.set(recoveryInputId, registered);
8115
+ }
8116
+ catch {
8117
+ this.turnReplyGuard.complete(turn.generation);
8118
+ this.reportUnrecoveredReplyDrop(turn, "recovery_prompt_delivery_failed");
8119
+ return;
8120
+ }
8121
+ }
7882
8122
  this.pasteQueueDepth++;
7883
8123
  this.pasteLock = this.pasteLock.then(async () => {
7884
8124
  try {
@@ -7921,7 +8161,8 @@ export class Daemon extends EventEmitter {
7921
8161
  return;
7922
8162
  this.turnReplyGuard.complete(turn.generation);
7923
8163
  this.reportUnrecoveredReplyDrop(turn, "recovery_prompt_delivery_failed");
7924
- });
8164
+ }).finally(() => { if (registered && this.requestContextQueuedWork.get(recoveryInputId) === registered)
8165
+ this.requestContextQueuedWork.delete(recoveryInputId); });
7925
8166
  }
7926
8167
  /** Recheck after queue waits and IO; cancellation must not become a failure notice. */
7927
8168
  currentReplyRecovery(generation, deliveryEpoch) {
@@ -8011,6 +8252,10 @@ export class Daemon extends EventEmitter {
8011
8252
  }
8012
8253
  /** Context-bound reply path shared by dead-MCP and malformed-call recovery. */
8013
8254
  deliverDaemonReply(body, requestPrefix, logLabel, target) {
8255
+ // System proxy text has no originating call lease. Until its final-output generation proof is
8256
+ // installed, it cannot borrow a live turn or lastChat; proven-parent model recovery uses C instead.
8257
+ if (this.requestContextLifecycle)
8258
+ return Promise.resolve(false);
8014
8259
  const args = { text: body };
8015
8260
  const chatId = target?.chatId ?? this.lastChatId;
8016
8261
  const threadId = target?.threadId ?? this.lastThreadId;
@@ -8606,6 +8851,7 @@ export class Daemon extends EventEmitter {
8606
8851
  this.cancelCapacityNudge("the instance was stopped, paused or respawned");
8607
8852
  this.runtimeMonitorsFrozen = true;
8608
8853
  this.launchFenceEpoch++;
8854
+ this.requestContextAdmission?.changed();
8609
8855
  this.interactionObservation.reset(this.interactionOwner());
8610
8856
  this.clearInteractionConfirmation();
8611
8857
  if (this.healthCheckTimer) {
@@ -8976,7 +9222,7 @@ export class Daemon extends EventEmitter {
8976
9222
  if (kind === "steer")
8977
9223
  wire = Daemon.steerEnvelope(wire);
8978
9224
  else if (kind === "btw")
8979
- wire = BTW_INBOUND_PREFIX + wire;
9225
+ wire = btwInboundEnvelope(wire, meta.delivery_id);
8980
9226
  return prepareDeliveryWire(wire, kind === "raw_paste");
8981
9227
  }
8982
9228
  humanReceiptAttempt(meta, wire) {
@@ -9208,28 +9454,63 @@ export class Daemon extends EventEmitter {
9208
9454
  this.updateLastChat(meta.chat_id, meta.thread_id, meta.adapter_id);
9209
9455
  this.pendingWork.recordInbound();
9210
9456
  this.recordRecentUserMessage(content, meta);
9211
- const formatted = BTW_INBOUND_PREFIX + this.formatInboundMessage(content, meta);
9457
+ const formatted = btwInboundEnvelope(this.formatInboundMessage(content, meta), meta.delivery_id);
9212
9458
  const status = channelStatus(meta);
9459
+ const durableAttempt = this.durableDeliveryAttempt(meta, content);
9460
+ if (durableAttempt === false) {
9461
+ this.deferDurableDelivery(meta, "invalid durable delivery attempt metadata");
9462
+ return;
9463
+ }
9213
9464
  this.steerLock = this.steerLock.then(async () => {
9214
9465
  if (!this.isDeliveryEpochCurrent(deliveryEpoch)) {
9215
- this.finishHumanReceipt(meta, { reached: false });
9466
+ this.deferDurableDelivery(meta, "delivery epoch changed before steer began");
9216
9467
  this.noteCancelledHuman(meta);
9217
9468
  return;
9218
9469
  }
9219
9470
  await this.wake();
9220
9471
  if (!this.isDeliveryEpochCurrent(deliveryEpoch)) {
9221
- this.finishHumanReceipt(meta, { reached: false });
9472
+ this.deferDurableDelivery(meta, "delivery epoch changed while waking for steer");
9222
9473
  this.noteCancelledHuman(meta);
9223
9474
  return;
9224
9475
  }
9225
9476
  const verdict = { reached: false, humanReceipt: this.humanReceiptAttempt(meta, formatted) };
9226
9477
  let delivered = false;
9227
9478
  try {
9228
- if (await this.deliverMessage(formatted, status, { steer: true, deliveryEpoch, submissionId: meta.message_id,
9229
- ...(meta.verification_id ? { humanVerificationId: meta.verification_id, humanMeta: meta } : {}), verdict })) {
9479
+ if (await this.deliverMessage(formatted, status, {
9480
+ steer: true,
9481
+ deliveryEpoch,
9482
+ submissionId: meta.message_id,
9483
+ ...(meta.verification_id ? { humanVerificationId: meta.verification_id, humanMeta: meta } : {}),
9484
+ verdict,
9485
+ durableAttempt: durableAttempt || undefined,
9486
+ })) {
9230
9487
  delivered = true;
9488
+ this.finishDurableSubmission(durableAttempt, verdict);
9231
9489
  this.markTurnStarted(meta, formatted, deliveryEpoch);
9232
9490
  }
9491
+ else if (durableAttempt && verdict.paneWriteStarted) {
9492
+ this.finishDurableDelivery(durableAttempt, "uncertain", `${verdict.phase ?? "post-submit"}:${verdict.proof ?? "unproven"}`, verdict);
9493
+ }
9494
+ else if (durableAttempt && verdict.durableBeginCommitted) {
9495
+ this.abortDurableDelivery(durableAttempt, `${verdict.phase ?? "delivery"}:${verdict.proof ?? "no-pane-write"}`);
9496
+ }
9497
+ else if (durableAttempt) {
9498
+ this.retryDurableDeliveryBeforeBegin(durableAttempt, `${verdict.phase ?? "delivery"}:${verdict.proof ?? "deferred"}`);
9499
+ }
9500
+ else if (verdict.reached && this.isDeliveryEpochCurrent(deliveryEpoch)) {
9501
+ // Legacy non-outbox path retains its existing failure surface.
9502
+ this.reportCrossInstanceDeliveryFailure(meta, verdict);
9503
+ }
9504
+ }
9505
+ catch (err) {
9506
+ // The verdict goes along: a write that started and then threw is still a hand-off the CLI may consume (#1201).
9507
+ if (durableAttempt && verdict.paneWriteStarted)
9508
+ this.finishDurableDelivery(durableAttempt, "uncertain", err.message, verdict);
9509
+ else if (durableAttempt && verdict.durableBeginCommitted)
9510
+ this.abortDurableDelivery(durableAttempt, err.message);
9511
+ else if (durableAttempt)
9512
+ this.retryDurableDeliveryBeforeBegin(durableAttempt, err.message);
9513
+ throw err;
9233
9514
  }
9234
9515
  finally {
9235
9516
  this.finishHumanReceipt(meta, verdict);
@@ -9237,8 +9518,11 @@ export class Daemon extends EventEmitter {
9237
9518
  this.noteCancelledHuman(meta);
9238
9519
  }
9239
9520
  }).catch(err => {
9240
- this.finishHumanReceipt(meta, { reached: false });
9521
+ this.deferDurableDelivery(meta, `target wake/side-question failed before pane submission: ${err.message}`);
9241
9522
  this.logger.warn({ err: err.message }, "btw delivery error");
9523
+ if (!durableAttempt && this.isDeliveryEpochCurrent(deliveryEpoch)) {
9524
+ this.reportCrossInstanceDeliveryFailure(meta, undefined, err.message);
9525
+ }
9242
9526
  });
9243
9527
  }
9244
9528
  /**
@@ -9246,7 +9530,9 @@ export class Daemon extends EventEmitter {
9246
9530
  * If targetSession is provided, only send to the matching socket.
9247
9531
  * Otherwise send to the instance's own session (this.name).
9248
9532
  */
9249
- pushChannelMessage(content, meta, _targetSession, deliveryEpoch = this.deliveryEpoch) {
9533
+ pushChannelMessage(content, meta, _targetSession, deliveryEpoch = this.deliveryEpoch, requestContextInputId) {
9534
+ if (requestContextInputId && !/^hub-input:[a-f0-9-]{36}$/.test(requestContextInputId))
9535
+ throw Error("Hub request input id is unavailable");
9250
9536
  if (!this.isDeliveryEpochCurrent(deliveryEpoch)) {
9251
9537
  this.logger.info("Pending channel delivery dropped by user cancel");
9252
9538
  this.deferDurableDelivery(meta, "delivery epoch changed before queue admission");
@@ -9336,7 +9622,8 @@ export class Daemon extends EventEmitter {
9336
9622
  ? this.currentWhatsNew(this.pendingWhatsNew) : null;
9337
9623
  const body = whatsNew ? withWhatsNew(formatted, whatsNew.notice) : formatted;
9338
9624
  const roomMarker = roomContextInputMarker(meta);
9339
- const pasted = roomMarker ? `${roomMarker}\n${body}` : body;
9625
+ const unmarked = roomMarker ? `${roomMarker}\n${body}` : body;
9626
+ const pasted = requestContextInputId && !roomMarker ? `[agend-request-input:${requestContextInputId}]\n${unmarked}` : unmarked;
9340
9627
  const status = channelStatus(meta);
9341
9628
  // A fresh delivery begins a fresh turn — its bubble must not inherit
9342
9629
  // the previous turn's tool list.
@@ -9369,6 +9656,7 @@ export class Daemon extends EventEmitter {
9369
9656
  sent = await this.deliverMessage(pasted, status, {
9370
9657
  deliveryEpoch,
9371
9658
  submissionId: meta.message_id,
9659
+ ...(requestContextInputId ? { requestContextInputId } : {}),
9372
9660
  ...(isHubQuestionMeta(meta) ? { hubQuestion: meta.correlation_id, hubContactLimit: meta.hub_contact_limit !== "off" } : {}),
9373
9661
  ...(meta.hub_room_context_generation ? { roomContextGeneration: meta.hub_room_context_generation } : {}),
9374
9662
  ...(meta.verification_id ? { humanVerificationId: meta.verification_id, humanMeta: meta } : {}),
@@ -9468,6 +9756,21 @@ export class Daemon extends EventEmitter {
9468
9756
  || (!!opts?.roomContextGeneration && opts.roomContextGeneration !== this.roomConversationGeneration());
9469
9757
  if (cancelled() || this.stormWindow?.isStopped())
9470
9758
  return false;
9759
+ const admittedReceiptId = opts?.humanMeta?.verification_id ?? opts?.humanVerificationId;
9760
+ const admittedInputId = opts?.requestContextInputId ?? (admittedReceiptId ? `human:${admittedReceiptId}` : opts?.durableAttempt ? `delivery:${opts.durableAttempt.deliveryId}:${opts.durableAttempt.attemptNo}` : null);
9761
+ // Captured once for this input, before waiting. An ended steer never turns into a fresh owner root.
9762
+ const continuation = this.requestContextLifecycle?.continuation?.(admittedInputId, opts?.requestContextRecovery);
9763
+ let heldOwner;
9764
+ const admissionCurrent = () => !cancelled() && !this.deliveryWritesStopping && !this.startupAborted
9765
+ && (heldOwner === undefined || heldOwner === JSON.stringify(this.interactionOwner()));
9766
+ const waitAdmission = async () => {
9767
+ const port = this.requestContextAdmission;
9768
+ if (!port.available(continuation))
9769
+ heldOwner ??= JSON.stringify(this.interactionOwner());
9770
+ return await port.wait(admissionCurrent, continuation) && admissionCurrent();
9771
+ };
9772
+ if (this.requestContextAdmission && !await waitAdmission())
9773
+ return false;
9471
9774
  formatted = prepareDeliveryWire(formatted, opts?.preserveExactBytes);
9472
9775
  // Direct paths such as /steer, /btw, /raw and schedules do not pass the
9473
9776
  // FleetManager idle gate. Hold them at the final common pane-write path so
@@ -9632,6 +9935,8 @@ export class Daemon extends EventEmitter {
9632
9935
  const outcome = await this.paneWriteLock.run(async () => {
9633
9936
  if (cancelled())
9634
9937
  return false;
9938
+ if (this.requestContextAdmission && !this.requestContextAdmission.available(continuation) && !verdict.paneWriteStarted && !verdict.durableBeginCommitted)
9939
+ return "request-context-held";
9635
9940
  // A spawn that started after the settle wait above invalidates the
9636
9941
  // window id and every readiness verdict since: the pane about to be
9637
9942
  // written may already belong to a replacement process. The same holds
@@ -9675,13 +9980,15 @@ export class Daemon extends EventEmitter {
9675
9980
  // same process, a pause/stop/respawn is not (launchFenceEpoch moves even
9676
9981
  // when a failed pause resumes the monitors).
9677
9982
  const writeCurrent = () => !cancelled()
9983
+ && (!this.requestContextAdmission || admissionCurrent() && (this.requestContextAdmission.available(continuation) || !!verdict.paneWriteStarted || !!verdict.durableBeginCommitted))
9678
9984
  && !this.staleAuthIssue()
9679
9985
  && !this.deliveryWritesStopping
9680
9986
  && !this.runtimeMonitorsFrozen
9681
9987
  && !this.spawning
9682
9988
  && settleGeneration === this.spawnGeneration
9683
9989
  && settleFence === this.launchFenceEpoch;
9684
- const stale = () => (this.spawning || settleGeneration !== this.spawnGeneration ? "spawn-started" : false);
9990
+ const stale = () => this.requestContextAdmission && !this.requestContextAdmission.available(continuation) && !verdict.paneWriteStarted && !verdict.durableBeginCommitted
9991
+ ? "request-context-held" : this.spawning || settleGeneration !== this.spawnGeneration ? "spawn-started" : false;
9685
9992
  const residue = await this.clearRestoredInputDraft(handingOffToNativeQueue, writeCurrent);
9686
9993
  if (residue === "stale")
9687
9994
  return stale();
@@ -9717,9 +10024,18 @@ export class Daemon extends EventEmitter {
9717
10024
  // M-2267: the pane is in a tmux mode: nothing written — wait for readiness (it holds while the mode lasts), retry.
9718
10025
  if (written === "pane-in-mode")
9719
10026
  return "dialog";
10027
+ // A publication fence before input keeps this attempt at its producer; never turn the wait into failure.
10028
+ if (written === false && this.requestContextAdmission && !this.requestContextAdmission.available(continuation) && !verdict.paneWriteStarted && !verdict.durableBeginCommitted)
10029
+ return "request-context-held";
9720
10030
  // Fenced before its first write: not attempted — redo after a spawn, else drop without a ❌.
9721
10031
  return written === false && verdict.fenced ? stale() : written;
9722
10032
  });
10033
+ if (outcome === "request-context-held") {
10034
+ if (!this.requestContextAdmission || !await waitAdmission())
10035
+ return false;
10036
+ round--;
10037
+ continue; // Waiting on admission consumes neither a dialog retry nor any input intent.
10038
+ }
9723
10039
  if (outcome === "spawn-started") {
9724
10040
  // The pane changed under this delivery: its queued paste must not land
9725
10041
  // in the replacement process's first screen. Redo the whole delivery
@@ -11903,10 +12219,24 @@ export class Daemon extends EventEmitter {
11903
12219
  verdict.roomInputQueued = handingOffToNativeQueue || steer;
11904
12220
  const humanMode = rawPaste ? "raw_paste" : steer ? "steer"
11905
12221
  : handingOffToNativeQueue ? "native_queue_handoff" : "idle_submit";
11906
- if (humanAttempt && signature.unique && signature.value === humanReceiptMarker(humanAttempt.verificationId, humanDialect).slice(1, -1)
12222
+ // Retained controls lead with the delivery marker for strict transcript/restart proof. That marker is
12223
+ // usable for a human receipt only through the outbox's exact control/receipt/owner/wire join, never text lookup.
12224
+ const controlMarker = durableAttempt ? `[agend-delivery-id:${durableAttempt.deliveryId}]` : null;
12225
+ const ownsControlReceipt = () => !!humanAttempt && !!durableAttempt && !rawPaste
12226
+ && this.deliveryOutbox?.ownsHumanControlReceipt?.(durableAttempt.deliveryId, this.bootId, durableAttempt.attemptNo, humanAttempt.receiptId, humanAttempt.ownerKey, humanAttempt.expectedWireHash) === true;
12227
+ const controlAlias = !!controlMarker && !!humanAttempt
12228
+ && [`${controlMarker}\n${humanAttempt.marker}\n`,
12229
+ Daemon.steerEnvelope(`${controlMarker}\n${humanAttempt.marker}\n`),
12230
+ btwInboundEnvelope(`${controlMarker}\n${humanAttempt.marker}\n`, durableAttempt.deliveryId)].some(prefix => formatted.startsWith(prefix))
12231
+ && ownsControlReceipt();
12232
+ if (controlAlias) {
12233
+ signature.value = controlMarker.slice(1, -1);
12234
+ signature.takenMarker = controlMarker;
12235
+ }
12236
+ if (humanAttempt && signature.unique && (controlAlias || signature.value === humanReceiptMarker(humanAttempt.verificationId, humanDialect).slice(1, -1))
11907
12237
  && humanBodyHash(formatted) === humanAttempt.expectedWireHash) {
11908
12238
  signature.humanPositive = tag => {
11909
- if (!humanAttempt.current() || (stillCurrent && !stillCurrent()))
12239
+ if (!humanAttempt.current() || (stillCurrent && !stillCurrent()) || controlAlias && !ownsControlReceipt())
11910
12240
  return;
11911
12241
  humanAttempt.proof = {
11912
12242
  receipt_id: humanAttempt.receiptId, verification_id: humanAttempt.verificationId,
@@ -12179,7 +12509,7 @@ export class Daemon extends EventEmitter {
12179
12509
  if (!this.steerPasteIsOurs(before.pane, formatted))
12180
12510
  return this.failDelivery(verdict, status, "steer-paste", "box-not-this-paste");
12181
12511
  const shown = this.backend?.readSteerComposerText?.(before.pane)?.replace(/\s+/g, " ").trim();
12182
- humanComposerOwned = !!humanAttempt && shown === (humanAttempt.marker ?? "[agend-human-id:" + humanAttempt.verificationId + "]");
12512
+ humanComposerOwned = !!humanAttempt && shown === (controlAlias ? controlMarker : humanAttempt.marker ?? "[agend-human-id:" + humanAttempt.verificationId + "]");
12183
12513
  // …and so is the Enter: the key is sent only while the reading is still within it.
12184
12514
  steerEnterDeadline = deadline;
12185
12515
  }
@@ -12951,6 +13281,7 @@ export class Daemon extends EventEmitter {
12951
13281
  // Grok cuts an echo to three rows, so the trailing message_id never shows after Enter; the marker always does.
12952
13282
  // Placed after the strand checks: text of ours still in the box (or its collapsed paste) outranks it.
12953
13283
  if (signature.takenMarker && after.inputReadable && this.backend?.readTakenMarkers?.(pane).includes(signature.takenMarker)) {
13284
+ signature.humanPositive?.("unique-id-pane");
12954
13285
  return this.submittedProof();
12955
13286
  }
12956
13287
  // 2. Positive evidence. A unique signature needs no baseline: no earlier
@@ -13391,7 +13722,7 @@ export class Daemon extends EventEmitter {
13391
13722
  const timer = setTimeout(() => finish({ result: null, error: "Pane tool result is unconfirmed; inspect its operation before retrying" }), daemonBudgetMs(input.tool) + 1000);
13392
13723
  timer.unref?.();
13393
13724
  try {
13394
- call = lease.requestContext ? Object.freeze({ id: randomUUID(), admission: lease.requestContext, current }) : undefined;
13725
+ call = lease.requestContext ? Object.freeze({ id: randomUUID(), admission: lease.requestContext, ...(lease.requestContext.coverage === "covered" ? { replyRoute: this.captureRequestContextReplyRoute(lease.requestContext.lease.snapshot) } : {}), current }) : undefined;
13395
13726
  if (call)
13396
13727
  this.requestContextCalls.set(call.id, call);
13397
13728
  this.handleToolCall({ ...input, requestId: ++this.fleetRequestSeq }, undefined, {
@@ -13427,6 +13758,17 @@ export class Daemon extends EventEmitter {
13427
13758
  this.emit("mcp_tool_response_written", { operationId, daemonBootId: this.bootId });
13428
13759
  }
13429
13760
  handleToolCall(msg, socket, peer, originatingCall) {
13761
+ const finish = this.requestContextPendingWork?.begin(this.name);
13762
+ try {
13763
+ Daemon.prototype.handleTrackedToolCall.call(this, msg, socket, peer, originatingCall, finish);
13764
+ }
13765
+ catch (error) {
13766
+ finish?.();
13767
+ throw error;
13768
+ }
13769
+ }
13770
+ handleTrackedToolCall(msg, socket, peer, originatingCall, finish) {
13771
+ const runLocal = (work) => this.requestContextPendingWork ? this.requestContextPendingWork.run(this.name, work) : work();
13430
13772
  const tool = msg.tool;
13431
13773
  const args = (msg.args ?? {});
13432
13774
  const requestId = msg.requestId;
@@ -13448,62 +13790,67 @@ export class Daemon extends EventEmitter {
13448
13790
  : null;
13449
13791
  // For now, log and respond. Full adapter routing will be wired in fleet manager.
13450
13792
  const respond = (result, error, errorCode) => {
13451
- if (originatingCall && !originatingCall.current()) {
13452
- result = null;
13453
- error = `Tool outcome is unconfirmed. ${operationId ? `Inspect operation ${operationId}` : "Inspect the tool operation status"}; do not repeat it.`;
13454
- }
13455
- if (originatingCall)
13456
- this.requestContextCalls.delete(originatingCall.id);
13457
- // A message that verifiably went out stands down the dead-MCP proxy reply
13458
- // for this turn: the agent proved it can still speak for itself.
13459
- if (!error && result != null && TURN_OUTBOUND_TOOLS.has(tool)) {
13460
- this.turnReplyGuard.settleToolAttempt(replyAttempt, true);
13461
- // #1209 P2: the user got an answer — the turn is over for resume
13462
- // purposes even before the idle edge completes the guard. Without
13463
- // this, a restart in the reply-to-idle window would re-inject a
13464
- // continuation for an already-answered turn.
13465
- if (replyAttempt?.completionAction) {
13466
- clearInFlightTurnMarker(this.instanceDir);
13467
- this.publishWorkingState("completion_delivered");
13793
+ try {
13794
+ if (originatingCall && !originatingCall.current()) {
13795
+ result = null;
13796
+ error = `Tool outcome is unconfirmed. ${operationId ? `Inspect operation ${operationId}` : "Inspect the tool operation status"}; do not repeat it.`;
13468
13797
  }
13469
- // #1377: a confirmed completion action (reply/react/edit_message) ends
13470
- // the human-facing obligation immediately — the idle edge does not need
13471
- // to confirm it. Clear any pending confirmation window so a later
13472
- // cross-instance busy→idle cycle cannot re-arm and fire false recovery.
13473
- // The guard itself completes on the next steady-idle tick via
13474
- // maybeConfirmReplyGuardIdle (which checks completionDelivered when
13475
- // replyGuardIdleConfirm is null) or at the next busy→idle edge.
13476
- // Cancelled turns are excluded: their completion semantics are handled
13477
- // by the idle edge's cancelledByUser check.
13478
- // An older reply that satisfied an earlier obligation but not the latest
13479
- // one (latestObligation > token.obligation) leaves completionDelivered
13480
- // false and must not clear the window either.
13481
- if (replyAttempt?.completionAction) {
13482
- const snap = this.turnReplyGuard.snapshot();
13483
- // generation 0 is a pre-arm token applied to the live generation (#2544).
13484
- if (snap && (snap.generation === replyAttempt.generation || replyAttempt.generation === 0)
13485
- && snap.phase === "awaiting"
13486
- && snap.completionDelivered && !snap.cancelledByUser) {
13487
- this.clearReplyGuardConfirm();
13798
+ if (originatingCall)
13799
+ this.requestContextCalls.delete(originatingCall.id);
13800
+ // A message that verifiably went out stands down the dead-MCP proxy reply
13801
+ // for this turn: the agent proved it can still speak for itself.
13802
+ if (!error && result != null && TURN_OUTBOUND_TOOLS.has(tool)) {
13803
+ this.turnReplyGuard.settleToolAttempt(replyAttempt, true);
13804
+ // #1209 P2: the user got an answer — the turn is over for resume
13805
+ // purposes even before the idle edge completes the guard. Without
13806
+ // this, a restart in the reply-to-idle window would re-inject a
13807
+ // continuation for an already-answered turn.
13808
+ if (replyAttempt?.completionAction) {
13809
+ clearInFlightTurnMarker(this.instanceDir);
13810
+ this.publishWorkingState("completion_delivered");
13811
+ }
13812
+ // #1377: a confirmed completion action (reply/react/edit_message) ends
13813
+ // the human-facing obligation immediately — the idle edge does not need
13814
+ // to confirm it. Clear any pending confirmation window so a later
13815
+ // cross-instance busy→idle cycle cannot re-arm and fire false recovery.
13816
+ // The guard itself completes on the next steady-idle tick via
13817
+ // maybeConfirmReplyGuardIdle (which checks completionDelivered when
13818
+ // replyGuardIdleConfirm is null) or at the next busy→idle edge.
13819
+ // Cancelled turns are excluded: their completion semantics are handled
13820
+ // by the idle edge's cancelledByUser check.
13821
+ // An older reply that satisfied an earlier obligation but not the latest
13822
+ // one (latestObligation > token.obligation) leaves completionDelivered
13823
+ // false and must not clear the window either.
13824
+ if (replyAttempt?.completionAction) {
13825
+ const snap = this.turnReplyGuard.snapshot();
13826
+ // generation 0 is a pre-arm token applied to the live generation (#2544).
13827
+ if (snap && (snap.generation === replyAttempt.generation || replyAttempt.generation === 0)
13828
+ && snap.phase === "awaiting"
13829
+ && snap.completionDelivered && !snap.cancelledByUser) {
13830
+ this.clearReplyGuardConfirm();
13831
+ }
13488
13832
  }
13489
13833
  }
13834
+ else if ((error || result == null) && replyAttempt?.reply && TURN_OUTBOUND_TOOLS.has(tool)) {
13835
+ // #1377: the adapter returned a definitive error — record this so the
13836
+ // confirm window can distinguish "in-flight" (unknown) from "known
13837
+ // failed" and report unknown immediately rather than starting recovery.
13838
+ this.turnReplyGuard.settleToolAttempt(replyAttempt, false);
13839
+ }
13840
+ const packet = { requestId, result, error, operationId, ...(errorCode !== undefined ? { errorCode } : {}) };
13841
+ const sent = peer ? peer.current() && peer.send(packet) : socket ? this.ipcServer?.send(socket, packet) ?? false : false;
13842
+ if (!sent) {
13843
+ if (peer)
13844
+ this.logger.debug({ tool, requestId }, "Native MCP result awaits transport-written confirmation");
13845
+ else
13846
+ this.logger.warn({ tool, requestId }, "Tool result could not be returned — originating MCP socket is closed");
13847
+ }
13848
+ else if (operationId) {
13849
+ this.emit("mcp_tool_response_written", { operationId, daemonBootId: this.bootId });
13850
+ }
13490
13851
  }
13491
- else if ((error || result == null) && replyAttempt?.reply && TURN_OUTBOUND_TOOLS.has(tool)) {
13492
- // #1377: the adapter returned a definitive error — record this so the
13493
- // confirm window can distinguish "in-flight" (unknown) from "known
13494
- // failed" and report unknown immediately rather than starting recovery.
13495
- this.turnReplyGuard.settleToolAttempt(replyAttempt, false);
13496
- }
13497
- const packet = { requestId, result, error, operationId, ...(errorCode !== undefined ? { errorCode } : {}) };
13498
- const sent = peer ? peer.current() && peer.send(packet) : socket ? this.ipcServer?.send(socket, packet) ?? false : false;
13499
- if (!sent) {
13500
- if (peer)
13501
- this.logger.debug({ tool, requestId }, "Native MCP result awaits transport-written confirmation");
13502
- else
13503
- this.logger.warn({ tool, requestId }, "Tool result could not be returned — originating MCP socket is closed");
13504
- }
13505
- else if (operationId) {
13506
- this.emit("mcp_tool_response_written", { operationId, daemonBootId: this.bootId });
13852
+ finally {
13853
+ finish?.();
13507
13854
  }
13508
13855
  };
13509
13856
  const sendFleet = (message) => {
@@ -13520,7 +13867,7 @@ export class Daemon extends EventEmitter {
13520
13867
  };
13521
13868
  try {
13522
13869
  if (this.requestContextPolicy)
13523
- requireRequestContextPolicy(this, this.name, tool, args, originatingCall?.admission);
13870
+ requireRequestContextPolicy(this, this.name, tool, args, originatingCall?.admission, originatingCall?.replyRoute);
13524
13871
  }
13525
13872
  catch (error) {
13526
13873
  respond(null, error.message);
@@ -13540,11 +13887,11 @@ export class Daemon extends EventEmitter {
13540
13887
  return;
13541
13888
  // Repo checkout — handled locally in daemon (no fleet-manager)
13542
13889
  if (tool === "checkout_repo") {
13543
- this.handleCheckoutRepo(args, respond);
13890
+ void runLocal(() => this.handleCheckoutRepo(args, respond));
13544
13891
  return;
13545
13892
  }
13546
13893
  if (tool === "release_repo") {
13547
- this.handleReleaseRepo(args, respond);
13894
+ void runLocal(() => this.handleReleaseRepo(args, respond));
13548
13895
  return;
13549
13896
  }
13550
13897
  if (tool === "set_display_name" || tool === "set_description" || tool === "list_emojis" || tool === "set_persona_emoji" || tool === "preview_emojis"
@@ -13594,7 +13941,7 @@ export class Daemon extends EventEmitter {
13594
13941
  });
13595
13942
  sendFleet({ type: WEB_THEME_IPC[tool], payload, meta: { instance_name: this.name }, fleetRequestId: fleetReqId });
13596
13943
  });
13597
- void (async () => {
13944
+ void runLocal(async () => {
13598
13945
  if (tool === "preview_web_appearance") {
13599
13946
  // The fleet builds the SVGs (whole, or in parts); they are written here, in the working directory.
13600
13947
  const first = await ask({ ...(args.modes !== undefined ? { modes: args.modes } : {}) });
@@ -13656,7 +14003,7 @@ export class Daemon extends EventEmitter {
13656
14003
  return (r.result && typeof r.result === "object" ? r.result : {});
13657
14004
  });
13658
14005
  reply(failed ? null : answer, failed);
13659
- })().catch((err) => reply(null, `${tool} failed: ${err instanceof Error ? err.message : "error"}`));
14006
+ }).catch((err) => reply(null, `${tool} failed: ${err instanceof Error ? err.message : "error"}`));
13660
14007
  return;
13661
14008
  }
13662
14009
  if (tool === TASK_TOOL) {
@@ -13680,13 +14027,13 @@ export class Daemon extends EventEmitter {
13680
14027
  });
13681
14028
  // files named in `attach` are read HERE, on the agent's side (its working directory, no symlink, size-capped),
13682
14029
  // and staged on the fleet in parts; the write itself then carries their ids. The fleet never opens a workspace path.
13683
- void (async () => {
14030
+ void runLocal(async () => {
13684
14031
  const sent = await sendTaskWrite(args, { workspace: this.config.working_directory, configuredWorkspace: this.config.working_directory, stateDir: getAgendHome(), instance: this.name }, askTask);
13685
14032
  if (sent.staging)
13686
14033
  respond(null, sent.error);
13687
14034
  else
13688
14035
  respond(sent.answer.result, sent.answer.error);
13689
- })().catch((err) => respond(null, `task failed: ${err instanceof Error ? err.message : "error"}`));
14036
+ }).catch((err) => respond(null, `task failed: ${err instanceof Error ? err.message : "error"}`));
13690
14037
  return;
13691
14038
  }
13692
14039
  if (DECISION_TOOLS.has(tool)) {
@@ -13779,7 +14126,19 @@ export class Daemon extends EventEmitter {
13779
14126
  // Context-bound routing: reply/react/edit_message always use the daemon's last known context.
13780
14127
  // chat_id and thread_id are not exposed in the tool schema — daemon is solely responsible for routing.
13781
14128
  // Must run before IPC forwarding so topic-mode (fleet manager) also receives the correct chat_id.
13782
- if (["reply", "react", "edit_message"].includes(tool)) {
14129
+ const ownedReplyRoute = this.requestContextPolicy && ["reply", "react", "edit_message"].includes(tool) ? originatingCall?.replyRoute : undefined;
14130
+ if (ownedReplyRoute) {
14131
+ if (!ownedReplyRoute.current()) {
14132
+ respond(null, "Originating request context is no longer current");
14133
+ return;
14134
+ }
14135
+ args.chat_id = ownedReplyRoute.target.chatId;
14136
+ if (ownedReplyRoute.target.threadId)
14137
+ args.thread_id = ownedReplyRoute.target.threadId;
14138
+ else
14139
+ delete args.thread_id;
14140
+ }
14141
+ if (!ownedReplyRoute && ["reply", "react", "edit_message"].includes(tool)) {
13783
14142
  const adapters = this.messageBus.getAllAdapters();
13784
14143
  const isTopicMode = adapters.length === 0;
13785
14144
  if (!this.lastChatId && !isTopicMode) {
@@ -13830,15 +14189,16 @@ export class Daemon extends EventEmitter {
13830
14189
  // Preserve the exact adapter world that supplied the chat context. An
13831
14190
  // instance binding is only a fallback: persisted/runtime context can be
13832
14191
  // from a secondary world, and message ids are not portable across bots.
13833
- adapterId: this.lastAdapterId,
14192
+ adapterId: ownedReplyRoute ? ownedReplyRoute.target.adapterId : this.lastAdapterId,
13834
14193
  });
13835
14194
  return;
13836
14195
  }
13837
14196
  // Same rule as deliverDaemonReply: one adapter is unambiguous, several with
13838
14197
  // no bound world is a routing failure rather than a first-wins guess.
13839
- const adapter = this.lastAdapterId
13840
- ? this.messageBus.getAdapter(this.lastAdapterId) ?? (adapters.length === 1 ? adapters[0] : undefined)
13841
- : (adapters.length === 1 ? adapters[0] : undefined);
14198
+ const selectedAdapter = ownedReplyRoute ? ownedReplyRoute.target.adapterId : this.lastAdapterId;
14199
+ const adapter = selectedAdapter
14200
+ ? this.messageBus.getAdapter(selectedAdapter) ?? (!ownedReplyRoute && adapters.length === 1 ? adapters[0] : undefined)
14201
+ : (!ownedReplyRoute && adapters.length === 1 ? adapters[0] : undefined);
13842
14202
  if (!adapter) {
13843
14203
  respond(null, "No channel world bound to this chat context — awaiting an inbound message to establish it");
13844
14204
  return;
@@ -13861,7 +14221,8 @@ export class Daemon extends EventEmitter {
13861
14221
  delete routed.buttons;
13862
14222
  }
13863
14223
  }
13864
- if (!routeToolCall(adapter, tool, routed, this.lastThreadId, respond)) {
14224
+ if (!routeToolCall(adapter, tool, routed, ownedReplyRoute ? ownedReplyRoute.target.threadId : this.lastThreadId, respond, ownedReplyRoute ? { beforeSend: () => { if (!originatingCall?.current() || !ownedReplyRoute.current() || !selectedAdapter || this.messageBus.getAdapter(selectedAdapter) !== adapter)
14225
+ throw Error("Originating request context is no longer current"); } } : {})) {
13865
14226
  respond(null, `Unknown tool: ${tool}`);
13866
14227
  }
13867
14228
  }
@@ -13967,6 +14328,9 @@ export class Daemon extends EventEmitter {
13967
14328
  mcpEnv.AGEND_TOOL_SET = toolSet;
13968
14329
  if (this.classicRestriction)
13969
14330
  mcpEnv.AGEND_CLASSIC_ALLOWED_TOOLS = JSON.stringify(this.classicRestriction.allowedAgendTools);
14331
+ const helperLaunch = this.requestContextHelper?.environment();
14332
+ if (helperLaunch)
14333
+ mcpEnv.AGEND_LAUNCH_TOKEN = helperLaunch;
13970
14334
  // The dashboard features the person switched off: out of the tool menu from this start (the fleet refuses them
13971
14335
  // at once, whatever the menu still shows).
13972
14336
  const dashboardOff = dashboardFeaturesOff(dashboardAccessOf(this.config));
@@ -14003,6 +14367,8 @@ export class Daemon extends EventEmitter {
14003
14367
  }
14004
14368
  catch { /* fallback to empty */ }
14005
14369
  instructions = buildFleetInstructions({
14370
+ ...(requestContextInstructionMode(this.requestContextPolicy) !== null && this.requestContextLifecycle && (!this.nativePaneLifecycle || this.nativePaneLifecycle.requestContextAvailable?.() === true)
14371
+ ? { requestContextPolicyInstalled: true } : {}),
14006
14372
  instanceName: this.name,
14007
14373
  taskBoard: !dashboardOff.includes("task_board"),
14008
14374
  workingDirectory: this.config.working_directory,
@@ -14020,6 +14386,8 @@ export class Daemon extends EventEmitter {
14020
14386
  }
14021
14387
  else {
14022
14388
  instructions = buildFleetInstructions({
14389
+ ...(requestContextInstructionMode(this.requestContextPolicy) !== null && this.requestContextLifecycle && (!this.nativePaneLifecycle || this.nativePaneLifecycle.requestContextAvailable?.() === true)
14390
+ ? { requestContextPolicyInstalled: true } : {}),
14023
14391
  instanceName: this.name,
14024
14392
  taskBoard: !dashboardOff.includes("task_board"),
14025
14393
  workingDirectory: this.config.working_directory,
@@ -14155,6 +14523,7 @@ export class Daemon extends EventEmitter {
14155
14523
  this.humanReminderAttempts?.clear();
14156
14524
  this.cliOomObservation = null;
14157
14525
  this.spawnGeneration++;
14526
+ this.requestContextAdmission?.changed();
14158
14527
  this.interactionObservation.reset(this.interactionOwner());
14159
14528
  this.clearInteractionConfirmation();
14160
14529
  this.inputTransientGuardGeneration = (this.backend?.getInputUnavailableTransients?.().length ?? 0) > 0
@@ -14536,6 +14905,8 @@ export class Daemon extends EventEmitter {
14536
14905
  finally {
14537
14906
  this.endSpawn();
14538
14907
  }
14908
+ if (!resumedSuccessfully)
14909
+ this.requestContextNewWork("fresh");
14539
14910
  return resumedSuccessfully;
14540
14911
  }
14541
14912
  /** The whole agent switch after a resume, on the monotonic clock (#906 §3). */
@@ -15003,6 +15374,7 @@ export class Daemon extends EventEmitter {
15003
15374
  if (this.startupAborted)
15004
15375
  return;
15005
15376
  this.startupAborted = true;
15377
+ this.requestContextHelper?.revoke();
15006
15378
  this.freezeRuntimeMonitors();
15007
15379
  this.pendingIpcRequests.clear();
15008
15380
  if (this.museUsageRelay) {
@@ -15429,6 +15801,7 @@ export class Daemon extends EventEmitter {
15429
15801
  this.assertSessionOomAdmission();
15430
15802
  admit();
15431
15803
  const launchFence = this.launchFenceEpoch;
15804
+ const helperLaunch = this.requestContextHelper?.begin();
15432
15805
  const backendConfig = this.buildBackendConfig(true);
15433
15806
  if (this.classicRestrictionFailed)
15434
15807
  throw Error("Restricted room policy is unavailable");
@@ -15558,20 +15931,42 @@ export class Daemon extends EventEmitter {
15558
15931
  admit();
15559
15932
  let windowId;
15560
15933
  this.assertSessionOomAdmission();
15561
- if (reuseWindow) {
15562
- this.controlClient?.unregisterWindow(this.tmux.getWindowId());
15563
- await this.tmux.respawnWindow(cmd, resolvedCwd, repairAdmission ? admit : undefined);
15564
- windowId = this.tmux.getWindowId();
15934
+ const retirementResources = this.requestContextStartupResources;
15935
+ if (retirementResources)
15936
+ retirementResources.pending++;
15937
+ try {
15938
+ if (reuseWindow) {
15939
+ this.controlClient?.unregisterWindow(this.tmux.getWindowId());
15940
+ await this.tmux.respawnWindow(cmd, resolvedCwd, repairAdmission ? admit : undefined);
15941
+ windowId = this.tmux.getWindowId();
15942
+ }
15943
+ else {
15944
+ // A crash respawn makes a brand new window. The dead one stays registered
15945
+ // unless we say so — the respawn branch above already does.
15946
+ const retired = this.tmux.getWindowId();
15947
+ windowId = await this.tmux.createWindow(cmd, resolvedCwd, this.name);
15948
+ if (retired && retired !== windowId)
15949
+ this.controlClient?.unregisterWindow(retired);
15950
+ }
15951
+ if (retirementResources) {
15952
+ const pid = await this.paneHost.getPanePid(this.tmuxSessionName, windowId);
15953
+ if (!pid || !Number.isSafeInteger(pid) || pid <= 1)
15954
+ throw Error("Request startup process identity unavailable");
15955
+ retirementResources.windows.push({ session: this.tmuxSessionName, window: windowId, pid });
15956
+ }
15565
15957
  }
15566
- else {
15567
- // A crash respawn makes a brand new window. The dead one stays registered
15568
- // unless we say so — the respawn branch above already does.
15569
- const retired = this.tmux.getWindowId();
15570
- windowId = await this.tmux.createWindow(cmd, resolvedCwd, this.name);
15571
- if (retired && retired !== windowId)
15572
- this.controlClient?.unregisterWindow(retired);
15958
+ catch (error) {
15959
+ if (retirementResources)
15960
+ retirementResources.unknown = true;
15961
+ throw error;
15962
+ }
15963
+ finally {
15964
+ if (retirementResources)
15965
+ retirementResources.pending--;
15573
15966
  }
15574
15967
  admit();
15968
+ if (helperLaunch)
15969
+ this.requestContextHelper.confirm(helperLaunch);
15575
15970
  this.writeWindowId(windowId);
15576
15971
  // Enable remain-on-exit to capture exit codes on crash
15577
15972
  await this.tmux.setRemainOnExit().catch(err => {