@sema-agent/core 7.56.0 → 7.58.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 (319) hide show
  1. package/CHANGELOG.md +926 -0
  2. package/LICENSE +1 -1
  3. package/dist/agents/org-delivery-gate.js +3 -4
  4. package/dist/agents/peer-held-queue.d.ts +69 -49
  5. package/dist/agents/peer-held-queue.js +255 -106
  6. package/dist/agents/peer-session-drain.js +63 -43
  7. package/dist/agents/send-message-tool.js +3 -2
  8. package/dist/agents/subagent-steps.js +2 -4
  9. package/dist/agents/subagent.js +8 -8
  10. package/dist/brain/anthropic.js +16 -8
  11. package/dist/brain/open-responses.js +10 -8
  12. package/dist/brain/openai.js +11 -9
  13. package/dist/brain/provider-dialect.d.ts +3 -2
  14. package/dist/brain/provider-dialect.js +2 -2
  15. package/dist/brain/request-params.d.ts +6 -0
  16. package/dist/brain/request-params.js +14 -1
  17. package/dist/brain/route-adjudicator.js +2 -1
  18. package/dist/brain/stream-engine.d.ts +9 -0
  19. package/dist/brain/stream-engine.js +24 -10
  20. package/dist/brain/stream-shared.d.ts +5 -4
  21. package/dist/brain/stream-shared.js +4 -4
  22. package/dist/core/a2a.d.ts +2 -1
  23. package/dist/core/a2a.js +23 -10
  24. package/dist/core/allow-entry.d.ts +5 -11
  25. package/dist/core/allow-entry.js +19 -26
  26. package/dist/core/approval-object.d.ts +21 -5
  27. package/dist/core/approval-object.js +44 -17
  28. package/dist/core/ask-origin.d.ts +23 -4
  29. package/dist/core/ask-origin.js +5 -1
  30. package/dist/core/auto-compaction.d.ts +75 -6
  31. package/dist/core/auto-compaction.js +43 -27
  32. package/dist/core/auto-mode-directive.d.ts +29 -5
  33. package/dist/core/auto-mode-directive.js +38 -8
  34. package/dist/core/background-agent-store.d.ts +6 -2
  35. package/dist/core/background-agent-store.js +1 -1
  36. package/dist/core/checkpoint-requirements.d.ts +13 -1
  37. package/dist/core/checkpoint-requirements.js +4 -0
  38. package/dist/core/checkpoint-store.d.ts +44 -40
  39. package/dist/core/checkpoint-store.js +32 -14
  40. package/dist/core/cross-boundary-taint.js +4 -2
  41. package/dist/core/engine-notice.d.ts +4 -3
  42. package/dist/core/engine-notice.js +6 -0
  43. package/dist/core/file-history-store.d.ts +14 -8
  44. package/dist/core/file-history-store.js +14 -4
  45. package/dist/core/fs-write-gate-policy.d.ts +4 -2
  46. package/dist/core/fs-write-gate-policy.js +7 -3
  47. package/dist/core/gate-fold.js +6 -3
  48. package/dist/core/gate-lanes.js +13 -5
  49. package/dist/core/git-worktree-env.d.ts +53 -11
  50. package/dist/core/git-worktree-env.js +96 -12
  51. package/dist/core/hooks.d.ts +6 -3
  52. package/dist/core/hooks.js +12 -5
  53. package/dist/core/human-input-projection.d.ts +1 -0
  54. package/dist/core/human-input-projection.js +3 -0
  55. package/dist/core/locked-config.d.ts +15 -1
  56. package/dist/core/locked-config.js +38 -2
  57. package/dist/core/mailbox-store.d.ts +62 -1
  58. package/dist/core/mailbox-store.js +59 -0
  59. package/dist/core/mcp-call-meta.d.ts +66 -0
  60. package/dist/core/mcp-call-meta.js +103 -0
  61. package/dist/core/mcp-connection-pool.d.ts +3 -1
  62. package/dist/core/mcp-connection-pool.js +3 -1
  63. package/dist/core/mcp-failure.d.ts +7 -1
  64. package/dist/core/mcp-failure.js +10 -0
  65. package/dist/core/mcp-name-judge.d.ts +46 -0
  66. package/dist/core/mcp-name-judge.js +61 -0
  67. package/dist/core/mcp-probe.d.ts +5 -1
  68. package/dist/core/mcp-probe.js +3 -6
  69. package/dist/core/mcp-server-link.d.ts +5 -2
  70. package/dist/core/mcp-server-spec.d.ts +46 -18
  71. package/dist/core/mcp-server-spec.js +1 -18
  72. package/dist/core/mcp.d.ts +6 -14
  73. package/dist/core/mcp.js +85 -65
  74. package/dist/core/memory-engine/consolidation-driver.js +4 -3
  75. package/dist/core/memory-engine/distiller.js +26 -17
  76. package/dist/core/memory-engine/layout.js +5 -2
  77. package/dist/core/memory-engine/scope-contract.d.ts +45 -4
  78. package/dist/core/memory-engine/scope-contract.js +80 -11
  79. package/dist/core/mode-policy.d.ts +8 -5
  80. package/dist/core/mode-policy.js +5 -4
  81. package/dist/core/mods/host.js +1 -1
  82. package/dist/core/mods/kernel/dispatch.d.ts +3 -0
  83. package/dist/core/mods/kernel/dispatch.js +10 -8
  84. package/dist/core/mods/kernel/events.d.ts +5 -1
  85. package/dist/core/mods/kernel/events.js +1 -1
  86. package/dist/core/mods/kernel/registration.d.ts +5 -1
  87. package/dist/core/mods/kernel/site-rules.d.ts +3 -0
  88. package/dist/core/mods/kernel/site-rules.js +10 -0
  89. package/dist/core/mods/package.d.ts +23 -0
  90. package/dist/core/mods/package.js +118 -0
  91. package/dist/core/mods/stations.d.ts +2 -2
  92. package/dist/core/mods/stations.js +1 -1
  93. package/dist/core/mods/tool-call.d.ts +5 -1
  94. package/dist/core/mods/tool-call.js +12 -3
  95. package/dist/core/park-selfcheck.js +2 -0
  96. package/dist/core/path-guard-rows.d.ts +20 -0
  97. package/dist/core/path-guard-rows.js +11 -0
  98. package/dist/core/peer-seat.d.ts +186 -0
  99. package/dist/core/peer-seat.js +307 -0
  100. package/dist/core/permission-rule-consent.d.ts +5 -3
  101. package/dist/core/permission-rule-consent.js +20 -15
  102. package/dist/core/permission-rule-model.d.ts +43 -2
  103. package/dist/core/permission-rule-model.js +52 -8
  104. package/dist/core/permission-rule-org.js +1 -1
  105. package/dist/core/present-plan-tool.d.ts +10 -1
  106. package/dist/core/present-plan-tool.js +46 -2
  107. package/dist/core/protocol-http-auth.d.ts +56 -31
  108. package/dist/core/protocol-http-auth.js +71 -42
  109. package/dist/core/protocol-naming.d.ts +20 -0
  110. package/dist/core/protocol-naming.js +20 -3
  111. package/dist/core/read-only-shell.d.ts +20 -5
  112. package/dist/core/read-only-shell.js +29 -14
  113. package/dist/core/redaction-marks.d.ts +16 -0
  114. package/dist/core/redaction-marks.js +16 -0
  115. package/dist/core/redaction-passes.js +8 -9
  116. package/dist/core/remote-env.d.ts +37 -1
  117. package/dist/core/remote-env.js +11 -0
  118. package/dist/core/resume-startup-cause.d.ts +24 -2
  119. package/dist/core/resume-startup-cause.js +20 -1
  120. package/dist/core/retention.d.ts +41 -15
  121. package/dist/core/retention.js +59 -12
  122. package/dist/core/rewrite-rejudge.d.ts +37 -0
  123. package/dist/core/rewrite-rejudge.js +40 -0
  124. package/dist/core/roles.js +50 -7
  125. package/dist/core/run-origin.d.ts +40 -0
  126. package/dist/core/run-origin.js +37 -0
  127. package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
  128. package/dist/core/runner/advertised-writable-dirs.js +126 -0
  129. package/dist/core/runner/compact-session.d.ts +10 -0
  130. package/dist/core/runner/compact-session.js +202 -0
  131. package/dist/core/runner/compaction-call-options.d.ts +2 -2
  132. package/dist/core/runner/compaction-restate.d.ts +15 -6
  133. package/dist/core/runner/compaction-restate.js +28 -2
  134. package/dist/core/runner/compaction-seams.d.ts +21 -1
  135. package/dist/core/runner/compaction-seams.js +11 -8
  136. package/dist/core/runner/contracts.d.ts +36 -21
  137. package/dist/core/runner/derived-route-fallback.d.ts +13 -0
  138. package/dist/core/runner/derived-route-fallback.js +6 -0
  139. package/dist/core/runner/env-capability-census.d.ts +3 -2
  140. package/dist/core/runner/env-capability-census.js +9 -3
  141. package/dist/core/runner/gate-exit.d.ts +18 -4
  142. package/dist/core/runner/gate-exit.js +5 -1
  143. package/dist/core/runner/permission-rule-lanes.d.ts +7 -7
  144. package/dist/core/runner/permission-rule-lanes.js +17 -11
  145. package/dist/core/runner/prepare-acquire-reconcile.d.ts +3 -0
  146. package/dist/core/runner/prepare-acquire-reconcile.js +2 -1
  147. package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
  148. package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
  149. package/dist/core/runner/prepare-config-doors.d.ts +14 -5
  150. package/dist/core/runner/prepare-config-doors.js +16 -13
  151. package/dist/core/runner/prepare-delegation-surface.d.ts +4 -0
  152. package/dist/core/runner/prepare-delegation-surface.js +15 -18
  153. package/dist/core/runner/prepare-gate-stations.js +1 -1
  154. package/dist/core/runner/prepare-hands-readface.d.ts +10 -4
  155. package/dist/core/runner/prepare-hands-readface.js +6 -1
  156. package/dist/core/runner/prepare-memory.d.ts +3 -0
  157. package/dist/core/runner/prepare-memory.js +19 -23
  158. package/dist/core/runner/prepare-park-ask.d.ts +2 -0
  159. package/dist/core/runner/prepare-park-ask.js +2 -2
  160. package/dist/core/runner/prepare-policy-chain.d.ts +4 -4
  161. package/dist/core/runner/prepare-policy-chain.js +4 -6
  162. package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
  163. package/dist/core/runner/prepare-protocol-tools.js +3 -3
  164. package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
  165. package/dist/core/runner/prepare-suspend-saga.js +2 -1
  166. package/dist/core/runner/prepare-task.d.ts +4 -1
  167. package/dist/core/runner/prepare-task.js +46 -37
  168. package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +13 -0
  169. package/dist/core/runner/prepare-tool-disclosure-mount.js +13 -7
  170. package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
  171. package/dist/core/runner/prepare-wiring-manifest.js +2 -2
  172. package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
  173. package/dist/core/runner/prepare-workspace-restore.js +4 -4
  174. package/dist/core/runner/resume-admission.js +1 -1
  175. package/dist/core/runner/resume-checkpoint-screen.js +2 -0
  176. package/dist/core/runner/rewind-files.d.ts +2 -5
  177. package/dist/core/runner/rewind-files.js +9 -51
  178. package/dist/core/runner/run-harness-handlers.d.ts +3 -4
  179. package/dist/core/runner/run-harness-handlers.js +1 -8
  180. package/dist/core/runner/run-identity-wiring.js +1 -0
  181. package/dist/core/runner/run-leg.js +15 -22
  182. package/dist/core/runner/run-notification-lane.d.ts +2 -0
  183. package/dist/core/runner/run-notification-lane.js +5 -2
  184. package/dist/core/runner/run-recovery-lanes.js +3 -4
  185. package/dist/core/runner/run-settle-and-teardown.js +5 -11
  186. package/dist/core/runner/run-terminal-adoption.js +3 -4
  187. package/dist/core/runner/run-turn-boundary.js +3 -5
  188. package/dist/core/runner/runtask.d.ts +8 -1
  189. package/dist/core/runner/runtask.js +28 -34
  190. package/dist/core/runner/send-message-continuation.js +1 -1
  191. package/dist/core/runner/session-verb-doors.d.ts +28 -0
  192. package/dist/core/runner/session-verb-doors.js +48 -0
  193. package/dist/core/runner/session-write-ledger.d.ts +30 -0
  194. package/dist/core/runner/session-write-ledger.js +101 -0
  195. package/dist/core/runner/stream-settle-backstop.js +11 -14
  196. package/dist/core/runner/sub-agent-deny-lists.d.ts +25 -3
  197. package/dist/core/runner/sub-agent-deny-lists.js +21 -10
  198. package/dist/core/runner/teardown-bounded.d.ts +1 -0
  199. package/dist/core/runner/teardown-bounded.js +1 -0
  200. package/dist/core/runner/terminal-account.js +3 -3
  201. package/dist/core/runner/tool-end-body.js +1 -0
  202. package/dist/core/runner/tool-occurrence.d.ts +4 -1
  203. package/dist/core/runner/tool-occurrence.js +2 -1
  204. package/dist/core/runner/write-protection-station.d.ts +8 -2
  205. package/dist/core/runner/write-protection-station.js +2 -0
  206. package/dist/core/runner-deps.d.ts +4 -4
  207. package/dist/core/secret-env.d.ts +4 -0
  208. package/dist/core/secret-env.js +3 -0
  209. package/dist/core/sensitive-path-policy.js +6 -7
  210. package/dist/core/session-log-transfer.d.ts +24 -0
  211. package/dist/core/session-log-transfer.js +166 -0
  212. package/dist/core/session-policy-store.d.ts +7 -2
  213. package/dist/core/session-policy-store.js +1 -1
  214. package/dist/core/session-store.d.ts +84 -19
  215. package/dist/core/session-store.js +162 -24
  216. package/dist/core/session.d.ts +92 -1
  217. package/dist/core/shell-read-silence.js +1 -0
  218. package/dist/core/shell-wrapper-projection.d.ts +1 -1
  219. package/dist/core/steer-replay.d.ts +4 -2
  220. package/dist/core/steer-replay.js +2 -1
  221. package/dist/core/store-contracts/background-agent-store-contract.js +1 -0
  222. package/dist/core/store-contracts/checkpoint-store-contract.js +19 -1
  223. package/dist/core/store-contracts/file-history-store-contract.js +9 -0
  224. package/dist/core/store-contracts/mailbox-store-contract.js +49 -1
  225. package/dist/core/store-contracts/session-repo-contract.js +112 -5
  226. package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
  227. package/dist/core/store-contracts/session-store-contract.js +236 -2
  228. package/dist/core/task-event.d.ts +68 -8
  229. package/dist/core/task-registry-agent.d.ts +8 -4
  230. package/dist/core/task-registry-agent.js +14 -8
  231. package/dist/core/task-registry-shared.d.ts +36 -6
  232. package/dist/core/task-registry-shared.js +11 -0
  233. package/dist/core/task-registry.d.ts +1 -1
  234. package/dist/core/task-registry.js +1 -1
  235. package/dist/core/task-spec.d.ts +37 -0
  236. package/dist/core/task-stream.d.ts +2 -1
  237. package/dist/core/terminal-cause.d.ts +1 -1
  238. package/dist/core/tool-catalog-entries.d.ts +6 -0
  239. package/dist/core/tool-catalog-entries.js +2 -0
  240. package/dist/core/tool-name-aliases.d.ts +32 -2
  241. package/dist/core/tool-name-aliases.js +23 -0
  242. package/dist/core/tool-name-readings.d.ts +4 -0
  243. package/dist/core/tool-name-readings.js +1 -0
  244. package/dist/core/tool-policy.d.ts +10 -6
  245. package/dist/core/tool-policy.js +4 -7
  246. package/dist/core/tool-result-store.d.ts +17 -10
  247. package/dist/core/tool-result-store.js +3 -1
  248. package/dist/core/trace.d.ts +4 -1
  249. package/dist/core/trace.js +2 -1
  250. package/dist/core/types.d.ts +1 -1
  251. package/dist/core/untrusted-egress.d.ts +18 -0
  252. package/dist/core/untrusted-egress.js +82 -12
  253. package/dist/core/wiring-manifest.d.ts +12 -3
  254. package/dist/core/wiring-manifest.js +4 -3
  255. package/dist/core/workspace-snapshot.d.ts +44 -0
  256. package/dist/core/workspace-snapshot.js +34 -0
  257. package/dist/core/write-protect.d.ts +43 -3
  258. package/dist/core/write-protect.js +43 -16
  259. package/dist/engine/execution-env/node-execution-env.js +15 -11
  260. package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
  261. package/dist/engine/harness/agent-harness.d.ts +12 -5
  262. package/dist/engine/harness/agent-harness.js +13 -2
  263. package/dist/engine/harness/types.d.ts +48 -7
  264. package/dist/engine/harness/types.js +5 -1
  265. package/dist/engine/llm/types.d.ts +12 -3
  266. package/dist/engine/llm/types.js +1 -1
  267. package/dist/engine/loop/agent-loop.d.ts +1 -4
  268. package/dist/engine/loop/agent-loop.js +26 -4
  269. package/dist/engine/session/import-validate.js +3 -0
  270. package/dist/engine/session/memory-repo.d.ts +17 -9
  271. package/dist/engine/session/memory-repo.js +44 -34
  272. package/dist/engine/session/repo-utils.d.ts +22 -4
  273. package/dist/engine/session/repo-utils.js +49 -1
  274. package/dist/engine/session/storage-base.d.ts +10 -1
  275. package/dist/engine/session/storage-base.js +7 -1
  276. package/dist/index.d.ts +23 -11
  277. package/dist/index.js +15 -6
  278. package/dist/internal/harness-types.d.ts +1 -1
  279. package/dist/internal/harness.d.ts +4 -3
  280. package/dist/internal/harness.js +3 -2
  281. package/dist/stores/file/checkpoint-store.d.ts +0 -4
  282. package/dist/stores/file/checkpoint-store.js +0 -1
  283. package/dist/stores/file/file-history-store.js +12 -4
  284. package/dist/stores/file/index.d.ts +4 -1
  285. package/dist/stores/file/index.js +4 -1
  286. package/dist/stores/file/mailbox-store.d.ts +2 -1
  287. package/dist/stores/file/mailbox-store.js +26 -1
  288. package/dist/stores/file/session-store.d.ts +15 -8
  289. package/dist/stores/file/session-store.js +28 -13
  290. package/dist/tools/fs/bash-readonly-classifier.d.ts +15 -19
  291. package/dist/tools/fs/bash-readonly-classifier.js +5 -10
  292. package/dist/tools/fs/fs-bash.js +10 -3
  293. package/dist/tools/fs/fs-write.d.ts +6 -3
  294. package/dist/tools/fs/fs-write.js +8 -7
  295. package/dist/tools/fs/index.d.ts +3 -0
  296. package/dist/tools/fs/index.js +1 -1
  297. package/dist/tools/fs/pattern-kill-guard.d.ts +3 -2
  298. package/dist/tools/fs/pattern-kill-guard.js +68 -36
  299. package/dist/tools/fs/safety.js +40 -8
  300. package/dist/tools/fs/search.js +6 -24
  301. package/dist/tools/fs/shell-read-check.d.ts +18 -1
  302. package/dist/tools/fs/shell-read-check.js +66 -16
  303. package/dist/tools/fs/shell-read-establish.js +2 -1
  304. package/dist/tools/fs/shell-read-identity.d.ts +12 -9
  305. package/dist/tools/fs/shell-read-identity.js +10 -5
  306. package/dist/tools/fs/shell-read-judge.d.ts +10 -1
  307. package/dist/tools/web.js +9 -7
  308. package/dist/tools/worktree.d.ts +42 -15
  309. package/dist/tools/worktree.js +60 -32
  310. package/package.json +4 -2
  311. package/test/export-surface.snapshot.json +141 -3
  312. package/wire-changes/core-stores-sql@7.57.0.json +29 -0
  313. package/wire-changes/core-stores-sql@7.58.0.json +29 -0
  314. package/wire-changes/core@7.57.0.json +1487 -0
  315. package/wire-changes/core@7.58.0.json +2188 -0
  316. package/wire-changes/mods-kernel@7.57.0.json +29 -0
  317. package/wire-changes/mods-kernel@7.58.0.json +81 -0
  318. package/wire-changes/primitives@7.57.0.json +245 -0
  319. package/wire-changes/primitives@7.58.0.json +29 -0
