@sema-agent/core 7.57.0 → 7.59.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 (399) hide show
  1. package/CHANGELOG.md +1161 -0
  2. package/README.md +6 -4
  3. package/dist/agents/cc-peer-directory.js +8 -8
  4. package/dist/agents/child-model-seat.d.ts +4 -2
  5. package/dist/agents/child-model-seat.js +5 -3
  6. package/dist/agents/peer-directory.d.ts +9 -0
  7. package/dist/agents/peer-directory.js +6 -2
  8. package/dist/agents/send-message-tool.js +21 -12
  9. package/dist/agents/subagent-steps.js +2 -4
  10. package/dist/agents/subagent.js +33 -34
  11. package/dist/brain/anthropic.js +161 -45
  12. package/dist/brain/errors.d.ts +9 -3
  13. package/dist/brain/errors.js +7 -1
  14. package/dist/brain/failover.js +2 -1
  15. package/dist/brain/open-responses.js +3 -3
  16. package/dist/brain/openai.js +103 -53
  17. package/dist/brain/provider-dialect.d.ts +11 -0
  18. package/dist/brain/provider-dialect.js +5 -2
  19. package/dist/brain/reasoning-request.js +5 -4
  20. package/dist/brain/reasoning.d.ts +19 -0
  21. package/dist/brain/reasoning.js +17 -2
  22. package/dist/brain/request-route.d.ts +4 -1
  23. package/dist/brain/request-route.js +4 -1
  24. package/dist/brain/route-adjudicator.d.ts +84 -18
  25. package/dist/brain/route-adjudicator.js +89 -22
  26. package/dist/brain/route-conformance.js +1 -1
  27. package/dist/brain/stream-engine.js +84 -49
  28. package/dist/brain/stream-shared.d.ts +30 -0
  29. package/dist/brain/stream-shared.js +34 -1
  30. package/dist/brain/timeout.d.ts +62 -5
  31. package/dist/brain/timeout.js +93 -6
  32. package/dist/core/a2a.d.ts +2 -1
  33. package/dist/core/a2a.js +23 -10
  34. package/dist/core/account-row.d.ts +61 -0
  35. package/dist/core/account-row.js +51 -0
  36. package/dist/core/advisor-verdict.d.ts +2 -1
  37. package/dist/core/advisor-verdict.js +1 -1
  38. package/dist/core/allow-entry.d.ts +20 -7
  39. package/dist/core/allow-entry.js +18 -9
  40. package/dist/core/approval-object.d.ts +29 -15
  41. package/dist/core/approval-object.js +47 -19
  42. package/dist/core/ask-origin.d.ts +21 -2
  43. package/dist/core/ask-origin.js +5 -1
  44. package/dist/core/auto-compaction.d.ts +4 -0
  45. package/dist/core/auto-compaction.js +2 -2
  46. package/dist/core/auto-mode-directive.d.ts +29 -5
  47. package/dist/core/auto-mode-directive.js +38 -8
  48. package/dist/core/background-agent-store.d.ts +16 -3
  49. package/dist/core/checkpoint-requirements.d.ts +19 -1
  50. package/dist/core/checkpoint-requirements.js +5 -1
  51. package/dist/core/checkpoint-store.d.ts +85 -23
  52. package/dist/core/checkpoint-store.js +31 -9
  53. package/dist/core/child-clamp-seats.d.ts +29 -0
  54. package/dist/core/child-clamp-seats.js +56 -1
  55. package/dist/core/compliance.d.ts +2 -2
  56. package/dist/core/compliance.js +1 -1
  57. package/dist/core/effective-path-target.d.ts +8 -2
  58. package/dist/core/effective-path-target.js +8 -3
  59. package/dist/core/engine-notice.d.ts +99 -9
  60. package/dist/core/engine-notice.js +19 -5
  61. package/dist/core/fs-write-gate-policy.d.ts +4 -2
  62. package/dist/core/fs-write-gate-policy.js +7 -3
  63. package/dist/core/gate-fold.js +7 -4
  64. package/dist/core/gate-lanes.js +19 -6
  65. package/dist/core/gate-outcome.d.ts +32 -3
  66. package/dist/core/gate-outcome.js +19 -1
  67. package/dist/core/git-worktree-env.d.ts +53 -11
  68. package/dist/core/git-worktree-env.js +96 -12
  69. package/dist/core/governance-codes.d.ts +9 -1
  70. package/dist/core/governance-codes.js +13 -0
  71. package/dist/core/hooks.d.ts +35 -4
  72. package/dist/core/hooks.js +17 -11
  73. package/dist/core/human-input-projection.d.ts +1 -0
  74. package/dist/core/human-input-projection.js +3 -0
  75. package/dist/core/image-admission.d.ts +6 -5
  76. package/dist/core/image-admission.js +18 -14
  77. package/dist/core/locked-config.d.ts +20 -3
  78. package/dist/core/locked-config.js +40 -3
  79. package/dist/core/mailbox-store.d.ts +45 -1
  80. package/dist/core/mailbox-store.js +53 -9
  81. package/dist/core/mcp-call-meta.d.ts +66 -0
  82. package/dist/core/mcp-call-meta.js +103 -0
  83. package/dist/core/mcp-connection-pool.d.ts +3 -1
  84. package/dist/core/mcp-connection-pool.js +3 -1
  85. package/dist/core/mcp-failure.d.ts +117 -15
  86. package/dist/core/mcp-failure.js +71 -3
  87. package/dist/core/mcp-probe.d.ts +4 -0
  88. package/dist/core/mcp-probe.js +1 -1
  89. package/dist/core/mcp-server-link.d.ts +27 -3
  90. package/dist/core/mcp-server-link.js +25 -1
  91. package/dist/core/mcp-server-spec.d.ts +46 -18
  92. package/dist/core/mcp-server-spec.js +1 -18
  93. package/dist/core/mcp.d.ts +16 -20
  94. package/dist/core/mcp.js +112 -55
  95. package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
  96. package/dist/core/memory-engine/consolidation-driver.js +3 -3
  97. package/dist/core/memory-engine/consolidation.d.ts +4 -0
  98. package/dist/core/memory-engine/consolidation.js +1 -0
  99. package/dist/core/memory-engine/delegation-settlement.js +5 -12
  100. package/dist/core/memory-engine/distiller.js +2 -2
  101. package/dist/core/memory-engine/dual-root.d.ts +50 -1
  102. package/dist/core/memory-engine/dual-root.js +44 -1
  103. package/dist/core/memory-engine/engine.d.ts +67 -14
  104. package/dist/core/memory-engine/engine.js +384 -212
  105. package/dist/core/memory-engine/export-bundle.d.ts +23 -0
  106. package/dist/core/memory-engine/export-bundle.js +23 -4
  107. package/dist/core/memory-engine/file-backend.d.ts +128 -55
  108. package/dist/core/memory-engine/file-backend.js +290 -117
  109. package/dist/core/memory-engine/index.d.ts +1 -1
  110. package/dist/core/memory-engine/layout.d.ts +59 -11
  111. package/dist/core/memory-engine/layout.js +190 -40
  112. package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
  113. package/dist/core/memory-engine/memory-backend-contract.js +39 -2
  114. package/dist/core/memory-engine/scope-contract.d.ts +45 -4
  115. package/dist/core/memory-engine/scope-contract.js +80 -11
  116. package/dist/core/memory-engine/sync-client.d.ts +9 -1
  117. package/dist/core/memory-engine/sync-client.js +31 -8
  118. package/dist/core/memory-engine/sync.d.ts +5 -0
  119. package/dist/core/memory-engine/types.d.ts +6 -0
  120. package/dist/core/mode-policy.d.ts +8 -5
  121. package/dist/core/mode-policy.js +5 -4
  122. package/dist/core/mods/classic-events.d.ts +5 -1
  123. package/dist/core/mods/host.js +1 -1
  124. package/dist/core/mods/kernel/dispatch.d.ts +3 -0
  125. package/dist/core/mods/kernel/dispatch.js +12 -9
  126. package/dist/core/mods/kernel/events.d.ts +6 -1
  127. package/dist/core/mods/kernel/events.js +2 -2
  128. package/dist/core/mods/kernel/registration.d.ts +9 -1
  129. package/dist/core/mods/kernel/registration.js +3 -0
  130. package/dist/core/mods/kernel/site-rules.d.ts +3 -0
  131. package/dist/core/mods/kernel/site-rules.js +10 -0
  132. package/dist/core/mods/package.d.ts +23 -0
  133. package/dist/core/mods/package.js +118 -0
  134. package/dist/core/mods/stations.d.ts +33 -12
  135. package/dist/core/mods/stations.js +45 -11
  136. package/dist/core/mods/tool-call.d.ts +5 -1
  137. package/dist/core/mods/tool-call.js +13 -4
  138. package/dist/core/parent-spec-seat.d.ts +8 -3
  139. package/dist/core/parent-spec-seat.js +2 -0
  140. package/dist/core/park-selfcheck.js +6 -0
  141. package/dist/core/path-guard-rows.d.ts +20 -0
  142. package/dist/core/path-guard-rows.js +11 -0
  143. package/dist/core/peer-seat.d.ts +248 -0
  144. package/dist/core/peer-seat.js +439 -0
  145. package/dist/core/permission-rule-consent.js +10 -4
  146. package/dist/core/permission-rule-model.d.ts +16 -0
  147. package/dist/core/permission-rule-model.js +1 -1
  148. package/dist/core/present-plan-tool.d.ts +20 -3
  149. package/dist/core/present-plan-tool.js +48 -4
  150. package/dist/core/protocol-http-auth.d.ts +40 -29
  151. package/dist/core/protocol-http-auth.js +30 -32
  152. package/dist/core/redaction-marks.d.ts +16 -0
  153. package/dist/core/redaction-marks.js +16 -0
  154. package/dist/core/redaction-passes.js +8 -9
  155. package/dist/core/resume-startup-cause.js +1 -0
  156. package/dist/core/retention.d.ts +41 -15
  157. package/dist/core/retention.js +59 -12
  158. package/dist/core/rewrite-rejudge.d.ts +38 -0
  159. package/dist/core/rewrite-rejudge.js +42 -2
  160. package/dist/core/roles.d.ts +34 -2
  161. package/dist/core/roles.js +43 -4
  162. package/dist/core/run-origin.d.ts +40 -0
  163. package/dist/core/run-origin.js +37 -0
  164. package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
  165. package/dist/core/runner/advertised-writable-dirs.js +126 -0
  166. package/dist/core/runner/announce-once-ledger.d.ts +5 -4
  167. package/dist/core/runner/announce-once-ledger.js +4 -2
  168. package/dist/core/runner/call-hook-stations.js +2 -2
  169. package/dist/core/runner/compaction-restate.d.ts +15 -6
  170. package/dist/core/runner/compaction-restate.js +28 -2
  171. package/dist/core/runner/contracts.d.ts +33 -21
  172. package/dist/core/runner/credential-origin-seat.js +4 -3
  173. package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
  174. package/dist/core/runner/cwd-alignment-probe.js +21 -0
  175. package/dist/core/runner/decide-continuation.d.ts +2 -2
  176. package/dist/core/runner/gate-exit.d.ts +30 -8
  177. package/dist/core/runner/gate-exit.js +15 -8
  178. package/dist/core/runner/image-removed-seat.d.ts +12 -0
  179. package/dist/core/runner/image-removed-seat.js +19 -0
  180. package/dist/core/runner/inline-image.js +1 -1
  181. package/dist/core/runner/memory-consolidation-driver.js +3 -3
  182. package/dist/core/runner/park-commit.d.ts +1 -1
  183. package/dist/core/runner/park-commit.js +3 -0
  184. package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
  185. package/dist/core/runner/prepare-ask-lane.js +2 -1
  186. package/dist/core/runner/prepare-boundary-parks.js +2 -2
  187. package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -5
  188. package/dist/core/runner/prepare-caps-and-workflow.js +3 -1
  189. package/dist/core/runner/prepare-config-doors.d.ts +8 -5
  190. package/dist/core/runner/prepare-config-doors.js +14 -10
  191. package/dist/core/runner/prepare-context-lane.js +2 -0
  192. package/dist/core/runner/prepare-delegation-surface.d.ts +8 -0
  193. package/dist/core/runner/prepare-delegation-surface.js +16 -18
  194. package/dist/core/runner/prepare-gate-stations.js +1 -1
  195. package/dist/core/runner/prepare-hands-readface.d.ts +11 -3
  196. package/dist/core/runner/prepare-hands-readface.js +9 -1
  197. package/dist/core/runner/prepare-inherited-gate.d.ts +1 -3
  198. package/dist/core/runner/prepare-inherited-gate.js +14 -27
  199. package/dist/core/runner/prepare-memory.d.ts +3 -0
  200. package/dist/core/runner/prepare-memory.js +26 -37
  201. package/dist/core/runner/prepare-park-ask.d.ts +1 -1
  202. package/dist/core/runner/prepare-park-ask.js +2 -1
  203. package/dist/core/runner/prepare-policy-chain.d.ts +7 -7
  204. package/dist/core/runner/prepare-policy-chain.js +18 -15
  205. package/dist/core/runner/prepare-project-context.d.ts +2 -2
  206. package/dist/core/runner/prepare-project-context.js +2 -2
  207. package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -1
  208. package/dist/core/runner/prepare-prompt-inputs.js +8 -19
  209. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
  210. package/dist/core/runner/prepare-protocol-tools.js +11 -3
  211. package/dist/core/runner/prepare-run-refs.d.ts +2 -3
  212. package/dist/core/runner/prepare-run-refs.js +4 -1
  213. package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
  214. package/dist/core/runner/prepare-suspend-saga.js +2 -1
  215. package/dist/core/runner/prepare-task.js +28 -13
  216. package/dist/core/runner/prepare-wiring-manifest.d.ts +2 -1
  217. package/dist/core/runner/prepare-wiring-manifest.js +4 -3
  218. package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
  219. package/dist/core/runner/prepare-workspace-restore.js +4 -4
  220. package/dist/core/runner/reply-pricing.d.ts +30 -0
  221. package/dist/core/runner/reply-pricing.js +19 -0
  222. package/dist/core/runner/resume-admission.js +5 -3
  223. package/dist/core/runner/resume-apply.js +6 -1
  224. package/dist/core/runner/resume-checkpoint-screen.js +2 -0
  225. package/dist/core/runner/resume-policy-outcome.js +5 -5
  226. package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
  227. package/dist/core/runner/role-seat-defaulted.js +40 -0
  228. package/dist/core/runner/run-brain-sinks.js +2 -0
  229. package/dist/core/runner/run-harness-handlers.d.ts +3 -4
  230. package/dist/core/runner/run-harness-handlers.js +1 -8
  231. package/dist/core/runner/run-identity-wiring.d.ts +2 -5
  232. package/dist/core/runner/run-identity-wiring.js +6 -4
  233. package/dist/core/runner/run-leg.d.ts +2 -0
  234. package/dist/core/runner/run-leg.js +42 -29
  235. package/dist/core/runner/run-notification-lane.js +3 -0
  236. package/dist/core/runner/run-stop-and-final-verify.js +2 -2
  237. package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
  238. package/dist/core/runner/run-terminal-adoption.js +9 -3
  239. package/dist/core/runner/run-turn-boundary.js +77 -70
  240. package/dist/core/runner/runtask.d.ts +1 -1
  241. package/dist/core/runner/runtask.js +2 -2
  242. package/dist/core/runner/side-call-account.d.ts +1 -1
  243. package/dist/core/runner/side-call-account.js +3 -18
  244. package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
  245. package/dist/core/runner/sub-agent-deny-lists.js +10 -0
  246. package/dist/core/runner/terminal-account.js +3 -3
  247. package/dist/core/runner/tool-end-body.js +2 -1
  248. package/dist/core/runner/tool-occurrence.d.ts +5 -2
  249. package/dist/core/runner/tool-occurrence.js +4 -3
  250. package/dist/core/runner/turn-attachments.d.ts +26 -22
  251. package/dist/core/runner/turn-attachments.js +24 -26
  252. package/dist/core/runner/write-protection-station.d.ts +8 -2
  253. package/dist/core/runner/write-protection-station.js +2 -0
  254. package/dist/core/runner-deps.d.ts +3 -3
  255. package/dist/core/secret-env.d.ts +32 -2
  256. package/dist/core/secret-env.js +65 -3
  257. package/dist/core/sensitive-path-policy.js +9 -10
  258. package/dist/core/session-log-transfer.d.ts +24 -0
  259. package/dist/core/session-log-transfer.js +166 -0
  260. package/dist/core/session-policy-store.d.ts +3 -1
  261. package/dist/core/session-policy-store.js +13 -9
  262. package/dist/core/session-store.d.ts +86 -24
  263. package/dist/core/session-store.js +162 -24
  264. package/dist/core/session.d.ts +92 -1
  265. package/dist/core/shell-read-silence.js +1 -0
  266. package/dist/core/side-query.d.ts +11 -1
  267. package/dist/core/side-query.js +9 -0
  268. package/dist/core/skill-grant-binding.d.ts +31 -2
  269. package/dist/core/skill-grant-binding.js +31 -1
  270. package/dist/core/skill-grant.d.ts +8 -5
  271. package/dist/core/skill-grant.js +6 -6
  272. package/dist/core/steer-replay.d.ts +4 -2
  273. package/dist/core/steer-replay.js +2 -1
  274. package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
  275. package/dist/core/store-contracts/checkpoint-store-contract.js +20 -2
  276. package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
  277. package/dist/core/store-contracts/session-repo-contract.js +112 -5
  278. package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
  279. package/dist/core/store-contracts/session-store-contract.js +236 -2
  280. package/dist/core/synthetic-read-verdict.js +2 -1
  281. package/dist/core/task-event.d.ts +92 -8
  282. package/dist/core/task-notification.js +16 -10
  283. package/dist/core/task-registry-agent.js +1 -0
  284. package/dist/core/task-registry-shared.d.ts +7 -1
  285. package/dist/core/task-spec.d.ts +49 -1
  286. package/dist/core/task-stream.d.ts +2 -1
  287. package/dist/core/terminal-cause.d.ts +11 -1
  288. package/dist/core/tool-catalog-entries.js +1 -0
  289. package/dist/core/tool-check-reading.d.ts +1 -0
  290. package/dist/core/tool-check-reading.js +3 -3
  291. package/dist/core/tool-policy.d.ts +16 -0
  292. package/dist/core/tool-result-store.d.ts +17 -10
  293. package/dist/core/tool-result-store.js +3 -1
  294. package/dist/core/tool-roster.d.ts +112 -5
  295. package/dist/core/tool-roster.js +42 -1
  296. package/dist/core/tool-spec.d.ts +3 -1
  297. package/dist/core/types.d.ts +3 -3
  298. package/dist/core/types.js +1 -1
  299. package/dist/core/untrusted-egress.d.ts +0 -2
  300. package/dist/core/untrusted-egress.js +10 -14
  301. package/dist/core/user-attachment.js +1 -1
  302. package/dist/core/wiring-manifest.d.ts +18 -6
  303. package/dist/core/wiring-manifest.js +4 -3
  304. package/dist/core/workspace-snapshot.d.ts +44 -0
  305. package/dist/core/workspace-snapshot.js +34 -0
  306. package/dist/core/write-protect.d.ts +43 -3
  307. package/dist/core/write-protect.js +43 -16
  308. package/dist/engine/compaction/compaction.js +29 -3
  309. package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
  310. package/dist/engine/execution-env/node-execution-env.js +24 -23
  311. package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
  312. package/dist/engine/harness/agent-harness.d.ts +30 -2
  313. package/dist/engine/harness/agent-harness.js +43 -12
  314. package/dist/engine/harness/messages.d.ts +3 -1
  315. package/dist/engine/harness/messages.js +3 -2
  316. package/dist/engine/harness/types.d.ts +56 -7
  317. package/dist/engine/harness/types.js +5 -1
  318. package/dist/engine/llm/rejected-images.d.ts +46 -0
  319. package/dist/engine/llm/rejected-images.js +54 -0
  320. package/dist/engine/llm/tool-turns.d.ts +2 -1
  321. package/dist/engine/llm/types.d.ts +30 -10
  322. package/dist/engine/llm/types.js +1 -1
  323. package/dist/engine/loop/agent-loop.d.ts +8 -0
  324. package/dist/engine/loop/agent-loop.js +52 -15
  325. package/dist/engine/loop/types.d.ts +3 -1
  326. package/dist/engine/session/import-validate.js +3 -0
  327. package/dist/engine/session/memory-repo.d.ts +17 -9
  328. package/dist/engine/session/memory-repo.js +44 -34
  329. package/dist/engine/session/path-to-root.d.ts +38 -0
  330. package/dist/engine/session/path-to-root.js +39 -0
  331. package/dist/engine/session/repo-utils.d.ts +22 -4
  332. package/dist/engine/session/repo-utils.js +49 -1
  333. package/dist/engine/session/storage-base.d.ts +10 -1
  334. package/dist/engine/session/storage-base.js +11 -22
  335. package/dist/index.d.ts +29 -16
  336. package/dist/index.js +21 -11
  337. package/dist/internal/harness-types.d.ts +2 -2
  338. package/dist/internal/harness.d.ts +3 -2
  339. package/dist/internal/harness.js +2 -2
  340. package/dist/internal/llm.d.ts +1 -0
  341. package/dist/orchestration/workflow-observe.d.ts +17 -1
  342. package/dist/orchestration/workflow-observe.js +20 -0
  343. package/dist/orchestration/workflow-types.d.ts +32 -7
  344. package/dist/orchestration/workflow.js +739 -489
  345. package/dist/shell/counting-pass.d.ts +50 -0
  346. package/dist/shell/counting-pass.js +502 -0
  347. package/dist/shell/lex.d.ts +4 -2
  348. package/dist/shell/lex.js +93 -34
  349. package/dist/shell/shell-words.d.ts +1 -1
  350. package/dist/shell/shell-words.js +7 -6
  351. package/dist/stores/file/index.d.ts +4 -1
  352. package/dist/stores/file/index.js +4 -1
  353. package/dist/stores/file/mailbox-store.js +6 -10
  354. package/dist/stores/file/session-store.d.ts +15 -8
  355. package/dist/stores/file/session-store.js +28 -13
  356. package/dist/tools/fs/fs-bash.d.ts +6 -0
  357. package/dist/tools/fs/fs-bash.js +6 -3
  358. package/dist/tools/fs/fs-write.d.ts +6 -3
  359. package/dist/tools/fs/fs-write.js +8 -7
  360. package/dist/tools/fs/index.d.ts +3 -0
  361. package/dist/tools/fs/index.js +7 -3
  362. package/dist/tools/fs/program-read-model.d.ts +13 -0
  363. package/dist/tools/fs/program-read-model.js +15 -0
  364. package/dist/tools/fs/program-read-model.rows.js +1 -1
  365. package/dist/tools/fs/read-deny.d.ts +13 -10
  366. package/dist/tools/fs/read-deny.js +25 -5
  367. package/dist/tools/fs/read-floor.d.ts +19 -0
  368. package/dist/tools/fs/read-floor.js +23 -0
  369. package/dist/tools/fs/safety.js +40 -8
  370. package/dist/tools/fs/search.js +6 -24
  371. package/dist/tools/fs/shell-read-check.d.ts +9 -2
  372. package/dist/tools/fs/shell-read-check.js +61 -16
  373. package/dist/tools/fs/shell-read-establish.js +2 -1
  374. package/dist/tools/fs/shell-read-identity.js +1 -1
  375. package/dist/tools/fs/shell-read-judge.d.ts +26 -9
  376. package/dist/tools/fs/shell-read-judge.js +10 -6
  377. package/dist/tools/fs/shell-read-plan.d.ts +6 -1
  378. package/dist/tools/fs/shell-read-plan.js +22 -15
  379. package/dist/tools/fs/shell-read-start.js +1 -0
  380. package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
  381. package/dist/tools/fs/shell-reentry-text.js +25 -3
  382. package/dist/tools/monitor.d.ts +4 -0
  383. package/dist/tools/monitor.js +2 -0
  384. package/dist/tools/worktree.d.ts +42 -15
  385. package/dist/tools/worktree.js +60 -32
  386. package/package.json +5 -2
  387. package/test/export-surface.snapshot.json +149 -1
  388. package/wire-changes/core-stores-sql@7.58.0.json +29 -0
  389. package/wire-changes/core-stores-sql@7.59.0.json +29 -0
  390. package/wire-changes/core@7.58.0.json +2188 -0
  391. package/wire-changes/core@7.59.0.json +2459 -0
  392. package/wire-changes/mods-kernel@7.58.0.json +81 -0
  393. package/wire-changes/mods-kernel@7.59.0.json +29 -0
  394. package/wire-changes/primitives@7.58.0.json +29 -0
  395. package/wire-changes/primitives@7.59.0.json +29 -0
  396. package/dist/primitives/credential-ref.d.ts +0 -89
  397. package/dist/primitives/credential-ref.js +0 -125
  398. package/dist/primitives/index.d.ts +0 -2
  399. package/dist/primitives/index.js +0 -1
