@sema-agent/core 7.60.0 → 7.61.0

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 (482) hide show
  1. package/CHANGELOG.md +605 -0
  2. package/README.md +2 -2
  3. package/dist/agents/agent-transcript-tool.d.ts +2 -2
  4. package/dist/agents/agent-transcript-tool.js +1 -1
  5. package/dist/agents/cascade.d.ts +61 -10
  6. package/dist/agents/cascade.js +60 -20
  7. package/dist/agents/composition-allowance.d.ts +53 -0
  8. package/dist/agents/composition-allowance.js +49 -0
  9. package/dist/agents/composition-placement.d.ts +29 -0
  10. package/dist/agents/composition-placement.js +24 -0
  11. package/dist/agents/cumulative-stats.d.ts +4 -0
  12. package/dist/agents/cumulative-stats.js +3 -0
  13. package/dist/agents/inherited-tool-pool.d.ts +5 -3
  14. package/dist/agents/inherited-tool-pool.js +2 -2
  15. package/dist/agents/list-agents-tool.d.ts +1 -1
  16. package/dist/agents/peer-notice-route.d.ts +1 -1
  17. package/dist/agents/peer-notice-route.js +4 -3
  18. package/dist/agents/peer-notices.d.ts +4 -4
  19. package/dist/agents/peer-notices.js +8 -4
  20. package/dist/agents/peer-session-drain.d.ts +8 -1
  21. package/dist/agents/peer-session-drain.js +36 -7
  22. package/dist/agents/repair-loop.js +16 -6
  23. package/dist/agents/retain-ledger.js +3 -1
  24. package/dist/agents/roster-store.d.ts +1 -1
  25. package/dist/agents/roster-store.js +7 -4
  26. package/dist/agents/send-message-tool.d.ts +8 -10
  27. package/dist/agents/send-message-tool.js +43 -23
  28. package/dist/agents/subagent-completion-gate.d.ts +35 -0
  29. package/dist/agents/subagent-completion-gate.js +62 -0
  30. package/dist/agents/subagent-steps.d.ts +7 -6
  31. package/dist/agents/subagent.d.ts +30 -40
  32. package/dist/agents/subagent.js +187 -196
  33. package/dist/agents/suspend-guard.d.ts +9 -0
  34. package/dist/agents/suspend-guard.js +4 -0
  35. package/dist/agents/verify.d.ts +41 -14
  36. package/dist/agents/verify.js +37 -27
  37. package/dist/brain/anthropic.js +1 -0
  38. package/dist/brain/errors.d.ts +7 -1
  39. package/dist/brain/errors.js +6 -0
  40. package/dist/brain/failover.js +2 -1
  41. package/dist/brain/open-responses.js +1 -0
  42. package/dist/brain/openai.js +1 -0
  43. package/dist/brain/provider-dialect.d.ts +10 -0
  44. package/dist/brain/provider-dialect.js +13 -2
  45. package/dist/brain/stream-engine.d.ts +3 -0
  46. package/dist/brain/stream-engine.js +4 -0
  47. package/dist/core/agent-state.d.ts +1 -1
  48. package/dist/core/allow-entry.d.ts +59 -23
  49. package/dist/core/allow-entry.js +131 -38
  50. package/dist/core/ask-origin.d.ts +79 -0
  51. package/dist/core/ask-origin.js +76 -0
  52. package/dist/core/ask-question.d.ts +19 -13
  53. package/dist/core/ask-question.js +8 -2
  54. package/dist/core/auto-compaction.d.ts +2 -0
  55. package/dist/core/auto-compaction.js +2 -1
  56. package/dist/core/auto-mode.js +3 -5
  57. package/dist/core/background-agent-store.d.ts +7 -5
  58. package/dist/core/background-agent-store.js +12 -11
  59. package/dist/core/checkpoint-requirements.d.ts +24 -3
  60. package/dist/core/checkpoint-requirements.js +9 -1
  61. package/dist/core/checkpoint-store.d.ts +78 -19
  62. package/dist/core/checkpoint-store.js +8 -4
  63. package/dist/core/child-clamp-seats.d.ts +3 -2
  64. package/dist/core/child-clamp-seats.js +4 -3
  65. package/dist/core/closest-name.d.ts +13 -0
  66. package/dist/core/closest-name.js +35 -0
  67. package/dist/core/context-settings.js +3 -5
  68. package/dist/core/cross-boundary-taint.d.ts +1 -1
  69. package/dist/core/decision-receipt.d.ts +14 -1
  70. package/dist/core/decision-receipt.js +6 -3
  71. package/dist/core/delegation-frames.d.ts +13 -9
  72. package/dist/core/effective-path-target.js +2 -3
  73. package/dist/core/engine-attestation.d.ts +11 -1
  74. package/dist/core/engine-attestation.js +2 -0
  75. package/dist/core/engine-notice.d.ts +49 -18
  76. package/dist/core/file-history-retention.d.ts +8 -0
  77. package/dist/core/file-history-retention.js +14 -11
  78. package/dist/core/file-history-store.d.ts +31 -1
  79. package/dist/core/file-history-store.js +31 -2
  80. package/dist/core/frame-settlement.d.ts +10 -0
  81. package/dist/core/frame-settlement.js +6 -1
  82. package/dist/core/fs-write-gate-policy.d.ts +3 -3
  83. package/dist/core/fs-write-gate-policy.js +8 -7
  84. package/dist/core/gate-fold.js +2 -1
  85. package/dist/core/gate-lanes.js +7 -4
  86. package/dist/core/gate-outcome.d.ts +40 -1
  87. package/dist/core/gate-outcome.js +10 -0
  88. package/dist/core/git-worktree-env.d.ts +7 -3
  89. package/dist/core/git-worktree-env.js +16 -13
  90. package/dist/core/governance-codes.d.ts +12 -4
  91. package/dist/core/governance-codes.js +16 -4
  92. package/dist/core/hooks.d.ts +12 -4
  93. package/dist/core/hooks.js +11 -4
  94. package/dist/core/host-floor.js +3 -5
  95. package/dist/core/image-admission.d.ts +48 -8
  96. package/dist/core/image-admission.js +35 -4
  97. package/dist/core/input-author.d.ts +36 -0
  98. package/dist/core/input-author.js +39 -0
  99. package/dist/core/leg-identity.d.ts +62 -0
  100. package/dist/core/leg-identity.js +18 -0
  101. package/dist/core/locked-config.d.ts +2 -1
  102. package/dist/core/locked-config.js +5 -3
  103. package/dist/core/lsp.d.ts +5 -3
  104. package/dist/core/lsp.js +3 -2
  105. package/dist/core/mailbox-store.d.ts +85 -10
  106. package/dist/core/mailbox-store.js +31 -10
  107. package/dist/core/mcp-connection-pool.d.ts +6 -20
  108. package/dist/core/mcp-connection-pool.js +10 -28
  109. package/dist/core/mcp-failure.d.ts +76 -15
  110. package/dist/core/mcp-failure.js +60 -33
  111. package/dist/core/mcp-host-seat.d.ts +92 -53
  112. package/dist/core/mcp-host-seat.js +220 -46
  113. package/dist/core/mcp-probe.js +2 -2
  114. package/dist/core/mcp-server-link.d.ts +18 -6
  115. package/dist/core/mcp-server-link.js +19 -4
  116. package/dist/core/mcp-server-spec.d.ts +2 -1
  117. package/dist/core/mcp-session-end.d.ts +1 -2
  118. package/dist/core/mcp-session-end.js +1 -1
  119. package/dist/core/mcp.d.ts +6 -49
  120. package/dist/core/mcp.js +115 -111
  121. package/dist/core/media-byte-cap.d.ts +21 -46
  122. package/dist/core/media-byte-cap.js +55 -55
  123. package/dist/core/member-group.d.ts +7 -0
  124. package/dist/core/member-group.js +35 -0
  125. package/dist/core/memory-engine/consolidation.d.ts +1 -1
  126. package/dist/core/memory-engine/consolidation.js +7 -1
  127. package/dist/core/memory-engine/dual-root.d.ts +31 -0
  128. package/dist/core/memory-engine/dual-root.js +59 -11
  129. package/dist/core/memory-engine/engine.js +27 -24
  130. package/dist/core/memory-engine/file-backend.d.ts +13 -0
  131. package/dist/core/memory-engine/file-backend.js +35 -15
  132. package/dist/core/memory-engine/layout.d.ts +3 -0
  133. package/dist/core/memory-engine/layout.js +13 -3
  134. package/dist/core/memory-engine/memory-deployment.d.ts +110 -0
  135. package/dist/core/memory-engine/memory-deployment.js +182 -0
  136. package/dist/core/memory-engine/sync-client.d.ts +39 -18
  137. package/dist/core/memory-engine/sync-client.js +72 -14
  138. package/dist/core/memory-engine/sync-report.d.ts +7 -4
  139. package/dist/core/memory-engine/sync.d.ts +9 -1
  140. package/dist/core/mode-policy.d.ts +8 -8
  141. package/dist/core/mode-policy.js +7 -5
  142. package/dist/core/mods/agent-stations.d.ts +39 -4
  143. package/dist/core/mods/agent-stations.js +59 -10
  144. package/dist/core/mods/dollar.d.ts +62 -0
  145. package/dist/core/mods/extension-call.d.ts +15 -1
  146. package/dist/core/mods/extension-call.js +7 -2
  147. package/dist/core/mods/kernel/dispatch.d.ts +4 -3
  148. package/dist/core/mods/kernel/dispatch.js +4 -4
  149. package/dist/core/mods/kernel/events.d.ts +4 -1
  150. package/dist/core/mods/kernel/events.js +6 -6
  151. package/dist/core/mods/kernel/registration.d.ts +3 -0
  152. package/dist/core/mods/kernel/registration.js +5 -0
  153. package/dist/core/mods/kernel/site-rules.d.ts +6 -3
  154. package/dist/core/mods/kernel/site-rules.js +10 -2
  155. package/dist/core/mods/session-append.d.ts +115 -0
  156. package/dist/core/mods/session-append.js +311 -0
  157. package/dist/core/mods/session-compact.d.ts +48 -0
  158. package/dist/core/mods/session-compact.js +194 -0
  159. package/dist/core/mods/session-receive.d.ts +93 -0
  160. package/dist/core/mods/session-receive.js +141 -0
  161. package/dist/core/mods/session-send.d.ts +72 -0
  162. package/dist/core/mods/session-send.js +88 -0
  163. package/dist/core/mods/stations.d.ts +38 -16
  164. package/dist/core/mods/stations.js +25 -11
  165. package/dist/core/mods/tool-call.d.ts +2 -0
  166. package/dist/core/mods/tool-call.js +4 -4
  167. package/dist/core/output-style.js +3 -4
  168. package/dist/core/own-property-receipt.d.ts +61 -2
  169. package/dist/core/own-property-receipt.js +42 -2
  170. package/dist/core/park-selfcheck.js +4 -2
  171. package/dist/core/path-identity.d.ts +11 -0
  172. package/dist/core/path-identity.js +4 -0
  173. package/dist/core/path-rule-binding.d.ts +3 -1
  174. package/dist/core/path-rule-binding.js +3 -1
  175. package/dist/core/peer-seat.d.ts +3 -3
  176. package/dist/core/peer-seat.js +20 -8
  177. package/dist/core/permission-rule-consent.d.ts +21 -5
  178. package/dist/core/permission-rule-consent.js +21 -1
  179. package/dist/core/permission-rule-model.d.ts +34 -11
  180. package/dist/core/permission-rule-model.js +47 -10
  181. package/dist/core/permission-rule-org.d.ts +1 -1
  182. package/dist/core/permission-rule-provider.js +4 -1
  183. package/dist/core/permission-rules.d.ts +4 -0
  184. package/dist/core/permission-rules.js +11 -16
  185. package/dist/core/remote-env.d.ts +74 -26
  186. package/dist/core/remote-env.js +20 -0
  187. package/dist/core/retention-policy.d.ts +24 -23
  188. package/dist/core/retention-policy.js +36 -2
  189. package/dist/core/retention.d.ts +4 -1
  190. package/dist/core/retired-keys.d.ts +4 -4
  191. package/dist/core/row-admission.d.ts +10 -0
  192. package/dist/core/row-admission.js +5 -0
  193. package/dist/core/runner/advisor-instructions.d.ts +2 -1
  194. package/dist/core/runner/advisor-instructions.js +2 -1
  195. package/dist/core/runner/announce-once-ledger.d.ts +4 -4
  196. package/dist/core/runner/assemble-result.d.ts +13 -3
  197. package/dist/core/runner/assemble-result.js +12 -7
  198. package/dist/core/runner/caller-roster.d.ts +12 -9
  199. package/dist/core/runner/caller-roster.js +5 -2
  200. package/dist/core/runner/checkpoint-scope.d.ts +16 -1
  201. package/dist/core/runner/checkpoint-scope.js +21 -0
  202. package/dist/core/runner/compact-session.js +14 -2
  203. package/dist/core/runner/compaction-call-options.d.ts +1 -1
  204. package/dist/core/runner/compaction-restate.d.ts +2 -2
  205. package/dist/core/runner/compaction-restate.js +4 -3
  206. package/dist/core/runner/construction-doors.d.ts +2 -2
  207. package/dist/core/runner/construction-doors.js +2 -2
  208. package/dist/core/runner/contracts.d.ts +98 -26
  209. package/dist/core/runner/cross-boundary-lane.d.ts +1 -1
  210. package/dist/core/runner/decide-continuation.d.ts +4 -2
  211. package/dist/core/runner/decide-continuation.js +7 -4
  212. package/dist/core/runner/denial-limit-arms.d.ts +15 -21
  213. package/dist/core/runner/denial-limit-arms.js +17 -10
  214. package/dist/core/runner/expire-settle.d.ts +44 -0
  215. package/dist/core/runner/expire-settle.js +55 -0
  216. package/dist/core/runner/git-status-frame.d.ts +3 -3
  217. package/dist/core/runner/git-status-frame.js +2 -1
  218. package/dist/core/runner/halt-attribution.d.ts +2 -1
  219. package/dist/core/runner/halt-attribution.js +2 -1
  220. package/dist/core/runner/local-claims.d.ts +17 -0
  221. package/dist/core/runner/local-claims.js +18 -0
  222. package/dist/core/runner/media-removed-seat.d.ts +46 -0
  223. package/dist/core/runner/media-removed-seat.js +88 -0
  224. package/dist/core/runner/park-commit.d.ts +2 -2
  225. package/dist/core/runner/permission-rule-lanes.d.ts +5 -1
  226. package/dist/core/runner/permission-rule-lanes.js +28 -9
  227. package/dist/core/runner/person-path-rows.js +1 -1
  228. package/dist/core/runner/placement-fence.d.ts +26 -0
  229. package/dist/core/runner/placement-fence.js +38 -0
  230. package/dist/core/runner/prepare-ask-lane.d.ts +6 -12
  231. package/dist/core/runner/prepare-ask-lane.js +4 -4
  232. package/dist/core/runner/prepare-boundary-parks.d.ts +4 -1
  233. package/dist/core/runner/prepare-boundary-parks.js +2 -2
  234. package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
  235. package/dist/core/runner/prepare-caps-and-workflow.js +1 -0
  236. package/dist/core/runner/prepare-config-doors.js +16 -17
  237. package/dist/core/runner/prepare-context-lane.d.ts +6 -2
  238. package/dist/core/runner/prepare-context-lane.js +13 -13
  239. package/dist/core/runner/prepare-delegation-surface.d.ts +9 -9
  240. package/dist/core/runner/prepare-delegation-surface.js +4 -5
  241. package/dist/core/runner/prepare-execution-env.d.ts +5 -2
  242. package/dist/core/runner/prepare-execution-env.js +7 -4
  243. package/dist/core/runner/prepare-gate-stations.d.ts +19 -14
  244. package/dist/core/runner/prepare-gate-stations.js +6 -4
  245. package/dist/core/runner/prepare-hands-readface.d.ts +5 -5
  246. package/dist/core/runner/prepare-hands-readface.js +4 -4
  247. package/dist/core/runner/prepare-inherited-gate.d.ts +6 -0
  248. package/dist/core/runner/prepare-inherited-gate.js +3 -0
  249. package/dist/core/runner/prepare-lsp.d.ts +3 -0
  250. package/dist/core/runner/prepare-lsp.js +2 -2
  251. package/dist/core/runner/prepare-park-ask.d.ts +5 -2
  252. package/dist/core/runner/prepare-park-ask.js +4 -5
  253. package/dist/core/runner/prepare-policy-chain.d.ts +10 -21
  254. package/dist/core/runner/prepare-policy-chain.js +16 -25
  255. package/dist/core/runner/prepare-project-context.d.ts +2 -2
  256. package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -4
  257. package/dist/core/runner/prepare-prompt-inputs.js +3 -2
  258. package/dist/core/runner/prepare-question-face.d.ts +6 -4
  259. package/dist/core/runner/prepare-question-face.js +2 -2
  260. package/dist/core/runner/prepare-run-refs.d.ts +3 -0
  261. package/dist/core/runner/prepare-run-refs.js +2 -2
  262. package/dist/core/runner/prepare-suspend-saga.d.ts +11 -7
  263. package/dist/core/runner/prepare-suspend-saga.js +17 -7
  264. package/dist/core/runner/prepare-task.d.ts +1 -1
  265. package/dist/core/runner/prepare-task.js +56 -28
  266. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +6 -0
  267. package/dist/core/runner/prepare-tool-disclosure-mount.js +3 -1
  268. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -0
  269. package/dist/core/runner/prepare-wiring-manifest.js +2 -1
  270. package/dist/core/runner/prepare-workspace-restore.d.ts +5 -0
  271. package/dist/core/runner/prepare-workspace-restore.js +10 -6
  272. package/dist/core/runner/read-root-grant.d.ts +1 -1
  273. package/dist/core/runner/read-root-grant.js +2 -1
  274. package/dist/core/runner/resume-admission.d.ts +5 -3
  275. package/dist/core/runner/resume-admission.js +17 -3
  276. package/dist/core/runner/resume-apply.js +3 -1
  277. package/dist/core/runner/resume-claim.d.ts +8 -3
  278. package/dist/core/runner/resume-claim.js +28 -12
  279. package/dist/core/runner/resume-internals-and-config.d.ts +2 -2
  280. package/dist/core/runner/resume-internals-and-config.js +10 -1
  281. package/dist/core/runner/resume-preflight.d.ts +3 -2
  282. package/dist/core/runner/resume-preflight.js +13 -26
  283. package/dist/core/runner/retired-runner-deps.js +2 -0
  284. package/dist/core/runner/run-git-lane.js +2 -1
  285. package/dist/core/runner/run-harness-handlers.js +2 -2
  286. package/dist/core/runner/run-identity-wiring.d.ts +2 -2
  287. package/dist/core/runner/run-identity-wiring.js +14 -5
  288. package/dist/core/runner/run-leg.d.ts +3 -3
  289. package/dist/core/runner/run-leg.js +40 -29
  290. package/dist/core/runner/run-notification-lane.js +20 -2
  291. package/dist/core/runner/run-recovery-lanes.js +3 -2
  292. package/dist/core/runner/run-settle-and-teardown.js +9 -7
  293. package/dist/core/runner/run-telemetry-and-budget-seats.d.ts +1 -1
  294. package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
  295. package/dist/core/runner/run-terminal-adoption.js +26 -17
  296. package/dist/core/runner/run-turn-boundary.js +27 -14
  297. package/dist/core/runner/runtask.d.ts +18 -3
  298. package/dist/core/runner/runtask.js +27 -11
  299. package/dist/core/runner/session-rule-policy.d.ts +1 -1
  300. package/dist/core/runner/session-rule-policy.js +6 -1
  301. package/dist/core/runner/shell-env-withheld.d.ts +1 -1
  302. package/dist/core/runner/stream-halt-verbs.d.ts +1 -14
  303. package/dist/core/runner/stream-halt-verbs.js +4 -3
  304. package/dist/core/runner/stream-reap.d.ts +7 -6
  305. package/dist/core/runner/stream-reap.js +13 -16
  306. package/dist/core/runner/stream-settle-backstop.d.ts +3 -2
  307. package/dist/core/runner/stream-settle-backstop.js +5 -3
  308. package/dist/core/runner/stream-steer-verb.d.ts +5 -2
  309. package/dist/core/runner/stream-steer-verb.js +8 -7
  310. package/dist/core/runner/terminal-account.d.ts +11 -1
  311. package/dist/core/runner/terminal-account.js +20 -0
  312. package/dist/core/runner/terminal-projection.d.ts +8 -2
  313. package/dist/core/runner/terminal-projection.js +2 -2
  314. package/dist/core/runner/tool-disclosure.d.ts +3 -0
  315. package/dist/core/runner/tool-disclosure.js +5 -2
  316. package/dist/core/runner/tool-end-body.d.ts +3 -3
  317. package/dist/core/runner/tool-end-body.js +1 -1
  318. package/dist/core/runner/tool-output-projection.d.ts +3 -3
  319. package/dist/core/runner/tool-output-projection.js +7 -6
  320. package/dist/core/runner/tool-table-view.d.ts +56 -0
  321. package/dist/core/runner/tool-table-view.js +51 -0
  322. package/dist/core/runner/turn-attachments.d.ts +3 -2
  323. package/dist/core/runner/turn-attachments.js +1 -1
  324. package/dist/core/runner/void-verifier-pause.d.ts +33 -0
  325. package/dist/core/runner/void-verifier-pause.js +41 -0
  326. package/dist/core/runner-deps.d.ts +24 -25
  327. package/dist/core/secret-env.d.ts +11 -11
  328. package/dist/core/secret-env.js +8 -9
  329. package/dist/core/session-log-transfer.js +9 -10
  330. package/dist/core/session-policy-store.d.ts +1 -1
  331. package/dist/core/session-policy-store.js +5 -2
  332. package/dist/core/session-reconcile.d.ts +3 -2
  333. package/dist/core/session-reconcile.js +7 -4
  334. package/dist/core/session-store.d.ts +2 -0
  335. package/dist/core/session-store.js +5 -7
  336. package/dist/core/session.d.ts +2 -1
  337. package/dist/core/shell-confinement.d.ts +37 -0
  338. package/dist/core/shell-confinement.js +56 -0
  339. package/dist/core/skill-grant.js +1 -1
  340. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +2 -2
  341. package/dist/core/store-contracts/checkpoint-store-contract.js +15 -2
  342. package/dist/core/store-contracts/file-history-store-contract.d.ts +5 -2
  343. package/dist/core/store-contracts/file-history-store-contract.js +25 -1
  344. package/dist/core/store-contracts/mailbox-store-contract.d.ts +12 -5
  345. package/dist/core/store-contracts/mailbox-store-contract.js +156 -9
  346. package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
  347. package/dist/core/store-contracts/tool-result-store-contract.js +30 -0
  348. package/dist/core/task-event.d.ts +17 -8
  349. package/dist/core/task-limits.d.ts +5 -0
  350. package/dist/core/task-notification.d.ts +89 -12
  351. package/dist/core/task-notification.js +87 -13
  352. package/dist/core/task-registry-agent.d.ts +5 -43
  353. package/dist/core/task-registry-agent.js +24 -51
  354. package/dist/core/task-registry-monitor.d.ts +1 -1
  355. package/dist/core/task-registry-monitor.js +15 -60
  356. package/dist/core/task-registry-shared.d.ts +15 -112
  357. package/dist/core/task-registry-shared.js +3 -41
  358. package/dist/core/task-registry-workflow.js +4 -21
  359. package/dist/core/task-registry.d.ts +19 -60
  360. package/dist/core/task-registry.js +19 -106
  361. package/dist/core/task-result.d.ts +24 -7
  362. package/dist/core/task-spec-members.d.ts +39 -0
  363. package/dist/core/task-spec-members.js +92 -0
  364. package/dist/core/task-spec.d.ts +10 -10
  365. package/dist/core/task-tool-shape.d.ts +7 -57
  366. package/dist/core/task-tool-shape.js +7 -66
  367. package/dist/core/terminal-cause.d.ts +30 -0
  368. package/dist/core/terminal-cause.js +1 -0
  369. package/dist/core/tool-catalog-entries.js +2 -5
  370. package/dist/core/tool-check-reading.js +16 -10
  371. package/dist/core/tool-conformance.js +1 -2
  372. package/dist/core/tool-errors.d.ts +6 -3
  373. package/dist/core/tool-errors.js +2 -0
  374. package/dist/core/tool-face-reader.js +3 -2
  375. package/dist/core/tool-face.d.ts +2 -3
  376. package/dist/core/tool-name-aliases.d.ts +5 -29
  377. package/dist/core/tool-name-aliases.js +9 -5
  378. package/dist/core/tool-name-readings.d.ts +14 -3
  379. package/dist/core/tool-name-readings.js +2 -0
  380. package/dist/core/tool-policy.d.ts +108 -18
  381. package/dist/core/tool-policy.js +84 -14
  382. package/dist/core/tool-result-store.d.ts +23 -0
  383. package/dist/core/tool-result-store.js +3 -2
  384. package/dist/core/tool-spec.d.ts +19 -6
  385. package/dist/core/trace.d.ts +18 -1
  386. package/dist/core/user-attachment.js +26 -21
  387. package/dist/core/workflow-journal-store.d.ts +1 -1
  388. package/dist/core/workflow-run-store.d.ts +2 -0
  389. package/dist/core/workflow-run-store.js +6 -5
  390. package/dist/core/workflow-settled-run.d.ts +5 -0
  391. package/dist/core/workflow-settled-run.js +7 -0
  392. package/dist/engine/execution-env/node-execution-env.d.ts +34 -9
  393. package/dist/engine/execution-env/node-execution-env.js +213 -21
  394. package/dist/engine/harness/agent-harness.d.ts +65 -18
  395. package/dist/engine/harness/agent-harness.js +90 -23
  396. package/dist/engine/harness/messages.d.ts +4 -3
  397. package/dist/engine/harness/messages.js +2 -2
  398. package/dist/engine/harness/types.d.ts +41 -7
  399. package/dist/engine/llm/media-removed.d.ts +14 -0
  400. package/dist/engine/llm/media-removed.js +9 -0
  401. package/dist/engine/llm/rejected-images.d.ts +35 -25
  402. package/dist/engine/llm/rejected-images.js +59 -10
  403. package/dist/engine/llm/types.d.ts +24 -3
  404. package/dist/engine/llm/types.js +7 -3
  405. package/dist/engine/loop/agent-loop.d.ts +6 -1
  406. package/dist/engine/loop/agent-loop.js +20 -11
  407. package/dist/engine/loop/types.d.ts +12 -3
  408. package/dist/engine/session/import-validate.js +7 -0
  409. package/dist/fixtures/index.d.ts +7 -5
  410. package/dist/fixtures/index.js +5 -3
  411. package/dist/index.d.ts +21 -11
  412. package/dist/index.js +15 -7
  413. package/dist/internal/harness-types.d.ts +2 -0
  414. package/dist/internal/llm.d.ts +2 -1
  415. package/dist/internal/llm.js +1 -0
  416. package/dist/orchestration/goal.d.ts +6 -2
  417. package/dist/orchestration/goal.js +6 -3
  418. package/dist/orchestration/run-workflow-tool.d.ts +11 -17
  419. package/dist/orchestration/run-workflow-tool.js +19 -42
  420. package/dist/orchestration/workflow-governance.d.ts +1 -1
  421. package/dist/orchestration/workflow-types.d.ts +2 -2
  422. package/dist/orchestration/workflow.d.ts +4 -0
  423. package/dist/orchestration/workflow.js +8 -5
  424. package/dist/stores/file/background-agent-store.js +18 -15
  425. package/dist/stores/file/checkpoint-store.js +7 -4
  426. package/dist/stores/file/file-history-store.js +3 -2
  427. package/dist/stores/file/index.d.ts +5 -3
  428. package/dist/stores/file/index.js +23 -8
  429. package/dist/stores/file/ledger-tuning.d.ts +23 -0
  430. package/dist/stores/file/ledger-tuning.js +21 -0
  431. package/dist/stores/file/mailbox-store.js +42 -22
  432. package/dist/stores/file/memory-store.js +3 -2
  433. package/dist/stores/file/permission-rule-adopt.js +24 -21
  434. package/dist/stores/file/permission-rule-store.js +6 -3
  435. package/dist/stores/file/session-policy-store.js +3 -2
  436. package/dist/stores/file/session-store.d.ts +16 -3
  437. package/dist/stores/file/session-store.js +21 -20
  438. package/dist/stores/file/tool-result-store.d.ts +11 -0
  439. package/dist/stores/file/tool-result-store.js +57 -3
  440. package/dist/stores/file/usage-window-store.js +3 -2
  441. package/dist/stores/file/workflow-journal-store.d.ts +0 -2
  442. package/dist/stores/file/workflow-journal-store.js +3 -18
  443. package/dist/stores/file/workflow-run-store.d.ts +1 -1
  444. package/dist/stores/file/workflow-run-store.js +15 -10
  445. package/dist/tools/fs/dead-cwd.d.ts +5 -5
  446. package/dist/tools/fs/dead-cwd.js +4 -11
  447. package/dist/tools/fs/fs-bash-background-text.d.ts +6 -0
  448. package/dist/tools/fs/fs-bash-background-text.js +6 -0
  449. package/dist/tools/fs/fs-bash.d.ts +3 -18
  450. package/dist/tools/fs/fs-bash.js +37 -124
  451. package/dist/tools/fs/fs-pdf.js +8 -6
  452. package/dist/tools/fs/fs-read.js +2 -2
  453. package/dist/tools/fs/fs-shared.d.ts +28 -3
  454. package/dist/tools/fs/fs-shared.js +15 -0
  455. package/dist/tools/fs/index.d.ts +1 -1
  456. package/dist/tools/fs/index.js +4 -14
  457. package/dist/tools/fs/pdf.d.ts +4 -4
  458. package/dist/tools/fs/pdf.js +6 -6
  459. package/dist/tools/fs/read-deny-home.js +8 -1
  460. package/dist/tools/fs/read-deny.d.ts +26 -2
  461. package/dist/tools/fs/read-deny.js +9 -2
  462. package/dist/tools/fs/read-floor.d.ts +13 -5
  463. package/dist/tools/fs/read-floor.js +206 -2
  464. package/dist/tools/fs/search.d.ts +3 -2
  465. package/dist/tools/fs/search.js +6 -6
  466. package/dist/tools/fs/shell-read-establish.js +3 -1
  467. package/dist/tools/fs/shell-read-identity.d.ts +3 -1
  468. package/dist/tools/fs/shell-read-identity.js +4 -2
  469. package/dist/tools/fs/shell-read-judge.d.ts +7 -1
  470. package/dist/tools/fs/shell-read-judge.js +1 -1
  471. package/dist/tools/monitor.d.ts +8 -7
  472. package/dist/tools/monitor.js +12 -10
  473. package/dist/tools/worktree.d.ts +5 -1
  474. package/dist/tools/worktree.js +20 -17
  475. package/package.json +6 -3
  476. package/test/export-surface.snapshot.json +92 -10
  477. package/wire-changes/core-stores-sql@7.61.0.json +480 -0
  478. package/wire-changes/core@7.61.0.json +4405 -0
  479. package/wire-changes/mods-kernel@7.61.0.json +65 -0
  480. package/wire-changes/primitives@7.61.0.json +30 -0
  481. package/dist/core/runner/image-removed-seat.d.ts +0 -12
  482. package/dist/core/runner/image-removed-seat.js +0 -19
