@bastani/atomic 0.10.10-alpha.2 → 0.10.11-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 (381) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/README.md +1 -1
  3. package/dist/_shared/dist-KOELCESV.js +2 -2
  4. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  5. package/dist/_shared/lib-4PES5P4V.js +2 -2
  6. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +8 -10
  7. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
  8. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +6 -6
  9. package/dist/_shared/mode-shared-2QJSCUM6.js +52 -15
  10. package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
  11. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  12. package/dist/_shared/runtime-O4KCSG4C.js +3 -3
  13. package/dist/_shared/{sdk-RRLVN7ER.js → sdk-AVFII7NK.js} +757 -233
  14. package/dist/_shared/sdk-AVFII7NK.js.map +1 -0
  15. package/dist/_shared/session-data-AHTU7IS6.js +3 -3
  16. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  17. package/dist/_shared/{startup-0-0-4VG2G44V.js → startup-0-0-57KF6LZH.js} +94 -42
  18. package/dist/_shared/startup-0-0-57KF6LZH.js.map +1 -0
  19. package/dist/_shared/{startup-0-1-XTIL65D4.js → startup-0-1-GIY75K46.js} +75 -13
  20. package/dist/_shared/startup-0-1-GIY75K46.js.map +1 -0
  21. package/dist/_shared/startup-0-2-27OWFHV6.js +72 -7
  22. package/dist/_shared/startup-0-2-27OWFHV6.js.map +1 -1
  23. package/dist/_shared/startup-0-3-T4DVFYWX.js +4 -4
  24. package/dist/_shared/startup-0-4-ZMJV547D.js +4 -4
  25. package/dist/_shared/{startup-0-5-FD2P735I.js → startup-0-5-YDW47QX6.js} +27 -69
  26. package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -0
  27. package/dist/_shared/startup-10-0-TDQNBDDL.js +6 -6
  28. package/dist/_shared/startup-12-0-55AAXBJZ.js +3 -3
  29. package/dist/_shared/startup-14-0-MLX36RBG.js +4 -4
  30. package/dist/_shared/startup-15-0-YUKGAC63.js +31 -7
  31. package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
  32. package/dist/_shared/startup-15-1-4S7FLMNG.js +7 -6
  33. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  34. package/dist/_shared/startup-8-0-34CBHPZH.js +4 -4
  35. package/dist/_shared/{startup-8-1-4KANEHRA.js → startup-8-1-X32CYSXB.js} +1219 -714
  36. package/dist/_shared/startup-8-1-X32CYSXB.js.map +1 -0
  37. package/dist/_shared/storage-command-7MGXLJGZ.js +14 -8
  38. package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
  39. package/dist/_shared/task-reference-stream-JWMUZSJX.js +1 -1
  40. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  41. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  42. package/dist/builtin/intercom/CHANGELOG.md +24 -0
  43. package/dist/builtin/intercom/broker/broker.bundle.mjs +993 -362
  44. package/dist/builtin/intercom/broker/database-wake-up-bus.ts +103 -24
  45. package/dist/builtin/intercom/broker/multinode-router.ts +42 -21
  46. package/dist/builtin/intercom/broker/multinode-state-store.ts +22 -1
  47. package/dist/builtin/intercom/broker/open-broker-state.ts +82 -31
  48. package/dist/builtin/intercom/broker/paths.ts +8 -4
  49. package/dist/builtin/intercom/broker/released-asker-remote-replies.ts +18 -6
  50. package/dist/builtin/intercom/broker/sql-add-column.ts +4 -1
  51. package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +65 -44
  52. package/dist/builtin/intercom/broker/sql-held-send-store.ts +11 -3
  53. package/dist/builtin/intercom/broker/sql-known-session-store.ts +24 -12
  54. package/dist/builtin/intercom/broker/sql-lease-store.ts +375 -65
  55. package/dist/builtin/intercom/broker/sql-outbox-store.ts +270 -101
  56. package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +20 -9
  57. package/dist/builtin/intercom/broker/sql-released-ask-store.ts +14 -6
  58. package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +27 -11
  59. package/dist/builtin/intercom/broker/sql-schema.ts +139 -1
  60. package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +97 -34
  61. package/dist/builtin/intercom/index.bundle.mjs +11 -8
  62. package/dist/builtin/intercom/package.json +1 -1
  63. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  64. package/dist/builtin/mcp/package.json +1 -1
  65. package/dist/builtin/subagents/CHANGELOG.md +20 -0
  66. package/dist/builtin/subagents/package.json +1 -1
  67. package/dist/builtin/subagents/skills/skill-creator/SKILL.md +1 -1
  68. package/dist/builtin/subagents/src/extension/index.bundle.mjs +62 -23
  69. package/dist/builtin/web-access/CHANGELOG.md +9 -0
  70. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  71. package/dist/builtin/web-access/package.json +1 -1
  72. package/dist/cli/args.js +2 -2
  73. package/dist/cli/auth-cli.code.js +4 -4
  74. package/dist/cli/auth-cli.impl.js +3 -3
  75. package/dist/cli/auth-cli.js +3 -3
  76. package/dist/cli/blueprint-command.code.js +3 -3
  77. package/dist/cli/blueprint-command.impl.js +3 -3
  78. package/dist/cli/blueprint-command.js +3 -3
  79. package/dist/cli/intercom-command.code.js +2 -2
  80. package/dist/cli/intercom-command.impl.js +3 -3
  81. package/dist/cli/intercom-command.js +3 -3
  82. package/dist/cli/list-models.code.js +2 -2
  83. package/dist/cli/list-models.impl.js +3 -3
  84. package/dist/cli/list-models.js +3 -3
  85. package/dist/cli/session-picker.code.js +1 -1
  86. package/dist/cli/session-picker.impl.js +3 -3
  87. package/dist/cli/session-picker.js +3 -3
  88. package/dist/cli/startup-ui.code.js +1 -1
  89. package/dist/cli/startup-ui.impl.js +3 -3
  90. package/dist/cli/startup-ui.js +3 -3
  91. package/dist/cli/storage-command.impl.js +3 -3
  92. package/dist/cli/storage-command.js +3 -3
  93. package/dist/cli/storage-search-session.code.js +3 -3
  94. package/dist/cli/storage-search-session.impl.js +3 -3
  95. package/dist/cli/storage-search-session.js +3 -3
  96. package/dist/cli/team-command.code.js +2 -2
  97. package/dist/cli/team-command.impl.js +3 -3
  98. package/dist/cli/team-command.js +3 -3
  99. package/dist/cli.js +2 -2
  100. package/dist/core/agent-session-methods.d.ts +3 -0
  101. package/dist/core/agent-session-methods.js.map +1 -1
  102. package/dist/core/agent-session.d.ts +1 -0
  103. package/dist/core/compaction/compactor.d.ts +2 -0
  104. package/dist/core/debug.impl.js +3 -3
  105. package/dist/core/debug.js +3 -3
  106. package/dist/core/export-html/card-projection.code.js +1 -1
  107. package/dist/core/export-html/card-projection.impl.js +3 -3
  108. package/dist/core/export-html/card-projection.js +3 -3
  109. package/dist/core/export-html/index.code.js +2 -2
  110. package/dist/core/export-html/index.impl.js +3 -3
  111. package/dist/core/export-html/index.js +3 -3
  112. package/dist/core/export-html/json-spans.impl.js +3 -3
  113. package/dist/core/export-html/json-spans.js +3 -3
  114. package/dist/core/export-html/oversized-render-inputs.code.js +1 -1
  115. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  116. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  117. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  118. package/dist/core/export-html/tool-renderer.js +3 -3
  119. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  120. package/dist/core/extensions/jiti-loader.js +3 -3
  121. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  122. package/dist/core/extensions/jiti-static-loader.js +3 -3
  123. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  124. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  125. package/dist/core/extensions/loader-host-modules.js +3 -3
  126. package/dist/core/extensions/loader-virtual-modules.js +2 -2
  127. package/dist/core/extensions/runner-context.js +3 -3
  128. package/dist/core/extensions/runner-context.js.map +1 -1
  129. package/dist/core/intercom-broker-control-host.code.js +1 -1
  130. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  131. package/dist/core/intercom-broker-control-host.js +3 -3
  132. package/dist/core/intercom-broker-control.code.js +3 -3
  133. package/dist/core/intercom-broker-control.impl.js +3 -3
  134. package/dist/core/intercom-broker-control.js +3 -3
  135. package/dist/core/model-registry.js +1 -1
  136. package/dist/core/model-resolver-defaults.d.ts +3 -2
  137. package/dist/core/package-manager-storage-adapters.code.js +1 -1
  138. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  139. package/dist/core/package-manager-storage-adapters.js +3 -3
  140. package/dist/core/sdk.code.js +3 -4
  141. package/dist/core/sdk.impl.js +3 -3
  142. package/dist/core/sdk.js +3 -3
  143. package/dist/core/session-manager-core.d.ts +5 -2
  144. package/dist/core/session-manager-core.js +17 -13
  145. package/dist/core/session-manager-core.js.map +1 -1
  146. package/dist/core/session-manager-list.impl.js +3 -3
  147. package/dist/core/session-manager-list.js +3 -3
  148. package/dist/core/session-manager.code.js +1 -1
  149. package/dist/core/session-manager.impl.js +3 -3
  150. package/dist/core/session-manager.js +3 -3
  151. package/dist/core/session-storage.code.js +1 -1
  152. package/dist/core/session-storage.impl.js +3 -3
  153. package/dist/core/session-storage.js +3 -3
  154. package/dist/core/storage/added-exports.d.ts +6 -0
  155. package/dist/core/storage/added-exports.js +16 -0
  156. package/dist/core/storage/added-exports.js.map +1 -0
  157. package/dist/core/storage/database.d.ts +16 -0
  158. package/dist/core/storage/database.js.map +1 -1
  159. package/dist/core/storage/fenced-paths.d.ts +47 -0
  160. package/dist/core/storage/fenced-paths.js +53 -0
  161. package/dist/core/storage/fenced-paths.js.map +1 -1
  162. package/dist/core/storage/file-identity.js +31 -2
  163. package/dist/core/storage/file-identity.js.map +1 -1
  164. package/dist/core/storage/index.d.ts +3 -0
  165. package/dist/core/storage/index.js +5 -2
  166. package/dist/core/storage/index.js.map +1 -1
  167. package/dist/core/storage/migrations.d.ts +22 -0
  168. package/dist/core/storage/migrations.js +55 -0
  169. package/dist/core/storage/migrations.js.map +1 -1
  170. package/dist/core/storage/node-sqlite-thread.js +19 -6
  171. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  172. package/dist/core/storage/node-sqlite.js +53 -4
  173. package/dist/core/storage/node-sqlite.js.map +1 -1
  174. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  175. package/dist/core/storage/offline-snapshot-file.js +3 -3
  176. package/dist/core/storage/prefix.d.ts +3 -2
  177. package/dist/core/storage/prefix.js +18 -2
  178. package/dist/core/storage/prefix.js.map +1 -1
  179. package/dist/core/storage/provider.js +2 -2
  180. package/dist/core/storage/schema-catalog.d.ts +42 -0
  181. package/dist/core/storage/schema-catalog.js +141 -0
  182. package/dist/core/storage/schema-catalog.js.map +1 -0
  183. package/dist/core/storage/selection.js +2 -2
  184. package/dist/core/storage/session/branch-fork-source.code.js +41 -20
  185. package/dist/core/storage/session/branch-fork-source.code.js.map +1 -1
  186. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  187. package/dist/core/storage/session/branch-fork-source.js +3 -3
  188. package/dist/core/storage/session/card-view.impl.js +3 -3
  189. package/dist/core/storage/session/card-view.js +3 -3
  190. package/dist/core/storage/session/child-reader.code.js +3 -3
  191. package/dist/core/storage/session/child-reader.impl.js +3 -3
  192. package/dist/core/storage/session/child-reader.js +3 -3
  193. package/dist/core/storage/session/chunked-resume-projection.code.js +1 -1
  194. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  195. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  196. package/dist/core/storage/session/expanded-child-details.code.js +3 -3
  197. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  198. package/dist/core/storage/session/expanded-child-details.js +3 -3
  199. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  200. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  201. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  202. package/dist/core/storage/session/fork-row-index.js +3 -3
  203. package/dist/core/storage/session/fork-staging.code.js +176 -36
  204. package/dist/core/storage/session/fork-staging.code.js.map +1 -1
  205. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  206. package/dist/core/storage/session/fork-staging.js +3 -3
  207. package/dist/core/storage/session/fork-window.code.js +3 -3
  208. package/dist/core/storage/session/fork-window.impl.js +3 -3
  209. package/dist/core/storage/session/fork-window.js +3 -3
  210. package/dist/core/storage/session/history-pages.impl.js +3 -3
  211. package/dist/core/storage/session/history-pages.js +3 -3
  212. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  213. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  214. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  215. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  216. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  217. package/dist/core/storage/session/memory-session-store.js +3 -3
  218. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  219. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  220. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  221. package/dist/core/storage/session/released-history-files.code.js +2 -2
  222. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  223. package/dist/core/storage/session/released-history-files.js +3 -3
  224. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  225. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  226. package/dist/core/storage/session/session-resume.impl.js +3 -3
  227. package/dist/core/storage/session/session-resume.js +3 -3
  228. package/dist/core/storage/session/session-search-index.d.ts +5 -0
  229. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  230. package/dist/core/storage/session/snapshot-cut.js +3 -3
  231. package/dist/core/storage/session/snapshot-history.code.js +3 -3
  232. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  233. package/dist/core/storage/session/snapshot-history.js +3 -3
  234. package/dist/core/storage/session/sql-chat-records.d.ts +15 -0
  235. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  236. package/dist/core/storage/session/sql-session-store.d.ts +102 -5
  237. package/dist/core/storage/session/sql-session-store.impl.js +4 -4
  238. package/dist/core/storage/session/sql-session-store.js +4 -4
  239. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  240. package/dist/core/storage/session/tree-outline.js +3 -3
  241. package/dist/core/storage/session/tree-presentation.code.js +1 -1
  242. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  243. package/dist/core/storage/session/tree-presentation.js +3 -3
  244. package/dist/core/storage/session/types.d.ts +14 -0
  245. package/dist/core/storage/sqlite-facade.d.ts +37 -5
  246. package/dist/core/storage/sqlite-facade.js +351 -18
  247. package/dist/core/storage/sqlite-facade.js.map +1 -1
  248. package/dist/core/storage/statement-sequence.d.ts +83 -0
  249. package/dist/core/storage/statement-sequence.js +21 -0
  250. package/dist/core/storage/statement-sequence.js.map +1 -1
  251. package/dist/core/storage/storage-status.code.js +1 -1
  252. package/dist/core/storage/storage-status.impl.js +3 -3
  253. package/dist/core/storage/storage-status.js +3 -3
  254. package/dist/core/storage/team.code.js +1 -1
  255. package/dist/core/storage/team.impl.js +3 -3
  256. package/dist/core/storage/team.js +3 -3
  257. package/dist/core/structured-output/index.code.js +1 -1
  258. package/dist/core/structured-output/index.impl.js +3 -3
  259. package/dist/core/structured-output/index.js +3 -3
  260. package/dist/core/tasks/task-completion-entry.code.js +1 -1
  261. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  262. package/dist/core/tasks/task-completion-entry.js +3 -3
  263. package/dist/core/tasks/task-file-history.code.js +3 -3
  264. package/dist/core/tasks/task-file-history.impl.js +3 -3
  265. package/dist/core/tasks/task-file-history.js +3 -3
  266. package/dist/core/tasks/task-reference-archive.code.js +4 -4
  267. package/dist/core/tasks/task-reference-archive.js +3 -3
  268. package/dist/core/tasks/task-reference-identity.js +3 -3
  269. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  270. package/dist/core/tasks/task-reference-stream.js +3 -3
  271. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  272. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  273. package/dist/core/tasks/task-view-source.code.js +1 -1
  274. package/dist/core/tasks/task-view-source.impl.js +3 -3
  275. package/dist/core/tasks/task-view-source.js +3 -3
  276. package/dist/core/tools/bash.d.ts +8 -4
  277. package/dist/core/tools/history-session.d.ts +5 -0
  278. package/dist/core/tools/history-tasks.d.ts +123 -0
  279. package/dist/core/tools/kill.d.ts +5 -2
  280. package/dist/core/tools/powershell.d.ts +2 -2
  281. package/dist/core/tools/read-url.code.js +3 -3
  282. package/dist/core/tools/read-url.impl.js +3 -3
  283. package/dist/core/tools/read-url.js +3 -3
  284. package/dist/core/tools/read.d.ts +12 -2
  285. package/dist/core/tools/resource-selectors.d.ts +2 -0
  286. package/dist/core/tools/search.d.ts +12 -2
  287. package/dist/core/worktree-snapshot/blob-store.d.ts +14 -2
  288. package/dist/core/worktree-snapshot/blob-store.js +69 -16
  289. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  290. package/dist/core/worktree-snapshot/errors.code.js +2 -2
  291. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  292. package/dist/core/worktree-snapshot/errors.js +3 -3
  293. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  294. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  295. package/dist/extensions/codemode/execute.code.js +2 -2
  296. package/dist/extensions/codemode/execute.impl.js +3 -3
  297. package/dist/extensions/codemode/execute.js +3 -3
  298. package/dist/extensions/codemode/renderer.code.js +2 -2
  299. package/dist/extensions/codemode/renderer.impl.js +3 -3
  300. package/dist/extensions/codemode/renderer.js +3 -3
  301. package/dist/extensions/mcp/cli.code.js +3 -3
  302. package/dist/extensions/mcp/cli.impl.js +3 -3
  303. package/dist/extensions/mcp/cli.js +3 -3
  304. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  305. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  306. package/dist/extensions/mcp/cli.lazy.js +3 -3
  307. package/dist/extensions/mcp/runtime.code.js +1 -1
  308. package/dist/extensions/mcp/runtime.impl.js +3 -3
  309. package/dist/extensions/mcp/runtime.js +3 -3
  310. package/dist/index.js +5 -5
  311. package/dist/main-first-time-setup.code.js +1 -1
  312. package/dist/main-first-time-setup.impl.js +3 -3
  313. package/dist/main-first-time-setup.js +3 -3
  314. package/dist/main.js +1 -1
  315. package/dist/modes/interactive/components/agent-panel.d.ts +1 -0
  316. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  317. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  318. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  319. package/dist/modes/interactive/components/task-inspector.d.ts +2 -0
  320. package/dist/modes/interactive/components/user-message-selector-archive.code.js +1 -1
  321. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  322. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  323. package/dist/modes/interactive/interactive-mode-helpers.d.ts +2 -2
  324. package/dist/modes/print-mode.js +1 -1
  325. package/dist/modes/rpc/agent-panel-bridge.d.ts +5 -0
  326. package/dist/package-manager-cli.code.js +6 -6
  327. package/dist/package-manager-cli.impl.js +3 -3
  328. package/dist/package-manager-cli.js +3 -3
  329. package/dist/rpc-entry.js +1 -1
  330. package/dist/startup-files.json +1 -1
  331. package/dist/startup-stages/0.js +1 -1
  332. package/dist/startup-stages/1.js +1 -1
  333. package/dist/startup-stages/10.js +1 -1
  334. package/dist/startup-stages/12.js +1 -1
  335. package/dist/startup-stages/2.js +8 -1
  336. package/dist/startup-stages/3.js +1 -6
  337. package/dist/startup-stages/5.js +1 -1
  338. package/dist/startup-stages/7.js +1 -5
  339. package/dist/utils/startup-database-spare.code.js +2 -2
  340. package/dist/utils/startup-database-spare.impl.js +3 -3
  341. package/dist/utils/startup-database-spare.js +3 -3
  342. package/dist/utils/tools-manager.code.js +1 -1
  343. package/dist/utils/tools-manager.impl.js +3 -3
  344. package/dist/utils/tools-manager.js +3 -3
  345. package/docs/background-tasks.md +123 -23
  346. package/docs/compaction.md +18 -0
  347. package/docs/docs.json +2 -0
  348. package/docs/environment-variables.md +1 -1
  349. package/docs/getting-started/installation.md +9 -2
  350. package/docs/guides/postgres-pgbouncer.md +339 -0
  351. package/docs/guides/postgres-tuning.md +311 -0
  352. package/docs/guides/resume-on-any-machine.md +2 -2
  353. package/docs/guides.md +2 -0
  354. package/docs/index.md +1 -1
  355. package/docs/libraries/agent-core.md +1 -1
  356. package/docs/libraries/ai.md +2 -2
  357. package/docs/libraries/codemode.md +1 -1
  358. package/docs/libraries/storage-libsql.md +6 -1
  359. package/docs/libraries/storage-postgres.md +11 -6
  360. package/docs/libraries/tui.md +1 -1
  361. package/docs/libraries.md +2 -2
  362. package/docs/programmatic.md +1 -1
  363. package/docs/quickstart.md +1 -1
  364. package/docs/sdk/storage.md +1 -1
  365. package/docs/sdk/web-server.md +1 -3
  366. package/docs/sdk.md +1 -7
  367. package/docs/sessions.md +58 -2
  368. package/docs/settings.md +20 -1
  369. package/docs/skills/authoring.md +1 -1
  370. package/docs/skills.md +79 -6
  371. package/docs/storage.md +262 -12
  372. package/docs/subagents/reference.md +2 -2
  373. package/docs/subagents.md +4 -3
  374. package/docs/tools.md +44 -10
  375. package/docs/windows.md +1 -1
  376. package/package.json +9 -9
  377. package/dist/_shared/sdk-RRLVN7ER.js.map +0 -1
  378. package/dist/_shared/startup-0-0-4VG2G44V.js.map +0 -1
  379. package/dist/_shared/startup-0-1-XTIL65D4.js.map +0 -1
  380. package/dist/_shared/startup-0-5-FD2P735I.js.map +0 -1
  381. package/dist/_shared/startup-8-1-4KANEHRA.js.map +0 -1
