@sema-agent/core 7.70.0 → 7.71.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/CHANGELOG.md +740 -0
  2. package/dist/agents/agent-transcript-tool.js +43 -19
  3. package/dist/agents/inherited-tool-pool.d.ts +5 -1
  4. package/dist/agents/inherited-tool-pool.js +6 -0
  5. package/dist/agents/retain-ledger.js +2 -0
  6. package/dist/agents/send-message-tool.d.ts +12 -1
  7. package/dist/agents/send-message-tool.js +47 -9
  8. package/dist/agents/subagent.js +31 -10
  9. package/dist/agents/tool-filter.js +1 -2
  10. package/dist/agents/verify.js +13 -2
  11. package/dist/agents/yield-adoption.js +11 -1
  12. package/dist/brain/claude-model-id.d.ts +11 -0
  13. package/dist/brain/claude-model-id.js +3 -1
  14. package/dist/config/catalog.js +10 -1
  15. package/dist/config/defaults.d.ts +3 -0
  16. package/dist/config/defaults.js +1 -0
  17. package/dist/core/allow-entry.js +1 -2
  18. package/dist/core/ask-origin.d.ts +55 -21
  19. package/dist/core/ask-origin.js +19 -11
  20. package/dist/core/ask-question.d.ts +4 -7
  21. package/dist/core/ask-question.js +2 -4
  22. package/dist/core/ask-unresolvable-notice.d.ts +17 -3
  23. package/dist/core/ask-unresolvable-notice.js +18 -4
  24. package/dist/core/attachment-source.d.ts +1 -1
  25. package/dist/core/attachment-source.js +2 -0
  26. package/dist/core/auto-compaction.d.ts +14 -4
  27. package/dist/core/auto-compaction.js +3 -2
  28. package/dist/core/auto-strip.js +2 -0
  29. package/dist/core/caller-text.d.ts +2 -33
  30. package/dist/core/caller-text.js +2 -23
  31. package/dist/core/caller-tool-name.js +1 -2
  32. package/dist/core/canonical-json.d.ts +9 -0
  33. package/dist/core/canonical-json.js +6 -0
  34. package/dist/core/checkpoint-features.d.ts +43 -80
  35. package/dist/core/checkpoint-features.js +10 -20
  36. package/dist/core/checkpoint-generation.d.ts +89 -19
  37. package/dist/core/checkpoint-generation.js +89 -14
  38. package/dist/core/checkpoint-queries.d.ts +95 -15
  39. package/dist/core/checkpoint-queries.js +108 -7
  40. package/dist/core/checkpoint-rekey.d.ts +2 -1
  41. package/dist/core/checkpoint-rekey.js +2 -2
  42. package/dist/core/checkpoint-requirements.d.ts +21 -7
  43. package/dist/core/checkpoint-requirements.js +2 -5
  44. package/dist/core/checkpoint-row-verdict.d.ts +3 -4
  45. package/dist/core/checkpoint-row-verdict.js +20 -41
  46. package/dist/core/checkpoint-store.d.ts +69 -41
  47. package/dist/core/checkpoint-store.js +28 -14
  48. package/dist/core/command-sandbox.d.ts +5 -3
  49. package/dist/core/command-sandbox.js +17 -9
  50. package/dist/core/config-refusal-codes.d.ts +1 -1
  51. package/dist/core/config-refusal-codes.js +1 -0
  52. package/dist/core/declaration-words.d.ts +2 -1
  53. package/dist/core/declaration-words.js +13 -2
  54. package/dist/core/effective-path-target.d.ts +23 -0
  55. package/dist/core/effective-path-target.js +15 -1
  56. package/dist/core/engine-attestation.d.ts +5 -1
  57. package/dist/core/engine-attestation.js +1 -0
  58. package/dist/core/engine-capabilities.d.ts +14 -9
  59. package/dist/core/engine-capabilities.js +1 -1
  60. package/dist/core/engine-notice.d.ts +62 -32
  61. package/dist/core/engine-version.js +1 -1
  62. package/dist/core/entries-not-applied.d.ts +1 -1
  63. package/dist/core/entries-not-applied.js +1 -0
  64. package/dist/core/file-history-store.d.ts +95 -11
  65. package/dist/core/file-history-store.js +117 -19
  66. package/dist/core/gate-fold.js +13 -7
  67. package/dist/core/gate-lanes.js +9 -9
  68. package/dist/core/governance-codes.d.ts +56 -7
  69. package/dist/core/governance-codes.js +105 -7
  70. package/dist/core/grant-holder.d.ts +53 -0
  71. package/dist/core/grant-holder.js +80 -0
  72. package/dist/core/hooks.d.ts +7 -3
  73. package/dist/core/hooks.js +2 -2
  74. package/dist/core/locked-config.d.ts +7 -1
  75. package/dist/core/locked-config.js +9 -2
  76. package/dist/core/mcp-call-meta.d.ts +52 -7
  77. package/dist/core/mcp-call-meta.js +21 -2
  78. package/dist/core/mcp-host-read.d.ts +1 -1
  79. package/dist/core/mcp-server-spec.d.ts +18 -0
  80. package/dist/core/mcp-server-spec.js +1 -0
  81. package/dist/core/mcp.js +2 -2
  82. package/dist/core/member-outcome.d.ts +22 -1
  83. package/dist/core/member-outcome.js +18 -6
  84. package/dist/core/memory-engine/delegation-settlement.js +5 -5
  85. package/dist/core/memory-engine/engine.js +19 -19
  86. package/dist/core/memory-engine/file-backend.d.ts +7 -2
  87. package/dist/core/memory-engine/file-backend.js +14 -12
  88. package/dist/core/memory-engine/frontmatter.js +1 -1
  89. package/dist/core/memory-engine/index.d.ts +1 -0
  90. package/dist/core/memory-engine/index.js +1 -0
  91. package/dist/core/memory-engine/layout.d.ts +34 -9
  92. package/dist/core/memory-engine/layout.js +36 -19
  93. package/dist/core/memory-engine/memory-deployment.js +8 -8
  94. package/dist/core/memory-engine/mount-failed-notice.d.ts +8 -5
  95. package/dist/core/memory-engine/mount-failed-notice.js +5 -2
  96. package/dist/core/mode-policy.d.ts +5 -0
  97. package/dist/core/mode-policy.js +6 -0
  98. package/dist/core/mods/host.d.ts +2 -1
  99. package/dist/core/mods/host.js +7 -6
  100. package/dist/core/mods/kernel/index.d.ts +1 -1
  101. package/dist/core/mods/kernel/index.js +1 -1
  102. package/dist/core/mods/kernel/registration.d.ts +5 -2
  103. package/dist/core/mods/kernel/registration.js +19 -3
  104. package/dist/core/mods/package.d.ts +12 -1
  105. package/dist/core/mods/package.js +36 -9
  106. package/dist/core/mods/stations.d.ts +7 -1
  107. package/dist/core/mods/stations.js +17 -3
  108. package/dist/core/mods/teammate-stations.d.ts +4 -1
  109. package/dist/core/mods/teammate-stations.js +1 -1
  110. package/dist/core/native-signal.d.ts +13 -0
  111. package/dist/core/native-signal.js +18 -0
  112. package/dist/core/park-resumability.d.ts +16 -14
  113. package/dist/core/park-resumability.js +9 -4
  114. package/dist/core/path-rule-binding.js +1 -1
  115. package/dist/core/permission-rule-model.d.ts +11 -5
  116. package/dist/core/permission-rule-model.js +5 -3
  117. package/dist/core/permission-rule-org.js +1 -1
  118. package/dist/core/permission-rule-provider.d.ts +5 -1
  119. package/dist/core/permission-rule-provider.js +6 -1
  120. package/dist/core/permission-rule-session.d.ts +35 -5
  121. package/dist/core/permission-rule-session.js +32 -1
  122. package/dist/core/permission-rule-store.d.ts +5 -1
  123. package/dist/core/permission-rule-store.js +28 -5
  124. package/dist/core/permission-rules.d.ts +2 -2
  125. package/dist/core/permission-rules.js +2 -3
  126. package/dist/core/principal-name.d.ts +12 -0
  127. package/dist/core/principal-name.js +6 -2
  128. package/dist/core/read-root-grant-screen.d.ts +7 -6
  129. package/dist/core/read-root-grant-screen.js +7 -8
  130. package/dist/core/remote-env.d.ts +42 -8
  131. package/dist/core/resume-config-judge.js +1 -1
  132. package/dist/core/resume-startup-cause.d.ts +19 -4
  133. package/dist/core/resume-startup-cause.js +25 -6
  134. package/dist/core/rewind-conversation.d.ts +4 -0
  135. package/dist/core/rewrite-rejudge.d.ts +9 -1
  136. package/dist/core/rewrite-rejudge.js +11 -1
  137. package/dist/core/rule-offer-read.js +3 -2
  138. package/dist/core/runner/assemble-result.d.ts +21 -11
  139. package/dist/core/runner/assemble-result.js +24 -4
  140. package/dist/core/runner/boundary-reminders.d.ts +104 -0
  141. package/dist/core/runner/boundary-reminders.js +108 -0
  142. package/dist/core/runner/branch-writeback.d.ts +21 -7
  143. package/dist/core/runner/branch-writeback.js +44 -6
  144. package/dist/core/runner/command-sandbox-frame.js +2 -1
  145. package/dist/core/runner/compact-session.js +11 -4
  146. package/dist/core/runner/constraint-layers.d.ts +24 -5
  147. package/dist/core/runner/constraint-layers.js +21 -2
  148. package/dist/core/runner/continuation-gate.js +3 -1
  149. package/dist/core/runner/contracts.d.ts +83 -13
  150. package/dist/core/runner/cross-boundary-lane.js +2 -1
  151. package/dist/core/runner/delegation-owner.d.ts +246 -45
  152. package/dist/core/runner/delegation-owner.js +237 -63
  153. package/dist/core/runner/expire-settle.d.ts +17 -0
  154. package/dist/core/runner/expire-settle.js +8 -2
  155. package/dist/core/runner/file-history-request.d.ts +4 -3
  156. package/dist/core/runner/file-history-request.js +4 -1
  157. package/dist/core/runner/file-history-restore.d.ts +11 -3
  158. package/dist/core/runner/file-history-restore.js +11 -3
  159. package/dist/core/runner/gate-exit.d.ts +22 -1
  160. package/dist/core/runner/gate-exit.js +12 -14
  161. package/dist/core/runner/nested-memory-content.js +1 -1
  162. package/dist/core/runner/nested-memory-lane.d.ts +10 -2
  163. package/dist/core/runner/nested-memory-lane.js +29 -8
  164. package/dist/core/runner/own-model-money-door.d.ts +13 -0
  165. package/dist/core/runner/own-model-money-door.js +17 -0
  166. package/dist/core/runner/park-commit.d.ts +4 -2
  167. package/dist/core/runner/park-commit.js +2 -1
  168. package/dist/core/runner/permission-rule-lanes.d.ts +4 -0
  169. package/dist/core/runner/permission-rule-lanes.js +7 -0
  170. package/dist/core/runner/person-path-rows.js +1 -1
  171. package/dist/core/runner/placement-fence.d.ts +8 -2
  172. package/dist/core/runner/placement-fence.js +8 -3
  173. package/dist/core/runner/policy-throw.d.ts +3 -2
  174. package/dist/core/runner/policy-throw.js +2 -2
  175. package/dist/core/runner/prepare-acquire-reconcile.d.ts +23 -14
  176. package/dist/core/runner/prepare-acquire-reconcile.js +33 -15
  177. package/dist/core/runner/prepare-artifact.d.ts +14 -1
  178. package/dist/core/runner/prepare-artifact.js +7 -2
  179. package/dist/core/runner/prepare-ask-lane.d.ts +8 -0
  180. package/dist/core/runner/prepare-ask-lane.js +14 -5
  181. package/dist/core/runner/prepare-boundary-parks.js +5 -4
  182. package/dist/core/runner/prepare-config-doors.d.ts +9 -4
  183. package/dist/core/runner/prepare-config-doors.js +25 -8
  184. package/dist/core/runner/prepare-defer-classify.d.ts +8 -4
  185. package/dist/core/runner/prepare-defer-classify.js +6 -6
  186. package/dist/core/runner/prepare-execution-env.d.ts +4 -1
  187. package/dist/core/runner/prepare-execution-env.js +8 -3
  188. package/dist/core/runner/prepare-file-history.d.ts +26 -0
  189. package/dist/core/runner/prepare-file-history.js +15 -1
  190. package/dist/core/runner/prepare-inherited-gate.d.ts +8 -3
  191. package/dist/core/runner/prepare-inherited-gate.js +9 -2
  192. package/dist/core/runner/prepare-leg-adoption.d.ts +2 -2
  193. package/dist/core/runner/prepare-park-ask.js +8 -5
  194. package/dist/core/runner/prepare-policy-chain.d.ts +5 -0
  195. package/dist/core/runner/prepare-policy-chain.js +18 -7
  196. package/dist/core/runner/prepare-prompt-assembly.d.ts +3 -0
  197. package/dist/core/runner/prepare-prompt-assembly.js +4 -3
  198. package/dist/core/runner/prepare-suspend-saga.d.ts +4 -1
  199. package/dist/core/runner/prepare-suspend-saga.js +19 -5
  200. package/dist/core/runner/prepare-task.d.ts +2 -5
  201. package/dist/core/runner/prepare-task.js +71 -26
  202. package/dist/core/runner/prepare-turn-wiring.js +7 -5
  203. package/dist/core/runner/prepare-workspace-restore.js +59 -28
  204. package/dist/core/runner/read-root-grant.d.ts +1 -0
  205. package/dist/core/runner/read-root-grant.js +1 -2
  206. package/dist/core/runner/resume-admission.d.ts +3 -0
  207. package/dist/core/runner/resume-admission.js +6 -4
  208. package/dist/core/runner/resume-apply.js +7 -5
  209. package/dist/core/runner/resume-claim.d.ts +2 -2
  210. package/dist/core/runner/resume-claim.js +4 -4
  211. package/dist/core/runner/resume-policy-outcome.d.ts +1 -1
  212. package/dist/core/runner/resume-policy-outcome.js +6 -4
  213. package/dist/core/runner/resume-preflight.d.ts +3 -0
  214. package/dist/core/runner/resume-preflight.js +10 -3
  215. package/dist/core/runner/rewind-conversation.js +11 -4
  216. package/dist/core/runner/rewind-files.js +29 -14
  217. package/dist/core/runner/rewind-outcome.d.ts +27 -0
  218. package/dist/core/runner/rewind-outcome.js +14 -0
  219. package/dist/core/runner/run-attachment-seats.js +2 -1
  220. package/dist/core/runner/run-clock-and-content.js +2 -0
  221. package/dist/core/runner/run-identity-wiring.js +2 -0
  222. package/dist/core/runner/run-leg.js +11 -1
  223. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  224. package/dist/core/runner/run-notification-lane.js +2 -2
  225. package/dist/core/runner/run-settle-and-teardown.d.ts +4 -2
  226. package/dist/core/runner/run-settle-and-teardown.js +52 -40
  227. package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
  228. package/dist/core/runner/run-stop-and-final-verify.js +5 -4
  229. package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
  230. package/dist/core/runner/run-terminal-adoption.js +3 -3
  231. package/dist/core/runner/run-turn-boundary.js +7 -0
  232. package/dist/core/runner/runtask.d.ts +7 -4
  233. package/dist/core/runner/runtask.js +18 -9
  234. package/dist/core/runner/session-call-grant-station.d.ts +64 -0
  235. package/dist/core/runner/session-call-grant-station.js +119 -0
  236. package/dist/core/runner/session-file-state-replay.js +2 -2
  237. package/dist/core/runner/session-prompt-seats.d.ts +95 -0
  238. package/dist/core/runner/session-prompt-seats.js +62 -0
  239. package/dist/core/runner/session-rule-policy.js +1 -1
  240. package/dist/core/runner/session-write-ledger.d.ts +8 -0
  241. package/dist/core/runner/session-write-ledger.js +16 -0
  242. package/dist/core/runner/side-call-account.js +5 -1
  243. package/dist/core/runner/stop-tail-notice.d.ts +7 -0
  244. package/dist/core/runner/stop-tail-notice.js +23 -8
  245. package/dist/core/runner/stream-reap.js +4 -2
  246. package/dist/core/runner/stream-settle-backstop.d.ts +1 -1
  247. package/dist/core/runner/stream-settle-backstop.js +17 -18
  248. package/dist/core/runner/terminal-account.js +17 -8
  249. package/dist/core/runner/terminal-projection.d.ts +3 -2
  250. package/dist/core/runner/terminal-projection.js +1 -1
  251. package/dist/core/runner/tool-turn-repair-seat.d.ts +2 -2
  252. package/dist/core/runner/tool-turn-repair-seat.js +12 -7
  253. package/dist/core/runner/turn-attachments.d.ts +22 -1
  254. package/dist/core/runner/turn-attachments.js +20 -3
  255. package/dist/core/runner-deps.d.ts +6 -2
  256. package/dist/core/secret-env.d.ts +26 -6
  257. package/dist/core/secret-env.js +6 -6
  258. package/dist/core/session-call-grant-screen.d.ts +58 -0
  259. package/dist/core/session-call-grant-screen.js +18 -0
  260. package/dist/core/session-call-grant.d.ts +93 -0
  261. package/dist/core/session-call-grant.js +524 -0
  262. package/dist/core/session-checkout.d.ts +3 -0
  263. package/dist/core/session-checkout.js +8 -3
  264. package/dist/core/session-policy-store.d.ts +14 -0
  265. package/dist/core/session-policy-store.js +16 -2
  266. package/dist/core/session-store.d.ts +18 -1
  267. package/dist/core/session-store.js +20 -4
  268. package/dist/core/session.d.ts +36 -4
  269. package/dist/core/shared-artifact-reads.d.ts +93 -0
  270. package/dist/core/shared-artifact-reads.js +94 -0
  271. package/dist/core/skill-grant.js +1 -1
  272. package/dist/core/skills-directory.d.ts +9 -45
  273. package/dist/core/skills-directory.js +9 -722
  274. package/dist/core/spend-account.js +3 -0
  275. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +22 -4
  276. package/dist/core/store-contracts/checkpoint-store-contract.js +363 -29
  277. package/dist/core/store-contracts/file-history-store-contract.d.ts +11 -3
  278. package/dist/core/store-contracts/file-history-store-contract.js +62 -2
  279. package/dist/core/store-contracts/grant-fixture.d.ts +52 -0
  280. package/dist/core/store-contracts/grant-fixture.js +84 -0
  281. package/dist/core/store-contracts/session-repo-contract.js +18 -0
  282. package/dist/core/store-contracts/session-store-contract.d.ts +15 -1
  283. package/dist/core/store-contracts/session-store-contract.js +211 -2
  284. package/dist/core/store-contracts/workflow-journal-store-contract.js +47 -8
  285. package/dist/core/suspend-lane-reasons.d.ts +13 -0
  286. package/dist/core/suspend-lane-reasons.js +5 -0
  287. package/dist/core/synthetic-read-verdict.d.ts +5 -3
  288. package/dist/core/synthetic-read-verdict.js +1 -1
  289. package/dist/core/task-limits.d.ts +15 -0
  290. package/dist/core/task-notification.d.ts +33 -7
  291. package/dist/core/task-notification.js +34 -9
  292. package/dist/core/task-registry-agent.d.ts +1 -1
  293. package/dist/core/task-registry-agent.js +18 -7
  294. package/dist/core/task-registry-shared.d.ts +29 -4
  295. package/dist/core/task-registry-shared.js +7 -0
  296. package/dist/core/task-registry.d.ts +21 -1
  297. package/dist/core/task-registry.js +36 -9
  298. package/dist/core/task-result.d.ts +55 -1
  299. package/dist/core/task-spec.d.ts +17 -3
  300. package/dist/core/terminal-cause.d.ts +68 -5
  301. package/dist/core/tool-catalog-entries.js +1 -1
  302. package/dist/core/tool-check-reading.js +2 -1
  303. package/dist/core/tool-errors.js +1 -0
  304. package/dist/core/tool-list-grammar.d.ts +0 -47
  305. package/dist/core/tool-list-grammar.js +1 -75
  306. package/dist/core/tool-model-gate.d.ts +7 -11
  307. package/dist/core/tool-model-gate.js +5 -8
  308. package/dist/core/tool-name-aliases.js +2 -3
  309. package/dist/core/tool-name-readings.d.ts +4 -0
  310. package/dist/core/tool-name-readings.js +1 -0
  311. package/dist/core/tool-policy.d.ts +46 -4
  312. package/dist/core/tool-policy.js +47 -18
  313. package/dist/core/tool-result-store.d.ts +0 -24
  314. package/dist/core/tool-result-store.js +1 -36
  315. package/dist/core/tool-spec.d.ts +8 -4
  316. package/dist/core/untrusted-egress.js +2 -2
  317. package/dist/core/untrusted-text.d.ts +8 -0
  318. package/dist/core/untrusted-text.js +14 -0
  319. package/dist/core/user-attachment.d.ts +16 -1
  320. package/dist/core/user-attachment.js +42 -18
  321. package/dist/core/wiring-manifest.d.ts +4 -9
  322. package/dist/core/wiring-manifest.js +1 -1
  323. package/dist/core/workflow-journal-store.d.ts +55 -8
  324. package/dist/core/workflow-journal-store.js +34 -10
  325. package/dist/core/workflow-run-store-contract.js +56 -1
  326. package/dist/core/workflow-run-store.d.ts +43 -19
  327. package/dist/core/workflow-run-store.js +17 -2
  328. package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
  329. package/dist/engine/execution-env/node-execution-env.js +4 -0
  330. package/dist/engine/harness/agent-harness.d.ts +10 -5
  331. package/dist/engine/harness/agent-harness.js +12 -4
  332. package/dist/engine/harness/types.d.ts +18 -0
  333. package/dist/engine/llm/tool-turns.d.ts +1 -1
  334. package/dist/engine/llm/types.d.ts +5 -4
  335. package/dist/engine/session/memory-repo.d.ts +15 -3
  336. package/dist/engine/session/memory-repo.js +21 -3
  337. package/dist/engine/session/memory-storage.d.ts +5 -0
  338. package/dist/engine/session/memory-storage.js +8 -3
  339. package/dist/engine/session/repo-utils.d.ts +9 -0
  340. package/dist/engine/session/repo-utils.js +14 -0
  341. package/dist/engine/session/storage-base.d.ts +20 -7
  342. package/dist/engine/session/storage-base.js +13 -1
  343. package/dist/index.d.ts +39 -21
  344. package/dist/index.js +32 -17
  345. package/dist/internal/harness.d.ts +1 -1
  346. package/dist/internal/harness.js +1 -1
  347. package/dist/orchestration/run-workflow-tool.d.ts +13 -1
  348. package/dist/orchestration/run-workflow-tool.js +101 -32
  349. package/dist/orchestration/workflow-park-adoption.d.ts +309 -92
  350. package/dist/orchestration/workflow-park-adoption.js +588 -323
  351. package/dist/orchestration/workflow-tree-id.d.ts +66 -0
  352. package/dist/orchestration/workflow-tree-id.js +66 -0
  353. package/dist/orchestration/workflow-types.d.ts +90 -11
  354. package/dist/orchestration/workflow-types.js +10 -1
  355. package/dist/orchestration/workflow.d.ts +30 -4
  356. package/dist/orchestration/workflow.js +424 -114
  357. package/dist/prompt-assembly/catalog/constitution.js +5 -1
  358. package/dist/prompt-assembly/catalog/core-behavior.d.ts +3 -4
  359. package/dist/prompt-assembly/catalog/core-behavior.js +61 -22
  360. package/dist/prompt-assembly/catalog/environment.js +2 -2
  361. package/dist/prompt-assembly/catalog/events.d.ts +16 -0
  362. package/dist/prompt-assembly/catalog/events.js +2 -0
  363. package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +72 -44
  364. package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.js +2 -2
  365. package/dist/prompt-assembly/catalog/locales/zh-Hans/events.js +2 -0
  366. package/dist/prompt-assembly/catalog/schema.d.ts +5 -1
  367. package/dist/prompt-assembly/catalog/schema.js +2 -0
  368. package/dist/prompt-assembly/catalog/sections.js +3 -14
  369. package/dist/prompt-assembly/event-registry.js +2 -0
  370. package/dist/prompt-assembly/select.js +1 -0
  371. package/dist/prompt-assembly/tool-catalog.d.ts +10 -7
  372. package/dist/prompt-assembly/tool-catalog.js +21 -7
  373. package/dist/prompt-assembly/types.d.ts +3 -0
  374. package/dist/prompts/default.d.ts +4 -1
  375. package/dist/prompts/default.js +6 -0
  376. package/dist/stores/file/checkpoint-store.d.ts +11 -10
  377. package/dist/stores/file/checkpoint-store.js +36 -10
  378. package/dist/stores/file/file-history-store.d.ts +6 -0
  379. package/dist/stores/file/file-history-store.js +21 -4
  380. package/dist/stores/file/fs-atomic.d.ts +1 -1
  381. package/dist/stores/file/index.d.ts +14 -4
  382. package/dist/stores/file/index.js +21 -5
  383. package/dist/stores/file/process-anchor.d.ts +9 -1
  384. package/dist/stores/file/session-policy-store.js +2 -17
  385. package/dist/stores/file/session-store.d.ts +27 -0
  386. package/dist/stores/file/session-store.js +81 -9
  387. package/dist/stores/file/workflow-journal-store.d.ts +14 -4
  388. package/dist/stores/file/workflow-journal-store.js +32 -24
  389. package/dist/stores/file/workflow-run-store.d.ts +15 -4
  390. package/dist/stores/file/workflow-run-store.js +76 -0
  391. package/dist/tools/artifact/artifact-tool.d.ts +10 -3
  392. package/dist/tools/artifact/artifact-tool.js +16 -1
  393. package/dist/tools/fs/bash-program-position.d.ts +10 -4
  394. package/dist/tools/fs/bash-program-position.js +11 -8
  395. package/dist/tools/fs/bash-readonly-classifier.d.ts +3 -1
  396. package/dist/tools/fs/bash-readonly-classifier.js +9 -2
  397. package/dist/tools/fs/find-actions.d.ts +30 -16
  398. package/dist/tools/fs/find-actions.js +272 -19
  399. package/dist/tools/fs/fs-bash.js +8 -5
  400. package/dist/tools/fs/fs-shared.d.ts +0 -29
  401. package/dist/tools/fs/fs-shared.js +0 -5
  402. package/dist/tools/fs/fs-write.js +2 -1
  403. package/dist/tools/fs/read-deny.d.ts +6 -1
  404. package/dist/tools/fs/read-deny.js +6 -1
  405. package/dist/tools/fs/read-floor.d.ts +6 -0
  406. package/dist/tools/fs/read-floor.js +5 -1
  407. package/dist/tools/fs/removal-actions.d.ts +43 -0
  408. package/dist/tools/fs/removal-actions.js +25 -0
  409. package/dist/tools/fs/removal-targets.d.ts +2 -21
  410. package/dist/tools/fs/removal-targets.js +2 -3
  411. package/dist/tools/fs/safety.d.ts +37 -1
  412. package/dist/tools/fs/safety.js +52 -0
  413. package/dist/tools/fs/shell-climb.d.ts +46 -0
  414. package/dist/tools/fs/shell-climb.js +79 -0
  415. package/dist/tools/fs/shell-read-check.js +47 -19
  416. package/dist/tools/fs/shell-read-establish.js +36 -22
  417. package/dist/tools/fs/shell-read-judge.d.ts +10 -2
  418. package/dist/tools/fs/shell-read-judge.js +4 -4
  419. package/dist/tools/fs/shell-read-plan.d.ts +3 -0
  420. package/dist/tools/fs/shell-read-plan.js +1 -1
  421. package/dist/tools/fs/shell-read-workdir.js +3 -2
  422. package/dist/tools/fs/shell-read-write-targets.d.ts +4 -3
  423. package/dist/tools/fs/shell-read-write-targets.js +3 -0
  424. package/package.json +2 -2
  425. package/test/export-surface.snapshot.json +173 -15
  426. package/wire-changes/core-stores-sql@7.71.0.json +40 -0
  427. package/wire-changes/core-stores-sql@7.71.1.json +40 -0
  428. package/wire-changes/core@7.71.0.json +5827 -0
  429. package/wire-changes/core@7.71.1.json +118 -0
  430. package/wire-changes/mods-kernel@7.71.0.json +52 -0
  431. package/wire-changes/mods-kernel@7.71.1.json +40 -0
  432. package/wire-changes/primitives@7.71.0.json +473 -0
  433. package/wire-changes/primitives@7.71.1.json +40 -0
  434. package/wire-changes/wiki-gate@7.71.0.json +40 -0
  435. package/wire-changes/wiki-gate@7.71.1.json +40 -0
  436. package/dist/core/frontmatter-fence.d.ts +0 -10
  437. package/dist/core/frontmatter-fence.js +0 -6
  438. package/dist/core/permission-rule-syntax.d.ts +0 -46
  439. package/dist/core/permission-rule-syntax.js +0 -52
