@sema-agent/core 7.62.0 → 7.64.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 (320) hide show
  1. package/CHANGELOG.md +936 -0
  2. package/dist/agents/cc-peer-directory.js +1 -0
  3. package/dist/agents/cc-peer-wire.d.ts +4 -0
  4. package/dist/agents/cc-peer-wire.js +1 -0
  5. package/dist/agents/cc-uds-peer-channel.js +5 -0
  6. package/dist/agents/cross-session-judge.d.ts +3 -1
  7. package/dist/agents/cross-session-judge.js +4 -1
  8. package/dist/agents/peer-directory.d.ts +8 -0
  9. package/dist/agents/peer-directory.js +4 -0
  10. package/dist/agents/peer-held-queue.d.ts +9 -3
  11. package/dist/agents/peer-held-queue.js +12 -9
  12. package/dist/agents/peer-idle.d.ts +20 -1
  13. package/dist/agents/peer-idle.js +23 -12
  14. package/dist/agents/peer-notice-route.d.ts +16 -5
  15. package/dist/agents/peer-notice-route.js +11 -9
  16. package/dist/agents/peer-notices.d.ts +25 -8
  17. package/dist/agents/peer-notices.js +6 -1
  18. package/dist/agents/peer-session-drain.d.ts +32 -6
  19. package/dist/agents/peer-session-drain.js +100 -26
  20. package/dist/agents/send-message-tool.d.ts +7 -0
  21. package/dist/agents/send-message-tool.js +18 -6
  22. package/dist/agents/subagent-transcript-placement.d.ts +23 -0
  23. package/dist/agents/subagent-transcript-placement.js +14 -0
  24. package/dist/agents/subagent.js +102 -54
  25. package/dist/brain/route-adjudicator.js +9 -4
  26. package/dist/core/allow-entry.d.ts +4 -0
  27. package/dist/core/approval-object.js +1 -1
  28. package/dist/core/arg-summary.js +1 -1
  29. package/dist/core/ask-origin.d.ts +1 -1
  30. package/dist/core/ask-origin.js +2 -2
  31. package/dist/core/ask-question.d.ts +2 -2
  32. package/dist/core/ask-unresolvable-notice.d.ts +13 -4
  33. package/dist/core/ask-unresolvable-notice.js +10 -3
  34. package/dist/core/auto-compaction.d.ts +7 -5
  35. package/dist/core/background-agent-store.d.ts +7 -0
  36. package/dist/core/background-agent-store.js +3 -0
  37. package/dist/core/canonical-json.d.ts +23 -13
  38. package/dist/core/canonical-json.js +4 -4
  39. package/dist/core/checkpoint-queries.d.ts +50 -4
  40. package/dist/core/checkpoint-queries.js +42 -17
  41. package/dist/core/checkpoint-requirements.d.ts +3 -3
  42. package/dist/core/checkpoint-requirements.js +2 -1
  43. package/dist/core/checkpoint-row-verdict.d.ts +15 -4
  44. package/dist/core/checkpoint-row-verdict.js +22 -2
  45. package/dist/core/checkpoint-store.d.ts +28 -11
  46. package/dist/core/checkpoint-store.js +45 -4
  47. package/dist/core/compliance.d.ts +6 -2
  48. package/dist/core/compliance.js +3 -3
  49. package/dist/core/context-settings.d.ts +40 -9
  50. package/dist/core/context-settings.js +32 -10
  51. package/dist/core/engine-attestation.d.ts +27 -7
  52. package/dist/core/engine-attestation.js +5 -1
  53. package/dist/core/engine-notice.d.ts +43 -5
  54. package/dist/core/extension-requester.d.ts +9 -0
  55. package/dist/core/extension-requester.js +7 -0
  56. package/dist/core/file-history-store.d.ts +28 -0
  57. package/dist/core/file-history-store.js +48 -5
  58. package/dist/core/fs-write-gate-policy.js +1 -1
  59. package/dist/core/gate-fold.js +2 -0
  60. package/dist/core/gate-lanes.js +2 -0
  61. package/dist/core/gate-outcome.d.ts +39 -2
  62. package/dist/core/gate-outcome.js +20 -1
  63. package/dist/core/git-worktree-env.d.ts +62 -3
  64. package/dist/core/git-worktree-env.js +91 -30
  65. package/dist/core/governance-codes.d.ts +9 -3
  66. package/dist/core/governance-codes.js +17 -3
  67. package/dist/core/leg-identity.d.ts +19 -1
  68. package/dist/core/leg-identity.js +12 -0
  69. package/dist/core/mailbox-store.d.ts +39 -4
  70. package/dist/core/mailbox-store.js +14 -2
  71. package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
  72. package/dist/core/memory-engine/consolidation-driver.js +99 -98
  73. package/dist/core/memory-engine/consolidation.d.ts +74 -10
  74. package/dist/core/memory-engine/consolidation.js +183 -11
  75. package/dist/core/memory-engine/control-objects.d.ts +25 -0
  76. package/dist/core/memory-engine/control-objects.js +151 -0
  77. package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
  78. package/dist/core/memory-engine/control-plane-adoption.js +159 -0
  79. package/dist/core/memory-engine/data-plane.d.ts +8 -4
  80. package/dist/core/memory-engine/data-plane.js +11 -6
  81. package/dist/core/memory-engine/delegation-settlement.d.ts +58 -40
  82. package/dist/core/memory-engine/delegation-settlement.js +270 -85
  83. package/dist/core/memory-engine/dual-root.d.ts +12 -6
  84. package/dist/core/memory-engine/dual-root.js +11 -7
  85. package/dist/core/memory-engine/engine.d.ts +136 -58
  86. package/dist/core/memory-engine/engine.js +491 -394
  87. package/dist/core/memory-engine/entry-scan.d.ts +8 -0
  88. package/dist/core/memory-engine/entry-scan.js +3 -0
  89. package/dist/core/memory-engine/file-backend.d.ts +62 -60
  90. package/dist/core/memory-engine/file-backend.js +122 -198
  91. package/dist/core/memory-engine/index.d.ts +8 -7
  92. package/dist/core/memory-engine/index.js +7 -6
  93. package/dist/core/memory-engine/landing-admission.d.ts +5 -3
  94. package/dist/core/memory-engine/landing-admission.js +3 -3
  95. package/dist/core/memory-engine/layout.d.ts +127 -46
  96. package/dist/core/memory-engine/layout.js +264 -109
  97. package/dist/core/memory-engine/memory-backend-contract.d.ts +26 -1
  98. package/dist/core/memory-engine/memory-backend-contract.js +476 -0
  99. package/dist/core/memory-engine/memory-deployment.d.ts +42 -11
  100. package/dist/core/memory-engine/memory-deployment.js +54 -15
  101. package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
  102. package/dist/core/memory-engine/origin-clearance.js +68 -9
  103. package/dist/core/memory-engine/scope-contract.d.ts +52 -11
  104. package/dist/core/memory-engine/scope-contract.js +68 -19
  105. package/dist/core/memory-engine/session-write-home.d.ts +37 -2
  106. package/dist/core/memory-engine/session-write-home.js +38 -11
  107. package/dist/core/memory-engine/sync-client.d.ts +3 -1
  108. package/dist/core/memory-engine/sync-client.js +7 -0
  109. package/dist/core/memory-engine/sync-report.d.ts +3 -2
  110. package/dist/core/memory-engine/sync-report.js +6 -2
  111. package/dist/core/memory-engine/tools.d.ts +2 -2
  112. package/dist/core/memory-engine/tools.js +10 -10
  113. package/dist/core/memory-engine/types.d.ts +155 -19
  114. package/dist/core/memory-engine/types.js +2 -0
  115. package/dist/core/memory.js +15 -6
  116. package/dist/core/mode-policy.js +3 -3
  117. package/dist/core/mods/agent-stations.d.ts +18 -0
  118. package/dist/core/mods/agent-stations.js +8 -6
  119. package/dist/core/mods/extension-call.d.ts +4 -0
  120. package/dist/core/mods/extension-call.js +8 -0
  121. package/dist/core/mods/stations.d.ts +20 -1
  122. package/dist/core/mods/stations.js +21 -2
  123. package/dist/core/mods/tool-call.js +3 -4
  124. package/dist/core/parent-spec-seat.d.ts +2 -2
  125. package/dist/core/park-selfcheck.js +2 -2
  126. package/dist/core/pause-registry.d.ts +2 -0
  127. package/dist/core/pause-registry.js +3 -0
  128. package/dist/core/peer-channel.d.ts +5 -0
  129. package/dist/core/permission-rule-consent.d.ts +26 -8
  130. package/dist/core/permission-rule-consent.js +76 -36
  131. package/dist/core/permission-rule-store.d.ts +72 -13
  132. package/dist/core/permission-rule-store.js +29 -8
  133. package/dist/core/read-only-shell.js +3 -2
  134. package/dist/core/redaction-marks.d.ts +8 -0
  135. package/dist/core/redaction-marks.js +6 -0
  136. package/dist/core/refusal-echo.d.ts +20 -0
  137. package/dist/core/refusal-echo.js +33 -0
  138. package/dist/core/remote-env.d.ts +12 -1
  139. package/dist/core/remote-env.js +3 -0
  140. package/dist/core/retention.d.ts +180 -10
  141. package/dist/core/retention.js +45 -0
  142. package/dist/core/retired-keys.d.ts +5 -0
  143. package/dist/core/retired-keys.js +3 -0
  144. package/dist/core/rule-offer-read.d.ts +0 -4
  145. package/dist/core/rule-offer-read.js +2 -18
  146. package/dist/core/runner/child-tree.d.ts +29 -3
  147. package/dist/core/runner/child-tree.js +39 -16
  148. package/dist/core/runner/classifier-ladder.d.ts +7 -1
  149. package/dist/core/runner/classifier-ladder.js +4 -2
  150. package/dist/core/runner/compact-session.js +10 -7
  151. package/dist/core/runner/compaction-call-options.d.ts +7 -7
  152. package/dist/core/runner/compaction-call-options.js +3 -2
  153. package/dist/core/runner/contracts.d.ts +39 -11
  154. package/dist/core/runner/delegation-owner.d.ts +10 -3
  155. package/dist/core/runner/delegation-owner.js +4 -1
  156. package/dist/core/runner/gate-exit.d.ts +6 -0
  157. package/dist/core/runner/gate-exit.js +13 -4
  158. package/dist/core/runner/inherited-ask-grants.js +1 -1
  159. package/dist/core/runner/memory-consolidation-driver.d.ts +10 -5
  160. package/dist/core/runner/memory-consolidation-driver.js +12 -9
  161. package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
  162. package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
  163. package/dist/core/runner/person-path-rows.d.ts +8 -3
  164. package/dist/core/runner/person-path-rows.js +5 -1
  165. package/dist/core/runner/placement-fence.d.ts +12 -0
  166. package/dist/core/runner/placement-fence.js +20 -6
  167. package/dist/core/runner/prepare-ask-lane.js +5 -5
  168. package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -2
  169. package/dist/core/runner/prepare-caps-and-workflow.js +7 -4
  170. package/dist/core/runner/prepare-config-doors.js +4 -0
  171. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  172. package/dist/core/runner/prepare-delegation-surface.js +2 -2
  173. package/dist/core/runner/prepare-execution-env.js +17 -6
  174. package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
  175. package/dist/core/runner/prepare-gate-stations.js +5 -5
  176. package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
  177. package/dist/core/runner/prepare-hands-readface.js +5 -4
  178. package/dist/core/runner/prepare-inherited-gate.d.ts +13 -9
  179. package/dist/core/runner/prepare-inherited-gate.js +12 -6
  180. package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
  181. package/dist/core/runner/prepare-memory-engine-session.js +4 -4
  182. package/dist/core/runner/prepare-memory.d.ts +7 -2
  183. package/dist/core/runner/prepare-memory.js +41 -39
  184. package/dist/core/runner/prepare-park-ask.js +4 -3
  185. package/dist/core/runner/prepare-policy-chain.js +7 -7
  186. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  187. package/dist/core/runner/prepare-task.js +26 -18
  188. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  189. package/dist/core/runner/prepare-wiring-manifest.js +3 -2
  190. package/dist/core/runner/prepare-workspace-restore.js +3 -6
  191. package/dist/core/runner/resume-admission.d.ts +2 -2
  192. package/dist/core/runner/resume-admission.js +2 -23
  193. package/dist/core/runner/role-resolution-table.d.ts +98 -0
  194. package/dist/core/runner/role-resolution-table.js +62 -0
  195. package/dist/core/runner/run-compaction-machinery.js +2 -2
  196. package/dist/core/runner/run-identity-wiring.js +12 -9
  197. package/dist/core/runner/run-leg.js +9 -5
  198. package/dist/core/runner/run-notification-lane.js +22 -22
  199. package/dist/core/runner/run-recovery-lanes.js +3 -3
  200. package/dist/core/runner/run-settle-and-teardown.js +3 -2
  201. package/dist/core/runner/run-terminal-adoption.js +1 -1
  202. package/dist/core/runner/run-turn-boundary.js +14 -15
  203. package/dist/core/runner/runtask.js +1 -1
  204. package/dist/core/runner/terminal-account.js +1 -1
  205. package/dist/core/runner/tool-occurrence.d.ts +4 -2
  206. package/dist/core/runner/tool-occurrence.js +2 -2
  207. package/dist/core/runner-deps.d.ts +7 -3
  208. package/dist/core/secret-env.d.ts +1 -1
  209. package/dist/core/secret-env.js +4 -4
  210. package/dist/core/session-checkout.d.ts +168 -0
  211. package/dist/core/session-checkout.js +579 -0
  212. package/dist/core/session-store.d.ts +12 -4
  213. package/dist/core/session-store.js +23 -3
  214. package/dist/core/session.d.ts +16 -2
  215. package/dist/core/session.js +3 -0
  216. package/dist/core/shell-read-silence.js +8 -0
  217. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
  218. package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
  219. package/dist/core/store-contracts/peer-directory-contract.js +8 -1
  220. package/dist/core/store-contracts/session-store-contract.js +39 -0
  221. package/dist/core/task-event.d.ts +30 -5
  222. package/dist/core/task-notification.d.ts +119 -32
  223. package/dist/core/task-notification.js +186 -100
  224. package/dist/core/task-registry-agent.d.ts +25 -2
  225. package/dist/core/task-registry-agent.js +56 -22
  226. package/dist/core/task-registry-shared.d.ts +33 -11
  227. package/dist/core/task-registry.d.ts +33 -9
  228. package/dist/core/task-registry.js +36 -18
  229. package/dist/core/task-spec-members.js +1 -1
  230. package/dist/core/task-spec.d.ts +27 -2
  231. package/dist/core/tool-errors.d.ts +14 -6
  232. package/dist/core/tool-errors.js +1 -1
  233. package/dist/core/tool-policy.d.ts +32 -13
  234. package/dist/core/tool-policy.js +27 -17
  235. package/dist/core/tool-result-store.d.ts +20 -0
  236. package/dist/core/tool-spec.d.ts +42 -19
  237. package/dist/core/trace.d.ts +3 -2
  238. package/dist/core/types.d.ts +1 -1
  239. package/dist/core/untrusted-egress.d.ts +15 -4
  240. package/dist/core/untrusted-egress.js +23 -22
  241. package/dist/core/workflow-journal-store.d.ts +11 -0
  242. package/dist/core/workflow-journal-store.js +7 -0
  243. package/dist/core/workflow-run-store.d.ts +9 -0
  244. package/dist/core/workflow-run-store.js +6 -0
  245. package/dist/core/workspace-snapshot.d.ts +3 -1
  246. package/dist/core/workspace-snapshot.js +1 -0
  247. package/dist/engine/compaction/compaction.d.ts +2 -1
  248. package/dist/engine/harness/types.d.ts +67 -1
  249. package/dist/engine/harness/types.js +108 -0
  250. package/dist/engine/session/import-validate.js +6 -1
  251. package/dist/engine/session/session.d.ts +30 -1
  252. package/dist/engine/session/session.js +48 -1
  253. package/dist/index.d.ts +12 -7
  254. package/dist/index.js +12 -7
  255. package/dist/internal/harness-types.d.ts +1 -1
  256. package/dist/orchestration/run-workflow-tool.d.ts +8 -1
  257. package/dist/orchestration/run-workflow-tool.js +8 -0
  258. package/dist/orchestration/workflow-types.d.ts +2 -1
  259. package/dist/orchestration/workflow.d.ts +6 -0
  260. package/dist/orchestration/workflow.js +5 -2
  261. package/dist/stores/file/checkpoint-store.d.ts +6 -0
  262. package/dist/stores/file/checkpoint-store.js +4 -1
  263. package/dist/stores/file/file-history-store.d.ts +13 -0
  264. package/dist/stores/file/file-history-store.js +75 -13
  265. package/dist/stores/file/index.d.ts +11 -1
  266. package/dist/stores/file/index.js +7 -11
  267. package/dist/stores/file/permission-rule-store.d.ts +23 -0
  268. package/dist/stores/file/permission-rule-store.js +75 -7
  269. package/dist/stores/file/session-store.js +2 -1
  270. package/dist/stores/file/tool-result-store.d.ts +14 -0
  271. package/dist/stores/file/tool-result-store.js +39 -2
  272. package/dist/stores/file/workflow-journal-store.d.ts +4 -0
  273. package/dist/stores/file/workflow-journal-store.js +17 -0
  274. package/dist/stores/file/workflow-run-store.d.ts +3 -0
  275. package/dist/stores/file/workflow-run-store.js +15 -0
  276. package/dist/tools/fs/bash-program-position.js +3 -3
  277. package/dist/tools/fs/program-read-model.d.ts +34 -10
  278. package/dist/tools/fs/program-read-model.js +37 -7
  279. package/dist/tools/fs/program-read-model.rows.js +13 -2
  280. package/dist/tools/fs/read-deny.d.ts +28 -3
  281. package/dist/tools/fs/read-deny.js +18 -2
  282. package/dist/tools/fs/removal-targets.js +3 -3
  283. package/dist/tools/fs/safety.d.ts +2 -0
  284. package/dist/tools/fs/safety.js +1 -1
  285. package/dist/tools/fs/shell-read-argv.d.ts +8 -1
  286. package/dist/tools/fs/shell-read-argv.js +34 -29
  287. package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
  288. package/dist/tools/fs/shell-read-bindings.js +5 -1
  289. package/dist/tools/fs/shell-read-brace.d.ts +18 -0
  290. package/dist/tools/fs/shell-read-brace.js +79 -0
  291. package/dist/tools/fs/shell-read-check.d.ts +8 -2
  292. package/dist/tools/fs/shell-read-check.js +16 -14
  293. package/dist/tools/fs/shell-read-establish.js +23 -16
  294. package/dist/tools/fs/shell-read-judge.d.ts +11 -0
  295. package/dist/tools/fs/shell-read-judge.js +3 -3
  296. package/dist/tools/fs/shell-read-plan.d.ts +10 -0
  297. package/dist/tools/fs/shell-read-plan.js +189 -93
  298. package/dist/tools/fs/shell-read-start.d.ts +19 -9
  299. package/dist/tools/fs/shell-read-start.js +20 -12
  300. package/dist/tools/fs/shell-read-word.d.ts +10 -0
  301. package/dist/tools/fs/shell-read-word.js +9 -5
  302. package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
  303. package/dist/tools/fs/shell-read-workdir.js +73 -12
  304. package/dist/tools/fs/shell-read-write-targets.js +13 -8
  305. package/dist/tools/worktree.d.ts +3 -2
  306. package/dist/tools/worktree.js +7 -35
  307. package/package.json +3 -2
  308. package/test/export-surface.snapshot.json +135 -11
  309. package/wire-changes/core-stores-sql@7.63.0.json +30 -0
  310. package/wire-changes/core-stores-sql@7.64.0.json +30 -0
  311. package/wire-changes/core@7.63.0.json +3523 -0
  312. package/wire-changes/core@7.64.0.json +2653 -0
  313. package/wire-changes/mods-kernel@7.63.0.json +30 -0
  314. package/wire-changes/mods-kernel@7.64.0.json +30 -0
  315. package/wire-changes/primitives@7.63.0.json +445 -0
  316. package/wire-changes/primitives@7.64.0.json +30 -0
  317. package/dist/core/credential-vocabulary.d.ts +0 -176
  318. package/dist/core/credential-vocabulary.js +0 -190
  319. package/dist/core/redaction-passes.d.ts +0 -82
  320. package/dist/core/redaction-passes.js +0 -377