@@ -1,9 +1,10 @@
1
1
  import { join } from "node:path";
2
2
  import { guardedMemoryStore } from "../../core/memory.js";
3
- import { TtlSessionStore } from "../../core/session-store.js";
3
+ import { STORE_HOOK_KEYS, TtlSessionStore } from "../../core/session-store.js";
4
4
  import { BootLock, createFileConsolidationLock, resolveDataRoot } from "./fs-atomic.js";
5
5
  import { assertAdoptionBootGate } from "./adoption/marker.js";
6
6
  import { FileCheckpointStore } from "./checkpoint-store.js";
7
+ import { readLedgerTuning } from "./ledger-tuning.js";
7
8
  import { FileMemoryStore } from "./memory-store.js";
8
9
  import { FileSessionRepo } from "./session-store.js";
9
10
  import { FileToolResultStore } from "./tool-result-store.js";
@@ -14,9 +15,11 @@ import { FileBackgroundAgentStore } from "./background-agent-store.js";
14
15
  import { FileMailboxStore } from "./mailbox-store.js";
15
16
  import { FileRosterStore } from "../../agents/roster-store.js";
16
17
  import { FileFileHistoryStore } from "./file-history-store.js";
17
- import { receiveOptions, receiveOwnProperties, refuseProxy } from "../../core/own-property-receipt.js";
18
- function nestedOptions(value, member) {
19
- return value === undefined ? undefined : receiveOwnProperties(value, { subject: `FileStorageBackendOptions.${member}`, unit: "option", moment: "at new FileStorageBackend" });
18
+ import { readMountedToolNames } from "../../core/session-policy-store.js";
19
+ import { optionKeys, receiveMembers, receiveOptions, refuseProxy, refuseStrayMembers } from "../../core/own-property-receipt.js";
20
+ import { receiveFileHistoryRetention } from "../../core/file-history-retention.js";
21
+ function nestedOptions(value, member, keys) {
22
+ return value === undefined ? undefined : receiveMembers(value, { subject: `FileStorageBackendOptions.${member}`, unit: "option", moment: "at new FileStorageBackend" }, keys);
20
23
  }
21
24
  export { FileCheckpointStore, CHECKPOINT_LEDGER_EVENT_KINDS, readCheckpointLedger, } from "./checkpoint-store.js";
22
25
  export { FileMemoryStore } from "./memory-store.js";
@@ -33,6 +36,10 @@ export { atomicWriteFile, writeThenLink, ensureDir, readJsonlRecords, AppendLog
33
36
  export { processFingerprint, isProcessLive } from "./fs-atomic.js";
34
37
  export { AdoptionError, assertAdoptionBootGate, readRootAdoptionFile, writeRootAdoptionFile, ROOT_ADOPTION_FILE, } from "./adoption/marker.js";
35
38
  export { adoptLocalDataRoot, ackAdoptionConfig, witnessAdoptionConfig, listAdoptionQuarantine, readAdoptionStatus, } from "./adoption/adopt.js";
39
+ const FILE_STORAGE_BACKEND_OPTION_KEYS = optionKeys()({ root: 0, utilityGate: 0, evict: 0, checkpoint: 0, fileHistory: 0, sessionPolicy: 0, embedder: 0, onCorruptRead: 0, sessions: 0 });
40
+ const NESTED_FILE_HISTORY_OPTION_KEYS = optionKeys()({ retention: 0 });
41
+ const NESTED_SESSION_POLICY_OPTION_KEYS = optionKeys()({ mountedToolNames: 0 });
42
+ const NESTED_CHECKPOINT_OPTION_KEYS = optionKeys()({ fsync: 0, compactEvery: 0, holderIsCurrent: 0 });
36
43
  export class FileStorageBackend {
37
44
  root;
38
45
  sessionStore;
@@ -62,7 +69,15 @@ export class FileStorageBackend {
62
69
  throw Object.assign(new Error(`FileStorageBackend runs no retention executor, so its options take no \`retention\` word: its stores declare "none".`), { code: "config.retention_capability" });
63
70
  }
64
71
  }
65
- const opts = receiveOptions(options, "FileStorageBackend");
72
+ const opts = receiveOptions(options, "FileStorageBackend", FILE_STORAGE_BACKEND_OPTION_KEYS);
73
+ const checkpointRecord = nestedOptions(opts.checkpoint, "checkpoint", NESTED_CHECKPOINT_OPTION_KEYS);
74
+ const checkpointOptions = checkpointRecord === undefined ? undefined : { ...checkpointRecord, ...readLedgerTuning(checkpointRecord, "FileCheckpointStore", "FileStorageBackendOptions.checkpoint") };
75
+ const sessionPolicyRecord = nestedOptions(opts.sessionPolicy, "sessionPolicy", NESTED_SESSION_POLICY_OPTION_KEYS);
76
+ const sessionPolicyOptions = sessionPolicyRecord?.mountedToolNames === undefined ? sessionPolicyRecord : { ...sessionPolicyRecord, mountedToolNames: readMountedToolNames(sessionPolicyRecord.mountedToolNames) };
77
+ const fileHistoryRecord = nestedOptions(opts.fileHistory, "fileHistory", NESTED_FILE_HISTORY_OPTION_KEYS);
78
+ const fileHistoryOptions = fileHistoryRecord === undefined ? undefined : { ...fileHistoryRecord, retention: receiveFileHistoryRetention("FileStorageBackendOptions.fileHistory", fileHistoryRecord.retention) };
79
+ if (opts.sessions !== undefined)
80
+ refuseStrayMembers(opts.sessions, { subject: "FileStorageBackendOptions.sessions", unit: "hook", moment: "at new FileStorageBackend" }, STORE_HOOK_KEYS);
66
81
  this.root = resolveDataRoot(opts.root);
67
82
  assertAdoptionBootGate(this.root, "FileStorageBackend");
68
83
  this.lock = new BootLock(join(this.root, "LOCK"));
@@ -75,14 +90,14 @@ export class FileStorageBackend {
75
90
  this.ttl = new TtlSessionStore({ repo, evict: opts.evict ?? "forget", durability: "durable", placements: { subagent: { durability: "durable" } }, ...(opts.sessions !== undefined ? { hooks: opts.sessions } : {}) });
76
91
  this.sessionStore = this.ttl;
77
92
  const sessionHeadOf = this.ttl.headOf;
78
- this.fileCheckpoints = new FileCheckpointStore(this.root, { ...nestedOptions(opts.checkpoint, "checkpoint"), ...corruptRead, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
93
+ this.fileCheckpoints = new FileCheckpointStore(this.root, { ...checkpointOptions, ...corruptRead, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
79
94
  built.push(() => this.fileCheckpoints.close());
80
95
  this.checkpointStore = this.fileCheckpoints;
81
96
  this.fileMemory = new FileMemoryStore(this.root, opts.embedder ? { embedder: opts.embedder } : {});
82
97
  built.push(() => this.fileMemory.close());
83
98
  this.memoryStore = guardedMemoryStore(this.fileMemory, opts.utilityGate);
84
99
  this.toolResultStore = new FileToolResultStore(this.root, corruptRead);
85
- this.sessionPolicyStore = new FileSessionPolicyStore(this.root, { ...nestedOptions(opts.sessionPolicy, "sessionPolicy"), ...corruptRead });
100
+ this.sessionPolicyStore = new FileSessionPolicyStore(this.root, { ...sessionPolicyOptions, ...corruptRead });
86
101
  this.fileWorkflowJournal = new FileWorkflowJournalStore(this.root, true, corruptRead);
87
102
  built.push(() => this.fileWorkflowJournal.dispose());
88
103
  this.workflowJournalStore = this.fileWorkflowJournal;
@@ -94,7 +109,7 @@ export class FileStorageBackend {
94
109
  built.push(() => this.fileMailbox.close());
95
110
  this.mailboxStore = this.fileMailbox;
96
111
  this.rosterStore = new FileRosterStore(join(this.root, "roster.json"), corruptRead ?? {});
97
- this.fileHistoryStore = new FileFileHistoryStore(this.root, { ...nestedOptions(opts.fileHistory, "fileHistory"), ...(corruptRead ?? {}) });
112
+ this.fileHistoryStore = new FileFileHistoryStore(this.root, { ...fileHistoryOptions, ...(corruptRead ?? {}) });
98
113
  this.consolidationLock = createFileConsolidationLock(join(this.root, "consolidation-locks"));
99
114
  }
100
115
  catch (err) {
@@ -0,0 +1,23 @@
1
+ /** Each store's compaction threshold when none is given. */
2
+ export declare const LEDGER_COMPACT_EVERY_DEFAULTS: Readonly<{
3
+ FileCheckpointStore: 1000;
4
+ FileMailboxStore: 500;
5
+ FileBackgroundAgentStore: 1000;
6
+ FileWorkflowRunStore: 1000;
7
+ }>;
8
+ /** A store that takes ledger tuning. */
9
+ export type LedgerTunedStore = keyof typeof LEDGER_COMPACT_EVERY_DEFAULTS;
10
+ /** A store's ledger tuning, read: every member present. */
11
+ export interface LedgerTuning {
12
+ readonly fsync: boolean;
13
+ readonly compactEvery: number;
14
+ }
15
+ /**
16
+ * Read a store's ledger tuning off an options record already received (the store door's copy, or a backend's nested record's):
17
+ * the values judged, the absent ones the store's defaults. `subject` names the record in a refusal (`FileMailboxStore options`,
18
+ * `FileStorageBackendOptions.checkpoint`).
19
+ */
20
+ export declare function readLedgerTuning(given: {
21
+ readonly fsync?: unknown;
22
+ readonly compactEvery?: unknown;
23
+ }, store: LedgerTunedStore, subject: string): LedgerTuning;
@@ -0,0 +1,21 @@
1
+ import { receiptRefusal } from "../../core/own-property-receipt.js";
2
+ export const LEDGER_COMPACT_EVERY_DEFAULTS = Object.freeze({
3
+ FileCheckpointStore: 1000,
4
+ FileMailboxStore: 500,
5
+ FileBackgroundAgentStore: 1000,
6
+ FileWorkflowRunStore: 1000,
7
+ });
8
+ function shown(value) {
9
+ return typeof value === "number" ? String(value) : value === null ? "null" : Array.isArray(value) ? "an array" : typeof value;
10
+ }
11
+ export function readLedgerTuning(given, store, subject) {
12
+ const fsync = given.fsync;
13
+ if (fsync !== undefined && typeof fsync !== "boolean") {
14
+ throw receiptRefusal(`${subject}.fsync must be a boolean when given (got ${shown(fsync)}) — refused rather than read as on`);
15
+ }
16
+ const compactEvery = given.compactEvery;
17
+ if (compactEvery !== undefined && !(typeof compactEvery === "number" && Number.isSafeInteger(compactEvery) && compactEvery >= 1)) {
18
+ throw receiptRefusal(`${subject}.compactEvery must be a whole number of events of at least 1 when given (got ${shown(compactEvery)}) — refused rather than kept: such a threshold is never reached (the ledger grows without compacting) or reached at every event (a rewrite per write)`);
19
+ }
20
+ return Object.freeze({ fsync: fsync !== false, compactEvery: compactEvery ?? LEDGER_COMPACT_EVERY_DEFAULTS[store] });
21
+ }
@@ -1,13 +1,14 @@
1
1
  import { join, resolve, sep } from "node:path";
2
2
  import { createHash, randomBytes } from "node:crypto";
3
- import { assertRetentionPolicy } from "../../core/retention-policy.js";
3
+ import { receiveRetentionPolicy } from "../../core/retention-policy.js";
4
4
  import { existsSync, linkSync, readdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
5
- import { assertMailboxDecisionMove, detachMailboxMessage, newestSentAt, readStoredMailboxDecision, readMailboxAppend, judgeMailboxAppendById, } from "../../core/mailbox-store.js";
5
+ import { assertMailboxDecisionMove, detachMailboxMessage, foldMailboxConsumed, MAILBOX_REAP_KNOBS, MAILBOX_REPLAY_FACETS, newestSentAt, readStoredMailboxDecision, readMailboxAppend, judgeMailboxAppendById, } from "../../core/mailbox-store.js";
6
6
  import { AppendLog, atomicWriteFile, canonicalStoreKey, ensureDir, readJsonlRecords, sanitizeScope, sanitizePathComponent } from "./fs-atomic.js";
7
7
  import { guardCorruptSink } from "./corrupt-read-sink.js";
8
8
  import { physicalPathOf } from "../../core/physical-path.js";
9
9
  import { assertAdoptionBootGate } from "./adoption/marker.js";
10
- import { receiveOptions } from "../../core/own-property-receipt.js";
10
+ import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
11
+ import { readLedgerTuning } from "./ledger-tuning.js";
11
12
  function diskMarkOf(path) {
12
13
  try {
13
14
  const st = statSync(path);
@@ -323,6 +324,7 @@ function sweepLockResidue(dir, lockName) {
323
324
  }
324
325
  }
325
326
  }
327
+ const FILE_MAILBOX_STORE_OPTION_KEYS = optionKeys()({ fsync: 0, lockWaitMs: 0, compactEvery: 0, onCorruptRead: 0 });
326
328
  export class FileMailboxStore {
327
329
  crossProcessSafe = true;
328
330
  identity;
@@ -334,10 +336,11 @@ export class FileMailboxStore {
334
336
  touched = new Map();
335
337
  discloseCorrupt;
336
338
  constructor(root, options) {
337
- const opts = receiveOptions(options, "FileMailboxStore");
339
+ const opts = receiveOptions(options, "FileMailboxStore", FILE_MAILBOX_STORE_OPTION_KEYS);
338
340
  assertAdoptionBootGate(root, "FileMailboxStore");
339
- this.fsyncEnabled = opts.fsync !== false;
340
- this.compactEvery = opts.compactEvery ?? 500;
341
+ const tuning = readLedgerTuning(opts, "FileMailboxStore", "FileMailboxStore options");
342
+ this.fsyncEnabled = tuning.fsync;
343
+ this.compactEvery = tuning.compactEvery;
341
344
  const lockWaitMs = opts.lockWaitMs ?? 10_000;
342
345
  if (typeof lockWaitMs !== "number" || !Number.isFinite(lockWaitMs) || lockWaitMs <= 0) {
343
346
  throw new Error(`FileMailboxStore: lockWaitMs must be a finite number > 0, got ${JSON.stringify(opts.lockWaitMs)}`);
@@ -386,10 +389,11 @@ export class FileMailboxStore {
386
389
  const events = readJsonlRecords(b.path, this.discloseCorrupt, MAILBOX_EVENT_JUDGE);
387
390
  b.messages = [];
388
391
  b.nextSeq = 1;
392
+ b.consumed = [];
389
393
  delete b.lease;
390
394
  for (const ev of events)
391
395
  applyEvent(b, ev);
392
- b.events = Math.max(0, events.length - (b.messages.length + 1 + (b.lease !== undefined ? 1 : 0)));
396
+ b.events = Math.max(0, events.length - (b.messages.length + 1 + (b.consumed.length > 0 ? 1 : 0) + (b.lease !== undefined ? 1 : 0)));
393
397
  b.mark = now;
394
398
  }
395
399
  load(scope, handle) {
@@ -406,7 +410,7 @@ export class FileMailboxStore {
406
410
  }
407
411
  ensureDir(join(this.dir, sanitizeScope(scope)));
408
412
  const events = readJsonlRecords(path, this.discloseCorrupt, MAILBOX_EVENT_JUDGE);
409
- const state = { messages: [], nextSeq: 1, log: new AppendLog(path), events: events.length, refs: 1, path, mark: undefined };
413
+ const state = { messages: [], nextSeq: 1, consumed: [], log: new AppendLog(path), events: events.length, refs: 1, path, mark: undefined };
410
414
  for (const ev of events)
411
415
  applyEvent(state, ev);
412
416
  state.mark = diskMarkOf(path);
@@ -429,14 +433,8 @@ export class FileMailboxStore {
429
433
  b.mark = markAfterWrite(path);
430
434
  }
431
435
  compact(b, path) {
432
- const lines = [];
433
- lines.push(JSON.stringify({ t: "lease", owner: "", expiresAt: 0, maxSeq: b.nextSeq - 1 }));
434
- for (const m of b.messages)
435
- lines.push(JSON.stringify({ t: "append", m }));
436
- if (b.lease !== undefined)
437
- lines.push(JSON.stringify({ t: "lease", ...b.lease }));
438
436
  b.log.closeForSwap();
439
- atomicWriteFile(this.tmpDir, path, lines.length ? `${lines.join("\n")}\n` : "");
437
+ atomicWriteFile(this.tmpDir, path, snapshotOf(b));
440
438
  b.events = 0;
441
439
  b.mark = markAfterWrite(path);
442
440
  }
@@ -446,7 +444,7 @@ export class FileMailboxStore {
446
444
  const record = readMailboxAppend(msg);
447
445
  return this.withBox(this.lockKey(scope, handle), this.boxPath(scope, handle), () => {
448
446
  const b = this.load(scope, handle);
449
- const held = judgeMailboxAppendById(b.messages, record);
447
+ const held = judgeMailboxAppendById({ held: b.messages, consumed: b.consumed }, record);
450
448
  if (held !== undefined)
451
449
  return held;
452
450
  const seq = b.nextSeq;
@@ -505,7 +503,7 @@ export class FileMailboxStore {
505
503
  if (!existsSync(path))
506
504
  return 0;
507
505
  return withPathLock(this.lockKey(scope, handle), () => {
508
- const b = { messages: [], nextSeq: 1 };
506
+ const b = { messages: [], nextSeq: 1, consumed: [] };
509
507
  for (const ev of readJsonlRecords(path, this.discloseCorrupt, MAILBOX_EVENT_JUDGE))
510
508
  applyEvent(b, ev);
511
509
  return b.messages.length;
@@ -525,14 +523,14 @@ export class FileMailboxStore {
525
523
  });
526
524
  }
527
525
  async reap(scope, now, opts) {
528
- assertRetentionPolicy("MailboxStore.reap", opts);
526
+ const policy = receiveRetentionPolicy("MailboxStore.reap", opts, MAILBOX_REAP_KNOBS);
529
527
  sweepLockResidue(join(this.dir, sanitizeScope(scope)));
530
- if (opts?.maxAgeMs === undefined)
528
+ if (policy.maxAgeMs === undefined)
531
529
  return 0;
532
530
  let dropped = 0;
533
531
  const scopeDir = join(this.dir, sanitizeScope(scope));
534
532
  const prefix = scopeDir + sep;
535
- const maxAgeMs = opts.maxAgeMs;
533
+ const maxAgeMs = policy.maxAgeMs;
536
534
  for (const [key, b] of [...sharedBoxes]) {
537
535
  if (!b.path.startsWith(prefix))
538
536
  continue;
@@ -565,13 +563,13 @@ export class FileMailboxStore {
565
563
  const swept = await this.withBox(key, path, () => {
566
564
  if (sharedBoxes.has(key))
567
565
  return false;
568
- const b = { messages: [], nextSeq: 1 };
566
+ const b = { messages: [], nextSeq: 1, consumed: [] };
569
567
  for (const ev of readJsonlRecords(path, this.discloseCorrupt, MAILBOX_EVENT_JUDGE))
570
568
  applyEvent(b, ev);
571
569
  const newest = newestSentAt(b.messages);
572
570
  if (newest === undefined || newest >= now - maxAgeMs)
573
571
  return false;
574
- atomicWriteFile(this.tmpDir, path, `${JSON.stringify({ t: "lease", owner: "", expiresAt: 0, maxSeq: b.nextSeq - 1 })}\n`);
572
+ atomicWriteFile(this.tmpDir, path, snapshotOf({ messages: [], nextSeq: b.nextSeq, consumed: b.consumed }));
575
573
  return true;
576
574
  });
577
575
  if (swept)
@@ -594,6 +592,22 @@ export class FileMailboxStore {
594
592
  }
595
593
  }
596
594
  const num = (v) => typeof v === "number" && Number.isFinite(v);
595
+ function isConsumedRecord(v) {
596
+ if (v === null || typeof v !== "object")
597
+ return false;
598
+ const { id, seq, digests } = v;
599
+ return typeof id === "string" && id !== "" && num(seq) && digests !== null && typeof digests === "object" && MAILBOX_REPLAY_FACETS.every((f) => typeof digests[f] === "string");
600
+ }
601
+ function snapshotOf(b) {
602
+ const lines = [JSON.stringify({ t: "lease", owner: "", expiresAt: 0, maxSeq: b.nextSeq - 1 })];
603
+ if (b.consumed.length > 0)
604
+ lines.push(JSON.stringify({ t: "consumed", records: b.consumed }));
605
+ for (const m of b.messages)
606
+ lines.push(JSON.stringify({ t: "append", m }));
607
+ if (b.lease !== undefined)
608
+ lines.push(JSON.stringify({ t: "lease", ...b.lease }));
609
+ return `${lines.join("\n")}\n`;
610
+ }
597
611
  const MAILBOX_EVENT_JUDGE = {
598
612
  accepts: (r) => {
599
613
  const ev = r;
@@ -605,6 +619,8 @@ const MAILBOX_EVENT_JUDGE = {
605
619
  return num(ev.upToSeq);
606
620
  if (ev.t === "decision")
607
621
  return num(r.seq) && typeof r.state === "string";
622
+ if (ev.t === "consumed")
623
+ return Array.isArray(r.records) && r.records.every(isConsumedRecord);
608
624
  return ev.t === "release" && typeof ev.owner === "string";
609
625
  },
610
626
  what: "a mailbox record is not one of this box's events — an unknown tag, or a known tag whose payload is missing",
@@ -627,10 +643,14 @@ function applyEvent(b, ev) {
627
643
  b.lease = { owner: ev.owner, expiresAt: ev.expiresAt, maxSeq: ev.maxSeq };
628
644
  }
629
645
  else if (ev.t === "ack") {
646
+ b.consumed = foldMailboxConsumed(b.consumed, b.messages.filter((m) => m.seq <= ev.upToSeq));
630
647
  b.messages = b.messages.filter((m) => m.seq > ev.upToSeq);
631
648
  if (b.lease !== undefined && b.lease.maxSeq <= ev.upToSeq)
632
649
  b.lease = undefined;
633
650
  }
651
+ else if (ev.t === "consumed") {
652
+ b.consumed = foldMailboxConsumed(ev.records, []);
653
+ }
634
654
  else if (ev.t === "decision") {
635
655
  const m = b.messages.find((x) => x.seq === ev.seq);
636
656
  if (m !== undefined)
@@ -4,9 +4,10 @@ import { firstSentence, lexicalSearchMatch, parseNoteTimestamp, MemoryProjection
4
4
  import { cosineDistance, jaccardDistance, termSet } from "../../core/memory-vector.js";
5
5
  import { canonicalStoreKey, AppendLog, atomicWriteFile, ensureDir, readJsonlRecords, sanitizeScope, } from "./fs-atomic.js";
6
6
  import { assertAdoptionBootGate } from "./adoption/marker.js";
7
- import { receiveOptions } from "../../core/own-property-receipt.js";
7
+ import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
8
8
  const MAX_OPEN_MEMORY_SCOPES = 64;
9
9
  const sharedMemoryDirs = new Map();
10
+ const FILE_MEMORY_STORE_OPTION_KEYS = optionKeys()({ embedder: 0, embedTimeoutMs: 0 });
10
11
  export class FileMemoryStore {
11
12
  root;
12
13
  embedder;
@@ -19,7 +20,7 @@ export class FileMemoryStore {
19
20
  scopeKey;
20
21
  closed = false;
21
22
  constructor(root, options) {
22
- const opts = receiveOptions(options, "FileMemoryStore");
23
+ const opts = receiveOptions(options, "FileMemoryStore", FILE_MEMORY_STORE_OPTION_KEYS);
23
24
  assertAdoptionBootGate(root, "FileMemoryStore");
24
25
  this.root = join(root, "memory");
25
26
  this.scopeKey = canonicalStoreKey(this.root);
@@ -6,40 +6,43 @@ import { principalNameOf } from "../../core/principal-name.js";
6
6
  import { createPermissionRuleStoreProvider } from "../../core/permission-rule-provider.js";
7
7
  import { syncPermissionRules } from "../../core/permission-rule-sync.js";
8
8
  import { thrownText } from "../../core/thrown-value.js";
9
+ import { optionKeys, receiveMembers } from "../../core/own-property-receipt.js";
9
10
  import { FileStoreLockError } from "./fs-atomic.js";
10
11
  import { FileDurableRulePartitionProvider, LOCAL_OWNER_FILE, principalRuleFileName, readRuleAdoptionFile, writeRuleAdoptionFile, } from "./permission-rule-store.js";
12
+ const ADOPT_OPTION_KEYS = optionKeys()({ dir: 0, from: 0, toPrincipal: 0, transport: 0, now: 0, onError: 0 });
11
13
  export async function adoptFilePermissionRuleStore(opts) {
12
- if (principalNameOf(opts.toPrincipal) === undefined) {
14
+ const o = receiveMembers(opts, { subject: "adoptFilePermissionRuleStore options", unit: "option", moment: "at adoptFilePermissionRuleStore" }, ADOPT_OPTION_KEYS);
15
+ if (principalNameOf(o.toPrincipal) === undefined) {
13
16
  throw new Error("adoptFilePermissionRuleStore requires the adopting principal, a principal name — adoption is the act of giving this bucket an identity");
14
17
  }
15
- const from = readRuleOwner(opts.from);
18
+ const from = readRuleOwner(o.from);
16
19
  if (from === undefined) {
17
20
  throw new Error("adoptFilePermissionRuleStore requires a source owner — a principal owner whose principal is a principal name, or the local owner");
18
21
  }
19
- if (from.kind === "principal" && from.principal === opts.toPrincipal) {
20
- throw new Error(`the bucket already belongs to "${opts.toPrincipal}" — there is nothing to adopt`);
22
+ if (from.kind === "principal" && from.principal === o.toPrincipal) {
23
+ throw new Error(`the bucket already belongs to "${o.toPrincipal}" — there is nothing to adopt`);
21
24
  }
22
- const sourceFile = join(opts.dir, from.kind === "local-owner" ? LOCAL_OWNER_FILE : principalRuleFileName(from.principal));
23
- const targetFile = join(opts.dir, principalRuleFileName(opts.toPrincipal));
24
- const existing = readRuleAdoptionFile(opts.dir);
25
+ const sourceFile = join(o.dir, from.kind === "local-owner" ? LOCAL_OWNER_FILE : principalRuleFileName(from.principal));
26
+ const targetFile = join(o.dir, principalRuleFileName(o.toPrincipal));
27
+ const existing = readRuleAdoptionFile(o.dir);
25
28
  if (existing !== undefined) {
26
29
  if ("adopted" in existing) {
27
- if (existing.adopted.toPrincipal === opts.toPrincipal && sameRuleOwner(existing.adopted.from, from))
30
+ if (existing.adopted.toPrincipal === o.toPrincipal && sameRuleOwner(existing.adopted.from, from))
28
31
  return { status: "adopted" };
29
32
  throw new Error(`this directory already carries a completed adoption (${ruleOwnerText(existing.adopted.from)} → "${existing.adopted.toPrincipal}") — a second adoption of the same directory is not a shape this helper supports`);
30
33
  }
31
- if (existing.marker.toPrincipal !== opts.toPrincipal || !sameRuleOwner(existing.marker.from, from)) {
34
+ if (existing.marker.toPrincipal !== o.toPrincipal || !sameRuleOwner(existing.marker.from, from)) {
32
35
  throw new Error(`an adoption toward "${existing.marker.toPrincipal}" is already in flight in this directory — refusing to start a different one (resume the original, or repair the marker by hand)`);
33
36
  }
34
37
  }
35
38
  else if (existsSync(targetFile)) {
36
- throw new Error(`the target bucket for "${opts.toPrincipal}" already exists — merging two existing buckets goes through an explicit sync join, not a rename`);
39
+ throw new Error(`the target bucket for "${o.toPrincipal}" already exists — merging two existing buckets goes through an explicit sync join, not a rename`);
37
40
  }
38
- const provider = new FileDurableRulePartitionProvider(opts.dir, opts.onError);
41
+ const provider = new FileDurableRulePartitionProvider(o.dir, o.onError);
39
42
  try {
40
43
  let lockProbe;
41
44
  try {
42
- lockProbe = writerOf(provider.forPrincipal(opts.toPrincipal));
45
+ lockProbe = writerOf(provider.forPrincipal(o.toPrincipal));
43
46
  }
44
47
  catch (err) {
45
48
  if (!(err instanceof FileStoreLockError))
@@ -50,7 +53,7 @@ export async function adoptFilePermissionRuleStore(opts) {
50
53
  throw new Error("the target store refused a write face");
51
54
  let phase = existing !== undefined && "marker" in existing ? existing.marker.phase : 2;
52
55
  if (existing === undefined) {
53
- writeRuleAdoptionFile(opts.dir, marker(from, opts.toPrincipal, 2));
56
+ writeRuleAdoptionFile(o.dir, marker(from, o.toPrincipal, 2));
54
57
  phase = 2;
55
58
  }
56
59
  if (phase < 3) {
@@ -61,11 +64,11 @@ export async function adoptFilePermissionRuleStore(opts) {
61
64
  }
62
65
  if (sourcePresent)
63
66
  renameSync(sourceFile, targetFile);
64
- writeRuleAdoptionFile(opts.dir, marker(from, opts.toPrincipal, 3));
67
+ writeRuleAdoptionFile(o.dir, marker(from, o.toPrincipal, 3));
65
68
  phase = 3;
66
69
  }
67
70
  if (phase < 4) {
68
- writeRuleAdoptionFile(opts.dir, marker(from, opts.toPrincipal, 4));
71
+ writeRuleAdoptionFile(o.dir, marker(from, o.toPrincipal, 4));
69
72
  phase = 4;
70
73
  }
71
74
  let syncResult;
@@ -73,9 +76,9 @@ export async function adoptFilePermissionRuleStore(opts) {
73
76
  try {
74
77
  syncResult = await syncPermissionRules({
75
78
  provider: createPermissionRuleStoreProvider({ durable: provider }),
76
- principal: opts.toPrincipal,
77
- transport: opts.transport,
78
- ...(opts.now !== undefined ? { now: opts.now } : {}),
79
+ principal: o.toPrincipal,
80
+ transport: o.transport,
81
+ ...(o.now !== undefined ? { now: o.now } : {}),
79
82
  });
80
83
  }
81
84
  catch (err) {
@@ -88,12 +91,12 @@ export async function adoptFilePermissionRuleStore(opts) {
88
91
  error: `the first sync round did not land clean (${(syncResult.warnings ?? []).join("; ") || `${syncResult.dropped.length} drop(s)`}) — resume when the endpoint is healthy`,
89
92
  };
90
93
  }
91
- writeRuleAdoptionFile(opts.dir, marker(from, opts.toPrincipal, 5));
94
+ writeRuleAdoptionFile(o.dir, marker(from, o.toPrincipal, 5));
92
95
  phase = 5;
93
96
  }
94
- writeRuleAdoptionFile(opts.dir, {
97
+ writeRuleAdoptionFile(o.dir, {
95
98
  schemaVersion: 1,
96
- adopted: { from, toPrincipal: opts.toPrincipal, atMs: (opts.now ?? Date.now)() },
99
+ adopted: { from, toPrincipal: o.toPrincipal, atMs: (o.now ?? Date.now)() },
97
100
  });
98
101
  return { status: "adopted", ...(syncResult !== undefined ? { syncResult } : {}) };
99
102
  }
@@ -11,6 +11,7 @@ import { SESSION_RULES_GRAMMAR, readRuleGrammarStamp } from "../../core/session-
11
11
  import { canonicalize } from "../../core/canonical-json.js";
12
12
  import { BootLock, FileStoreLockError } from "./fs-atomic.js";
13
13
  import { assertAdoptionBootGate } from "./adoption/marker.js";
14
+ import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
14
15
  import { thrownText } from "../../core/thrown-value.js";
15
16
  function isRuleFile(v) {
16
17
  const p = v;
@@ -402,6 +403,7 @@ class FileDurableRulePartition {
402
403
  }),
403
404
  };
404
405
  }
406
+ const FILE_DURABLE_RULE_PARTITION_PROVIDER_OPTION_KEYS = optionKeys()({ dataRoot: 0, platform: 0 });
405
407
  export class FileDurableRulePartitionProvider {
406
408
  dir;
407
409
  onError;
@@ -411,11 +413,12 @@ export class FileDurableRulePartitionProvider {
411
413
  constructor(dir, onError, opts) {
412
414
  this.dir = dir;
413
415
  this.onError = onError;
414
- if (opts?.dataRoot !== undefined)
415
- assertAdoptionBootGate(opts.dataRoot, "FileDurableRulePartitionProvider");
416
+ const options = receiveOptions(opts, "FileDurableRulePartitionProvider", FILE_DURABLE_RULE_PARTITION_PROVIDER_OPTION_KEYS);
417
+ if (options.dataRoot !== undefined)
418
+ assertAdoptionBootGate(options.dataRoot, "FileDurableRulePartitionProvider");
416
419
  let said = false;
417
420
  this.vetting = {
418
- platform: opts?.platform,
421
+ platform: options.platform,
419
422
  modeBitsUnjudged: (where) => {
420
423
  if (said)
421
424
  return;
@@ -4,7 +4,8 @@ import { judgeSessionRulesWrite, readMountedToolNames, readSessionRulesShape, Se
4
4
  import { atomicWriteFile, ensureDir, sanitizeScope } from "./fs-atomic.js";
5
5
  import { guardCorruptSink } from "./corrupt-read-sink.js";
6
6
  import { assertAdoptionBootGate, readRootAdoptionFile } from "./adoption/marker.js";
7
- import { receiveOptions } from "../../core/own-property-receipt.js";
7
+ import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
8
+ const FILE_SESSION_POLICY_STORE_OPTION_KEYS = optionKeys()({ mountedToolNames: 0, onCorruptRead: 0 });
8
9
  export const SESSION_POLICY_MARK_SUFFIX = ".hwm.json";
9
10
  const MARK_SUFFIX = SESSION_POLICY_MARK_SUFFIX;
10
11
  export function readSessionPolicyMark(path) {
@@ -75,7 +76,7 @@ export class FileSessionPolicyStore {
75
76
  mountedToolNames;
76
77
  anonymousAlias;
77
78
  constructor(root, options) {
78
- const opts = receiveOptions(options, "FileSessionPolicyStore");
79
+ const opts = receiveOptions(options, "FileSessionPolicyStore", FILE_SESSION_POLICY_STORE_OPTION_KEYS);
79
80
  assertAdoptionBootGate(root, "FileSessionPolicyStore");
80
81
  this.mountedToolNames = readMountedToolNames(opts?.mountedToolNames);
81
82
  this.dir = join(root, "session-policy");
@@ -51,6 +51,13 @@ export declare class FileSessionRepo implements SessionRepo {
51
51
  * the row). `skipped` words the corrupt-header refusal's reading of the records around it, where the caller has one.
52
52
  */
53
53
  private headerOf;
54
+ /**
55
+ * The row's header record, where the log has one: its FIRST record, which must be the meta header every write path lays down. A log whose
56
+ * first record is anything else is no row this store wrote — `corrupt_session`, said once here for every reader of the row. The cells
57
+ * inside it are each read by their own reader ({@link headerOf} for the whole header, `placementOf` for the placement tuple alone):
58
+ * a reader of one cell does not answer for the others.
59
+ */
60
+ private metaLineOf;
54
61
  /**
55
62
  * The row's head in one read, without replaying the log: ONE descriptor on the session file, its first record for the owner and
56
63
  * occupant cells, and walking back from its end to the last entry record for the leaf. The three come from one inode — a file
@@ -73,9 +80,13 @@ export declare class FileSessionRepo implements SessionRepo {
73
80
  * `undefined` = no row; a row whose header cannot be read rejects (`corrupt_session`).
74
81
  */
75
82
  private rowOf;
76
- /** The one descriptor a by-id read of the row takes: its size and modification time and its header, from one inode (a file replaced
77
- * or removed while this reads is still the inode this descriptor opened); `undefined` = no file. */
83
+ /** The one descriptor a by-id read of the row takes: its size and modification time and its header decoded whole, from one inode (a
84
+ * file replaced or removed while this reads is still the inode this descriptor opened); `undefined` = no file. A reader of one cell
85
+ * alone takes {@link atFirstRecord}, which this is built on. */
78
86
  private atRow;
87
+ /** The descriptor under every by-id header read: the file's size and modification time and its first record, undecoded — the bytes
88
+ * each cell's reader decodes. One inode, bounded by the lines before the first record, never by the log; `undefined` = no file. */
89
+ private atFirstRecord;
79
90
  private storage;
80
91
  /**
81
92
  * RB-437 — release every shared authority this repo joined (LAST holder ⇒ evict + close the append fd).
@@ -119,7 +130,9 @@ export declare class FileSessionRepo implements SessionRepo {
119
130
  scope?: string;
120
131
  }): Promise<PlacedSessionRow[]>;
121
132
  /** Cheap placement probe for one id (the TtlSessionStore's cold-cache release consults it so the
122
- * placed real-deletion obligation holds after a restart). `undefined` = missing file OR unplaced; a row that cannot be read rejects. */
133
+ * placed real-deletion obligation holds after a restart), answered from the row's header record alone — never a replay of its log —
134
+ * and from the placement cell alone: a row whose owner cell cannot be read still says whether it is placed (the readers of the owner
135
+ * refuse that row; this probe is not one of them). `undefined` = missing file OR unplaced; a log with no header record rejects. */
123
136
  placementOf(sessionId: string): Promise<SessionPlacementRecord | undefined>;
124
137
  delete(metadata: SessionMetadata, expect?: SessionRowExpectation): Promise<void>;
125
138
  fork(sourceMetadata: SessionMetadata, options?: SessionForkOptions & SessionCreateOptions): Promise<Session>;
@@ -4,7 +4,7 @@ import { BaseSessionStorage, StoredSession, SessionError, assertForkTarget, comp
4
4
  import { canonicalStoreKey, AppendLog, atomicWriteFile, ensureDir, firstJsonlRecord, lastJsonlRecord, readJsonlRecords, sanitizePathComponent, writeThenLink } from "./fs-atomic.js";
5
5
  import { guardCorruptSink } from "./corrupt-read-sink.js";
6
6
  import { assertAdoptionBootGate } from "./adoption/marker.js";
7
- import { receiveOptions } from "../../core/own-property-receipt.js";
7
+ import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
8
8
  import { thrownText } from "../../core/thrown-value.js";
9
9
  const SUFFIX = ".jsonl";
10
10
  const SESSION_LINE_JUDGE = {
@@ -72,13 +72,14 @@ class FileSessionStorage extends BaseSessionStorage {
72
72
  this.recordEntry(entry);
73
73
  }
74
74
  }
75
+ const FILE_SESSION_REPO_OPTION_KEYS = optionKeys()({ onCorruptRead: 0 });
75
76
  export class FileSessionRepo {
76
77
  dir;
77
78
  tmpDir;
78
79
  onCorruptRead;
79
80
  joined = new Map();
80
81
  constructor(root, options) {
81
- const opts = receiveOptions(options, "FileSessionRepo");
82
+ const opts = receiveOptions(options, "FileSessionRepo", FILE_SESSION_REPO_OPTION_KEYS);
82
83
  assertAdoptionBootGate(root, "FileSessionRepo");
83
84
  this.dir = join(root, "sessions");
84
85
  this.tmpDir = join(root, "tmp");
@@ -111,21 +112,25 @@ export class FileSessionRepo {
111
112
  return { meta, entries };
112
113
  }
113
114
  headerOf(id, path, first, skipped = () => "") {
114
- if (first === undefined || first.kind !== "meta")
115
- throw new SessionError("corrupt_session", `Session ${id} is unreadable: its log has no meta header${skipped()}`);
115
+ const head = this.metaLineOf(id, first, skipped);
116
116
  const said = (key) => (detail) => this.disclose(path, `session header ${key}: ${detail}`, id);
117
- const incarnation = readIncarnationCell(first.incarnation, said("incarnation"));
118
- const forkedFromIncarnation = readIncarnationCell(first.forkedFromIncarnation, said("forkedFromIncarnation"));
117
+ const incarnation = readIncarnationCell(head.incarnation, said("incarnation"));
118
+ const forkedFromIncarnation = readIncarnationCell(head.forkedFromIncarnation, said("forkedFromIncarnation"));
119
119
  return {
120
120
  id,
121
- createdAt: first.createdAt,
122
- ...(first.forkedFrom !== undefined ? { forkedFrom: first.forkedFrom } : {}),
123
- ...(first.placement !== undefined ? { placement: first.placement } : {}),
121
+ createdAt: head.createdAt,
122
+ ...(head.forkedFrom !== undefined ? { forkedFrom: head.forkedFrom } : {}),
123
+ ...(head.placement !== undefined ? { placement: head.placement } : {}),
124
124
  ...(incarnation !== undefined ? { incarnation } : {}),
125
125
  ...(forkedFromIncarnation !== undefined ? { forkedFromIncarnation } : {}),
126
- owner: readOwnerCell(first.owner, id),
126
+ owner: readOwnerCell(head.owner, id),
127
127
  };
128
128
  }
129
+ metaLineOf(id, first, skipped = () => "") {
130
+ if (first === undefined || first.kind !== "meta")
131
+ throw new SessionError("corrupt_session", `Session ${id} is unreadable: its log has no meta header${skipped()}`);
132
+ return first;
133
+ }
129
134
  async headOf(sessionId) {
130
135
  return this.headNow(sessionId);
131
136
  }
@@ -156,9 +161,12 @@ export class FileSessionRepo {
156
161
  }
157
162
  atRow(sessionId, read) {
158
163
  const path = this.pathFor(sessionId);
164
+ return this.atFirstRecord(sessionId, (fd, size, first, mtimeMs) => read(fd, size, this.headerOf(sessionId, path, first), mtimeMs));
165
+ }
166
+ atFirstRecord(sessionId, read) {
159
167
  let fd;
160
168
  try {
161
- fd = openSync(path, "r");
169
+ fd = openSync(this.pathFor(sessionId), "r");
162
170
  }
163
171
  catch (err) {
164
172
  if (err.code === "ENOENT")
@@ -167,7 +175,7 @@ export class FileSessionRepo {
167
175
  }
168
176
  try {
169
177
  const { size, mtimeMs } = fstatSync(fd);
170
- return read(fd, size, this.headerOf(sessionId, path, firstJsonlRecord(fd, size, SESSION_LINE_JUDGE)), mtimeMs);
178
+ return read(fd, size, firstJsonlRecord(fd, size, SESSION_LINE_JUDGE), mtimeMs);
171
179
  }
172
180
  finally {
173
181
  closeSync(fd);
@@ -292,14 +300,7 @@ export class FileSessionRepo {
292
300
  return out;
293
301
  }
294
302
  async placementOf(sessionId) {
295
- try {
296
- return this.read(sessionId).meta.placement;
297
- }
298
- catch (err) {
299
- if (err instanceof SessionError && err.code === "not_found")
300
- return undefined;
301
- throw err;
302
- }
303
+ return this.atFirstRecord(sessionId, (_fd, _size, first) => this.metaLineOf(sessionId, first).placement);
303
304
  }
304
305
  async delete(metadata, expect) {
305
306
  if (expect !== undefined && !sessionRowMatches(expect, this.headNow(metadata.id), () => sessionLogMarkOf(this.read(metadata.id).entries)))