@sema-agent/core 7.15.0 → 7.17.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 (287) hide show
  1. package/CHANGELOG.md +202 -0
  2. package/dist/agents/builtin-agents.d.ts +3 -3
  3. package/dist/agents/cross-session-envelope.d.ts +0 -1
  4. package/dist/agents/cross-session-envelope.js +0 -1
  5. package/dist/agents/peer-notices.d.ts +0 -9
  6. package/dist/agents/peer-notices.js +0 -63
  7. package/dist/agents/subagent.js +7 -15
  8. package/dist/brain/request-params.d.ts +2 -2
  9. package/dist/config/defaults.d.ts +0 -7
  10. package/dist/config/defaults.js +0 -2
  11. package/dist/core/artifact-host.d.ts +218 -0
  12. package/dist/core/artifact-host.js +92 -0
  13. package/dist/core/ask-origin.d.ts +29 -3
  14. package/dist/core/ask-origin.js +17 -9
  15. package/dist/core/ask-question.d.ts +25 -0
  16. package/dist/core/ask-question.js +4 -0
  17. package/dist/core/ask-unresolvable-notice.d.ts +30 -21
  18. package/dist/core/ask-unresolvable-notice.js +16 -8
  19. package/dist/core/auto-compaction.d.ts +10 -10
  20. package/dist/core/auto-mode-arming.d.ts +2 -2
  21. package/dist/core/background-agent-store.d.ts +5 -5
  22. package/dist/core/background-shell.d.ts +1 -1
  23. package/dist/core/checkpoint-execution-record.d.ts +0 -3
  24. package/dist/core/checkpoint-execution-record.js +0 -4
  25. package/dist/core/checkpoint-store.d.ts +71 -99
  26. package/dist/core/checkpoint-store.js +9 -16
  27. package/dist/core/context-edit.d.ts +36 -104
  28. package/dist/core/context-edit.js +37 -60
  29. package/dist/core/effective-path-target.d.ts +68 -8
  30. package/dist/core/effective-path-target.js +42 -30
  31. package/dist/core/engine-notice.d.ts +46 -32
  32. package/dist/core/env-budget.d.ts +31 -0
  33. package/dist/core/env-budget.js +39 -0
  34. package/dist/core/exec-output-tail.d.ts +5 -5
  35. package/dist/core/file-history-store.js +3 -6
  36. package/dist/core/fs-write-gate-policy.d.ts +1 -1
  37. package/dist/core/fs-write-gate-policy.js +3 -3
  38. package/dist/core/gate-lanes.js +9 -15
  39. package/dist/core/governance-codes.d.ts +1 -1
  40. package/dist/core/governance-codes.js +4 -0
  41. package/dist/core/hands-band.d.ts +1 -1
  42. package/dist/core/hooks.d.ts +18 -17
  43. package/dist/core/lsp-session.d.ts +1 -1
  44. package/dist/core/lsp.d.ts +1 -1
  45. package/dist/core/lsp.js +5 -4
  46. package/dist/core/mcp.d.ts +5 -5
  47. package/dist/core/mcp.js +4 -48
  48. package/dist/core/memory-engine/delegation-settlement.d.ts +37 -12
  49. package/dist/core/memory-engine/delegation-settlement.js +128 -39
  50. package/dist/core/memory-engine/engine.d.ts +9 -8
  51. package/dist/core/memory-engine/engine.js +115 -120
  52. package/dist/core/memory-engine/file-backend.d.ts +17 -5
  53. package/dist/core/memory-engine/file-backend.js +78 -34
  54. package/dist/core/memory-engine/index.d.ts +2 -2
  55. package/dist/core/memory-engine/index.js +2 -2
  56. package/dist/core/memory-engine/layout.d.ts +152 -54
  57. package/dist/core/memory-engine/layout.js +441 -104
  58. package/dist/core/memory-engine/types.d.ts +8 -3
  59. package/dist/core/memory-engine/types.js +5 -0
  60. package/dist/core/memory-recall.d.ts +0 -8
  61. package/dist/core/memory.d.ts +1 -1
  62. package/dist/core/oracle-isolation.js +2 -2
  63. package/dist/core/parent-spec-seat.d.ts +66 -0
  64. package/dist/core/parent-spec-seat.js +47 -0
  65. package/dist/core/permission-rule-model.d.ts +11 -6
  66. package/dist/core/permission-rule-model.js +53 -37
  67. package/dist/core/permission-rules.js +8 -3
  68. package/dist/core/protocol-naming.d.ts +2 -2
  69. package/dist/core/remote-env.d.ts +1 -1
  70. package/dist/core/retired-keys.d.ts +19 -0
  71. package/dist/core/retired-keys.js +15 -0
  72. package/dist/core/runner/abort-race.d.ts +3 -3
  73. package/dist/core/runner/active-skill-scope.d.ts +2 -2
  74. package/dist/core/runner/active-skill-scope.js +3 -3
  75. package/dist/core/runner/assemble-result.d.ts +42 -40
  76. package/dist/core/runner/assemble-result.js +5 -4
  77. package/dist/core/runner/checkpoint-scope.d.ts +4 -4
  78. package/dist/core/runner/clock-and-limits.d.ts +3 -3
  79. package/dist/core/runner/compaction-call-options.d.ts +35 -99
  80. package/dist/core/runner/compaction-knobs.d.ts +4 -4
  81. package/dist/core/runner/compaction-seams.d.ts +5 -5
  82. package/dist/core/runner/contracts.d.ts +232 -233
  83. package/dist/core/runner/decide-continuation.d.ts +6 -6
  84. package/dist/core/runner/denial-limit-arms.d.ts +8 -8
  85. package/dist/core/runner/derived-route-fallback.d.ts +2 -2
  86. package/dist/core/runner/gate-exit.d.ts +6 -6
  87. package/dist/core/runner/gate-exit.js +15 -1
  88. package/dist/core/runner/git-status-frame.d.ts +7 -7
  89. package/dist/core/runner/halt-attribution.d.ts +35 -0
  90. package/dist/core/runner/halt-attribution.js +16 -0
  91. package/dist/core/runner/inherited-ask-grants.d.ts +6 -6
  92. package/dist/core/runner/memory-capture-optout.d.ts +1 -1
  93. package/dist/core/runner/memory-consolidation-driver.d.ts +4 -4
  94. package/dist/core/runner/memory-consolidation.d.ts +6 -8
  95. package/dist/core/runner/memory-consolidation.js +0 -1
  96. package/dist/core/runner/park-commit.d.ts +6 -6
  97. package/dist/core/runner/permission-rule-lanes.d.ts +19 -19
  98. package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -4
  99. package/dist/core/runner/prepare-artifact.d.ts +53 -0
  100. package/dist/core/runner/prepare-artifact.js +77 -0
  101. package/dist/core/runner/prepare-ask-lane.d.ts +3 -3
  102. package/dist/core/runner/prepare-boundary-parks.d.ts +3 -3
  103. package/dist/core/runner/prepare-caps-and-workflow.d.ts +9 -7
  104. package/dist/core/runner/prepare-caps-and-workflow.js +2 -3
  105. package/dist/core/runner/prepare-config-doors.d.ts +24 -24
  106. package/dist/core/runner/prepare-config-doors.js +5 -2
  107. package/dist/core/runner/prepare-context-lane.d.ts +8 -8
  108. package/dist/core/runner/prepare-context-lane.js +2 -13
  109. package/dist/core/runner/prepare-defer-classify.d.ts +2 -2
  110. package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
  111. package/dist/core/runner/prepare-file-history.d.ts +3 -3
  112. package/dist/core/runner/prepare-file-history.js +3 -52
  113. package/dist/core/runner/prepare-gate-stations.d.ts +5 -5
  114. package/dist/core/runner/prepare-hands-readface.d.ts +35 -38
  115. package/dist/core/runner/prepare-hands-readface.js +3 -2
  116. package/dist/core/runner/prepare-inherited-gate.d.ts +9 -6
  117. package/dist/core/runner/prepare-inherited-gate.js +7 -8
  118. package/dist/core/runner/prepare-listings.d.ts +3 -3
  119. package/dist/core/runner/prepare-lsp.d.ts +3 -3
  120. package/dist/core/runner/prepare-memory-engine-session.d.ts +5 -5
  121. package/dist/core/runner/prepare-memory.d.ts +4 -6
  122. package/dist/core/runner/prepare-memory.js +10 -9
  123. package/dist/core/runner/prepare-offload-wrappers.d.ts +2 -2
  124. package/dist/core/runner/prepare-park-ask.d.ts +6 -6
  125. package/dist/core/runner/prepare-policy-chain.d.ts +7 -7
  126. package/dist/core/runner/prepare-policy-chain.js +15 -30
  127. package/dist/core/runner/prepare-prompt-assembly.js +1 -1
  128. package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -5
  129. package/dist/core/runner/prepare-protocol-tools.d.ts +1 -1
  130. package/dist/core/runner/prepare-question-face.d.ts +4 -4
  131. package/dist/core/runner/prepare-run-refs.d.ts +11 -11
  132. package/dist/core/runner/prepare-safety-scan.d.ts +2 -2
  133. package/dist/core/runner/prepare-suspend-saga.d.ts +4 -4
  134. package/dist/core/runner/prepare-suspend-saga.js +0 -2
  135. package/dist/core/runner/prepare-task.d.ts +12 -12
  136. package/dist/core/runner/prepare-task.js +10 -9
  137. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +2 -3
  138. package/dist/core/runner/prepare-wiring-manifest.d.ts +4 -4
  139. package/dist/core/runner/prepare-wiring-manifest.js +9 -7
  140. package/dist/core/runner/prepare-workspace-restore.d.ts +1 -1
  141. package/dist/core/runner/remote-env-retry.d.ts +3 -3
  142. package/dist/core/runner/resume-admission.d.ts +1 -1
  143. package/dist/core/runner/resume-admission.js +2 -1
  144. package/dist/core/runner/resume-claim.d.ts +1 -1
  145. package/dist/core/runner/resume-internals-and-config.d.ts +1 -1
  146. package/dist/core/runner/resume-internals-and-config.js +4 -0
  147. package/dist/core/runner/resume-policy-outcome.d.ts +1 -1
  148. package/dist/core/runner/resume-preflight.d.ts +1 -1
  149. package/dist/core/runner/resume-review-outcome.d.ts +1 -1
  150. package/dist/core/runner/retired-runner-deps.d.ts +3 -0
  151. package/dist/core/runner/retired-runner-deps.js +7 -0
  152. package/dist/core/runner/run-brain-sinks.d.ts +1 -1
  153. package/dist/core/runner/run-clock-and-content.d.ts +4 -4
  154. package/dist/core/runner/run-compaction-machinery.d.ts +3 -3
  155. package/dist/core/runner/run-git-lane.d.ts +1 -1
  156. package/dist/core/runner/run-harness-handlers.d.ts +2 -2
  157. package/dist/core/runner/run-harness-handlers.js +2 -3
  158. package/dist/core/runner/run-identity-wiring.d.ts +4 -4
  159. package/dist/core/runner/run-leg.d.ts +3 -3
  160. package/dist/core/runner/run-notification-lane.d.ts +2 -2
  161. package/dist/core/runner/run-reasoning-seat.d.ts +2 -2
  162. package/dist/core/runner/run-settle-and-teardown.d.ts +5 -5
  163. package/dist/core/runner/run-settle-and-teardown.js +3 -1
  164. package/dist/core/runner/run-telemetry-and-budget-seats.d.ts +2 -2
  165. package/dist/core/runner/run-terminal-adoption.d.ts +5 -5
  166. package/dist/core/runner/runtask.d.ts +14 -14
  167. package/dist/core/runner/session-file-state-replay.d.ts +3 -3
  168. package/dist/core/runner/session-file-state-replay.js +3 -3
  169. package/dist/core/runner/session-rule-policy.d.ts +2 -2
  170. package/dist/core/runner/session-rule-policy.js +3 -4
  171. package/dist/core/runner/steer-admission.d.ts +2 -2
  172. package/dist/core/runner/stream-halt-verbs.d.ts +1 -1
  173. package/dist/core/runner/stream-halt-verbs.js +1 -1
  174. package/dist/core/runner/stream-reap.d.ts +1 -1
  175. package/dist/core/runner/stream-steer-verb.js +1 -4
  176. package/dist/core/runner/synthetic-tools.d.ts +8 -8
  177. package/dist/core/runner/teardown-bounded.d.ts +2 -2
  178. package/dist/core/runner/tool-defer-gate.d.ts +1 -1
  179. package/dist/core/runner/tool-disclosure.d.ts +33 -33
  180. package/dist/core/runner/tool-end-body.d.ts +3 -3
  181. package/dist/core/runner/tool-face-overlay.d.ts +2 -2
  182. package/dist/core/runner/tool-output-projection.d.ts +2 -2
  183. package/dist/core/runner/turn-attachments.d.ts +53 -53
  184. package/dist/core/runner/usage-accounting.d.ts +4 -4
  185. package/dist/core/runner/workspace-path.d.ts +1 -1
  186. package/dist/core/runner/workspace-path.js +3 -0
  187. package/dist/core/runner-deps.d.ts +30 -49
  188. package/dist/core/safe-notify.d.ts +1 -1
  189. package/dist/core/sensitive-path-policy.d.ts +1 -1
  190. package/dist/core/sensitive-path-policy.js +4 -4
  191. package/dist/core/session.d.ts +2 -2
  192. package/dist/core/skill-tool-specifier.d.ts +1 -1
  193. package/dist/core/skills-directory.d.ts +1 -1
  194. package/dist/core/store-contracts/checkpoint-store-contract.js +1 -1
  195. package/dist/core/strategy-store.d.ts +8 -11
  196. package/dist/core/task-event.d.ts +20 -17
  197. package/dist/core/task-limits.d.ts +1 -1
  198. package/dist/core/task-notification.d.ts +5 -5
  199. package/dist/core/task-registry-agent.d.ts +5 -5
  200. package/dist/core/task-registry-monitor.d.ts +2 -2
  201. package/dist/core/task-registry-shared.d.ts +27 -27
  202. package/dist/core/task-registry-shared.js +3 -13
  203. package/dist/core/task-registry.d.ts +8 -8
  204. package/dist/core/task-result.d.ts +37 -37
  205. package/dist/core/task-spec.d.ts +5 -5
  206. package/dist/core/task-stream.d.ts +16 -11
  207. package/dist/core/tool-catalog-entries.d.ts +1 -0
  208. package/dist/core/tool-catalog-entries.js +5 -0
  209. package/dist/core/tool-conformance.d.ts +0 -2
  210. package/dist/core/tool-conformance.js +1 -3
  211. package/dist/core/tool-errors.d.ts +5 -0
  212. package/dist/core/tool-errors.js +1 -0
  213. package/dist/core/tool-policy.d.ts +51 -22
  214. package/dist/core/tool-policy.js +28 -5
  215. package/dist/core/tool-result-budget.d.ts +1 -1
  216. package/dist/core/tool-result-store.d.ts +11 -11
  217. package/dist/core/tool-spec.d.ts +34 -38
  218. package/dist/core/tools.d.ts +2 -2
  219. package/dist/core/trace.d.ts +12 -15
  220. package/dist/core/untrusted-text.d.ts +1 -1
  221. package/dist/core/wiring-manifest.d.ts +4 -3
  222. package/dist/core/workflow-journal-store.d.ts +11 -11
  223. package/dist/engine/execution-env/node-execution-env.d.ts +3 -2
  224. package/dist/engine/execution-env/node-execution-env.js +4 -2
  225. package/dist/engine/harness/agent-harness.d.ts +47 -4
  226. package/dist/engine/harness/agent-harness.js +52 -9
  227. package/dist/engine/llm/types.d.ts +1 -1
  228. package/dist/engine/loop/agent-loop.js +15 -8
  229. package/dist/engine/loop/types.d.ts +5 -0
  230. package/dist/index.d.ts +21 -16
  231. package/dist/index.js +17 -12
  232. package/dist/internal/harness.d.ts +1 -0
  233. package/dist/orchestration/run-spec.d.ts +3 -0
  234. package/dist/orchestration/run-spec.js +3 -3
  235. package/dist/orchestration/run-workflow-tool.d.ts +12 -6
  236. package/dist/orchestration/run-workflow-tool.js +23 -5
  237. package/dist/orchestration/workflow-primitives.d.ts +4 -2
  238. package/dist/orchestration/workflow-primitives.js +1 -4
  239. package/dist/orchestration/workflow-types.d.ts +34 -4
  240. package/dist/orchestration/workflow-types.js +2 -0
  241. package/dist/orchestration/workflow.d.ts +39 -7
  242. package/dist/orchestration/workflow.js +234 -113
  243. package/dist/prompt-assembly/assemble.d.ts +2 -2
  244. package/dist/prompt-assembly/assemble.js +9 -9
  245. package/dist/prompt-assembly/composer.d.ts +6 -7
  246. package/dist/prompt-assembly/composer.js +10 -10
  247. package/dist/prompt-assembly/epoch.js +1 -1
  248. package/dist/prompt-assembly/event-registry.d.ts +0 -21
  249. package/dist/prompt-assembly/packs/sema-default.js +30 -30
  250. package/dist/prompt-assembly/types.d.ts +14 -14
  251. package/dist/prompts/coordinator.d.ts +0 -13
  252. package/dist/prompts/coordinator.js +0 -3
  253. package/dist/stores/file/checkpoint-store.js +1 -5
  254. package/dist/stores/file/file-history-store.js +2 -2
  255. package/dist/stores/file/permission-rule-store.d.ts +4 -35
  256. package/dist/stores/file/permission-rule-store.js +4 -148
  257. package/dist/tools/artifact/artifact-text.d.ts +62 -0
  258. package/dist/tools/artifact/artifact-text.js +68 -0
  259. package/dist/tools/artifact/artifact-tool.d.ts +52 -0
  260. package/dist/tools/artifact/artifact-tool.js +351 -0
  261. package/dist/tools/artifact/local-stub.d.ts +26 -0
  262. package/dist/tools/artifact/local-stub.js +296 -0
  263. package/dist/tools/fs/bash-readonly-classifier.d.ts +114 -48
  264. package/dist/tools/fs/bash-readonly-classifier.js +171 -60
  265. package/dist/tools/fs/encoding.d.ts +31 -40
  266. package/dist/tools/fs/fs-bash.d.ts +49 -45
  267. package/dist/tools/fs/fs-bash.js +19 -27
  268. package/dist/tools/fs/fs-pdf.d.ts +8 -8
  269. package/dist/tools/fs/fs-search-tools.d.ts +4 -4
  270. package/dist/tools/fs/fs-search-tools.js +5 -2
  271. package/dist/tools/fs/fs-shared.d.ts +146 -158
  272. package/dist/tools/fs/fs-shared.js +3 -11
  273. package/dist/tools/fs/fs-write.d.ts +8 -8
  274. package/dist/tools/fs/gh-rate-limit.d.ts +13 -14
  275. package/dist/tools/fs/index.d.ts +78 -78
  276. package/dist/tools/fs/index.js +4 -1
  277. package/dist/tools/fs/notebook.d.ts +24 -25
  278. package/dist/tools/fs/pdf.d.ts +3 -3
  279. package/dist/tools/fs/read-deny.d.ts +22 -22
  280. package/dist/tools/fs/read-face.d.ts +21 -24
  281. package/dist/tools/fs/repo-map.d.ts +8 -8
  282. package/dist/tools/fs/safety.d.ts +233 -130
  283. package/dist/tools/fs/safety.js +131 -31
  284. package/dist/tools/fs/search.d.ts +63 -71
  285. package/dist/tools/fs/search.js +8 -6
  286. package/package.json +6 -2
  287. package/test/export-surface.snapshot.json +119 -39
