@bastani/atomic 0.10.2-alpha.1 → 0.10.3-alpha.1

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 (499) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +17 -0
  3. package/dist/builtin/intercom/broker/broker-instance.ts +2 -13
  4. package/dist/builtin/intercom/broker/broker.ts +158 -73
  5. package/dist/builtin/intercom/broker/durable-ended-queue.ts +14 -2
  6. package/dist/builtin/intercom/broker/host-command-environment.ts +13 -0
  7. package/dist/builtin/intercom/broker/hosted-session-errors.ts +1 -0
  8. package/dist/builtin/intercom/broker/multinode-router.ts +111 -16
  9. package/dist/builtin/intercom/broker/multinode-state-store.ts +50 -4
  10. package/dist/builtin/intercom/broker/open-broker-state.ts +5 -4
  11. package/dist/builtin/intercom/broker/spawn.ts +144 -25
  12. package/dist/builtin/intercom/broker/sql-add-column.ts +33 -0
  13. package/dist/builtin/intercom/broker/sql-known-session-store.ts +120 -36
  14. package/dist/builtin/intercom/broker/sql-outbox-store.ts +75 -13
  15. package/dist/builtin/intercom/broker/start-announcement.ts +55 -10
  16. package/dist/builtin/intercom/broker/watchdog.ts +10 -7
  17. package/dist/builtin/intercom/index.bundle.mjs +111 -27
  18. package/dist/builtin/intercom/package.json +1 -1
  19. package/dist/builtin/mcp/package.json +1 -1
  20. package/dist/builtin/subagents/CHANGELOG.md +29 -0
  21. package/dist/builtin/subagents/package.json +1 -1
  22. package/dist/builtin/subagents/skills/skill-creator/SKILL.md +30 -52
  23. package/dist/builtin/subagents/skills/skill-creator/eval-viewer/generate_review.py +34 -40
  24. package/dist/builtin/subagents/skills/skill-creator/eval-viewer/viewer.html +2 -2
  25. package/dist/builtin/subagents/skills/skill-creator/scripts/atomic_cli.py +668 -0
  26. package/dist/builtin/subagents/skills/skill-creator/scripts/generate_report.py +3 -3
  27. package/dist/builtin/subagents/skills/skill-creator/scripts/improve_description.py +42 -38
  28. package/dist/builtin/subagents/skills/skill-creator/scripts/run_eval.py +268 -176
  29. package/dist/builtin/subagents/skills/skill-creator/scripts/run_loop.py +20 -11
  30. package/dist/builtin/subagents/skills/skill-creator/scripts/utils.py +1 -1
  31. package/dist/builtin/subagents/src/extension/index.bundle.mjs +163 -97
  32. package/dist/builtin/web-access/CHANGELOG.md +14 -0
  33. package/dist/builtin/web-access/index.bundle.mjs +5 -4
  34. package/dist/builtin/web-access/package.json +1 -1
  35. package/dist/core/agent-session-auto-compaction.d.ts +10 -1
  36. package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
  37. package/dist/core/agent-session-auto-compaction.js +54 -2
  38. package/dist/core/agent-session-auto-compaction.js.map +1 -1
  39. package/dist/core/agent-session-compaction.d.ts +4 -0
  40. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  41. package/dist/core/agent-session-compaction.js +17 -2
  42. package/dist/core/agent-session-compaction.js.map +1 -1
  43. package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -1
  44. package/dist/core/agent-session-custom-message-commit.js +3 -1
  45. package/dist/core/agent-session-custom-message-commit.js.map +1 -1
  46. package/dist/core/agent-session-events.d.ts +2 -0
  47. package/dist/core/agent-session-events.d.ts.map +1 -1
  48. package/dist/core/agent-session-events.js +34 -13
  49. package/dist/core/agent-session-events.js.map +1 -1
  50. package/dist/core/agent-session-export.d.ts.map +1 -1
  51. package/dist/core/agent-session-export.js +3 -0
  52. package/dist/core/agent-session-export.js.map +1 -1
  53. package/dist/core/agent-session-message-queue.d.ts +27 -0
  54. package/dist/core/agent-session-message-queue.d.ts.map +1 -1
  55. package/dist/core/agent-session-message-queue.js +213 -30
  56. package/dist/core/agent-session-message-queue.js.map +1 -1
  57. package/dist/core/agent-session-methods.d.ts +6 -1
  58. package/dist/core/agent-session-methods.d.ts.map +1 -1
  59. package/dist/core/agent-session-methods.js.map +1 -1
  60. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  61. package/dist/core/agent-session-prompt.js +35 -3
  62. package/dist/core/agent-session-prompt.js.map +1 -1
  63. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  64. package/dist/core/agent-session-runtime.js +2 -2
  65. package/dist/core/agent-session-runtime.js.map +1 -1
  66. package/dist/core/agent-session-state.d.ts.map +1 -1
  67. package/dist/core/agent-session-state.js +6 -1
  68. package/dist/core/agent-session-state.js.map +1 -1
  69. package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
  70. package/dist/core/agent-session-tool-hooks.js +15 -2
  71. package/dist/core/agent-session-tool-hooks.js.map +1 -1
  72. package/dist/core/agent-session-typed-queue.d.ts +14 -1
  73. package/dist/core/agent-session-typed-queue.d.ts.map +1 -1
  74. package/dist/core/agent-session-typed-queue.js +26 -1
  75. package/dist/core/agent-session-typed-queue.js.map +1 -1
  76. package/dist/core/agent-session-types.d.ts +5 -0
  77. package/dist/core/agent-session-types.d.ts.map +1 -1
  78. package/dist/core/agent-session-types.js.map +1 -1
  79. package/dist/core/agent-session.d.ts.map +1 -1
  80. package/dist/core/agent-session.js +2 -1
  81. package/dist/core/agent-session.js.map +1 -1
  82. package/dist/core/async-scope.d.ts +9 -4
  83. package/dist/core/async-scope.d.ts.map +1 -1
  84. package/dist/core/async-scope.js +13 -5
  85. package/dist/core/async-scope.js.map +1 -1
  86. package/dist/core/builtin-diagnostics.js +2 -2
  87. package/dist/core/builtin-diagnostics.js.map +1 -1
  88. package/dist/core/chat-admission-order.d.ts.map +1 -1
  89. package/dist/core/chat-admission-order.js +2 -1
  90. package/dist/core/chat-admission-order.js.map +1 -1
  91. package/dist/core/chat-record-saves.d.ts +4 -0
  92. package/dist/core/chat-record-saves.d.ts.map +1 -0
  93. package/dist/core/chat-record-saves.js +25 -0
  94. package/dist/core/chat-record-saves.js.map +1 -0
  95. package/dist/core/command-deliveries.d.ts +62 -0
  96. package/dist/core/command-deliveries.d.ts.map +1 -0
  97. package/dist/core/command-deliveries.js +139 -0
  98. package/dist/core/command-deliveries.js.map +1 -0
  99. package/dist/core/diagnostic-writer.d.ts.map +1 -1
  100. package/dist/core/diagnostic-writer.js +5 -4
  101. package/dist/core/diagnostic-writer.js.map +1 -1
  102. package/dist/core/extension-startup-close.d.ts +1 -2
  103. package/dist/core/extension-startup-close.d.ts.map +1 -1
  104. package/dist/core/extension-startup-close.js +2 -2
  105. package/dist/core/extension-startup-close.js.map +1 -1
  106. package/dist/core/extensions/jiti-aliases.d.ts +11 -0
  107. package/dist/core/extensions/jiti-aliases.d.ts.map +1 -0
  108. package/dist/core/extensions/jiti-aliases.js +28 -0
  109. package/dist/core/extensions/jiti-aliases.js.map +1 -0
  110. package/dist/core/extensions/loader-api.js +3 -3
  111. package/dist/core/extensions/loader-api.js.map +1 -1
  112. package/dist/core/extensions/loader-bindings.js +2 -2
  113. package/dist/core/extensions/loader-bindings.js.map +1 -1
  114. package/dist/core/extensions/loader-rollback.d.ts +1 -2
  115. package/dist/core/extensions/loader-rollback.d.ts.map +1 -1
  116. package/dist/core/extensions/loader-rollback.js +2 -2
  117. package/dist/core/extensions/loader-rollback.js.map +1 -1
  118. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  119. package/dist/core/extensions/loader-virtual-modules.js +53 -9
  120. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  121. package/dist/core/extensions/native-builtin-entries.d.ts +5 -0
  122. package/dist/core/extensions/native-builtin-entries.d.ts.map +1 -1
  123. package/dist/core/extensions/native-builtin-entries.js +8 -1
  124. package/dist/core/extensions/native-builtin-entries.js.map +1 -1
  125. package/dist/core/extensions/reloadable-scripts.d.ts +21 -2
  126. package/dist/core/extensions/reloadable-scripts.d.ts.map +1 -1
  127. package/dist/core/extensions/reloadable-scripts.js +11 -3
  128. package/dist/core/extensions/reloadable-scripts.js.map +1 -1
  129. package/dist/core/extensions/source-builtin-imports.d.ts +40 -0
  130. package/dist/core/extensions/source-builtin-imports.d.ts.map +1 -0
  131. package/dist/core/extensions/source-builtin-imports.js +142 -0
  132. package/dist/core/extensions/source-builtin-imports.js.map +1 -0
  133. package/dist/core/extensions/transform-graph.d.ts +15 -0
  134. package/dist/core/extensions/transform-graph.d.ts.map +1 -0
  135. package/dist/core/extensions/transform-graph.js +85 -0
  136. package/dist/core/extensions/transform-graph.js.map +1 -0
  137. package/dist/core/extensions/ts-source-specifiers.d.ts +2 -0
  138. package/dist/core/extensions/ts-source-specifiers.d.ts.map +1 -1
  139. package/dist/core/extensions/ts-source-specifiers.js +7 -0
  140. package/dist/core/extensions/ts-source-specifiers.js.map +1 -1
  141. package/dist/core/extensions/ts-transform-worker.d.ts +2 -0
  142. package/dist/core/extensions/ts-transform-worker.d.ts.map +1 -0
  143. package/dist/core/extensions/ts-transform-worker.js +43 -0
  144. package/dist/core/extensions/ts-transform-worker.js.map +1 -0
  145. package/dist/core/message-admission.d.ts.map +1 -1
  146. package/dist/core/message-admission.js +4 -4
  147. package/dist/core/message-admission.js.map +1 -1
  148. package/dist/core/messages.d.ts +5 -0
  149. package/dist/core/messages.d.ts.map +1 -1
  150. package/dist/core/messages.js +35 -0
  151. package/dist/core/messages.js.map +1 -1
  152. package/dist/core/model-fallback-failures.d.ts +1 -1
  153. package/dist/core/model-fallback-failures.d.ts.map +1 -1
  154. package/dist/core/model-fallback-failures.js +18 -1
  155. package/dist/core/model-fallback-failures.js.map +1 -1
  156. package/dist/core/process-start-token.d.ts +7 -0
  157. package/dist/core/process-start-token.d.ts.map +1 -1
  158. package/dist/core/process-start-token.js +14 -0
  159. package/dist/core/process-start-token.js.map +1 -1
  160. package/dist/core/project-trust-electorate.d.ts +24 -0
  161. package/dist/core/project-trust-electorate.d.ts.map +1 -0
  162. package/dist/core/project-trust-electorate.js +52 -0
  163. package/dist/core/project-trust-electorate.js.map +1 -0
  164. package/dist/core/project-trust-state.d.ts +15 -0
  165. package/dist/core/project-trust-state.d.ts.map +1 -1
  166. package/dist/core/project-trust-state.js +15 -0
  167. package/dist/core/project-trust-state.js.map +1 -1
  168. package/dist/core/provider-request-admission.d.ts.map +1 -1
  169. package/dist/core/provider-request-admission.js +2 -2
  170. package/dist/core/provider-request-admission.js.map +1 -1
  171. package/dist/core/queued-input-admission.js +2 -2
  172. package/dist/core/queued-input-admission.js.map +1 -1
  173. package/dist/core/queued-message-delivery.d.ts +2 -2
  174. package/dist/core/queued-message-delivery.d.ts.map +1 -1
  175. package/dist/core/queued-message-delivery.js +6 -3
  176. package/dist/core/queued-message-delivery.js.map +1 -1
  177. package/dist/core/resource-admission-scope.js +2 -2
  178. package/dist/core/resource-admission-scope.js.map +1 -1
  179. package/dist/core/resume/blueprint/process.d.ts +3 -4
  180. package/dist/core/resume/blueprint/process.d.ts.map +1 -1
  181. package/dist/core/resume/blueprint/process.js +33 -17
  182. package/dist/core/resume/blueprint/process.js.map +1 -1
  183. package/dist/core/resume/path-mapping.js +4 -4
  184. package/dist/core/resume/path-mapping.js.map +1 -1
  185. package/dist/core/resume/session-resume.d.ts +9 -0
  186. package/dist/core/resume/session-resume.d.ts.map +1 -1
  187. package/dist/core/resume/session-resume.js +27 -2
  188. package/dist/core/resume/session-resume.js.map +1 -1
  189. package/dist/core/resume-cache-checkpoint.d.ts +27 -1
  190. package/dist/core/resume-cache-checkpoint.d.ts.map +1 -1
  191. package/dist/core/resume-cache-checkpoint.js +45 -0
  192. package/dist/core/resume-cache-checkpoint.js.map +1 -1
  193. package/dist/core/sdk.d.ts.map +1 -1
  194. package/dist/core/sdk.js +7 -31
  195. package/dist/core/sdk.js.map +1 -1
  196. package/dist/core/session-lifecycle-scope.d.ts +1 -2
  197. package/dist/core/session-lifecycle-scope.d.ts.map +1 -1
  198. package/dist/core/session-lifecycle-scope.js +2 -2
  199. package/dist/core/session-lifecycle-scope.js.map +1 -1
  200. package/dist/core/session-lifecycle-work.js +2 -2
  201. package/dist/core/session-lifecycle-work.js.map +1 -1
  202. package/dist/core/session-manager-core.d.ts.map +1 -1
  203. package/dist/core/session-manager-core.js +3 -0
  204. package/dist/core/session-manager-core.js.map +1 -1
  205. package/dist/core/session-storage.d.ts +12 -0
  206. package/dist/core/session-storage.d.ts.map +1 -1
  207. package/dist/core/session-storage.js +68 -1
  208. package/dist/core/session-storage.js.map +1 -1
  209. package/dist/core/settings-lock-directory.d.ts.map +1 -1
  210. package/dist/core/settings-lock-directory.js +4 -3
  211. package/dist/core/settings-lock-directory.js.map +1 -1
  212. package/dist/core/settings-write-ownership.d.ts +1 -2
  213. package/dist/core/settings-write-ownership.d.ts.map +1 -1
  214. package/dist/core/settings-write-ownership.js +2 -2
  215. package/dist/core/settings-write-ownership.js.map +1 -1
  216. package/dist/core/storage/node-sqlite-thread.d.ts.map +1 -1
  217. package/dist/core/storage/node-sqlite-thread.js +6 -4
  218. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  219. package/dist/core/storage/node-sqlite.d.ts.map +1 -1
  220. package/dist/core/storage/node-sqlite.js +22 -8
  221. package/dist/core/storage/node-sqlite.js.map +1 -1
  222. package/dist/core/system-prompt.d.ts +16 -2
  223. package/dist/core/system-prompt.d.ts.map +1 -1
  224. package/dist/core/system-prompt.js +33 -6
  225. package/dist/core/system-prompt.js.map +1 -1
  226. package/dist/core/tasks/agent-adapter.d.ts.map +1 -1
  227. package/dist/core/tasks/agent-adapter.js +2 -1
  228. package/dist/core/tasks/agent-adapter.js.map +1 -1
  229. package/dist/core/tasks/completion.d.ts +3 -2
  230. package/dist/core/tasks/completion.d.ts.map +1 -1
  231. package/dist/core/tasks/completion.js.map +1 -1
  232. package/dist/core/tasks/execution-scope.js +2 -2
  233. package/dist/core/tasks/execution-scope.js.map +1 -1
  234. package/dist/core/tools/bash.d.ts.map +1 -1
  235. package/dist/core/tools/bash.js +2 -1
  236. package/dist/core/tools/bash.js.map +1 -1
  237. package/dist/core/tools/history-regex-worker.d.ts.map +1 -1
  238. package/dist/core/tools/history-regex-worker.js +3 -2
  239. package/dist/core/tools/history-regex-worker.js.map +1 -1
  240. package/dist/core/tools/shell-task-render.d.ts +3 -2
  241. package/dist/core/tools/shell-task-render.d.ts.map +1 -1
  242. package/dist/core/tools/shell-task-render.js +7 -5
  243. package/dist/core/tools/shell-task-render.js.map +1 -1
  244. package/dist/core/tools/shell-task-status.d.ts +6 -2
  245. package/dist/core/tools/shell-task-status.d.ts.map +1 -1
  246. package/dist/core/tools/shell-task-status.js +13 -8
  247. package/dist/core/tools/shell-task-status.js.map +1 -1
  248. package/dist/core/tools/sqlite-selector-connection.d.ts.map +1 -1
  249. package/dist/core/tools/sqlite-selector-connection.js +4 -3
  250. package/dist/core/tools/sqlite-selector-connection.js.map +1 -1
  251. package/dist/core/tools/windows-directory-security.d.ts.map +1 -1
  252. package/dist/core/tools/windows-directory-security.js +2 -1
  253. package/dist/core/tools/windows-directory-security.js.map +1 -1
  254. package/dist/core/worktree-snapshot/git.js +2 -2
  255. package/dist/core/worktree-snapshot/git.js.map +1 -1
  256. package/dist/extensions/mcp/index.d.ts +6 -1
  257. package/dist/extensions/mcp/index.d.ts.map +1 -1
  258. package/dist/extensions/mcp/index.js +150 -18
  259. package/dist/extensions/mcp/index.js.map +1 -1
  260. package/dist/extensions/mcp/tool-records.d.ts +44 -9
  261. package/dist/extensions/mcp/tool-records.d.ts.map +1 -1
  262. package/dist/extensions/mcp/tool-records.js +58 -16
  263. package/dist/extensions/mcp/tool-records.js.map +1 -1
  264. package/dist/index.d.ts +2 -0
  265. package/dist/index.d.ts.map +1 -1
  266. package/dist/index.js +4 -0
  267. package/dist/index.js.map +1 -1
  268. package/dist/main-session.d.ts +3 -1
  269. package/dist/main-session.d.ts.map +1 -1
  270. package/dist/main-session.js +1 -0
  271. package/dist/main-session.js.map +1 -1
  272. package/dist/main.d.ts.map +1 -1
  273. package/dist/main.js +230 -96
  274. package/dist/main.js.map +1 -1
  275. package/dist/modes/interactive/agent-view/agent-view-bridge.d.ts +5 -0
  276. package/dist/modes/interactive/agent-view/agent-view-bridge.d.ts.map +1 -1
  277. package/dist/modes/interactive/agent-view/agent-view-bridge.js.map +1 -1
  278. package/dist/modes/interactive/agent-view/agent-view-switcher.d.ts +5 -2
  279. package/dist/modes/interactive/agent-view/agent-view-switcher.d.ts.map +1 -1
  280. package/dist/modes/interactive/agent-view/agent-view-switcher.js +3 -3
  281. package/dist/modes/interactive/agent-view/agent-view-switcher.js.map +1 -1
  282. package/dist/modes/interactive/agent-view/contracts.d.ts +6 -0
  283. package/dist/modes/interactive/agent-view/contracts.d.ts.map +1 -1
  284. package/dist/modes/interactive/agent-view/contracts.js.map +1 -1
  285. package/dist/modes/interactive/agent-view/install.d.ts.map +1 -1
  286. package/dist/modes/interactive/agent-view/install.js +2 -1
  287. package/dist/modes/interactive/agent-view/install.js.map +1 -1
  288. package/dist/modes/interactive/agent-view/open-port.d.ts +4 -2
  289. package/dist/modes/interactive/agent-view/open-port.d.ts.map +1 -1
  290. package/dist/modes/interactive/agent-view/open-port.js +4 -3
  291. package/dist/modes/interactive/agent-view/open-port.js.map +1 -1
  292. package/dist/modes/interactive/agent-view/prompt-retarget.d.ts.map +1 -1
  293. package/dist/modes/interactive/agent-view/prompt-retarget.js +18 -5
  294. package/dist/modes/interactive/agent-view/prompt-retarget.js.map +1 -1
  295. package/dist/modes/interactive/agent-view/remote-port.d.ts +10 -1
  296. package/dist/modes/interactive/agent-view/remote-port.d.ts.map +1 -1
  297. package/dist/modes/interactive/agent-view/remote-port.js +36 -4
  298. package/dist/modes/interactive/agent-view/remote-port.js.map +1 -1
  299. package/dist/modes/interactive/agent-view/viewed-keys.d.ts +56 -0
  300. package/dist/modes/interactive/agent-view/viewed-keys.d.ts.map +1 -0
  301. package/dist/modes/interactive/agent-view/viewed-keys.js +63 -0
  302. package/dist/modes/interactive/agent-view/viewed-keys.js.map +1 -0
  303. package/dist/modes/interactive/agent-view/viewed-submit.d.ts +14 -4
  304. package/dist/modes/interactive/agent-view/viewed-submit.d.ts.map +1 -1
  305. package/dist/modes/interactive/agent-view/viewed-submit.js +51 -17
  306. package/dist/modes/interactive/agent-view/viewed-submit.js.map +1 -1
  307. package/dist/modes/interactive/components/agent-panel.d.ts.map +1 -1
  308. package/dist/modes/interactive/components/agent-panel.js +8 -21
  309. package/dist/modes/interactive/components/agent-panel.js.map +1 -1
  310. package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
  311. package/dist/modes/interactive/components/chat-session-host-actions.js +18 -5
  312. package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
  313. package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
  314. package/dist/modes/interactive/components/chat-session-host-rendering.js +6 -0
  315. package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
  316. package/dist/modes/interactive/components/chat-session-host-state.d.ts +1 -0
  317. package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
  318. package/dist/modes/interactive/components/chat-session-host-state.js +2 -0
  319. package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
  320. package/dist/modes/interactive/components/chat-session-host-types.d.ts +5 -0
  321. package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -1
  322. package/dist/modes/interactive/components/chat-session-host-types.js.map +1 -1
  323. package/dist/modes/interactive/components/custom-editor.d.ts +33 -2
  324. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  325. package/dist/modes/interactive/components/custom-editor.js +58 -2
  326. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  327. package/dist/modes/interactive/components/host-session-picker.js +2 -2
  328. package/dist/modes/interactive/components/host-session-picker.js.map +1 -1
  329. package/dist/modes/interactive/components/main-composer-keys.d.ts +16 -5
  330. package/dist/modes/interactive/components/main-composer-keys.d.ts.map +1 -1
  331. package/dist/modes/interactive/components/main-composer-keys.js +27 -8
  332. package/dist/modes/interactive/components/main-composer-keys.js.map +1 -1
  333. package/dist/modes/interactive/components/notice-line.d.ts +8 -25
  334. package/dist/modes/interactive/components/notice-line.d.ts.map +1 -1
  335. package/dist/modes/interactive/components/notice-line.js +18 -17
  336. package/dist/modes/interactive/components/notice-line.js.map +1 -1
  337. package/dist/modes/interactive/components/prompt-slot.d.ts +20 -3
  338. package/dist/modes/interactive/components/prompt-slot.d.ts.map +1 -1
  339. package/dist/modes/interactive/components/prompt-slot.js +82 -32
  340. package/dist/modes/interactive/components/prompt-slot.js.map +1 -1
  341. package/dist/modes/interactive/components/queued-messages-view.d.ts +5 -2
  342. package/dist/modes/interactive/components/queued-messages-view.d.ts.map +1 -1
  343. package/dist/modes/interactive/components/queued-messages-view.js +12 -5
  344. package/dist/modes/interactive/components/queued-messages-view.js.map +1 -1
  345. package/dist/modes/interactive/components/task-board.d.ts +5 -8
  346. package/dist/modes/interactive/components/task-board.d.ts.map +1 -1
  347. package/dist/modes/interactive/components/task-board.js +5 -49
  348. package/dist/modes/interactive/components/task-board.js.map +1 -1
  349. package/dist/modes/interactive/components/task-completion-message.d.ts.map +1 -1
  350. package/dist/modes/interactive/components/task-completion-message.js +9 -2
  351. package/dist/modes/interactive/components/task-completion-message.js.map +1 -1
  352. package/dist/modes/interactive/components/task-marks.d.ts +19 -0
  353. package/dist/modes/interactive/components/task-marks.d.ts.map +1 -0
  354. package/dist/modes/interactive/components/task-marks.js +25 -0
  355. package/dist/modes/interactive/components/task-marks.js.map +1 -0
  356. package/dist/modes/interactive/components/task-row.d.ts +10 -2
  357. package/dist/modes/interactive/components/task-row.d.ts.map +1 -1
  358. package/dist/modes/interactive/components/task-row.js +39 -32
  359. package/dist/modes/interactive/components/task-row.js.map +1 -1
  360. package/dist/modes/interactive/components/task-transcript-page.d.ts +7 -0
  361. package/dist/modes/interactive/components/task-transcript-page.d.ts.map +1 -1
  362. package/dist/modes/interactive/components/task-transcript-page.js +106 -10
  363. package/dist/modes/interactive/components/task-transcript-page.js.map +1 -1
  364. package/dist/modes/interactive/components/tool-block-families.d.ts.map +1 -1
  365. package/dist/modes/interactive/components/tool-block-families.js +8 -9
  366. package/dist/modes/interactive/components/tool-block-families.js.map +1 -1
  367. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  368. package/dist/modes/interactive/components/tool-execution.js +5 -1
  369. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  370. package/dist/modes/interactive/extension-command-hold.d.ts.map +1 -1
  371. package/dist/modes/interactive/extension-command-hold.js +5 -7
  372. package/dist/modes/interactive/extension-command-hold.js.map +1 -1
  373. package/dist/modes/interactive/interactive-extension-dialogs.js +6 -1
  374. package/dist/modes/interactive/interactive-extension-dialogs.js.map +1 -1
  375. package/dist/modes/interactive/interactive-extension-runtime.d.ts.map +1 -1
  376. package/dist/modes/interactive/interactive-extension-runtime.js +21 -7
  377. package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
  378. package/dist/modes/interactive/interactive-initial-session-binding.d.ts +1 -2
  379. package/dist/modes/interactive/interactive-initial-session-binding.d.ts.map +1 -1
  380. package/dist/modes/interactive/interactive-initial-session-binding.js +2 -2
  381. package/dist/modes/interactive/interactive-initial-session-binding.js.map +1 -1
  382. package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
  383. package/dist/modes/interactive/interactive-input-handling.js +13 -4
  384. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  385. package/dist/modes/interactive/interactive-mode-base.d.ts +2 -1
  386. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  387. package/dist/modes/interactive/interactive-mode-base.js +6 -1
  388. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  389. package/dist/modes/interactive/interactive-mode-helpers.d.ts +4 -2
  390. package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
  391. package/dist/modes/interactive/interactive-mode-helpers.js +6 -0
  392. package/dist/modes/interactive/interactive-mode-helpers.js.map +1 -1
  393. package/dist/modes/interactive/interactive-mode-surface.d.ts +5 -0
  394. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  395. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  396. package/dist/modes/interactive/interactive-process-lifecycle.js +96 -17
  397. package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
  398. package/dist/modes/interactive/interactive-queueing.d.ts +5 -0
  399. package/dist/modes/interactive/interactive-queueing.d.ts.map +1 -1
  400. package/dist/modes/interactive/interactive-queueing.js +37 -5
  401. package/dist/modes/interactive/interactive-queueing.js.map +1 -1
  402. package/dist/modes/interactive/interactive-render-chat.d.ts.map +1 -1
  403. package/dist/modes/interactive/interactive-render-chat.js +45 -4
  404. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  405. package/dist/modes/interactive/interactive-resource-disclosure.d.ts +4 -1
  406. package/dist/modes/interactive/interactive-resource-disclosure.d.ts.map +1 -1
  407. package/dist/modes/interactive/interactive-resource-disclosure.js +20 -1
  408. package/dist/modes/interactive/interactive-resource-disclosure.js.map +1 -1
  409. package/dist/modes/interactive/interactive-resource-rendering.js +3 -0
  410. package/dist/modes/interactive/interactive-resource-rendering.js.map +1 -1
  411. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  412. package/dist/modes/interactive/interactive-startup.js +43 -5
  413. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  414. package/dist/modes/interactive-engine/activity-watchdog.d.ts +6 -3
  415. package/dist/modes/interactive-engine/activity-watchdog.d.ts.map +1 -1
  416. package/dist/modes/interactive-engine/activity-watchdog.js +3 -2
  417. package/dist/modes/interactive-engine/activity-watchdog.js.map +1 -1
  418. package/dist/modes/interactive-engine/engine-health.d.ts +2 -0
  419. package/dist/modes/interactive-engine/engine-health.d.ts.map +1 -1
  420. package/dist/modes/interactive-engine/engine-health.js.map +1 -1
  421. package/dist/modes/interactive-engine/engine-quit-intent.d.ts +10 -0
  422. package/dist/modes/interactive-engine/engine-quit-intent.d.ts.map +1 -1
  423. package/dist/modes/interactive-engine/engine-quit-intent.js +33 -0
  424. package/dist/modes/interactive-engine/engine-quit-intent.js.map +1 -1
  425. package/dist/modes/interactive-engine/extension-ui-bridge.d.ts +7 -1
  426. package/dist/modes/interactive-engine/extension-ui-bridge.d.ts.map +1 -1
  427. package/dist/modes/interactive-engine/extension-ui-bridge.js +15 -2
  428. package/dist/modes/interactive-engine/extension-ui-bridge.js.map +1 -1
  429. package/dist/modes/interactive-engine/host-listener-failures.d.ts +24 -0
  430. package/dist/modes/interactive-engine/host-listener-failures.d.ts.map +1 -0
  431. package/dist/modes/interactive-engine/host-listener-failures.js +98 -0
  432. package/dist/modes/interactive-engine/host-listener-failures.js.map +1 -0
  433. package/dist/modes/interactive-engine/isolated-runtime.d.ts +16 -0
  434. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  435. package/dist/modes/interactive-engine/isolated-runtime.js +74 -7
  436. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  437. package/dist/modes/interactive-engine/protocol.d.ts +5 -0
  438. package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
  439. package/dist/modes/interactive-engine/protocol.js +8 -2
  440. package/dist/modes/interactive-engine/protocol.js.map +1 -1
  441. package/dist/modes/interactive-engine/remote-component.d.ts +13 -0
  442. package/dist/modes/interactive-engine/remote-component.d.ts.map +1 -1
  443. package/dist/modes/interactive-engine/remote-component.js +69 -4
  444. package/dist/modes/interactive-engine/remote-component.js.map +1 -1
  445. package/dist/modes/print-mode.d.ts.map +1 -1
  446. package/dist/modes/print-mode.js +34 -6
  447. package/dist/modes/print-mode.js.map +1 -1
  448. package/dist/modes/rpc/agent-panel-bridge.d.ts +7 -0
  449. package/dist/modes/rpc/agent-panel-bridge.d.ts.map +1 -1
  450. package/dist/modes/rpc/agent-panel-bridge.js +11 -1
  451. package/dist/modes/rpc/agent-panel-bridge.js.map +1 -1
  452. package/dist/modes/rpc/agent-view-rpc-panel.d.ts.map +1 -1
  453. package/dist/modes/rpc/agent-view-rpc-panel.js +11 -5
  454. package/dist/modes/rpc/agent-view-rpc-panel.js.map +1 -1
  455. package/dist/modes/rpc/rpc-client-process.d.ts +8 -1
  456. package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
  457. package/dist/modes/rpc/rpc-client-process.js +89 -65
  458. package/dist/modes/rpc/rpc-client-process.js.map +1 -1
  459. package/dist/modes/rpc/rpc-client.d.ts +21 -0
  460. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  461. package/dist/modes/rpc/rpc-client.js +77 -33
  462. package/dist/modes/rpc/rpc-client.js.map +1 -1
  463. package/dist/modes/rpc/rpc-event-buffer.d.ts +5 -0
  464. package/dist/modes/rpc/rpc-event-buffer.d.ts.map +1 -1
  465. package/dist/modes/rpc/rpc-event-buffer.js +8 -2
  466. package/dist/modes/rpc/rpc-event-buffer.js.map +1 -1
  467. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  468. package/dist/modes/rpc/rpc-mode.js +9 -2
  469. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  470. package/dist/utils/shell.d.ts +5 -1
  471. package/dist/utils/shell.d.ts.map +1 -1
  472. package/dist/utils/shell.js +14 -7
  473. package/dist/utils/shell.js.map +1 -1
  474. package/dist/utils/worker-threads.d.ts +10 -4
  475. package/dist/utils/worker-threads.d.ts.map +1 -1
  476. package/dist/utils/worker-threads.js +10 -4
  477. package/dist/utils/worker-threads.js.map +1 -1
  478. package/docs/background-tasks.md +10 -10
  479. package/docs/compaction.md +1 -0
  480. package/docs/development.md +1 -1
  481. package/docs/environment-variables.md +4 -0
  482. package/docs/extensions/api-reference.md +2 -0
  483. package/docs/extensions/events.md +1 -1
  484. package/docs/getting-started/installation.md +1 -0
  485. package/docs/guides/non-interactive.md +2 -0
  486. package/docs/guides/resume-on-any-machine.md +3 -1
  487. package/docs/intercom/reference.md +1 -1
  488. package/docs/keybindings.md +6 -5
  489. package/docs/libraries/ai.md +2 -1
  490. package/docs/mcp-servers.md +1 -1
  491. package/docs/sdk/reference.md +1 -1
  492. package/docs/sdk.md +6 -0
  493. package/docs/security.md +4 -2
  494. package/docs/settings.md +2 -1
  495. package/docs/storage.md +2 -0
  496. package/docs/subagents.md +2 -2
  497. package/docs/tui/reference.md +3 -1
  498. package/npm-shrinkwrap.json +49 -49
  499. package/package.json +6 -6
