@bastani/atomic 0.10.10 → 0.10.11-alpha.2

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 (402) hide show
  1. package/CHANGELOG.md +139 -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 +11 -13
  7. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
  8. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +9 -9
  9. package/dist/_shared/mode-shared-2QJSCUM6.js +55 -18
  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 +5 -5
  13. package/dist/_shared/{sdk-RRLVN7ER.js → sdk-IQMULKFU.js} +2962 -470
  14. package/dist/_shared/sdk-IQMULKFU.js.map +1 -0
  15. package/dist/_shared/session-data-AHTU7IS6.js +4 -4
  16. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  17. package/dist/_shared/settings-startup-8-DNZ2RIHM.js +1 -1
  18. package/dist/_shared/{settings-startup-4QCVCI53.js → settings-startup-HXQLSUWM.js} +8 -2
  19. package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -0
  20. package/dist/_shared/{startup-0-0-4VG2G44V.js → startup-0-0-3IXNMFM2.js} +482 -53
  21. package/dist/_shared/startup-0-0-3IXNMFM2.js.map +1 -0
  22. package/dist/_shared/{startup-0-1-XTIL65D4.js → startup-0-1-7T2IAE7J.js} +121 -251
  23. package/dist/_shared/startup-0-1-7T2IAE7J.js.map +1 -0
  24. package/dist/_shared/{startup-0-2-27OWFHV6.js → startup-0-2-5QHPCEON.js} +293 -10
  25. package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -0
  26. package/dist/_shared/{startup-0-3-T4DVFYWX.js → startup-0-3-4ZYBYQNM.js} +273 -14
  27. package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +1 -0
  28. package/dist/_shared/startup-0-4-ZMJV547D.js +6 -6
  29. package/dist/_shared/{startup-0-5-FD2P735I.js → startup-0-5-YDW47QX6.js} +29 -71
  30. package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -0
  31. package/dist/_shared/startup-10-0-TDQNBDDL.js +9 -9
  32. package/dist/_shared/startup-12-0-55AAXBJZ.js +4 -4
  33. package/dist/_shared/startup-14-0-MLX36RBG.js +6 -6
  34. package/dist/_shared/startup-15-0-YUKGAC63.js +34 -10
  35. package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
  36. package/dist/_shared/startup-15-1-4S7FLMNG.js +10 -9
  37. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  38. package/dist/_shared/startup-8-0-34CBHPZH.js +421 -84
  39. package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
  40. package/dist/_shared/{startup-8-1-4KANEHRA.js → startup-8-1-X32CYSXB.js} +1291 -722
  41. package/dist/_shared/startup-8-1-X32CYSXB.js.map +1 -0
  42. package/dist/_shared/storage-command-7MGXLJGZ.js +17 -9
  43. package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
  44. package/dist/_shared/task-reference-stream-JWMUZSJX.js +1 -1
  45. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  46. package/dist/_shared/tree-outline-MUEPK5B7.js +3 -3
  47. package/dist/builtin/intercom/CHANGELOG.md +29 -0
  48. package/dist/builtin/intercom/broker/broker.bundle.mjs +1138 -384
  49. package/dist/builtin/intercom/broker/database-wake-up-bus.ts +103 -24
  50. package/dist/builtin/intercom/broker/multinode-router.ts +42 -21
  51. package/dist/builtin/intercom/broker/multinode-state-store.ts +22 -1
  52. package/dist/builtin/intercom/broker/open-broker-state.ts +82 -31
  53. package/dist/builtin/intercom/broker/paths.ts +8 -4
  54. package/dist/builtin/intercom/broker/released-asker-remote-replies.ts +18 -6
  55. package/dist/builtin/intercom/broker/sql-add-column.ts +4 -1
  56. package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +65 -44
  57. package/dist/builtin/intercom/broker/sql-held-send-store.ts +11 -3
  58. package/dist/builtin/intercom/broker/sql-known-session-store.ts +24 -12
  59. package/dist/builtin/intercom/broker/sql-lease-store.ts +386 -65
  60. package/dist/builtin/intercom/broker/sql-outbox-store.ts +462 -130
  61. package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +20 -9
  62. package/dist/builtin/intercom/broker/sql-released-ask-store.ts +14 -6
  63. package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +27 -11
  64. package/dist/builtin/intercom/broker/sql-schema.ts +198 -5
  65. package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +97 -34
  66. package/dist/builtin/intercom/index.bundle.mjs +11 -8
  67. package/dist/builtin/intercom/package.json +1 -1
  68. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  69. package/dist/builtin/mcp/package.json +1 -1
  70. package/dist/builtin/subagents/CHANGELOG.md +18 -0
  71. package/dist/builtin/subagents/package.json +1 -1
  72. package/dist/builtin/subagents/skills/skill-creator/SKILL.md +1 -1
  73. package/dist/builtin/subagents/src/extension/index.bundle.mjs +62 -23
  74. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  75. package/dist/builtin/web-access/package.json +1 -1
  76. package/dist/cli/args.js +2 -2
  77. package/dist/cli/auth-cli.code.js +6 -6
  78. package/dist/cli/auth-cli.impl.js +3 -3
  79. package/dist/cli/auth-cli.js +3 -3
  80. package/dist/cli/blueprint-command.code.js +4 -4
  81. package/dist/cli/blueprint-command.impl.js +3 -3
  82. package/dist/cli/blueprint-command.js +3 -3
  83. package/dist/cli/intercom-command.code.js +3 -3
  84. package/dist/cli/intercom-command.impl.js +3 -3
  85. package/dist/cli/intercom-command.js +3 -3
  86. package/dist/cli/list-models.code.js +2 -2
  87. package/dist/cli/list-models.impl.js +3 -3
  88. package/dist/cli/list-models.js +3 -3
  89. package/dist/cli/session-picker.code.js +2 -2
  90. package/dist/cli/session-picker.impl.js +3 -3
  91. package/dist/cli/session-picker.js +3 -3
  92. package/dist/cli/startup-ui.code.js +2 -2
  93. package/dist/cli/startup-ui.impl.js +3 -3
  94. package/dist/cli/startup-ui.js +3 -3
  95. package/dist/cli/storage-command.impl.js +3 -3
  96. package/dist/cli/storage-command.js +3 -3
  97. package/dist/cli/storage-search-session.code.js +3 -3
  98. package/dist/cli/storage-search-session.impl.js +3 -3
  99. package/dist/cli/storage-search-session.js +3 -3
  100. package/dist/cli/team-command.code.js +3 -3
  101. package/dist/cli/team-command.impl.js +3 -3
  102. package/dist/cli/team-command.js +3 -3
  103. package/dist/cli.js +2 -2
  104. package/dist/core/agent-session-methods.d.ts +3 -0
  105. package/dist/core/agent-session-methods.js.map +1 -1
  106. package/dist/core/agent-session.d.ts +1 -0
  107. package/dist/core/compaction/compactor.d.ts +2 -0
  108. package/dist/core/debug.impl.js +3 -3
  109. package/dist/core/debug.js +3 -3
  110. package/dist/core/export-html/card-projection.code.js +1 -1
  111. package/dist/core/export-html/card-projection.impl.js +3 -3
  112. package/dist/core/export-html/card-projection.js +3 -3
  113. package/dist/core/export-html/index.code.js +2 -2
  114. package/dist/core/export-html/index.impl.js +3 -3
  115. package/dist/core/export-html/index.js +3 -3
  116. package/dist/core/export-html/json-spans.impl.js +3 -3
  117. package/dist/core/export-html/json-spans.js +3 -3
  118. package/dist/core/export-html/oversized-render-inputs.code.js +2 -2
  119. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  120. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  121. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  122. package/dist/core/export-html/tool-renderer.js +3 -3
  123. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  124. package/dist/core/extensions/jiti-loader.js +3 -3
  125. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  126. package/dist/core/extensions/jiti-static-loader.js +3 -3
  127. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  128. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  129. package/dist/core/extensions/loader-host-modules.js +3 -3
  130. package/dist/core/extensions/loader-virtual-modules.js +2 -2
  131. package/dist/core/extensions/runner-context.js +4 -4
  132. package/dist/core/extensions/runner-context.js.map +1 -1
  133. package/dist/core/intercom-broker-control-host.code.js +1 -1
  134. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  135. package/dist/core/intercom-broker-control-host.js +3 -3
  136. package/dist/core/intercom-broker-control.code.js +3 -3
  137. package/dist/core/intercom-broker-control.impl.js +3 -3
  138. package/dist/core/intercom-broker-control.js +3 -3
  139. package/dist/core/model-registry.js +1 -1
  140. package/dist/core/model-resolver-defaults.d.ts +3 -2
  141. package/dist/core/package-manager-storage-adapters.code.js +1 -1
  142. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  143. package/dist/core/package-manager-storage-adapters.js +3 -3
  144. package/dist/core/sdk.code.js +4 -5
  145. package/dist/core/sdk.impl.js +3 -3
  146. package/dist/core/sdk.js +3 -3
  147. package/dist/core/session-manager-core.d.ts +5 -2
  148. package/dist/core/session-manager-core.js +39 -23
  149. package/dist/core/session-manager-core.js.map +1 -1
  150. package/dist/core/session-manager-list.impl.js +3 -3
  151. package/dist/core/session-manager-list.js +3 -3
  152. package/dist/core/session-manager.code.js +3 -3
  153. package/dist/core/session-manager.impl.js +3 -3
  154. package/dist/core/session-manager.js +3 -3
  155. package/dist/core/session-open-markers.js +3 -0
  156. package/dist/core/session-open-markers.js.map +1 -0
  157. package/dist/core/session-storage.code.js +1 -1
  158. package/dist/core/session-storage.impl.js +3 -3
  159. package/dist/core/session-storage.js +3 -3
  160. package/dist/core/storage/added-exports.d.ts +6 -0
  161. package/dist/core/storage/added-exports.js +19 -0
  162. package/dist/core/storage/added-exports.js.map +1 -0
  163. package/dist/core/storage/database.d.ts +53 -0
  164. package/dist/core/storage/database.js.map +1 -1
  165. package/dist/core/storage/fenced-paths.d.ts +47 -0
  166. package/dist/core/storage/fenced-paths.js +53 -0
  167. package/dist/core/storage/fenced-paths.js.map +1 -1
  168. package/dist/core/storage/file-identity.js +31 -2
  169. package/dist/core/storage/file-identity.js.map +1 -1
  170. package/dist/core/storage/index.d.ts +4 -1
  171. package/dist/core/storage/index.js +5 -2
  172. package/dist/core/storage/index.js.map +1 -1
  173. package/dist/core/storage/migrations.d.ts +33 -2
  174. package/dist/core/storage/migrations.js +73 -5
  175. package/dist/core/storage/migrations.js.map +1 -1
  176. package/dist/core/storage/node-sqlite-thread.js +48 -6
  177. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  178. package/dist/core/storage/node-sqlite.js +137 -4
  179. package/dist/core/storage/node-sqlite.js.map +1 -1
  180. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  181. package/dist/core/storage/offline-snapshot-file.js +3 -3
  182. package/dist/core/storage/prefix.d.ts +3 -2
  183. package/dist/core/storage/prefix.js +23 -2
  184. package/dist/core/storage/prefix.js.map +1 -1
  185. package/dist/core/storage/provider.js +2 -2
  186. package/dist/core/storage/schema-catalog.d.ts +120 -0
  187. package/dist/core/storage/schema-catalog.js +351 -0
  188. package/dist/core/storage/schema-catalog.js.map +1 -0
  189. package/dist/core/storage/selection.js +2 -2
  190. package/dist/core/storage/session/branch-fork-source.code.js +47 -25
  191. package/dist/core/storage/session/branch-fork-source.code.js.map +1 -1
  192. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  193. package/dist/core/storage/session/branch-fork-source.js +3 -3
  194. package/dist/core/storage/session/card-view.impl.js +3 -3
  195. package/dist/core/storage/session/card-view.js +3 -3
  196. package/dist/core/storage/session/child-reader.code.js +4 -4
  197. package/dist/core/storage/session/child-reader.impl.js +3 -3
  198. package/dist/core/storage/session/child-reader.js +3 -3
  199. package/dist/core/storage/session/chunked-resume-projection.code.js +1 -1
  200. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  201. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  202. package/dist/core/storage/session/errors.js +1 -1
  203. package/dist/core/storage/session/expanded-child-details.code.js +4 -4
  204. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  205. package/dist/core/storage/session/expanded-child-details.js +3 -3
  206. package/dist/core/storage/session/fork-detach.d.ts +118 -0
  207. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  208. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  209. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  210. package/dist/core/storage/session/fork-row-index.js +3 -3
  211. package/dist/core/storage/session/fork-schema.js +53 -0
  212. package/dist/core/storage/session/fork-schema.js.map +1 -0
  213. package/dist/core/storage/session/fork-segments.d.ts +58 -0
  214. package/dist/core/storage/session/fork-staging.code.js +176 -36
  215. package/dist/core/storage/session/fork-staging.code.js.map +1 -1
  216. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  217. package/dist/core/storage/session/fork-staging.js +3 -3
  218. package/dist/core/storage/session/fork-sweep.js +61 -0
  219. package/dist/core/storage/session/fork-sweep.js.map +1 -0
  220. package/dist/core/storage/session/fork-window.code.js +4 -4
  221. package/dist/core/storage/session/fork-window.impl.js +3 -3
  222. package/dist/core/storage/session/fork-window.js +3 -3
  223. package/dist/core/storage/session/history-pages.impl.js +3 -3
  224. package/dist/core/storage/session/history-pages.js +3 -3
  225. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  226. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  227. package/dist/core/storage/session/jsonl-session-store.d.ts +37 -1
  228. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  229. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  230. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  231. package/dist/core/storage/session/memory-session-store.js +3 -3
  232. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  233. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  234. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  235. package/dist/core/storage/session/released-history-files.code.js +3 -3
  236. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  237. package/dist/core/storage/session/released-history-files.js +3 -3
  238. package/dist/core/storage/session/resident-fork-rows.code.js +1 -1
  239. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  240. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  241. package/dist/core/storage/session/session-resume.impl.js +3 -3
  242. package/dist/core/storage/session/session-resume.js +3 -3
  243. package/dist/core/storage/session/session-search-index.d.ts +5 -0
  244. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  245. package/dist/core/storage/session/snapshot-cut.js +3 -3
  246. package/dist/core/storage/session/snapshot-history.code.js +4 -4
  247. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  248. package/dist/core/storage/session/snapshot-history.js +3 -3
  249. package/dist/core/storage/session/sql-chat-records.d.ts +15 -0
  250. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  251. package/dist/core/storage/session/sql-session-store.d.ts +445 -11
  252. package/dist/core/storage/session/sql-session-store.impl.js +4 -4
  253. package/dist/core/storage/session/sql-session-store.js +4 -4
  254. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  255. package/dist/core/storage/session/tree-outline.js +3 -3
  256. package/dist/core/storage/session/tree-presentation.code.js +1 -1
  257. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  258. package/dist/core/storage/session/tree-presentation.js +3 -3
  259. package/dist/core/storage/session/types.d.ts +36 -0
  260. package/dist/core/storage/sqlite-facade.d.ts +54 -6
  261. package/dist/core/storage/sqlite-facade.js +384 -18
  262. package/dist/core/storage/sqlite-facade.js.map +1 -1
  263. package/dist/core/storage/statement-sequence.d.ts +83 -0
  264. package/dist/core/storage/statement-sequence.js +21 -0
  265. package/dist/core/storage/statement-sequence.js.map +1 -1
  266. package/dist/core/storage/storage-status.code.js +1 -1
  267. package/dist/core/storage/storage-status.impl.js +3 -3
  268. package/dist/core/storage/storage-status.js +3 -3
  269. package/dist/core/storage/team.code.js +1 -1
  270. package/dist/core/storage/team.impl.js +3 -3
  271. package/dist/core/storage/team.js +3 -3
  272. package/dist/core/structured-output/index.code.js +1 -1
  273. package/dist/core/structured-output/index.impl.js +3 -3
  274. package/dist/core/structured-output/index.js +3 -3
  275. package/dist/core/tasks/task-completion-entry.code.js +1 -1
  276. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  277. package/dist/core/tasks/task-completion-entry.js +3 -3
  278. package/dist/core/tasks/task-file-history.code.js +4 -4
  279. package/dist/core/tasks/task-file-history.impl.js +3 -3
  280. package/dist/core/tasks/task-file-history.js +3 -3
  281. package/dist/core/tasks/task-reference-archive.code.js +5 -5
  282. package/dist/core/tasks/task-reference-archive.js +3 -3
  283. package/dist/core/tasks/task-reference-identity.js +3 -3
  284. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  285. package/dist/core/tasks/task-reference-stream.js +3 -3
  286. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  287. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  288. package/dist/core/tasks/task-view-source.code.js +1 -1
  289. package/dist/core/tasks/task-view-source.impl.js +3 -3
  290. package/dist/core/tasks/task-view-source.js +3 -3
  291. package/dist/core/tools/bash.d.ts +8 -4
  292. package/dist/core/tools/history-session.d.ts +7 -0
  293. package/dist/core/tools/history-tasks.d.ts +123 -0
  294. package/dist/core/tools/kill.d.ts +5 -2
  295. package/dist/core/tools/powershell.d.ts +2 -2
  296. package/dist/core/tools/read-url.code.js +3 -3
  297. package/dist/core/tools/read-url.impl.js +3 -3
  298. package/dist/core/tools/read-url.js +3 -3
  299. package/dist/core/tools/read.d.ts +12 -2
  300. package/dist/core/tools/resource-selectors.d.ts +2 -0
  301. package/dist/core/tools/search.d.ts +12 -2
  302. package/dist/core/worktree-snapshot/blob-store.d.ts +45 -2
  303. package/dist/core/worktree-snapshot/blob-store.js +228 -60
  304. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  305. package/dist/core/worktree-snapshot/errors.code.js +3 -3
  306. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  307. package/dist/core/worktree-snapshot/errors.js +3 -3
  308. package/dist/core/worktree-snapshot/fork-snapshot-index.js +121 -0
  309. package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -0
  310. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  311. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  312. package/dist/extensions/codemode/execute.code.js +3 -3
  313. package/dist/extensions/codemode/execute.impl.js +3 -3
  314. package/dist/extensions/codemode/execute.js +3 -3
  315. package/dist/extensions/codemode/renderer.code.js +2 -2
  316. package/dist/extensions/codemode/renderer.impl.js +3 -3
  317. package/dist/extensions/codemode/renderer.js +3 -3
  318. package/dist/extensions/mcp/cli.code.js +3 -3
  319. package/dist/extensions/mcp/cli.impl.js +3 -3
  320. package/dist/extensions/mcp/cli.js +3 -3
  321. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  322. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  323. package/dist/extensions/mcp/cli.lazy.js +3 -3
  324. package/dist/extensions/mcp/runtime.code.js +1 -1
  325. package/dist/extensions/mcp/runtime.impl.js +3 -3
  326. package/dist/extensions/mcp/runtime.js +3 -3
  327. package/dist/index.js +8 -8
  328. package/dist/main-first-time-setup.code.js +2 -2
  329. package/dist/main-first-time-setup.impl.js +3 -3
  330. package/dist/main-first-time-setup.js +3 -3
  331. package/dist/main.js +1 -1
  332. package/dist/modes/interactive/components/agent-panel.d.ts +1 -0
  333. package/dist/modes/interactive/components/stored-tree-view.code.js +3 -3
  334. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  335. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  336. package/dist/modes/interactive/components/task-inspector.d.ts +2 -0
  337. package/dist/modes/interactive/components/user-message-selector-archive.code.js +1 -1
  338. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  339. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  340. package/dist/modes/interactive/interactive-mode-helpers.d.ts +2 -2
  341. package/dist/modes/print-mode.js +1 -1
  342. package/dist/modes/rpc/agent-panel-bridge.d.ts +5 -0
  343. package/dist/package-manager-cli.code.js +7 -7
  344. package/dist/package-manager-cli.impl.js +3 -3
  345. package/dist/package-manager-cli.js +3 -3
  346. package/dist/rpc-entry.js +1 -1
  347. package/dist/startup-files.json +1 -1
  348. package/dist/startup-stages/0.js +1 -1
  349. package/dist/startup-stages/1.js +1 -1
  350. package/dist/startup-stages/10.js +1 -1
  351. package/dist/startup-stages/12.js +1 -1
  352. package/dist/startup-stages/2.js +9 -1
  353. package/dist/startup-stages/3.js +1 -6
  354. package/dist/startup-stages/5.js +1 -1
  355. package/dist/startup-stages/7.js +1 -1
  356. package/dist/startup-stages/8.js +2 -2
  357. package/dist/utils/startup-database-spare.code.js +3 -3
  358. package/dist/utils/startup-database-spare.impl.js +3 -3
  359. package/dist/utils/startup-database-spare.js +3 -3
  360. package/dist/utils/tools-manager.code.js +1 -1
  361. package/dist/utils/tools-manager.impl.js +3 -3
  362. package/dist/utils/tools-manager.js +3 -3
  363. package/docs/background-tasks.md +123 -23
  364. package/docs/compaction.md +18 -0
  365. package/docs/docs.json +2 -0
  366. package/docs/environment-variables.md +1 -1
  367. package/docs/getting-started/installation.md +9 -2
  368. package/docs/guides/postgres-pgbouncer.md +346 -0
  369. package/docs/guides/postgres-tuning.md +311 -0
  370. package/docs/guides/resume-on-any-machine.md +2 -2
  371. package/docs/guides.md +2 -0
  372. package/docs/index.md +1 -1
  373. package/docs/libraries/agent-core.md +1 -1
  374. package/docs/libraries/ai.md +2 -2
  375. package/docs/libraries/codemode.md +1 -1
  376. package/docs/libraries/storage-libsql.md +6 -1
  377. package/docs/libraries/storage-postgres.md +11 -6
  378. package/docs/libraries/tui.md +1 -1
  379. package/docs/libraries.md +2 -2
  380. package/docs/programmatic.md +1 -1
  381. package/docs/quickstart.md +1 -1
  382. package/docs/sdk/storage.md +1 -1
  383. package/docs/sdk/web-server.md +1 -3
  384. package/docs/sdk.md +1 -7
  385. package/docs/sessions.md +67 -2
  386. package/docs/settings.md +20 -1
  387. package/docs/skills/authoring.md +1 -1
  388. package/docs/skills.md +79 -6
  389. package/docs/storage.md +305 -14
  390. package/docs/subagents/reference.md +2 -2
  391. package/docs/subagents.md +4 -3
  392. package/docs/tools.md +44 -10
  393. package/docs/windows.md +1 -1
  394. package/package.json +9 -9
  395. package/dist/_shared/sdk-RRLVN7ER.js.map +0 -1
  396. package/dist/_shared/settings-startup-4QCVCI53.js.map +0 -1
  397. package/dist/_shared/startup-0-0-4VG2G44V.js.map +0 -1
  398. package/dist/_shared/startup-0-1-XTIL65D4.js.map +0 -1
  399. package/dist/_shared/startup-0-2-27OWFHV6.js.map +0 -1
  400. package/dist/_shared/startup-0-3-T4DVFYWX.js.map +0 -1
  401. package/dist/_shared/startup-0-5-FD2P735I.js.map +0 -1
  402. package/dist/_shared/startup-8-1-4KANEHRA.js.map +0 -1