@@ -5,7 +5,7 @@ import type { ProviderCondition, ProviderConditionSource } from "../../brain/pro
5
5
  import type { RequestRoute, RouteCarrierBag, RouteCredentialSource } from "../../brain/request-route.js";
6
6
  export type { RouteCredentialSource } from "../../brain/request-route.js";
7
7
  import type { ModelOutputInvalidCause } from "./tool-turns.js";
8
- import type { PromptTraitName, RenderedLocale, TraitCondition } from "../../prompt-assembly/catalog/schema.js";
8
+ import type { PromptTraitName, RenderedLocale, ToolCardFactName, TraitCondition } from "../../prompt-assembly/catalog/schema.js";
9
9
  export type KnownApi = "openai-completions" | "mistral-conversations" | "openai-responses" | "azure-openai-responses" | "openai-chatgpt-responses" | "anthropic-messages" | "bedrock-converse-stream" | "google-generative-ai" | "google-vertex";
10
10
  export type Api = KnownApi | (string & {});
11
11
  export type KnownImagesApi = "openrouter-images";
@@ -883,14 +883,15 @@ export interface Tool<TParameters extends TSchema = TSchema> {
883
883
  }
884
884
  /**
885
885
  * One conditional variant of a tool's description — the tool card's variant table is these, first match wins, with
886
- * `description` as the unconditional last entry. Chosen by the run's prompt traits through the same trait reading the
887
- * prompt catalog's variants use; the variant chosen is reported in the tool's `cardId` (`<card>#<id>`).
886
+ * `description` as the unconditional last entry. Chosen by the run's prompt traits and its prompt facts through the same
887
+ * readings the prompt catalog's variants use; the variant chosen is reported in the tool's `cardId` (`<card>#<id>`).
888
888
  */