@@ -92,9 +92,17 @@ export declare function formatToolError(error: unknown): string;
92
92
  * `unknown` would UNDO the very audit finding this folder exists to fix (these ARE real
93
93
  * terminal codes, not foreign ones); (c) pre-existing precedent (`config.compliance_required`,
94
94
  * NOT part of this diff) already folds a transient/retryable governance code into `config`.
95
- * `memory.admission_required`/`_denied`/`env.lifetime_expired` are EXACT codes, not broad
96
- * `memory.`/`env.` prefixes — falsification review (A-005.3 follow-up) caught an
97
- * earlier draft folding EVERY `memory.*`/`env.*` code here, which misclassified the
95
+ * The whole `env.` namespace is `config` BY PREFIX: a terminal code there is a refusal or a
96
+ * limit of the execution environment — `env.lifetime_expired`, or the code a deployment's
97
+ * `executionEnvFactory` throws when it refuses to mint (the engine carries a factory's code
98
+ * to the terminal verbatim; the module registers none of them, so a code a later deployment
99
+ * mints still reads `config`) — and what a caller does about every one of them is the same:
100
+ * change the environment or the configuration, then retry. The other `env.`-spelled strings
101
+ * of the codebase (a prompt-assembly block id, mod-kernel event names) are never a terminal
102
+ * code, and this folder's domain is the terminal code alone.
103
+ * `memory.admission_required`/`_denied` are EXACT codes, not a broad `memory.` prefix —
104
+ * falsification review (A-005.3 follow-up) caught an
105
+ * earlier draft folding EVERY `memory.*` code here, which misclassified the
98
106
  * memory-engine's non-governance incident codes (`memory.secret_detected` et al.,