@@ -1,21 +1,21 @@
1
1
  import { __name } from "./rolldown-runtime-BGM3D5V3.js";
2
2
  import { createSessionCwdMatcher, normalizePath, resolvePath } from "./p0-cli-BB45ZQY6.js";
3
- import { CURRENT_SESSION_VERSION, EntryTypeReader, JsonTextChecker, applySessionSummaryEntries, bindChatEpoch, boundedChatRecord, decodeChatRecord, firstChatOrders, getErrnoCode, historySnapshotFor, inheritForkScope, isClassifiedWorkflowSession, materializeSessionSummaryMetadata, noteSnapshotGeneration, observeReferenceCut, readLines, referenceMetadataRead, registerArchiveLoad, registerForkScope, require_sha256, sha256Hex, summarizeSession, yieldTurn } from "./startup-0-0-4VG2G44V.js";
4
- import { AgentRehydrateError, AgentReleaseConfigError, SessionKeyDigests, appendFileChatRecord, deleteFileChatRecords, hasFileChatRecords, latestLegacyMessageTime, legacyCompletionTarget, readFileChatOrders, readFileChatRecords, rememberEarlierCompletion, summarizeLegacySession } from "./startup-0-1-XTIL65D4.js";
5
- import { agentWakeDispatcher } from "./startup-0-2-27OWFHV6.js";
6
- import { SESSION_HISTORY_CHUNK_BYTES, SESSION_HISTORY_PAGE_BYTES, SESSION_HISTORY_SCAN_ENTRIES, SessionIdError, entrySizeLimit, matchesSessionIdPrefix, yieldSessionTurn } from "./settings-startup-4QCVCI53.js";
7
- import { access, appendFile, copyFile, link, mkdir, open, readFile, readdir, rename, stat, truncate, unlink, writeFile } from "node:fs/promises";
3
+ import { CURRENT_SESSION_VERSION, EntryTypeReader, JsonTextChecker, applySessionSummaryEntries, bindChatEpoch, boundedChatRecord, decodeChatRecord, firstChatOrders, getErrnoCode, historySnapshotFor, inheritForkScope, isClassifiedWorkflowSession, materializeSessionSummaryMetadata, noteSnapshotGeneration, observeReferenceCut, readLines, referenceMetadataRead, registerArchiveLoad, registerForkScope, require_sha256, sha256Hex, summarizeSession, yieldTurn } from "./startup-0-0-3IXNMFM2.js";
4
+ import { AgentRehydrateError, AgentReleaseConfigError, SessionKeyDigests, appendFileChatRecord, deleteFileChatRecords, hasFileChatRecords, latestLegacyMessageTime, legacyCompletionTarget, readFileChatOrders, readFileChatRecords, rememberEarlierCompletion, summarizeLegacySession } from "./startup-0-1-7T2IAE7J.js";
5
+ import { agentWakeDispatcher } from "./startup-0-2-5QHPCEON.js";
6
+ import { SESSION_HISTORY_CHUNK_BYTES, SESSION_HISTORY_PAGE_BYTES, SESSION_HISTORY_SCAN_ENTRIES, SessionIdError, entrySizeLimit, matchesSessionIdPrefix, onlySeqs, yieldSessionTurn } from "./settings-startup-HXQLSUWM.js";
7
+ import { access, copyFile, link, mkdir, open, readFile, readdir, rename, stat, truncate, unlink, writeFile } from "node:fs/promises";
8
8
  import { closeSync, existsSync, openSync, readSync, readdirSync, statSync } from "fs";