889
889
  export interface ToolDescriptionVariant {
890
890
  /** The variant's name in the tool's card id: non-empty, at most 64 characters of `[A-Za-z0-9._-]`, unique per tool. */
891
891
  readonly id: string;
892
- /** The trait condition (`allOf` / `noneOf`, trait names) under which this text replaces `description`. */
892
+ /** The trait condition under which this text replaces `description`, with `facts` (over `TOOL_CARD_FACT_NAMES`); `{}` only beside it. */
893
893
  readonly traits: TraitCondition;
894
+ readonly facts?: Readonly<Partial<Record<ToolCardFactName, boolean>>>;
894
895
  /** The description text (non-blank). */
895
896
  readonly text: string;
896
897
  }
@@ -1,14 +1,23 @@
1
1
  import { type Session, type SessionCreateOptions, type SessionForkOptions, type SessionHead, type SessionMetadata, type SessionPlacementRecord, type SessionRepo, type SessionRow, type SessionRowExpectation, type SessionRowRead, type SessionTreeEntry } from "../harness/types.js";
2
2
  import { type SessionRepoRowCells } from "./row-cells.js";
3
+ import { type HolderJudge, type StoreHolderFence } from "../../core/checkpoint-generation.js";
4
+ /** {@link InMemorySessionRepo}'s options. */
5
+ export interface InMemorySessionRepoOptions {
6
+ readonly rowCells?: SessionRepoRowCells;
7
+ /** The deployment's grant judge ({@link HolderJudge}): every storage this repo hands out judges the holder of each append and leaf
8
+ * move that carries one by it, first; with it the repo declares `fence = { holder: "writes" }`. */
9
+ readonly holderIsCurrent?: HolderJudge;
10
+ }
3
11
  export declare class InMemorySessionRepo implements SessionRepo<SessionMetadata, SessionCreateOptions> {
4
12
  private rows;
5
13
  /** Each row's last touch (epoch ms). */
6
14
  private touched;
7
15
  /** Who holds the rows' occupant cells ({@link SessionRepoRowCells}): `"engine"` (absent) — this repo; `"host"` — the host's store. */
8
16
  readonly rowCells: SessionRepoRowCells;
9
- constructor(options?: {
10
- readonly rowCells?: SessionRepoRowCells;
11
- });
17
+ /** The holder declaration: present (`{ holder: "writes" }`) only on a repo given a judge. */
18
+ readonly fence?: StoreHolderFence;
19
+ private readonly holderIsCurrent;
20
+ constructor(options?: InMemorySessionRepoOptions);
12
21
  create(options?: SessionCreateOptions): Promise<Session>;
13
22
  open(metadata: SessionMetadata): Promise<Session>;
14
23
  /** The row's head off the one row that IS it: every cell comes from that row, so a delete and re-create of the id while this reads
@@ -42,6 +51,9 @@ export declare class InMemorySessionRepo implements SessionRepo<SessionMetadata,
42
51
  preserveActorAssertions?: boolean;
43
52
  expect?: SessionRowExpectation;
44
53
  }): Promise<SessionHead>;
54
+ /** {@link SessionRepo.recordOwner}: the row judged and its owner recorded in one synchronous step, on the storage every handle of the row
55
+ * holds — the row object is not replaced, so a session handed out before the write keeps writing to the row and reads the recorded owner. */
56
+ recordOwner(sessionId: string, owner: string, expect: SessionRowExpectation): Promise<SessionHead | undefined>;
45
57
  /** Lay a row down under its id: one storage, one session over it, and the metadata as this repo holds it ({@link heldRowCells}),
46
58
  * frozen — every write that lays a row down comes through here, so no row holds a cell its mode does not. */
47
59
  private lay;
@@ -2,17 +2,22 @@ import { SessionError } from "../harness/types.js";
2
2
  import { validateEntriesForImport } from "./import-validate.js";
3
3
  import { InMemorySessionStorage } from "./memory-storage.js";
4
4
  import { resolveLeafId } from "./storage-base.js";
5
- import { assertForkTarget, createSessionId, createTimestamp, forkRowCells, forkTargetTaken, frozenRow, getEntriesToFork, headOfSession, importRowCells, incarnationCell, ownerCell, rowExpectationMissed, sessionHeadOf, toSession } from "./repo-utils.js";
5
+ import { assertForkTarget, createSessionId, createTimestamp, forkRowCells, forkTargetTaken, frozenRow, getEntriesToFork, headOfSession, importRowCells, incarnationCell, ownerCell, readRowExpectation, recordedOwnerCells, recordedOwnerName, rowExpectationMissed, sessionHeadOf, toSession } from "./repo-utils.js";
6
6
  import { heldRowCells, heldRowMatches, readSessionRepoRowCells } from "./row-cells.js";
7
7
  import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
8
- const IN_MEMORY_SESSION_REPO_OPTION_KEYS = optionKeys()({ rowCells: 0 });
8
+ import { readHolderJudge } from "../../core/checkpoint-generation.js";
9
+ const IN_MEMORY_SESSION_REPO_OPTION_KEYS = optionKeys()({ rowCells: 0, holderIsCurrent: 0 });
9
10
  export class InMemorySessionRepo {
10
11
  rows = new Map();
11
12
  touched = new Map();
12
13
  rowCells;
14
+ holderIsCurrent;
13
15
  constructor(options) {
14
16
  const opts = receiveOptions(options, "InMemorySessionRepo", IN_MEMORY_SESSION_REPO_OPTION_KEYS);
15
17
  this.rowCells = readSessionRepoRowCells("InMemorySessionRepo options", opts.rowCells);
18
+ this.holderIsCurrent = readHolderJudge("InMemorySessionRepo.holderIsCurrent", opts.holderIsCurrent);
19
+ if (this.holderIsCurrent !== undefined)
20
+ this.fence = Object.freeze({ holder: "writes" });
16
21
  }
17
22
  async create(options = {}) {
18
23
  if (options.id !== undefined) {
@@ -94,9 +99,22 @@ export class InMemorySessionRepo {
94
99
  const { metadata } = this.lay(importRowCells(sessionId, owner, prior?.metadata, createTimestamp()), validated);
95
100
  return sessionHeadOf(metadata, resolveLeafId(validated));
96
101
  }
102
+ async recordOwner(sessionId, owner, expect) {
103
+ const name = recordedOwnerName(owner);
104
+ const row = this.rows.get(sessionId);
105
+ if (row === undefined)
106
+ return void readRowExpectation(expect);
107
+ const claimed = recordedOwnerCells(sessionId, name, row.metadata, expect, () => heldRowMatches(this.rowCells, expect, row.metadata, () => row.storage.logMarkNow()));
108
+ if (claimed === undefined)
109
+ return sessionHeadOf(row.metadata, row.storage.leafNow());
110
+ const metadata = frozenRow(heldRowCells(this.rowCells, claimed));
111
+ row.storage.recordOwnerCell(metadata);
112
+ this.rows.set(sessionId, { ...row, metadata });
113
+ return sessionHeadOf(metadata, row.storage.leafNow());
114
+ }
97
115
  lay(given, entries) {
98
116
  const metadata = frozenRow(heldRowCells(this.rowCells, given));
99
- const storage = new InMemorySessionStorage({ metadata, entries });
117
+ const storage = new InMemorySessionStorage({ metadata, entries, ...(this.holderIsCurrent !== undefined ? { holderIsCurrent: this.holderIsCurrent } : {}) });
100
118
  const row = { session: toSession(storage), storage, metadata };
101
119
  this.rows.set(metadata.id, row);
102
120
  return row;
@@ -1,4 +1,5 @@
1
1
  import type { SessionMetadata, SessionTreeEntry, SessionWriteOptions } from "../harness/types.js";
2
+ import type { HolderJudge } from "../../core/checkpoint-generation.js";
2
3
  import { BaseSessionStorage } from "./storage-base.js";
3
4
  /** Volatile session storage used by tests and in-process harness callers. */
4
5
  export declare class InMemorySessionStorage<TMetadata extends SessionMetadata = SessionMetadata> extends BaseSessionStorage<TMetadata> {
@@ -7,7 +8,11 @@ export declare class InMemorySessionStorage<TMetadata extends SessionMetadata =
7
8
  metadata?: TMetadata;
8
9
  /** Branch floor for a bounded-window load (F3); the entries must start at this id. */
9
10
  floorEntryId?: string | null;
11
+ /** The deployment's grant judge: every append and leaf move carrying `opts.holder` is judged by it first ({@link HolderJudge}). */
12
+ holderIsCurrent?: HolderJudge;
10
13
  });
11
14
  setLeafId(leafId: string | null, opts?: SessionWriteOptions): Promise<void>;
12
15
  appendEntry(entry: SessionTreeEntry, opts?: SessionWriteOptions): Promise<void>;
16
+ /** The in-memory repo's owner write: the row's metadata with its owner recorded, adopted by this storage in the repo's judging step. */
17
+ recordOwnerCell(metadata: TMetadata): void;
13
18
  }
@@ -2,14 +2,19 @@ import { BaseSessionStorage } from "./storage-base.js";
2
2
  import { uuidv7 } from "./uuid.js";
3
3
  export class InMemorySessionStorage extends BaseSessionStorage {
4
4
  constructor(options) {
5
- super(options?.metadata ?? { id: uuidv7(), createdAt: new Date().toISOString() }, options?.entries ? [...options.entries] : [], undefined, options?.floorEntryId !== undefined ? { floorEntryId: options.floorEntryId } : undefined);
5
+ super(options?.metadata ?? { id: uuidv7(), createdAt: new Date().toISOString() }, options?.entries ? [...options.entries] : [], undefined, options?.floorEntryId !== undefined || options?.holderIsCurrent !== undefined
6
+ ? { ...(options.floorEntryId !== undefined ? { floorEntryId: options.floorEntryId } : {}), ...(options.holderIsCurrent !== undefined ? { holderIsCurrent: options.holderIsCurrent } : {}) }
7
+ : undefined);
6
8
  }
7
9
  async setLeafId(leafId, opts) {
8
- this.assertExpectedLeaf(opts);
10
+ this.assertExpectedLeaf(opts, "setLeafId");
9
11
  this.recordEntry(this.createLeafEntry(leafId));
10
12
  }
11
13
  async appendEntry(entry, opts) {
12
- this.assertExpectedLeaf(opts);
14
+ this.assertExpectedLeaf(opts, "appendEntry");
13
15
  this.recordEntry(entry);
14
16
  }
17
+ recordOwnerCell(metadata) {
18
+ this.adoptRecordedOwner(metadata);
19
+ }
15
20
  }
@@ -112,6 +112,15 @@ export declare function ownerCell(owner: unknown): Pick<SessionMetadata, "owner"
112
112
  * already the importer's takes the log — owners compared null-safe, `undefined` naming `null` — so another owner's row is refused
113
113
  * `conflict` and a placed row `placement_refused`, before anything is written. `owner` is judged either way. */
114
114
  export declare function importRowCells(sessionId: string, owner: unknown, existing: SessionMetadata | undefined, createdAt: string): SessionMetadata;
115
+ /** The owner a {@link import("../harness/types.js").SessionRepo.recordOwner} call records: a principal name, read by the one name reading;
116
+ * anything else (`null` included — a row that records none is the row this write is for) is refused `config.invalid_argument` before the
117
+ * row is read. */
118
+ export declare function recordedOwnerName(owner: unknown): string;
119
+ /** The one write law of `recordOwner`, judged on the row as the repo holds it in the write's own step: a row that records a name is left
120
+ * as it is (`undefined`: nothing to write — the caller answers its head as read); a row that records none and is the row `expect` names
121
+ * ({@link sessionRowMatches}, asked through `matches`) takes `name` as its owner and nothing else; any other row is refused `conflict`.
122
+ * `expect` is read for its shape first, whatever the row. */
123
+ export declare function recordedOwnerCells(sessionId: string, name: string, existing: SessionMetadata, expect: SessionRowExpectation, matches: () => boolean): SessionMetadata | undefined;
115
124
  /** The one decoding of a stored owner cell: a stored name ({@link recordedPrincipalNameOf}) is the owner; absence (`undefined`, `null`) is anonymous. A cell that is
116
125
  * there but is neither (a blank string included) cannot be read as anyone's, and reading it as anonymous would admit every
117
126
  * principal — the row is refused as `corrupt_session` instead (a read fault, never an answer). */
@@ -142,6 +142,20 @@ export function importRowCells(sessionId, owner, existing, createdAt) {
142
142
  throw new SessionError("conflict", `session ${sessionId} is not the importer's row — an import replaces only a log whose row the importer owns (or an anonymous row, by an anonymous import); nothing was written`);
143
143
  return existing;
144
144
  }
145
+ export function recordedOwnerName(owner) {
146
+ const name = principalNameOf(owner);
147
+ if (name === undefined)
148
+ throw receiptRefusal(`recordOwner: the owner to record must be a principal name (${PRINCIPAL_NAME_SPELLING}), got ${notAnOwnerShape(owner)} — refused before the row was read, nothing written`);
149
+ return name;
150
+ }
151
+ export function recordedOwnerCells(sessionId, name, existing, expect, matches) {
152
+ readRowExpectation(expect);
153
+ if ((existing.owner ?? null) !== null)
154
+ return undefined;
155
+ if (!matches())
156
+ throw rowExpectationMissed(sessionId, "owner record");
157
+ return { ...existing, owner: name };
158
+ }
145
159
  export function readOwnerCell(raw, sessionId) {
146
160
  if (raw === undefined || raw === null)
147
161
  return null;
@@ -1,5 +1,6 @@
1
1
  import { type LeafEntry, type SessionLogMark, type SessionMetadata, type SessionStorage, type SessionTreeEntry, type SessionWriteOptions } from "../harness/types.js";
2
2
  import { type ParentLinks, type ReplayLoss } from "./path-to-root.js";
3
+ import { type HolderJudge } from "../../core/checkpoint-generation.js";
3
4
  /** How a session log's entries link to their parents — one reading for every walk over a storage's entries: an empty parent id reads as "no
4
5
  * parent" here, as it always has (#2244 tracks reading it as a refusal). */
5
6
  export declare function entryParentLinks(byId: {
@@ -14,22 +15,26 @@ export declare function sessionLogMarkOf(entries: readonly SessionTreeEntry[]):
14
15
  * answers, and so what a repo answers as the head of a row whose log it has just written or read whole. */
15
16
  export declare function resolveLeafId(entries: readonly SessionTreeEntry[]): string | null;
16
17
  export declare abstract class BaseSessionStorage<TMetadata extends SessionMetadata = SessionMetadata> implements SessionStorage<TMetadata> {
17
- private readonly metadata;
18
+ private metadata;
18
19
  private readonly entries;
19
20
  private readonly byId;
20
21
  private readonly labelsById;
21
22
  private leafId;
22
23
  private readonly floorId;
23
24
  private readonly replayLoss;
25
+ /** The deployment's grant judge this storage's writes are judged by (`opts.holderIsCurrent`); absent ⇒ a write carrying a holder is refused. */
26
+ private readonly holderIsCurrent;
24
27
  /**
25
28
  * The storage of one loaded log. Its leaf (`leafId`, the leaf after the log's last entry unless the backend states its head) and its floor
26
29
  * (`opts.floorEntryId`) must name entries the log holds: a load that does not is a stored log that does not hold together, refused
27
30
  * `corrupt_session`. `opts.replayLoss` = what the replay that read the log dropped (absent = it dropped nothing): the refusals of this storage
28
- * state it, and a walk that breaks at a parent the log does not hold carries it ({@link LineageBreak}).
31
+ * state it, and a walk that breaks at a parent the log does not hold carries it ({@link LineageBreak}). `opts.holderIsCurrent` = the
32
+ * deployment's grant judge every write carrying a holder is judged by ({@link assertExpectedLeaf}).
29
33
  */
30
34
  protected constructor(metadata: TMetadata, entries: SessionTreeEntry[], leafId?: string | null, opts?: {
31
35
  floorEntryId?: string | null;
32
36
  replayLoss?: ReplayLoss;
37
+ holderIsCurrent?: HolderJudge;
33
38
  });
34
39
  /** ` (N of M records skipped as corrupt)` when the replay that read this log dropped records, else empty. */
35
40
  private lostText;
@@ -44,15 +49,23 @@ export declare abstract class BaseSessionStorage<TMetadata extends SessionMetada
44
49
  /** The log's mark ({@link sessionLogMarkOf}) as it stands at this instant, read synchronously: for a repo judging a row and writing it in
45
50
  * one step with no await between them (an await would let a write through this storage land between the judgement and the write). */
46
51
  logMarkNow(): SessionLogMark;
52
+ /** The active leaf at this instant, read synchronously (the head a repo answers from the same step as the write it judged). */
53
+ leafNow(): string | null;
54
+ /** The repo's owner write of the row this storage holds ({@link SessionRepo.recordOwner}): the metadata every holder of this storage reads
55
+ * from now on, swapped in one synchronous step — the log, the leaf and every handle on this storage stay. Only the repo that holds the row
56
+ * calls it, inside the step that judged the row. */
57
+ protected adoptRecordedOwner(metadata: TMetadata): void;
47
58
  protected createLeafEntry(leafId: string | null): LeafEntry;
48
59
  createEntryId(): Promise<string>;
49
60
  /**
50
- * Optimistic-lock check (F2). Throws `SessionError("conflict")` when `opts.expectedLeafId` is
51
- * provided and does not match the current in-memory leaf. Concrete `appendEntry`/`setLeafId`
52
- * implementations call this before persisting; durable backends should instead perform the same
53
- * check atomically against shared state (a conditional write) so concurrent instances can't fork.
61
+ * THE write's conditions, one synchronous judge point, in this order: the grant holder ({@link SessionWriteOptions.holder}, judged by
62
+ * this storage's `holderIsCurrent` — {@link holderJudgedCurrent}; not current ⇒ `holder.superseded`, whatever the leaf), then the
63
+ * optimistic lock (F2: `opts.expectedLeafId` provided and not the current in-memory leaf ⇒ `SessionError("conflict")`). Concrete
64
+ * `appendEntry`/`setLeafId` implementations call this before persisting, with no await between it and the write; durable backends
65
+ * should instead perform the same checks atomically against shared state (a conditional write in one transaction) so concurrent
66
+ * instances can't fork. `what` names the write in the refusal.
54
67
  */
55
- protected assertExpectedLeaf(opts?: SessionWriteOptions): void;
68
+ protected assertExpectedLeaf(opts?: SessionWriteOptions, what?: "appendEntry" | "setLeafId"): void;
56
69
  protected recordEntry(entry: SessionTreeEntry): void;
57
70
  getEntry(id: string): Promise<SessionTreeEntry | undefined>;
58
71
  findEntries<TType extends SessionTreeEntry["type"]>(type: TType): Promise<Array<Extract<SessionTreeEntry, {
@@ -1,6 +1,8 @@
1
1
  import { SessionError, } from "../harness/types.js";
2
2
  import { LineageBreak, pathToRoot, replayLossText } from "./path-to-root.js";
3
3
  import { uuidv7 } from "./uuid.js";
4
+ import { holderJudgedCurrent, readHolderJudge } from "../../core/checkpoint-generation.js";
5
+ import { holderSupersededError } from "../../core/grant-holder.js";
4
6
  export function entryParentLinks(byId) {
5
7
  return { read: (id) => byId.get(id), idOf: (entry) => entry.id, parentOf: (entry) => entry.parentId || null };
6
8
  }
@@ -53,6 +55,7 @@ export class BaseSessionStorage {
53
55
  leafId;
54
56
  floorId;
55
57
  replayLoss;
58
+ holderIsCurrent;
56
59
  constructor(metadata, entries, leafId = resolveLeafId(entries), opts) {
57
60
  this.metadata = metadata;
58
61
  this.entries = entries;
@@ -61,6 +64,7 @@ export class BaseSessionStorage {
61
64
  this.leafId = leafId;
62
65
  this.floorId = opts?.floorEntryId ?? null;
63
66
  this.replayLoss = opts?.replayLoss !== undefined && opts.replayLoss.dropped > 0 ? opts.replayLoss : undefined;
67
+ this.holderIsCurrent = readHolderJudge("the session storage's holderIsCurrent", opts?.holderIsCurrent);
64
68
  this.assertLeafHeld();
65
69
  if (this.floorId !== null && !this.byId.has(this.floorId)) {
66
70
  throw new SessionError("corrupt_session", `Floor entry ${this.floorId} not loaded — the bounded window names a floor the loaded log does not hold${this.lostText()}`, undefined, "floor_missing");
@@ -90,6 +94,12 @@ export class BaseSessionStorage {
90
94
  logMarkNow() {
91
95
  return sessionLogMarkOf(this.entries);
92
96
  }
97
+ leafNow() {
98
+ return this.leafId;
99
+ }
100
+ adoptRecordedOwner(metadata) {
101
+ this.metadata = metadata;
102
+ }
93
103
  createLeafEntry(leafId) {
94
104
  if (leafId !== null && !this.byId.has(leafId)) {
95
105
  throw new SessionError("not_found", `Entry ${leafId} not found`);
@@ -105,7 +115,9 @@ export class BaseSessionStorage {
105
115
  async createEntryId() {
106
116
  return generateEntryId(this.byId);
107
117
  }
108
- assertExpectedLeaf(opts) {
118
+ assertExpectedLeaf(opts, what = "appendEntry") {
119
+ if (!holderJudgedCurrent(opts?.holder, this.holderIsCurrent, "session"))
120
+ throw holderSupersededError(what);
109
121
  if (opts?.expectedLeafId !== undefined && opts.expectedLeafId !== this.leafId) {
110
122
  throw new SessionError("conflict", `Stale write: expected leaf ${opts.expectedLeafId ?? "(empty)"}, but current leaf is ${this.leafId ?? "(empty)"}`);
111
123
  }