@@ -35,6 +35,7 @@ import {
35
35
  holdsSessionId,
36
36
  KNOWN_SESSION_RETENTION_MS,
37
37
  type KnownSession,
38
+ type KnownSessionBindResult,
38
39
  type KnownSessionState,
39
40
  type Lease,
40
41
  type LeaseState,
@@ -54,6 +55,7 @@ import {
54
55
  reservationKeyFor,
55
56
  returnAddressOf,
56
57
  type SentMessageReservation,
58
+ type SessionIdReclaimResult,
57
59
  } from "./multinode-state-store.js";
58
60
  import type { PendingQuestion, PendingQuestionIndex } from "./pending-question-index.js";
59
61
  import { ROUTE_UNAVAILABLE_REASON } from "./delivery-failure-reason.js";
@@ -168,6 +170,31 @@ const MAX_SUPERSEDED_HOPS = 8;
168
170
  export const KNOWN_SESSION_REFRESH_INTERVAL_MS = 60 * 60 * 1000;
169
171
  const TARGET_GROUP_REFUSAL = "Target session is in a different intercom group";
170
172
 
173
+ /** How a registration's claim of its preferred id ended (`MultiNodeRouter.claimSessionId`). */
174
+ export type SessionIdClaim =
175
+ | { readonly status: "granted" }
176
+ | { readonly status: "refused" }
177
+ /** #5607: the shared database did not answer in time; see `SessionIdReclaimRequest`. */
178
+ | { readonly status: "unanswered"; readonly unanswered: UnansweredSessionIdClaim };
179
+
180
+ /** #5607: a claim the shared database did not answer in time: the id it asked for, and the value it wrote with it. */
181
+ export interface UnansweredSessionIdClaim {
182
+ readonly sessionId: string;
183
+ readonly claim: string;
184
+ }
185
+
186
+ /**
187
+ * #5607: given to `sessionRegistered` for a session whose claim went unanswered. The session is not registered on this
188
+ * broker yet: `settle` registers it, once, under the claimed id (`keep`) or the fresh one its registration started
189
+ * with, and reports whether it kept the claimed id. It cannot keep it once its registration has been answered or a
190
+ * session here holds that id, and does nothing after the first call.
191
+ */
192
+ export interface SessionIdReclaimRequest extends UnansweredSessionIdClaim {
193
+ readonly settle: (keep: boolean) => boolean;
194
+ /** Whether `settle` is still to be called: false once the registration settled without it, as when it was answered. */
195
+ readonly unsettled: () => boolean;
196
+ }
197
+
171
198
  /** What the broker uses of `open-broker-state.ts`, which it loads lazily (replaceable in tests). */
172
199
  export interface BrokerStateOpener<Source> {
173
200
  resolveBrokerStateSource(
@@ -421,6 +448,14 @@ function outboxFullReason(full: { readonly limit: number; readonly byteLimit: nu
421
448
  } MiB); this message was not queued. Messages already queued for it are kept. Try again after it returns and receives them.`;
422
449
  }
423
450
 
451
+ /**
452
+ * #5607: what an enqueue for a recipient the sender found offline (`hostBrokerId` absent) also does: wake the broker
453
+ * holding the recipient's live presence as the row is written, should it have registered meanwhile.
454
+ */
455
+ function offlineHost(hostBrokerId: string | undefined): Pick<OutboxEnqueueRequest, "wakeHostWithinMs"> {
456
+ return hostBrokerId === undefined ? { wakeHostWithinMs: BROKER_LEASE_STALE_AFTER_MS } : {};
457
+ }
458
+
424
459
  function queuedFrame(messageId: string, attemptId: string | undefined, position: number): BrokerOutboundFrame {
425
460
  return {
426
461
  type: "queued",
@@ -608,29 +643,77 @@ export class MultiNodeRouter {
608
643
  /**
609
644
  * Whether a registration with `returnAddress` may take the Intercom id `sessionId`, binding the id to it when free.
610
645
  * In multi-node mode an id carries authority (shared ask routes and known sessions name sessions by id), so only the
611
- * session that registered it gets it back. False when the shared store does not answer in time.
646
+ * session that registered it gets it back. `unanswered` when the shared store does not answer in time: the session
647
+ * registers under a fresh id, and its registration's binding write tries once more to keep this one (#5607).
612
648
  */
613
- async claimSessionId(sessionId: string, returnAddress: string): Promise<boolean> {
614
- if (this.closed) return false;
649
+ async claimSessionId(sessionId: string, returnAddress: string): Promise<SessionIdClaim> {
650
+ if (this.closed) return { status: "refused" };
651
+ // #5607: written with the binding, so a later write can tell whether the binding is still this claim's.
652
+ const claim = randomUUID();
615
653
  let bound: ReturnType<typeof setTimeout> | undefined;
616
654
  try {
617
- return await Promise.race([
655
+ return await Promise.race<SessionIdClaim>([
618
656
  this.state.knownSessions
619
- .bind(sessionId, returnAddress, KNOWN_SESSION_RETENTION_MS)
620
- .then((result) => result.status === "bound"),
621
- new Promise<boolean>((resolve) => {
622
- bound = setTimeout(() => resolve(false), SESSION_ID_CLAIM_BOUND_MS);
657
+ .bind(sessionId, returnAddress, KNOWN_SESSION_RETENTION_MS, claim)
658
+ .then((result) => ({ status: result.status === "bound" ? "granted" : "refused" })),
659
+ new Promise<SessionIdClaim>((resolve) => {
660
+ bound = setTimeout(
661
+ () => resolve({ status: "unanswered", unanswered: { sessionId, claim } }),
662
+ SESSION_ID_CLAIM_BOUND_MS,
663
+ );
623
664
  bound.unref?.();
624
665
  }),
625
666
  ]);
626
667
  } catch (error) {
627
668
  this.report(error);
628
- return false;
669
+ return { status: "refused" };
629
670
  } finally {
630
671
  clearTimeout(bound);
631
672
  }
632
673
  }
633
674
 
675
+ /**
676
+ * #5607: the binding write of a registration whose claim of its preferred id went unanswered, in the slot today's
677
+ * fresh-id binding takes. One write keeps the preferred id when the binding is still the one that claim wrote and no
678
+ * other broker presents a session of its return address, in any group; otherwise it binds the fresh id. The session is then registered
679
+ * here under the id the write chose, or under the fresh id when the claimed one can no longer be given (its
680
+ * registration was answered meanwhile, or a session here holds it), which is then bound as today.
681
+ */
682
+ private async reclaimOrBind(
683
+ session: BrokerConnectedSession,
684
+ reclaim: SessionIdReclaimRequest,
685
+ ): Promise<KnownSessionBindResult> {
686
+ const { knownSessions } = this.state;
687
+ const returnAddress = session.registrationReturnAddress ?? "";
688
+ const freshId = session.info.id;
689
+ const bindFresh = () => {
690
+ reclaim.settle(false);
691
+ return knownSessions.bind(freshId, returnAddress, KNOWN_SESSION_RETENTION_MS);
692
+ };
693
+ if (knownSessions.reclaim === undefined || !reclaim.unsettled()) return bindFresh();
694
+ let reclaimed: SessionIdReclaimResult;
695
+ try {
696
+ reclaimed = await knownSessions.reclaim({
697
+ intercomSessionId: reclaim.sessionId,
698
+ returnAddress,
699
+ claim: reclaim.claim,
700
+ retentionMs: KNOWN_SESSION_RETENTION_MS,
701
+ brokerId: this.brokerId,
702
+ presenceStaleAfterMs: BROKER_LEASE_STALE_AFTER_MS,
703
+ freshId,
704
+ });
705
+ } catch (error) {
706
+ reclaim.settle(false);
707
+ throw error;
708
+ }
709
+ if (reclaimed.status === "fresh") {
710
+ reclaim.settle(false);
711
+ return reclaimed.binding;
712
+ }
713
+ if (reclaimed.status === "kept" && reclaim.settle(true)) return { status: "bound" };
714
+ return bindFresh();
715
+ }
716
+
634
717
  private holdsSessionId(sessionId: string, returnAddress: string | undefined): Promise<boolean> {
635
718
  return holdsSessionId(this.state.knownSessions, sessionId, returnAddress);
636
719
  }
@@ -643,6 +726,7 @@ export class MultiNodeRouter {
643
726
  sessionRegistered(
644
727
  session: BrokerConnectedSession,
645
728
  consumed?: ConsumedReservation,
729
+ reclaim?: SessionIdReclaimRequest,
646
730
  ): Promise<void> {
647
731
  if (this.closed || this.presence.has(session)) return Promise.resolve();
648
732
  const entry: PresenceEntry = {};
@@ -657,11 +741,14 @@ export class MultiNodeRouter {
657
741
  this.serial(identity, async () => {
658
742
  try {
659
743
  // An id bound to another session's return address is not this session's across nodes (see `claimSessionId`).
660
- const binding = await this.state.knownSessions.bind(
661
- session.info.id,
662
- session.registrationReturnAddress ?? "",
663
- KNOWN_SESSION_RETENTION_MS,
664
- );
744
+ const binding =
745
+ reclaim === undefined
746
+ ? await this.state.knownSessions.bind(
747
+ session.info.id,
748
+ session.registrationReturnAddress ?? "",
749
+ KNOWN_SESSION_RETENTION_MS,
750
+ )
751
+ : await this.reclaimOrBind(session, reclaim);
665
752
  if (binding.status === "refused") {
666
753
  entry.unbound = true;
667
754
  return;
@@ -948,6 +1035,7 @@ export class MultiNodeRouter {
948
1035
  digest: crossNodeDigest(JSON.stringify(frame)),
949
1036
  frame,
950
1037
  owed: true,
1038
+ ...offlineHost(owner.hostBrokerId),
951
1039
  });
952
1040
  if (enqueued.status === "invalid" || enqueued.status === "full") continue;
953
1041
  if (enqueued.status === "inserted" && owner.hostBrokerId !== undefined) {
@@ -1055,6 +1143,7 @@ export class MultiNodeRouter {
1055
1143
  digest: crossNodeDigest(JSON.stringify(frame)),
1056
1144
  frame,
1057
1145
  owed: true,
1146
+ ...offlineHost(hosted?.holderId),
1058
1147
  });
1059
1148
  // Not queued: the ask stays marked ended, so a later sweep tries again.
1060
1149
  if (enqueued.status === "full" || enqueued.status === "invalid") continue;
@@ -1974,7 +2063,13 @@ export class MultiNodeRouter {
1974
2063
  const { owner, frame } = decision;
1975
2064
  const digest = crossNodeDigest(request.signature);
1976
2065
  const enqueued = await this.state.outbox
1977
- .enqueue({ targetIdentity: owner.identity, originBrokerId: this.brokerId, digest, frame })
2066
+ .enqueue({
2067
+ targetIdentity: owner.identity,
2068
+ originBrokerId: this.brokerId,
2069
+ digest,
2070
+ frame,
2071
+ ...offlineHost(owner.hostBrokerId),
2072
+ })
1978
2073
  .catch((error: Error) => this.reopenAfter(decision, error));
1979
2074
  if (enqueued.status === "conflict") {
1980
2075
  await this.reopenQuestion(decision);
@@ -2253,7 +2348,7 @@ export class MultiNodeRouter {
2253
2348
  ? { questionRoute: { targetSessionId: target.sessionId, senderGroupIdentity: senderGroupIdentity(from) } }
2254
2349
  : {}),
2255
2350
  },
2256
- { targetIdentity: target.identity, originBrokerId: this.brokerId, digest, frame },
2351
+ { targetIdentity: target.identity, originBrokerId: this.brokerId, digest, frame, ...offlineHost(target.hostBrokerId) },
2257
2352
  );
2258
2353
  if (enqueued.status === "conflict") {
2259
2354
  this.failConflict(request);
@@ -183,6 +183,13 @@ export interface OutboxEnqueueRequest {
183
183
  * refusing it would leave the ask waiting forever.
184
184
  */
185
185
  readonly owed?: boolean;
186
+ /**
187
+ * #5607: the sender found the recipient offline. In the write that inserts the row, the broker holding the
188
+ * recipient's presence lease, renewed within this many milliseconds, is sent a wake-up hint for it (the database
189
+ * wake-up bus's `outbox` hint), so a recipient that registered elsewhere meanwhile gets the row at once. A store that
190
+ * ignores it wakes nobody; the backup poll still finds the row.
191
+ */
192
+ readonly wakeHostWithinMs?: number;
186
193
  }
187
194
 
188
195
  export interface OutboxRow {
@@ -227,7 +234,12 @@ export interface OutboxClaimRequest {
227
234
  }
228
235
 
229
236
  export type OutboxEnqueueResult =
230
- | { readonly status: "inserted"; readonly row: OutboxRow }
237
+ | {
238
+ readonly status: "inserted";
239
+ readonly row: OutboxRow;
240
+ /** #5607: with `wakeHostWithinMs`, the broker the write sent a wake-up hint for the row. */
241
+ readonly woke?: string;
242
+ }
231
243
  /** Same id and digest: no second row is written and the existing row reports its current state. */
232
244
  | { readonly status: "duplicate"; readonly row: OutboxRow }
233
245
  | { readonly status: "conflict"; readonly messageId: string }
@@ -833,6 +845,27 @@ export type KnownSessionBindResult =
833
845
  | { readonly status: "bound" }
834
846
  | { readonly status: "refused"; readonly returnAddress: string }
835
847
  | InvalidStateInput;
848
+ /** #5607: see `KnownSessionStore.reclaim`. */
849
+ export interface SessionIdReclaim {
850
+ readonly intercomSessionId: string;
851
+ readonly returnAddress: string;
852
+ /** The `claim` the registration's own `bind` was given. */
853
+ readonly claim: string;
854
+ readonly retentionMs: number;
855
+ /** The broker reclaiming; a presence lease it holds itself does not count. */
856
+ readonly brokerId: string;
857
+ /** A presence lease renewed within this many milliseconds is live. */
858
+ readonly presenceStaleAfterMs: number;
859
+ /** The id bound instead when the id is not kept. */
860
+ readonly freshId: string;
861
+ }
862
+
863
+ export type SessionIdReclaimResult =
864
+ | { readonly status: "kept" }
865
+ /** Not kept: `freshId` was bound as `bind` binds it, with its result. */
866
+ | { readonly status: "fresh"; readonly binding: KnownSessionBindResult }
867
+ | InvalidStateInput;
868
+
836
869
  export type KnownSessionBindingResult =
837
870
  | { readonly status: "bound"; readonly returnAddress: string }
838
871
  | { readonly status: "unbound" }
@@ -855,9 +888,22 @@ export interface KnownSessionStore {
855
888
  * gave none), unless another return address has held it within `retentionMs`, and reset the binding's age. In multi-node mode an id carries
856
889
  * authority: it is granted, and delivered to, only the session it is bound to. An id with no binding yet is bound
857
890
  * first to the return address its earliest known-session record has, so a record kept from before bindings existed
858
- * still holds it.
859
- */
860
- bind(intercomSessionId: string, returnAddress: string, retentionMs: number): Promise<KnownSessionBindResult>;
891
+ * still holds it. #5607: `claim`, a value unique to this registration, is recorded as the binding's latest claim
892
+ * when it binds, so `reclaim` can tell later whether the binding is still the one this registration wrote.
893
+ */
894
+ bind(
895
+ intercomSessionId: string,
896
+ returnAddress: string,
897
+ retentionMs: number,
898
+ claim?: string,
899
+ ): Promise<KnownSessionBindResult>;
900
+ /**
901
+ * #5607: the one write a returning registration makes when its `bind` did not answer in time. It keeps the id when
902
+ * the binding is still the one that `bind` wrote (same return address and claim, within `retentionMs`) and no other
903
+ * broker holds a live presence lease for a session of that return address, in any group, resetting the binding's age. Otherwise
904
+ * it binds `freshId` as `bind` does. Optional: without it such a registration gets a fresh id, bound as `bind` binds it.
905
+ */
906
+ reclaim?(request: SessionIdReclaim): Promise<SessionIdReclaimResult>;
861
907
  /** The return address the id is bound to, if a binding recorded within `retentionMs` holds it. */
862
908
  binding(intercomSessionId: string, retentionMs: number): Promise<KnownSessionBindingResult>;
863
909
  /** Delete records and bindings last recorded more than `olderThanMs` ago; returns the count of records. */
@@ -21,7 +21,7 @@ import { openSqlEndedChildQueueStore } from "./sql-ended-child-queue-store.js";
21
21
  import { openSqlHeldSendStore } from "./sql-held-send-store.js";
22
22
  import { openSqlKnownSessionStore } from "./sql-known-session-store.js";
23
23
  import { openSqlBrokerLeaseStore } from "./sql-lease-store.js";
24
- import { openSqlOutboxStore } from "./sql-outbox-store.js";
24
+ import { openSqlOutboxStore, withoutFailedWake } from "./sql-outbox-store.js";
25
25
  import { openSqlPendingAskStore } from "./sql-pending-ask-store.js";
26
26
  import { openSqlReleasedAskStore } from "./sql-released-ask-store.js";
27
27
  import { openSqlRestoringReservationStore } from "./sql-restoring-reservation-store.js";
@@ -158,11 +158,12 @@ export async function openIntercomBrokerState(
158
158
  sentMessages,
159
159
  knownSessions,
160
160
  reserveAndEnqueue(reservation, request) {
161
- return database.transaction(async (tx) => {
161
+ // #5607: written again, without it, when only an offline recipient's wake-up hint failed.
162
+ return withoutFailedWake(request, (attempt) => database.transaction(async (tx) => {
162
163
  const key = { messageId: reservation.messageId, digest: reservation.digest };
163
164
  const earlier = await sentMessages.lookupIn(tx, key);
164
165
  if (earlier.status === "conflict") return { status: "conflict", messageId: reservation.messageId } as const;
165
- const enqueued = await outbox.enqueueIn(tx, request);
166
+ const enqueued = await outbox.enqueueIn(tx, attempt);
166
167
  if (enqueued.status === "full") {
167
168
  // Refused before anything was written, so the transaction has no commit to sync.
168
169
  if (earlier.status === "match") await sentMessages.forgetIn(tx, key);
@@ -171,7 +172,7 @@ export async function openIntercomBrokerState(
171
172
  // Its answer is not needed: the outbox's unique message id is the authority for a row it holds (spec §5.5).
172
173
  await sentMessages.reserveIn(tx, reservation);
173
174
  return enqueued;
174
- });
175
+ }));
175
176
  },
176
177
  openEndedChildQueue(owner) {
177
178
  return openSqlEndedChildQueueStore(options, owner);
@@ -25,6 +25,7 @@ import {
25
25
  import { BROKER_READY_TIMEOUT_MS } from "./startup-timeout.js";
26
26
  import {
27
27
  BROKER_ANNOUNCE_PATH_ENV,
28
+ BROKER_ANNOUNCE_START_ENV,
28
29
  BROKER_ANNOUNCE_TOKEN_ENV,
29
30
  type BrokerStartAnnouncement,
30
31
  readBrokerStartAnnouncementAsync,
@@ -36,9 +37,11 @@ import {
36
37
  isIntercomBrokerStopTimeoutError,
37
38
  processSharedStorageSelection,
38
39
  processSharedStorageSelectionAsync,
40
+ readProcessCreationTime,
39
41
  takeTakeoverMutex,
40
42
  takeTakeoverMutexAsync,
41
43
  } from "@bastani/atomic";
44
+ import { hostCommandEnvironment } from "./host-command-environment.js";
42
45
  import { isBrokerStatusReport } from "./broker-status.js";
43
46
  import { BROKER_UPGRADE_STOP_TIMEOUT_MS, requestBrokerShutdown, waitForBrokerExit } from "./broker-stop.js";
44
47
  import { BROKER_CONTROL_TIMEOUT_MS, controlRequest } from "./control-request.js";
@@ -298,7 +301,8 @@ export function getBrokerLaunchSpec(
298
301
  *
299
302
  * The broker routes through the shared storage this process was launched with (`--storage`,
300
303
  * `--storage-file` or `ATOMIC_STORAGE`), passed as `ATOMIC_STORAGE`; without one it reads settings.
301
- * With `announcement` it also gets the file and token it announces its pid with (`start-announcement.ts`).
304
+ * With `announcement` it also gets the file and token it announces its pid with, and asks it to add when it was created
305
+ * (`start-announcement.ts`).
302
306
  */
303
307
  function buildBrokerSpawnOptions(
304
308
  storage: string | undefined,
@@ -321,7 +325,11 @@ function buildBrokerSpawnOptions(
321
325
  ...(storage === undefined ? {} : { [BROKER_STORAGE_ENV]: storage }),
322
326
  ...(announcement === undefined
323
327
  ? {}
324
- : { [BROKER_ANNOUNCE_PATH_ENV]: announcement.path, [BROKER_ANNOUNCE_TOKEN_ENV]: announcement.token }),
328
+ : {
329
+ [BROKER_ANNOUNCE_PATH_ENV]: announcement.path,
330
+ [BROKER_ANNOUNCE_TOKEN_ENV]: announcement.token,
331
+ [BROKER_ANNOUNCE_START_ENV]: "1",
332
+ }),
325
333
  }),
326
334
  windowsHide: true,
327
335
  };
@@ -641,7 +649,9 @@ async function spawnBrokerHoldingLock(
641
649
  // returns while that broker is writing its start-up files.
642
650
  waitForBroker(
643
651
  readyTimeoutMs,
644
- announcement === undefined ? undefined : () => readBrokerStartAnnouncementAsync(announcement),
652
+ announcement === undefined
653
+ ? undefined
654
+ : async () => (await readBrokerStartAnnouncementAsync(announcement))?.pid,
645
655
  cancelSignal,
646
656
  ).then(() => {
647
657
  cleanup();
@@ -651,14 +661,22 @@ async function spawnBrokerHoldingLock(
651
661
  const starting = launch.kind === "direct" && child.exitCode === null && child.signalCode === null;
652
662
  // #4727: the session that launched this broker is gone and the broker did not start in time; it is stopped
653
663
  // before this call returns, so it never writes into an agent directory its host may already be removing. Behind
654
- // the Windows launcher the broker is found by the pid it announced; one that never announced cannot be found.
655
- let abandonedPid: number | undefined;
664
+ // the Windows launcher the broker is found by the pid it announced; one that never announced cannot be found,
665
+ // and one that did not announce when it was created cannot be told apart from a later process given its pid
666
+ // (#6133), so neither is stopped.
667
+ let abandoned: StartingBroker | undefined;
656
668
  if (signal?.aborted) {
657
- if (launch.kind === "direct") abandonedPid = starting ? child.pid : undefined;
658
- else if (announcement !== undefined) abandonedPid = await readBrokerStartAnnouncementAsync(announcement);
669
+ if (launch.kind === "direct") {
670
+ if (starting && child.pid !== undefined) abandoned = { kind: "group", pid: child.pid };
671
+ } else if (announcement !== undefined) {
672
+ const announced = await readBrokerStartAnnouncementAsync(announcement);
673
+ if (announced?.started !== undefined) {
674
+ abandoned = { kind: "announced", pid: announced.pid, started: announced.started };
675
+ }
676
+ }
659
677
  }
660
- if (abandonedPid !== undefined) {
661
- void stopStartingBroker(abandonedPid).finally(() => reject(toError(error)));
678
+ if (abandoned !== undefined) {
679
+ void stopStartingBroker(abandoned).finally(() => reject(toError(error)));
662
680
  return;
663
681
  }
664
682
  // A broker still starting keeps the lock, so later spawners wait for it instead of starting another.
@@ -685,29 +703,130 @@ const STARTING_BROKER_KILL_WAIT_MS = 5_000;
685
703
  /** A killed process is gone within milliseconds, and a session that is closing waits for it. */
686
704
  const STARTING_BROKER_KILL_POLL_MS = 10;
687
705
 
706
+ /** A broker that has not started listening, as the spawner that launched it finds it. */
707
+ type StartingBroker =
708
+ /**
709
+ * Spawned directly and detached, so it leads a process group of its own. A custom broker command can run the broker
710
+ * as its own child rather than replacing itself with it; the group holds both. Its pid is read while the spawner's
711
+ * child has not been reaped, so it still names that child.
712
+ */
713
+ | { readonly kind: "group"; readonly pid: number }
714
+ /** Behind the Windows launcher: the pid the broker announced, and when that process was created. */
715
+ | { readonly kind: "announced"; readonly pid: number; readonly started: string };
716
+
717
+ /** How long the check and Windows PowerShell's start may take before the session stops waiting for the broker. */
718
+ const ANNOUNCED_BROKER_STOP_START_MS = 5_000;
719
+ /** Beyond the PowerShell's own bounds, how much longer the session waits for it to end. */
720
+ const ANNOUNCED_BROKER_STOP_MARGIN_MS = 1_000;
721
+
688
722
  /**
689
- * Kill a broker that has not started listening, with every process it started, and wait until they are gone. A custom
690
- * broker command can run the broker as its own child rather than replacing itself with it. Elsewhere than Windows the
691
- * broker was spawned detached, so it leads a process group of its own; on Windows `pid` is the broker's announced pid,
692
- * and `taskkill /T` ends its process tree.
723
+ * The PowerShell that stops the Windows broker `pid` created at `started` (#6133), with every process it started. Each
724
+ * process is ended only through a handle this PowerShell holds to it, opened before it is checked and kept until the
725
+ * PowerShell ends: Windows gives a pid to no other process while a handle to it is open, so a check made through the
726
+ * handle stays true for the process it ends. So a PowerShell that is itself ended part way leaves processes running,
727
+ * and never ends one that is not the broker's.
728
+ *
729
+ * The broker is the process whose creation time is `started`. Its processes are found from one `Win32_Process`
730
+ * snapshot by parent pid: a process counts as a child only if it was created no earlier than its parent (an older
731
+ * process naming that pid as its parent was started by an earlier holder of the pid), and only if the process its
732
+ * handle holds was created when the snapshot says (not a later process given the snapshot's pid). Without a snapshot it
733
+ * ends the broker alone. It waits up to `waitMs` for the broker to exit. A process it may not open, or one created at
734
+ * another time, is left alone.
693
735
  */
694
- async function stopStartingBroker(pid: number): Promise<void> {
695
- const deadline = Date.now() + STARTING_BROKER_KILL_WAIT_MS;
696
- if (process.platform === "win32") {
697
- await new Promise<void>((resolve) => {
698
- const taskkill = spawn("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
699
- taskkill.once("error", () => resolve());
700
- taskkill.once("exit", () => resolve());
701
- });
702
- while (isProcessAlive(pid) && Date.now() < deadline) await sleep(STARTING_BROKER_KILL_POLL_MS);
703
- return;
736
+ function stopAnnouncedBrokerScript(pid: number, started: string, waitMs: number): string {
737
+ return `$ErrorActionPreference = 'Stop'
738
+ function Hold([int]$id) {
739
+ try { $p = [System.Diagnostics.Process]::GetProcessById($id); $null = $p.Handle; $p } catch { $null }
740
+ }
741
+ function Created($p) {
742
+ try { $p.StartTime.ToFileTimeUtc() } catch { $null }
743
+ }
744
+ function Micros([datetime]$time) { $time.ToUniversalTime().ToString('yyyyMMddHHmmssffffff') }
745
+ $broker = Hold ${pid}
746
+ if ($null -eq $broker) { exit 3 }
747
+ $brokerCreated = Created $broker
748
+ if ($null -eq $brokerCreated -or $brokerCreated -ne [long]'${started}') { exit 3 }
749
+ $held = New-Object System.Collections.ArrayList
750
+ [void]$held.Add($broker)
751
+ $ids = New-Object 'System.Collections.Generic.HashSet[int]'
752
+ [void]$ids.Add($broker.Id)
753
+ $snapshot = @()
754
+ try { $snapshot = @(Get-CimInstance -ClassName Win32_Process -Property ProcessId, ParentProcessId, CreationDate) } catch { }
755
+ $level = @(, @($broker, $brokerCreated))
756
+ while ($level.Count -gt 0) {
757
+ $next = @()
758
+ foreach ($parent in $level) {
759
+ foreach ($entry in $snapshot) {
760
+ if ($entry.ParentProcessId -ne $parent[0].Id -or $ids.Contains([int]$entry.ProcessId) -or $null -eq $entry.CreationDate) { continue }
761
+ $child = Hold $entry.ProcessId
762
+ if ($null -eq $child) { continue }
763
+ $created = Created $child
764
+ if ($null -eq $created -or $created -lt $parent[1]) { continue }
765
+ if ((Micros $child.StartTime) -ne (Micros $entry.CreationDate)) { continue }
766
+ [void]$held.Add($child)
767
+ [void]$ids.Add($child.Id)
768
+ $next += , @($child, $created)
769
+ }
704
770
  }
771
+ $level = $next
772
+ }
773
+ foreach ($p in $held) { try { $p.Kill() } catch { } }
774
+ if ($broker.WaitForExit(${waitMs})) { exit 0 } else { exit 4 }
775
+ `;
776
+ }
777
+
778
+ /**
779
+ * Stop the Windows broker found by its announcement, as {@link stopAnnouncedBrokerScript} does. A pid that already names
780
+ * another process is left alone without starting PowerShell. The session waits at most
781
+ * {@link ANNOUNCED_BROKER_STOP_START_MS} for the check and PowerShell's start, {@link STARTING_BROKER_KILL_WAIT_MS} for
782
+ * the broker to exit, and {@link ANNOUNCED_BROKER_STOP_MARGIN_MS}. It never ends the PowerShell: once the session stops
783
+ * waiting, the PowerShell finishes on its own, or ends with this process, which can only leave processes running.
784
+ */
785
+ async function stopAnnouncedBroker(pid: number, started: string): Promise<void> {
786
+ const entered = performance.now();
787
+ const bound = ANNOUNCED_BROKER_STOP_START_MS + STARTING_BROKER_KILL_WAIT_MS + ANNOUNCED_BROKER_STOP_MARGIN_MS;
788
+ if ((await readProcessCreationTime(pid)) !== started) return;
789
+ if (performance.now() - entered >= ANNOUNCED_BROKER_STOP_START_MS) return;
790
+ const systemRoot = process.env.SystemRoot || process.env.windir || "C:\\Windows";
791
+ await new Promise<void>((resolve) => {
792
+ const powershell = spawn(
793
+ join(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"),
794
+ [
795
+ "-NoProfile",
796
+ "-NonInteractive",
797
+ "-EncodedCommand",
798
+ Buffer.from(stopAnnouncedBrokerScript(pid, started, STARTING_BROKER_KILL_WAIT_MS), "utf16le").toString("base64"),
799
+ ],
800
+ { cwd: systemRoot, env: hostCommandEnvironment(), stdio: "ignore", windowsHide: true },
801
+ );
802
+ powershell.unref();
803
+ const done = () => {
804
+ clearTimeout(timer);
805
+ resolve();
806
+ };
807
+ const timer = setTimeout(done, bound - (performance.now() - entered));
808
+ powershell.once("error", done);
809
+ powershell.once("exit", done);
810
+ });
811
+ }
812
+
813
+ /**
814
+ * Kill a broker that has not started listening, with every process it started, and wait until they are gone.
815
+ *
816
+ * #6133: on Windows the broker is found by the pid it announced, which Windows gives to another process within seconds
817
+ * once the broker has exited. It is stopped only through a handle to the process whose creation time is the one it
818
+ * announced ({@link stopAnnouncedBroker}), never by its pid alone; a pid that names another process, or a process this
819
+ * one may not open, counts as a broker that has already exited.
820
+ */
821
+ async function stopStartingBroker(broker: StartingBroker): Promise<void> {
822
+ if (broker.kind === "announced") return stopAnnouncedBroker(broker.pid, broker.started);
823
+ const deadline = Date.now() + STARTING_BROKER_KILL_WAIT_MS;
705
824
  try {
706
- process.kill(-pid, "SIGKILL");
825
+ process.kill(-broker.pid, "SIGKILL");
707
826
  } catch {
708
827
  return;
709
828
  }
710
- while (isProcessAlive(-pid) && Date.now() < deadline) await sleep(STARTING_BROKER_KILL_POLL_MS);
829
+ while (isProcessAlive(-broker.pid) && Date.now() < deadline) await sleep(STARTING_BROKER_KILL_POLL_MS);
711
830
  }
712
831
 
713
832
  /** How often a session waiting to upgrade the broker checks whether the spawn lock is free. */
@@ -9,6 +9,39 @@ function isDuplicateColumn(error: unknown): boolean {
9
9
  return /duplicate column|column .* already exists/i.test(text);
10
10
  }
11
11
 
12
+ /**
13
+ * A statement the database refused for a privilege the role lacks: the PostgreSQL adapter's `missing-privilege`, which
14
+ * the database facade reports as the cause of its `StorageUnavailableError`.
15
+ */
16
+ function isMissingPrivilege(error: unknown): boolean {
17
+ let at = error;
18
+ for (let depth = 0; depth < 4 && typeof at === "object" && at !== null; depth++) {
19
+ if ((at as { reason?: unknown }).reason === "missing-privilege") return true;
20
+ at = (at as { cause?: unknown }).cause;
21
+ }
22
+ return false;
23
+ }
24
+
25
+ /**
26
+ * `addMissingColumns` for one column a store can do without: whether the column is there. A role that may not change
27
+ * tables (a PostgreSQL runtime role with only DML privileges) leaves it out, and the store works as before it existed
28
+ * until `atomic storage migrate`, run as the owner role, adds it. Any other failure is thrown.
29
+ */
30
+ export async function addOptionalColumn(
31
+ database: SqliteDatabase,
32
+ table: string,
33
+ column: string,
34
+ definition: string,
35
+ ): Promise<boolean> {
36
+ try {
37
+ await addMissingColumns(database, table, { [column]: definition });
38
+ return true;
39
+ } catch (error) {
40
+ if (isMissingPrivilege(error)) return false;
41
+ throw error;
42
+ }
43
+ }
44
+
12
45
  /**
13
46
  * Adds each missing column of `columns` (name → definition after the name) to `table`, in order. A table from an older
14
47
  * broker gets the columns, and an older broker ignores them. Each column is probed and added in a serial transaction,