@@ -17,7 +17,7 @@ import type {
17
17
  ReleasedAskSupersede,
18
18
  StateStoreInvalidReason,
19
19
  } from "./multinode-state-store.js";
20
- import { ensureBrokerSchema } from "./sql-schema.js";
20
+ import { ensureBrokerSchema, withBrokerSchemaCatalog } from "./sql-schema.js";
21
21
 
22
22
  interface ReleasedAskRow extends SqliteRow {
23
23
  readonly question_id: string;
@@ -69,9 +69,17 @@ function toRecord(row: ReleasedAskRow): ReleasedAskRecord {
69
69
  }
70
70
 
71
71
  /** S3 (#4386): `ReleasedAskStore` on the shared storage adapter's database, table `<prefix>intercom_released_asks`. */
72
- export async function openSqlReleasedAskStore({ database, prefix }: IntercomBrokerStateOptions): Promise<ReleasedAskStore> {
72
+ export function openSqlReleasedAskStore(options: IntercomBrokerStateOptions): Promise<ReleasedAskStore> {
73
+ // Its schema checks answer from one read of the catalog, shared with an open around it: a current schema costs
74
+ // no transaction and no lock, also when the store is opened on its own (#6560).
75
+ return withBrokerSchemaCatalog(options.database, options.prefix, () => openReleasedAskStoreInCatalog(options));
76
+ }
77
+
78
+ async function openReleasedAskStoreInCatalog({ database, prefix }: IntercomBrokerStateOptions): Promise<ReleasedAskStore> {
73
79
  const table = `${validateStoragePrefix(prefix, dialectOf(database).name)}intercom_released_asks`;
74
80
  const { types, nowMs, greatest } = dialectOf(database);
81
+ /** Its transactions read and write this table alone, so they exclude one another, not every writer (#6560). */
82
+ const serial = { concurrency: { kind: "serial", domain: table } } as const;
75
83
  await ensureBrokerSchema(database, prefix, "released-asks", (tx) =>
76
84
  tx.exec(`
77
85
  CREATE TABLE IF NOT EXISTS ${table}(
@@ -124,7 +132,7 @@ export async function openSqlReleasedAskStore({ database, prefix }: IntercomBrok
124
132
  inserted += changes;
125
133
  }
126
134
  return inserted;
127
- });
135
+ }, serial);
128
136
  return { status: "kept", kept };
129
137
  },
130
138
  async lookup(key) {
@@ -153,7 +161,7 @@ export async function openSqlReleasedAskStore({ database, prefix }: IntercomBrok
153
161
  return { status: row.reply_message_id === claim.replyMessageId ? "claimed" : "taken", ask: toRecord(row) } as const;
154
162
  }
155
163
  return claimFor(tx, claim, row);
156
- });
164
+ }, serial);
157
165
  },
158
166
  async supersede(claim) {
159
167
  const bad = invalidReleasedAskSupersede(claim);
@@ -169,7 +177,7 @@ export async function openSqlReleasedAskStore({ database, prefix }: IntercomBrok
169
177
  return { status: row.reply_message_id === claim.replyMessageId ? "claimed" : "taken", ask: toRecord(row) } as const;
170
178
  }
171
179
  return claimFor(tx, claim, row);
172
- });
180
+ }, serial);
173
181
  },
174
182
  async answer(claim) {
175
183
  const bad = invalidReleasedAskClaim(claim);
@@ -216,6 +224,6 @@ export async function openSqlReleasedAskStore({ database, prefix }: IntercomBrok
216
224
  claim.replierSessionId,
217
225
  );
218
226
  return { status: "settled" } as const;
219
- });
227
+ }, serial);
220
228
  }
221
229
  }
@@ -27,7 +27,7 @@ import type {
27
27
  import { reservationAdmitsSender } from "./group-membership.js";
28
28
  import { isReleasedReservationKey } from "./released-children.js";
29
29
  import { addMissingColumns } from "./sql-add-column.js";
30
- import { ensureBrokerSchema } from "./sql-schema.js";
30
+ import { ensureBrokerSchema, openCatalogOf, withBrokerSchemaCatalog } from "./sql-schema.js";
31
31
 
32
32
  type ReservationRow = SqliteRow & {
33
33
  reservation_key: string;
@@ -123,7 +123,13 @@ async function renameWakeIndex(tx: SqliteExecutor, dialect: StorageDialect, tabl
123
123
  * `<prefix>intercom_restoring_reservations`. Insertion order and fencing tokens come from
124
124
  * `<prefix>intercom_restoring_reservation_counters`, so both keep increasing after `prune` deletes rows.
125
125
  */
126
- export async function openSqlRestoringReservationStore({
126
+ export function openSqlRestoringReservationStore(options: IntercomBrokerStateOptions): Promise<RestoringReservationStore> {
127
+ // Its schema checks answer from one read of the catalog, shared with an open around it: a current schema costs
128
+ // no transaction and no lock, also when the store is opened on its own (#6560).
129
+ return withBrokerSchemaCatalog(options.database, options.prefix, () => openRestoringReservationStoreInCatalog(options));
130
+ }
131
+
132
+ async function openRestoringReservationStoreInCatalog({
127
133
  database,
128
134
  prefix,
129
135
  }: IntercomBrokerStateOptions): Promise<RestoringReservationStore> {
@@ -132,6 +138,11 @@ export async function openSqlRestoringReservationStore({
132
138
  const counters = `${validPrefix}intercom_restoring_reservation_counters`;
133
139
  const wakeClaims = `${validPrefix}intercom_restoring_wake_claims`;
134
140
  const { types, nowMs, greatest } = dialectOf(database);
141
+ /**
142
+ * Its transactions read and write this table, its counters and its wake claims alone, which no other store
143
+ * touches, so they exclude one another, not every writer of the database (#6560).
144
+ */
145
+ const serial = { concurrency: { kind: "serial", domain: table } } as const;
135
146
  await ensureBrokerSchema(database, prefix, "restoring-reservations", (tx) =>
136
147
  tx.exec(`
137
148
  CREATE TABLE IF NOT EXISTS ${table}(
@@ -172,8 +183,13 @@ export async function openSqlRestoringReservationStore({
172
183
  await ensureBrokerSchema(database, prefix, "restoring-reservation-indexes", (tx) =>
173
184
  tx.exec(`CREATE INDEX IF NOT EXISTS ${table}_child ON ${table}(child_target) WHERE end_json IS NULL`),
174
185
  );
175
- // Probed every time, as an earlier broker may recreate its index meanwhile; a current one runs no DDL (#5218).
176
- await database.transaction((tx) => renameWakeIndex(tx, dialectOf(database), table));
186
+ // Probed every time, as an earlier broker may recreate its index meanwhile; a current one runs no DDL (#5218). The
187
+ // catalog an open read answers that probe, so a current index costs no transaction (#6560).
188
+ const catalog = await openCatalogOf(database);
189
+ const wakeIndexCurrent =
190
+ catalog?.hasObject(`${table}_wake`) === true &&
191
+ !catalog.hasObject(`${table}_wake_requested`.slice(0, dialectOf(database).name === "postgres" ? 63 : undefined));
192
+ if (!wakeIndexCurrent) await database.transaction((tx) => renameWakeIndex(tx, dialectOf(database), table));
177
193
  const columns = `reservation_key, owner_session_id, owner_broker_id, child_name AS child_name_json, child_target,
178
194
  targets_json, "group" AS reservation_group, dormant, wake, wake_generation, fencing_token, "order" AS reservation_order,
179
195
  gone AS gone_json, end_json,
@@ -316,7 +332,7 @@ export async function openSqlRestoringReservationStore({
316
332
  },
317
333
  superseded,
318
334
  };
319
- });
335
+ }, serial);
320
336
  },
321
337
  async lookup(target, sender, staleAfterMs): Promise<RestoringReservationLookupResult> {
322
338
  if (target.length === 0) return invalid("empty-target");
@@ -353,7 +369,7 @@ export async function openSqlRestoringReservationStore({
353
369
  reservationKey,
354
370
  );
355
371
  return { status: changes > 0 ? "requested" : "not-wakeable" };
356
- });
372
+ }, serial);
357
373
  },
358
374
  async takeWakeRequests(ownerBrokerId): Promise<RestoringReservationTakeWakeResult> {
359
375
  if (ownerBrokerId.length === 0) return invalid("empty-broker-id");
@@ -374,7 +390,7 @@ export async function openSqlRestoringReservationStore({
374
390
  childName: JSON.parse(row.child_name_json) as string,
375
391
  })),
376
392
  };
377
- });
393
+ }, serial);
378
394
  },
379
395
  async renew(lease): Promise<RestoringReservationRenewResult> {
380
396
  const bad = invalidLease(lease);
@@ -387,7 +403,7 @@ export async function openSqlRestoringReservationStore({
387
403
  lease.reservationKey,
388
404
  );
389
405
  return { status: "renewed" };
390
- });
406
+ }, serial);
391
407
  },
392
408
  async release(lease, outcome): Promise<RestoringReservationReleaseResult> {
393
409
  const bad = invalidLease(lease);
@@ -411,7 +427,7 @@ export async function openSqlRestoringReservationStore({
411
427
  : { outcome: "released", refusal: outcome.refusal },
412
428
  );
413
429
  return { status: "released" };
414
- });
430
+ }, serial);
415
431
  },
416
432
  async consume(reservationKey, registered): Promise<RestoringReservationConsumeResult> {
417
433
  if (reservationKey.length === 0) return invalid("empty-reservation-key");
@@ -435,7 +451,7 @@ export async function openSqlRestoringReservationStore({
435
451
  ended.push(row.reservation_key);
436
452
  }
437
453
  return { status: "consumed", reservationKeys: ended };
438
- });
454
+ }, serial);
439
455
  },
440
456
  async insertionMark(): Promise<number> {
441
457
  const row = await database.get<SqliteRow & { value: number }>(
@@ -458,7 +474,7 @@ export async function openSqlRestoringReservationStore({
458
474
  );
459
475
  await tx.run(`DELETE FROM ${wakeClaims} WHERE reservation_key NOT IN (SELECT reservation_key FROM ${table})`);
460
476
  return changes;
461
- });
477
+ }, serial);
462
478
  },
463
479
  };
464
480
  }
@@ -1,9 +1,36 @@
1
+ import * as storage from "@bastani/atomic/storage";
1
2
  import { dialectOf, ensureStorageSchema, type SqliteDatabase, type SqliteExecutor, storageMigrationTable } from "@bastani/atomic/storage";
2
3
 
4
+ /**
5
+ * `storageSchemaCurrent`, `schemaCatalogOf` and `withStorageSchemaCatalog` of the storage API, which an Atomic
6
+ * installation older than #6560 lacks: a named import would fail to link there, so they are taken from the module
7
+ * namespace, and without them every open checks its schema in a transaction, as before.
8
+ */
9
+ const catalogApi: Partial<
10
+ Pick<typeof storage, "storageSchemaCurrent" | "schemaCatalogOf" | "withStorageSchemaCatalog">
11
+ > = storage;
12
+
13
+ /**
14
+ * Runs `open`, a broker store's open on `database`, with one read of the prefix's schema catalog, which its schema
15
+ * checks answer from: a store whose schema is current opens with no schema transaction and no lock, whether the broker
16
+ * opens it with the others (`openIntercomBrokerState`, whose read it shares), on its own, or later, as the ended-child
17
+ * queue of a new home (#6560). `views` are other handles on the same connection whose checks answer from the read.
18
+ */
19
+ export async function withBrokerSchemaCatalog<T>(
20
+ database: SqliteDatabase,
21
+ prefix: string | undefined,
22
+ open: () => Promise<T>,
23
+ views: readonly SqliteDatabase[] = [],
24
+ ): Promise<T> {
25
+ const withCatalog = catalogApi.withStorageSchemaCatalog;
26
+ return withCatalog === undefined ? open() : withCatalog(database, storageMigrationTable(prefix), open, views);
27
+ }
28
+
3
29
  /**
4
30
  * Runs `setup`, a broker store's idempotent schema statements, in a transaction of its own, unless the prefix's ledger
5
31
  * records `revision` for `store` already (#5218): on PostgreSQL a current schema runs no DDL, so a role with only DML
6
- * privileges opens the store. Raise `revision` whenever `setup` creates or alters anything new.
32
+ * privileges opens the store. Raise `revision` whenever `setup` creates or alters anything new. Inside an open that read
33
+ * the catalog (`withStorageSchemaCatalog`), a revision it found recorded skips the transaction too (#6560).
7
34
  */
8
35
  export async function ensureBrokerSchema(
9
36
  database: SqliteDatabase,
@@ -13,9 +40,120 @@ export async function ensureBrokerSchema(
13
40
  revision = 1,
14
41
  ): Promise<void> {
15
42
  const schema = { ledger: storageMigrationTable(prefix), domain: `intercom-${store}`, revision };
43
+ if (await catalogApi.storageSchemaCurrent?.(database, schema)) return;
44
+ if (await createsNothingNew(database, setup)) return;
16
45
  await database.transaction((tx) =>
17
46
  ensureStorageSchema(tx, dialectOf(database), schema, async () => {
18
47
  await setup(tx);
19
48
  }),
20
49
  );
21
50
  }
51
+
52
+ /**
53
+ * Whether `setup` would change nothing on a SQLite or libSQL database: where it only runs `CREATE TABLE` and
54
+ * `CREATE INDEX` statements with `IF NOT EXISTS`, and the catalog an open in progress read found each object, as a
55
+ * table or an index as the statement names it. SQLite records no versions, so such a setup ran at every open in a
56
+ * write transaction of its own, which took the database's write lock and, on a server, three round trips (#6560).
57
+ * Statements on an existing object of that kind do nothing, so skipping them is the same. The setup runs against a
58
+ * handle that only collects the SQL it would run; any other call, or a statement of another form, and it runs as
59
+ * before. False outside such an open, and on PostgreSQL, whose ledger decides.
60
+ */
61
+ async function createsNothingNew(
62
+ database: SqliteDatabase,
63
+ setup: (tx: SqliteExecutor) => Promise<unknown>,
64
+ ): Promise<boolean> {
65
+ if (dialectOf(database).versionedMigrations) return false;
66
+ const typeOf = (await openCatalogOf(database))?.sqliteObjectType;
67
+ if (typeOf === undefined) return false;
68
+ const scripts: string[] = [];
69
+ let other = false;
70
+ const refuse = () => {
71
+ other = true;
72
+ return Promise.reject(new Error("not a schema statement"));
73
+ };
74
+ const collecting: SqliteExecutor = {
75
+ exec: (sql) => {
76
+ scripts.push(sql);
77
+ return Promise.resolve();
78
+ },
79
+ run: refuse,
80
+ get: refuse,
81
+ all: refuse,
82
+ };
83
+ try {
84
+ await setup(collecting);
85
+ } catch {
86
+ return false;
87
+ }
88
+ if (other) return false;
89
+ for (const script of scripts) {
90
+ const statements = splitStatements(script);
91
+ if (statements === undefined) return false;
92
+ for (const statement of statements) {
93
+ const created = CREATE_IF_NOT_EXISTS.exec(statement);
94
+ if (created === null) return false;
95
+ const name = created[3] ?? created[4]!;
96
+ if (typeOf(name) !== created[2]!.toLowerCase()) return false;
97
+ }
98
+ }
99
+ return true;
100
+ }
101
+
102
+ /** `CREATE [UNIQUE] TABLE|INDEX IF NOT EXISTS <name>`, the name plain or double-quoted and never schema-qualified. */
103
+ const CREATE_IF_NOT_EXISTS =
104
+ /^CREATE\s+(UNIQUE\s+)?(TABLE|INDEX)\s+IF\s+NOT\s+EXISTS\s+(?:"([^"]+)"|([A-Za-z_][A-Za-z0-9_]*))(?![A-Za-z0-9_$."])/i;
105
+
106
+ /**
107
+ * The statements of `script`, each trimmed, split at the semicolons outside quotes, brackets, parentheses and comments;
108
+ * undefined when a quote or comment does not end, or a statement starts with a comment.
109
+ */
110
+ function splitStatements(script: string): string[] | undefined {
111
+ const statements: string[] = [];
112
+ let start = 0;
113
+ let depth = 0;
114
+ for (let at = 0; at < script.length; at++) {
115
+ const char = script[at]!;
116
+ const close = char === "'" || char === '"' || char === "`" ? char : char === "[" ? "]" : undefined;
117
+ if (close !== undefined) {
118
+ const end = script.indexOf(close, at + 1);
119
+ if (end < 0) return undefined;
120
+ at = end;
121
+ } else if (char === "-" && script[at + 1] === "-") {
122
+ const end = script.indexOf("\n", at);
123
+ at = end < 0 ? script.length : end;
124
+ } else if (char === "/" && script[at + 1] === "*") {
125
+ const end = script.indexOf("*/", at + 2);
126
+ if (end < 0) return undefined;
127
+ at = end + 1;
128
+ } else if (char === "(") depth++;
129
+ else if (char === ")") depth--;
130
+ else if (char === ";" && depth === 0) {
131
+ statements.push(script.slice(start, at));
132
+ start = at + 1;
133
+ }
134
+ }
135
+ statements.push(script.slice(start));
136
+ const trimmed = statements.map((statement) => statement.trim()).filter((statement) => statement.length > 0);
137
+ return trimmed.some((statement) => statement.startsWith("--") || statement.startsWith("/*")) ? undefined : trimmed;
138
+ }
139
+
140
+ /**
141
+ * Whether the catalog an open in progress read found `table` with every one of `columns`, so adding them would change
142
+ * nothing (#6560). False outside such an open.
143
+ */
144
+ export async function catalogHasColumns(
145
+ database: SqliteDatabase,
146
+ table: string,
147
+ columns: readonly string[],
148
+ ): Promise<boolean> {
149
+ const catalog = await openCatalogOf(database);
150
+ return catalog !== undefined && columns.every((column) => catalog.hasColumn(table, column));
151
+ }
152
+
153
+ /**
154
+ * The schema catalog an open of `database` in progress read (`withStorageSchemaCatalog`), undefined outside one. Its
155
+ * answers describe the schema when the open began.
156
+ */
157
+ export async function openCatalogOf(database: SqliteDatabase): Promise<storage.StorageSchemaCatalog | undefined> {
158
+ return catalogApi.schemaCatalogOf?.(database);
159
+ }
@@ -1,4 +1,10 @@
1
- import { dialectOf, type SqliteExecutor, type SqliteRow, validateStoragePrefix } from "@bastani/atomic/storage";
1
+ import {
2
+ dialectOf,
3
+ type SqliteExecutor,
4
+ type SqliteRow,
5
+ type SqliteStatement,
6
+ validateStoragePrefix,
7
+ } from "@bastani/atomic/storage";
2
8
  import type {
3
9
  IntercomBrokerStateOptions,
4
10
  InvalidStateInput,
@@ -12,7 +18,8 @@ import type {
12
18
  SentMessageState,
13
19
  SentQuestionRoute,
14
20
  } from "./multinode-state-store.js";
15
- import { ensureBrokerSchema } from "./sql-schema.js";
21
+ import { rowTransaction } from "./sql-outbox-store.js";
22
+ import { ensureBrokerSchema, withBrokerSchemaCatalog } from "./sql-schema.js";
16
23
 
17
24
  type SentRow = SqliteRow & {
18
25
  digest: string;
@@ -34,18 +41,43 @@ export interface SqlSentMessageAuthority extends SentMessageAuthority {
34
41
  reserveIn(executor: SqliteExecutor, reservation: SentMessageReservation): Promise<SentMessageReserveResult>;
35
42
  lookupIn(executor: SqliteExecutor, key: SentMessageKey): Promise<SentMessageLookupResult>;
36
43
  forgetIn(executor: SqliteExecutor, key: SentMessageKey): Promise<SentMessageForgetResult>;
44
+ /** The read `lookupIn` makes for `messageId`, for a transaction's `leading` statements (#6560). */
45
+ lookupStatement(messageId: string): SqliteStatement;
46
+ /**
47
+ * The one write `reserveIn` makes for `reservation`, for a caller that needs no answer from it; undefined for a
48
+ * reservation `reserveIn` refuses without writing (#6560).
49
+ */
50
+ reserveStatement(reservation: SentMessageReservation): SqliteStatement | undefined;
51
+ /**
52
+ * An SQL condition that holds while `key` is the message's reservation, in the transaction that evaluates it: a
53
+ * send's outbox row is inserted only under it, after the send's own `reserveStatement` (#6560).
54
+ */
55
+ reservedCondition(key: SentMessageKey): SqliteStatement;
37
56
  }
38
57
 
39
58
  /**
40
59
  * S3: `SentMessageAuthority` on the shared storage adapter's database, table `<prefix>intercom_sent_messages`.
41
60
  * Digests are opaque strings computed by the caller.
42
61
  */
43
- export async function openSqlSentMessageAuthority({
62
+ export function openSqlSentMessageAuthority(options: IntercomBrokerStateOptions): Promise<SqlSentMessageAuthority> {
63
+ // Its schema checks answer from one read of the catalog, shared with an open around it: a current schema costs
64
+ // no transaction and no lock, also when the store is opened on its own (#6560).
65
+ return withBrokerSchemaCatalog(options.database, options.prefix, () => openSentMessageAuthorityInCatalog(options));
66
+ }
67
+
68
+ async function openSentMessageAuthorityInCatalog({
44
69
  database,
45
70
  prefix,
46
71
  }: IntercomBrokerStateOptions): Promise<SqlSentMessageAuthority> {
47
72
  const table = `${validateStoragePrefix(prefix, dialectOf(database).name)}intercom_sent_messages`;
48
73
  const { types, nowMs } = dialectOf(database);
74
+ /**
75
+ * Its own transactions write one row each, in one statement that decides on the row's lock and newest version, so
76
+ * they take no lock domain. A send's `reserveAndEnqueue` writes the message's row first, in its recipient's domain,
77
+ * and inserts its outbox row only under it (`reservedCondition`), so a rival reservation of the message either
78
+ * comes first and refuses the send, or waits for it and is refused (#6560).
79
+ */
80
+ const fenced = rowTransaction();
49
81
  await ensureBrokerSchema(database, prefix, "sent-messages", (tx) =>
50
82
  tx.exec(`
51
83
  CREATE TABLE IF NOT EXISTS ${table}(
@@ -59,18 +91,17 @@ export async function openSqlSentMessageAuthority({
59
91
  CREATE INDEX IF NOT EXISTS ${table}_recorded ON ${table}(recorded_at);
60
92
  `),
61
93
  );
62
- const read = (executor: SqliteExecutor, messageId: string) =>
63
- executor.get<SentRow>(
64
- `SELECT digest, target_identity, question_route_json, state FROM ${table} WHERE message_id = ?`,
65
- messageId,
66
- );
94
+ const lookupStatement = (messageId: string): SqliteStatement => ({
95
+ sql: `SELECT digest, target_identity, question_route_json, state FROM ${table} WHERE message_id = ?`,
96
+ params: [messageId],
97
+ });
98
+ const read = (executor: SqliteExecutor, messageId: string) => {
99
+ const { sql, params } = lookupStatement(messageId);
100
+ return executor.get<SentRow>(sql, ...params);
101
+ };
67
102
 
68
- const reserveIn = async (
69
- tx: SqliteExecutor,
70
- reservation: SentMessageReservation,
71
- ): Promise<SentMessageReserveResult> => {
72
- if (reservation.messageId.length === 0) return emptyMessageId;
73
- if (reservation.targetIdentity.length === 0) return { status: "invalid", reason: "empty-target-identity" };
103
+ const reserveStatement = (reservation: SentMessageReservation): SqliteStatement | undefined => {
104
+ if (reservation.messageId.length === 0 || reservation.targetIdentity.length === 0) return undefined;
74
105
  const route =
75
106
  reservation.questionRoute === undefined
76
107
  ? null
@@ -78,14 +109,21 @@ export async function openSqlSentMessageAuthority({
78
109
  targetSessionId: reservation.questionRoute.targetSessionId,
79
110
  senderGroupIdentity: reservation.questionRoute.senderGroupIdentity,
80
111
  });
81
- const { changes } = await tx.run(
82
- `INSERT INTO ${table}(message_id, digest, target_identity, question_route_json, state, recorded_at)
112
+ return {
113
+ sql: `INSERT INTO ${table}(message_id, digest, target_identity, question_route_json, state, recorded_at)
83
114
  VALUES (?, ?, ?, ?, 'reserved', ${nowMs}) ON CONFLICT(message_id) DO NOTHING`,
84
- reservation.messageId,
85
- reservation.digest,
86
- reservation.targetIdentity,
87
- route,
88
- );
115
+ params: [reservation.messageId, reservation.digest, reservation.targetIdentity, route],
116
+ };
117
+ };
118
+
119
+ const reserveIn = async (
120
+ tx: SqliteExecutor,
121
+ reservation: SentMessageReservation,
122
+ ): Promise<SentMessageReserveResult> => {
123
+ if (reservation.messageId.length === 0) return emptyMessageId;
124
+ if (reservation.targetIdentity.length === 0) return { status: "invalid", reason: "empty-target-identity" };
125
+ const { sql, params } = reserveStatement(reservation)!;
126
+ const { changes } = await tx.run(sql, ...params);
89
127
  if (changes === 1) return { status: "reserved" };
90
128
  const existing = await read(tx, reservation.messageId);
91
129
  if (existing === undefined || existing.digest !== reservation.digest) return { status: "conflict" };
@@ -105,40 +143,65 @@ export async function openSqlSentMessageAuthority({
105
143
  };
106
144
  };
107
145
 
146
+ /** The message's row, deleted only while it holds `key`'s digest (#6560). */
147
+ const forgetStatement = (key: SentMessageKey): SqliteStatement => ({
148
+ sql: `DELETE FROM ${table} WHERE message_id = ? AND digest = ?`,
149
+ params: [key.messageId, key.digest],
150
+ });
151
+ const acceptStatement = (key: SentMessageKey): SqliteStatement => ({
152
+ sql: `UPDATE ${table} SET state = 'accepted' WHERE message_id = ? AND digest = ?`,
153
+ params: [key.messageId, key.digest],
154
+ });
155
+ /**
156
+ * Why a write guarded by `key`'s digest changed nothing: another digest holds the message, or none did when the write
157
+ * ran (one inserted since then came after it).
158
+ */
159
+ const refusal = async (tx: SqliteExecutor, key: SentMessageKey) => {
160
+ const existing = await read(tx, key.messageId);
161
+ return existing !== undefined && existing.digest !== key.digest
162
+ ? ({ status: "conflict" } as const)
163
+ : ({ status: "missing" } as const);
164
+ };
165
+
108
166
  const forgetIn = async (tx: SqliteExecutor, key: SentMessageKey): Promise<SentMessageForgetResult> => {
109
167
  if (key.messageId.length === 0) return emptyMessageId;
110
- const existing = await read(tx, key.messageId);
111
- if (existing === undefined) return { status: "missing" };
112
- if (existing.digest !== key.digest) return { status: "conflict" };
113
- await tx.run(`DELETE FROM ${table} WHERE message_id = ?`, key.messageId);
114
- return { status: "forgotten" };
168
+ const { sql, params } = forgetStatement(key);
169
+ const { changes } = await tx.run(sql, ...params);
170
+ return changes > 0 ? { status: "forgotten" } : refusal(tx, key);
115
171
  };
116
172
 
173
+ /** A transaction whose first statement, sent with its start on a pipelined connection, is `first` (#6560). */
174
+ const leadingWith = (first: SqliteStatement) => ({ ...fenced, leading: [first] });
175
+
117
176
  return {
118
177
  reserveIn,
119
178
  lookupIn,
120
179
  forgetIn,
180
+ lookupStatement,
181
+ reserveStatement,
182
+ reservedCondition: (key) => ({
183
+ sql: `EXISTS (SELECT 1 FROM ${table} WHERE message_id = ? AND digest = ?)`,
184
+ params: [key.messageId, key.digest],
185
+ }),
121
186
  async reserve(reservation): Promise<SentMessageReserveResult> {
122
187
  if (reservation.messageId.length === 0) return emptyMessageId;
123
188
  if (reservation.targetIdentity.length === 0) return { status: "invalid", reason: "empty-target-identity" };
124
- return database.transaction((tx) => reserveIn(tx, reservation));
189
+ return database.transaction((tx) => reserveIn(tx, reservation), leadingWith(reserveStatement(reservation)!));
125
190
  },
126
191
  async accept(key: SentMessageKey): Promise<SentMessageAcceptResult> {
127
192
  if (key.messageId.length === 0) return emptyMessageId;
193
+ const accepting = acceptStatement(key);
128
194
  return database.transaction(async (tx) => {
129
- const existing = await read(tx, key.messageId);
130
- if (existing === undefined) return { status: "missing" };
131
- if (existing.digest !== key.digest) return { status: "conflict" };
132
- await tx.run(`UPDATE ${table} SET state = 'accepted' WHERE message_id = ?`, key.messageId);
133
- return { status: "accepted" };
134
- });
195
+ const { changes } = await tx.run(accepting.sql, ...accepting.params);
196
+ return changes > 0 ? { status: "accepted" } : refusal(tx, key);
197
+ }, leadingWith(accepting));
135
198
  },
136
199
  lookup(key: SentMessageKey): Promise<SentMessageLookupResult> {
137
200
  return lookupIn(database, key);
138
201
  },
139
202
  async forget(key: SentMessageKey): Promise<SentMessageForgetResult> {
140
203
  if (key.messageId.length === 0) return emptyMessageId;
141
- return database.transaction((tx) => forgetIn(tx, key));
204
+ return database.transaction((tx) => forgetIn(tx, key), leadingWith(forgetStatement(key)));
142
205
  },
143
206
  async prune(olderThanMs: number): Promise<number> {
144
207
  const { changes } = await database.run(
@@ -7,7 +7,7 @@ import * as __atomicHostImport1 from "@bastani/atomic-ai";
7
7
  if (!(name in namespace)) missing.push(`The requested module '${specifier}' does not provide an export named '${name}'`);
8
8
  if (missing.length > 0) {
9
9
  const application = typeof __atomicHostImport0.APP_NAME === "string" ? __atomicHostImport0.APP_NAME : "atomic";
10
- if (__atomicHostImport0.VERSION !== "0.10.10-alpha.2") missing.unshift(application + " was updated to 0.10.10-alpha.2 while this session was running; restart it to keep using the intercom extension.");
10
+ if (__atomicHostImport0.VERSION !== "0.10.11-alpha.1") missing.unshift(application + " was updated to 0.10.11-alpha.1 while this session was running; restart it to keep using the intercom extension.");
11
11
  throw new Error(missing.join("\n"));
12
12
  }
13
13
  }
@@ -7395,7 +7395,7 @@ var init_broker_status = __esm(() => {
7395
7395
  import { createHash } from "crypto";
7396
7396
  import { lstat as lstat2, mkdir, readFile } from "node:fs/promises";
7397
7397
  import { homedir as homedir2, tmpdir as tmpdir2 } from "os";
7398
- import { basename, dirname, join as join2, resolve } from "path";
7398
+ import { basename, dirname, isAbsolute, join as join2, resolve } from "path";
7399
7399
  function getHomeDir() {
7400
7400
  if (process.platform === "win32") {
7401
7401
  if (process.env.USERPROFILE)
@@ -7492,6 +7492,9 @@ async function privateSocketDirectoryAsync() {
7492
7492
  function inDirectorySocketPath(agentDir) {
7493
7493
  return join2(getIntercomDirPath(agentDir), "broker.sock");
7494
7494
  }
7495
+ function absoluteSocketPath(socketPath) {
7496
+ return isAbsolute(socketPath) ? socketPath : resolve(socketPath);
7497
+ }
7495
7498
  function fitsUnixSocketPath(socketPath, platform) {
7496
7499
  return Buffer.byteLength(socketPath) <= maxUnixSocketPathBytes(platform);
7497
7500
  }
@@ -7501,7 +7504,7 @@ function directBrokerSocketPath(platform = process.platform, agentDir = getAgent
7501
7504
  return pipe.length <= MAX_PIPE_NAME_LENGTH ? pipe : `${WINDOWS_PIPE_PREFIX}${agentDirDigest(agentDir)}`;
7502
7505
  }
7503
7506
  const socketPath = inDirectorySocketPath(agentDir);
7504
- return fitsUnixSocketPath(socketPath, platform) ? socketPath : undefined;
7507
+ return fitsUnixSocketPath(absoluteSocketPath(socketPath), platform) ? socketPath : undefined;
7505
7508
  }
7506
7509
  async function recordedSocketPathAsync(agentDir) {
7507
7510
  let recorded;
@@ -7526,7 +7529,7 @@ async function chooseBrokerSocketPathAsync(platform = process.platform, agentDir
7526
7529
  const direct = directBrokerSocketPath(platform, agentDir);
7527
7530
  if (direct !== undefined)
7528
7531
  return direct;
7529
- const socketPath = inDirectorySocketPath(agentDir);
7532
+ const socketPath = absoluteSocketPath(inDirectorySocketPath(agentDir));
7530
7533
  const shortPath = join2(await privateSocketDirectoryAsync(), `${agentDirDigest(agentDir)}.sock`);
7531
7534
  if (!fitsUnixSocketPath(shortPath, platform)) {
7532
7535
  throw new Error(`Intercom broker socket paths ${socketPath} and ${shortPath} are both longer than the ${maxUnixSocketPathBytes(platform)} bytes a Unix socket path allows`);
@@ -10729,7 +10732,7 @@ var init_path_exists = () => {};
10729
10732
  // dist/builtin/intercom/broker/spawn.ts
10730
10733
  import { spawn as spawn2 } from "child_process";
10731
10734
  import { access as access4, appendFile, chmod, lstat as lstat4, mkdir as mkdir2, open as open2, readFile as readFile6, stat as stat7, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
10732
- import { basename as basename3, dirname as dirname3, isAbsolute, join as join6, resolve as resolve2, win32 as win323 } from "path";
10735
+ import { basename as basename3, dirname as dirname3, isAbsolute as isAbsolute2, join as join6, resolve as resolve2, win32 as win323 } from "path";
10733
10736
  import { fileURLToPath } from "url";
10734
10737
  import { createRequire as createRequire4 } from "module";
10735
10738
  import {
@@ -10885,7 +10888,7 @@ function resolveAgainstCallerCwd(rawPath) {
10885
10888
  return rawPath;
10886
10889
  }
10887
10890
  }
10888
- return isAbsolute(rawPath) ? rawPath : resolve2(rawPath);
10891
+ return isAbsolute2(rawPath) ? rawPath : resolve2(rawPath);
10889
10892
  }
10890
10893
  function brokerSafeCwdOptions(extensionDir, commandPath) {
10891
10894
  const resolvedExt = resolveAgainstCallerCwd(extensionDir);
@@ -10934,7 +10937,7 @@ function absolutizeAgentDirEnvInPlace(env) {
10934
10937
  if (!value || value === "~" || value.startsWith("~/") || process.platform === "win32" && value.startsWith("~\\")) {
10935
10938
  continue;
10936
10939
  }
10937
- const needsResolve = process.platform === "win32" ? !isAbsoluteWindowsPath(value) : !isAbsolute(value);
10940
+ const needsResolve = process.platform === "win32" ? !isAbsoluteWindowsPath(value) : !isAbsolute2(value);
10938
10941
  if (needsResolve) {
10939
10942
  env[targetKey] = resolveAgainstCallerCwd(value);
10940
10943
  }
@@ -11470,7 +11473,7 @@ async function spawnBrokerHoldingLock(lockOwner, brokerCommand, brokerArgs, read
11470
11473
  const resolvedExtensionDir = resolveAgainstCallerCwd(extensionDir);
11471
11474
  const brokerPath = await resolveBrokerEntrypointAsync(resolvedExtensionDir);
11472
11475
  const isCustomPath = !usesDefaultBrokerCommand(brokerCommand, brokerArgs) && (/[\\/]/u.test(brokerCommand) || process.platform === "win32" && /^[A-Za-z]:/u.test(brokerCommand));
11473
- const normalizedCustomCommand = isCustomPath && (process.platform === "win32" ? !isAbsoluteWindowsPath(brokerCommand) : !isAbsolute(brokerCommand)) ? resolveAgainstCallerCwd(brokerCommand) : brokerCommand;
11476
+ const normalizedCustomCommand = isCustomPath && (process.platform === "win32" ? !isAbsoluteWindowsPath(brokerCommand) : !isAbsolute2(brokerCommand)) ? resolveAgainstCallerCwd(brokerCommand) : brokerCommand;
11474
11477
  const initialCommandPath = usesDefaultBrokerCommand(brokerCommand, brokerArgs) ? process.execPath : normalizedCustomCommand;
11475
11478
  const baseSpawnOptions = await getBrokerSpawnOptionsAsync(resolvedExtensionDir, "ignore", undefined, initialCommandPath);
11476
11479
  const effectiveCommand = process.platform === "win32" && !usesDefaultBrokerCommand(brokerCommand, brokerArgs) ? await resolveWindowsCustomCommandAsync(normalizedCustomCommand, baseSpawnOptions.env) : normalizedCustomCommand;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/intercom",
3
- "version": "0.10.10-alpha.2",
3
+ "version": "0.10.11-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic extension for direct messaging and coordination between parent, child, and peer agent sessions.",
6
6
  "contributors": [
@@ -6,7 +6,7 @@ import * as __atomicHostImport0 from "@bastani/atomic";
6
6
  if (!(name in namespace)) missing.push(`The requested module '${specifier}' does not provide an export named '${name}'`);
7
7
  if (missing.length > 0) {
8
8
  const application = typeof __atomicHostImport0.APP_NAME === "string" ? __atomicHostImport0.APP_NAME : "atomic";
9
- if (__atomicHostImport0.VERSION !== "0.10.10-alpha.2") missing.unshift(application + " was updated to 0.10.10-alpha.2 while this session was running; restart it to keep using the mcp extension.");
9
+ if (__atomicHostImport0.VERSION !== "0.10.11-alpha.1") missing.unshift(application + " was updated to 0.10.11-alpha.1 while this session was running; restart it to keep using the mcp extension.");
10
10
  throw new Error(missing.join("\n"));
11
11
  }
12
12
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/mcp",
3
- "version": "0.10.10-alpha.2",
3
+ "version": "0.10.11-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic's MCP integration for server connections, OAuth, tools, resources, and terminal management.",
6
6
  "contributors": [