@@ -1,6 +1,10 @@
1
- import { InMemorySessionRepo, ParentChainGuard, SessionError, findUnansweredToolBatch, compareOccupants, ownerCell, uuidv7, } from "../internal/harness.js";
1
+ import { InMemorySessionRepo, ParentChainGuard, SessionError, findUnansweredToolBatch, compareOccupants, ownerCell, sessionLogMarkOf, uuidv7, } from "../internal/harness.js";
2
2
  import { isSessionConflict, readSessionListQuery } from "./session.js";
3
+ import { readRetentionDeclaration } from "./retention.js";
3
4
  import { readMember } from "./thrown-value.js";
5
+ import { principalNameFault, principalNameOf } from "./principal-name.js";
6
+ import { receiptRefusal, receiveOwnProperties } from "./own-property-receipt.js";
7
+ import { repoLogTransfer } from "./session-log-transfer.js";
4
8
  const DAY_MS = 24 * 60 * 60 * 1000;
5
9
  import { SESSION_DEFAULT_TTL_DAYS } from "../config/defaults.js";
6
10
  export { SESSION_DEFAULT_TTL_DAYS };
@@ -19,22 +23,28 @@ export function admitSessionPlacement(sessionId, persisted, request, capability)
19
23
  }
20
24
  }
21
25
  export class TtlSessionStore {
22
- retention = "none";
26
+ retention;
23
27
  durability;
24
28
  placements;
25
29
  listPlaced;
26
30
  headOf;
27
31
  repoHead;
32
+ logTransfer;
33
+ delete;
34
+ judgesRows = false;
35
+ beforeRowDelete;
28
36
  repo;
29
37
  entries = new Map();
30
38
  pending = new Map();
31
39
  pendingPlacedDeletes = new Set();
32
40
  releasing = new Map();
41
+ resolutions = new Map();
33
42
  pinned = new Set();
34
43
  defaultTtlMs;
35
44
  evictPolicy;
36
45
  sweepTimer;
37
46
  constructor(opts = {}) {
47
+ this.retention = readRetentionDeclaration("TtlSessionStoreOptions.retention", opts.retention);
38
48
  this.repo = opts.repo ?? new InMemorySessionRepo();
39
49
  const durability = opts.durability ?? (opts.repo === undefined ? "process-local" : undefined);
40
50
  if (durability !== undefined)
@@ -49,9 +59,28 @@ export class TtlSessionStore {
49
59
  }
50
60
  const repoHeadOf = this.repo.headOf;
51
61
  if (typeof repoHeadOf === "function") {
52
- this.repoHead = (sessionId) => repoHeadOf.call(this.repo, sessionId);
53
- this.headOf = this.repoHead;
62
+ const repoHead = (sessionId) => repoHeadOf.call(this.repo, sessionId);
63
+ this.repoHead = repoHead;
64
+ this.headOf = repoHead;
65
+ const { readRow, importEntries } = this.repo;
66
+ if (typeof readRow === "function") {
67
+ this.judgesRows = true;
68
+ this.delete = (sessionId, guard) => this.deleteOwned(sessionId, guard);
69
+ }
70
+ if (typeof readRow === "function" && typeof importEntries === "function") {
71
+ this.logTransfer = repoLogTransfer({
72
+ readRow: (id) => readRow.call(this.repo, id),
73
+ importEntries: (id, owner, entries, options) => importEntries.call(this.repo, id, owner, entries, options),
74
+ holding: (id, work) => this.holdingId(id, () => {
75
+ this.entries.delete(id);
76
+ return work();
77
+ }),
78
+ });
79
+ }
54
80
  }
81
+ const beforeRowDelete = readStoreHooks(opts.hooks);
82
+ if (beforeRowDelete !== undefined)
83
+ this.beforeRowDelete = (sessionId) => Reflect.apply(beforeRowDelete, opts.hooks, [sessionId]);
55
84
  if (opts.sweepIntervalMs !== undefined && opts.sweepIntervalMs > 0) {
56
85
  this.sweepTimer = setInterval(() => this.sweep(), opts.sweepIntervalMs);
57
86
  this.sweepTimer.unref?.();
@@ -60,12 +89,10 @@ export class TtlSessionStore {
60
89
  async acquire(sessionId, opts) {
61
90
  this.sweep();
62
91
  if (sessionId) {
63
- const inflightRelease = this.releasing.get(sessionId);
64
- if (inflightRelease !== undefined)
65
- await inflightRelease;
92
+ await this.settledHolds(sessionId);
66
93
  const existing = this.entries.get(sessionId);
67
94
  if (existing) {
68
- if (await this.cachedViewStands(sessionId, existing)) {
95
+ if ((await this.standingRow(sessionId, existing)) !== undefined) {
69
96
  this.assertPlacementAdmission(sessionId, existing.placement, opts);
70
97
  existing.lastActiveAt = Date.now();
71
98
  return { session: existing.session, sessionId };
@@ -105,11 +132,11 @@ export class TtlSessionStore {
105
132
  return false;
106
133
  return this.repoHead === undefined;
107
134
  }
108
- async cachedViewStands(sessionId, cached) {
135
+ async standingRow(sessionId, cached) {
109
136
  if (this.repoHead === undefined)
110
- return true;
111
- const [shown, row] = await Promise.all([cached.session.getMetadata(), this.repoHead(sessionId)]);
112
- return this.viewStandsFor(shown, row);
137
+ return null;
138
+ const [shown, leaf, row] = await Promise.all([cached.session.getMetadata(), cached.session.getStorage().getLeafId(), this.repoHead(sessionId)]);
139
+ return this.viewStandsFor(shown, row) && row !== undefined && row.leafId === leaf ? row : undefined;
113
140
  }
114
141
  assertPlacementAdmission(sessionId, placement, opts) {
115
142
  const store = this;
@@ -120,6 +147,28 @@ export class TtlSessionStore {
120
147
  });
121
148
  }
122
149
  async openOrCreate(id, requireExisting = false, placement) {
150
+ for (;;) {
151
+ const watch = { overtaken: this.releasing.has(id) };
152
+ const watching = this.resolutions.get(id) ?? new Set();
153
+ watching.add(watch);
154
+ this.resolutions.set(id, watching);
155
+ let session;
156
+ try {
157
+ session = await this.resolveRow(id, requireExisting, placement);
158
+ }
159
+ finally {
160
+ watching.delete(watch);
161
+ if (watching.size === 0 && this.resolutions.get(id) === watching)
162
+ this.resolutions.delete(id);
163
+ }
164
+ if (!watch.overtaken)
165
+ return session;
166
+ if (this.entries.get(id)?.session === session)
167
+ this.entries.delete(id);
168
+ await this.settledHolds(id);
169
+ }
170
+ }
171
+ async resolveRow(id, requireExisting, placement) {
123
172
  try {
124
173
  const session = await this.repo.open({ id, createdAt: "" });
125
174
  const meta = await session.getMetadata();
@@ -234,7 +283,14 @@ export class TtlSessionStore {
234
283
  return;
235
284
  return this.holdingId(sessionId, () => this.releaseRow(sessionId, cached));
236
285
  }
286
+ async settledHolds(sessionId) {
287
+ const held = this.releasing.get(sessionId);
288
+ if (held !== undefined)
289
+ await held;
290
+ }
237
291
  async holdingId(sessionId, work) {
292
+ for (const watch of this.resolutions.get(sessionId) ?? [])
293
+ watch.overtaken = true;
238
294
  const prior = this.releasing.get(sessionId);
239
295
  let settle;
240
296
  const gate = new Promise((r) => (settle = r));
@@ -242,7 +298,7 @@ export class TtlSessionStore {
242
298
  try {
243
299
  if (prior !== undefined)
244
300
  await prior;
245
- await work();
301
+ return await work();
246
302
  }
247
303
  finally {
248
304
  if (this.releasing.get(sessionId) === gate)
@@ -253,17 +309,75 @@ export class TtlSessionStore {
253
309
  async releaseRow(sessionId, cached) {
254
310
  if (cached?.placement !== undefined)
255
311
  this.pendingPlacedDeletes.add(sessionId);
256
- const view = cached !== undefined && (await this.cachedViewStands(sessionId, cached)) ? cached : undefined;
312
+ const standing = cached !== undefined ? await this.standingRow(sessionId, cached) : undefined;
313
+ const view = standing !== undefined ? cached : undefined;
314
+ const judged = view === undefined && this.repoHead !== undefined && this.rowReadMatters(sessionId) ? await this.repoHead(sessionId) : undefined;
257
315
  const placed = view !== undefined ? view.placement !== undefined : await this.rowIsPlaced(sessionId);
258
316
  if (view === undefined && !placed)
259
317
  return;
318
+ if (!placed) {
319
+ await this.deleteRow(await view.session.getMetadata(), this.idleViewExpectation(standing, view));
320
+ return;
321
+ }
260
322
  const meta = view !== undefined ? await view.session.getMetadata() : { id: sessionId, createdAt: "" };
261
- if (!placed)
262
- return this.repo.delete(meta);
323
+ const occupant = view !== undefined ? standing : (judged ?? null);
263
324
  this.pendingPlacedDeletes.add(sessionId);
264
- await this.repo.delete(meta);
325
+ await this.deleteRow(meta, this.judgesRows ? async () => ({ row: occupant }) : undefined);
265
326
  this.pendingPlacedDeletes.delete(sessionId);
266
327
  }
328
+ idleViewExpectation(standing, view) {
329
+ if (!this.judgesRows || standing === null)
330
+ return undefined;
331
+ return async () => ({ row: standing, log: sessionLogMarkOf(await view.session.getStorage().getEntries()) });
332
+ }
333
+ async deleteRow(meta, expect) {
334
+ if (this.beforeRowDelete !== undefined)
335
+ await this.beforeRowDelete(meta.id);
336
+ if (expect === undefined) {
337
+ await this.repo.delete(meta);
338
+ return true;
339
+ }
340
+ try {
341
+ await this.repo.delete(meta, await expect());
342
+ }
343
+ catch (err) {
344
+ if (isSessionConflict(err))
345
+ return false;
346
+ throw err;
347
+ }
348
+ return true;
349
+ }
350
+ async deleteOwned(sessionId, guard) {
351
+ const want = readDeleteGuard(guard);
352
+ return this.holdingId(sessionId, async () => {
353
+ this.entries.delete(sessionId);
354
+ const head = await this.repoHead(sessionId);
355
+ if (head === undefined || head.owner !== want)
356
+ return false;
357
+ if ((await this.readPlacement(sessionId)) !== undefined)
358
+ return false;
359
+ if (!(await this.deleteRow({ id: sessionId, createdAt: "" }, async () => ({ row: head }))))
360
+ return false;
361
+ this.pinned.delete(sessionId);
362
+ return true;
363
+ });
364
+ }
365
+ async rowMetadata(sessionId) {
366
+ try {
367
+ return await (await this.repo.open({ id: sessionId, createdAt: "" })).getMetadata();
368
+ }
369
+ catch (err) {
370
+ if (isNotFound(err))
371
+ return undefined;
372
+ throw err;
373
+ }
374
+ }
375
+ async readPlacement(sessionId) {
376
+ const probe = this.placementProbe();
377
+ if (probe !== undefined)
378
+ return probe(sessionId);
379
+ return (await this.rowMetadata(sessionId))?.placement;
380
+ }
267
381
  placementProbe() {
268
382
  const probe = this.repo.placementOf;
269
383
  return typeof probe === "function" ? probe.bind(this.repo) : undefined;
@@ -274,10 +388,9 @@ export class TtlSessionStore {
274
388
  async rowIsPlaced(sessionId) {
275
389
  if (!this.rowReadMatters(sessionId))
276
390
  return false;
277
- const probe = this.placementProbe();
278
391
  let placement;
279
392
  try {
280
- placement = probe !== undefined ? await probe(sessionId) : (await (await this.repo.open({ id: sessionId, createdAt: "" })).getMetadata()).placement;
393
+ placement = await this.readPlacement(sessionId);
281
394
  }
282
395
  catch (err) {
283
396
  if (!isNotFound(err))
@@ -296,9 +409,7 @@ export class TtlSessionStore {
296
409
  this.pinned.delete(sessionId);
297
410
  }
298
411
  async register(sessionId, owner) {
299
- const inflightRelease = this.releasing.get(sessionId);
300
- if (inflightRelease !== undefined)
301
- await inflightRelease;
412
+ await this.settledHolds(sessionId);
302
413
  if (await this.hasRow(sessionId))
303
414
  return;
304
415
  if (owner === undefined)
@@ -335,8 +446,9 @@ export class TtlSessionStore {
335
446
  this.entries.delete(id);
336
447
  if (this.evictPolicy === "delete" && e.placement === undefined) {
337
448
  void this.holdingId(id, async () => {
338
- if (await this.cachedViewStands(id, e))
339
- await this.repo.delete({ id, createdAt: "" });
449
+ const standing = await this.standingRow(id, e);
450
+ if (standing !== undefined)
451
+ await this.deleteRow({ id, createdAt: "" }, this.idleViewExpectation(standing, e));
340
452
  }).catch(() => { });
341
453
  }
342
454
  }
@@ -379,6 +491,32 @@ function newestFirst(a, b) {
379
491
  return b.lastActiveAt - a.lastActiveAt;
380
492
  return a.sessionId < b.sessionId ? 1 : a.sessionId > b.sessionId ? -1 : 0;
381
493
  }
494
+ function readStoreHooks(hooks) {
495
+ if (hooks === undefined)
496
+ return undefined;
497
+ if (typeof hooks !== "object" || hooks === null)
498
+ throw receiptRefusal(`TtlSessionStoreOptions.hooks must be an object when given, got ${hooks === null ? "null" : typeof hooks}`);
499
+ const got = receiveOwnProperties(hooks, { subject: "TtlSessionStoreOptions.hooks", unit: "hook", moment: "at construction" });
500
+ for (const name of Object.keys(got)) {
501
+ if (name !== "beforeSessionDelete")
502
+ throw receiptRefusal(`TtlSessionStoreOptions.hooks.${name} is not a hook this store runs (it runs beforeSessionDelete)`);
503
+ }
504
+ const hook = got["beforeSessionDelete"];
505
+ if (hook !== undefined && typeof hook !== "function")
506
+ throw receiptRefusal(`TtlSessionStoreOptions.hooks.beforeSessionDelete must be a function when given, got ${hook === null ? "null" : typeof hook}`);
507
+ return hook;
508
+ }
509
+ function readDeleteGuard(guard) {
510
+ if (typeof guard !== "object" || guard === null)
511
+ throw new TypeError(`SessionStore.delete: the guard must be an object { owner }, got ${guard === null ? "null" : typeof guard}`);
512
+ const owner = readMember(guard, "owner");
513
+ if (owner === null)
514
+ return null;
515
+ const name = principalNameOf(owner);
516
+ if (name === undefined)
517
+ throw new TypeError(`SessionStore.delete: guard.owner must be a principal name or null (anonymous), got ${principalNameFault(owner)}`);
518
+ return name;
519
+ }
382
520
  function isNotFound(err) {
383
521
  return readMember(err, "code") === "not_found";
384
522
  }
@@ -8,7 +8,7 @@ export type { SessionWriteOptions } from "../internal/harness.js";
8
8
  import type { Session } from "../internal/harness.js";
9
9
  import type { SessionHead, SessionTreeEntry } from "../internal/harness.js";
10
10
  export type { SessionPlacementRecord } from "../internal/harness.js";
11
- export type { SessionHead } from "../internal/harness.js";
11
+ export type { SessionHead, SessionLogMark, SessionRowExpectation, SessionRowRead } from "../internal/harness.js";
12
12
  /** True when `err` is a session optimistic-lock conflict (a concurrent writer won the branch leaf). Both
13
13
  * halves read what a HOST `SessionStorage` threw, so both are guarded — unreadable is not a conflict,
14
14
  * never a raise inside the classify-and-rethrow guard. The class test is KEPT: widening the verdict to
@@ -340,11 +340,102 @@ export interface SessionStore<S extends SessionStoreSummary = SessionStoreSummar
340
340
  * authorization decision — the caller re-reads {@link headOf} and judges there. The owner lives and dies with its row.
341
341
  */
342
342
  register?(sessionId: string, owner: string | null): Promise<void>;
343
+ /**
344
+ * The storage half of moving a session's log between backends (session-sync): read it out ({@link SessionLogTransfer.listEntryIds},
345
+ * {@link SessionLogTransfer.exportStream}) and replace it whole through a staging the readers never see
346
+ * ({@link SessionLogTransfer.beginReplace}). One write law for every store: a commit onto an existing row keeps that row's occupant and
347
+ * owner and lands only on a row that is already the committer's (compared null-safe; another owner's row is refused `conflict`, a placed
348
+ * row `placement_refused`, nothing written); onto an absent id it creates the row recording the committer and a fresh occupant; every
349
+ * entry passes the engine's import gate ({@link StreamingImportValidator}); and the owner check, the relation the committer judges, the
350
+ * write and the head the commit answers are one step — against every writer of the row, not only this instance's: the commit reads the
351
+ * row once (owner, log and head of one generation), `decide` weighs that log, and the write lands only while the row is still that
352
+ * generation with that log (a write through another instance or the repo since then refuses the commit `conflict`, nothing written);
353
+ * the head answered is the one the write committed (on `"keep"`, the one read). A refusal, or a throw from `decide`, writes nothing.
354
+ * **Optional**: absent = this store does not take part in a cross-backend move.
355
+ */
356
+ readonly logTransfer?: SessionLogTransfer;
357
+ /**
358
+ * Delete a session at its owner's request — the row and its whole log. Only when the row's owner equals `guard.owner` (null-safe:
359
+ * `null` deletes only an anonymous row); a placed row is not deleted here (its deletion is `release`'s, through the joint reap). `true`
360
+ * = this call deleted the row; `false` = there was no row, the guard did not hold, or the row is placed — nothing was deleted, so a
361
+ * repeat is harmless. The id answers nothing afterwards, and a later create under it is a new occupant. A store wired with
362
+ * {@link SessionStoreHooks.beforeSessionDelete} runs it first and deletes nothing when it rejects (the call rejects with it).
363
+ * **Optional**: absent = this store has no owner-guarded delete.
364
+ */
365
+ delete?(sessionId: string, guard: {
366
+ owner: string | null;
367
+ }): Promise<boolean>;
343
368
  /** Number of live/cached sessions (best-effort). */
344
369
  readonly size: number;
345
370
  /** Release resources (timers, connections). Best-effort; must not throw. */
346
371
  dispose(): void | Promise<void>;
347
372
  }
373
+ /** What {@link SessionLogTransfer.exportStream} reads: `afterSeq` resumes after that 0-based position of the oldest-first log (absent
374
+ * = from the first entry; an integer ≥ -1); `batchSize` is how many entries a store reads per page (an integer ≥ 1; absent = the store's
375
+ * own page) — a store holding the log whole reads it once whatever the page, the stream is the same. A bad value is refused. */
376
+ export interface SessionLogExportOptions {
377
+ afterSeq?: number;
378
+ batchSize?: number;
379
+ }
380
+ /** The read and replace halves of {@link SessionStore.logTransfer}. */
381
+ export interface SessionLogTransfer {
382
+ /** The ids of the session's whole log, oldest-first (no compaction floor applied); `null` = no such session. */
383
+ listEntryIds(sessionId: string): Promise<readonly string[] | null>;
384
+ /** The session's whole log, oldest-first, as a stream; `null` = no such session (see {@link SessionLogExportOptions}). */
385
+ exportStream(sessionId: string, opts?: SessionLogExportOptions): Promise<AsyncIterable<SessionTreeEntry> | null>;
386
+ /** Open a staging for a replacement of `sessionId`'s log: entries appended to it are invisible to every reader until its commit.
387
+ * `preserveActorAssertions` is the import gate's trusted-source declaration (see {@link StreamingImportValidator}), read here
388
+ * because the gate reads each batch as it is appended. */
389
+ beginReplace(sessionId: string, opts?: {
390
+ preserveActorAssertions?: boolean;
391
+ }): SessionLogReplace;
392
+ }
393
+ /** What a commit's `decide` sees, inside the commit's one step: the destination's entry ids as they stand now (`null` = no row) and the
394
+ * staged ids, and a read of either side's entries by id. */
395
+ export interface SessionLogCommitView {
396
+ readonly current: readonly string[] | null;
397
+ readonly staged: readonly string[];
398
+ read(side: "current" | "staged", ids: readonly string[]): Promise<SessionTreeEntry[]>;
399
+ }
400
+ /** A commit of a staged replacement. */
401
+ export interface SessionLogCommit {
402
+ /** The committing principal (`null` = anonymous) — the authenticated importer, never a value read from the staged log. */
403
+ owner: string | null;
404
+ /** The committer's judgement of the relation between the two logs, inside the commit's one step: `"replace"` writes the staged log,
405
+ * `"keep"` leaves the destination's log as it is (an identical push); a throw writes nothing and the commit rejects with it. */
406
+ decide(view: SessionLogCommitView): "replace" | "keep" | Promise<"replace" | "keep">;
407
+ }
408
+ /** One staging opened by {@link SessionLogTransfer.beginReplace}. After its commit settles (either way) or its abort, it takes nothing more. */
409
+ export interface SessionLogReplace {
410
+ /** An opaque name of this staging. */
411
+ readonly stagingId: string;
412
+ /** Stage a batch, after the batches before it; each entry passes the import gate here, and a refused batch refuses the staging. */
413
+ append(entries: readonly SessionTreeEntry[]): Promise<void>;
414
+ /** The commit point: the write law of {@link SessionStore.logTransfer}, then `decide`, then the write and the head the row holds
415
+ * after it, in one step. Before it settles, no reader sees the staged log; a refusal, or a throw from `decide`, writes nothing; a row
416
+ * written by anyone else since the commit read it refuses it `conflict` (read the row again and stage again). The first commit call
417
+ * ends the staging, whatever its outcome. */
418
+ commit(input: SessionLogCommit): Promise<{
419
+ outcome: "replaced" | "kept";
420
+ head: SessionHead;
421
+ }>;
422
+ /** Drop the staging; nothing is written. Idempotent. */
423
+ abort(): Promise<void>;
424
+ }
425
+ /**
426
+ * A deployment's hooks on a session store's row deletions — the cleanup of the deployment's own records keyed by session id (a title, a
427
+ * pin, an instruction baseline). `beforeSessionDelete` runs, and is awaited, before every deletion of a row the store makes (an owner's
428
+ * {@link SessionStore.delete}, a placed `release`, an `evict: "delete"` release or idle sweep); when it rejects the row is not deleted and
429
+ * the deletion fails with it — an owner's `delete` or a placed `release` called again runs both again, while an ordinary release has
430
+ * dropped its view and, like any failed ordinary release, has nothing more to delete. The deletion after the hook lands only on the row
431
+ * the store judged (the repo judges it in the step that removes the row — another writer may have deleted the row, created another under
432
+ * the id, or written it while the hook ran); a row that is no longer the one judged is not deleted. The row is still there while the hook
433
+ * runs, so no create under the same id can meet the deployment's records for the occupant being deleted. Called with the id only; it
434
+ * must be idempotent.
435
+ */
436
+ export interface SessionStoreHooks {
437
+ beforeSessionDelete?(sessionId: string): void | Promise<void>;
438
+ }
348
439
  /** Structural detection: does this store expose the optional {@link SessionStore.fork}? Mounts the fork
349
440
  * capability only when true (INERT otherwise — mirrors `hasScheduler`/`hasBackgroundShell`). */
350
441
  export declare function hasSessionFork(store: SessionStore): store is SessionStore & {
@@ -17,6 +17,7 @@ const MEMBER_KINDS = {
17
17
  unestablished: "mark",
18
18
  writesPlaced: "mark",
19
19
  writeProtected: "mark",
20
+ writeProtectedOnDisk: "mark",
20
21
  targetUnresolved: "mark",
21
22
  unplacedOptions: "record",
22
23
  admit: "admission",
@@ -1,5 +1,6 @@
1
1
  import type { AssistantMessage, StopReason, Tool, ToolResultMessage, Usage, UserMessage } from "../internal/llm.js";
2
- import type { Brain, Model, ModelRef, ModelRole, ModelRoles, TaskSpec, ThinkingLevel } from "./types.js";
2
+ import type { Brain, Model, ModelRef, ModelRole, ModelRoles, RunnerDeps, TaskSpec, ThinkingLevel } from "./types.js";
3
+ import type { AccountRow } from "./account-row.js";
3
4
  import { type DegradationInfo } from "../brain/degrading.js";
4
5
  import { type BrainErrorCode } from "../brain/errors.js";
5
6
  /** A tool DEFINITION exposed to the model in a side query (never executed by the engine). */
@@ -113,6 +114,13 @@ export interface SideQueryResult {
113
114
  * figures, untouched. `usageMissing` ⇒ the numbers are UNKNOWN shells, not zeros. */
114
115
  usage: Usage;
115
116
  usageMissing?: true;
117
+ /** This query's line in the session's account: `origin: "side_query"`, priced by the engine from the deployment's price table
118
+ * (the arithmetic a run's own model calls use; `usage.cost` above stays the provider's own figure), the model that ANSWERED
119
+ * being the one priced. A host that keeps the account keeps this line beside its run lines and reads them back through
120
+ * `foldAccount`. `costMicroUsd` is absent when that model has no price table (unknown, not free); a reply that reported
121
+ * no usage yields `tokens: 0` with `usageMissing`. A malformed price table prices at its arithmetic, as it does for a run
122
+ * whose deployment governs no money. */
123
+ account: AccountRow;
116
124
  stopReason: StopReason;
117
125
  /** Present on `stopReason:"error"|"aborted"` — the query did not produce a usable reply. The verb
118
126
  * RETURNS the honest failure instead of throwing: utility callers uniformly need "no answer +
@@ -133,5 +141,7 @@ export interface SideQueryDeps {
133
141
  brain: Brain;
134
142
  models?: Record<string, Model>;
135
143
  roles?: ModelRoles;
144
+ /** The deployment's price table (`RunnerDeps.pricing`) the result's `account` line is priced from; absent ⇒ the model's own `cost`, else unpriced. */
145
+ pricing?: RunnerDeps["pricing"];
136
146
  }
137
147
  export declare function runSideQuery(spec: SideQuerySpec, deps: SideQueryDeps): Promise<SideQueryResult>;
@@ -6,6 +6,7 @@ import { effectiveTraitsOf, readModelPromptTraits, selectorsOf } from "../prompt
6
6
  import { readDegradation } from "../brain/degrading.js";
7
7
  import { extractErrorCode } from "../brain/errors.js";
8
8
  import { cacheFamilyOf, uncachedInputTokensOf } from "./runner/usage-accounting.js";
9
+ import { priceReply } from "./runner/reply-pricing.js";
9
10
  import { providerReportedModel } from "./message-utils.js";
10
11
  import { providerToolCallId } from "../brain/tool-call-id.js";
11
12
  function normalizeSideQueryUsage(model, u) {
@@ -82,6 +83,13 @@ export async function runSideQuery(spec, deps) {
82
83
  const servedModel = typeof msg.model === "string" && msg.model.length > 0 ? msg.model : resolved.model.id;
83
84
  const reportedModel = providerReportedModel(msg);
84
85
  const errorCode = extractErrorCode(msg.errorMessage);
86
+ const priced = priceReply(msg.usage, { model: resolved.model, ...(degraded !== undefined && degraded.to !== resolved.model.id ? { servedBy: degraded.to } : {}) }, { pricing: deps.pricing, catalog: deps.models });
87
+ const account = {
88
+ origin: "side_query",
89
+ tokens: msg.usage.totalTokens || 0,
90
+ ...(priced.priced ? { costMicroUsd: priced.costMicroUsd } : {}),
91
+ ...(msg.usageMissing === true ? { usageMissing: true } : {}),
92
+ };
85
93
  return {
86
94
  text,
87
95
  toolCalls,
@@ -91,6 +99,7 @@ export async function runSideQuery(spec, deps) {
91
99
  ...(reportedModel !== undefined ? { responseModel: reportedModel } : {}),
92
100
  usage: normalizeSideQueryUsage(resolved.model, msg.usage),
93
101
  ...(msg.usageMissing === true ? { usageMissing: true } : {}),
102
+ account,
94
103
  stopReason: msg.stopReason,
95
104
  ...(msg.errorMessage !== undefined ? { errorMessage: msg.errorMessage } : {}),
96
105
  ...(msg.stopReason === "error" && errorCode !== undefined ? { errorCode } : {}),
@@ -2,7 +2,8 @@
2
2
  * What a Skill card's approval is bound to, as ONE value: the skill the call names and the two lists approving it releases,
3
3
  * in the rule grammar's canonical spelling (de-duplicated, sorted). Its hash is the `boundGrantDigest` a parked approval is
4
4
  * judged by, so a reader holds the list a person approved and the binding that covers it as the same fact — the live
5
- * `AskRequest`, the parked row and the inbox projection all carry it (minted by `skillGrantBindingMembers`).
5
+ * `AskRequest`, the parked row, the inbox projection and the request a Runner hands a policy all carry it (minted by
6
+ * `skillGrantBindingMembers`; on a request through {@link requestGrantBinding}).
6
7
  *
7
8
  * A leaf on purpose: the checkpoint projection reads it at its boundary and may not import the module that mints it (it imports only
8
9
  * the hash).
@@ -18,7 +19,8 @@ export interface BoundSkillGrants {
18
19
  /**
19
20
  * Why a card carries no binding digest — the closed set of `boundGrantAbsence`: `not_bindable` (the call is not an
20
21
  * activation of the engine's `Skill` tool: it binds no grant) or `unreadable` (the card binds a grant and what it binds
21
- * cannot be read: a stored row whose digest is not a string, or that says neither).
22
+ * cannot be read: a stored row whose digest is not a string, or that says neither; a request copied over moved args whose
23
+ * digest the engine did not mint for that call, {@link withArgsBinding}).
22
24
  */
23
25
  export declare const BOUND_GRANT_ABSENCES: readonly ["not_bindable", "unreadable"];
24
26
  export type BoundGrantAbsence = (typeof BOUND_GRANT_ABSENCES)[number];
@@ -63,3 +65,30 @@ export declare function readBoundBinding(row: {
63
65
  } | {
64
66
  boundGrantAbsence: BoundGrantAbsence;
65
67
  };
68
+ /**
69
+ * The grant-binding words of a request a Runner hands a policy — the leg's card factory `of` over the request's own `args` (the members
70
+ * every card of the call carries, by the same function): the digest arm with its value frozen, or the factory's absence word. The digest
71
+ * arm carries a note of how the same call is minted over other args, so a copy of the request over moved args carries the answer for
72
+ * THOSE ({@link withArgsBinding}).
73
+ */
74
+ export declare function requestGrantBinding(of: GrantBindingOf, call: {
75
+ readonly toolName: string;
76
+ }, args: unknown): SkillGrantBindingMembers;
77
+ /** A carrier of a call's binding words — a request or a row: its tool name, its args and the three members, as stored. */
78
+ export interface GrantBindingCarrier {
79
+ readonly toolName?: unknown;
80
+ readonly args: unknown;
81
+ readonly boundGrantDigest?: unknown;
82
+ readonly boundGrants?: unknown;
83
+ readonly boundGrantAbsence?: unknown;
84
+ }
85
+ /**
86
+ * The carrier moved to other args — a copy holding `args` and the binding for THEM (a carrier that holds none moves with none). The
87
+ * binding follows the args by ONE rule: a digest {@link requestGrantBinding} minted for this call is minted again over `args`; a digest
88
+ * with no such note (a clone, a host-built request, a note minted for another call or digest) holds over the same bytes and reads
89
+ * `unreadable` over moved ones — it binds a grant, and what it binds over these args cannot be read here; an absence word holds for any
90
+ * args of the call (args never make a call a `Skill` activation, nor an unreadable binding readable). Every member is read as
91
+ * {@link readBoundBinding} reads a row: a digest that is not a string, or a word outside the set, moves as `unreadable`; lists that do
92
+ * not hash to the digest are dropped (the digest alone holds over the same bytes). Lists a request carries are a frozen copy.
93
+ */
94
+ export declare function withArgsBinding<R extends GrantBindingCarrier>(carrier: R, args: unknown): R;
@@ -1,4 +1,4 @@
1
- import { boundInputHashOf } from "./canonical-json.js";
1
+ import { boundInputHashOf, canonicalize } from "./canonical-json.js";
2
2
  export const BOUND_GRANT_ABSENCES = Object.freeze(["not_bindable", "unreadable"]);
3
3
  const BOUND_GRANT_ABSENCE_SET = new Set(BOUND_GRANT_ABSENCES);
4
4
  const isBoundGrantAbsence = (v) => BOUND_GRANT_ABSENCE_SET.has(v);
@@ -28,3 +28,33 @@ export function readBoundBinding(row) {
28
28
  const word = row.boundGrantAbsence;
29
29
  return { boundGrantAbsence: digest === undefined && isBoundGrantAbsence(word) ? word : "unreadable" };
30
30
  }
31
+ const REMINT = new WeakMap();
32
+ export function requestGrantBinding(of, call, args) {
33
+ const members = of(call, args);
34
+ if (members.boundGrants === undefined)
35
+ return members;
36
+ const boundGrants = frozenGrants(members.boundGrants);
37
+ const toolName = call.toolName;
38
+ REMINT.set(boundGrants, { toolName, digest: members.boundGrantDigest, remint: (moved) => requestGrantBinding(of, { toolName }, moved) });
39
+ return { boundGrantDigest: members.boundGrantDigest, boundGrants };
40
+ }
41
+ export function withArgsBinding(carrier, args) {
42
+ if (carrier.boundGrantDigest === undefined && carrier.boundGrants === undefined && carrier.boundGrantAbsence === undefined)
43
+ return { ...carrier, args };
44
+ return { ...carrier, args, boundGrantDigest: undefined, boundGrants: undefined, boundGrantAbsence: undefined, ...movedBinding(carrier, args) };
45
+ }
46
+ function movedBinding(carrier, args) {
47
+ const grants = carrier.boundGrants;
48
+ const note = typeof grants === "object" && grants !== null ? REMINT.get(grants) : undefined;
49
+ if (note !== undefined && note.digest === carrier.boundGrantDigest && note.toolName === carrier.toolName)
50
+ return note.remint(args);
51
+ const read = readBoundBinding(carrier);
52
+ if (!("boundGrantDigest" in read))
53
+ return read;
54
+ if (canonicalize(args) !== canonicalize(carrier.args))
55
+ return { boundGrantAbsence: "unreadable" };
56
+ return read.boundGrants !== undefined ? { boundGrantDigest: read.boundGrantDigest, boundGrants: frozenGrants(read.boundGrants) } : read;
57
+ }
58
+ function frozenGrants(g) {
59
+ return Object.freeze({ skill: g.skill, allowedTools: Object.freeze([...g.allowedTools]), disallowedTools: Object.freeze([...g.disallowedTools]) });
60
+ }
@@ -50,7 +50,8 @@ export declare function skillNamedBy<T extends Pick<SkillGrantSource, "name">>(a
50
50
  export declare function skillGrantDigest(skill: Pick<SkillGrantSource, "name" | "allowedTools" | "disallowedTools"> | undefined): string;
51
51
  /**
52
52
  * The card members of a call to the engine's `Skill` tool — the ONE factory every ask spreads them from: the live
53
- * `AskRequest` an approver is handed, an ancestor's, the parked row and (through the row) the inbox projection.
53
+ * `AskRequest` an approver is handed, an ancestor's, the parked row and (through the row) the inbox projection — and, through
54
+ * `requestGrantBinding`, the request a Runner hands a policy (`ToolCallRequest`: the same members over the request's own args).
54
55
  * `boundGrants` is the skill's name and canonical lists, `boundGrantDigest` its hash — the same value, so what a person was
55
56
  * shown and what an approving resume is judged by cannot differ. The binding is a property of the CALL, whoever asked and
56
57
  * however the question was worded. Every other call — and any call when no skill is loaded (no engine `Skill` tool is
@@ -118,9 +119,10 @@ export declare function skillAllowDecision(hit: SkillGrantHit, updatedInput: unk
118
119
  /**
119
120
  * The Skill card's question: the reference implementation's sentence (`Execute skill: <name>`), and — when approving
120
121
  * releases anything — the entries it releases for the rest of the run in this mode (an entry that grants nothing, or
121
- * stands down in this mode, is not named). Deployment text, sanitized and capped.
122
+ * stands down in this mode, is not named — under the leg's `classifyAllShell` in `auto`, no shell entry). Deployment text,
123
+ * sanitized and capped.
122
124
  */
123
- export declare function skillActivationQuestion(skill: SkillGrantSource, mode: PermissionMode | undefined, roster?: ReadonlySet<string>): string;
125
+ export declare function skillActivationQuestion(skill: SkillGrantSource, mode: PermissionMode | undefined, allShell: boolean, roster?: ReadonlySet<string>): string;
124
126
  /** The face the gate and the resumed execution boundary read the table through, bound to the leg's call facts. */
125
127
  export interface SkillGrantLane {
126
128
  /** The allow layer's skill member: what grants this call in this mode, or undefined. */
@@ -150,8 +152,9 @@ export interface SkillGateSeats {
150
152
  }
151
153
  /** The `Skill` tool's per-call seat over the loaded skills: a skill that declares a list states no permission of its own. */
152
154
  export type SkillSeatReader = (args: unknown, mode: PermissionMode | undefined) => PermissionSeatReading | undefined;
153
- /** The reader over these skills (`undefined` when none is loaded): `Execute skill: <name>` for a skill declaring a list. */
154
- export declare function skillSeatReader(skills: readonly SkillGrantSource[], mounted?: MountedToolNames): SkillSeatReader | undefined;
155
+ /** The reader over these skills (`undefined` when none is loaded): `Execute skill: <name>` for a skill declaring a list.
156
+ * `allShell`: the leg's `classifyAllShell` declaration (the card names only what approving releases in the call's mode). */
157
+ export declare function skillSeatReader(skills: readonly SkillGrantSource[], allShell: boolean, mounted?: MountedToolNames): SkillSeatReader | undefined;
155
158
  /**
156
159
  * The gate's seat inputs for one call, composed in ONE place: the mounted instance's static seat (`calledName`), the `Skill`
157
160
  * tool's per-call reader in the leg's live mode (only when the call's wire name is the engine's `Skill` — `skillToolName`),