@@ -1,8 +1,9 @@
1
1
  import { forkGovernanceDenial, resolveDelegationEntryCaps } from "../../agents/subagent.js";
2
2
  import { isLiveQuestionFace } from "../ask-question.js";
3
+ import { parentSpecSeatOf } from "../parent-spec-seat.js";
3
4
  import { createPreToolUseConstraintPolicy } from "../hooks.js";
4
5
  import { StubExecutionEnv } from "../stub-env.js";
5
- import { askApproverIdentity, isLiveApproverSeat } from "../tool-policy.js";
6
+ import { askApproverIdentity, durableMandateSourceOf } from "../tool-policy.js";
6
7
  import { attachRebuiltDenialTrackers, createDenialLimitStop } from "./denial-limit-arms.js";
7
8
  export function prepareInheritedGate(input) {
8
9
  const { spec, deps, internals, resume, sessions, sessionId, runId, hostTaskId, taskRootFinal, executionEnv, ownedEnv, lockedPreflight, toolFaceSnapshot, promptProfile, resolvedInteractionPosture, autoModeSeat, handsEnabled, reportUsage, harnessRef, skillScope, forwardEvent, subagentRetain, worktreeIsolation, requestReview, requestStopAfterTurn, enterPlanMode, reminderMark, reminderDisclosureCounts, fileHistoryEnabled, historyScope, historyRoot, historyFs, abortRun } = input;
@@ -93,6 +94,7 @@ export function prepareInheritedGate(input) {
93
94
  }
94
95
  };