99
107
  * explicitly listed as NON-governance in `NON_GOVERNANCE_MEMORY_CODES` — a content-safety
100
108
  * tool-call refusal, not a task-spec rejection) as configuration failures. `usage.*` STAYS
@@ -119,9 +127,9 @@ export type WorkerErrorClass = "budget" | "limit" | "output" | "suspend" | "revi
119
127
  *
120
128
  * SCOPE: this folds a TERMINAL `TaskResult.errorCode` only — i.e. every OUR dotted prefix that the runner can
121
129
  * assemble into a failed task outcome (`limits.`/`output.`/`suspend.`/`review.`/`unexpected.`/
122
- * `oracle.`/`resume.`/`config.`/`usage.`) as a broad PREFIX, plus `memory.admission_required` /
123
- * `memory.admission_denied` / `env.lifetime_expired` / the two `model.*_exhausted` loop terminals as EXACT codes (their
124
- * sibling `memory.*`/`env.*`/`model.*` strings are NOT all terminal-errorCode-shaped — see {@link EXACT_CODE_CLASS}'s
130
+ * `oracle.`/`resume.`/`config.`/`usage.`/`env.`) as a broad PREFIX, plus `memory.admission_required` /
131
+ * `memory.admission_denied` / the two `model.*_exhausted` loop terminals as EXACT codes (their
132
+ * sibling `memory.*`/`model.*` strings are NOT all terminal-errorCode-shaped — see {@link EXACT_CODE_CLASS}'s
125
133
  * comment), plus the flat 1.36 codes.
126
134
  * The `limits.` namespace splits into the `budget` and `limit` classes by exact code — see
127
135
  * {@link EXACT_CODE_CLASS}. Operation-level dotted codes that are surfaced to a *caller* and never become a
@@ -88,7 +88,6 @@ const EXACT_CODE_CLASS = new Map([
88
88
  ["memory.admission_required", "config"],
89
89
  ["memory.admission_denied", "config"],
90
90
  ["memory.capture_optout_denied", "config"],
91
- ["env.lifetime_expired", "config"],
92
91
  ["model.malformed_tool_use_exhausted", "output"],
93
92
  ["model.truncated_output_exhausted", "output"],
94
93
  ]);
@@ -102,6 +101,7 @@ const DOTTED_PREFIX_CLASS = [
102
101
  ["resume.", "resume"],
103
102
  ["config.", "config"],
104
103
  ["usage.", "config"],
104
+ ["env.", "config"],
105
105
  ];