9
9
  import { join } from "path";
10
10
  import { basename as basename$1, dirname as dirname$1, join as join$1, resolve as resolve$1 } from "node:path";
11
11
  import { createSessionCwdMatcherAsync } from "../utils/canonical-path.js";
12
- import { createReadStream, rmdir as rmdir$1, stat as stat$1 } from "node:fs";
12
+ import { constants as constants$1, createReadStream, rmdir as rmdir$1, stat as stat$1 } from "node:fs";
13
13
  import { uuidv7 } from "@bastani/atomic-ai";
14
14
  import { SessionSpillError, StoragePayloadTooLargeError, describeStorageError, isStorageTransientError, isStorageWriteLockTimeoutError, isStorageWriterQueueUnusableError } from "../core/storage/errors.js";
15
15
  import { open as open$1 } from "fs/promises";
16
16
  import { createHash, randomUUID } from "node:crypto";
17
17
  import lockfile from "proper-lockfile";
18
- import { setTimeout } from "node:timers/promises";
18
+ import { setTimeout as setTimeout$1 } from "node:timers/promises";
19
19
  import { randomUUID as randomUUID$1 } from "crypto";
20
20
  import { SessionConflictError, SessionExistsError, SessionFormatVersionError, SessionFormatVersionError as SessionFormatVersionError$1, SessionIdMismatchError, SessionInvalidTextError, SessionInvalidTimestampError, SessionNotFoundError, StorageUnavailableError as StorageUnavailableError$1, StoreClosedError as StoreClosedError$1 } from "../core/storage/session/errors.js";
