@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
@@ -196,7 +196,8 @@ export async function prepareHandsMount(input) {
196
196
  const handsReadOnly = spec.handsReadOnly === true;
197
197
  backgroundTaskToolsActive = handsIncludeShell && !handsReadOnly && hasBackgroundShell(executionEnv);
198
198
  const shellFaceHere = [...predictMountedToolNames(new Set(backgroundTaskToolsActive ? ["hands", "backgroundTasks"] : ["hands"]))].filter(isShellFaceToolName);
199
- wsSnapshot = resume !== undefined || !(handsIncludeShell && !handsReadOnly) ? undefined : await session.getWorkspaceState().catch(() => undefined);
199
+ const checkpointTracked = resume?.seed.handsCwd !== undefined;
200
+ wsSnapshot = checkpointTracked || !(handsIncludeShell && !handsReadOnly) ? undefined : await session.getWorkspaceState().catch(() => undefined);
200
201
  rebaseWsPath = (p) => (wsSnapshot === undefined || wsSnapshot.taskRoot === rootCanonical ? p : rebaseWorkspacePath(p, wsSnapshot.taskRoot, rootCanonical));
201
202
  if (handsIncludeShell && !handsReadOnly) {
202
203
  handsCwdRef = { current: rootCanonical };
@@ -207,7 +208,7 @@ export async function prepareHandsMount(input) {
207
208
  workspaceStateSettle = {
208
209
  rootCanonical,
209
210
  restoredHandsCwd: handsCwdRef.current !== rootCanonical ? handsCwdRef.current : undefined,
210
- ...(resume !== undefined ? { baselineUnknown: true } : {}),
211
+ ...(resume !== undefined && wsSnapshot === undefined ? { baselineUnknown: true } : {}),
211
212
  };
212
213
  }
213
214
  const seedReadFaceSection = resume?.seed.readFace;
@@ -226,7 +227,7 @@ export async function prepareHandsMount(input) {
226
227
  const tables = (pathTables = await input.personRows.attachTables(judgedRunTables));
227
228
  readDenyMatcher = tables.readDeny;
228
229
  runReadFloor = readFloorSeat(tables.readDeny);
229
- readRoots = readRootsOver({ own: () => [...additionalRootsCanonical, ...additionalReadRootsCanonical], tables, ready: input.personRows.tablesReady, store: () => artifactStoreRef.current,
230
+ readRoots = readRootsOver({ own: () => [...(input.writeLocation() === rootCanonical ? [] : [input.writeLocation()]), ...additionalRootsCanonical, ...additionalReadRootsCanonical], tables, ready: input.personRows.tablesReady, store: () => artifactStoreRef.current,
230
231
  onHeld: (entry, store) => emitTrace(deps.tracer, () => ({ kind: "config.additional_directory_skipped", version: 1, taskId: hostTaskId, entry, field: "persistedReadRule", reason: `admits_artifact_store: the local artifact store ${store} lies inside it or it inside the store — the Artifact tool's ledger and stored files stay outside every root the file tools reach`, ts: Date.now() })) });
231
232
  readDenyBuiltinTiersActive = activeReadDenyBuiltinTiers(readDenyBuiltinCfg);
232
233
  readDenyAdditionsNormalized = compileReadDeny(readDenyAdditions, "readDenyPatterns", { tiers: [] }).entries;
@@ -330,7 +331,7 @@ export async function prepareHandsMount(input) {
330
331
  seatOf: () => (handsReadOnly ? "readonly" : "full_shell"),
331
332
  boundaryOf: (_tool, _cwd, toolCallId) => readonlyBoundary(toolCallId) ?? shellReadBoundary(toolCallId), rootsCanonical: true,
332
333
  homeViews: tables.readDeny.homeViews,
333
- onAdmissionRefused: (toolCallId) => void input.toolOccurrences.refuse(toolCallId, "read_boundary"),
334
+ onAdmissionRefused: (toolCallId, echoed) => void input.toolOccurrences.refuse(toolCallId, "read_boundary", echoed !== undefined ? { echoed } : undefined),
334
335
  });
335
336
  }
336
337
  if (!handsReadOnly) {
@@ -43,7 +43,7 @@ import type { LockedPreflight } from "../locked-config.js";
43
43
  import type { OwnOrgAdmissionVerdict } from "../memory-admission.js";
44
44
  import type { DelegationContentSafety } from "../memory-engine/delegation-provenance.js";
45
45
  import type { SessionPermissionRules } from "../session-policy-store.js";
46
- import type { SessionStore } from "../session.js";
46
+ import { type SessionStore } from "../session.js";
47
47
  import { type PlacementTarget } from "../remote-env.js";
48
48
  import { type OnAsk, type ToolPolicy } from "../tool-policy.js";
49
49
  import type { PathRuleBases } from "../permission-rule-model.js";
@@ -51,6 +51,7 @@ import type { PermissionMode, RunnerDeps, RuntimeCaps, ShellGateDoctrine, TaskEv
51
51
  import { PermissionModeController } from "../mode-policy.js";
52
52
  import { type SkillGrantTable } from "../skill-grant.js";
53
53
  import type { InheritedGate, Prepared, PrepareResume, RunInternals, StopForDenialLimit, ToolFaceSnapshot, WriteFaceSeat } from "./contracts.js";
54
+ import type { DelegationSettlementSeat } from "../tool-spec.js";
54
55
  export interface PrepareInheritedGateInput {
55
56
  /** borrowed-readonly — the REBOUND spec. Read: `shellGate` (the own doctrine the chain fold tightens), `durableApproval`
56
57
  * (the mandate tests + the children's copy), `onQuestion` (the frozen question seat), `handsReadOnly` / `interactiveTools`
@@ -79,21 +80,25 @@ export interface PrepareInheritedGateInput {
79
80
  /** borrowed-readonly — the trusted spawn-side channel: `inheritedGate` (the LIVE half of the chain fold), `ownOrgAdmissionRef`
80
81
  * (the same-session continuation's freeze), `delegationProvenance` (the F-012 stamp), and the identity / peer / notification
81
82
  * seats the ctx enrichment forwards. Never mutated. */
82
- internals: Pick<RunInternals, "inheritedGate" | "sessionModeSeats" | "ownOrgAdmissionRef" | "delegationProvenance" | "memoryCaptureAncestors" | "parentTaskId" | "parentSessionId" | "rootSessionId" | "placementRoot" | "explicitAgentName" | "peerSelfRef" | "peerInboundChainRef" | "onTaskNotification" | "onSubagentSpawn" | "insideFork" | "questionFaceStripped"> | undefined;
83
+ internals: Pick<RunInternals, "inheritedGate" | "sessionModeSeats" | "ownOrgAdmissionRef" | "delegationProvenance" | "memoryCaptureAncestors" | "parentTaskId" | "parentSessionId" | "rootSessionId" | "rootSessionIncarnation" | "placementRoot" | "explicitAgentName" | "peerSelfRef" | "peerInboundChainRef" | "onTaskNotification" | "onSubagentSpawn" | "insideFork" | "questionFaceStripped"> | undefined;
83
84
  /** borrowed-readonly — the resume leg, or undefined on a fresh one: `seed.inheritedGate` is the CHECKPOINT half of the chain
84
85
  * fold (the trust floor the live half may only tighten), `seed.readFace` the hands-less re-park's carried section. */
85
86
  resume: Pick<PrepareResume, "seed" | "outcome"> | undefined;
86
87
  /** borrowed-readonly — the session store's fork face: `fork` / `release` are bound into the ctx's `hostSessionFork` (present
87
- * only when the store can fork). */
88
- sessions: Pick<SessionStore, "fork" | "release">;
88
+ * only when the store can fork); `placements` decides whether a fork placement is handed on. */
89
+ sessions: Pick<SessionStore, "fork" | "release" | "placements">;
89
90
  /** borrowed-readonly — the acquired session id (the crash lane's context, the ctx seat, the ancestor chain's own row). */
90
91
  sessionId: string;
91
92
  /** borrowed-readonly — the run's invocation id (the stop seat's notice names it). */
92
93
  runId: string;
93
94
  /** borrowed-readonly — the per-task identity (`ctx.taskId`, the same fallback the runner uses). */
94
95
  hostTaskId: string;
95
- /** borrowed-readonly — the SETTLED task root (`ctx.parentCwd`). */
96
+ /** borrowed-readonly — the SETTLED task root (`ctx.callerRoot`: the checkout a delegated child must not be placed inside). */
96
97
  taskRootFinal: string;
98
+ /** borrowed-readonly — where a delegated child is asked to work, read per tool call (`ctx.parentCwd`): the leg's write
99
+ * location (`writeLocationOf` — the active EnterWorktree tree while one is tracked), else the task root as the deployment
100
+ * spelled it. */
101
+ delegationCwd: () => string;
97
102
  /** borrowed-readonly — the target this leg's env reported as its workspace settled (`ctx.placementTarget`: the fence of
98
103
  * every agent the delegation tools spawn or wake from this leg); absent when it reported none. */
99
104
  ownTarget: PlacementTarget | undefined;
@@ -207,6 +212,8 @@ export interface PrepareInheritedGateInput {
207
212
  } | undefined;
208
213
  /** borrowed-readonly — LATE-BOUND: the memory-engine session (the ctx's capture-floor getters read it at THEIR call time). */
209
214
  memoryEngineSession: () => Prepared["memoryEngineSession"];
215
+ /** borrowed-readonly — LATE-BOUND: this leg's occupant (`SessionMetadata.incarnation` of the acquired session; the lineage read assigns it). */
216
+ sessionIncarnation: () => string | undefined;
210
217
  }
211
218
  export interface PrepareInheritedGateResult {
212
219
  /** owned — the LIVE half of the inherited chain as supplied (`internals.inheritedGate`); the durable-gate notice reads it. */
@@ -319,10 +326,7 @@ export interface PrepareInheritedGateResult {
319
326
  /** borrowed-mutable — the delegation-settlement coordinates. Writer: the memory-engine-session phase, once per leg when the
320
327
  * mounted session carries a settlement seat. Read lazily by delegation tools through the ctx. */
321
328
  delegationSettlementRef: {
322
- current?: {
323
- controlDir: string;
324
- sessionId: string;
325
- };
329
+ current?: DelegationSettlementSeat;
326
330
  };
327
331
  /** owned — chain assembly SINGLE SITE: upstream chain + this task's own contribution, called by delegation tools at spawn. */
328
332
  inheritedGateForChildren: () => InheritedGate;
@@ -5,6 +5,7 @@ import { parentSpecSeatOf } from "../parent-spec-seat.js";
5
5
  import { chainJudges, sameInstallation } from "../mods/stations.js";
6
6
  import { childClampSeats, clampSourceOf } from "../child-clamp-seats.js";
7
7
  import { rowFollowsFloor } from "./session-rule-policy.js";
8
+ import { declaresSubagentPlacement } from "../session.js";
8
9
  import { performsIo } from "../remote-env.js";
9
10
  import { durableMandateSourceOf } from "../tool-policy.js";
10
11
  import { chainAnchorRecords } from "./child-tree.js";
@@ -16,7 +17,7 @@ import { frozenSkillGrants } from "../skill-grant.js";
16
17
  import { attachRebuiltDenialTrackers, createDenialLimitStop } from "./denial-limit-arms.js";
17
18
  import { valveLeaves } from "../../agents/tool-filter.js";
18
19
  export function prepareInheritedGate(input) {
19
- const { spec, deps, askSeat, internals, resume, sessions, sessionId, runId, hostTaskId, taskRootFinal, executionEnv, ownedEnv, lockedPreflight, pathRuleAnchors, toolFaceSnapshot, mountsCallerTool, promptLean, resolvedInteractionPosture, permissionModeSeat, handsEnabled, reportUsage, harnessRef, skillGrants, forwardEvent, subagentRetain, taskArtifacts, worktreeIsolation, requestReview, requestStopAfterTurn, enterPlanMode, reminderMark, reminderDisclosureCounts, fileHistoryEnabled, historyScope, historyRoot, historyFs, abortRun } = input;
20
+ const { spec, deps, askSeat, internals, resume, sessions, sessionId, runId, hostTaskId, taskRootFinal, delegationCwd, executionEnv, ownedEnv, lockedPreflight, pathRuleAnchors, toolFaceSnapshot, mountsCallerTool, promptLean, resolvedInteractionPosture, permissionModeSeat, handsEnabled, reportUsage, harnessRef, skillGrants, forwardEvent, subagentRetain, taskArtifacts, worktreeIsolation, requestReview, requestStopAfterTurn, enterPlanMode, reminderMark, reminderDisclosureCounts, fileHistoryEnabled, historyScope, historyRoot, historyFs, abortRun } = input;
20
21
  const liveInheritedGate = internals?.inheritedGate;
21
22
  const seedInheritedGate = resume?.seed.inheritedGate;
22
23
  const inheritedAncestorRules = (() => {
@@ -189,6 +190,7 @@ export function prepareInheritedGate(input) {
189
190
  const centerAdoption = input.centerAdoption();
190
191
  const agentStations = input.agentStations();
191
192
  const sendStation = input.sendStation();
193
+ const rootSessionIncarnation = internals?.rootSessionId !== undefined ? internals.rootSessionIncarnation : input.sessionIncarnation();
192
194
  return {
193
195
  ...ctx,
194
196
  delegationEntryCaps: delegationEntryCapsResolved,
@@ -220,14 +222,17 @@ export function prepareInheritedGate(input) {
220
222
  return input.memoryEngineSession()?.captureOptOut?.indeterminate() ?? false;
221
223
  },
222
224
  get memoryCaptureControlDir() {
223
- return input.memoryEngineSession()?.engine.controlPlaneDir;
225
+ return input.memoryEngineSession()?.engine.controlPlaneRoot;
224
226
  },
225
227
  get memoryCaptureAncestors() {
226
- const ctl = input.memoryEngineSession()?.engine.controlPlaneDir;
228
+ const ctl = input.memoryEngineSession()?.engine.controlPlaneRoot;
227
229
  return [...(internals?.memoryCaptureAncestors ?? []), { sessionId, ...(ctl !== undefined ? { controlDir: ctl } : {}) }];
228
230
  },
229
231
  getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
230
- parentCwd: taskRootFinal,
232
+ get parentCwd() {
233
+ return delegationCwd();
234
+ },
235
+ callerRoot: taskRootFinal,
231
236
  ...(input.ownTarget !== undefined ? { placementTarget: input.ownTarget } : {}),
232
237
  ...(input.hostFloor !== undefined ? { hostFloor: input.hostFloor } : {}),
233
238
  ...(fileHistoryEnabled ? { fileHistoryLineage: { scope: historyScope, root: historyRoot, fs: historyFs } } : {}),
@@ -249,6 +254,7 @@ export function prepareInheritedGate(input) {
249
254
  ...(internals?.parentTaskId !== undefined ? { parentTaskId: internals.parentTaskId } : {}),
250
255
  ...(internals?.parentSessionId !== undefined ? { parentSessionId: internals.parentSessionId } : {}),
251
256
  ...(internals?.rootSessionId !== undefined ? { rootSessionId: internals.rootSessionId } : {}), ...(internals?.placementRoot !== undefined ? { placementRoot: internals.placementRoot } : {}),
257
+ ...(rootSessionIncarnation !== undefined ? { rootSessionIncarnation } : {}),
252
258
  delegationOwner: input.delegationOwner,
253
259
  ...(internals?.explicitAgentName !== undefined ? { spawnedAgentName: internals.explicitAgentName } : {}),
254
260
  ...(internals?.peerSelfRef !== undefined ? { peerSelfRef: internals.peerSelfRef } : {}),
@@ -256,11 +262,11 @@ export function prepareInheritedGate(input) {
256
262
  ...(deps.rosterStore !== undefined ? { roster: deps.rosterStore } : {}),
257
263
  ...(sessions.fork !== undefined
258
264
  ? {
259
- hostSessionFork: async () => {
265
+ hostSessionFork: async (forkOpts) => {
260
266
  const tree = await input.delegationOwner.read();
261
267
  if (!tree.bound)
262
268
  throw delegationOwnerUnbound(tree.reason);
263
- const forked = (await sessions.fork(sessionId, tree.owner)) ?? null;
269
+ const forked = (await sessions.fork(sessionId, tree.owner, forkOpts !== undefined && declaresSubagentPlacement(sessions) ? forkOpts : undefined)) ?? null;
264
270
  if (forked === null)
265
271
  return null;
266
272
  return {
@@ -17,6 +17,7 @@ import type { LockedPreflight } from "../locked-config.js";
17
17
  import { type DelegationContentSafety } from "../memory-engine/delegation-provenance.js";
18
18
  import type { RunnerDeps, TaskSpec } from "../types.js";
19
19
  import type { Prepared, RunInternals } from "./contracts.js";
20
+ import type { DelegationSettlementSeat } from "../tool-spec.js";
20
21
  import { RosterBuilder } from "../tool-roster.js";
21
22
  export interface PrepareMemoryEngineSessionInput {
22
23
  /** borrowed-readonly — the mounted engine session, or undefined (the ARMING fact's first half). Read: `pollution`
@@ -50,10 +51,7 @@ export interface PrepareMemoryEngineSessionInput {
50
51
  /** borrowed-mutable — the children's settlement seat (the inherited-gate phase mints it). Writer: THIS phase, once at
51
52
  * arming, when the memory session mounted a settlement (memoryProvenance "carry"). */
52
53
  delegationSettlementRef: {
53
- current?: {
54
- controlDir: string;
55
- sessionId: string;
56
- };
54
+ current?: DelegationSettlementSeat;
57
55
  };
58
56
  /** borrowed-readonly — the REBOUND spec; only `tools` (the RAW caller specs: caller-tool names and the marker-bearing
59
57
  * delegation entries — the assembled roster objects carry neither marker). Never mutated. */
@@ -30,7 +30,7 @@ export function prepareMemoryEngineSession(input) {
30
30
  onNotice: deps.onNotice,
31
31
  });
32
32
  if (memoryEngineSession?.settlement !== undefined) {
33
- delegationSettlementRef.current = { controlDir: memoryEngineSession.settlement.controlDir, sessionId: memoryEngineSession.settlement.sessionId };
33
+ delegationSettlementRef.current = { governance: memoryEngineSession.settlement.governance, controlDir: memoryEngineSession.settlement.controlDir, sessionId: memoryEngineSession.settlement.sessionId };
34
34
  }
35
35
  const recordExternal = () => {
36
36
  if (delegationProvenanceChannel !== undefined)
@@ -118,7 +118,7 @@ export function prepareMemoryEngineSession(input) {
118
118
  let preCallLaunchRows;
119
119
  if (delegationEvidenceAttestedOnly && memoryEngineSession?.settlement !== undefined) {
120
120
  try {
121
- preCallLaunchRows = new Set(sessionSettlements(memoryEngineSession.settlement.controlDir, memoryEngineSession.settlement.sessionId)
121
+ preCallLaunchRows = new Set((await sessionSettlements(memoryEngineSession.settlement.governance, memoryEngineSession.settlement.sessionId))
122
122
  .filter((r) => r.row.lane === "background" && r.row.toolUseId === toolCallId)
123
123
  .map((r) => r.row.settleId));
124
124
  }
@@ -165,7 +165,7 @@ export function prepareMemoryEngineSession(input) {
165
165
  preCallLaunchRows !== undefined &&
166
166
  claimedSettleId !== undefined &&
167
167
  !preCallLaunchRows.has(claimedSettleId) &&
168
- sessionSettlements(settlementSeat.controlDir, settlementSeat.sessionId).some((r) => r.row.lane === "background" && r.row.settleId === claimedSettleId && r.row.toolUseId === toolCallId);
168
+ (await sessionSettlements(settlementSeat.governance, settlementSeat.sessionId)).some((r) => r.row.lane === "background" && r.row.settleId === claimedSettleId && r.row.toolUseId === toolCallId);
169
169
  }
170
170
  catch {
171
171
  isLaunchReceipt = false;
@@ -173,7 +173,7 @@ export function prepareMemoryEngineSession(input) {
173
173
  }
174
174
  if (!isLaunchReceipt && settlementSeat !== undefined) {
175
175
  try {
176
- recordSyncUnattestable(settlementSeat.controlDir, { sessionId: settlementSeat.sessionId, toolCallId, now: Date.now });
176
+ await recordSyncUnattestable(settlementSeat.governance, { sessionId: settlementSeat.sessionId, toolCallId, now: Date.now });
177
177
  }
178
178
  catch (err) {
179
179
  const e = new Error(`delegated output withheld (fail-closed): the delegation delivered without a provable attestation and the settlement account could not record the fact (${thrownText(err)}) — repair the memory control plane or retry`);
@@ -198,6 +198,10 @@ export interface MemoryInjectionComposition {
198
198
  path: string;
199
199
  content: string;
200
200
  }>;
201
+ /** #1123 — the notices this prepare drained, as whole engine reminders (the engine's `announceBlock`, then the
202
+ * session-scope coda in its own reminder when one is owed): an EVENT, so it never enters `memoryBlock` (the cached
203
+ * prefix) — the leg's first request carries it once, ahead of the user's message. Absent when nothing was drained. */
204
+ noticesFrame?: string;
201
205
  }
202
206
  export interface PrepareMemoryResult {
203
207
  memoryEngineSession: Prepared["memoryEngineSession"];
@@ -212,12 +216,13 @@ export interface PrepareMemoryResult {
212
216
  * so a hands-phase refusal cannot consume announcements a later prepare should deliver, and it takes the
213
217
  * roster-wide persistence verdict the driver can only read off the MOUNTED roster (`rosterCanPersist`: the
214
218
  * `memoryPersistenceCapable` declaration when set, else the store-path inference over the assembled tools) and
215
- * `isSubagent` (a non-fork delegated child — no user conversation, no not-mounted notice). Call once per prepare.
219
+ * `isSubagent` (a non-fork delegated child — no user conversation, no not-mounted notice). Call once per prepare;
220
+ * async because the drain goes through the engine's governance store.
216
221
  */
217
222
  composeInjection: (facts: {
218
223
  rosterCanPersist: boolean;
219
224
  isSubagent: boolean;
220
- }) => MemoryInjectionComposition;
225
+ }) => Promise<MemoryInjectionComposition>;
221
226
  /**
222
227
  * The FROZEN org-admission verdict of this prepare: every org scope the task actually mounts
223
228
  * (deployment-origin kept + request-origin admitted). Threaded into the run's child chain
@@ -4,9 +4,10 @@ import { admitMemoryScopes } from "../memory-admission.js";
4
4
  import { adoptLegacyRepoDirs, canonicalize, deriveRepoControlPlaneDir, deriveProjectControlDir, deriveProjectMemoryDir, deriveRepoKey, deriveRepoMemoryDir, effectiveControlRootOf, isContainedIn, lookupProjectIdHint, recordProjectIdHint, resolveMemoryEngineRoot, transferMemoryAnnouncements } from "../memory-engine/layout.js";
5
5
  import { derivePersonalControlDir, derivePersonalMemoryDir, directoryPinOf, memoryPlaneStore, mergeHarvestReports, mergeInjections, needsDualRoots, parsedProjectPlane, scopePlanesOf } from "../memory-engine/dual-root.js";
6
6
  import { memoryProjectScopeAbsentNotice, normalizeMemorySpec } from "../memory.js";
7
- import { deriveSupersededSet } from "../memory-engine/consolidation.js";
7
+ import { deriveSupersededSet, fileGovernanceStore } from "../memory-engine/consolidation.js";
8
8
  import { shadowNamesOf } from "../memory-engine/shadowing.js";
9
- import { MEMORY_ANNOUNCEMENT_CAPTURE_OPTOUT_CODA, MEMORY_ANNOUNCEMENT_READONLY_CODA, MEMORY_CAPTURE_OPTOUT_NOTICE, MEMORY_PREFERENCE_DISCIPLINE, MEMORY_READONLY_NOTICE, MemoryEngine, entryFileHeadCarriesOrigin, memoryCaptureOptedOutNotice, memoryCaptureOptOutUnpersistedNotice, memoryConsolidationRecommendedNotice, memoryHarvestQuarantinedNotice, memoryHoldNotices, memoryRecallDisciplineSegment, memoryRestoreWithheldNotice, memorySessionPollutedNotice, memoryUnavailableNotice, pollutionContainmentCounts, } from "../memory-engine/engine.js";
9
+ import { mintSystemReminder } from "../reminder-mint.js";
10
+ import { MEMORY_ANNOUNCEMENT_CAPTURE_OPTOUT_CODA, MEMORY_ANNOUNCEMENT_READONLY_CODA, MEMORY_CAPTURE_OPTOUT_NOTICE, MEMORY_PREFERENCE_DISCIPLINE, MEMORY_READONLY_NOTICE, MemoryEngine, entryFileHeadCarriesOrigin, memoryCaptureOptedOutNotice, memoryCaptureOptOutUnpersistedNotice, memoryConsolidationRecommendedNotice, memoryHarvestConflictNotice, memoryHarvestQuarantinedNotice, memoryHarvestRefusedNotice, memoryHoldNotices, memoryRecallDisciplineSegment, memoryRestoreWithheldNotice, memorySessionPollutedNotice, memoryUnavailableNotice, pollutionContainmentCounts, } from "../memory-engine/engine.js";
10
11
  import { adjudicateCaptureOptOut, captureOptOutDeniedError, captureOptOutUnpersistedError } from "./memory-capture-optout.js";
11
12
  import { readSessionCaptureOptOut } from "../memory-engine/layout.js";
12
13
  import { sessionIncarnationResolver } from "../memory-engine/session-incarnation.js";
@@ -129,11 +130,11 @@ export async function prepareMemory(input) {
129
130
  const firstSwitch = verdictOnPartitionRoot && lookupProjectIdHint(engineRoot, repoRoot) !== marker.projectId;
130
131
  if (verdictOnPartitionRoot)
131
132
  recordProjectIdHint(engineRoot, repoRoot, marker.projectId);
132
- if (firstSwitch) {
133
+ if (firstSwitch && backend.governance === undefined) {
133
134
  try {
134
135
  const oldCtl = deriveRepoControlPlaneDir(engineRoot, repoRoot);
135
136
  const newCtl = deriveProjectControlDir(engineRoot, marker.projectId);
136
- transferMemoryAnnouncements(oldCtl, newCtl);
137
+ await transferMemoryAnnouncements(fileGovernanceStore(oldCtl), fileGovernanceStore(newCtl));
137
138
  }
138
139
  catch (err) {
139
140
  deps.onError?.(asThrownError(err), { phase: "config", sessionId });
@@ -206,7 +207,7 @@ export async function prepareMemory(input) {
206
207
  }
207
208
  if (samePlane.fault)
208
209
  anyFault = true;
209
- if (ancestorDir !== undefined && ancestorDir !== eng.controlPlaneDir) {
210
+ if (ancestorDir !== undefined && ancestorDir !== eng.controlPlaneRoot) {
210
211
  try {
211
212
  const crossPlane = deps.memoryCaptureRecordStore !== undefined ? await deps.memoryCaptureRecordStore({ controlDir: ancestorDir }).read(ancestorId) : readSessionCaptureOptOut(ancestorDir, ancestorId);
212
213
  if (crossPlane !== undefined) {
@@ -311,7 +312,7 @@ export async function prepareMemory(input) {
311
312
  for (const [ancestorId, ancestorDir] of ancestors) {
312
313
  const samePlane = await writeEngine.sessionCaptureOptOutOrFault(ancestorId);
313
314
  let crossPlane;
314
- if (ancestorDir !== undefined && ancestorDir !== writeEngine.controlPlaneDir) {
315
+ if (ancestorDir !== undefined && ancestorDir !== writeEngine.controlPlaneRoot) {
315
316
  try {
316
317
  crossPlane = deps.memoryCaptureRecordStore !== undefined ? await deps.memoryCaptureRecordStore({ controlDir: ancestorDir }).read(ancestorId) : readSessionCaptureOptOut(ancestorDir, ancestorId);
317
318
  }
@@ -376,12 +377,12 @@ export async function prepareMemory(input) {
376
377
  sessionId,
377
378
  ...(m.write === null && shadowNames !== undefined && shadowNames.size > 0 ? { shadowNames } : {}),
378
379
  });
379
- openedLegs.push(() => void m.engine.endSessionLeg(handle, sessionId));
380
+ openedLegs.push(() => m.engine.endSessionLeg(handle, sessionId));
380
381
  mounted.push(handle);
381
382
  materializedResidue.push(...planeScopes(m.scopes, m.write));
382
383
  if (m.write !== null) {
383
384
  try {
384
- const withheld = new Set(m.engine.readChallengeExclusions().keys());
385
+ const withheld = new Set((await m.engine.readChallengeExclusions()).keys());
385
386
  const committed = await m.engine.listCommittedHeaders([m.write]);
386
387
  const superseded = deriveSupersededSet(committed, { excluded: (id) => withheld.has(id) });
387
388
  shadowNames = shadowNamesOf(committed, m.write, { excluded: (id) => withheld.has(id) || superseded.has(id) });
@@ -398,7 +399,7 @@ export async function prepareMemory(input) {
398
399
  writeHandle = writeIsPersonal ? personalHandle : projectHandle;
399
400
  readOnlyEngine = writeIsPersonal ? projectEngine : personalEngine;
400
401
  readOnlyHandle = writeIsPersonal ? projectHandle : personalHandle;
401
- injectFn = () => mergeInjections(projectEngine.inject(projectHandle, { writeToolMounted: writeChannelOpen, reminderMark: input.reminderMark }), personalEngine.inject(personalHandle, { writeToolMounted: writeChannelOpen, reminderMark: input.reminderMark }));
402
+ injectFn = async () => mergeInjections(await projectEngine.inject(projectHandle, { writeToolMounted: writeChannelOpen, reminderMark: input.reminderMark }), await personalEngine.inject(personalHandle, { writeToolMounted: writeChannelOpen, reminderMark: input.reminderMark }));
402
403
  toolPlanes = [
403
404
  {
404
405
  backend: retrievalBackend(backend, adoptionRestricted || captureOptedOut || captureIndeterminate || p.writePlane !== "project"),
@@ -440,7 +441,7 @@ export async function prepareMemory(input) {
440
441
  const personalEngine = personal.engine;
441
442
  await armCaptureOptOut(personalEngine);
442
443
  const handle = await personalEngine.materialize(memorySpec.scopes, memorySpec.writeScope, { adoptionRestricted: adoptionRestricted || captureOptedOut || captureIndeterminate, sessionId });
443
- openedLegs.push(() => void personalEngine.endSessionLeg(handle, sessionId));
444
+ openedLegs.push(() => personalEngine.endSessionLeg(handle, sessionId));
444
445
  materializedResidue.push(...planeScopes(memorySpec.scopes, memorySpec.writeScope));
445
446
  memoryMarkedEntriesServed = handle.markedEntriesPresent === true;
446
447
  writeEngine = personalEngine;
@@ -470,7 +471,7 @@ export async function prepareMemory(input) {
470
471
  });
471
472
  await armCaptureOptOut(engine);
472
473
  const handle = await engine.materialize(memorySpec.scopes, memorySpec.writeScope, { adoptionRestricted: adoptionRestricted || captureOptedOut || captureIndeterminate, sessionId });
473
- openedLegs.push(() => void engine.endSessionLeg(handle, sessionId));
474
+ openedLegs.push(() => engine.endSessionLeg(handle, sessionId));
474
475
  materializedResidue.push(...planeScopes(memorySpec.scopes, memorySpec.writeScope));
475
476
  memoryMarkedEntriesServed = handle.markedEntriesPresent === true;
476
477
  writeEngine = engine;
@@ -497,7 +498,7 @@ export async function prepareMemory(input) {
497
498
  }
498
499
  const foreignUnderRoot = [];
499
500
  if (input.writeToolsMounted && writeHandle.writeScope !== null && input.advertisedWritableDirs !== undefined) {
500
- const controlPlane = canonicalize(writeEngine.controlPlaneDir);
501
+ const controlPlane = canonicalize(writeEngine.controlPlaneRoot);
501
502
  if (isContainedIn(writableRootOf(writeHandle), controlPlane))
502
503
  foreignUnderRoot.push(`the engine's control plane ${controlPlane}`);
503
504
  }
@@ -557,6 +558,12 @@ export async function prepareMemory(input) {
557
558
  }
558
559
  deliverEngineNotice(deps.onNotice, memoryHarvestQuarantinedNotice({ count, moved, escalated, ...(report.reportId !== undefined ? { reportId: report.reportId } : {}), ...(reason !== undefined ? { reason } : {}), sessionId, provenance: input.memoryProvenance, ...(indexOnly ? { indexRolledBack: true } : {}) }));
559
560
  }
561
+ const refused = memoryHarvestRefusedNotice(report, sessionId);
562
+ if (refused !== undefined)
563
+ deliverEngineNotice(deps.onNotice, refused);
564
+ const conflicted = memoryHarvestConflictNotice(report, sessionId);
565
+ if (conflicted !== undefined)
566
+ deliverEngineNotice(deps.onNotice, conflicted);
560
567
  if (report.restoreWithheld !== undefined && report.restoreWithheld.length > 0) {
561
568
  deliverEngineNotice(deps.onNotice, memoryRestoreWithheldNotice({ paths: report.restoreWithheld, sessionId }));
562
569
  }
@@ -607,11 +614,12 @@ export async function prepareMemory(input) {
607
614
  memoryEngineSession = {
608
615
  engine: writeEngine,
609
616
  handle: writeHandle,
617
+ scopeContract: memorySpec.scopeContract,
610
618
  inject: injectFn,
611
619
  harvest: harvestSafe,
612
- release: () => {
620
+ release: async () => {
613
621
  for (const end of openedLegs)
614
- end();
622
+ await end();
615
623
  },
616
624
  captureOptOut: {
617
625
  optedOut: () => {
@@ -677,11 +685,12 @@ export async function prepareMemory(input) {
677
685
  pollution: {
678
686
  polluted: () => writeEngine.sessionPollution(sessionId),
679
687
  markPolluted: (reason, cause) => {
680
- const outcome = writeEngine.markSessionPolluted(sessionId, reason, cause);
681
- if (outcome === "existed" || (outcome === "unpersisted" && pollutionAnnounced))
682
- return;
683
- pollutionAnnounced = true;
684
- deliverEngineNotice(deps.onNotice, memorySessionPollutedNotice({ reason, sessionId, provenance: input.memoryProvenance }));
688
+ void writeEngine.markSessionPolluted(sessionId, reason, cause).then((outcome) => {
689
+ if (outcome === "existed" || (outcome === "unpersisted" && pollutionAnnounced))
690
+ return;
691
+ pollutionAnnounced = true;
692
+ deliverEngineNotice(deps.onNotice, memorySessionPollutedNotice({ reason, sessionId, provenance: input.memoryProvenance }));
693
+ });
685
694
  },
686
695
  },
687
696
  contentSafety: {
@@ -689,7 +698,7 @@ export async function prepareMemory(input) {
689
698
  execIsExternalContent: memorySpec.execIsExternalContent === true,
690
699
  },
691
700
  ...(input.memoryProvenance !== "off"
692
- ? { settlement: { controlDir: writeEngine.controlPlaneDir, sessionId, provenance: "carry" } }
701
+ ? { settlement: { governance: writeEngine.governance, controlDir: writeEngine.controlPlaneRoot, sessionId, provenance: "carry" } }
693
702
  : {}),
694
703
  ...(input.memoryProvenance !== "off"
695
704
  ? {
@@ -733,7 +742,7 @@ export async function prepareMemory(input) {
733
742
  catch (err) {
734
743
  if (memoryEngineSession === undefined)
735
744
  for (const end of openedLegs)
736
- end();
745
+ await end();
737
746
  if (typeof err.code === "string" &&
738
747
  (err.code.startsWith("config.memory_scope") ||
739
748
  err.code.startsWith("config.memory_project") ||
@@ -760,40 +769,32 @@ export async function prepareMemory(input) {
760
769
  const detail = "TaskSpec.memory is enabled but RunnerDeps.memoryBackend is not configured; memory is inactive for this task (the legacy memoryStore fallback was retired in design/138 S4 and the dep was removed in design/157 B19).";
761
770
  deps.onError?.(new Error(detail), { phase: "config", sessionId });
762
771
  }
763
- const composeInjection = (facts) => {
772
+ const composeInjection = async (facts) => {
764
773
  let memoryBlock;
765
774
  let seedFiles;
766
775
  let recallDisciplineSegment;
776
+ let noticesFrame;
767
777
  if (memoryEngineSession) {
768
- const injection = memoryEngineSession.inject();
778
+ const injection = await memoryEngineSession.inject();
769
779
  let blockBody = injection.block;
770
780
  if (captureOptedOut) {
771
- blockBody = [MEMORY_CAPTURE_OPTOUT_NOTICE, injection.index, injection.announceBlock].filter((s) => Boolean(s && s.trim())).join("\n\n");
781
+ blockBody = [MEMORY_CAPTURE_OPTOUT_NOTICE, injection.index].filter((s) => Boolean(s && s.trim())).join("\n\n");
772
782
  }
773
783
  else if (captureIndeterminate && facts.rosterCanPersist) {
774
- blockBody = [memoryUnavailableNotice({ what: "capture-record-unreadable", notesReadable: true }), injection.index, injection.announceBlock].filter((s) => Boolean(s && s.trim())).join("\n\n");
784
+ blockBody = [memoryUnavailableNotice({ what: "capture-record-unreadable", notesReadable: true }), injection.index].filter((s) => Boolean(s && s.trim())).join("\n\n");
775
785
  }
776
786
  else if (!facts.rosterCanPersist && injection.instruction === "" && injection.readOnlyNotice === undefined) {
777
787
  blockBody = blockBody.trim() ? `${MEMORY_READONLY_NOTICE}\n\n${blockBody}` : MEMORY_READONLY_NOTICE;
778
788
  }
779
789
  else if (!facts.rosterCanPersist && injection.instruction !== "") {
780
- blockBody = [MEMORY_READONLY_NOTICE, injection.index, injection.announceBlock].filter((s) => Boolean(s && s.trim())).join("\n\n");
790
+ blockBody = [MEMORY_READONLY_NOTICE, injection.index].filter((s) => Boolean(s && s.trim())).join("\n\n");
781
791
  }
782
792
  else if (input.memoryPersistenceDeclared === true && injection.readOnlyNotice !== undefined) {
783
- blockBody = [injection.index, injection.announceBlock].filter((s) => Boolean(s && s.trim())).join("\n\n");
793
+ blockBody = [injection.index].filter((s) => Boolean(s && s.trim())).join("\n\n");
784
794
  }
785
- if (!facts.rosterCanPersist &&
786
- (injection.announceBlock?.trim() ?? "") !== "" &&
787
- blockBody.includes(injection.announceBlock) &&
788
- !blockBody.trimEnd().endsWith(MEMORY_ANNOUNCEMENT_READONLY_CODA)) {
789
- blockBody = `${blockBody}\n\n${MEMORY_ANNOUNCEMENT_READONLY_CODA}`;
790
- }
791
- if (captureOptedOut &&
792
- facts.rosterCanPersist &&
793
- (injection.announceBlock?.trim() ?? "") !== "" &&
794
- blockBody.includes(injection.announceBlock) &&
795
- !blockBody.trimEnd().endsWith(MEMORY_ANNOUNCEMENT_CAPTURE_OPTOUT_CODA)) {
796
- blockBody = `${blockBody}\n\n${MEMORY_ANNOUNCEMENT_CAPTURE_OPTOUT_CODA}`;
795
+ if ((injection.announceBlock?.trim() ?? "") !== "") {
796
+ const coda = !facts.rosterCanPersist ? MEMORY_ANNOUNCEMENT_READONLY_CODA : captureOptedOut ? MEMORY_ANNOUNCEMENT_CAPTURE_OPTOUT_CODA : undefined;
797
+ noticesFrame = coda === undefined ? injection.announceBlock : `${injection.announceBlock}\n${mintSystemReminder(coda, input.reminderMark)}`;
797
798
  }
798
799
  if (blockBody.trim())
799
800
  memoryBlock = blockBody;
@@ -814,6 +815,7 @@ export async function prepareMemory(input) {
814
815
  memoryBlock,
815
816
  ...(recallDisciplineSegment !== undefined ? { recallDisciplineSegment } : {}),
816
817
  ...(seedFiles !== undefined ? { seedFiles } : {}),
818
+ ...(noticesFrame !== undefined ? { noticesFrame } : {}),
817
819
  };
818
820
  };
819
821
  if (effectiveMemoryScopes === undefined) {
@@ -57,6 +57,7 @@ export function prepareParkAsk(input) {
57
57
  return refuseBeforeDelivery("question.malformed_request");
58
58
  }
59
59
  const retainedQuestionsHash = boundInputHashOf(retained.questions);
60
+ const retainedCallHash = exactBoundInputHashOf(req.toolName, retained);
60
61
  if (!Value.Check(mountedQuestionTool.parameters, retained) || validateAskQuestions(presented) !== undefined) {
61
62
  return refuseBeforeDelivery("question.malformed_request");
62
63
  }
@@ -71,7 +72,7 @@ export function prepareParkAsk(input) {
71
72
  toolCallId: req.toolCallId,
72
73
  questions: presented,
73
74
  ...questionSourceOf(askSource),
74
- boundInputHash: boundInputHashOf(retained),
75
+ ...(retainedCallHash !== undefined ? { boundInputHash: retainedCallHash } : {}),
75
76
  deliveryId,
76
77
  }, contentAskSignal))();
77
78
  const settlement = await raceAbort(facePromise.then((outcome) => ({ tag: "outcome", outcome }), (error) => ({ tag: "threw", error })), contentAskSignal, () => ({ tag: "aborted" }));
@@ -149,7 +150,7 @@ export function prepareParkAsk(input) {
149
150
  const bindable = bindableArgsOf(req.toolName, parkedArgs);
150
151
  if (!bindable.ok)
151
152
  throw new ParkRefusal(bindable.refusal);
152
- const parkedHash = exactBoundInputHashOf(parkedArgs);
153
+ const parkedHash = exactBoundInputHashOf(req.toolName, parkedArgs);
153
154
  if (parkedHash === undefined)
154
155
  throw new ParkRefusal(`the canonical form of the arguments of "${req.toolName}" cannot be built — no approval row can be bound to them`);
155
156
  const projectionMovedArgs = backendFidelity !== "structured-clone" && !samePlainValue(parked.value, parkedArgs);
@@ -306,7 +307,7 @@ export function prepareParkAsk(input) {
306
307
  toolCallId: req.toolCallId,
307
308
  toolName: req.toolName,
308
309
  ...parkedToolIdentity(toolRosterDeltas.current, req.toolName), ...parkedToolFace(toolRosterDeltas.current, req),
309
- ...(licenseCovers(parkedHash, req.args) ? approvalTargetsOf(callTargetReadingOf(req), shellReadLandings?.(req.toolCallId)) : {}),
310
+ ...(licenseCovers(parkedHash, req.toolName, req.args) ? approvalTargetsOf(callTargetReadingOf(req), shellReadLandings?.(req.toolCallId)) : {}),
310
311
  args: parkedArgs,
311
312
  ...(() => {
312
313
  const p = approvalPreviewOf(req.toolName, parkedArgs);
@@ -10,7 +10,7 @@ import { isCoveringRuleName, ruleNameCovers } from "../namespaced-rule-name.js";
10
10
  import { isIsolated } from "../remote-env.js";
11
11
  import { deliverEngineNotice } from "../engine-notice.js";
12
12
  import { earlierGrammarNotice } from "../session-policy-store.js";
13
- import { attest, attestationOf, checkToolPolicyProjection, combinePolicies, createTranscriptIntegrityPolicy, createUnverifiableDeletePolicy, durableParkOptInDeclared, isLiveApproverSeat, mergeAttestation, refuseOutOfContractDecision, resolveAsk, toolPolicyNameSets, withAttestation, wrapToolPolicy } from "../tool-policy.js";
13
+ import { attest, attestationOf, checkToolPolicyProjection, combinePolicies, createTranscriptIntegrityPolicy, createUnverifiableDeletePolicy, durableParkOptInDeclared, isLiveApproverSeat, mergeAttestation, refuseOutOfContractDecision, resolveAskFor, toolPolicyNameSets, withAttestation, wrapToolPolicy } from "../tool-policy.js";
14
14
  import { judgeRuleToolName, mountedToolNames, nearMissSpellingOf } from "../tool-name-aliases.js";
15
15
  import { approvalCardMemberOf } from "../tool-roster.js";
16
16
  import { NAMESPACED_NAME_SHAPES } from "../protocol-table.js";
@@ -400,7 +400,7 @@ export async function preparePolicyChain(input) {
400
400
  if (editArbitrated !== undefined && !outletReleased) {
401
401
  return onApproval(editArbitrated.action === "allow" ? { action: "allow", updatedInput: editArgs, decisionReason: "mode" } : editArbitrated);
402
402
  }
403
- const { resolved: rr, judged: settled } = await resolveInheritedAsk(judged, (j) => resolveAsk({
403
+ const { resolved: rr, judged: settled } = await resolveInheritedAsk(judged, (j) => resolveAskFor({
404
404
  toolName: creq.toolName,
405
405
  toolCallId: creq.toolCallId,
406
406
  args: editArgs,
@@ -414,7 +414,7 @@ export async function preparePolicyChain(input) {
414
414
  ...askMandateMember(ancestorFacts(j.ask)),
415
415
  ...inheritedAskCarry(j, isLiveApproverSeat(onAskOf), ancestorTracker),
416
416
  ruleEvidence: inheritedAskEvidence,
417
- }, onAskOf, csignal ?? abortController.signal, lateAskSettlementObserver({ toolName: creq.toolName, toolCallId: creq.toolCallId, sessionId, runId, taskId: hostTaskId, onNotice: deps.onNotice, onError: deps.onError })), ancestorTracker, creq, inheritedStationFacts(creq));
417
+ }, onAskOf, csignal ?? abortController.signal, lateAskSettlementObserver({ toolName: creq.toolName, toolCallId: creq.toolCallId, sessionId, runId, taskId: hostTaskId, onNotice: deps.onNotice, onError: deps.onError }), j.ask), ancestorTracker, creq, inheritedStationFacts(creq));
418
418
  void settleReadRootGrant(rr.readRootGrant, undefined, { toolName: creq.toolName, toolCallId: creq.toolCallId, sessionId, runId, taskId: hostTaskId, onNotice: deps.onNotice });
419
419
  settleDenialLimitFallback({ fallback: settled.fallback, mintedHere: settled.mintedHere, tracker: ancestorTracker, resolved: rr, headless: headlessDenyAtRecheck, stop: stopForDenialLimit, toolName: creq.toolName, toolCallId: creq.toolCallId });
420
420
  if (rr.action !== "allow")
@@ -456,7 +456,7 @@ export async function preparePolicyChain(input) {
456
456
  if (arbitrated !== undefined)
457
457
  return settledAs(arbitrated);
458
458
  const askT0 = now();
459
- const { resolved, judged: settled } = await resolveInheritedAsk(judged, (j) => resolveAsk({
459
+ const { resolved, judged: settled } = await resolveInheritedAsk(judged, (j) => resolveAskFor({
460
460
  toolName: creq.toolName,
461
461
  toolCallId: creq.toolCallId,
462
462
  args: presentedArgs,
@@ -470,7 +470,7 @@ export async function preparePolicyChain(input) {
470
470
  ...askMandateMember(ancestorFacts(j.ask.action === "ask" ? j.ask : undefined)),
471
471
  ...inheritedAskCarry(j, isLiveApproverSeat(pc.onAsk), pc.autoMode?.denialTracking),
472
472
  ruleEvidence: inheritedAskEvidence,
473
- }, pc.onAsk, csignal ?? abortController.signal, lateAskSettlementObserver({ toolName: creq.toolName, toolCallId: creq.toolCallId, sessionId, runId, taskId: hostTaskId, onNotice: deps.onNotice, onError: deps.onError })), pc.autoMode?.denialTracking, creq, inheritedStationFacts(creq));
473
+ }, pc.onAsk, csignal ?? abortController.signal, lateAskSettlementObserver({ toolName: creq.toolName, toolCallId: creq.toolCallId, sessionId, runId, taskId: hostTaskId, onNotice: deps.onNotice, onError: deps.onError }), j.ask), pc.autoMode?.denialTracking, creq, inheritedStationFacts(creq));
474
474
  void settleReadRootGrant(resolved.readRootGrant, undefined, { toolName: creq.toolName, toolCallId: creq.toolCallId, sessionId, runId, taskId: hostTaskId, onNotice: deps.onNotice });
475
475
  const askWaitMs = Math.max(0, now() - askT0);
476
476
  if (resolved.action === "deny" && resolved.approverUnavailable === true) {
@@ -539,7 +539,7 @@ export async function preparePolicyChain(input) {
539
539
  return arbitrated;
540
540
  const presentedArgs = creq.args;
541
541
  const askT0 = now();
542
- const { resolved, judged: settled } = await resolveInheritedAsk(judged, (j) => resolveAsk({
542
+ const { resolved, judged: settled } = await resolveInheritedAsk(judged, (j) => resolveAskFor({
543
543
  toolName: creq.toolName,
544
544
  toolCallId: creq.toolCallId,
545
545
  args: presentedArgs,
@@ -553,7 +553,7 @@ export async function preparePolicyChain(input) {
553
553
  ...askMandateMember(ancestorFacts(j.ask.action === "ask" ? j.ask : undefined)),
554
554
  ...inheritedAskCarry(j, isLiveApproverSeat(pc.onAsk), pc.autoMode?.denialTracking),
555
555
  ruleEvidence: inheritedAskEvidence,
556
- }, pc.onAsk, csignal ?? abortController.signal, lateAskSettlementObserver({ toolName: creq.toolName, toolCallId: creq.toolCallId, sessionId, runId, taskId: hostTaskId, onNotice: deps.onNotice, onError: deps.onError })), pc.autoMode?.denialTracking, creq, inheritedStationFacts(creq));
556
+ }, pc.onAsk, csignal ?? abortController.signal, lateAskSettlementObserver({ toolName: creq.toolName, toolCallId: creq.toolCallId, sessionId, runId, taskId: hostTaskId, onNotice: deps.onNotice, onError: deps.onError }), j.ask), pc.autoMode?.denialTracking, creq, inheritedStationFacts(creq));
557
557
  void settleReadRootGrant(resolved.readRootGrant, undefined, { toolName: creq.toolName, toolCallId: creq.toolCallId, sessionId, runId, taskId: hostTaskId, onNotice: deps.onNotice });
558
558
  const askWaitMs = Math.max(0, now() - askT0);
559
559
  if (resolved.action === "deny" && resolved.approverUnavailable === true) {
@@ -28,7 +28,7 @@ export async function preparePromptInputs(input) {
28
28
  goalEnabled: internals?.goalMode === true,
29
29
  awarenessEnabled: thinking !== undefined && ULTRA_REASONING_TIERS.has(thinking),
30
30
  worktreeIsolated: internals?.isolation === "worktree" && ownedEnv !== undefined,
31
- withinTaskCompactionEnabled: compactionEnabled(spec.compaction?.enabled, input.contextOverlay) && (spec.compaction?.withinTask ?? true),
31
+ withinTaskCompactionEnabled: compactionEnabled("autoCompact", spec.compaction, input.contextOverlay) && (spec.compaction?.withinTask ?? true),
32
32
  isSubagent: delegation.isNonForkChild,
33
33
  };
34
34
  const sugar = requestBodySugar({ spec, resolvedRole, ...(input.taskRole !== undefined ? { taskRole: input.taskRole } : {}), ...(internals !== undefined ? { internals } : {}) });