106
106
  export function errorClassOf(errorCode) {
107
107
  if (!errorCode)
@@ -564,11 +564,13 @@ export interface AskRuleEvidence {
564
564
  }
565
565
  /** The human/model-readable text of a decision. */
566
566
  export declare function decisionText(d: PermissionResult): string | undefined;
567
- /** Does a license (a record's `inputDigest`) cover the bytes that `runs`? The ONE judge — the gate's ledger keeps a settlement for
568
- * the bytes it licensed by it, and the unstated question asks whether an answer was given for these bytes by it. A license for
569
- * bytes covers what the tool reads them as ({@link argsReadFrom}: the one recorded step a reading took to `runs`). Compared by
570
- * the EXACT digest only: bytes outside the bindable domain have none and are covered by no license. */
571
- export declare function licenseCovers(licensed: string | undefined, runs: unknown): boolean;
567
+ /** Does a license (a record's `inputDigest`, a park row's `boundInputHash`) cover the call of `tool` over the bytes that `runs`? The
568
+ * ONE judge — the gate's ledger keeps a settlement for the bytes it licensed by it, and the unstated question asks whether an
569
+ * answer was given for these bytes by it. A license binds the tool and the bytes together ({@link exactBoundInputHashOf}), so a
570
+ * license for one tool covers no call of another. A license for bytes covers what the tool reads them as ({@link argsReadFrom}:
571
+ * the one recorded step a reading took to `runs`). Compared by the EXACT digest only: bytes outside the bindable domain have
572
+ * none and are covered by no license. */
573
+ export declare function licenseCovers(licensed: string | undefined, tool: string, runs: unknown): boolean;
572
574
  /**
573
575
  * THE judge of whether an approval can be bound to arguments, and the arguments it binds — asked wherever an approval is about to
574
576
  * be asked or adopted, and nowhere else: the ask resolver (its no-approver arm too) and the approval policy before anyone is asked,
@@ -1298,14 +1300,14 @@ export interface AskRequest {
1298
1300
  * bidi bit's two faces can.
1299
1301
  */
1300
1302
  readonly previewWithheld?: "oversize" | "unavailable";
1301
- /** Canonical digest of {@link args} as presented in THIS ask, computed by the engine's one
1302
- * `boundInputHashOf` — the same digest a durable park binds its checkpoint to, so an aggregating
1303
+ /** Canonical digest of the call's tool ({@link toolName}) and {@link args} as presented in THIS ask, computed by the engine's
1304
+ * one call binding (`exactBoundInputHashOf`) — the same digest a durable park binds its checkpoint to, so an aggregating
1303
1305
  * approver can reconcile a synchronous ask row against a parked checkpoint row for the same call
1304
- * by `(toolCallId, hash)` equality. RECONCILIATION metadata only, never adjudication input: it
1305
- * repeats for two asks over identical args, and an `updatedInput` edit round re-mints it over the
1306
- * edited args. Filled at the `resolveAsk` chokepoint (present for every wired-approver call, so a
1307
- * mint site added later is covered by construction); optional on the type because a deployment may
1308
- * invoke its approver function directly. */
1306
+ * by `(toolCallId, hash)` equality, and two calls of different tools over identical args under one id do not reconcile.
1307
+ * RECONCILIATION metadata only, never adjudication input: it repeats for two asks of one tool over identical args, and an
1308
+ * `updatedInput` edit round re-mints it over the edited args. Filled at the `resolveAsk` chokepoint (present for every
1309
+ * wired-approver call, so a mint site added later is covered by construction); optional on the type because a deployment
1310
+ * may invoke its approver function directly. */
1309
1311
  readonly boundInputHash?: string;
1310
1312
  /** A call to the engine's `Skill` tool: the hash of {@link boundGrants} — the digest a parked approval of the same card is judged by, so a live card reconciles against its parked row by `(toolCallId, boundGrantDigest)` and an answer is remembered by "this tool + this binding". Present exactly on that call (whoever asked, however the question was worded); every other card carries {@link boundGrantAbsence} instead; `message` renders the same lists narrowed to what releases in the leg's mode. Reconciliation metadata, never adjudication input. */
1311
1313
  readonly boundGrantDigest?: string;
@@ -2025,13 +2027,17 @@ export type ResolverArmResult = (Extract<ResolvedAsk, {
2025
2027
  }> & {
2026
2028
  settlement?: Settlement;
2027
2029
  bindingRefusal?: undefined;
2030
+ quotesQuestion?: undefined;
2028
2031
  })
2029
- /** `bindingRefusal`: the arm refused arguments no approval can be bound to — the record carries the sentence. */
2032
+ /** `bindingRefusal`: the arm refused arguments no approval can be bound to — the record carries the sentence. `quotesQuestion`:
2033
+ * the arm's sentence quotes the ask's question (`req.message`) whole, so the resolution may carry the literals that question
2034
+ * quotes ({@link quotingQuestion}; read by {@link resolveAskFor} alone, never on the resolution). */
2030
2035
  | (Extract<ResolvedAsk, {
2031
2036
  action: "deny";
2032
2037
  }> & {
2033
2038
  settlement: Settlement;
2034
2039
  bindingRefusal?: string;
2040
+ quotesQuestion?: true;
2035
2041
  });
2036
2042
  /**
2037
2043
  * The DIRECTIONAL format controls, as a closed set (see {@link AskRequest.hasBidiControls}):
@@ -2109,3 +2115,16 @@ onLateSettlement?: (late: {
2109
2115
  kind: "error";
2110
2116
  error: unknown;
2111
2117
  }) => void): Promise<ResolvedAsk>;
2118
+ /**
2119
+ * {@link resolveAsk} at an engine mint station, which also hands over the decision it ASKED (`asked`): when the arm that ran
2120
+ * quotes the question ({@link quotingQuestion}) and the question the request puts to the approver IS the sentence the engine
2121
+ * composed for `asked` ({@link engineSentenceOf}, byte for byte — a card that appended to it, or a layer that rewrote it, puts
2122
+ * another sentence there), the refusal's record carries the literals that sentence quotes. The list's only source is the record
2123
+ * of the station that composed the question; the request carries none. Not re-exported from `src/index.ts`.
2124
+ */
2125
+ export declare function resolveAskFor(req: AskRequest, onAsk: OnAsk | undefined, signal: AbortSignal | undefined, onLateSettlement: ((late: {
2126
+ kind: "approve";
2127
+ } | {
2128
+ kind: "error";
2129
+ error: unknown;
2130
+ }) => void) | undefined, asked: object | undefined): Promise<ResolvedAsk>;
@@ -4,7 +4,7 @@ import { argsReadFrom, carryArgsReadFrom, withArgsReading } from "./effective-pa
4
4
  import { editRewrittenSentence, readRejudge, rewriteChasedSentence } from "./rewrite-rejudge.js";
5
5
  import { brandPolicyAskClass } from "./ask-class.js";
6
6
  import { decisionAskClassesOf, headlessDenialMessage, joinAskReasons } from "./ask-origin.js";
7
- import { attest, attestationOf, isEngineAttestation, mergeAttestation, mintAttestation, withAttestation } from "./engine-attestation.js";
7
+ import { attest, attestationOf, engineSentenceOf, isEngineAttestation, mergeAttestation, mintAttestation, withAttestation } from "./engine-attestation.js";
8
8
  import { ownReadRootCandidate, readRootGrantSeat } from "./read-root-grant-screen.js";
9
9
  import { DECIDED_VIA, decidersNote, isDecidedVia, policyDeciderOf, settledByDecider } from "./gate-outcome.js";
10
10
  import { unjudgedAllowRefused } from "./real-approval.js";
@@ -16,7 +16,7 @@ import { readOnlyShellVerdict } from "./read-only-shell.js";
16
16
  import { DEFAULT_GATE_AWAIT_TIMEOUT_MS, withGateTimeout } from "./gate-bounded-await.js";
17
17
  import { protectivePathTargetOf, shellFaceToolNames } from "./tool-registry.js";
18
18
  import { heldBy } from "./tool-name-readings.js";
19
- import { bindableValueOf, boundInputHashOf, describeBindingFault, exactBoundInputHashOf } from "./canonical-json.js";
19
+ import { bindableValueOf, describeBindingFault, exactBoundInputHashOf } from "./canonical-json.js";
20
20
  import { delimitUntrusted, inlineUntrusted, REVIEWER_NOTE_MAX_BODY } from "./untrusted-text.js";
21
21
  import { describeRejectedValue } from "./tool-search-setting.js";
22
22
  import { egressText, egressThrownText } from "./untrusted-egress.js";
@@ -98,8 +98,8 @@ export const ASK_EVIDENCE_ABSENCE_VALUES = ["not_wired", "not_adjudicated", "una
98
98
  export function decisionText(d) {
99
99
  return d.message;
100
100
  }
101
- export function licenseCovers(licensed, runs) {
102
- return licensed !== undefined && (licensed === exactBoundInputHashOf(runs) || licensed === exactBoundInputHashOf(argsReadFrom(runs)));
101
+ export function licenseCovers(licensed, tool, runs) {
102
+ return licensed !== undefined && (licensed === exactBoundInputHashOf(tool, runs) || licensed === exactBoundInputHashOf(tool, argsReadFrom(runs)));
103
103
  }
104
104
  export function bindableArgsOf(toolName, args) {
105
105
  const bound = bindableValueOf(args);
@@ -118,7 +118,7 @@ export function bindingRefusalOf(toolName, args, fault) {
118
118
  }
119
119
  export function answeredFor(d, call, runs) {
120
120
  const record = attestationOf(d, call);
121
- return record?.settlement !== undefined && licenseCovers(record.inputDigest, runs);
121
+ return record?.settlement !== undefined && licenseCovers(record.inputDigest, call.toolName, runs);
122
122
  }
123
123
  export const REFUSES_NO_WHOLE_TOOL = () => false;
124
124
  export const TOOL_TABLE_VIEW_READ = "tool-table-view";
@@ -499,9 +499,9 @@ export function createApprovalPolicy(opts) {
499
499
  if (!bound.ok)
500
500
  return attestOver(undefined)({ action: "deny", message: bound.refusal }, settledByNobody("presentation_failed"), bound.refusal);
501
501
  const shown = { value: structuredClone(bound.value) };
502
- const askedDigest = exactBoundInputHashOf(shown.value);
502
+ const askedDigest = exactBoundInputHashOf(req.toolName, shown.value);
503
503
  const attest = attestOver(askedDigest);
504
- const heldWhileWaiting = () => licenseCovers(askedDigest, req.args);
504
+ const heldWhileWaiting = () => licenseCovers(askedDigest, req.toolName, req.args);
505
505
  const changedWhilePending = () => attest({
506
506
  action: "deny",
507
507
  message: `the arguments of "${req.toolName}" changed while its approval was pending — denied fail-closed ` +
@@ -1057,6 +1057,7 @@ export function policyRefusalMessage(toolName, askMessage, note, decidedVia) {
1057
1057
  `was blocked and why you needed it, then continue with the parts of the task that do not require approval.`;
1058
1058
  return note === undefined ? body : `${body}\nPolicy note:\n${delimitUntrusted("policy note", note, REVIEWER_NOTE_MAX_BODY)}`;
1059
1059
  }
1060
+ const quotingQuestion = Object.freeze({ quotesQuestion: true });
1060
1061
  export const BIDI_CONTROL_CHARS = "\\u061C\\u200E\\u200F\\u202A-\\u202E\\u2066-\\u2069";
1061
1062
  const BIDI_CONTROL_RE = new RegExp(`[${BIDI_CONTROL_CHARS}]`, "u");
1062
1063
  const BIDI_SCAN_MAX_NODES = 5_000;
@@ -1131,12 +1132,17 @@ export function carriesBidiControls(value, limits) {
1131
1132
  }
1132
1133
  }
1133
1134
  export async function resolveAsk(req, onAsk, signal, onLateSettlement) {
1134
- const askedDigest = exactBoundInputHashOf(req.args);
1135
- const { settlement, bindingRefusal, ...r } = await resolveAskArms(req, onAsk, signal, onLateSettlement);
1135
+ return resolveAskFor(req, onAsk, signal, onLateSettlement, undefined);
1136
+ }
1137
+ export async function resolveAskFor(req, onAsk, signal, onLateSettlement, asked) {
1138
+ const askedDigest = exactBoundInputHashOf(req.toolName, req.args);
1139
+ const question = asked !== undefined ? engineSentenceOf(asked, req) : undefined;
1140
+ const { settlement, bindingRefusal, quotesQuestion, ...r } = await resolveAskArms(req, onAsk, signal, onLateSettlement);
1136
1141
  if (settlement === undefined)
1137
1142
  return r;
1138
- const licensedDigest = r.action === "allow" && r.updatedInput !== undefined ? exactBoundInputHashOf(r.updatedInput) : r.presentedInput !== undefined ? exactBoundInputHashOf(r.presentedInput) : askedDigest;
1139
- return attest(r, req, { settlement, ...(req.origin !== undefined ? { origin: req.origin } : {}), ...(req.classes !== undefined ? { classes: req.classes } : {}), ...(licensedDigest !== undefined ? { inputDigest: licensedDigest } : {}), ...(bindingRefusal !== undefined ? { bindingRefusal } : {}) });
1143
+ const echoed = quotesQuestion === true && question?.echoed !== undefined && req.message === question.text && r.message !== undefined ? question.echoed : undefined;
1144
+ const licensedDigest = r.action === "allow" && r.updatedInput !== undefined ? exactBoundInputHashOf(req.toolName, r.updatedInput) : r.presentedInput !== undefined ? exactBoundInputHashOf(req.toolName, r.presentedInput) : askedDigest;
1145
+ return attest(r, req, { settlement, ...(req.origin !== undefined ? { origin: req.origin } : {}), ...(req.classes !== undefined ? { classes: req.classes } : {}), ...(licensedDigest !== undefined ? { inputDigest: licensedDigest } : {}), ...(bindingRefusal !== undefined ? { bindingRefusal } : {}), ...(echoed !== undefined ? { sentence: { text: r.message, echoed } } : {}) });
1140
1146
  }
1141
1147
  function raceAskWaitAgainstSignal(wait, signal) {
1142
1148
  const settledWait = wait.then((value) => ({ tag: "value", value }), (error) => ({ tag: "threw", error }));
@@ -1267,7 +1273,7 @@ function readApproverOutcomeObject(ok, toolName, editLane) {
1267
1273
  async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
1268
1274
  if (onAsk === "allow") {
1269
1275
  if (req.requiresRealApproval === true)
1270
- return unjudgedAllowRefused(req, "blanket");
1276
+ return { ...unjudgedAllowRefused(req, "blanket"), ...quotingQuestion };
1271
1277
  return { action: "allow", decisionReason: "mode" };
1272
1278
  }
1273
1279
  if (onAsk === undefined || onAsk === "deny") {
@@ -1277,7 +1283,7 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
1277
1283
  message: bound.ok ? headlessDenialMessage(req.toolName, req.message) : bound.refusal,
1278
1284
  decisionReason: "mode",
1279
1285
  settlement: settledByNobody("no_approver"),
1280
- ...(bound.ok ? {} : { bindingRefusal: bound.refusal }),
1286
+ ...(bound.ok ? quotingQuestion : { bindingRefusal: bound.refusal }),
1281
1287
  };
1282
1288
  }
1283
1289
  if (signal?.aborted) {
@@ -1290,11 +1296,12 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
1290
1296
  let ok;
1291
1297
  try {
1292
1298
  const approverView = { value: structuredClone(presented.value) };
1299
+ const reconciliationHash = exactBoundInputHashOf(req.toolName, presented.value);
1293
1300
  const bidi = carriesBidiControls(presented.value) || carriesBidiControls(req.preview);
1294
- const { hasBidiControls: _carried, ...bare } = req;
1301
+ const { hasBidiControls: _carried, boundInputHash: _claimed, ...bare } = req;
1295
1302
  const wait = Promise.resolve(onAsk({
1296
1303
  ...bare,
1297
- boundInputHash: boundInputHashOf(presented.value),
1304
+ ...(reconciliationHash !== undefined ? { boundInputHash: reconciliationHash } : {}),
1298
1305
  args: approverView.value,
1299
1306
  ...(bidi ? { hasBidiControls: true } : {}),
1300
1307
  ...(offered !== undefined ? { readRootCandidate: { ...offered } } : {}),
@@ -1309,6 +1316,7 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
1309
1316
  `elapsed with no answer; auto-denied: ${req.message}`,
1310
1317
  decisionReason: "mode",
1311
1318
  settlement: { kind: "denial_limit_window_expired", who: { party: "engine", window: "denial_limit" }, when: Date.now() },
1319
+ ...quotingQuestion,
1312
1320
  };
1313
1321
  }
1314
1322
  if (raced.tag === "aborted") {
@@ -1338,6 +1346,7 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
1338
1346
  decisionReason: "mode",
1339
1347
  settlement: settledByNobody("approver_unavailable"),
1340
1348
  approverUnavailable: true,
1349
+ ...quotingQuestion,
1341
1350
  };
1342
1351
  }
1343
1352
  if (typeof ok === "object" && ok !== null) {
@@ -1345,7 +1354,7 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
1345
1354
  if (reading.kind === "refused")
1346
1355
  return { action: "deny", message: reading.message, decisionReason: "mode", settlement: reading.settlement, ...(reading.binding === true ? { bindingRefusal: reading.message } : {}) };
1347
1356
  if (reading.kind === "allow" && reading.settlement.who.party === "policy" && req.requiresRealApproval === true) {
1348
- return { ...unjudgedAllowRefused(req, "policy"), ...readRootGrantSeat(reading.grant, offered, false) };
1357
+ return { ...unjudgedAllowRefused(req, "policy"), ...quotingQuestion, ...readRootGrantSeat(reading.grant, offered, false) };
1349
1358
  }
1350
1359
  const grantSeat = readRootGrantSeat(reading.grant, offered, reading.kind === "allow");
1351
1360
  if (reading.kind === "deny") {
@@ -1358,6 +1367,7 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
1358
1367
  : humanRefusalMessage(req, reading.note),
1359
1368
  decisionReason: "mode",
1360
1369
  settlement: reading.settlement,
1370
+ ...quotingQuestion,
1361
1371
  ...grantSeat,
1362
1372
  };
1363
1373
  }
@@ -1376,5 +1386,5 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
1376
1386
  settlement: settledByNobody("approver_contract"),
1377
1387
  };
1378
1388
  }
1379
- return { action: "deny", message: humanRefusalMessage(req), decisionReason: "mode", settlement: settledByDecider("person", "refused", undefined) };
1389
+ return { action: "deny", message: humanRefusalMessage(req), decisionReason: "mode", settlement: settledByDecider("person", "refused", undefined), ...quotingQuestion };
1380
1390
  }
@@ -141,6 +141,26 @@ export interface ToolResultStore {
141
141
  reap?(now: number, opts?: {
142
142
  maxAgeMs?: number;
143
143
  }): Promise<number> | number;
144
+ /**
145
+ * Delete the entries stored with NO owner record that were stored before `cutoffMs` (epoch ms) — the orphan-tool-results domain's
146
+ * leg ({@link import("./retention.js").RETENTION_CASCADE}). No session can claim such an entry (written without provenance, or a
147
+ * winning write interrupted between its content and its owner record), so no session deletion ever reaches it; the cutoff is the
148
+ * one bound it has. Answers how many entries it removed.
149
+ *
150
+ * Rules every implementation follows:
151
+ * - **an owned entry is never this verb's**, however old — its session's deletion is its way out;
152
+ * - **an owner record that is present but unreadable is not "no owner"**: that entry is kept, because a guess would destroy
153
+ * another session's output (the same posture {@link deleteBySession} counts as `unattributable`);
154
+ * - **the bound is the call's**: a `cutoffMs` that is not a finite number is refused (`config.retention_policy_invalid`)
155
+ * before any entry is touched; no policy object is read;
156
+ * - whether a transcript still points at an unowned entry is the caller's to judge (it holds the transcripts); this verb
157
+ * judges the store's own two facts, the owner record and the write time;
158
+ * - **idempotent**, and an entry that disappears between enumeration and removal is honest absence.
159
+ *
160
+ * Optional: absent ⇒ unowned entries leave only through {@link reap}'s age bound, which does not consult ownership. A store
161
+ * that records no write time cannot age an entry and does not implement it (the in-memory store keeps none).
162
+ */
163
+ deleteUnattributable?(cutoffMs: number): Promise<number> | number;
144
164
  /**
145
165
  * The READ half of the same ownership coordinate {@link deleteBySession} erases by: every entry this store recorded as belonging to
146
166
  * `sessionId`, as the ref and the owner recorded at its winning write. Without it the offloaded results a session's transcript
@@ -16,6 +16,7 @@ import type { TaskSpec } from "./task-spec.js";
16
16
  import type { BackgroundChildEvent } from "./delegation-frames.js";
17
17
  import type { ModelRef } from "./model-seat.js";
18
18
  import type { ToolFamily, ToolHostTarget, ToolPathTarget, ToolRenderHints, ToolRuleFace } from "./tool-face.js";
19
+ import type { MemoryGovernanceDocs } from "./memory-engine/types.js";
19
20
  /**
20
21
  * Side-effect class of a tool. Used by wake/resume reconciliation: when a call was interrupted
21
22
  * before its result was recorded, the outcome is unknown, so core must decide whether re-doing it
@@ -672,6 +673,14 @@ export interface NestedUsageAccum {
672
673
  * carry knownness alongside the number it qualifies. */
673
674
  anyUnpriced: boolean;
674
675
  }
676
+ /** {@link ToolExecuteContext.delegationSettlement}'s answer: where a delegation's settlement rows are kept (the WRITE
677
+ * plane's governance store), that plane's control-plane directory (the pollution marker and the hold custody files a
678
+ * settled delegation's effects reach), and the session whose rows they are. */
679
+ export interface DelegationSettlementSeat {
680
+ readonly governance: MemoryGovernanceDocs;
681
+ readonly controlDir: string;
682
+ readonly sessionId: string;
683
+ }
675
684
  export interface ToolExecuteContext {
676
685
  toolCallId: string;
677
686
  signal?: AbortSignal;
@@ -700,6 +709,10 @@ export interface ToolExecuteContext {
700
709
  * fixed point `ctx.rootSessionId ?? ctx.sessionId` at every spawn). Absent for a top-level run
701
710
  * (its OWN sessionId is the root). */
702
711
  rootSessionId?: string;
712
+ /** The occupant (`SessionMetadata.incarnation`) of the session the fixed point above names (`rootSessionId ?? sessionId`)
713
+ * as this tree holds it — Runner-filled, trusted. A spawn hands it down beside the root anchor
714
+ * (`RunInternals.rootSessionIncarnation`); absent = unknown (a row minted before occupants, a revival's tree). */
715
+ rootSessionIncarnation?: string;
703
716
  /** The run's delegation tree owner seat (`RunInternals.delegationOwner`, Runner-filled): a delegation tool reads the tree's owner
704
717
  * through it for the rows it creates for a child (a placed transcript, a fork, a park's durable row) and threads it into a spawned
705
718
  * child's internals by reference — never into a revival's. */
@@ -817,18 +830,31 @@ export interface ToolExecuteContext {
817
830
  * session backing, the child run fails LOUD ("refusing a silent fresh run") instead of silently
818
831
  * running an empty session under the forked id. Split-runner deployments must share session backing
819
832
  * (same store instance or same durable backend) for fork to complete.
820
- */
821
- hostSessionFork?: () => Promise<{
833
+ *
834
+ * The one argument is the store's own fork placement ({@link import("./session.js").SessionStore.fork}'s `opts`): a background
835
+ * fork's delegation tuple, laid down by the branch's creating write. It names no owner and no source — those stay bound here. It
836
+ * is handed on only when the host store declares the partition (the store creating the branch is the one that opts in); otherwise
837
+ * the branch is an ordinary fork.
838
+ */
839
+ hostSessionFork?: (opts?: {
840
+ placement?: Omit<import("./session.js").SessionPlacement, "owner">;
841
+ }) => Promise<{
822
842
  sessionId: string;
823
843
  release: () => Promise<void>;
824
844
  } | null>;
825
845
  /**
826
- * The RUNNING task's effective working root (worktree-aware), Runner-filled — read-only context a
827
- * delegation tool threads into its child's trusted internals so the child's env can inherit the
828
- * parent's cwd (CC parity: a Task sub-agent works in the main session's directory). Undefined when
829
- * the tool runs outside a Runner task.
846
+ * The RUNNING task's WRITE LOCATION (worktree-aware: the EnterWorktree tree while one is active, the task root otherwise —
847
+ * `currentCheckoutOf`, read at the call), Runner-filled — read-only context a delegation tool threads into its child's
848
+ * trusted internals so the child's env can inherit where the parent works (CC parity: a Task sub-agent works in the main
849
+ * session's directory). Undefined when the tool runs outside a Runner task.
830
850
  */
831
851
  parentCwd?: string;
852
+ /**
853
+ * The RUNNING task's own task root, Runner-filled beside {@link parentCwd}: the checkout a delegated child placed in "the
854
+ * caller's tree" would be writing into, whichever tree the caller has switched to inside it — what the child's placement
855
+ * judgment compares against (`RunInternals.callerRoot`). Absent on a ctx a caller outside the Runner built: its root is then where it works ({@link parentCwd}).
856
+ */
857
+ callerRoot?: string;
832
858
  /**
833
859
  * The RUNNING task's own placement target (Runner-filled, read-only, never a model argument): what its execution
834
860
  * environment reported as its workspace settled. A delegation tool hands it, as is, to every agent it spawns or wakes
@@ -1226,19 +1252,16 @@ export interface ToolExecuteContext {
1226
1252
  */
1227
1253
  delegationProvenanceForChildren?: () => import("./memory-engine/delegation-provenance.js").DelegationContentSafety | undefined;
1228
1254
  /**
1229
- * design/336 §3.3 — the delegation-settlement account's coordinates (the WRITE plane's memory
1230
- * control dir + this session's id), Runner-filled when the run mounts a memory session under
1231
- * `memoryProvenance: "carry"`. A delegation tool's BACKGROUND lane writes its launch write-ahead
1232
- * (pending row BEFORE registration and invoke) and its terminal settle through these — as pure
1233
- * data, because the terminal observation can run after this task leg returned and must rebuild
1234
- * its write handle from the coordinates alone. Undefined ⇒ no settlement account (memory-less
1235
- * run, or `"off"`): the background lane launches without rows, the pre-336 accepted-cost shape.
1236
- * Same trust posture as {@link delegationProvenanceForChildren}: never a model/tool argument.
1237
- */
1238
- delegationSettlement?: () => {
1239
- controlDir: string;
1240
- sessionId: string;
1241
- } | undefined;
1255
+ * design/336 §3.3 — the delegation-settlement account's coordinates (the WRITE plane's governance
1256
+ * store + its memory control dir + this session's id), Runner-filled when the run mounts a memory
1257
+ * session under `memoryProvenance: "carry"`. A delegation tool's BACKGROUND lane writes its launch
1258
+ * write-ahead (pending row BEFORE registration and invoke) and its terminal settle through these —
1259
+ * never through a live engine or session, because the terminal observation can run after this task
1260
+ * leg returned. Undefined ⇒ no settlement account (memory-less run, or `"off"`): the background lane
1261
+ * launches without rows, the pre-336 accepted-cost shape. Same trust posture as
1262
+ * {@link delegationProvenanceForChildren}: never a model/tool argument.
1263
+ */
1264
+ delegationSettlement?: () => DelegationSettlementSeat | undefined;
1242
1265
  /**
1243
1266
  * RB-201 FO-3 (form-one audit) — the auto-mode classifier decider ARMED
1244
1267
  * for THIS task (auto-mode intent ∧ `RunnerDeps.autoMode` present ∧ `RuntimeCaps.autoMode !== false`
@@ -762,8 +762,9 @@ export type TraceEvent = {
762
762
  taskId: string;
763
763
  ts: number;
764
764
  } | {
765
- /** MF-18 修① — a manual /compact was processed while compaction is DISABLED by the
766
- * task spec (`compaction.enabled:false`): the request can never be honored this run. */
765
+ /** MF-18 修① — a manual /compact was processed while requested compaction is switched OFF
766
+ * (the `manualCompact` seat is `false`, the task's or the deployment's): the request is answered
767
+ * without a pass; the `autoCompact` seat does not reach it. */
767
768
  kind: "compaction.disabled";
768
769
  version: 1;
769
770
  taskId: string;
@@ -15,7 +15,7 @@ export type { ModelRef, ModelRole, RoleSpec, ModelRoles, Brain } from "./model-s
15
15
  export { MODEL_ROLES } from "./model-seat.js";
16
16
  export type { StaleToolResultOffloadOptions, ImageInput, TaskSpec, ShellGateDoctrine, UserAttachment } from "./task-spec.js";
17
17
  export type { PermissionMode } from "./ask-origin.js";
18
- export type { ToolEffect, ToolContentOrigin, ReversibilityVerdict, ReadRootGrantCandidate, ToolSpec, ToolReturn, NestedUsage, NestedUsageAccum, ToolExecuteContext } from "./tool-spec.js";
18
+ export type { ToolEffect, ToolContentOrigin, ReversibilityVerdict, ReadRootGrantCandidate, ToolSpec, ToolReturn, NestedUsage, NestedUsageAccum, ToolExecuteContext, DelegationSettlementSeat } from "./tool-spec.js";
19
19
  export type { BeforeWriteRequest, BeforeWriteResult, BeforeWriteHook, TrackEditRequest, TrackEditResult, TrackFileEditHook, FileEditedNotice, FileEditedHook, HandsBandOptions } from "./hands-band.js";
20
20
  export type { AgentDefinition, SkillSpec } from "./agent-definition.js";
21
21
  export type { McpServerSpec, A2aServerSpec, McpElicitRequest, McpElicitResponse, OnElicit, McpRevocationLedger, McpMountIdentity, McpTransportKind, DeclarationFault, DeclarationPathRule, DeclarationRead, ToolAxesRead, ToolAxesSurface } from "./mcp-server-spec.js";
@@ -1,6 +1,16 @@
1
- import { type RedactionReport } from "./redaction-passes.js";
2
- export type { RedactionFinding, RedactionReport, RedactionConfidence, RedactionSource, SummarizableFinding, } from "./redaction-passes.js";
3
- export { summarizeRedactions } from "./redaction-passes.js";
1
+ import { type RedactionReport, type SummarizableFinding } from "@sema-agent/primitives";
2
+ export type { RedactionFinding, RedactionReport, RedactionConfidence, RedactionSource, SummarizableFinding } from "@sema-agent/primitives";
3
+ /** Render findings as ONE human-readable line, e.g. `"3 redactions: prefixed-token (high) x1, url (medium) x1, fs-path (low)
4
+ * x1"`, so an upper layer can declare to its consumer how much was removed and how confidently.
5
+ *
6
+ * PURE, and deliberately only that: it reads the array, returns a string, and injects nothing anywhere. Attaching this
7
+ * line to an output is the caller's decision — a redaction pipeline that silently appended prose to the very text it was
8
+ * asked to bound would break both the size contract (`boundedString`) and the byte-invariance the whole channel is built
9
+ * on.
10
+ *
11
+ * Grouping is by kind AND confidence together: collapsing on kind alone would report whichever confidence happened to
12
+ * arrive first for the rest of that group, a silent mis-statement of how sure the removals were. */
13
+ export declare function summarizeRedactions(findings: readonly SummarizableFinding[]): string;
4
14
  /**
5
15
  * Every exit that redacts — into a model's context, a host's event or error lane, a log line, a person's screen — does it
6
16
  * with ONE pass, its tier's, and nothing else redacts: a text through {@link egressText}, a thrown value's text through
@@ -27,7 +37,8 @@ declare const EGRESS_TIER: unique symbol;
27
37
  export type Egress<T extends EgressTier> = string & {
28
38
  readonly [EGRESS_TIER]: T;
29
39
  };
30
- /** Tier `tier`'s one pass over a text. */
40
+ /** Tier `tier`'s one pass over a text. A report's `preexistingMarkers` counts the engine's own marks ({@link REDACTION_MARKS})
41
+ * already in the text. */
31
42
  export declare function egressText<T extends EgressTier>(tier: T, text: string, report?: RedactionReport): Egress<T>;
32
43
  /** The text a thrown value reads as (`thrownText`), through tier `tier`'s pass: the one form a thrown value's words take
33
44
  * on their way out of the engine. */
@@ -1,34 +1,35 @@
1
1
  import { types } from "node:util";
2
+ import { isSensitiveRecordKey, renderSecrets, URL_OF_ANY_SCHEME } from "@sema-agent/primitives";
2
3
  import { delimitUntrusted, inlineUntrusted, neutralizeForFence } from "./untrusted-text.js";
3
- import { egressPasses, runRedactionPasses } from "./redaction-passes.js";
4
- import { REDACTION_MARK, REDACTION_MARKS, redactionMarkerSpans } from "./redaction-marks.js";
5
- import { CREDENTIAL_VOCABULARY, egressPassGroups, isSensitiveRecordKey, URI_SCHEME_SOURCE } from "./credential-vocabulary.js";
4
+ import { REDACTION_MARK, REDACTION_MARKS, REDACTION_NOTATION, redactionMarkerSpans } from "./redaction-marks.js";
6
5
  import { isErrorLike, readMember, thrownText } from "./thrown-value.js";
7
6
  import { sliceHeadSafe } from "./surrogate-safe-slice.js";
8
- export { summarizeRedactions } from "./redaction-passes.js";
9
- const URL_OF_ANY_PROTOCOL = new RegExp(String.raw `${URI_SCHEME_SOURCE}:\/\/[^\s"'\`]+`, "gi");
10
- const BARE_USERNAME_MAX_LEN = 20;
11
- function redactUserinfo(scheme, userinfoWithAt) {
12
- const userinfo = userinfoWithAt.slice(0, -1);
13
- if (CREDENTIAL_VOCABULARY.policy.urlUserinfo === "whole" || userinfo.includes("@"))
14
- return `${scheme}${REDACTION_MARKS.credentials}@`;
15
- const colonIdx = userinfo.indexOf(":");
16
- if (colonIdx === -1) {
17
- return userinfo.length >= BARE_USERNAME_MAX_LEN ? `${scheme}${REDACTION_MARKS.credentials}@` : `${scheme}${userinfo}@`;
7
+ export function summarizeRedactions(findings) {
8
+ if (findings.length === 0)
9
+ return "no redactions";
10
+ const counts = new Map();
11
+ for (const f of findings) {
12
+ const label = `${f.kind} (${f.confidence})`;
13
+ counts.set(label, (counts.get(label) ?? 0) + 1);
18
14
  }
19
- return `${scheme}${userinfo.slice(0, colonIdx)}:${REDACTION_MARKS.credentials}@`;
15
+ const parts = [...counts].map(([label, n]) => `${label} x${n}`);
16
+ return `${findings.length} redaction${findings.length === 1 ? "" : "s"}: ${parts.join(", ")}`;
20
17
  }
21
- const SECRET_TIER_PASSES = egressPasses(egressPassGroups(CREDENTIAL_VOCABULARY), {
22
- "url-credentials": (_m, scheme, userinfo) => redactUserinfo(scheme, userinfo),
18
+ const EGRESS_POLICY = Object.freeze({
19
+ grade: "wide",
20
+ readings: Object.freeze([Object.freeze({ kind: "raw" }), Object.freeze({ kind: "format-free" })]),
21
+ urlUserinfo: "keep-username",
22
+ onUnresolvedReading: "secret",
23
23
  });
24
- const HOST_LEAK_PASSES = [
25
- ...SECRET_TIER_PASSES,
26
- { kind: "url", confidence: "medium", marker: REDACTION_MARKS.url, source: "untrusted-egress", re: URL_OF_ANY_PROTOCOL, replace: REDACTION_MARKS.url },
24
+ const HOST_LEAK_PASSES = Object.freeze([
25
+ { kind: "url", confidence: "medium", marker: REDACTION_MARKS.url, source: "untrusted-egress", re: new RegExp(URL_OF_ANY_SCHEME.source, URL_OF_ANY_SCHEME.flags), replace: REDACTION_MARKS.url },
27
26
  { kind: "fs-path", confidence: "low", marker: REDACTION_MARKS.path, source: "untrusted-egress", re: /(?:\/[A-Za-z0-9_.-]+){2,}/g, replace: REDACTION_MARKS.path },
28
- ];
29
- const TIER_PASSES = { "same-principal": SECRET_TIER_PASSES, human: HOST_LEAK_PASSES };
27
+ ]);
28
+ const TIER_PASSES = { "same-principal": Object.freeze([]), human: HOST_LEAK_PASSES };
30
29
  export function egressText(tier, text, report) {
31
- return runRedactionPasses(text, TIER_PASSES[tier], report);
30
+ if (report !== undefined && report.preexistingMarkers === undefined)
31
+ report.preexistingMarkers = redactionMarkerSpans(text).length;
32
+ return renderSecrets(text, EGRESS_POLICY, REDACTION_NOTATION, { passes: TIER_PASSES[tier], report });
32
33
  }
33
34
  export function egressThrownText(tier, err) {
34
35
  return egressText(tier, thrownText(err));
@@ -137,6 +137,16 @@ export interface WorkflowJournalStore {
137
137
  * returns its API route (cloud form). `undefined`/absent ⇒ the completion notification's diagnostics
138
138
  * line names no journal (the record behind its ref still carries every agent's row). Engine-facing string, never parsed. */
139
139
  locator?(runId: string, scope: string): string | undefined;
140
+ /**
141
+ * Erase `runId`'s journal IF its recorded scope === `scope` (the {@link load} wall: a cross-scope call erases nothing) — the
142
+ * session-tree cascade's leg for a terminal run its session started ({@link import("./retention.js").RETENTION_CASCADE}).
143
+ * `true` = this call removed it; `false` = there was none under that scope. Idempotent; a store fault throws (a deletion
144
+ * face that cannot delete is loud). A later `load` of the id answers empty; the cascade deletes the run's record with it, and a
145
+ * resume from a run whose record is gone is refused before the load (`workflow.park_truth_unreadable`, `record_missing`). A resume
146
+ * claim naming the id holds ids only and is not this verb's (the claim's own release and sweep govern it). OPTIONAL: absent ⇒ this store's journals outlive their runs,
147
+ * and the deployment owns that gap.
148
+ */
149
+ deleteRun?(runId: string, scope: string): Promise<boolean>;
140
150
  /**
141
151
  * ADMISSION for a resume, so two concurrent
142
152
  * `resumeFromRunId` legs off ONE source run cannot fork its execution.
@@ -308,6 +318,7 @@ export declare class InMemoryWorkflowJournalStore implements WorkflowJournalStor
308
318
  /** Release ONLY a claim `newRunId` still holds (a missing/foreign/already-taken-over claim is a
309
319
  * no-op, never an error — matches the file store's contract). */
310
320
  releaseResumeClaim(input: ResumeClaimArgs): Promise<void>;
321
+ deleteRun(runId: string, scope: string): Promise<boolean>;
311
322
  load(runId: string, scope: string): Promise<WorkflowJournalEntry[]>;
312
323
  append(runId: string, scope: string, entry: WorkflowJournalEntry): Promise<void>;
313
324
  }
@@ -144,6 +144,13 @@ export class InMemoryWorkflowJournalStore {
144
144
  if (existing !== undefined && existing.holder === input.newRunId)
145
145
  table.delete(input.sourceRunId);
146
146
  }
147
+ async deleteRun(runId, scope) {
148
+ const rec = this.runs.get(runId);
149
+ if (!rec || rec.scope !== scope)
150
+ return false;
151
+ this.runs.delete(runId);
152
+ return true;
153
+ }
147
154
  async load(runId, scope) {
148
155
  const rec = this.runs.get(runId);
149
156
  if (!rec || rec.scope !== scope)
@@ -197,6 +197,14 @@ export interface WorkflowRunStore {
197
197
  maxAgeMs?: number;
198
198
  keep?: number;
199
199
  }): Promise<number>;
200
+ /**
201
+ * Delete the TERMINAL runs in `scope` whose `originatingSessionId` is `sessionId` (strict equality, the
202
+ * {@link listByScope} `session` filter's) — the session-tree cascade's leg ({@link import("./retention.js").RETENTION_CASCADE}).
203
+ * A running run is never deleted (it is a live reference: the cascade does not delete its session's tree). Answers the ids it
204
+ * deleted; idempotent (a repeat answers `[]`); a store fault throws. OPTIONAL: absent ⇒ this store's runs outlive the session
205
+ * that started them, and the deployment owns that gap.
206
+ */
207
+ deleteBySession?(sessionId: string, scope: string): Promise<string[]>;
200
208
  }
201
209
  /**
202
210
  * REF-A5 — THE optimistic-concurrency guard for {@link WorkflowRunStore.update}, shared by every backend:
@@ -236,6 +244,7 @@ export declare class InMemoryWorkflowRunStore implements WorkflowRunStore {
236
244
  maxAgeMs?: number;
237
245
  keep?: number;
238
246
  }): Promise<number>;
247
+ deleteBySession(sessionId: string, scope: string): Promise<string[]>;
239
248
  /** Test/inspection helper: number of stored runs. */
240
249
  get size(): number;
241
250
  }
@@ -97,6 +97,12 @@ export class InMemoryWorkflowRunStore {
97
97
  this.runs.delete(id);
98
98
  return doomed.size;
99
99
  }
100
+ async deleteBySession(sessionId, scope) {
101
+ const doomed = [...this.runs.values()].filter((r) => r.scope === scope && r.originatingSessionId === sessionId && isTerminalWorkflowStatus(r.status)).map((r) => r.id);
102
+ for (const id of doomed)
103
+ this.runs.delete(id);
104
+ return doomed;
105
+ }
100
106
  get size() {
101
107
  return this.runs.size;
102
108
  }