@@ -203,8 +203,8 @@ export type RuleOffersAbsence = (typeof RULE_OFFERS_ABSENCES)[number];
203
203
  * class row's `ruleMayClear` ({@link classifyAsk} — every door below is a class there), read once by the gate's allow layer.
204
204
  * · `word` — the DISCLOSED reason ({@link RuleOffersAbsence}), first door wins, in the display order the card has always
205
205
  * used (governance, the outranked allow, the hook, the ask rule, the two ancestor doors, then the marks). Display
206
- * only. A structural door the offer factory owns (no lane wired, a tool it does not speak for, a
207
- * task that cannot hold a rule) is decided BEFORE this and is deliberately silent;
206
+ * only. The structural door the offer factory owns (no rule speaks for the call: no lane wired, a
207
+ * task that cannot hold a rule, a call the lane does not judge) is decided BEFORE this and is deliberately silent;
208
208
  * · `mandated` — the FACT the ask carries as its own member. Read off the whole mandate set, so which
209
209
  * door is DISPLAYED cannot change it: an ask that is both outranked and mandated is mandated;
210
210
  * · `mandate` — WHICH table word the bit stands on, only when the MARKS family is its whole reason (no
@@ -426,6 +426,10 @@ export interface MandateMarks {
426
426
  * for a shell command's written targets). A GATE fact like the org words: it rides the pass, not the decision, so no
427
427
  * layer outside the engine declares it. */
428
428
  writeProtected?: boolean;
429
+ /** The same judge's record that a written target met its table only where the path resolves on disk (its real target, a hop
430
+ * of its link chain) — the path as written names no row (`GatePass.writeProtectedOnDisk`; the two writers of
431
+ * `writeProtected`, the reading of each target being one or the other). A GATE fact like `writeProtected`. */
432
+ writeProtectedOnDisk?: boolean;
429
433
  /** The gate's record that the READING of a written target could not say where it leads on disk (`GatePass.targetUnresolved`:
430
434
  * a target a shell command's program writes, placed, whose destination the read station could not resolve) — a fact of
431
435
  * the reading, never a judge's verdict. The write face's twin of `probeUnanswered`. */
@@ -526,8 +530,13 @@ export type ToolMarkSource = "deployment" | "mcp_annotation" | "a2a_default";
526
530
  * row ({@link REMOVAL_BREAKER_ROW}).
527
531
  * `rule_unreadable` is a rule that may govern the call and cannot be read for it: the organization's snapshot, a partition of
528
532
  * the person's store, or this call against a deny / ask row (the lexer's word, a content row, the read station's rows).
533
+ * `write_protection` and `write_protection_on_disk` are the two readings of one table hit, judged per written target and never
534
+ * both for one target: the path AS WRITTEN names a row of the write-protection table (`write_protection` — the classifier may
535
+ * answer it), or only where the path resolves on disk does (`write_protection_on_disk` — its real target, or a link on the way:
536
+ * an innocent spelling the disk carries onto a guarded path, which the auto-mode classifier does not answer). A command
537
+ * writing several targets may carry both.
529
538
  */
530
- export declare const ASK_CLASSES: readonly ["content_question", "hook", "ancestor", "dangerous_delete", "unverifiable_delete", "unverifiable_shell_text", "transcript_write", "org_rule", "rule_unreadable", "ask_rule", "denial_limit_fallback", "classifier_no_ruling", "requires_user_interaction", "cross_boundary", "operator_forced", "shell_floor", "target_unresolved", "probe", "write_protection", "tool_marks_mcp", "tool_marks_a2a", "policy_rra", "artifact_shared_read", "mode", "unstated", "ordinary"];
539
+ export declare const ASK_CLASSES: readonly ["content_question", "hook", "ancestor", "dangerous_delete", "unverifiable_delete", "unverifiable_shell_text", "transcript_write", "org_rule", "rule_unreadable", "ask_rule", "denial_limit_fallback", "classifier_no_ruling", "requires_user_interaction", "cross_boundary", "operator_forced", "shell_floor", "target_unresolved", "probe", "write_protection_on_disk", "write_protection", "tool_marks_mcp", "tool_marks_a2a", "policy_rra", "artifact_shared_read", "mode", "unstated", "ordinary"];
531
540
  export type AskClass = (typeof ASK_CLASSES)[number];
532
541
  /** Membership test for {@link AskClass} — the word crosses the wire on `tool_end.gate.disposition`. */
533
542
  export declare function isAskClass(v: unknown): v is AskClass;
@@ -561,7 +570,10 @@ export interface ModeArbitrationRow {
561
570
  * rule or a bypass mode clears it, auto mode's classifier answers it, and a sandbox admits nothing on its behalf (the
562
571
  * tool's effect lands at a remote peer, outside any containment the leg declares). `hookAskFloor` marks the classes the reference's rule / safety check answers
563
572
  * `ask` for — an ask rule, a question the tool needs a person for, a dangerous removal, a protected or unresolvable write
564
- * target, the session transcript, another's shared artifact.
573
+ * target, the session transcript, another's shared artifact. `write_protection_on_disk` is `write_protection`'s row but for the
574
+ * classifier column: the reference implementation marks a protected-write question its classifier may not answer exactly when
575
+ * the requested path alone is safe and the target's resolution is what reaches the guarded name — every other column of the
576
+ * question is the table's.
565
577
  * A row is a class's reading on every face but the ones {@link RELEASED_ON_SHELL_FACE} names: `target_unresolved`'s
566
578
  * `bypassImmune` is the file face's (and every other face's) reading, and the shell face reads it released — folded where the
567
579
  * ask's row is ({@link foldArbitrationRow}), listed per face by {@link releasableAskClassesFor}.
@@ -693,6 +705,13 @@ export declare const MODE_ARBITRATION: {
693
705
  readonly ruleMayClear: false;
694
706
  readonly hookAskFloor: false;
695
707
  };
708
+ readonly write_protection_on_disk: {
709
+ readonly bypassImmune: false;
710
+ readonly classifierEligible: false;
711
+ readonly sandboxAdmission: true;
712
+ readonly ruleMayClear: false;
713
+ readonly hookAskFloor: true;
714
+ };
696
715
  readonly write_protection: {
697
716
  readonly bypassImmune: false;
698
717
  readonly classifierEligible: true;
@@ -145,7 +145,7 @@ export function persistedRuleMandateOf(marks) {
145
145
  const word = irreversibilityMandateOf(marks);
146
146
  if (word === "probe_mandate" || word === "probe_unanswered")
147
147
  return word;
148
- if (marks.writeProtected === true)
148
+ if (marks.writeProtected === true || marks.writeProtectedOnDisk === true)
149
149
  return "write_protection";
150
150
  return marks.egress === true || marks.requiresUserInteraction === true ? "tool_marks" : word;
151
151
  }
@@ -205,6 +205,7 @@ export const ASK_CLASSES = Object.freeze([
205
205
  "shell_floor",
206
206
  "target_unresolved",
207
207
  "probe",
208
+ "write_protection_on_disk",
208
209
  "write_protection",
209
210
  "tool_marks_mcp",
210
211
  "tool_marks_a2a",
@@ -238,6 +239,7 @@ export const MODE_ARBITRATION = {
238
239
  shell_floor: { bypassImmune: true, classifierEligible: true, sandboxAdmission: true, ruleMayClear: false, hookAskFloor: false },
239
240
  target_unresolved: { bypassImmune: true, classifierEligible: false, sandboxAdmission: true, ruleMayClear: false, hookAskFloor: true },
240
241
  probe: { bypassImmune: false, classifierEligible: true, sandboxAdmission: false, ruleMayClear: false, hookAskFloor: false },
242
+ write_protection_on_disk: { bypassImmune: false, classifierEligible: false, sandboxAdmission: true, ruleMayClear: false, hookAskFloor: true },
241
243
  write_protection: { bypassImmune: false, classifierEligible: true, sandboxAdmission: true, ruleMayClear: false, hookAskFloor: true },
242
244
  tool_marks_mcp: { bypassImmune: false, classifierEligible: true, sandboxAdmission: true, ruleMayClear: false, hookAskFloor: false },
243
245
  tool_marks_a2a: { bypassImmune: false, classifierEligible: true, sandboxAdmission: true, ruleMayClear: false, hookAskFloor: false },
@@ -369,6 +371,8 @@ export function classifyAsk(d, facts) {
369
371
  classes.add("target_unresolved");
370
372
  if (marks.writeProtected === true)
371
373
  classes.add("write_protection");
374
+ if (marks.writeProtectedOnDisk === true)
375
+ classes.add("write_protection_on_disk");
372
376
  if (facts.tightened === "unstated")
373
377
  classes.add("unstated");
374
378
  for (const c of facts.ancestorClasses ?? [])
@@ -3,8 +3,8 @@ import { type Message, type Model, type Tool } from "../internal/llm.js";
3
3
  import type { ContextWindowOverlay } from "./context-settings.js";
4
4
  import type { PostCompactContext, PreCompactContext, PreCompactResult } from "./hooks.js";
5
5
  import type { TraceEvent } from "./trace.js";
6
- import type { Brain } from "./types.js";
7
- import type { TaskEvent, TaskEventIdentity } from "./task-event.js";
6
+ import type { Brain, ModelRef, TaskSpec } from "./types.js";
7
+ import type { CompactOutcome, TaskEvent, TaskEventIdentity } from "./task-event.js";
8
8
  import type { CompactionEffect } from "./frame-settlement.js";
9
9
  import type { MintedAttachmentFrame } from "./user-attachment.js";
10
10
  /**
@@ -39,13 +39,18 @@ export type CompactionPhaseDurations = Omit<Extract<TraceEvent, {
39
39
  kind: "compaction.phase_timings";
40
40
  }>, "kind" | "version" | "taskId" | "ts" | "durationMs">;
41
41
  /** True iff `err` is a compaction failure caused by a manual compact() caller WITHDRAWING its
42
- * request — see {@link MaybeCompactOptions.manualCancelSignal}. Two mint sites since the
43
- * design/374 slice-3 commit-boundary re-check (C16): the summary call's own abort outcome, and
44
- * the pre-persist "cancelled before commit" throw (a brain that ignored the abort finished the
45
- * summary, but the withdrawal still fired before anything landed). Absence of the marker means
42
+ * request — see {@link MaybeCompactOptions.manualCancelSignal}. Minted at every cut point of the
43
+ * pass: before the pass commits, while the summary provider or the credential callback is
44
+ * answering ({@link untilPassCut}), the summary call's own abort outcome, and the pre-persist
45
+ * "cancelled before commit" throw (design/374 slice-3, C16: a brain that ignored the abort finished
46
+ * the summary, but the withdrawal still fired before anything landed). Absence of the marker means
46
47
  * the failure was NOT the withdrawal: a real summarizer error racing a late cancel stays
47
48
  * unmarked so the caller's breaker/onError accounting still sees it. */
48
49
  export declare function isCompactionManualCancel(err: unknown): boolean;
50
+ /** The ONE reason a failed compaction pass reports, read by every lane that accounts for one (the turn boundary, the end-of-task pass,
51
+ * the prompt-too-long recovery) for its trace frame and its `compaction_outcome{failed}` event: the thrown value's words through the
52
+ * same-principal tier, THEN bounded — minted before the cut, so the cut can leave no part of a value. */
53
+ export declare function compactionFailureReason(err: unknown): string;
49
54
  /**
50
55
  * design/145 §1/§3 — the window-safety decision surfaced to the caller BEFORE the summary call
51
56
  * (same pre-call posture as `onInputTruncated`: the disclosure must survive a later summary
@@ -419,6 +424,10 @@ export interface MaybeCompactOptions {
419
424
  * context may have lost an engine frame the run still needs, and every reader of the new baseline
420
425
  * (the next model request first) must see it restated. */
421
426
  postureRestate?: () => Promise<void>;
427
+ /** The session plan file's post-compaction reference (`planFileRestateOption`, the runner's `compactionRestateOptions`):
428
+ * where the plan is and what it says, on a leg whose run admitted a plan file that holds one; runs right after
429
+ * `postureRestate`, under the same belt. */
430
+ planFileRestate?: () => Promise<void>;
422
431
  /** The advisor tool's instructions' post-compaction restatement on a leg that mounts the tool (the runner's
423
432
  * `compactionRestateOptions`): runs right after `postureRestate`, under the same belt, for the same reason. */
424
433
  advisorRestate?: () => Promise<void>;
@@ -734,6 +743,66 @@ export interface CompactedFrameSource {
734
743
  export declare function mintCompactedEvent(comp: CompactedFrameSource, trigger: "auto" | "manual" | "forced", identity: TaskEventIdentity): Extract<TaskEvent, {
735
744
  type: "compacted";
736
745
  }>;
746
+ /** `Runner.compactSession`'s request — the out-of-run manual compaction of a session no leg of the Runner holds. A plain
747
+ * data object; the keys are a closed set. */
748
+ export interface CompactSessionRequest {
749
+ /** The session to compact. It must exist. */
750
+ sessionId: string;
751
+ /** The model the session's next turn runs on — its window bounds the pass (resolved like `TaskSpec.model`). */
752
+ model: ModelRef;
753
+ /** This pass's summarization instructions: they REPLACE `compaction.instructions` and the default for this pass (the
754
+ * `TaskStream.compact` reading); sanitized and capped like every instructions channel. */
755
+ instructions?: string;
756
+ /** The members of `TaskSpec.compaction` a pass reads, as a run would carry them. */
757
+ compaction?: Pick<NonNullable<TaskSpec["compaction"]>, "enabled" | "reserveTokens" | "keepRecentTokens" | "instructions" | "clampTolerance">;
758
+ /** The independent summary model (`TaskSpec.compactionModel`); absent ⇒ the deployment's `summarize` role (or its tier
759
+ * default), else the main model. A role-derived model whose key↔URL pairing is broken falls back to the main model,
760
+ * announced, as on a run. */
761
+ compactionModel?: ModelRef;
762
+ /** Per-model credentials (`TaskSpec.getApiKeyAndHeaders`). */
763
+ getApiKeyAndHeaders?: TaskSpec["getApiKeyAndHeaders"];
764
+ /** Withdraws the pass: aborted before the session's lock is taken, the answer is `"mooted"` with nothing done; while the pass
765
+ * runs the summary call and the credential wait read it (store reads and appends, and the pre-flight's own 5 s timer, do not); a pass that already persisted is not undone. */
766
+ signal?: AbortSignal;
767
+ }
768
+ /** `Runner.compactSession`'s answer. */
769
+ export interface CompactSessionResult {
770
+ /** What the pass did — the closed set `TaskStream.compact` resolves with. */
771
+ outcome: CompactOutcome;
772
+ /**
773
+ * The pass's frames, in order, each with its own `eventId` and no task attribution: `compaction_started` once the
774
+ * pass committed, then the frame that ends it — `compacted` (`trigger: "manual"`) on a landing, else
775
+ * `compaction_outcome` (`trigger: "manual"`). Empty when the pass never ran (a withdrawn request). Returned, not
776
+ * streamed: a `compaction_started` here is a record of the pass, not a live progress signal.
777
+ */
778
+ events: Array<Extract<TaskEvent, {
779
+ type: "compaction_started" | "compacted" | "compaction_outcome";
780
+ }>>;
781
+ /** The model calls the pass made (the summary, a hook's `$.model.complete`), priced as a run's side calls are; absent
782
+ * when none was made. `usageMissing` ⇒ a reply reported no usage (a lower bound); `unpriced` ⇒ a call ran on a model
783
+ * the deployment could not price. */
784
+ usage?: {
785
+ tokens: number;
786
+ totalInputTokens: number;
787
+ promptTokens: number;
788
+ cachedTokens: number;
789
+ cacheWriteTokens: number;
790
+ outputTokens: number;
791
+ costMicroUsd: number;
792
+ usageMissing?: true;
793
+ unpriced?: true;
794
+ };
795
+ }
796
+ /**
797
+ * The MANUAL outcome of a pass that returned (did not throw) — the one reading for every manual pass: the turn
798
+ * boundary serving a `TaskStream.compact` request and the out-of-run `Runner.compactSession`. A manual pass forces
799
+ * (`force` + `minTokens: 0`), so the floor's `suppressedByFloor` cannot occur and is not a case here.
800
+ */
801
+ export declare function manualCompactOutcomeOf(comp: {
802
+ compacted: boolean;
803
+ blocked?: boolean;
804
+ disabled?: boolean;
805
+ }): CompactOutcome;
737
806
  /**
738
807
  * THE mint of the `compaction_started` wire frame — the opening half of the pair whose closing half is the
739
808
  * `compacted` frame above (or a `compaction_outcome` that carries the same `pass`). One function, three
@@ -8,6 +8,7 @@ import { brainToRuntime } from "./runtime.js";
8
8
  import { defuseFenceMarkers, sanitizeUntrustedText } from "./untrusted-text.js";
9
9
  import { createSafeNotifier, observeThenableRejection } from "./safe-notify.js";
10
10
  import { thrownText } from "./thrown-value.js";
11
+ import { egressThrownText } from "./untrusted-egress.js";
11
12
  export const DEFAULT_COMPACTION_INSTRUCTIONS = "Preserve verbatim every code, identifier, name, number, file path, error message, credential " +
12
13
  "reference, and explicit user instruction or decision mentioned anywhere in the conversation. " +
13
14
  "When in doubt, keep the specific detail rather than generalizing it.";
@@ -21,9 +22,33 @@ export function sanitizeCompactionInstructions(text) {
21
22
  : defused;
22
23
  }
23
24
  const COMPACTION_MANUAL_CANCEL_FLAG = "semaCompactionManualCancel";
25
+ const PASS_CUT = Symbol("compaction-pass-cut");
26
+ async function untilPassCut(start, signal) {
27
+ if (signal?.aborted === true)
28
+ return PASS_CUT;
29
+ if (signal === undefined)
30
+ return await start();
31
+ let release = () => undefined;
32
+ const cut = new Promise((resolve) => {
33
+ const onAbort = () => resolve(PASS_CUT);
34
+ signal.addEventListener("abort", onAbort, { once: true });
35
+ release = () => signal.removeEventListener("abort", onAbort);
36
+ });
37
+ try {
38
+ return await Promise.race([Promise.resolve(start()), cut]);
39
+ }
40
+ finally {
41
+ release();
42
+ }
43
+ }
24
44
  export function isCompactionManualCancel(err) {
25
45
  return (typeof err === "object" && err !== null && err[COMPACTION_MANUAL_CANCEL_FLAG] === true);
26
46
  }
47
+ const COMPACTION_FAILURE_REASON_MAX = 512;
48
+ export function compactionFailureReason(err) {
49
+ const words = egressThrownText("same-principal", err);
50
+ return words.length > COMPACTION_FAILURE_REASON_MAX ? `${words.slice(0, COMPACTION_FAILURE_REASON_MAX)}…` : words;
51
+ }
27
52
  function summarizationCharsCapacity(model) {
28
53
  return model.contextWindow > 0
29
54
  ? model.contextWindow * (model.charsPerToken ?? DEFAULT_CHARS_PER_TOKEN)
@@ -161,29 +186,15 @@ export async function maybeCompact(opts) {
161
186
  let providerSummary;
162
187
  if (opts.summaryProvider && !forceRealSummary && !prep.value.isSplitTurn) {
163
188
  const providerModifiedFiles = computeFileLists(prep.value.fileOps).modifiedFilesByRecency;
164
- const signal = opts.signal;
165
- const cut = Symbol("cut");
166
- let release = () => undefined;
167
- const cutByAbort = new Promise((resolve) => {
168
- if (signal === undefined || signal.aborted)
169
- return;
170
- const onAbort = () => resolve(cut);
171
- signal.addEventListener("abort", onAbort, { once: true });
172
- release = () => signal.removeEventListener("abort", onAbort);
173
- });
189
+ const summaryProvider = opts.summaryProvider;
190
+ const boundary = prep.value;
174
191
  let consulted;
175
192
  try {
176
- consulted =
177
- signal?.aborted === true
178
- ? cut
179
- : await Promise.race([
180
- Promise.resolve(opts.summaryProvider({
181
- messagesToSummarize: prep.value.messagesToSummarize,
182
- previousSummary: prep.value.previousSummary,
183
- modifiedFiles: providerModifiedFiles,
184
- })),
185
- cutByAbort,
186
- ]);
193
+ consulted = await untilPassCut(() => summaryProvider({
194
+ messagesToSummarize: boundary.messagesToSummarize,
195
+ previousSummary: boundary.previousSummary,
196
+ modifiedFiles: providerModifiedFiles,
197
+ }), opts.signal);
187
198
  const trimmed = typeof consulted === "string" ? consulted.trim() : "";
188
199
  if (trimmed) {
189
200
  providerSummary = trimmed;
@@ -191,10 +202,7 @@ export async function maybeCompact(opts) {
191
202
  }
192
203
  catch {
193
204
  }
194
- finally {
195
- release();
196
- }
197
- if (consulted === cut) {
205
+ if (consulted === PASS_CUT) {
198
206
  throw Object.assign(new CompactionError("aborted", "compaction cancelled while the summary provider was answering — nothing was persisted"), opts.manualCancelSignal?.aborted === true ? { [COMPACTION_MANUAL_CANCEL_FLAG]: true } : {});
199
207
  }
200
208
  }
@@ -298,7 +306,12 @@ export async function maybeCompact(opts) {
298
306
  });
299
307
  }
300
308
  }
301
- const auth = await opts.getApiKeyAndHeaders?.(summaryModel);
309
+ const getApiKeyAndHeaders = opts.getApiKeyAndHeaders;
310
+ const authed = getApiKeyAndHeaders === undefined ? undefined : await untilPassCut(() => getApiKeyAndHeaders(summaryModel), opts.signal);
311
+ if (authed === PASS_CUT) {
312
+ throw Object.assign(new CompactionError("aborted", "compaction cancelled while the summary model's credentials were being fetched — nothing was summarized or persisted"), opts.manualCancelSignal?.aborted === true ? { [COMPACTION_MANUAL_CANCEL_FLAG]: true } : {});
313
+ }
314
+ const auth = authed;
302
315
  const summarySignal = opts.signal;
303
316
  const runtime = brainToRuntime(opts.brain);
304
317
  const forkCandidate = opts.compactionModel === undefined ? opts.forkContext?.() : undefined;
@@ -504,7 +517,7 @@ export async function maybeCompact(opts) {
504
517
  catch {
505
518
  }
506
519
  }
507
- for (const restate of [opts.postureRestate, opts.advisorRestate]) {
520
+ for (const restate of [opts.postureRestate, opts.planFileRestate, opts.advisorRestate]) {
508
521
  if (restate === undefined)
509
522
  continue;
510
523
  try {
@@ -601,6 +614,9 @@ export function mintCompactedEvent(comp, trigger, identity) {
601
614
  ...identity,
602
615
  };
603
616
  }
617
+ export function manualCompactOutcomeOf(comp) {
618
+ return comp.compacted ? "compacted" : comp.blocked ? "blocked" : comp.disabled ? "disabled" : "noop";
619
+ }
604
620
  export function mintCompactionStartedEvent(start, identity) {
605
621
  return { type: "compaction_started", trigger: start.trigger, pass: start.pass, startedAt: start.startedAt, ...identity };
606
622
  }
@@ -29,6 +29,21 @@ export declare const PLAN_MODE_NO_EXIT_SPARSE_DIRECTIVE: string;
29
29
  * the child answers the request it was given (its final answer goes back to the agent that delegated to it). The
30
30
  * reference has no sparse arm for a sub-agent, so a restatement of this row is this body. */
31
31
  export declare const PLAN_MODE_CHILD_DIRECTIVE: string;
32
+ /** A frame that names the leg's session plan file: the text before the file, and the text after it. The file goes between
33
+ * them as the seat tells it (`planFileShown`, advertised-writable-dirs.ts — one line, verbatim); the fold recognizes the
34
+ * frame by its two halves. */
35
+ export interface PostureTemplate {
36
+ readonly head: string;
37
+ readonly tail: string;
38
+ }
39
+ /** The planning frame of a leg that keeps its plan in a FILE (`TaskSpec.planFile`, the reference's disk arm): the reference
40
+ * full reminder's disk-arm opening — the edit ban "with the exception of the plan file mentioned below" — and its
41
+ * `## Plan File Info:` section, with the file's existence left to the model (the reference words it two ways off a disk
42
+ * read; this frame names both actions), and the tail adapted to the engine's exit (the plan-exit tool reads the file, a
43
+ * human approves). */
44
+ export declare const PLAN_MODE_FILE_DIRECTIVE: PostureTemplate;
45
+ /** The file arm's sparse restatement — the reference sparse shape with its plan-file clause ("Read-only except plan file"). */
46
+ export declare const PLAN_MODE_FILE_SPARSE_DIRECTIVE: PostureTemplate;
32
47
  /** The planning frame's exit — the reference exit renderer's text without its plan-file clause. Names no tool, so
33
48
  * one exit retires every planning wording. */
34
49
  export declare const PLAN_MODE_EXIT_DIRECTIVE: string;
@@ -50,6 +65,9 @@ export interface PostureLegFacts {
50
65
  exitToolMounted: boolean;
51
66
  /** This leg runs as a delegated child (every core spawn lane, a fork included). */
52
67
  isChildLeg: boolean;
68
+ /** The session plan file the run admitted (`TaskSpec.planFile`), as the seat tells it to the model (`planFileShown`) —
69
+ * absent ⇒ the plan is the plan-exit tool's argument and no frame names a file. */
70
+ planFile?: string;
53
71
  }
54
72
  /** Every fact a row's `owedBy` reads: the mode facts and the leg's shape. */
55
73
  export type PostureFacts = ApprovalPostureFacts & PostureLegFacts;
@@ -60,8 +78,8 @@ export interface PostureRow {
60
78
  readonly family: PostureFamily;
61
79
  /** Whether the leg's mode facts call for this row. */
62
80
  readonly owedBy: (facts: PostureFacts) => boolean;
63
- /** The frame that states the posture. */
64
- readonly frame: string;
81
+ /** The frame that states the posture — a fixed text, or a frame that names the leg's plan file ({@link PostureTemplate}). */
82
+ readonly frame: string | PostureTemplate;
65
83
  /** The frame that retires it. */
66
84
  readonly exit: string;
67
85
  /**
@@ -72,14 +90,17 @@ export interface PostureRow {
72
90
  readonly cadence?: {
73
91
  readonly everyTurns: number;
74
92
  readonly fullEvery: number;
75
- readonly sparse: string;
93
+ readonly sparse: string | PostureTemplate;
76
94
  };
77
95
  }
96
+ /** A frame's text for this leg: a fixed text as it stands, a template with the leg's plan file between its halves. */
97
+ export declare function postureText(text: string | PostureTemplate, facts: Pick<PostureFacts, "planFile">): string;
78
98
  /**
79
99
  * Every posture the engine states, in the order the owed row is chosen. `plan` first: it is the mode the leg
80
100
  * was put in, and the bypass frame's shell-first instruction would contradict it. Within it the leg's shape picks the
81
- * wording — a delegated child (the reference's sub-agent variant), else a leg with the plan-exit tool on its roster
82
- * (the planning body that names it), else the body that names no tool. Then the reference
101
+ * wording — a delegated child (the reference's sub-agent variant), else a leg with the plan-exit tool on its roster and a
102
+ * session plan file (the body that names both), else a leg with the plan-exit tool (the planning body that names it),
103
+ * else the body that names no tool. Then the reference
83
104
  * implementation's own arm order for its one posture attachment: bypass (effective `bypassPermissions`, or — outside
84
105
  * `dontAsk`, whose mode refuses every ask before any seat could answer — no person answers an ask), then auto (the
85
106
  * classifier is armed — a requested auto mode the engine folded back is not stated, because the run is not operating
@@ -95,6 +116,9 @@ export interface StandingPosture {
95
116
  readonly statements: number;
96
117
  /** Assistant turns since the family's last frame (the cadence's due clock). */
97
118
  readonly turnsSince: number;
119
+ /** The plan file the standing frame named, as rendered (a template frame only): a leg whose plan file reads otherwise
120
+ * is owed the full frame again — the frame's row is the same, what it states is not. */
121
+ readonly file?: string;
98
122
  }
99
123
  /** The standing families of a context, keyed by family, in the order they first stood. */
100
124
  export type PostureStanding = ReadonlyMap<PostureFamily, StandingPosture>;
@@ -11,10 +11,22 @@ export const PLAN_MODE_SPARSE_DIRECTIVE = `Plan mode still active (see full inst
11
11
  export const PLAN_MODE_NO_EXIT_DIRECTIVE = "Plan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits, run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system — every such call asks the user first, and is refused where nobody can answer. This supercedes any other instructions you have received. Instead, you should: research and analyze with read-only tools, and when you have formed a concrete plan, give it as your final answer and stop.";
12
12
  export const PLAN_MODE_NO_EXIT_SPARSE_DIRECTIVE = "Plan mode still active (see full instructions earlier in conversation). Read-only: no edits, commits, or config changes. When your plan is ready, give it as your final answer and stop.";
13
13
  export const PLAN_MODE_CHILD_DIRECTIVE = "Plan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits, run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system — every such call asks the user first, and is refused where nobody can answer. This supercedes any other instructions you have received. Instead, you should: research and analyze with read-only tools, and answer the request comprehensively — your final answer, carrying the plan, goes back to the agent that delegated to you.";
14
+ export const PLAN_MODE_FILE_DIRECTIVE = {
15
+ head: "Plan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits (with the exception of the plan file mentioned below), run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system — every such call asks the user first, and is refused where nobody can answer. This supercedes any other instructions you have received.\n\n## Plan File Info:\nYour plan file is ",
16
+ tail: `. If it does not exist yet, create your plan there using the Write tool; if it already exists, read it and make incremental edits using the Edit tool. You should build your plan incrementally by writing to or editing this file. NOTE that this is the only file you are allowed to edit - other than this you are only allowed to take READ-ONLY actions.\n\nWhen your plan is ready, call the ${PRESENT_PLAN_TOOL_NAME} tool: it reads the plan from that file and requests approval — never ask for approval via plain text.`,
17
+ };
18
+ export const PLAN_MODE_FILE_SPARSE_DIRECTIVE = {
19
+ head: "Plan mode still active (see full instructions earlier in conversation). Read-only except plan file (",
20
+ tail: `). When your plan is ready, call the ${PRESENT_PLAN_TOOL_NAME} tool — it reads the plan from that file. Never ask about plan approval via plain text.`,
21
+ };
14
22
  export const PLAN_MODE_EXIT_DIRECTIVE = "## Exited Plan Mode\n\nYou have exited plan mode. You can now make edits, run tools, and take actions.";
23
+ export function postureText(text, facts) {
24
+ return typeof text === "string" ? text : `${text.head}${facts.planFile ?? ""}${text.tail}`;
25
+ }
15
26
  const PLAN_CADENCE = { everyTurns: 5, fullEvery: 5, sparse: PLAN_MODE_SPARSE_DIRECTIVE };
16
27
  export const POSTURE_TABLE = Object.freeze([
17
28
  { family: "plan", owedBy: (f) => f.mode === "plan" && f.isChildLeg, frame: PLAN_MODE_CHILD_DIRECTIVE, exit: PLAN_MODE_EXIT_DIRECTIVE, cadence: { ...PLAN_CADENCE, sparse: PLAN_MODE_CHILD_DIRECTIVE } },
29
+ { family: "plan", owedBy: (f) => f.mode === "plan" && f.exitToolMounted && f.planFile !== undefined, frame: PLAN_MODE_FILE_DIRECTIVE, exit: PLAN_MODE_EXIT_DIRECTIVE, cadence: { ...PLAN_CADENCE, sparse: PLAN_MODE_FILE_SPARSE_DIRECTIVE } },
18
30
  { family: "plan", owedBy: (f) => f.mode === "plan" && f.exitToolMounted, frame: PLAN_MODE_DIRECTIVE, exit: PLAN_MODE_EXIT_DIRECTIVE, cadence: PLAN_CADENCE },
19
31
  { family: "plan", owedBy: (f) => f.mode === "plan", frame: PLAN_MODE_NO_EXIT_DIRECTIVE, exit: PLAN_MODE_EXIT_DIRECTIVE, cadence: { ...PLAN_CADENCE, sparse: PLAN_MODE_NO_EXIT_SPARSE_DIRECTIVE } },
20
32
  { family: "auto", owedBy: (f) => f.mode === "bypassPermissions" || (f.mode !== "dontAsk" && f.askEffective === "auto_allow"), frame: BYPASS_POSTURE_DIRECTIVE, exit: BYPASS_POSTURE_EXIT_DIRECTIVE },
@@ -28,15 +40,32 @@ const POSTURE_VOCABULARY = POSTURE_TABLE.flatMap((row) => [
28
40
  [row.exit, { row, exit: true }],
29
41
  ...(row.cadence !== undefined ? [[row.cadence.sparse, { row, exit: false }]] : []),
30
42
  ]);
43
+ function vocabularyLengthAt(rest, text) {
44
+ if (typeof text === "string")
45
+ return rest.startsWith(text) ? text.length : undefined;
46
+ if (!rest.startsWith(text.head))
47
+ return undefined;
48
+ const end = rest.indexOf(text.tail, text.head.length);
49
+ if (end <= text.head.length || rest.slice(text.head.length, end).includes("\n"))
50
+ return undefined;
51
+ return end + text.tail.length;
52
+ }
31
53
  function postureItemsOf(body) {
32
54
  const out = [];
33
55
  let rest = body;
34
56
  while (rest.length > 0) {
35
- const hit = POSTURE_VOCABULARY.find(([text]) => rest === text || rest.startsWith(`${text}\n\n`));
36
- if (hit === undefined)
57
+ let matched;
58
+ for (const [text, item] of POSTURE_VOCABULARY) {
59
+ const length = vocabularyLengthAt(rest, text);
60
+ if (length !== undefined && (length === rest.length || rest.startsWith("\n\n", length))) {
61
+ matched = { item: typeof text === "string" ? item : { ...item, file: rest.slice(text.head.length, length - text.tail.length) }, length };
62
+ break;
63
+ }
64
+ }
65
+ if (matched === undefined)
37
66
  return undefined;
38
- out.push(hit[1]);
39
- rest = rest === hit[0] ? "" : rest.slice(hit[0].length + 2);
67
+ out.push(matched.item);
68
+ rest = matched.length === rest.length ? "" : rest.slice(matched.length + 2);
40
69
  }
41
70
  return out.length > 0 ? out : undefined;
42
71
  }
@@ -54,7 +83,7 @@ export function postureStandingOf(messages, reminderMark) {
54
83
  if (item.exit)
55
84
  standing.delete(item.row.family);
56
85
  else
57
- standing.set(item.row.family, { row: item.row, statements: (standing.get(item.row.family)?.statements ?? 0) + 1, turnsSince: 0 });
86
+ standing.set(item.row.family, { row: item.row, statements: (standing.get(item.row.family)?.statements ?? 0) + 1, turnsSince: 0, ...(item.file !== undefined ? { file: item.file } : {}) });
58
87
  }
59
88
  }
60
89
  }
@@ -70,10 +99,11 @@ export function composePostureFrames(facts, standing) {
70
99
  if (owed === undefined)
71
100
  return frames;
72
101
  const s = standing.get(owed.family);
73
- if (s === undefined || s.row !== owed)
74
- frames.push(owed.frame);
102
+ const fileMoved = s !== undefined && typeof owed.frame !== "string" && s.file !== (facts.planFile ?? "");
103
+ if (s === undefined || s.row !== owed || fileMoved)
104
+ frames.push(postureText(owed.frame, facts));
75
105
  else if (owed.cadence !== undefined && s.turnsSince >= owed.cadence.everyTurns) {
76
- frames.push((s.statements + 1) % owed.cadence.fullEvery === 1 ? owed.frame : owed.cadence.sparse);
106
+ frames.push(postureText((s.statements + 1) % owed.cadence.fullEvery === 1 ? owed.frame : owed.cadence.sparse, facts));
77
107
  }
78
108
  return frames;
79
109
  }
@@ -37,7 +37,11 @@ export interface BackgroundAgentRecord {
37
37
  * keys on THIS field (listBySession matches it as a second arm), not on an alias walk. */
38
38
  rootSessionId?: string;
39
39
  parentTaskId?: string;
40
- name?: string;
40
+ /** The agent's name — the spawner's explicit one, or the one the engine derives from `handle`
41
+ * (`engineAgentName`) when the spawn named none. Written by the registration that creates the row, so
42
+ * every row core writes carries one; a revival re-reads it verbatim. A host store that reads a row an
43
+ * earlier version wrote without one derives it from `handle` with the same function. */
44
+ name: string;
41
45
  agentType?: string;
42
46
  description?: string;
43
47
  /** Revival lookup key (CC meta-sidecar parity); populated when known, never required. The team
@@ -180,7 +184,7 @@ export interface BackgroundAgentRowSummary {
180
184
  sessionId?: string;
181
185
  parentSessionId?: string;
182
186
  rootSessionId?: string;
183
- name?: string;
187
+ name: string;
184
188
  agentType?: string;
185
189
  status: BackgroundAgentRecord["status"];
186
190
  spawnedAt: number;
@@ -183,7 +183,7 @@ function toSummary(r) {
183
183
  ...(r.sessionId !== undefined ? { sessionId: r.sessionId } : {}),
184
184
  ...(r.parentSessionId !== undefined ? { parentSessionId: r.parentSessionId } : {}),
185
185
  ...(r.rootSessionId !== undefined ? { rootSessionId: r.rootSessionId } : {}),
186
- ...(r.name !== undefined ? { name: r.name } : {}),
186
+ name: r.name,
187
187
  ...(r.agentType !== undefined ? { agentType: r.agentType } : {}),
188
188
  status: r.status,
189
189
  spawnedAt: r.spawnedAt,
@@ -6,7 +6,7 @@ import { type StoreFidelity, type Checkpoint, type CheckpointFeature, type Check
6
6
  * had carried beside the one its word now names, and the members added after the table, each a capability a reader
7
7
  * must have. Downstream reads them for display only (`CheckpointError.detail.requires`).
8
8
  */
9
- export declare const REQUIREMENT_WORDS: readonly ["resource", "binding", "token", "orgAdmission", "f012", "realApproval", "face", "requirements_digest", "org_admission_inherited", "org_write_grant", "org_governed", "delegation_provenance", "skill_grants", "skill_card_binding", "hands_coordinates", "hands_home", "path_rule_anchors", "path_rule_installations", "permission_mode", "plan_mode_restore", "persisted_rule_mandate", "deployment_authored", "call_names", "write_face", "denial_limit_fallback", "leg_scope", "tool_ceiling", "tool_lists_judged", "own_tool_lists", "approval_targets", "cross_boundary", "mount_site", "skill_scopes"];
9
+ export declare const REQUIREMENT_WORDS: readonly ["resource", "binding", "token", "orgAdmission", "f012", "realApproval", "face", "requirements_digest", "org_admission_inherited", "org_write_grant", "org_governed", "delegation_provenance", "skill_grants", "skill_card_binding", "hands_coordinates", "hands_home", "path_rule_anchors", "path_rule_installations", "permission_mode", "plan_mode_restore", "persisted_rule_mandate", "deployment_authored", "call_names", "write_face", "denial_limit_fallback", "leg_scope", "tool_ceiling", "tool_lists_judged", "own_tool_lists", "approval_targets", "approval_target_reads", "cross_boundary", "mount_site", "skill_scopes", "run_origin"];
10
10
  export type RequirementWord = (typeof REQUIREMENT_WORDS)[number];
11
11
  /** Runtime twin of {@link RequirementWord}. */
12
12
  export declare function isRequirementWord(word: unknown): word is RequirementWord;
@@ -221,6 +221,9 @@ export declare const CHECKPOINT_STATE_REQUIREMENTS: {
221
221
  readonly legScope: {
222
222
  readonly word: "leg_scope";
223
223
  };
224
+ readonly runOrigin: {
225
+ readonly word: "run_origin";
226
+ };
224
227
  readonly toolCeiling: {
225
228
  readonly word: "tool_ceiling";
226
229
  };
@@ -332,6 +335,9 @@ export declare const PENDING_ACTION_REQUIREMENTS: {
332
335
  readonly targets: {
333
336
  readonly word: "approval_targets";
334
337
  };
338
+ readonly targetReads: {
339
+ readonly word: "approval_target_reads";
340
+ };
335
341
  readonly hasBidiControls: {
336
342
  readonly ignorable: "shown, never decided (card, listing, transcript or reported count): every read of the name renders, carries transcript or counts";
337
343
  };
@@ -588,6 +594,9 @@ export declare const CHECKPOINT_REQUIREMENTS: {
588
594
  readonly legScope: {
589
595
  readonly word: "leg_scope";
590
596
  };
597
+ readonly runOrigin: {
598
+ readonly word: "run_origin";
599
+ };
591
600
  readonly toolCeiling: {
592
601
  readonly word: "tool_ceiling";
593
602
  };
@@ -844,6 +853,9 @@ export declare const CHECKPOINT_REQUIREMENTS: {
844
853
  readonly targets: {
845
854
  readonly word: "approval_targets";
846
855
  };
856
+ readonly targetReads: {
857
+ readonly word: "approval_target_reads";
858
+ };
847
859
  readonly hasBidiControls: {
848
860
  readonly ignorable: "shown, never decided (card, listing, transcript or reported count): every read of the name renders, carries transcript or counts";
849
861
  };
@@ -32,9 +32,11 @@ export const REQUIREMENT_WORDS = Object.freeze([
32
32
  "tool_lists_judged",
33
33
  "own_tool_lists",
34
34
  "approval_targets",
35
+ "approval_target_reads",
35
36
  "cross_boundary",
36
37
  "mount_site",
37
38
  "skill_scopes",
39
+ "run_origin",
38
40
  ]);
39
41
  export function isRequirementWord(word) {
40
42
  return typeof word === "string" && REQUIREMENT_WORDS.includes(word);
@@ -94,6 +96,7 @@ export const CHECKPOINT_STATE_REQUIREMENTS = {
94
96
  placementRootSessionId: DECISION_READ,
95
97
  externalContentTarget: DECISION_READ,
96
98
  legScope: { word: "leg_scope" },
99
+ runOrigin: { word: "run_origin" },
97
100
  toolCeiling: { word: "tool_ceiling" },
98
101
  toolListsJudged: { word: "tool_lists_judged" },
99
102
  ownToolLists: { word: "own_tool_lists" },
@@ -133,6 +136,7 @@ export const PENDING_ACTION_REQUIREMENTS = {
133
136
  names: { word: "call_names" },
134
137
  engineMounted: { word: "mount_site" },
135
138
  targets: { word: "approval_targets" },
139
+ targetReads: { word: "approval_target_reads" },
136
140
  hasBidiControls: SHOWN,
137
141
  batchToolCallIds: DECISION_READ,
138
142
  completedCallIds: SHOWN,