@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,6 @@
1
1
  import { strict as assert } from "node:assert";
2
- import { uuidv7 } from "../../internal/harness.js";
3
- import { SESSION_LIST_LIMITS, hasSessionFork, isSessionConflict } from "../session.js";
2
+ import { SessionError, uuidv7 } from "../../internal/harness.js";
3
+ import { SESSION_LIST_LIMITS, hasSessionFork, isSessionConflict, } from "../session.js";
4
4
  import { readMember } from "../thrown-value.js";
5
5
  import { receiptRefusal, receiveOwnProperties } from "../own-property-receipt.js";
6
6
  import { beginContract } from "./contract-harness.js";
@@ -181,6 +181,8 @@ async function runSessionStoreContract(make, hooks) {
181
181
  headOf: hasHead,
182
182
  ownership: hasOwnership,
183
183
  replica: () => hooks.replica !== undefined,
184
+ logTransfer: (s) => hasHead(s) && typeof s.logTransfer === "object" && s.logTransfer !== null,
185
+ delete: (s) => hasHead(s) && typeof s.delete === "function",
184
186
  };
185
187
  const faceRun = (name, needs, fn) => run(name, async (store, open) => {
186
188
  const missing = [];
@@ -989,5 +991,237 @@ async function runSessionStoreContract(make, hooks) {
989
991
  assert.notEqual(await tokenOf(store, forkedId, "fork"), source, "a fork copies the history, never the occupant");
990
992
  assert.equal(await tokenOf(store, src, "fork source after"), source, "forking does not touch the source's occupant");
991
993
  });
994
+ run("[transfer] the read half answers the whole log oldest-first, resumes after a position, and says null for an id with no row; a bad read option is refused", async (store) => {
995
+ if (!(await FACE_PRESENT.logTransfer(store)))
996
+ return report("logTransfer", "absent");
997
+ const t = store.logTransfer;
998
+ const id = freshId();
999
+ const session = (await store.acquire(id)).session;
1000
+ for (const e of [userEntry("e1", null), assistantEntry("e2", "e1"), userEntry("e3", "e2")])
1001
+ await append(session, e);
1002
+ assert.deepEqual(await t.listEntryIds(id), ["e1", "e2", "e3"]);
1003
+ assert.deepEqual(await streamIds(t, id), ["e1", "e2", "e3"]);
1004
+ assert.deepEqual(await streamIds(t, id, { afterSeq: 0, batchSize: 1 }), ["e2", "e3"], "afterSeq resumes after that position, whatever the page");
1005
+ assert.deepEqual(await streamIds(t, id, { afterSeq: -1 }), ["e1", "e2", "e3"]);
1006
+ const absent = freshId();
1007
+ assert.equal(await t.listEntryIds(absent), null, "no row ⇒ null, never an empty log");
1008
+ assert.equal(await t.exportStream(absent), null);
1009
+ for (const bad of [{ afterSeq: -2 }, { afterSeq: 1.5 }, { batchSize: 0 }, { afterSeq: "0" }, { cursor: 1 }]) {
1010
+ await rejectsWithCode(() => Reflect.apply(t.exportStream, t, [id, bad]), "config.invalid_argument", `exportStream(${JSON.stringify(bad)})`);
1011
+ }
1012
+ report("logTransfer", "verified");
1013
+ });
1014
+ faceRun("[transfer] a commit onto the committer's own row replaces the log and keeps the row: the occupant and owner stay, and the new log is what this store and a reopened one serve", ["logTransfer", "ownership"], async (store, open) => {
1015
+ const id = freshId();
1016
+ await store.register(id, "kit-alice");
1017
+ const held = (await store.acquire(id)).session;
1018
+ await append(held, userEntry("old1", null));
1019
+ const before = await tokenOf(store, id, "before the commit");
1020
+ const done = await commitLog(store, id, { owner: "kit-alice" }, [userEntry("n1", null), assistantEntry("n2", "n1")]);
1021
+ assert.equal(done.outcome, "replaced");
1022
+ assert.deepEqual({ owner: done.head.owner, incarnation: done.head.incarnation, leafId: done.head.leafId }, { owner: "kit-alice", incarnation: before, leafId: "n2" }, "the head the commit answers is the row it left");
1023
+ assert.deepEqual(await headOf(store, id), done.head);
1024
+ assert.deepEqual(await entryIds((await store.acquire(id)).session), ["n1", "n2"], "a cached view of the replaced log is not served again");
1025
+ const second = await open(hooks.reopen(store));
1026
+ assert.deepEqual(await entryIds(await readBack(second, id)), ["n1", "n2"]);
1027
+ assert.equal(await tokenOf(second, id, "after a restart"), before, "the occupant is the row's: a commit onto an existing row keeps it");
1028
+ });
1029
+ faceRun("[transfer] a commit onto an id with no row creates it: the committer is its owner (null = anonymous) and it is a new occupant", ["logTransfer", "headOf"], async (store) => {
1030
+ const [owned, anonymous] = [freshId(), freshId()];
1031
+ const a = await commitLog(store, owned, { owner: "kit-alice" }, [userEntry("e1", null)]);
1032
+ assert.equal(a.outcome, "replaced");
1033
+ assert.equal(a.head.owner, "kit-alice");
1034
+ const token = await tokenOf(store, owned, "a row a commit created");
1035
+ assert.equal(a.head.incarnation, token);
1036
+ const b = await commitLog(store, anonymous, { owner: null }, [userEntry("e1", null)]);
1037
+ assert.equal(b.head.owner, null);
1038
+ assert.notEqual(await tokenOf(store, anonymous, "a second created row"), token, "two rows are two occupants");
1039
+ });
1040
+ faceRun("[transfer] a commit lands only on the committer's row: another owner's, an anonymous row by a principal, an owned row by an anonymous commit — each refused conflict, decide never asked, nothing written", ["logTransfer", "ownership"], async (store) => {
1041
+ const owned = freshId();
1042
+ await store.register(owned, "kit-alice");
1043
+ await append((await store.acquire(owned)).session, userEntry("a1", null));
1044
+ const anonymous = freshId();
1045
+ await append((await store.acquire(anonymous)).session, userEntry("z1", null));
1046
+ for (const [id, owner, keep] of [[owned, "kit-bob", "a1"], [owned, null, "a1"], [anonymous, "kit-bob", "z1"]]) {
1047
+ for (const verdict of ["replace", "keep"]) {
1048
+ let asked = false;
1049
+ await rejectsWithConflict(() => commitLog(store, id, { owner, decide: () => {
1050
+ asked = true;
1051
+ return verdict;
1052
+ } }, [userEntry("x1", null)]), `a ${verdict} commit by ${String(owner)} onto another's row`);
1053
+ assert.equal(asked, false, "the relation is not judged for a row the committer may not write");
1054
+ assert.deepEqual(await store.logTransfer.listEntryIds(id), [keep], "a refused commit writes nothing");
1055
+ }
1056
+ }
1057
+ assert.equal(await ownerOf(store, owned, "the owned row"), "kit-alice");
1058
+ assert.equal(await ownerOf(store, anonymous, "the anonymous row"), null);
1059
+ });
1060
+ faceRun("[transfer] a row another writer creates while a staging is open: the commit is refused conflict and that row stands — and a row of the committer's own that appears is shown to decide", ["logTransfer", "ownership"], async (store) => {
1061
+ const id = freshId();
1062
+ const staging = store.logTransfer.beginReplace(id);
1063
+ await staging.append([userEntry("x1", null)]);
1064
+ await store.register(id, "kit-bob");
1065
+ await rejectsWithConflict(() => staging.commit({ owner: "kit-alice", decide: () => "replace" }), "a commit onto a row another principal created after the staging opened");
1066
+ assert.equal(await ownerOf(store, id, "the other writer's row"), "kit-bob", "the commit took nobody's row");
1067
+ assert.deepEqual(await store.logTransfer.listEntryIds(id), []);
1068
+ const mine = freshId();
1069
+ const staged = store.logTransfer.beginReplace(mine);
1070
+ await staged.append([userEntry("x1", null)]);
1071
+ await store.register(mine, "kit-alice");
1072
+ let seen;
1073
+ await rejectsWithCode(() => staged.commit({ owner: "kit-alice", decide: (v) => { seen = v.current; throw new SessionError("conflict", "the committer expected no row"); } }), "conflict", "a committer refusing a row it did not expect");
1074
+ assert.deepEqual(seen, [], "decide sees the row as it stands now — present, with its (empty) log, not the absence the staging began on");
1075
+ assert.deepEqual(await store.logTransfer.listEntryIds(mine), []);
1076
+ });
1077
+ faceRun("[transfer] a placed row's log is not replaced: the commit is refused placement_refused and the transcript stays", ["logTransfer", "placements"], async (store) => {
1078
+ const id = freshId();
1079
+ await append((await store.acquire(id, { placement: placementFor() })).session, userEntry("p1", null));
1080
+ await rejectsWithCode(() => commitLog(store, id, { owner: null }, [userEntry("x1", null)]), "placement_refused", "a commit onto a placed row");
1081
+ assert.deepEqual(await store.logTransfer.listEntryIds(id), ["p1"]);
1082
+ });
1083
+ faceRun("[transfer] every staged entry passes the import gate: a refused batch ends the staging, a staged log that does not close is refused at the commit, and either way nothing is written", ["logTransfer", "headOf"], async (store) => {
1084
+ const id = freshId();
1085
+ const broken = store.logTransfer.beginReplace(id);
1086
+ await rejectsWithCode(() => broken.append([userEntry("e2", "missing-parent")]), "invalid_session", "a batch whose entry's parent never appears");
1087
+ await rejectsWithCode(() => broken.append([userEntry("e1", null)]), "invalid_session", "a staging after a refused batch");
1088
+ await rejectsWithCode(() => broken.commit({ owner: null, decide: () => "replace" }), "invalid_session", "a commit of a refused staging");
1089
+ const tworoots = store.logTransfer.beginReplace(id);
1090
+ let early;
1091
+ try {
1092
+ await tworoots.append([userEntry("r1", null), userEntry("r2", null)]);
1093
+ }
1094
+ catch (err) {
1095
+ early = err;
1096
+ }
1097
+ if (early !== undefined)
1098
+ assert.equal(readMember(early, "code"), "invalid_session", "a two-root batch refused at append is refused invalid_session");
1099
+ await rejectsWithCode(() => tworoots.commit({ owner: null, decide: () => "replace" }), "invalid_session", "a staged log with two roots");
1100
+ assert.equal(await headOf(store, id), undefined, "no row was created");
1101
+ });
1102
+ faceRun("[transfer] before its commit a staging is invisible; decide reads both sides, and its throw writes nothing; an abort writes nothing and ends the staging; a decide answer outside the two is refused", ["logTransfer", "ownership"], async (store) => {
1103
+ const id = freshId();
1104
+ await store.register(id, "kit-alice");
1105
+ await append((await store.acquire(id)).session, userEntry("old1", null));
1106
+ const staging = store.logTransfer.beginReplace(id);
1107
+ await staging.append([userEntry("n1", null)]);
1108
+ await staging.append([assistantEntry("n2", "n1")]);
1109
+ assert.deepEqual(await store.logTransfer.listEntryIds(id), ["old1"], "nothing staged is read before the commit");
1110
+ assert.deepEqual(await entryIds((await store.acquire(id)).session), ["old1"]);
1111
+ const boom = new Error("the committer's own refusal");
1112
+ let reads = [];
1113
+ const thrown = await thrownBy(() => staging.commit({
1114
+ owner: "kit-alice",
1115
+ decide: async (v) => {
1116
+ assert.deepEqual(v.current, ["old1"]);
1117
+ assert.deepEqual(v.staged, ["n1", "n2"]);
1118
+ const current = await v.read("current", ["old1"]);
1119
+ reads = [...current, ...(await v.read("staged", ["n2", "n1"]))].map((e) => e.id);
1120
+ firstTextBlock(current[0]).text = "written by decide";
1121
+ throw boom;
1122
+ },
1123
+ }), "a commit whose decide throws");
1124
+ assert.equal(thrown, boom, "the commit rejects with decide's own throw");
1125
+ assert.deepEqual(reads, ["old1", "n2", "n1"], "read answers the entries asked for, in the order asked");
1126
+ assert.deepEqual(await store.logTransfer.listEntryIds(id), ["old1"]);
1127
+ const kept = (await (await store.acquire(id)).session.getStorage().getEntries())[0];
1128
+ assert.equal(firstTextBlock(kept).text, "t-old1", "an entry decide read is a copy: writing to it changes no log");
1129
+ await rejectsWithCode(() => staging.commit({ owner: "kit-alice", decide: () => "replace" }), "invalid_session", "a second commit of one staging");
1130
+ const aborted = store.logTransfer.beginReplace(id);
1131
+ await aborted.append([userEntry("n1", null)]);
1132
+ await aborted.abort();
1133
+ await aborted.abort();
1134
+ await rejectsWithCode(() => aborted.commit({ owner: "kit-alice", decide: () => "replace" }), "invalid_session", "a commit after an abort");
1135
+ const odd = store.logTransfer.beginReplace(id);
1136
+ await odd.append([userEntry("n1", null)]);
1137
+ await rejectsWithCode(() => Reflect.apply(odd.commit, odd, [{ owner: "kit-alice", decide: () => "restamp" }]), "config.invalid_argument", "a decide answer outside replace / keep");
1138
+ assert.deepEqual(await store.logTransfer.listEntryIds(id), ["old1"], "nothing was written by any of them");
1139
+ });
1140
+ faceRun("[transfer] decide answering keep leaves the log as it is and answers the row's head; keep for an id with no row is refused and creates nothing", ["logTransfer", "ownership"], async (store) => {
1141
+ const id = freshId();
1142
+ await store.register(id, "kit-alice");
1143
+ await append((await store.acquire(id)).session, userEntry("e1", null));
1144
+ const done = await commitLog(store, id, { owner: "kit-alice", decide: () => "keep" }, [userEntry("e1", null)]);
1145
+ assert.equal(done.outcome, "kept");
1146
+ assert.deepEqual(done.head, await headOf(store, id));
1147
+ assert.equal(done.head.leafId, "e1");
1148
+ const absent = freshId();
1149
+ await rejectsWithCode(() => commitLog(store, absent, { owner: null, decide: () => "keep" }, [userEntry("e1", null)]), "invalid_session", "keep for an id with no row");
1150
+ assert.equal(await headOf(store, absent), undefined);
1151
+ });
1152
+ faceRun("[transfer] a commit through another instance: this instance's cached view of the replaced log is not served again", ["logTransfer", "ownership", "replica"], async (store, open) => {
1153
+ const id = freshId();
1154
+ const other = await open(hooks.replica(store));
1155
+ await store.register(id, "kit-alice");
1156
+ await append((await store.acquire(id)).session, userEntry("old1", null));
1157
+ await commitLog(other, id, { owner: "kit-alice" }, [userEntry("n1", null), assistantEntry("n2", "n1")]);
1158
+ assert.deepEqual(await entryIds((await store.acquire(id)).session), ["n1", "n2"], "the occupant is the same, the log is not — a view of the old log is a view of a log the row no longer holds");
1159
+ });
1160
+ faceRun("[transfer] a write through another instance while decide weighs the destination (an append to it): the commit is refused conflict, nothing written, and that write stands", ["logTransfer", "ownership", "replica"], async (store, open) => {
1161
+ const id = freshId();
1162
+ const other = await open(hooks.replica(store));
1163
+ await store.register(id, "kit-alice");
1164
+ await append((await store.acquire(id)).session, userEntry("e1", null));
1165
+ const staging = store.logTransfer.beginReplace(id);
1166
+ await staging.append([userEntry("n1", null)]);
1167
+ const decide = async () => {
1168
+ await append((await other.acquire(id)).session, assistantEntry("e2", "e1"));
1169
+ return "replace";
1170
+ };
1171
+ await rejectsWithConflict(() => staging.commit({ owner: "kit-alice", decide }), "a commit whose destination another instance wrote while decide weighed it");
1172
+ assert.deepEqual(await store.logTransfer.listEntryIds(id), ["e1", "e2"], "the other instance's write stands, and nothing of the staged log was written");
1173
+ });
1174
+ faceRun("[delete] only the owner's delete deletes: another owner's or an anonymous guard on an owned row, and an owner's guard on an anonymous row, answer false and leave the row; the right guard answers true, the id is gone, a repeat answers false, and a later create is a new occupant", ["delete", "ownership"], async (store) => {
1175
+ const id = freshId();
1176
+ await store.register(id, "kit-alice");
1177
+ await append((await store.acquire(id)).session, userEntry("e1", null));
1178
+ const before = await tokenOf(store, id, "the owned row");
1179
+ assert.equal(await store.delete(id, { owner: "kit-bob" }), false);
1180
+ assert.equal(await store.delete(id, { owner: null }), false, "null is no wildcard: it deletes only an anonymous row");
1181
+ assert.equal(await ownerOf(store, id, "after two refused deletes"), "kit-alice");
1182
+ assert.equal(await store.delete(id, { owner: "kit-alice" }), true);
1183
+ assert.equal(await headOf(store, id), undefined, "a deleted row answers nothing");
1184
+ assert.equal(await store.delete(id, { owner: "kit-alice" }), false, "a repeat is harmless");
1185
+ assert.deepEqual(await entryIds((await store.acquire(id)).session), [], "the deleted log is not served under the id again");
1186
+ assert.notEqual(await tokenOf(store, id, "the id created again"), before, "a later create under the id is a new occupant");
1187
+ const anonymous = freshId();
1188
+ await append((await store.acquire(anonymous)).session, userEntry("z1", null));
1189
+ assert.equal(await store.delete(anonymous, { owner: "kit-alice" }), false);
1190
+ assert.equal(await store.delete(anonymous, { owner: null }), true);
1191
+ assert.equal(await store.delete(freshId(), { owner: null }), false, "no row ⇒ false");
1192
+ });
1193
+ faceRun("[delete] a guard that names no owner is refused before anything is deleted: an absent owner, a blank one, a non-object guard", ["delete", "ownership"], async (store) => {
1194
+ const id = freshId();
1195
+ await store.register(id, "kit-alice");
1196
+ for (const guard of [{}, { owner: undefined }, { owner: "" }, { owner: " " }, { owner: 7 }, null, "kit-alice"]) {
1197
+ await thrownBy(() => Reflect.apply(store.delete, store, [id, guard]), `delete with guard ${JSON.stringify(guard)}`);
1198
+ }
1199
+ assert.equal(await ownerOf(store, id, "after the refused deletes"), "kit-alice");
1200
+ });
1201
+ faceRun("[delete] a placed row is not deleted here: its deletion is release's", ["delete", "placements"], async (store) => {
1202
+ const id = freshId();
1203
+ await append((await store.acquire(id, { placement: placementFor() })).session, userEntry("p1", null));
1204
+ assert.equal(await store.delete(id, { owner: null }), false);
1205
+ assert.ok((await headOf(store, id)) !== undefined, "the placed row stands");
1206
+ });
992
1207
  await settle();
993
1208
  }