21
21
  import { isProxy } from "node:util/types";
@@ -3057,6 +3057,31 @@ function renameHookMessage(entry) {
3057
3057
  };
3058
3058
  }
3059
3059
  // dist/core/storage/session/jsonl-session-store.js
3060
+ /**
3061
+ * The state each session file was last recorded in by a store of this process, by path, least recently recorded first.
3062
+ * A store opening the directory again takes a file's state from here while the file's stat stamp is unchanged, rather
3063
+ * than read the file again (#6560). The stamp names the inode, the size and the change times, so a state taken from
3064
+ * here is one the file is in.
3065
+ */
3066
+ const recordedFileStates = /* @__PURE__ */ new Map();
3067
+ /** The most files {@link recordedFileStates} keeps; the least recently recorded goes first. */
3068
+ const RECORDED_FILE_STATES = 2048;
3069
+ /** How many files an open stats at once to check them against {@link recordedFileStates}. */
3070
+ const SCAN_STATS_IN_FLIGHT = 32;
3071
+ function recordFileState(path, state) {
3072
+ recordedFileStates.delete(path);
3073
+ recordedFileStates.set(path, state);
3074
+ if (recordedFileStates.size > RECORDED_FILE_STATES) recordedFileStates.delete(recordedFileStates.keys().next().value);
3075
+ }
3076
+ /**
3077
+ * Windows refuses to remove a directory that holds an open file and may refuse to replace one, so there a handle is
3078
+ * closed once its appends are written.
3079
+ */
3080
+ const KEEP_APPEND_FILES = process.platform !== "win32";
3081
+ /** How long a kept handle stays open after its last use. */
3082
+ const KEPT_FILE_IDLE_MS = 3e4;
3083
+ /** The most handles one store keeps open; the least recently used is closed first. */
3084
+ const KEPT_FILES = 16;
3060
3085
  function isForkCatalogType(type) {
3061
3086
  return type === "session_info" || type === "session_summary" || type === "branch_summary";
3062
3087
  }
@@ -3099,6 +3124,10 @@ const SCAN_WINDOW_BYTES$1 = 1048576;
3099
3124
  function witnessOf(bytes) {
3100
3125
  return Buffer.from(bytes.subarray(-64));
3101
3126
  }
3127
+ /** The witness of `witness` followed by `bytes`, copying no more of `bytes` than the witness keeps. */
3128
+ function witnessAfter(witness, bytes) {
3129
+ return bytes.length >= 64 ? witnessOf(bytes) : witnessOf(Buffer.concat([witness, bytes]));
3130
+ }
3102
3131
  /**
3103
3132
  * The entry on a last line that has no newline after it, or `undefined` when that line is torn: its writer stopped
3104
3133
  * before finishing it, so it was never acknowledged. Every entry line is a JSON object, and no part of an object's
@@ -3409,6 +3438,37 @@ async function scanSessionLines(file, size, atEnd, from, index, signal, visitor)
3409
3438
  header: false
3410
3439
  };
3411
3440
  }
3441
+ /**
3442
+ * Where the `count`th entry line before byte `end` starts, `end` being the end of an entry line: read backwards from
3443
+ * `end` a chunk at a time, each twice the last up to one scan window, as `tail -n` reads. A line of only whitespace is
3444
+ * not an entry, as {@link scanSessionLines} skips it. Undefined when the header comes first, or when a line holds no
3445
+ * visible ASCII but bytes of multi-byte characters, which only decoding it would call blank or not.
3446
+ */
3447
+ async function lineStartFromEnd(file, end, count, signal) {
3448
+ let found = 0;
3449
+ let visible = false;
3450
+ let wide = false;
3451
+ let chunkBytes = RANGE_CHUNK_BYTES;
3452
+ for (let position = end; position > 0;) {
3453
+ signal?.throwIfAborted();
3454
+ const length = Math.min(chunkBytes, position);
3455
+ const bytes = await readFrom(file, position - length, length);
3456
+ position -= length;
3457
+ for (let at = length - 1; at >= 0; at--) {
3458
+ const byte = bytes[at];
3459
+ if (byte === 10) {
3460
+ if (position + at === end - 1) continue;
3461
+ if (visible) {
3462
+ if (++found === count) return position + at + 1;
3463
+ } else if (wide) return void 0;
3464
+ visible = false;
3465
+ wide = false;
3466
+ } else if (byte > 32 && byte < 128) visible = true;
3467
+ else if (byte >= 128) wide = true;
3468
+ }
3469
+ chunkBytes = Math.min(2 * chunkBytes, SCAN_WINDOW_BYTES$1);
3470
+ }
3471
+ }
3412
3472
  /** Session files whose torn last line this process has already reported. */
3413
3473
  const reportedTornFiles = /* @__PURE__ */ new Set();
3414
3474
  function reportTornLine(path) {
@@ -3616,6 +3676,10 @@ var JsonlSessionStore = class JsonlSessionStore {
3616
3676
  };
3617
3677
  }
3618
3678
  queue = Promise.resolve();
3679
+ /** Operations queued so far, counted so an append joins only a group that is still the last thing queued. */
3680
+ queued = 0;
3681
+ appendGroup;
3682
+ keptFiles = /* @__PURE__ */ new Map();
3619
3683
  closed = false;
3620
3684
  poisoned;
3621
3685
  directory;