95
96
  const frozenOnQuestion = spec.onQuestion ?? deps.onQuestion;
97
+ const parentSpecSeat = parentSpecSeatOf(spec, frozenOnQuestion);
96
98
  const provenanceForChildrenRef = {};
97
99
  const delegationProvenanceForChildren = () => provenanceForChildrenRef.current;
98
100
  const delegationSettlementRef = {};
@@ -106,8 +108,7 @@ export function prepareInheritedGate(input) {
106
108
  ...(ownSessionRulesRef.current !== undefined ? [ownSessionRulesRef.current] : []),
107
109
  ];
108
110
  const ownCallerPolicy = lockedPreflight.toolPolicy;
109
- const durableMandate = input.runtimeCaps()?.forceDurableGate === true ||
110
- (spec.durableApproval !== undefined && !isLiveApproverSeat(frozenOnAsk));
111
+ const durableMandate = durableMandateSourceOf({ forceDurableGate: input.runtimeCaps()?.forceDurableGate === true, durableApprovalDeclared: spec.durableApproval !== undefined, onAsk: frozenOnAsk }) !== undefined;
111
112
  const contentMandate = input.runtimeCaps()?.forceDurableGate === true ||
112
113
  (spec.durableApproval !== undefined && !isLiveQuestionFace(frozenOnQuestion));
113
114
  const ownPreToolUse = input.preToolUseObservational() ? undefined : input.hooks()?.preToolUse;
@@ -186,15 +187,13 @@ export function prepareInheritedGate(input) {
186
187
  ...(readDenyAdditionsNormalized.length > 0 ? { readDenyPatterns: Object.freeze(readDenyAdditionsNormalized.map((e) => ({ ...e }))) } : {}),
187
188
  ...(spec.interactiveTools === false ? { interactiveTools: false } : {}),
188
189
  oneShot: spec.oneShot,
189
- clientContext: spec.clientContext,
190
+ parentSpecSeat,
191
+ ...(internals?.questionFaceStripped === true ? { questionFaceStripped: true } : {}),
190
192
  excludeTools: toolFaceSnapshot.exclude,
191
193
  deferTools: toolFaceSnapshot.defer,
192
194
  alwaysLoadTools: toolFaceSnapshot.alwaysLoad,
193
195
  ...(toolFaceSnapshot.restoreGated !== undefined ? { restoreGatedTools: toolFaceSnapshot.restoreGated } : {}),
194
196
  promptProfile,
195
- ...(spec.additionalDirectories !== undefined ? { additionalDirectories: Object.freeze([...spec.additionalDirectories]) } : {}),
196
- ...(spec.additionalReadDirectories !== undefined ? { additionalReadDirectories: Object.freeze([...spec.additionalReadDirectories]) } : {}),
197
- ...(spec.envFacts !== undefined ? { envFacts: { ...spec.envFacts } } : {}),
198
197
  ...(spec.memoryPersistenceCapable !== undefined ? { memoryPersistenceCapable: spec.memoryPersistenceCapable } : {}),
199
198
  get memoryCaptureOptedOut() {
200
199
  return input.memoryEngineSession()?.captureOptOut?.optedOut() ?? false;
@@ -263,5 +262,5 @@ export function prepareInheritedGate(input) {
263
262
  ...(spec.enablePlanMode === true ? { enterPlanMode } : {}),
264
263
  };
265
264
  };
266
- return { liveInheritedGate, seedInheritedGate, inheritedAncestorRules, inheritedShellGate, inheritedParentConstraints, autoModeIntent, inheritedAdmittedOrgScopes, priorOwnOrgVerdict, orgGovernedProvenance, effectiveShellGate, ownSessionRulesRef, memoryAdmittedOrgScopesRef, ownOrgVerdictRef, orgAdmissionCheckpointState, faceCheckpointSection, faceCheckpointState, f012CheckpointState, frozenOnAsk, hookEnvSource, notifyOwnHookCrash, frozenOnQuestion, provenanceForChildrenRef, delegationSettlementRef, inheritedGateForChildren, carrierReadFace, fullShellReachable, gateStopRef, stopForDenialLimit, enrichSpecToolCtx };
265
+ return { liveInheritedGate, seedInheritedGate, inheritedAncestorRules, inheritedShellGate, inheritedParentConstraints, autoModeIntent, inheritedAdmittedOrgScopes, priorOwnOrgVerdict, orgGovernedProvenance, effectiveShellGate, ownSessionRulesRef, memoryAdmittedOrgScopesRef, ownOrgVerdictRef, orgAdmissionCheckpointState, faceCheckpointSection, faceCheckpointState, f012CheckpointState, frozenOnAsk, hookEnvSource, notifyOwnHookCrash, frozenOnQuestion, parentSpecSeat, provenanceForChildrenRef, delegationSettlementRef, inheritedGateForChildren, carrierReadFace, fullShellReachable, gateStopRef, stopForDenialLimit, enrichSpecToolCtx };
267
266
  }
@@ -1,13 +1,13 @@
1
1
  /**
2
- * design/390 M15 — prepareTask's LISTINGS phase: the per-task agent definitions' tool-name audit
2
+ * PrepareTask's LISTINGS phase: the per-task agent definitions' tool-name audit
3
3
  * (deny entries fail loud, allow entries advise), the agent-listing announce face read off the
4
4
  * delegation tool's roster (with its deferred / excluded / removal-to-zero arms), the two listing
5
5
  * opt-out advisories, the announced-listings mirror seeded from the once-per-session ledger, the
6
6
  * deferred roster's ToolSearch ride, and the date_change seam. The body is the driver's stretch moved
7
- * verbatim; the interface is the dependency list it had implicitly (design/238 R-1).
7
+ * verbatim; the interface is the dependency list it had implicitly.
8
8
  *
9
9
  * SYNCHRONOUS FUNCTION, SYNCHRONOUS CALL: the stretch has no await, so the phase adds no yield between
10
- * the disclosure mount before it and the context-lane seats after it (design/390 §1.5 S1: a stretch
10
+ * the disclosure mount before it and the context-lane seats after it (a stretch
11
11
  * with no await is extracted as a sync function — an `async` wrapper would open a microtask window).
12
12
  *
13
13
  * Throws pass through unchanged: `config.agent.unknown_tool` (a deny entry naming a tool this
@@ -1,13 +1,13 @@
1
1
  /**
2
- * design/390 §1.2 M8 — prepareTask's LSP phase, verbatim from the driver: the manager fold (spec > deps), the
2
+ * PrepareTask's LSP phase, verbatim from the driver: the manager fold (spec > deps), the
3
3
  * LSP tool mount over the per-task env with its git-ignore filter, the diagnostics lane behind its four
4
4
  * preconditions (a manager whose sessions feed a registry, write-capable hands, not opted out), the run-scoped
5
5
  * registry key, and the edit nudge (raw path → the SAME resolution the tool leg uses → registry reset +
6
6
  * session didChange). No manager ⇒ nothing mounts and both lane seats are undefined. The interface is the
7
- * dependency list the segment had implicitly (design/238 R-1).
7
+ * dependency list the segment had implicitly.
8
8
  *
9
9
  * SYNCHRONOUS FUNCTION, SYNCHRONOUS CALL: the stretch has no await, so the phase adds no yield between the
10
- * fork-governance note before it and the memory trio's occupancy read after it (design/390 §1.5 S1: a stretch
10
+ * fork-governance note before it and the memory trio's occupancy read after it (a stretch
11
11
  * with no await is extracted as a sync function — an `async` wrapper would open a microtask window).
12
12
  * Read-stability of the host handles for the call: {@link RunInternals} (`@contract prepare.deps-read-stable`).
13
13
  */
@@ -1,16 +1,16 @@
1
1
  /**
2
- * design/390 §1.2 M12 — prepareTask's MEMORY-ENGINE-SESSION phase, verbatim from the driver: the content-origin
3
- * classification + one-way session pollution wrap section (design/178 §3 / design/180 half A / design/324 /
4
- * design/336 §3.3 + §5.5 / design/378 D-4 / design/380 O9a). Its arming predicate (a mounted memory session OR an
2
+ * PrepareTask's MEMORY-ENGINE-SESSION phase, verbatim from the driver: the content-origin
3
+ * classification + one-way session pollution wrap section (consolidating several design threads).
4
+ * Its arming predicate (a mounted memory session OR an
5
5
  * upstream recorder channel), the chain-narrowed classification config, the children's provenance seat, the
6
6
  * declared-MCP-class announcement, the settlement seat, the per-tool wrap with its three record verbs (mark /
7
7
  * recordExternal / recordIncomplete), the Read tool's recall-taint arm and the delegation arm's three-valued
8
8
  * attestation judgment all live here; the announcement helper only this section called moved with it. The
9
- * interface is the dependency list the segment had implicitly (design/238 R-1).
9
+ * interface is the dependency list the segment had implicitly.
10
10
  *
11
11
  * SYNCHRONOUS FUNCTION, SYNCHRONOUS CALL: the stretch has no await of its own (the awaits sit inside the wrappers it
12
12
  * installs, which run at tool-call time), so the phase adds no yield between the deferred classification before it
13
- * and the prompt assembly after it (design/390 §1.5: a stretch with no await is extracted as a sync function).
13
+ * and the prompt assembly after it (a stretch with no await is extracted as a sync function).
14
14
  * Read-stability of the host handles for the call: {@link RunInternals} (`@contract prepare.deps-read-stable`).
15
15
  *
16
16
  * One read changed spelling and nothing else: the declared-class announcement read `mcp?.statuses` while `mcp` had
@@ -18,12 +18,6 @@ export interface PrepareMemoryInput {
18
18
  /** borrowed-readonly — the resolved task root: the containment boundary every derived memory dir
19
19
  * is checked against, and the repo-root fallback when `deps.rootPath` is unset. */
20
20
  taskRootPath: string;
21
- /** borrowed-mutable — the caller's write-gate cell, and THIS phase is its writer: it installs the
22
- * memory write gate into `.current` (the module header's one out-param effect). Identity is the
23
- * contract — the caller's hands/read-face seat reads this exact cell. */
24
- memoryWriteGateRef: {
25
- current?: BeforeWriteHook;
26
- };
27
21
  /**
28
22
  * borrowed-readonly — #181-F5: whether a tool NAMED `Write` (the tool the CC `# Memory` instruction names) is on the
29
23
  * ASSEMBLED roster this run, not excluded, AND can actually REACH the host-side memory root:
@@ -199,6 +193,10 @@ export interface MemoryInjectionComposition {
199
193
  export interface PrepareMemoryResult {
200
194
  memoryEngineSession: Prepared["memoryEngineSession"];
201
195
  memoryTools?: ToolSpec[];
196
+ /** owned — the memory WRITE gate (Write/Edit/NotebookEdit run their FINAL text through MemoryEngine.gateWrite when
197
+ * the target lands inside the memory writable root; the read-only plane refuses its own domain). Present iff a memory
198
+ * engine mounted; the hands phase composes it into the band's beforeWrite (a memory-less run: every write passes). */
199
+ memoryWriteGate?: BeforeWriteHook;
202
200
  /**
203
201
  * owned — #691: the injection's COMPOSITION step, run by the driver AFTER the hands phase (the mount above runs
204
202
  * BEFORE it). It performs the one destructive read this phase has — `inject()` drains the announcement queue —
@@ -10,9 +10,11 @@ import { readSessionCaptureOptOut } from "../memory-engine/layout.js";
10
10
  import { createMemoryEngineTools } from "../memory-engine/tools.js";
11
11
  import { assertScopeContractPlacement, parseScopeKey, resolveProjectId } from "../memory-engine/scope-contract.js";
12
12
  import { FileMemoryEngineBackend } from "../memory-engine/file-backend.js";
13
+ import { writableRootOf } from "../memory-engine/types.js";
13
14
  let undeclaredCapturePostureAnnounced = false;
14
15
  export async function prepareMemory(input) {
15
- const { spec, deps, sessionId, taskRootPath, memoryWriteGateRef, admissionCtx } = input;
16
+ const { spec, deps, sessionId, taskRootPath, admissionCtx } = input;
17
+ let memoryWriteGate;
16
18
  const memorySpec = normalizeMemorySpec(spec.memory);
17
19
  let admittedOrgScopes = [];
18
20
  let ownOrgVerdict;
@@ -460,21 +462,19 @@ export async function prepareMemory(input) {
460
462
  }
461
463
  const foreignUnderRoot = [];
462
464
  if (input.writeToolsMounted && writeHandle.writeScope !== null && input.advertisedWritableDirs !== undefined) {
463
- for (const d of [...writeEngine.readonlyDirNamesUnderRoot(writeHandle)].sort())
464
- foreignUnderRoot.push(`another scope's directory ${d}`);
465
465
  const controlPlane = canonicalize(writeEngine.controlPlaneDir);
466
- if (isContainedIn(writeHandle.writableRoot, controlPlane))
466
+ if (isContainedIn(writableRootOf(writeHandle), controlPlane))
467
467
  foreignUnderRoot.push(`the engine's control plane ${controlPlane}`);
468
468
  }
469
469
  if (foreignUnderRoot.length > 0) {
470
- deps.onError?.(new Error(`memory advertised writable directory refused: the write scope's root ${writeHandle.writableRoot} contains what is not the model's to touch (${foreignUnderRoot.join("; ")}) — the file tools' root fence is directory-granular, so admitting it would expose those files; memory writes through the file tools stay closed this session and the write instruction is not taught.`), { phase: "config", sessionId });
470
+ deps.onError?.(new Error(`memory advertised writable directory refused: the write scope's root ${writableRootOf(writeHandle)} contains what is not the model's to touch (${foreignUnderRoot.join("; ")}) — the file tools' root fence is directory-granular, so admitting it would expose those files; memory writes through the file tools stay closed this session and the write instruction is not taught.`), { phase: "config", sessionId });
471
471
  }
472
472
  writeChannelOpen =
473
473
  input.writeToolsMounted &&
474
474
  writeHandle.writeScope !== null &&
475
475
  foreignUnderRoot.length === 0 &&
476
- (input.advertisedWritableDirs === undefined || (await input.advertisedWritableDirs.admit({ path: writeHandle.writableRoot, advertiser: "memory", expectCanonical: writeHandle.writableRoot })));
477
- memoryWriteGateRef.current = async (w) => {
476
+ (input.advertisedWritableDirs === undefined || (await input.advertisedWritableDirs.admit({ path: writableRootOf(writeHandle), advertiser: "memory", expectCanonical: writableRootOf(writeHandle) })));
477
+ memoryWriteGate = async (w) => {
478
478
  if (readOnlyEngine !== undefined && readOnlyHandle !== undefined) {
479
479
  const ro = readOnlyEngine.gateWrite(readOnlyHandle, w.key, w.content);
480
480
  if (!ro.ok)
@@ -482,7 +482,7 @@ export async function prepareMemory(input) {
482
482
  }
483
483
  if (input.memoryPersistenceDeclared === false) {
484
484
  const root = writeHandle.writableRoot;
485
- if (w.key === root || w.key.startsWith(`${root}${sep}`)) {
485
+ if (root !== null && (w.key === root || w.key.startsWith(`${root}${sep}`))) {
486
486
  return {
487
487
  ok: false,
488
488
  code: "read_only_layering",
@@ -493,7 +493,7 @@ export async function prepareMemory(input) {
493
493
  }
494
494
  {
495
495
  const root = writeHandle.writableRoot;
496
- if (w.key === root || w.key.startsWith(`${root}${sep}`)) {
496
+ if (root !== null && (w.key === root || w.key.startsWith(`${root}${sep}`))) {
497
497
  const state = captureOptedOut ? { record: { at: 0, reason: "in-run state" }, fault: false } : await writeEngine.sessionCaptureOptOutOrFault(sessionId);
498
498
  if (state.record !== undefined || state.fault) {
499
499
  return {
@@ -777,6 +777,7 @@ export async function prepareMemory(input) {
777
777
  ownOrgVerdict,
778
778
  effectiveMemoryScopes,
779
779
  ...(memoryTools !== undefined ? { memoryTools } : {}),
780
+ ...(memoryWriteGate !== undefined ? { memoryWriteGate } : {}),
780
781
  composeInjection,
781
782
  };
782
783
  }
@@ -1,11 +1,11 @@
1
1
  /**
2
- * design/390 §1.2 M0 (the offload half of the prelude) — prepareTask's nested-usage accumulator, the
2
+ * (The offload half of the prelude) — prepareTask's nested-usage accumulator, the
3
3
  * large-tool-result offload store resolution and the THREE offload wrappers every later mount site
4
4
  * applies (caller tools, first-party hand tools, remote MCP/A2A peers), verbatim from the driver.
5
5
  *
6
6
  * SYNCHRONOUS by construction: the segment held no await in the driver, and a phase that yields where
7
7
  * the driver did not would open a microtask window between two steps that used to be adjacent (the
8
- * design/238 T1 posture). Nothing here touches the store — the wrappers close over it and only the
8
+ * posture). Nothing here touches the store — the wrappers close over it and only the
9
9
  * wrapped tools' `execute` reach it, at run time.
10
10
  *
11
11
  * What stays in the driver: the trust-axis choice of `offloadScope` (`spec.principal ?? "default"`)
@@ -1,11 +1,11 @@
1
1
  /**
2
- * design/390 §1.2 M19 (park ask) — prepareTask's PARK CLOSURE and CONTENT-ASK ROUTING closure, verbatim from the driver's
2
+ * PrepareTask's PARK CLOSURE and CONTENT-ASK ROUTING closure, verbatim from the driver's
3
3
  * gate-machinery block: `resolveContentAsk` (the question face's delivery race, the binding table's cap and redemption
4
4
  * identity, the stranded-answer disclosure) and `suspendAsk` (the sync-first decline and the park-priority mandates, the
5
5
  * args capture / fidelity projection / re-adjudication steps, the pause-then-cut fence, the gate-kind choice, the row
6
6
  * mint, the commit through the saga and the post-commit publication). The one module-scope helper only this segment
7
- * threw (`ParkRefusal`) moved with it. The interface is the dependency list the segment had implicitly (design/238
8
- * R-1) — the two closures used to capture every seat here off the driver's scope, which is the capture surface this
7
+ * threw (`ParkRefusal`) moved with it. The interface is the dependency list the segment had implicitly
8
+ * — the two closures used to capture every seat here off the driver's scope, which is the capture surface this
9
9
  * decomposition exists to make explicit.
10
10
  *
11
11
  * The thirteen-argument park closure is unchanged: twelve positional seats then the structural {@link AskCarry}, the
@@ -13,7 +13,7 @@
13
13
  * carry onto the row exactly as before — this phase mints no origin, changes no word, adds no arm to the closed set.
14
14
  *
15
15
  * SYNCHRONOUS FUNCTION, SYNCHRONOUS CALL: the stretch has no await of its own (both closures run per tool call), so the
16
- * phase adds no yield between the boundary parks before it and the gate station after it (design/390 §1.5).
16
+ * phase adds no yield between the boundary parks before it and the gate station after it.
17
17
  * Read-stability of the host handles for the call: {@link RunInternals} (`@contract prepare.deps-read-stable`).
18
18
  *
19
19
  * Both closures exist exactly when the ask lane and the saga do (the same predicate) — an absent lane answers two absent
@@ -50,7 +50,7 @@ export interface PrepareParkAskInput {
50
50
  /** borrowed-readonly — the leg's checkpoint store, or undefined (then `suspendAsk` is absent — the park predicate's store
51
51
  * term). Read: the declared fidelity; the saga writes to it. */
52
52
  checkpointStore: CheckpointStore | undefined;
53
- /** borrowed-readonly — the leg's delta seat (design/388 B18): the park reads the gated tool's identity off its
53
+ /** borrowed-readonly — the leg's delta seat (B18): the park reads the gated tool's identity off its
54
54
  * CURRENT roster snapshot so the row carries who the action was minted against. */
55
55
  toolRosterDeltas: ToolRosterDeltaSeat;
56
56
  /** borrowed-readonly — the wiring-manifest phase's park predicate (`parkLane.effective`): arms `suspendAsk`. */
@@ -155,7 +155,7 @@ export interface PrepareParkAskResult {
155
155
  /** The M19 park-ask phase body — prepareTask's park closure and content-ask routing stretch, verbatim (see the module header). */
156
156
  export declare function prepareParkAsk(input: PrepareParkAskInput): PrepareParkAskResult;
157
157
  /**
158
- * From the resumed/active transcript, the batch position of `currentId` (design/45 §4.ter): the tool-call
158
+ * From the resumed/active transcript, the batch position of `currentId`: the tool-call
159
159
  * ids of the assistant message that issued it (the batch), and the subset already resolved (executed
160
160
  * before the suspend — #1..k-1). ID-based, not positional (council Question #1): immune to reordering.
161
161
  */
@@ -1,14 +1,14 @@
1
1
  /**
2
- * design/390 §1.2 M17 (design/238 P21) — prepareTask's POLICY-CHAIN phase, verbatim from the driver: the caller policy
2
+ * PrepareTask's POLICY-CHAIN phase, verbatim from the driver: the caller policy
3
3
  * and its name audit (advisory once per deployment; the two hard refusals), the session / ancestor / frozen-projection /
4
4
  * skill-scope deny-narrowing layers and their fold, the resume-edit base policy, the hook record with its timeout seat
5
5
  * and observational half, the same-instance arbitration machinery (the caller slot's first-decision record), the
6
- * inherited-unavailable marker channel, the RB-40 grant record, the sandbox-admission mode's arming and its three
6
+ * inherited-unavailable marker channel, the grant record, the sandbox-admission mode's arming and its three
7
7
  * sideband maps, the source-identity and risk-axes factories, the two permission-rule lanes and the rule-offer
8
8
  * factory, the approved-edit re-check, the inherited-constraint wrappers (the same-instance adapter and the true
9
9
  * wrapper), the rewrite-emitter index and the instrumented chain, the integrity guards, the fold, and the final-form
10
10
  * re-check that is the effective policy. The advised-names dedupe pair only this section reads moved with it.
11
- * The interface is the dependency list the segment had implicitly (design/238 R-1).
11
+ * The interface is the dependency list the segment had implicitly.
12
12
  *
13
13
  * ASYNC PHASE: the stretch awaits the session-policy store (the task's own rules and each ancestor's live re-read)
14
14
  * exactly where the segment did; the closures it builds await at tool-call time. The phase boundary adds one
@@ -75,9 +75,9 @@ export interface PreparePolicyChainInput {
75
75
  irreversible?: false;
76
76
  egress?: false;
77
77
  }>;
78
- /** borrowed-readonly — the caller tools' names, the first-await snapshot (the sandbox boundary predicate: a caller tool
79
- * is never contained by the hand tools' env). */
80
- ownToolNames: ReadonlySet<string>;
78
+ /** borrowed-readonly — the ENGINE HAND roster: every tool whose effect dispatches through the task's execution env,
79
+ * membership minted at the mount sites (the sandbox boundary predicate's one containment fact). */
80
+ envHandToolNames: ReadonlySet<string>;
81
81
  /** borrowed-readonly — the shell-seat provenance set (the offer factory's `shellGated` mandate term, read per call). */
82
82
  shellGatedTools: ReadonlySet<string>;
83
83
  /** borrowed-readonly — the tracked-cwd seat, read per call by the lanes and the offer factory (never written here). */
@@ -148,7 +148,7 @@ export interface PreparePolicyChainResult {
148
148
  /** borrowed-mutable — the inherited-unavailable marker channel. Writers: the inherited arms here (mark); the gate station
149
149
  * (the lifecycle-end sweep) and the park lane's consumers (delete on consumption). */
150
150
  inheritedUnavailableAsks: Set<string>;
151
- /** borrowed-mutable — the RB-40 grant record. Writers: the inherited arms here (record a clean allow at a live approver);
151
+ /** borrowed-mutable — the grant record. Writers: the inherited arms here (record a clean allow at a live approver);
152
152
  * the gate station (consume on reuse, sweep at settlement). */
153
153
  inheritedAskGrants: Map<string, {
154
154
  approver: unknown;
@@ -1,11 +1,10 @@
1
- import { SEND_MESSAGE_TOOL_NAME } from "../../agents/send-message-tool.js";
2
1
  import { policyAskClassOf } from "../ask-class.js";
3
2
  import { ASK_USER_QUESTION_TOOL_NAME } from "../ask-question.js";
4
3
  import { resolveCheckpointStore } from "../checkpoint-store.js";
5
4
  import { cloneObserverInput, resolveHookTimeoutMs } from "../hooks.js";
6
5
  import { isNamespacedCoveringRuleName, namespacedRuleNameCovers } from "../permission-rules.js";
7
6
  import { isIsolated } from "../remote-env.js";
8
- import { askApproverIdentity, carryEngineAttestations, carryPrecedingSettlement, checkToolPolicyProjection, combinePolicies, createTranscriptIntegrityPolicy, createUnverifiableDeletePolicy, isLiveApproverSeat, resolveAsk, toolPolicyNameSets } from "../tool-policy.js";
7
+ import { askApproverIdentity, carryEngineAttestations, carryPrecedingSettlement, checkToolPolicyProjection, combinePolicies, createTranscriptIntegrityPolicy, createUnverifiableDeletePolicy, isLiveApproverSeat, resolveAsk, toolPolicyNameSets, attestAskUnresolvableCause } from "../tool-policy.js";
9
8
  import { RETIRED_TOOL_NAMES } from "../tool-name-aliases.js";
10
9
  import { NAMESPACED_NAME_SHAPES, protocolOf } from "../protocol-table.js";
11
10
  import { emitTrace } from "../trace.js";
@@ -16,7 +15,7 @@ import { askGrantShapeOf } from "./inherited-ask-grants.js";
16
15
  import { createPermissionRuleLanes, inheritedAskRuleEvidence, createRuleOffersOf } from "./permission-rule-lanes.js";
17
16
  import { createSessionRulePolicy } from "./session-rule-policy.js";
18
17
  export async function preparePolicyChain(input) {
19
- const { spec, deps, internals, sessionId, runId, hostTaskId, taskRootFinal, executionEnv, lockedPreflight, tools, harnessTools, toolEffects, egressTools, irreversibilityTier, axisExplicitNegatives, ownToolNames, shellGatedTools, handsCwdRef, readDenyMatcher, questionToolMounted, runtimeCaps, inheritedAncestorRules, inheritedParentConstraints, seedInheritedGate, hasSkillManifest, skillScope, frozenOnAsk, hookEnvSource, notifyOwnHookCrash, autoModeDecider, stopForDenialLimit, delegation, abortController, now, ownSessionRulesRef } = input;
18
+ const { spec, deps, internals, sessionId, runId, hostTaskId, taskRootFinal, executionEnv, lockedPreflight, tools, harnessTools, toolEffects, egressTools, irreversibilityTier, axisExplicitNegatives, shellGatedTools, envHandToolNames, handsCwdRef, readDenyMatcher, questionToolMounted, runtimeCaps, inheritedAncestorRules, inheritedParentConstraints, seedInheritedGate, hasSkillManifest, skillScope, frozenOnAsk, hookEnvSource, notifyOwnHookCrash, autoModeDecider, stopForDenialLimit, delegation, abortController, now, ownSessionRulesRef } = input;
20
19
  const policy = lockedPreflight.toolPolicy;
21
20
  const auditPolicyNames = (auditee) => {
22
21
  const nameGroups = toolPolicyNameSets(auditee);
@@ -144,6 +143,12 @@ export async function preparePolicyChain(input) {
144
143
  inheritedUnavailableAsks.add(toolCallId);
145
144
  return true;
146
145
  };
146
+ const mandatedCallFloats = (toolCallId) => resolveCheckpointStore(spec, deps) !== undefined && (spec.durableApproval !== undefined || runtimeCaps?.forceDurableGate === true) && markInheritedUnavailable(toolCallId);
147
+ const mandateUnreconstructibleDeny = (creq) => attestAskUnresolvableCause({
148
+ action: "deny",
149
+ message: `inherited parent policy requires durable approval for "${creq.toolName}" — the parent's durable ask cannot be reconstructed in a delegated child; denied fail-closed (tighten-only)`,
150
+ }, "mandate_unreconstructible", creq);
151
+ const markerChannelFullDeny = (creq) => attestAskUnresolvableCause({ action: "deny", message: `no approver is reachable for the inherited approval of "${creq.toolName}" and the marker channel is at capacity — denied fail-closed` }, "approver_unavailable", creq);
147
152
  const inheritedAskGrants = new Map();
148
153
  const recordInheritedAskGrant = (toolCallId, approver, presented, waitMs) => {
149
154
  if (typeof approver !== "function")
@@ -190,7 +195,7 @@ export async function preparePolicyChain(input) {
190
195
  list.push({ cls, layer });
191
196
  foldAskClasses.set(toolCallId, list);
192
197
  };
193
- const sandboxBoundaryCapable = (toolName) => egressTools.has(toolName) || toolName.includes("__") || ownToolNames.has(toolName) || toolName === SEND_MESSAGE_TOOL_NAME;
198
+ const sandboxBoundaryCapable = (toolName) => egressTools.has(toolName) || !envHandToolNames.has(toolName);
194
199
  const emitSandboxAdmitted = (info) => {
195
200
  emitTrace(deps.tracer, () => ({
196
201
  kind: "permission.sandbox_admitted",
@@ -358,16 +363,9 @@ export async function preparePolicyChain(input) {
358
363
  };
359
364
  }
360
365
  if (pc.durableMandate === true) {
361
- if (resolveCheckpointStore(spec, deps) !== undefined &&
362
- (spec.durableApproval !== undefined || runtimeCaps?.forceDurableGate === true) &&
363
- markInheritedUnavailable(creq.toolCallId)) {
366
+ if (mandatedCallFloats(creq.toolCallId))
364
367
  return first;
365
- }
366
- return {
367
- action: "deny",
368
- message: `inherited parent policy requires durable approval for "${creq.toolName}" — the parent's durable ` +
369
- `ask cannot be reconstructed in a delegated child; denied fail-closed (tighten-only)`,
370
- };
368
+ return mandateUnreconstructibleDeny(creq);
371
369
  }
372
370
  const judged = await judgeInheritedClassifier({ autoMode: pc.autoMode, ask: first, req: creq, signal: csignal ?? abortController.signal, subject: "this call" });
373
371
  if (judged.kind === "allow")
@@ -398,10 +396,7 @@ export async function preparePolicyChain(input) {
398
396
  if (resolved.action === "deny" && resolved.approverUnavailable === true) {
399
397
  if (markInheritedUnavailable(creq.toolCallId))
400
398
  return inheritedAsk;
401
- return {
402
- action: "deny",
403
- message: `no approver is reachable for the inherited approval of "${creq.toolName}" and the marker channel is at capacity — denied fail-closed`,
404
- };
399
+ return markerChannelFullDeny(creq);
405
400
  }
406
401
  settleDenialLimitFallback({ fallback, mintedHere, tracker: pc.autoMode?.denialTracking, resolved, headless: headlessDenyAtFold, stop: stopForDenialLimit, toolName: creq.toolName, toolCallId: creq.toolCallId });
407
402
  if (resolved.action !== "allow")
@@ -437,16 +432,9 @@ export async function preparePolicyChain(input) {
437
432
  };
438
433
  }
439
434
  if (pc.durableMandate === true) {
440
- if (resolveCheckpointStore(spec, deps) !== undefined &&
441
- (spec.durableApproval !== undefined || runtimeCaps?.forceDurableGate === true) &&
442
- markInheritedUnavailable(creq.toolCallId)) {
435
+ if (mandatedCallFloats(creq.toolCallId))
443
436
  return decision;
444
- }
445
- return {
446
- action: "deny",
447
- message: `inherited parent policy requires durable approval for "${creq.toolName}" — the parent's durable ` +
448
- `ask cannot be reconstructed in a delegated child; denied fail-closed (tighten-only)`,
449
- };
437
+ return mandateUnreconstructibleDeny(creq);
450
438
  }
451
439
  const presentedArgs = decision.updatedInput !== undefined ? decision.updatedInput : creq.args;
452
440
  const judged = await judgeInheritedClassifier({ autoMode: pc.autoMode, ask: decision, req: { ...creq, args: presentedArgs }, signal: csignal ?? abortController.signal, subject: "this call" });
@@ -477,10 +465,7 @@ export async function preparePolicyChain(input) {
477
465
  if (resolved.action === "deny" && resolved.approverUnavailable === true) {
478
466
  if (markInheritedUnavailable(creq.toolCallId))
479
467
  return inheritedAsk;
480
- return {
481
- action: "deny",
482
- message: `no approver is reachable for the inherited approval of "${creq.toolName}" and the marker channel is at capacity — denied fail-closed`,
483
- };
468
+ return markerChannelFullDeny(creq);
484
469
  }
485
470
  settleDenialLimitFallback({ fallback, mintedHere, tracker: pc.autoMode?.denialTracking, resolved, headless: headlessDenyAtFold, stop: stopForDenialLimit, toolName: creq.toolName, toolCallId: creq.toolCallId });
486
471
  if (resolved.action !== "allow")
@@ -95,7 +95,7 @@ export async function preparePromptAssembly(input) {
95
95
  }
96
96
  : undefined;
97
97
  const promptConstitution = assembled.constitution;
98
- const promptBlocks = assembled.legacyBlocks;
98
+ const promptBlocks = assembled.blocks;
99
99
  const collisionAudit = auditToolCollisions(tools);
100
100
  for (const y of collisionAudit.yields) {
101
101
  onceLedger.onError(new Error(`tool mount: caller tool "${y.name}" shadows another tool with the same canonical name (deliberate last-write-wins yield — the later mount serves)`), { phase: "config", sessionId });
@@ -1,11 +1,11 @@
1
1
  /**
2
- * design/390 M10 — prepareTask's PROMPT-INPUTS phase: the prompt provider selection, the runtime
2
+ * PrepareTask's PROMPT-INPUTS phase: the prompt provider selection, the runtime
3
3
  * feature flags the harness-context block gates on (so it never claims a mechanism the task lacks),
4
4
  * the three-source user system prompt + the caller's append block, the fenced MCP server-instructions
5
5
  * block, the environment facts (client zone + date basis, knowledge cutoff, the deployment's sandbox
6
6
  * axes, resume-continuity facts on a durable-resume leg only, the hands facts + the one batched env
7
- * probe with its cwd/pwd alignment guard) and the git-status lane probe. The body is the driver's
8
- * stretch moved verbatim; the interface is the dependency list it had implicitly (design/238 R-1).
7
+ * probe with its cwd/pwd alignment guard) and the git-status lane probe. The body is moved verbatim
8
+ * from the driver's own stretch; its interface is the dependency list that stretch had implicitly.
9
9
  *
10
10
  * ASYNC BY CONTENT: the stretch awaits the env probe (hands) and the git-status lane probe (always).
11
11
  * It sits past prepareTask's first await, so the driver's `await` adds no window a caller could reach.
@@ -13,7 +13,7 @@
13
13
  * The one input computed by the DRIVER rather than read here: `failClosedReason` — the
14
14
  * self-orchestration fail-closed advisory's text. Its helper takes the whole `TaskSpec`/`RunnerDeps`
15
15
  * (it audits several deployment seats), which this phase's narrow `spec`/`deps` seats cannot satisfy
16
- * (design/238 R-4); the driver evaluates the helper in the Input literal and this phase only announces
16
+ * The driver evaluates the helper in the Input literal and this phase only announces
17
17
  * the result on the operator lane, exactly where the stretch always did.
18
18
  *
19
19
  * Nothing here throws on its own: the env probe and the alignment guard are best-effort (a stub/odd env
@@ -91,7 +91,7 @@ export interface PreparePromptInputsInput {
91
91
  additionalRootsCanonical: readonly string[];
92
92
  /** borrowed-readonly — the canonical extra read-only roots (copied into the env facts). */
93
93
  additionalReadRootsCanonical: readonly string[];
94
- /** borrowed-readonly — #691: the advertised-writable-directory seat (hands only). The scratchpad section is
94
+ /** borrowed-readonly — the advertised-writable-directory seat (hands only). The scratchpad section is
95
95
  * rendered only when the seat did not SKIP the scratchpad — a directory the fence refused is not advertised. */
96
96
  advertisedWritableDirs?: AdvertisedWritableDirs;
97
97
  /** borrowed-readonly — the acquired session's id (operator-line context). */
@@ -36,7 +36,7 @@ export interface PrepareProtocolToolsInput {
36
36
  * wrapper) and, at RUN time, the refresh closure's splice within a server's name-prefix domain. Later
37
37
  * phases push their own mounts; the roster's full writer table is the delegation-surface phase's. */
38
38
  roster: RosterBuilder;
39
- /** borrowed-mutable — the run-time delta seat (design/388 §2.5): the refresh closure re-mints the roster through it after
39
+ /** borrowed-mutable — the run-time delta seat: the refresh closure re-mints the roster through it after
40
40
  * every re-splice so the stream learns of the change. Armed by the driver after the roster is minted. */
41
41
  rosterSeat: ToolRosterDeltaSeat;
42
42
  /** borrowed-readonly — the large-result wrapper for protocol tools (per-tool `_meta` bar, 50K default). */
@@ -1,17 +1,17 @@
1
1
  /**
2
- * design/390 §1.2 M7 — prepareTask's QUESTION-FACE phase, verbatim from the driver: the leg's ONE checkpoint-store
2
+ * PrepareTask's QUESTION-FACE phase, verbatim from the driver: the leg's ONE checkpoint-store
3
3
  * read, the durable mandate as it binds at the question seat, the content-ask binding table (with the leak
4
4
  * bound the routing lane checks against — the constant below), the stranded-answer disclosure and the leg-end
5
5
  * settle, the three-way mount decision (live face / durable face / override), and the AskUserQuestion mount
6
6
  * with its redeemed-approval, posture, fallback and synthetic-continuation arms. The interface is the
7
- * dependency list the segment had implicitly (design/238 R-1).
7
+ * dependency list the segment had implicitly.
8
8
  *
9
9
  * SYNCHRONOUS FUNCTION, SYNCHRONOUS CALL: the stretch has no await, so the phase adds no yield between the
10
- * offload-reader mount before it and the scheduler mount after it (design/390 §1.5 S1: a stretch with no await
10
+ * offload-reader mount before it and the scheduler mount after it (a stretch with no await
11
11
  * is extracted as a sync function — an `async` wrapper would open a microtask window). Read-stability of the
12
12
  * host handles for the call: {@link RunInternals} (`@contract prepare.deps-read-stable`).
13
13
  *
14
- * One seat is a LIVE GETTER (design/238 D-3): the inherited-unavailable marker set is declared by the driver's
14
+ * One seat is a LIVE GETTER: the inherited-unavailable marker set is declared by the driver's
15
15
  * gate-fold section AFTER this phase and read per call at RUN time, so it enters as `() => ReadonlySet` — a
16
16
  * read before the driver declares it throws (temporal dead zone), which is the fail-loud an uninitialized
17
17
  * live read owes.
@@ -1,17 +1,17 @@
1
1
  /**
2
- * design/390 §1.2 M3a — prepareTask's RUN-REFS phase, verbatim from the driver: the run's own edited-files
2
+ * PrepareTask's RUN-REFS phase, verbatim from the driver: the run's own edited-files
3
3
  * ledger, the harness ref, the per-task skill scope, the display-forwarding wrapper, the three run-local refs
4
4
  * (review request / stop-after-turn / plan mode) with the ctx primitives that write them, the subagent-retain
5
5
  * ledger and the worktree-isolation helper. Nothing here has behavior of its own: the phase MINTS SEATS —
6
6
  * mutable cells and the closures bound to them — that later phases, the tool ctx and the run loop read and
7
- * write. The interface is the dependency list the segment had implicitly (design/238 R-1).
7
+ * write. The interface is the dependency list the segment had implicitly.
8
8
  *
9
9
  * SYNCHRONOUS FUNCTION, SYNCHRONOUS CALL: the stretch has no await, so the phase adds no yield between the
10
- * file-history phase before it and the inherited-gate fold after it (design/390 §1.5 S1: a stretch with no
10
+ * file-history phase before it and the inherited-gate fold after it (a stretch with no
11
11
  * await is extracted as a sync function — an `async` wrapper would open a microtask window).
12
12
  *
13
- * Every cell that leaves here as `borrowed-mutable` carries its writer table on the Result member (design/238
14
- * R-3): the closures minted here, the driver's harness build, the project-context phase's inherited-skill
13
+ * Every cell that leaves here as `borrowed-mutable` carries its writer table on the Result member:
14
+ * the closures minted here, the driver's harness build, the project-context phase's inherited-skill
15
15
  * seed, the skill tool, and the run loop's two writes — nothing else writes them. Read-stability of the host
16
16
  * handles for the call: {@link RunInternals} (`@contract prepare.deps-read-stable`).
17
17
  */
@@ -43,8 +43,8 @@ export interface PrepareRunRefsResult {
43
43
  /** owned — the ledger's LIVE read face (`Prepared.editedFilesSnapshot`, read at result assembly). */
44
44
  editedFilesSnapshot: EditedFilesLedger["snapshot"];
45
45
  /** borrowed-mutable — the harness seat: holds the harness once built, so a tool's execute can read the model
46
- * the parent is CURRENTLY on (design/38 1B: the `ToolExecuteContext.model` snapshot a delegation tool uses
47
- * for `inherit`), and breaks the harness↔tool_search build cycle (design/36 rematerialize). Writers (R-3):
46
+ * the parent is CURRENTLY on (the `ToolExecuteContext.model` snapshot a delegation tool uses
47
+ * for `inherit`), and breaks the harness↔tool_search build cycle (rematerialize). Writers (R-3):
48
48
  * the driver, ONCE, when the harness is built (`harnessRef.current = harness`) — before any run. Readers:
49
49
  * `requestStopAfterTurn` here (mirrors the stop onto the harness's one-way flag), the tool ctx's model
50
50
  * snapshot, the rebuild seam and the delegation mounts. Identity is the contract: every closure minted
@@ -63,7 +63,7 @@ export interface PrepareRunRefsResult {
63
63
  * (the first request wins) and the run loop's turn-boundary consumer, which clears `pending` once the
64
64
  * `plan_review` checkpoint is minted. */
65
65
  reviewRequestRef: Prepared["reviewRequestRef"];
66
- /** owned — the ctx primitive that arms `reviewRequestRef` (design/80 D-B). */
66
+ /** owned — the ctx primitive that arms `reviewRequestRef`. */
67
67
  requestReview: (opts?: {
68
68
  reason?: string;
69
69
  }) => void;
@@ -79,7 +79,7 @@ export interface PrepareRunRefsResult {
79
79
  /** owned — the ctx primitive (mounted on the ctx only under `enablePlanMode`). */
80
80
  enterPlanMode: () => void;
81
81
  /** ownership-ref — the parent-run subagent-retain ledger, or undefined when the spec did not opt in. Its
82
- * lifecycle protocol belongs to the Runner (disposed in the task's terminal finally, design/122 D4); a
82
+ * lifecycle protocol belongs to the Runner (disposed in the task's terminal finally); a
83
83
  * prepare that throws has nothing to release here — the ledger is empty until a delegation retains. */
84
84
  subagentRetain: SubagentRetainLedger | undefined;
85
85
  /** owned — the Agent tool's worktree-isolation helper (lazy; write-capable runs only), or undefined. */
@@ -90,8 +90,8 @@ export interface PrepareRunRefsResult {
90
90
  * A run that opted into `forwardSubagentEvents` may have BACKGROUND children whose frames are forwarded to the
91
91
  * deployment's sink from the child's own run. Those forwards are scheduled on later microtasks than the parent's
92
92
  * turn, so "the parent stream ended" and "the child's already-emitted frames reached the sink" are two different
93
- * moments — the gap is one microtask ladder deep and moves whenever the gate's station structure changes (design/393
94
- * / #594: the three-layer gate added three async frames to a child's gated call, and a consumer that read the parent
93
+ * moments — the gap is one microtask ladder deep and moves whenever the gate's station structure changes
94
+ * (the three-layer gate added three async frames to a child's gated call, and a consumer that read the parent
95
95
  * to `done` then inspected the sink lost the child's `tool_end`). The rule is not a tick count: **before the parent
96
96
  * says `done`, every frame a child had already handed to the forward channel is delivered.** One macrotask turn is
97
97
  * the smallest boundary that strictly orders after all pending microtasks; it is taken only on the opted-in run,
@@ -9,10 +9,10 @@ export interface PrepareSafetyScanInput {
9
9
  deps: RunnerDeps;
10
10
  }
11
11
  /**
12
- * The scan's outputs. Ownership annotations (design/238 §4.2 four-class form):
12
+ * The scan's outputs. Ownership annotations (four-class form):
13
13
  *
14
14
  * `ownToolNames` is **borrowed-readonly** — a first-await snapshot with no mutation anywhere after
15
- * the scan; its one later read is the sandbox-boundary predicate's `.has()`.
15
+ * the scan (sandbox containment reads the env-hand roster, not this set).
16
16
  *
17
17
  * The six collections are **borrowed-mutable**: the driver and later phases fold into them IN
18
18
  * PLACE (identity is part of the contract — closures alias these exact objects). Mutation owners
@@ -1,16 +1,16 @@
1
1
  /**
2
- * design/390 §1.2 M19 (suspend saga) — prepareTask's DURABLE SETTLEMENT machinery, verbatim from the driver's
2
+ * PrepareTask's DURABLE SETTLEMENT machinery, verbatim from the driver's
3
3
  * gate-machinery block: the in-flight spend and repair-bundle folds, the §4.bis correctness-state serializer, the shared
4
4
  * paused-VM compensation bound to this task's failure ledger, the put-commit + put-failure saga (the pre-put cut
5
5
  * checkpoint, the screening-park disclosure, the rejection read-back with its three answers), the suspend-loop cap, the
6
6
  * env capability split (suspendable / park-only / neither) and the park-only handle. The module-scope helpers only this
7
7
  * segment called moved with it (the compensation's bound and body, the auto-mode latch reading, the placement stamp).
8
- * The interface is the dependency list the segment had implicitly (design/238 R-1) — every seat below used to be
8
+ * The interface is the dependency list the segment had implicitly — every seat below used to be
9
9
  * captured off the driver's scope.
10
10
  *
11
11
  * SYNCHRONOUS FUNCTION, SYNCHRONOUS CALL: the stretch has no await of its own (every await lives inside the closures it
12
12
  * builds, which run at park time), so the phase adds no yield between the ask lane before it and the boundary parks
13
- * after it (design/390 §1.5). Read-stability of the host handles for the call: {@link RunInternals}
13
+ * after it. Read-stability of the host handles for the call: {@link RunInternals}
14
14
  * (`@contract prepare.deps-read-stable`).
15
15
  *
16
16
  * The saga exists exactly when the wiring-manifest phase's `gateMachineryActive` holds (the ask lane's presence law) —
@@ -27,7 +27,7 @@ import type { OutputRef } from "./synthetic-tools.js";
27
27
  import type { HookInvocationIdentity } from "../hooks.js";
28
28
  import type { InheritedGate, Prepared, PrepareResume, RunInternals, SuspendSaga } from "./contracts.js";
29
29
  /**
30
- * design/384 slice 2 — the ONE compensation for a paused-but-unparked VM, shared by the fence's
30
+ * The ONE compensation for a paused-but-unparked VM, shared by the fence's
31
31
  * post-pause checkpoints (③ in the park closure, ④ in the saga) and the saga's put-failure absent
32
32
  * arm (previously inline there: same two hops, one implementation now, so the three sites cannot
33
33
  * drift). Restores the workspace (bounded transient retry) then re-establishes consistency