1209
+ function firstTextBlock(entry) {
1210
+ const content = entry.type === "message" ? entry.message.content : undefined;
1211
+ const block = Array.isArray(content) ? content[0] : undefined;
1212
+ assert.ok(block !== undefined && typeof block.text === "string", "a kit user entry carries one text block");
1213
+ return block;
1214
+ }
1215
+ async function streamIds(t, sessionId, opts) {
1216
+ const stream = await t.exportStream(sessionId, opts);
1217
+ assert.ok(stream !== null, "the row exists, so exportStream must answer a stream");
1218
+ const ids = [];
1219
+ for await (const e of stream)
1220
+ ids.push(e.id);
1221
+ return ids;
1222
+ }
1223
+ async function commitLog(store, sessionId, commit, entries) {
1224
+ const staging = store.logTransfer.beginReplace(sessionId);
1225
+ await staging.append(entries);
1226
+ return staging.commit({ owner: commit.owner, decide: commit.decide ?? (() => "replace") });
1227
+ }
@@ -2,6 +2,7 @@ import { callTargetReadingOf } from "./effective-path-target.js";
2
2
  import { advertisedWritableRootsSeat, attestationOf, describeThrown, exemptRootsSeat, refuseOutOfContractDecision } from "./tool-policy.js";
3
3
  import { ownedClearanceFacts, ruleClearanceOf } from "./ask-origin.js";
4
4
  import { skillRowRefusal } from "./skill-grant.js";
5
+ import { NOT_BINDABLE } from "./skill-grant-binding.js";
5
6
  import { applyPersistedTightening } from "./persisted-rule-arms.js";
6
7
  import { readOrgRuleLane, readPersistedRuleLane } from "./rule-lane-reads.js";
7
8
  import { ORG_ADJUDICATION_TIMEOUT_MS, settleOrgVerdictWithin } from "./permission-rule-org.js";
@@ -79,7 +80,7 @@ function createProbeJudge(layers, kind) {
79
80
  return async (unstated, budget) => {
80
81
  const deadlineAt = budget?.deadlineAt ?? Date.now() + ORG_ADJUDICATION_TIMEOUT_MS;
81
82
  const left = () => Math.max(0, Math.min(ORG_ADJUDICATION_TIMEOUT_MS, deadlineAt - Date.now()));
82
- const probe = { ...unstated, approvalReach: "none" };
83
+ const probe = { ...unstated, approvalReach: "none", ...NOT_BINDABLE };
83
84
  const probedArgs = structuredClone(probe.args);
84
85
  const stamped = layers.stampCallTarget?.(probe, layers.signal);
85
86
  const req = stamped !== undefined ? await stamped : probe;
@@ -153,6 +153,23 @@ export interface BrainStatus {
153
153
  * first-byte window before headers, the armed first-token watchdog after — so a consumer can render
154
154
  * "45s of 300s". Absent on every other phase. */
155
155
  timeoutMs?: number;
156
+ /**
157
+ * On a `waiting_first_token` frame: WHICH wait it is. `response_headers` — the `fetch()` call to the
158
+ * response headers (connecting, sending the request body, and whatever the gateway does before it starts
159
+ * answering; the engine cannot see these apart, they happen inside the transport); `first_token` — the
160
+ * headers to the first content delta (a thinking delta counts). Present on every `waiting_first_token`
161
+ * frame, absent on every other phase.
162
+ */
163
+ waitSegment?: "response_headers" | "first_token";
164
+ /**
165
+ * On a retry-wait frame (`phase: "reconnecting"`, `errClass: "stall"`) for an attempt this process ended
166
+ * because the HOST WAS SUSPENDED across the wait — the machine slept, or the process was stopped — how long,
167
+ * ms: the sum of the gaps longer than five seconds between the engine's once-a-second readings of the wall
168
+ * clock, from the start of the wait the attempt was in (response headers, first token, or the silence
169
+ * between deltas). The attempt is ended at the first reading where this exceeds half of that wait's window,
170
+ * and is re-sent on a fresh connection. Absent on every other frame — a stall a deadline cut carries none.
171
+ */
172
+ sleptMs?: number;
156
173
  /** 1-based index of the attempt that just failed (the wait precedes attempt `attempt + 1`);
157
174
  * same numbering as the `brain.retry` telemetry frame. Absent on frames that are not a retry wait. */
158
175
  attempt?: number;
@@ -278,6 +295,27 @@ export interface ExtensionRequester {
278
295
  readonly kind: "extension";
279
296
  readonly name: string;
280
297
  }
298
+ /**
299
+ * Who replaced the arguments the gate let a tool call go with, one entry per replacement: an extension of this leg by its
300
+ * registration name (its `classic.PreToolUse` answer's `updatedInput`); the leg's restriction chain (`policy` — the bytes came
301
+ * back in the chain's answer, whoever inside it wrote them: the deployment's `ToolPolicy`, a constraint the leg inherited (an
302
+ * ancestor leg's screening among them), an approver a layer consults itself — the layer word a refusal of that chain carries); or
303
+ * the approver of the call's ask, who answered with other arguments (`approver` — whether a person or the host's own approver is
304
+ * the frame's `gate.settlement.who`).
305
+ */
306
+ export type RewriteAuthor = ExtensionRequester | {
307
+ readonly kind: "policy";
308
+ } | {
309
+ readonly kind: "approver";
310
+ };
311
+ /** The arguments the gate let a call go with when they are not the ones it took ({@link RewriteAuthor} names who replaced them). */
312
+ export interface ToolInputRewrite {
313
+ /** One entry per replacement that changed the arguments, in the order they were made (a judge that changed them twice is named twice). */
314
+ readonly by: readonly RewriteAuthor[];
315
+ /** The arguments the gate let the call go with, as the gate's frozen plain-data projection of them (the `finalInput` it records:
316
+ * a member that is not plain data — a bigint, a cycle's closing member — reads as a `[not recorded: …]` marker). */
317
+ readonly input: unknown;
318
+ }
281
319
  /** Streaming events surfaced from a running task (for live UIs). */
282
320
  export type TaskEvent = ({
283
321
  type: "text_delta";
@@ -576,6 +614,12 @@ export type TaskEvent = ({
576
614
  * evidence. The persisted `toolResult` row repeats the frame's mark as `details.notExecuted: true` (a live
577
615
  * leg's rows, the resumed leg's and the reconcile's appended close) — the engine's key alone: a tool's own
578
616
  * value under that name is dropped from the row.
617
+ * It is also set on a call whose gate LET IT GO and which the loop itself then refused before the body started:
618
+ * the arguments the gate cleared failed the loop's own re-validation or re-reading (a rewrite the tool's input
619
+ * check refuses, a form the tool would read as other bytes), or the run was aborted in that gap. Such a frame
620
+ * reads `gate.disposition` allowed, `isError` (with an `errorCode` when the refusal carries one), this mark — and, when the gate replaced the
621
+ * arguments, {@link rewrite} beside them. A call refused before any gate saw it (an unknown tool, arguments the
622
+ * model's own call got wrong) carries no mark: nothing there says whether the loop got that far.
579
623
  * ABSENT means only that no such evidence exists — never "it ran": a call closed with its outcome unknown
580
624
  * (a reconcile at the next process start, a call interrupted mid-execution) carries no mark, because
581
625
  * telling a consumer it did not run could invite a replay of a write that already took effect.
@@ -589,6 +633,20 @@ export type TaskEvent = ({
589
633
  * whose body ran or that no extension answered.
590
634
  */
591
635
  answeredBy?: string;
636
+ /**
637
+ * @contract tool_end.rewrite — the gate let the call go with arguments other than the ones it took: `input` is what it
638
+ * let the call go with, `by` who replaced them. Whether the body then ran is the frame's other members' to say (`isError`
639
+ * with `errorCode`, as for a tool's refusal of those arguments; {@link notExecuted}) — this member is never evidence that
640
+ * it did. Present exactly when the gate's allow exit let the call go, no extension answered for the call in place of its
641
+ * body, and the arguments it let the call go with differ from those it took at its entry (both as the tool reads them —
642
+ * the loop's argument preparation and schema coercion are no rewrite, so the comparison is never against `tool_start.args`,
643
+ * which stays the model's own). Absent on a call refused before it was let go, on a parked or answered-in-place call, and
644
+ * on one whose arguments were replaced and then set back; a refusal recorded after the call was let go (the shell read
645
+ * admission inside the execution, the loop's own refusal of the arguments the gate cleared) leaves it beside that refusal
646
+ * — the call was let go with them. On the frame only: the persisted `toolResult` row does not repeat it. A resumed leg's
647
+ * frames do not carry it.
648
+ */
649
+ rewrite?: ToolInputRewrite;
592
650
  /** The same member as the paired `tool_start`'s: an extension's own call, and who asked for it. */
593
651
  requestedBy?: ExtensionRequester;
594
652
  /**
@@ -968,6 +1026,10 @@ export type TaskEvent = ({
968
1026
  * the engine read for it and will send (`outcome`) — an admission result, not a delivery. Each attachment is
969
1027
  * delivered as its own message after the objective; its `message_committed` is the delivery. */
970
1028
  attachments?: readonly HumanInputAttachment[];
1029
+ /** What brought THIS input, when its host said so on its carrier (`"scheduled"`: the deployment's scheduler handed it —
1030
+ * render it as the scheduler's, not as someone typing): the objective's `TaskSpec.runOrigin`, a parked or waking
1031
+ * message's `runOrigin`. Absent ⇒ the host said nothing (never "a person sent it"). Attribution only. */
1032
+ runOrigin?: import("./run-origin.js").RunOrigin;
971
1033
  } & TaskEventIdentity) | ({
972
1034
  /**
973
1035
  * design/99 §E3/§E10 — a live BRAIN-LAYER status the brain would otherwise absorb
@@ -1171,17 +1233,39 @@ export type TaskEvent = ({
1171
1233
  status: "running" | "completed" | "failed";
1172
1234
  } & TaskEventIdentity) | ({
1173
1235
  /**
1174
- * design/99 §E13 — the task's tracked working directory CHANGED mid-run (a `bash`
1175
- * `cd` moved it). Emitted live after the tool that moved it, carrying the new logical cwd, so a shell UI
1176
- * can update its prompt/path display. The tracked cwd is the RAW logical path (a `cd` through a symlink
1177
- * reports the raw path navigated, not the resolved target). Only fires when a real shell is mounted
1178
- * (absent under `handsReadOnly` / no-exec). The initial cwd is NOT announced (it is the known root); only
1179
- * subsequent changes are. A live observability signal — not persisted, and the tracked cwd RESETS to the
1180
- * root across a suspend/resume (the per-leg execution cwd is not durable today — a pre-existing limitation
1181
- * tracked with the E18/E19 execution-state durability work); within a leg, every `cd` move is reported.
1236
+ * WHERE THIS LEG STANDS, one WHOLE snapshot (minted only by `workspaceSnapshotOf`). EVERY prepared
1237
+ * leg — fresh, resumed, continued, child; a read-only leg and a leg with no shell included — sends ONE leg-start frame
1238
+ * after `wiring_manifest` and the leg-start `tool_disclosure` census (when the leg has one), before its first model or
1239
+ * tool interaction, then one more each time the snapshot CHANGES (a `bash` `cd`, EnterWorktree /
1240
+ * ExitWorktree; observed after the tool that moved it, a resumed leg's approved call included). A frame equal to the
1241
+ * last one this leg sent is never sent. Replace your copy with each frame (last frame wins): the leg-start frame is
1242
+ * a snapshot, not a report that something moved — a consumer already holding the same values renders nothing for it.
1243
+ * A host keeping a session row keeps the LAST frame; nothing else needs re-deriving (the next leg re-sends its own).
1182
1244
  */
1183
1245
  type: "workspace_changed";
1246
+ /** The tracked logical cwd — the RAW path the shell navigated (a `cd` through a symlink reports the path walked,
1247
+ * not its target). A resumed or continuing leg starts where it restored to; a leg with no shell reports `root`. */
1184
1248
  cwd: string;
1249
+ /** This leg's task root as the leg's root receiving point settled it — the spelling its file fences and path rules are
1250
+ * anchored at, and where `cwd` starts. */
1251
+ root: string;
1252
+ /** The model's EnterWorktree switch active on this leg (`byPath`: entered via `path`, not created by this session);
1253
+ * ABSENT = no switch is active on this leg. */
1254
+ entered?: {
1255
+ dir: string;
1256
+ byPath?: true;
1257
+ };
1258
+ /** This leg's project identity, decided ONCE at leg start and fixed for the leg: `marker` = the checkout's
1259
+ * `.sema/project` (a `TaskSpec.projectId`, when given, equals it); `declared` = `TaskSpec.projectId` in a checkout
1260
+ * that carries no marker. ABSENT = no marker and no declaration, or the marker could not be read (the deployment's
1261
+ * `onError` was told which file and why). */
1262
+ project?: {
1263
+ id: string;
1264
+ source: "marker" | "declared";
1265
+ };
1266
+ /** True ⇔ the paths name locations inside a remote / non-host execution env, not host paths (the reading
1267
+ * `ResolvedWorkspace.remote` carries). */
1268
+ remote: boolean;
1185
1269
  } & TaskEventIdentity) | ({
1186
1270
  /**
1187
1271
  * design/173 §2.4/§8.1 — this leg's EFFECTIVE wiring manifest: the machine-readable
@@ -262,6 +262,7 @@ function malformedFacet(f) {
262
262
  }
263
263
  export function engineFrameRecordOf(payload, priority, box) {
264
264
  return {
265
+ id: taskNotificationDedupKey(payload),
265
266
  content: encodeEngineFrame(payload, priority),
266
267
  sentAt: Date.now(),
267
268
  peerMeta: { fromRoot: box.sessionId, kind: "engine_frame" },
@@ -514,20 +515,24 @@ export function routeOrParkNotification(store, sessionId, payload, priority, onD
514
515
  if (box !== undefined && durable) {
515
516
  store.noteDurablePark(sessionId, dedupKey);
516
517
  const record = carrier !== undefined ? sessionBoxRecordOf({ ...payload, agentMessage: carrier }, box) : engineFrameRecordOf(payload, priority, box);
517
- let appended;
518
- try {
519
- appended = Promise.resolve(box.mailbox.append(box.scope, box.handle, record));
520
- }
521
- catch (e) {
522
- appended = Promise.reject(e);
523
- }
524
- const settled = appended.then(() => onDisposition?.("parked_durably"), (e) => {
525
- store.forgetDurablePark(sessionId, dedupKey);
518
+ const ask = () => {
519
+ try {
520
+ return Promise.resolve(box.mailbox.append(box.scope, box.handle, record));
521
+ }
522
+ catch (e) {
523
+ return Promise.reject(e);
524
+ }
525
+ };
526
+ const appended = ask().catch((first) => {
526
527
  try {
527
- box.onError?.(e);
528
+ box.onError?.(first);
528
529
  }
529
530
  catch {
530
531
  }
532
+ return ask();
533
+ });
534
+ const settled = appended.then(() => onDisposition?.("parked_durably"), () => {
535
+ store.forgetDurablePark(sessionId, dedupKey);
531
536
  store.pend(sessionId, payload, priority);
532
537
  onDisposition?.("parked");
533
538
  });
@@ -544,6 +549,7 @@ export function routeOrParkNotification(store, sessionId, payload, priority, onD
544
549
  export function sessionBoxRecordOf(payload, box) {
545
550
  const peer = payload.peer;
546
551
  return {
552
+ id: taskNotificationDedupKey(payload),
547
553
  from: payload.agentMessage.from,
548
554
  content: payload.agentMessage.body,
549
555
  sentAt: Date.now(),
@@ -426,6 +426,7 @@ export function registerBackgroundAgentLane(core, input) {
426
426
  ...(input.agentType !== undefined ? { agentType: input.agentType } : {}),
427
427
  ...(input.description !== undefined ? { description: input.description } : {}),
428
428
  ...(input.model !== undefined ? { model: input.model } : {}),
429
+ ...(input.policyFloor !== undefined ? { policyFloor: input.policyFloor } : {}),
429
430
  writerId: core.writerId,
430
431
  writerEpoch: 1,
431
432
  spawnedAt: now,
@@ -860,7 +860,8 @@ export declare function engineAgentName(handle: string): string;
860
860
  * also a spawn identity (the teammate key, `spawnName` on frames, a roster entry, the unnamed-child tool pool),
861
861
  * and a reader that hands a row's name back into a place that reads it as an identity — a revival's `name`
862
862
  * argument, a retained resume's row name — goes through here, so an agent nobody named stays unnamed in every
863
- * later cycle. A reader that only needs to ADDRESS the agent reads `name` as it is.
863
+ * later cycle. A reader that only needs to ADDRESS the agent reads `name` as it is. A serving layer's roster reads
864
+ * "chosen vs derived" back through here from the row's handle + name — it keeps no column of its own for it.
864
865
  */
865
866
  export declare function chosenAgentName(handle: string, name: string | undefined): string | undefined;
866
867
  /** Synthetic settle error the subagent reap path passes after a stop/parent teardown. It is NOT a
@@ -988,6 +989,11 @@ export interface RegisterBackgroundAgentInput extends TaskAccess {
988
989
  * force at WAKE time; only a spawn that carried a Model OBJECT records that object's id. Same
989
990
  * value and same rule as the roster row's `model` column. */
990
991
  model?: string;
992
+ /** The tighten-only floor the child is born under — the clamp table's projection of its spawn spec — written onto the
993
+ * durable row ({@link import("./background-agent-store.js").BackgroundAgentRecord.policyFloor}); `{}` when nothing is
994
+ * clamped. A row registered without one states no floor and is never revived. A seeded (revival) registration ignores it:
995
+ * the claimed row keeps the floor it was born with. */
996
+ policyFloor?: import("./child-clamp-seats.js").ClampValues;
991
997
  toolUseId?: string;
992
998
  abort: AbortController;
993
999
  now?: number;
@@ -111,6 +111,22 @@ export interface TaskSpec {
111
111
  * honest one, because `hostAsserted` states whether the identity was ingress-derived.
112
112
  */
113
113
  actor?: ActorAssertion;
114
+ /**
115
+ * What started this task, when the host says so ({@link import("./run-origin.js").RunOrigin}): `"scheduled"` = the
116
+ * deployment's scheduler (cron, heartbeat, delayed wake-up, stored routine) fired an intent stored earlier — nobody submitted
117
+ * it just now. Absent = the host said nothing (never read as "a person sent it"). Attribution only, exactly like
118
+ * {@link actor}: no permission, approval, mode or scope decision reads it, and it never enters the model's context.
119
+ *
120
+ * It is the word of the objective, the input that opens the task's first leg: that leg's `wiring_manifest` reports it
121
+ * (`leg.runOrigin`), the objective's `human_input` frame and its message carry it, and a checkpoint the leg parks records it
122
+ * (`CheckpointSummary.runOrigin`). A resumed leg continues the row's word unless a wake opens it (with the newest input the
123
+ * wake hands over, which states its own); a resume config carries NO word — any value is refused, before the claim. A
124
+ * delegated child does not inherit it. A value outside the set is refused at the door (`config.run_origin_invalid`).
125
+ *
126
+ * 🔴 Trust contract: set it ONLY at the deployment's own scheduler fire path — never copy it from a request body, or any
127
+ * caller can mark its run as scheduled and the audit face reads the claim as the host's. The engine cannot verify it.
128
+ */
129
+ runOrigin?: import("./run-origin.js").RunOrigin;
114
130
  /**
115
131
  * design/173 §3/§8.3 — the caller's DECLARED interaction posture for this run. `"interactive"`
116
132
  * asserts a live human is reachable and makes prepare REFUSE the leg (fail-loud
@@ -178,6 +194,14 @@ export interface TaskSpec {
178
194
  userAttachments?: readonly UserAttachment[];
179
195
  /** Reuse an existing in-memory session for chat continuity; omit to start fresh. */
180
196
  sessionId?: string;
197
+ /**
198
+ * The project the host files this session under — a project UUID (the id a `.sema/project` marker carries; send it on
199
+ * every leg). The engine has ONE judge of a leg's project identity: when the leg's checkout carries a marker, the marker
200
+ * decides and this value must EQUAL it (else the leg is refused, `config.project_identity_mismatch`); in a checkout with
201
+ * no marker this value IS the identity. Not a UUID ⇒ `config.project_id_invalid`. The verdict rides
202
+ * `workspace_changed.project`; read it there rather than re-deriving it. Memory keys only by the marker.
203
+ */
204
+ projectId?: string;
181
205
  /**
182
206
  * design/114 Phase3 — with `sessionId` set, REQUIRE that session to already exist: if it is gone (e.g. a
183
207
  * non-durable store lost it across a restart, or a typo'd id), the run FAILS LOUD (`resume.session_not_found`)
@@ -972,6 +996,19 @@ export interface TaskSpec {
972
996
  * `requestReview` is a no-op). The tool is a thin composition over the general `requestReview` primitive.
973
997
  */
974
998
  enablePlanMode?: boolean;
999
+ /**
1000
+ * The absolute path of THIS session's plan file in the leg's execution environment (the reference's `<plans dir>/<slug>.md`).
1001
+ * Where the plan lives is one fact: declared, the plan is that file — admitted by the advertised-writable seat (its third
1002
+ * advertiser), so the file tools' root fence (write + read) and every mode's write gate admit it without a question, the
1003
+ * write-protection table does not demote it, `ExitPlanMode` takes no `plan` and reads it, and the planning frames name it;
1004
+ * absent, the plan is `ExitPlanMode`'s `plan` argument and no plan file exists (byte-identical to a run before this seat).
1005
+ * The fence and write gates admit the path and anything beneath it until #2746 (KL-1503-a); the table exempts exactly the
1006
+ * file; siblings, a link swapped in later and every deny row stay as they were. The host creates the file's directory
1007
+ * before the run. Refused with `config.plan_file_invalid` (the run never starts): not an absolute string in lexical normal
1008
+ * form that the model can be told verbatim; a link, directory or other non-file leaf; a parent that is not a directory;
1009
+ * hands absent or read-only; a key holding a fence root. Not inherited by a delegated child, a fork or a workflow step.
1010
+ */
1011
+ planFile?: string;
975
1012
  /**
976
1013
  * Interactive-tool mounting override (AskUserQuestion / ExitPlanMode /
977
1014
  * EnterPlanMode share one `isEnabled` gate — in non-interactive mode without an SDK permission-prompt
@@ -1039,6 +1076,17 @@ export interface TaskSpec {
1039
1076
  * Persists on the checkpoint's data half (`CheckpointState.inheritedGate.permissionMode`), re-judged on every leg.
1040
1077
  */
1041
1078
  permissionMode?: PermissionMode;
1079
+ /**
1080
+ * In `auto` mode, let no shell allow entry clear a call — the classifier judges it (the reference's
1081
+ * `autoMode.classifyAllShell`). `true` ⇒ while the mode is `auto` (read per call), the whole shell tool, a name that reaches
1082
+ * it and every `Bash(…)` rule whatever it names stand down — in stored rules, a skill's `allowed-tools`, {@link allowedTools}
1083
+ * and the deployment's list alike. Absent / `false` ⇒ only the entries that hand over arbitrary code stand down. Narrows only;
1084
+ * outside `auto`, and for deny / ask rules, a hook's allow, non-shell entries and a read-only command, nothing changes. Which settings planes may set it is the host's
1085
+ * reading (the reference: user, flag and managed settings, never a repository's own); the host sends its allow lists
1086
+ * unchanged beside it. Tighten-only: `tightenTaskSpec` keeps a baseline's `true`, an engine-built child inherits it. A
1087
+ * present non-boolean refuses the run (`config.invalid_argument`).
1088
+ */
1089
+ classifyAllShell?: boolean;
1042
1090
  /** Task-scoped MCP servers, materialized into tools then disposed. */
1043
1091
  mcp?: McpServerSpec[];
1044
1092
  /** Task-scoped A2A peers (remote agents), whose advertised skills mount as `a2a__<peer>__<skill>`
@@ -1078,7 +1126,7 @@ export interface TaskSpec {
1078
1126
  * deployment's {@link import("./runner-deps.js").RunnerDeps.allowedTools}, under the same predicate: deny and ask rules
1079
1127
  * still win, and a question no allow rule clears (a mandated, governance, hook or plan question) is still put to a person,
1080
1128
  * with the entry disclosed on the card. In `auto` mode an entry that hands over arbitrary code (the whole shell, an
1081
- * interpreter or launcher prefix) is left to the classifier.
1129
+ * interpreter or launcher prefix) is left to the classifier — every shell entry, under {@link classifyAllShell}.
1082
1130
  *
1083
1131
  * Lives for this run — the steers it takes in included; a delegated child holds the entries until it ends; a resumed leg
1084
1132
  * holds them only when its spec supplies them again (they are not written into a checkpoint). An entry this grammar
@@ -53,7 +53,8 @@ export interface TaskStream extends AsyncIterable<TaskEvent> {
53
53
  * evidence of a replay, and two callers colliding on one id must not silently lose the second
54
54
  * (the parked leg's `appendPendingSteer` judges and refuses it identically). The error carries
55
55
  * `detail.differs` — the facets that differ (closed `STEER_REPLAY_FACETS`: `text`, `trusted`,
56
- * `priority`, `actor`), compared on what the caller SENT, never on the framed bytes. With `text`
56
+ * `priority`, `actor`, `runOrigin` — this verb takes no run origin, so a repeat here never differs in it),
57
+ * compared on what the caller SENT, never on the framed bytes. With `text`
57
58
  * among them it is another instruction: re-issue it under a fresh id. Without, it is the accepted one
58
59
  * re-sent at another tier / trust / attribution, which acceptance does not change: a fresh id would
59
60
  * queue it twice, so replay it with its original values to confirm the receipt.