@@ -3662,12 +3726,53 @@ var JsonlSessionStore = class JsonlSessionStore {
3662
3726
  */
3663
3727
  static async open(directory, options) {
3664
3728
  const store = new JsonlSessionStore(directory, options?.exactDirectory === true, options?.lockFs);
3665
- if (options?.createDirectory !== false) await store.run(() => mkdir(store.directory, { recursive: true }).then(() => {}), false);
3666
- if (options?.scanExisting !== false) await store.run(async () => {
3667
- for (const path of await store.paths()) try {
3668
- await store.readSnapshot(path);
3669
- } catch {
3729
+ const create = options?.createDirectory !== false;
3730
+ if (options?.scanExisting === false) {
3731
+ if (create) await store.run(() => mkdir(store.directory, { recursive: true }).then(() => {}), false);
3732
+ return store;
3733
+ }
3734
+ const paths = await store.run(async () => {
3735
+ try {
3736
+ return await store.paths();
3737
+ } catch (cause) {
3738
+ if (cause.code !== "ENOENT" || !create) return void 0;
3739
+ await mkdir(store.directory, { recursive: true });
3740
+ return [];
3741
+ }
3742
+ }, false);
3743
+ const unread = await store.run(async () => {
3744
+ const changed = /* @__PURE__ */ new Set();
3745
+ const all = paths ?? [];
3746
+ for (let at = 0; at < all.length; at += SCAN_STATS_IN_FLIGHT) {
3747
+ const batch = all.slice(at, at + SCAN_STATS_IN_FLIGHT);
3748
+ const stamps = await Promise.all(batch.map(async (path) => {
3749
+ const recorded = recordedFileStates.get(path);
3750
+ if (recorded?.summaryState === void 0) return void 0;
3751
+ const stats = await stat(path, { bigint: true }).catch(() => void 0);
3752
+ return stats !== void 0 && store.stamp(stats) === recorded.stamp ? recorded : void 0;
3753
+ }));
3754
+ for (const [index, path] of batch.entries()) {
3755
+ const recorded = stamps[index];
3756
+ if (recorded !== void 0) store.fileStates.set(path, recorded);
3757
+ else changed.add(path);
3758
+ }
3759
+ }
3760
+ return changed;
3761
+ }, false);
3762
+ if (paths === void 0 || unread.size > 0) await store.run(async () => {
3763
+ for (const path of paths ?? await store.paths()) {
3764
+ if (paths !== void 0 && !unread.has(path)) continue;
3765
+ try {
3766
+ await store.readSnapshot(path);
3767
+ } catch {
3768
+ store.fileStates.delete(path);
3769
+ }
3770
+ }
3771
+ for (const path of paths ?? []) {
3772
+ const state = store.fileStates.get(path);
3773
+ if (state === void 0) continue;
3670
3774
  store.fileStates.delete(path);
3775
+ store.fileStates.set(path, state);
3671
3776
  }
3672
3777
  });
3673
3778
  return store;
@@ -3688,7 +3793,7 @@ var JsonlSessionStore = class JsonlSessionStore {
3688
3793
  validateSessionHeader(header);
3689
3794
  validateSessionEntries(entries);
3690
3795
  if (await this.claimed(header.id)) throw new SessionExistsError(header.id);
3691
- const payload = this.encode(header, entries);
3796
+ const payload = Buffer.from(this.encode(header, entries));
3692
3797
  const path = location === void 0 ? this.locationFor(header) : resolve$1(location);
3693
3798
  await mkdir(resolve$1(path, ".."), { recursive: true });
3694
3799
  const temporary = `${path}.${randomUUID()}.tmp`;
@@ -3834,19 +3939,113 @@ var JsonlSessionStore = class JsonlSessionStore {
3834
3939
  });
3835
3940
  }
3836
3941
  }
3942
+ /**
3943
+ * Appends made while an earlier one waits its turn join it and commit together, as a LevelDB log writer's queue does:
3944
+ * under one lock, each is checked against the session as the appends before it leave it, and each file gets one write
3945
+ * of all their lines. Every append is answered once its lines are written and the lock is released, as it was alone,
3946
+ * and one that conflicts or fails validation rejects alone. Nothing is synced, as before.
3947
+ */
3837
3948
  append(sessionId, entries, options) {
3838
- return this.run(async () => {
3839
- const { path, state } = await this.forWrite(sessionId, options);
3840
- validateSessionEntries(entries);
3841
- if (entries.length === 0) return { lastSeq: state.lastSeq };
3842
- if (state.torn) await truncate(path, state.size);
3843
- const lines = entries.map((entry) => JSON.stringify(entry));
3844
- let payload = `${lines.join("\n")}\n`;
3845
- if (!state.terminated) payload = `\n${payload}`;
3846
- const offset = state.size;
3847
- if (entries.some((entry) => entry.type === "compaction")) await copyFile(path, `${path}.${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.${randomUUID()}.compact.bak`);
3949
+ if (this.closed) return Promise.reject(new StoreClosedError$1(this.descriptor));
3950
+ return new Promise((resolve, reject) => {
3951
+ const request = {
3952
+ sessionId,
3953
+ entries,
3954
+ options,
3955
+ resolve,
3956
+ reject
3957
+ };
3958
+ const waiting = this.appendGroup;
3959
+ if (waiting !== void 0 && !waiting.started && waiting.queued === this.queued) {
3960
+ waiting.requests.push(request);
3961
+ return;
3962
+ }
3963
+ const group = {
3964
+ requests: [request],
3965
+ queued: 0,
3966
+ started: false
3967
+ };
3968
+ this.appendGroup = group;
3969
+ this.run(() => this.commitAppends(group)).then(() => {
3970
+ for (const { answer, resolve, reject } of group.requests) if (answer !== void 0 && "lastSeq" in answer) resolve(answer);
3971
+ else reject(answer?.error);
3972
+ }, (cause) => {
3973
+ for (const pending of group.requests) pending.reject(cause);
3974
+ });
3975
+ group.queued = this.queued;
3976
+ });
3977
+ }
3978
+ async commitAppends(group) {
3979
+ group.started = true;
3980
+ if (this.appendGroup === group) this.appendGroup = void 0;
3981
+ const staged = /* @__PURE__ */ new Map();
3982
+ for (const request of group.requests) try {
3983
+ await this.stageAppend(staged, request);
3984
+ } catch (cause) {
3985
+ if (this.poisoned) throw this.poisoned;
3986
+ request.answer = { error: this.failure(cause) };
3987
+ }
3988
+ for (const file of staged.values()) await this.writeStaged(file);
3989
+ }
3990
+ /** Checks one append against its session as the appends staged before it leave it, and stages its lines. */
3991
+ async stageAppend(staged, request) {
3992
+ const { sessionId, entries, options } = request;
3993
+ let file = staged.get(sessionId);
3994
+ if (file === void 0) {
3995
+ const { path, state, stats, header } = await this.forWrite(sessionId, options);
3996
+ file = {
3997
+ sessionId,
3998
+ path,
3999
+ identity: state.identity,
4000
+ epoch: epochOf(stats, JSON.stringify(header)),
4001
+ before: state,
4002
+ entries: [],
4003
+ lines: [],
4004
+ requests: []
4005
+ };
4006
+ staged.set(sessionId, file);
4007
+ } else {
4008
+ const lastSeq = file.before.lastSeq + file.entries.length;
4009
+ if (options.expectSeq !== lastSeq || options.epoch !== void 0 && options.epoch !== file.epoch) throw new SessionConflictError(sessionId, options.expectSeq, lastSeq);
4010
+ }
4011
+ validateSessionEntries(entries);
4012
+ const lines = entries.map((entry) => JSON.stringify(entry));
4013
+ if (entries.some((entry) => entry.type === "compaction")) {
4014
+ if (!await this.writeStaged(file)) {
4015
+ staged.delete(sessionId);
4016
+ throw new SessionConflictError(sessionId, options.expectSeq, file.before.lastSeq);
4017
+ }
4018
+ await copyFile(file.path, `${file.path}.${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.${randomUUID()}.compact.bak`);
4019
+ }
4020
+ for (const [index, entry] of entries.entries()) {
4021
+ file.entries.push(entry);
4022
+ file.lines.push(lines[index]);
4023
+ }
4024
+ file.requests.push({
4025
+ request,
4026
+ lastSeq: file.before.lastSeq + file.entries.length
4027
+ });
4028
+ }
4029
+ /**
4030
+ * Writes the lines staged for `file` through its kept handle, then decides the appends they came from: false when the
4031
+ * write failed and they fail. A failed write is cut off again; when that fails too the store is poisoned.
4032
+ */
4033
+ async writeStaged(file) {
4034
+ const { path, before, entries, lines, requests } = file;
4035
+ file.entries = [];
4036
+ file.lines = [];
4037
+ file.requests = [];
4038
+ if (entries.length === 0) {
4039
+ for (const { request, lastSeq } of requests) request.answer = { lastSeq };
4040
+ return true;
4041
+ }
4042
+ const offset = before.size;
4043
+ const payload = Buffer.from(`${before.terminated ? "" : "\n"}${lines.join("\n")}\n`);
4044
+ try {
4045
+ const kept = await this.keptFile(path, file.identity);
4046
+ if (before.torn) await truncate(path, before.size);
3848
4047
  try {
3849
- await appendFile(path, payload);
4048
+ await writeAll(kept.handle, payload);
3850
4049
  } catch (cause) {
3851
4050
  try {
3852
4051
  await truncate(path, offset);
@@ -3856,24 +4055,34 @@ var JsonlSessionStore = class JsonlSessionStore {
3856
4055
  }
3857
4056
  throw cause;
3858
4057
  }
3859
- const lastSeq = state.lastSeq + entries.length;
3860
- const appended = await this.remember(path, {
3861
- ...state,
3862
- lastSeq,
4058
+ const stats = await kept.handle.stat({ bigint: true });
4059
+ await this.remember(path, {
4060
+ ...before,
4061
+ lastSeq: before.lastSeq + entries.length,
3863
4062
  lastEntryId: entries.at(-1)?.id,
3864
4063
  terminated: true,
3865
4064
  torn: false,
3866
- witness: witnessOf(Buffer.concat([state.witness, Buffer.from(payload)])),
3867
- ...state.summaryState === void 0 ? {} : { summaryState: applySessionSummaryEntries(state.summaryState, entries).state }
3868
- });
4065
+ witness: witnessAfter(before.witness, payload),
4066
+ ...before.summaryState === void 0 ? {} : { summaryState: applySessionSummaryEntries(before.summaryState, entries).state }
4067
+ }, void 0, stats);
4068
+ file.before = this.fileStates.get(path);
3869
4069
  const rangeIndex = this.rangeIndexes.get(path);
3870
- if (rangeIndex?.seenStamp === state.stamp) {
3871
- rangeIndex.seenStamp = this.stamp(appended);
3872
- rangeIndex.seenSize = Number(appended.size);
4070
+ if (rangeIndex?.seenStamp === before.stamp) {
4071
+ rangeIndex.seenStamp = this.stamp(stats);
4072
+ rangeIndex.seenSize = Number(stats.size);
3873
4073
  }
3874
- await this.indexAppended(path, state, entries, lines, offset + (state.terminated ? 0 : 1));
3875
- return { lastSeq };
3876
- });
4074
+ await this.indexAppended(path, before, entries, lines, offset + (before.terminated ? 0 : 1), stats);
4075
+ if (KEEP_APPEND_FILES) this.armIdle(path, kept);
4076
+ else await this.closeKept(path);
4077
+ } catch (cause) {
4078
+ await this.closeKept(path);
4079
+ const failure = cause === this.poisoned ? cause : this.failure(cause);
4080
+ for (const { request } of requests) request.answer = { error: failure };
4081
+ if (cause === this.poisoned) throw cause;
4082
+ return false;
4083
+ }
4084
+ for (const { request, lastSeq } of requests) request.answer = { lastSeq };
4085
+ return true;
3877
4086
  }
3878
4087
  replace(sessionId, header, entries, options) {
3879
4088
  return this.run(async () => {
@@ -3913,6 +4122,7 @@ var JsonlSessionStore = class JsonlSessionStore {
3913
4122
  await output.close();
3914
4123
  }
3915
4124
  await this.forgetIndex(path);
4125
+ await this.closeKept(path);
3916
4126
  await rename(temporary, path);
3917
4127
  const headerStamp = JSON.stringify(header);
3918
4128
  const stats = await this.remember(path, {
@@ -3935,7 +4145,8 @@ var JsonlSessionStore = class JsonlSessionStore {
3935
4145
  }
3936
4146
  async commit(path, header, entries) {
3937
4147
  await this.forgetIndex(path);
3938
- const payload = this.encode(header, entries);
4148
+ await this.closeKept(path);
4149
+ const payload = Buffer.from(this.encode(header, entries));
3939
4150
  const temporary = `${path}.${randomUUID()}.tmp`;
3940
4151
  try {
3941
4152
  await writeFile(temporary, payload, { flag: "wx" });
@@ -3960,7 +4171,11 @@ var JsonlSessionStore = class JsonlSessionStore {
3960
4171
  query.signal?.throwIfAborted();
3961
4172
  const located = await this.locate(sessionId);
3962
4173
  if (!located) throw new SessionNotFoundError(sessionId);
3963
- return this.readRangeOf(located.path, query, sessionId, located.state);
4174
+ const page = await this.readRangeOf(located.path, query, sessionId, located.state);
4175
+ return {
4176
+ ...page,
4177
+ entries: onlySeqs(page.entries, query.seqs)
4178
+ };
3964
4179
  }, false, query.signal);
3965
4180
  }
3966
4181
  readFileEntryRange(path, query) {
@@ -4065,6 +4280,15 @@ var JsonlSessionStore = class JsonlSessionStore {
4065
4280
  seq: mark.seq - 1,
4066
4281
  header: false
4067
4282
  };
4283
+ const back = index.completeCount - fromSeq + 1;
4284
+ if (index.completeEnd > 0 && back < fromSeq - 1 - cursor.seq) {
4285
+ const start = await lineStartFromEnd(file, index.completeEnd, back, query.signal);
4286
+ if (start !== void 0) cursor = {
4287
+ offset: start,
4288
+ seq: fromSeq - 1,
4289
+ header: false
4290
+ };
4291
+ }
4068
4292
  }
4069
4293
  const skipTypes = query.skipTypes ?? [];
4070
4294
  let chars = 0;
@@ -4221,7 +4445,7 @@ var JsonlSessionStore = class JsonlSessionStore {
4221
4445
  const { path, jsonl } = await this.indexed(reference.sessionId);
4222
4446
  if (jsonl.index.epoch !== reference.epoch) throw new SessionConflictError(reference.sessionId, reference.seq, jsonl.index.seq);
4223
4447
  const start = spanStart(jsonl, reference.seq) + offset;
4224
- return readBytes(path, start, Math.min(SESSION_HISTORY_CHUNK_BYTES, spanEnd(jsonl, reference.seq) - start));
4448
+ return readBytes(path, start, Math.min(SESSION_HISTORY_CHUNK_BYTES, spanEnd(jsonl, reference.seq) - start), this.keptFor(path, jsonl.identity));
4225
4449
  });
4226
4450
  }
4227
4451
  readRange(sessionId, startSeq, endSeq, expectedEpoch) {
@@ -4472,8 +4696,9 @@ var JsonlSessionStore = class JsonlSessionStore {
4472
4696
  if (!located) throw new SessionNotFoundError(sessionId);
4473
4697
  if (!isCurrentSessionHeader(located.stored)) throw new SessionFormatVersionError$1(located.path, located.stored.version);
4474
4698
  }
4475
- const { path, header } = located;
4476
- const jsonl = await this.indexFor(path, header);
4699
+ const { path, header, stats } = located;
4700
+ const jsonl = await this.indexFor(path, header, stats);
4701
+ const prior = this.fileStates.get(path);
4477
4702
  await this.remember(path, {
4478
4703
  headerStamp: jsonl.headerStamp,
4479
4704
  headerId: header.id,
@@ -4481,27 +4706,28 @@ var JsonlSessionStore = class JsonlSessionStore {
4481
4706
  lastEntryId: jsonl.index.lastId ?? void 0,
4482
4707
  witness: jsonl.witness,
4483
4708
  terminated: jsonl.terminated,
4484
- torn: jsonl.torn
4485
- }, jsonl.torn ? jsonl.size : void 0);
4709
+ torn: jsonl.torn,
4710
+ ...prior?.summaryState !== void 0 && prior.stamp === this.stamp(stats) ? { summaryState: prior.summaryState } : {}
4711
+ }, jsonl.torn ? jsonl.size : void 0, stats);
4486
4712
  return {
4487
4713
  path,
4488
4714
  header,
4489
4715
  jsonl
4490
4716
  };
4491
4717
  }
4492
- async indexFor(path, header) {
4493
- const stats = await stat(path, { bigint: true });
4718
+ async indexFor(path, header, stats) {
4494
4719
  const identity = `${stats.dev}:${stats.ino}`;
4495
4720
  const headerStamp = JSON.stringify(header);
4496
4721
  const cached = this.indexes.get(path) ?? await readSidecar(path);
4497
4722
  if (cached !== void 0 && cached.identity === identity && cached.birthtimeNs === String(stats.birthtimeNs) && cached.headerStamp === headerStamp) {
4498
4723
  const fileSize = Number(stats.size);
4499
- if (cached.fileSize === fileSize && cached.mtimeNs === String(stats.mtimeNs) && await witnessHolds(path, cached)) {
4724
+ const kept = this.keptFor(path, identity);
4725
+ if (cached.fileSize === fileSize && cached.mtimeNs === String(stats.mtimeNs) && await witnessHolds(path, cached, kept)) {
4500
4726
  this.indexes.set(path, cached);
4501
4727
  return cached;
4502
4728
  }
4503
- if (fileSize > cached.size && await witnessHolds(path, cached)) {
4504
- const grown = await this.catchUp(path, cached, stats);
4729
+ if (fileSize > cached.size && await witnessHolds(path, cached, kept)) {
4730
+ const grown = await this.catchUp(path, cached, stats, kept);
4505
4731
  if (grown !== void 0) return this.keepIndex(path, grown);
4506
4732
  }
4507
4733
  }
@@ -4525,6 +4751,16 @@ var JsonlSessionStore = class JsonlSessionStore {
4525
4751
  * again, for a reader of positions that never selects a window. */
4526
4752
  async buildIndex(path, headerStamp, stats, input, folded) {
4527
4753
  const identity = `${stats.dev}:${stats.ino}`;
4754
+ if (input === void 0) {
4755
+ const kept = this.keptFor(path, identity);
4756
+ if (kept !== void 0) return this.buildIndex(path, headerStamp, stats, { handle: kept }, folded);
4757
+ const handle = await open(path, "r");
4758
+ try {
4759
+ return await this.buildIndex(path, headerStamp, stats, { handle }, folded);
4760
+ } finally {
4761
+ await handle.close();
4762
+ }
4763
+ }
4528
4764
  const birthtimeNs = String(stats.birthtimeNs);
4529
4765
  const epoch = epochOf(stats, headerStamp);
4530
4766
  const topology = folded?.topology ?? await this.foldFile(path, epoch, () => true, input);
@@ -4537,7 +4773,7 @@ var JsonlSessionStore = class JsonlSessionStore {
4537
4773
  fileSize: Number(stats.size),
4538
4774
  mtimeNs: String(stats.mtimeNs),
4539
4775
  size: active.size,
4540
- witness: input ? await readFrom(input.handle, Math.max(0, active.size - WITNESS_BYTES), Math.min(active.size, WITNESS_BYTES)) : await readWitness(path, active.size),
4776
+ witness: await readFrom(input.handle, Math.max(0, active.size - WITNESS_BYTES), Math.min(active.size, WITNESS_BYTES)),
4541
4777
  terminated: active.terminated,
4542
4778
  torn: active.torn,
4543
4779
  spans: active.spans,
@@ -4606,10 +4842,10 @@ var JsonlSessionStore = class JsonlSessionStore {
4606
4842
  if (!pinned) await file.close();
4607
4843
  }
4608
4844
  }
4609
- async catchUp(path, cached, stats) {
4845
+ async catchUp(path, cached, stats, kept) {
4610
4846
  const from = cached.size - cached.witness.length;
4611
4847
  if (Number(stats.size) - from > SCAN_WINDOW_BYTES$1) return this.streamCatchUp(path, cached, stats);
4612
- const bytes = await readBytes(path, from, Number(stats.size) - from);
4848
+ const bytes = await readBytes(path, from, Number(stats.size) - from, kept);
4613
4849
  let offset = cached.size;
4614
4850
  let appended = bytes.subarray(cached.witness.length);
4615
4851
  if (appended.length > 0 && !cached.terminated) {
@@ -4653,7 +4889,7 @@ var JsonlSessionStore = class JsonlSessionStore {
4653
4889
  fileSize: Number(stats.size),
4654
4890
  mtimeNs: String(stats.mtimeNs),
4655
4891
  size,
4656
- witness: witnessOf(Buffer.concat([cached.witness, appended.subarray(0, size - offset)])),
4892
+ witness: witnessAfter(cached.witness, appended.subarray(0, size - offset)),
4657
4893
  terminated: appended.length === 0 ? cached.terminated : terminated,
4658
4894
  torn,
4659
4895
  spans,
@@ -4739,7 +4975,7 @@ var JsonlSessionStore = class JsonlSessionStore {
4739
4975
  }
4740
4976
  return foldSessionResume(cached.index, entries, (id) => seqs.get(id));
4741
4977
  }
4742
- async indexAppended(path, before, entries, lines, firstLine) {
4978
+ async indexAppended(path, before, entries, lines, firstLine, stats) {
4743
4979
  const cached = this.indexes.get(path);
4744
4980
  if (cached === void 0 || cached.identity !== before.identity || cached.size !== before.size || cached.index.seq !== before.lastSeq || resumeIndexNeedsRefold(cached.index, entries)) {
4745
4981
  this.indexes.delete(path);
@@ -4753,7 +4989,6 @@ var JsonlSessionStore = class JsonlSessionStore {
4753
4989
  position += length + 1;
4754
4990
  }
4755
4991
  const state = this.fileStates.get(path);
4756
- const stats = await stat(path, { bigint: true });
4757
4992
  const next = {
4758
4993
  ...cached,
4759
4994
  fileSize: Number(stats.size),
@@ -4774,7 +5009,8 @@ var JsonlSessionStore = class JsonlSessionStore {
4774
5009
  const wanted = [...new Set(seqs.filter((seq) => seq >= 1 && seq <= jsonl.index.seq))].sort((a, b) => a - b);
4775
5010
  const entries = [];
4776
5011
  if (wanted.length === 0) return entries;
4777
- const file = input?.handle ?? await open(path, "r");
5012
+ const kept = input === void 0 ? this.keptFor(path, jsonl.identity) : void 0;
5013
+ const file = input?.handle ?? kept ?? await open(path, "r");
4778
5014
  try {
4779
5015
  if (exactRevision && !matchesIndexRevision(await file.stat({ bigint: true }), jsonl)) return [];
4780
5016
  let index = 0;
@@ -4805,7 +5041,7 @@ var JsonlSessionStore = class JsonlSessionStore {
4805
5041
  }
4806
5042
  if (exactRevision && !matchesIndexRevision(await file.stat({ bigint: true }), jsonl)) return [];
4807
5043
  } finally {
4808
- if (!input) await file.close();
5044
+ if (!input && !kept) await file.close();
4809
5045
  }
4810
5046
  return entries;
4811
5047
  }
@@ -4817,7 +5053,8 @@ var JsonlSessionStore = class JsonlSessionStore {
4817
5053
  for (let seq = 1; seq <= total; seq++) if (jsonl.ids[seq - 1] === hash) candidates.push(seq);
4818
5054
  const oversized = (seq) => spanEnd(jsonl, seq) - spanStart(jsonl, seq) > SCAN_WINDOW_BYTES$1;
4819
5055
  if (!candidates.some(oversized)) return (await this.entriesAt(path, jsonl, candidates, pinned ? { handle: pinned } : void 0)).findLast((held) => held.entry.id === entryId)?.seq;
4820
- const file = pinned ?? await open(path, "r");
5056
+ const kept = pinned ? void 0 : this.keptFor(path, jsonl.identity);
5057
+ const file = pinned ?? kept ?? await open(path, "r");
4821
5058
  try {
4822
5059
  for (let at = candidates.length - 1; at >= 0; at--) {
4823
5060
  const seq = candidates[at];
@@ -4826,7 +5063,7 @@ var JsonlSessionStore = class JsonlSessionStore {
4826
5063
  if ((oversized(seq) ? (await jsonlEntryProjection(readChunks(file, start, end)))?.entry : JSON.parse((await readFrom(file, start, end - start)).toString("utf8")))?.id === entryId) return seq;
4827
5064
  }
4828
5065
  } finally {
4829
- if (!pinned) await file.close();
5066
+ if (!pinned && !kept) await file.close();
4830
5067
  }
4831
5068
  }
4832
5069
  async readPersisted(path, stored) {
@@ -4856,6 +5093,7 @@ var JsonlSessionStore = class JsonlSessionStore {
4856
5093
  id: sessionId,
4857
5094
  epoch: epochOf(located.stats, JSON.stringify(located.header))
4858
5095
  };
5096
+ await this.closeKept(located.path);
4859
5097
  await unlink(located.path);
4860
5098
  this.fileStates.delete(located.path);
4861
5099
  await this.forgetIndex(located.path);
@@ -4944,23 +5182,84 @@ var JsonlSessionStore = class JsonlSessionStore {
4944
5182
  close() {
4945
5183
  if (this.closed) return Promise.reject(new StoreClosedError$1(this.descriptor));
4946
5184
  this.closed = true;
4947
- return this.queue;
5185
+ return this.queue.then(async () => {
5186
+ for (const path of [...this.keptFiles.keys()]) await this.closeKept(path);
5187
+ });
5188
+ }
5189
+ /** Closes the handles kept for the session's files: nothing live writes it any more. */
5190
+ releaseSession(sessionId) {
5191
+ if (this.closed) return Promise.resolve();
5192
+ return this.run(async () => {
5193
+ for (const [path, state] of this.fileStates) if (state.headerId === sessionId) await this.closeKept(path);
5194
+ }, false);
5195
+ }
5196
+ /**
5197
+ * The handle kept open to append to the file at `path`, opened when there is none for the file `identity` names. It
5198
+ * is used only while the caller holds the directory lock and has found that the path still names that file.
5199
+ */
5200
+ async keptFile(path, identity) {
5201
+ const kept = this.keptFiles.get(path);
5202
+ if (kept?.identity === identity) {
5203
+ this.keptFiles.delete(path);
5204
+ this.keptFiles.set(path, kept);
5205
+ return kept;
5206
+ }
5207
+ await this.closeKept(path);
5208
+ const opened = {
5209
+ handle: await open(path, constants$1.O_RDWR | constants$1.O_APPEND),
5210
+ identity,
5211
+ idle: void 0,
5212
+ armed: 0
5213
+ };
5214
+ this.keptFiles.set(path, opened);
5215
+ while (this.keptFiles.size > KEPT_FILES) await this.closeKept(this.keptFiles.keys().next().value);
5216
+ return opened;
5217
+ }
5218
+ /** The kept handle of the file at `path`, while it is the file `identity` names, to read through. */
5219
+ keptFor(path, identity) {
5220
+ const kept = this.keptFiles.get(path);
5221
+ if (kept?.identity !== identity) return void 0;
5222
+ this.armIdle(path, kept);
5223
+ return kept.handle;
5224
+ }
5225
+ async closeKept(path) {
5226
+ const kept = this.keptFiles.get(path);
5227
+ if (kept === void 0) return;
5228
+ this.keptFiles.delete(path);
5229
+ clearTimeout(kept.idle);
5230
+ await kept.handle.close().catch(() => void 0);
5231
+ }
5232
+ /** Closes the handle once it goes unused for {@link KEPT_FILE_IDLE_MS}, between two of this store's operations. */
5233
+ armIdle(path, kept) {
5234
+ clearTimeout(kept.idle);
5235
+ const armed = ++kept.armed;
5236
+ kept.idle = setTimeout(() => {
5237
+ this.queue = this.queue.then(async () => {
5238
+ if (this.keptFiles.get(path) === kept && kept.armed === armed) await this.closeKept(path);
5239
+ });
5240
+ }, KEPT_FILE_IDLE_MS);
5241
+ kept.idle.unref();
4948
5242
  }
4949
5243
  run(operation, locked = true, signal) {
4950
5244
  if (this.closed) return Promise.reject(new StoreClosedError$1(this.descriptor));
5245
+ this.queued++;
4951
5246
  const result = this.queue.then(async () => {
4952
5247
  if (this.poisoned) throw this.poisoned;
4953
5248
  try {
4954
5249
  return await (locked ? this.exclusive(operation, signal) : operation());
4955
5250
  } catch (cause) {
4956
5251
  if (signal?.aborted && cause === signal.reason) throw cause;
4957
- if (cause instanceof SessionConflictError || cause instanceof SessionExistsError || cause instanceof SessionNotFoundError || cause instanceof SessionIdMismatchError || cause instanceof SessionInvalidTextError || cause instanceof SessionInvalidTimestampError || cause instanceof SessionFormatVersionError$1 || cause instanceof JsonlStoragePoisonedError || cause instanceof DOMException) throw cause;
4958
- throw new StorageUnavailableError$1(this.descriptor, cause);
5252
+ throw this.failure(cause);
4959
5253
  }
4960
5254
  });
4961
5255
  this.queue = result.then(() => {}, () => {});
4962
5256
  return result;
4963
5257
  }
5258
+ /** What an operation rejects with for `cause`: the session errors as they are, any other as the store unavailable. */
5259
+ failure(cause) {
5260
+ if (cause instanceof SessionConflictError || cause instanceof SessionExistsError || cause instanceof SessionNotFoundError || cause instanceof SessionIdMismatchError || cause instanceof SessionInvalidTextError || cause instanceof SessionInvalidTimestampError || cause instanceof SessionFormatVersionError$1 || cause instanceof JsonlStoragePoisonedError || cause instanceof DOMException) return cause;
5261
+ return new StorageUnavailableError$1(this.descriptor, cause);
5262
+ }
4964
5263
  async exclusive(operation, signal, directory = this.directory) {
4965
5264
  const lockfilePath = join$1(directory, ".session.lock");
4966
5265
  let release;
@@ -4970,6 +5269,7 @@ var JsonlSessionStore = class JsonlSessionStore {
4970
5269
  try {
4971
5270
  release = await lockfile.lock(directory, {
4972
5271
  lockfilePath,
5272
+ realpath: false,
4973
5273
  ...this.lockFs ? { fs: this.lockFs } : {},
4974
5274
  onCompromised: (cause) => {
4975
5275
  this.poisoned = new StorageUnavailableError$1(this.descriptor, cause);
@@ -4979,12 +5279,12 @@ var JsonlSessionStore = class JsonlSessionStore {
4979
5279
  } catch (cause) {
4980
5280
  const code = cause.code;
4981
5281
  if (code === "EPERM" && process.platform === "win32" && refusals < LOCK_BACKOFF_MS.length) {
4982
- await setTimeout(LOCK_BACKOFF_MS[refusals++]);
5282
+ await setTimeout$1(LOCK_BACKOFF_MS[refusals++]);
4983
5283
  continue;
4984
5284
  }
4985
5285
  if (code !== "ELOCKED") throw cause;
4986
5286
  if (await this.clearUnreleased(lockfilePath)) continue;
4987
- await setTimeout(5);
5287
+ await setTimeout$1(5);
4988
5288
  }
4989
5289
  }
4990
5290
  let result;
@@ -5017,7 +5317,7 @@ var JsonlSessionStore = class JsonlSessionStore {
5017
5317
  if (!TRANSIENT_RELEASE_CODES.has(cause.code ?? "")) throw cause;
5018
5318
  }
5019
5319
  for (const wait of LOCK_BACKOFF_MS) {
5020
- await setTimeout(wait);
5320
+ await setTimeout$1(wait);
5021
5321
  try {
5022
5322
  await removeDirectory(fs, lockfilePath);
5023
5323
  return;
@@ -5133,6 +5433,24 @@ var JsonlSessionStore = class JsonlSessionStore {
5133
5433
  if (cached.headerId !== sessionId) continue;
5134
5434
  const parent = dirname$1(path);
5135
5435
  if (parent !== this.directory && (this.exactDirectory || dirname$1(parent) !== this.directory)) return void 0;
5436
+ const kept = this.keptFiles.get(path);
5437
+ const current = kept && await stat(path, { bigint: true }).catch(() => void 0);
5438
+ if (current !== void 0 && `${current.dev}:${current.ino}` === kept?.identity) {
5439
+ const stored = await readFirstLineFrom(kept.handle, headerLineBytes(cached.headerStamp), 0).catch(() => void 0);
5440
+ if (stored === void 0) return void 0;
5441
+ if (stored.id !== sessionId) {
5442
+ this.fileStates.delete(path);
5443
+ return;
5444
+ }
5445
+ this.armIdle(path, kept);
5446
+ return {
5447
+ path,
5448
+ header: await this.readHeaderAt(path, stored),
5449
+ stored,
5450
+ stats: current,
5451
+ state: cached
5452
+ };
5453
+ }
5136
5454
  let stored;
5137
5455
  try {
5138
5456
  stored = await this.readFirstLine(path, headerLineBytes(cached.headerStamp));
@@ -5225,9 +5543,9 @@ var JsonlSessionStore = class JsonlSessionStore {
5225
5543
  const newline = bytes.lastIndexOf(10);
5226
5544
  if (newline !== -1) {
5227
5545
  complete = size + newline + 1;
5228
- completeWitness = witnessOf(Buffer.concat([witness, bytes.subarray(0, newline + 1)]));
5546
+ completeWitness = witnessAfter(witness, bytes.subarray(0, newline + 1));
5229
5547
  }
5230
- witness = witnessOf(Buffer.concat([witness, bytes]));
5548
+ witness = witnessAfter(witness, bytes);
5231
5549
  size += bytes.length;
5232
5550
  });
5233
5551
  const entries = [];
@@ -5276,16 +5594,19 @@ var JsonlSessionStore = class JsonlSessionStore {
5276
5594
  lastSeq: entries.length,
5277
5595
  headerId: header.id,
5278
5596
  lastEntryId: entries.at(-1)?.id,
5279
- terminated: content.endsWith("\n"),
5597
+ terminated: content.at(-1) === 10,
5280
5598
  torn: false,
5281
- witness: witnessOf(Buffer.from(content)),
5599
+ witness: witnessOf(content),
5282
5600
  summaryState: applySessionSummaryEntries(void 0, entries).state
5283
5601
  };
5284
5602
  }
5285
- /** Records the file as it is now; `size` ends it before a torn last line. */
5286
- async remember(path, state, size) {
5287
- const stats = await stat(path, { bigint: true });
5288
- this.fileStates.set(path, {
5603
+ /**
5604
+ * Records the file as it is now; `size` ends it before a torn last line. `stats` are the file's, taken since its last
5605
+ * change, when the caller has them.
5606
+ */
5607
+ async remember(path, state, size, stats) {
5608
+ stats ??= await stat(path, { bigint: true });
5609
+ this.keepFileState(path, {
5289
5610
  ...state,
5290
5611
  stamp: this.stamp(stats),
5291
5612
  identity: `${stats.dev}:${stats.ino}`,
@@ -5293,6 +5614,10 @@ var JsonlSessionStore = class JsonlSessionStore {
5293
5614
  });
5294
5615
  return stats;
5295
5616
  }
5617
+ keepFileState(path, state) {
5618
+ this.fileStates.set(path, state);
5619
+ recordFileState(path, state);
5620
+ }
5296
5621
  /**
5297
5622
  * Foreign appends read only the header, at most 64 known boundary bytes, and new bytes.
5298
5623
  * The witness detects a changed append boundary, not arbitrary edits in old history.
@@ -5351,13 +5676,15 @@ var JsonlSessionStore = class JsonlSessionStore {
5351
5676
  witness: witnessOf(bytes.subarray(0, end)),
5352
5677
  ...state.summaryState === void 0 ? {} : { summaryState: applySessionSummaryEntries(state.summaryState, entries).state }
5353
5678
  };
5354
- this.fileStates.set(path, state);
5679
+ this.keepFileState(path, state);
5355
5680
  }
5356
5681
  }
5357
5682
  if (state.lastSeq !== options.expectSeq || options.epoch !== void 0 && epochOf(stats, JSON.stringify(header)) !== options.epoch) throw new SessionConflictError(sessionId, options.expectSeq, state.lastSeq);
5358
5683
  return {
5359
5684
  path,
5360
- state
5685
+ state,
5686
+ stats,
5687
+ header
5361
5688
  };
5362
5689
  }
5363
5690
  encode(header, entries) {
@@ -5422,6 +5749,15 @@ async function readFrom(file, position, length) {
5422
5749
  }
5423
5750
  return bytes;
5424
5751
  }
5752
+ /** Node's own write size for a file: a larger payload is written a slice at a time, as `appendFile` writes it. */
5753
+ const WRITE_SLICE_BYTES = 524288;
5754
+ /** Writes all of `bytes` at the end of the file `file` was opened to append to. */
5755
+ async function writeAll(file, bytes) {
5756
+ for (let at = 0; at < bytes.length;) {
5757
+ const { bytesWritten } = await file.write(bytes, at, Math.min(WRITE_SLICE_BYTES, bytes.length - at));
5758
+ at += bytesWritten;
5759
+ }
5760
+ }
5425
5761
  async function readFirstLineFrom(file, firstReadBytes, start = null) {
5426
5762
  const chunks = [];
5427
5763
  let position = start;
@@ -5437,7 +5773,8 @@ async function readFirstLineFrom(file, firstReadBytes, start = null) {
5437
5773
  const value = JSON.parse(Buffer.concat(chunks).toString("utf8"));
5438
5774
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
5439
5775
  }
5440
- async function readBytes(path, position, length) {
5776
+ async function readBytes(path, position, length, kept) {
5777
+ if (kept !== void 0) return readFrom(kept, position, length);
5441
5778
  const file = await open(path, "r");
5442
5779
  try {
5443
5780
  return await readFrom(file, position, length);
@@ -5445,13 +5782,13 @@ async function readBytes(path, position, length) {
5445
5782
  await file.close();
5446
5783
  }
5447
5784
  }
5448
- async function readWitness(path, size) {
5785
+ async function readWitness(path, size, kept) {
5449
5786
  const from = Math.max(0, size - 64);
5450
- return readBytes(path, from, size - from);
5787
+ return readBytes(path, from, size - from, kept);
5451
5788
  }
5452
- async function witnessHolds(path, jsonl) {
5789
+ async function witnessHolds(path, jsonl, kept) {
5453
5790
  try {
5454
- return (await readWitness(path, jsonl.size)).equals(jsonl.witness);
5791
+ return (await readWitness(path, jsonl.size, kept)).equals(jsonl.witness);
5455
5792
  } catch {
5456
5793
  return false;
5457
5794
  }
@@ -6495,7 +6832,7 @@ var MemorySessionStore = class MemorySessionStore {
6495
6832
  if (entries === void 0) continue;
6496
6833
  return {
6497
6834
  lastSeq,
6498
- entries,
6835
+ entries: onlySeqs(entries, query.seqs),
6499
6836
  throughSeq
6500
6837
  };
6501
6838
  }
@@ -6594,7 +6931,7 @@ var MemorySessionStore = class MemorySessionStore {
6594
6931
  directory: record.directory,
6595
6932
  file: record.file,
6596
6933
  spilledBytes: record.spilledBytes,
6597
- blocks: [...record.blocks],
6934
+ blocks: record.blocks,
6598
6935
  chunks: [...record.entries],
6599
6936
  lastSeq: record.lastSeq,
6600
6937
  totalBytes: record.totalBytes
@@ -8023,7 +8360,7 @@ function __atomicOnDemandFailed(error, feature) {
8023
8360
  return (async () => {
8024
8361
  const root = new URL("../", import.meta.url);
8025
8362
  const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
8026
- const key = `${root.href}#0.10.10`;
8363
+ const key = `${root.href}#0.10.11-alpha.2`;
8027
8364
  let release = releases.get(key);
8028
8365
  if (release === undefined) {
8029
8366
  const current = (async () => {
@@ -8051,7 +8388,7 @@ function __atomicOnDemandFailed(error, feature) {
8051
8388
  } catch {
8052
8389
  // No installation to read, as in a bundle of the package: the release the process runs decides.
8053
8390
  }
8054
- const updatedTo = typeof installed === "string" && installed !== "0.10.10" ? installed : running !== undefined && running.version !== "0.10.10" ? "0.10.10" : undefined;
8391
+ const updatedTo = typeof installed === "string" && installed !== "0.10.11-alpha.2" ? installed : running !== undefined && running.version !== "0.10.11-alpha.2" ? "0.10.11-alpha.2" : undefined;
8055
8392
  if (updatedTo === undefined) throw error;
8056
8393
  const application = typeof running?.name === "string" ? running.name : "atomic";
8057
8394
  const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {