@sema-agent/core 7.61.0 → 7.63.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 (298) hide show
  1. package/CHANGELOG.md +840 -0
  2. package/dist/agents/cascade.d.ts +11 -3
  3. package/dist/agents/cascade.js +1 -1
  4. package/dist/agents/peer-held-queue.d.ts +27 -4
  5. package/dist/agents/peer-held-queue.js +81 -36
  6. package/dist/agents/peer-session-drain.js +13 -3
  7. package/dist/agents/subagent-transcript-placement.d.ts +23 -0
  8. package/dist/agents/subagent-transcript-placement.js +14 -0
  9. package/dist/agents/subagent.d.ts +6 -1
  10. package/dist/agents/subagent.js +143 -58
  11. package/dist/agents/suspend-guard.d.ts +38 -16
  12. package/dist/agents/suspend-guard.js +9 -4
  13. package/dist/agents/verify.js +4 -3
  14. package/dist/brain/route-adjudicator.js +9 -4
  15. package/dist/core/approval-object.js +1 -1
  16. package/dist/core/arg-summary.js +1 -1
  17. package/dist/core/ask-question.d.ts +2 -2
  18. package/dist/core/canonical-json.d.ts +23 -13
  19. package/dist/core/canonical-json.js +4 -4
  20. package/dist/core/checkpoint-features.d.ts +722 -0
  21. package/dist/core/checkpoint-features.js +98 -0
  22. package/dist/core/checkpoint-queries.d.ts +47 -4
  23. package/dist/core/checkpoint-queries.js +36 -16
  24. package/dist/core/checkpoint-requirements.d.ts +12 -5
  25. package/dist/core/checkpoint-requirements.js +11 -5
  26. package/dist/core/checkpoint-row-verdict.d.ts +110 -0
  27. package/dist/core/checkpoint-row-verdict.js +245 -0
  28. package/dist/core/checkpoint-store.d.ts +76 -753
  29. package/dist/core/checkpoint-store.js +83 -144
  30. package/dist/core/compliance.d.ts +6 -2
  31. package/dist/core/compliance.js +3 -3
  32. package/dist/core/engine-attestation.d.ts +1 -1
  33. package/dist/core/engine-notice.d.ts +38 -7
  34. package/dist/core/engine-notice.js +9 -2
  35. package/dist/core/gate-fold.js +2 -2
  36. package/dist/core/git-worktree-env.d.ts +62 -3
  37. package/dist/core/git-worktree-env.js +91 -30
  38. package/dist/core/governance-codes.d.ts +9 -3
  39. package/dist/core/governance-codes.js +16 -3
  40. package/dist/core/hooks.d.ts +13 -0
  41. package/dist/core/human-input-projection.d.ts +1 -0
  42. package/dist/core/human-input-projection.js +3 -0
  43. package/dist/core/image-admission.d.ts +1 -1
  44. package/dist/core/locked-config.d.ts +2 -2
  45. package/dist/core/mcp-host-seat.js +6 -1
  46. package/dist/core/memory-engine/consolidation-driver.d.ts +33 -18
  47. package/dist/core/memory-engine/consolidation-driver.js +99 -98
  48. package/dist/core/memory-engine/consolidation.d.ts +73 -10
  49. package/dist/core/memory-engine/consolidation.js +167 -11
  50. package/dist/core/memory-engine/data-plane.d.ts +8 -4
  51. package/dist/core/memory-engine/data-plane.js +11 -6
  52. package/dist/core/memory-engine/delegation-settlement.d.ts +37 -35
  53. package/dist/core/memory-engine/delegation-settlement.js +53 -59
  54. package/dist/core/memory-engine/dual-root.d.ts +12 -6
  55. package/dist/core/memory-engine/dual-root.js +9 -5
  56. package/dist/core/memory-engine/engine.d.ts +98 -35
  57. package/dist/core/memory-engine/engine.js +477 -380
  58. package/dist/core/memory-engine/entry-scan.d.ts +8 -0
  59. package/dist/core/memory-engine/entry-scan.js +3 -0
  60. package/dist/core/memory-engine/file-backend.d.ts +29 -3
  61. package/dist/core/memory-engine/file-backend.js +66 -35
  62. package/dist/core/memory-engine/index.d.ts +7 -7
  63. package/dist/core/memory-engine/index.js +6 -6
  64. package/dist/core/memory-engine/landing-admission.d.ts +5 -3
  65. package/dist/core/memory-engine/landing-admission.js +3 -3
  66. package/dist/core/memory-engine/layout.d.ts +121 -45
  67. package/dist/core/memory-engine/layout.js +252 -102
  68. package/dist/core/memory-engine/memory-backend-contract.d.ts +19 -1
  69. package/dist/core/memory-engine/memory-backend-contract.js +320 -0
  70. package/dist/core/memory-engine/memory-deployment.d.ts +31 -8
  71. package/dist/core/memory-engine/memory-deployment.js +26 -12
  72. package/dist/core/memory-engine/scope-contract.d.ts +52 -11
  73. package/dist/core/memory-engine/scope-contract.js +68 -19
  74. package/dist/core/memory-engine/session-write-home.d.ts +3 -1
  75. package/dist/core/memory-engine/session-write-home.js +1 -1
  76. package/dist/core/memory-engine/sync-client.d.ts +3 -1
  77. package/dist/core/memory-engine/sync-client.js +7 -0
  78. package/dist/core/memory-engine/sync-report.d.ts +3 -2
  79. package/dist/core/memory-engine/sync-report.js +6 -2
  80. package/dist/core/memory-engine/tools.d.ts +2 -2
  81. package/dist/core/memory-engine/tools.js +10 -10
  82. package/dist/core/memory-engine/types.d.ts +118 -19
  83. package/dist/core/memory-engine/types.js +1 -0
  84. package/dist/core/memory-vector.d.ts +1 -1
  85. package/dist/core/memory.d.ts +10 -10
  86. package/dist/core/memory.js +15 -6
  87. package/dist/core/mode-policy.js +1 -1
  88. package/dist/core/mods/classic-events.d.ts +9 -1
  89. package/dist/core/mods/dollar.d.ts +32 -1
  90. package/dist/core/mods/dollar.js +13 -1
  91. package/dist/core/mods/kernel/events.d.ts +11 -3
  92. package/dist/core/mods/kernel/events.js +13 -10
  93. package/dist/core/mods/lifecycle-stations.d.ts +36 -4
  94. package/dist/core/mods/lifecycle-stations.js +44 -9
  95. package/dist/core/mods/session-append.d.ts +4 -1
  96. package/dist/core/mods/session-append.js +7 -0
  97. package/dist/core/mods/session-receive.js +12 -15
  98. package/dist/core/mods/stations.d.ts +70 -6
  99. package/dist/core/mods/stations.js +144 -1
  100. package/dist/core/own-property-receipt.d.ts +7 -0
  101. package/dist/core/own-property-receipt.js +3 -0
  102. package/dist/core/park-selfcheck.js +2 -2
  103. package/dist/core/pause-registry.d.ts +2 -0
  104. package/dist/core/pause-registry.js +3 -0
  105. package/dist/core/permission-rule-consent.d.ts +10 -3
  106. package/dist/core/permission-rule-consent.js +37 -24
  107. package/dist/core/permission-rule-store.d.ts +35 -1
  108. package/dist/core/permission-rule-store.js +27 -8
  109. package/dist/core/read-only-shell.js +3 -2
  110. package/dist/core/read-root-candidate.js +1 -1
  111. package/dist/core/redaction-marks.d.ts +8 -0
  112. package/dist/core/redaction-marks.js +6 -0
  113. package/dist/core/remote-env.d.ts +12 -1
  114. package/dist/core/remote-env.js +3 -0
  115. package/dist/core/resume-startup-cause.d.ts +5 -4
  116. package/dist/core/runner/child-tree.d.ts +29 -3
  117. package/dist/core/runner/child-tree.js +39 -16
  118. package/dist/core/runner/compact-session.js +5 -2
  119. package/dist/core/runner/contracts.d.ts +36 -17
  120. package/dist/core/runner/delegation-owner.d.ts +43 -0
  121. package/dist/core/runner/delegation-owner.js +59 -0
  122. package/dist/core/runner/gate-exit.js +2 -2
  123. package/dist/core/runner/inherited-ask-grants.js +1 -1
  124. package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
  125. package/dist/core/runner/lineage-reroot-view.js +108 -0
  126. package/dist/core/runner/memory-consolidation-driver.d.ts +6 -3
  127. package/dist/core/runner/memory-consolidation-driver.js +4 -4
  128. package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
  129. package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
  130. package/dist/core/runner/permission-rule-lanes.d.ts +2 -1
  131. package/dist/core/runner/permission-rule-lanes.js +2 -2
  132. package/dist/core/runner/person-path-rows.d.ts +23 -3
  133. package/dist/core/runner/person-path-rows.js +31 -4
  134. package/dist/core/runner/placement-fence.d.ts +12 -0
  135. package/dist/core/runner/placement-fence.js +20 -6
  136. package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
  137. package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
  138. package/dist/core/runner/prepare-ask-lane.js +2 -2
  139. package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -1
  140. package/dist/core/runner/prepare-caps-and-workflow.js +6 -3
  141. package/dist/core/runner/prepare-config-doors.d.ts +6 -6
  142. package/dist/core/runner/prepare-config-doors.js +3 -4
  143. package/dist/core/runner/prepare-execution-env.js +17 -6
  144. package/dist/core/runner/prepare-hands-readface.d.ts +3 -2
  145. package/dist/core/runner/prepare-hands-readface.js +32 -10
  146. package/dist/core/runner/prepare-inherited-gate.d.ts +12 -8
  147. package/dist/core/runner/prepare-inherited-gate.js +14 -6
  148. package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
  149. package/dist/core/runner/prepare-memory-engine-session.js +4 -4
  150. package/dist/core/runner/prepare-memory.d.ts +3 -2
  151. package/dist/core/runner/prepare-memory.js +28 -20
  152. package/dist/core/runner/prepare-park-ask.js +4 -3
  153. package/dist/core/runner/prepare-task.js +22 -16
  154. package/dist/core/runner/prepare-workspace-restore.js +3 -6
  155. package/dist/core/runner/resume-admission.d.ts +3 -3
  156. package/dist/core/runner/resume-admission.js +6 -3
  157. package/dist/core/runner/resume-apply.d.ts +4 -0
  158. package/dist/core/runner/resume-apply.js +11 -4
  159. package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
  160. package/dist/core/runner/resume-checkpoint-screen.js +4 -84
  161. package/dist/core/runner/run-git-lane.d.ts +2 -0
  162. package/dist/core/runner/run-git-lane.js +4 -1
  163. package/dist/core/runner/run-harness-handlers.d.ts +2 -0
  164. package/dist/core/runner/run-harness-handlers.js +3 -2
  165. package/dist/core/runner/run-leg.js +25 -8
  166. package/dist/core/runner/run-settle-and-teardown.js +6 -4
  167. package/dist/core/runner/run-stop-and-final-verify.js +2 -1
  168. package/dist/core/runner/run-turn-boundary.js +7 -4
  169. package/dist/core/runner/runtask.js +6 -6
  170. package/dist/core/runner/steering-preview.d.ts +9 -0
  171. package/dist/core/runner/steering-preview.js +5 -0
  172. package/dist/core/runner/stream-steer-verb.js +8 -0
  173. package/dist/core/runner/terminal-account.js +1 -1
  174. package/dist/core/runner/tool-face-overlay.js +2 -0
  175. package/dist/core/runner/turn-attachments.d.ts +5 -0
  176. package/dist/core/runner/turn-attachments.js +1 -1
  177. package/dist/core/runner-deps.d.ts +8 -4
  178. package/dist/core/secret-env.d.ts +9 -6
  179. package/dist/core/secret-env.js +41 -22
  180. package/dist/core/session-checkout.d.ts +108 -0
  181. package/dist/core/session-checkout.js +485 -0
  182. package/dist/core/session-store.d.ts +13 -5
  183. package/dist/core/session-store.js +28 -4
  184. package/dist/core/session.d.ts +29 -5
  185. package/dist/core/session.js +3 -0
  186. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +6 -12
  187. package/dist/core/store-contracts/checkpoint-store-contract.js +73 -6
  188. package/dist/core/store-contracts/session-store-contract.js +61 -8
  189. package/dist/core/task-event.d.ts +28 -1
  190. package/dist/core/task-notification.d.ts +9 -1
  191. package/dist/core/task-notification.js +8 -1
  192. package/dist/core/task-registry-agent.d.ts +40 -8
  193. package/dist/core/task-registry-agent.js +57 -24
  194. package/dist/core/task-registry-shared.d.ts +33 -11
  195. package/dist/core/task-registry-workflow.js +4 -3
  196. package/dist/core/task-registry.d.ts +27 -10
  197. package/dist/core/task-registry.js +19 -13
  198. package/dist/core/task-result.d.ts +5 -5
  199. package/dist/core/task-spec-members.js +1 -1
  200. package/dist/core/task-spec.d.ts +21 -1
  201. package/dist/core/terminal-cause.d.ts +6 -6
  202. package/dist/core/tool-face.d.ts +6 -2
  203. package/dist/core/tool-face.js +1 -1
  204. package/dist/core/tool-policy.d.ts +16 -13
  205. package/dist/core/tool-policy.js +11 -10
  206. package/dist/core/tool-roster.d.ts +4 -4
  207. package/dist/core/tool-spec.d.ts +42 -19
  208. package/dist/core/types.d.ts +2 -2
  209. package/dist/core/types.js +1 -1
  210. package/dist/core/untrusted-egress.d.ts +15 -4
  211. package/dist/core/untrusted-egress.js +23 -22
  212. package/dist/core/workspace-snapshot.d.ts +3 -1
  213. package/dist/core/workspace-snapshot.js +1 -0
  214. package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
  215. package/dist/engine/execution-env/node-execution-env.js +12 -5
  216. package/dist/engine/harness/types.d.ts +77 -1
  217. package/dist/engine/harness/types.js +108 -0
  218. package/dist/engine/session/import-validate.js +6 -1
  219. package/dist/engine/session/parent-chain-guard.d.ts +3 -3
  220. package/dist/engine/session/parent-chain-guard.js +1 -1
  221. package/dist/engine/session/path-to-root.d.ts +18 -3
  222. package/dist/engine/session/path-to-root.js +15 -1
  223. package/dist/engine/session/repo-utils.d.ts +12 -1
  224. package/dist/engine/session/repo-utils.js +41 -0
  225. package/dist/engine/session/session.d.ts +24 -1
  226. package/dist/engine/session/session.js +46 -2
  227. package/dist/engine/session/storage-base.d.ts +20 -0
  228. package/dist/engine/session/storage-base.js +28 -9
  229. package/dist/index.d.ts +16 -12
  230. package/dist/index.js +11 -8
  231. package/dist/internal/harness-types.d.ts +1 -1
  232. package/dist/internal/harness.d.ts +4 -3
  233. package/dist/internal/harness.js +3 -2
  234. package/dist/orchestration/run-workflow-tool.d.ts +7 -1
  235. package/dist/orchestration/run-workflow-tool.js +28 -11
  236. package/dist/orchestration/workflow-governance.d.ts +1 -1
  237. package/dist/orchestration/workflow.d.ts +6 -0
  238. package/dist/orchestration/workflow.js +5 -8
  239. package/dist/stores/file/checkpoint-store.d.ts +2 -0
  240. package/dist/stores/file/checkpoint-store.js +7 -6
  241. package/dist/stores/file/fs-atomic.d.ts +0 -22
  242. package/dist/stores/file/fs-atomic.js +0 -17
  243. package/dist/stores/file/index.d.ts +2 -9
  244. package/dist/stores/file/index.js +2 -4
  245. package/dist/stores/file/session-store.d.ts +13 -7
  246. package/dist/stores/file/session-store.js +42 -18
  247. package/dist/tools/fs/bash-program-position.d.ts +3 -2
  248. package/dist/tools/fs/bash-program-position.js +10 -10
  249. package/dist/tools/fs/program-read-model.d.ts +34 -10
  250. package/dist/tools/fs/program-read-model.js +37 -7
  251. package/dist/tools/fs/program-read-model.rows.js +13 -2
  252. package/dist/tools/fs/read-deny.d.ts +13 -1
  253. package/dist/tools/fs/read-deny.js +10 -2
  254. package/dist/tools/fs/removal-targets.js +5 -5
  255. package/dist/tools/fs/safety.d.ts +2 -0
  256. package/dist/tools/fs/safety.js +1 -1
  257. package/dist/tools/fs/shell-read-argv.d.ts +11 -2
  258. package/dist/tools/fs/shell-read-argv.js +45 -29
  259. package/dist/tools/fs/shell-read-bindings.d.ts +20 -2
  260. package/dist/tools/fs/shell-read-bindings.js +153 -69
  261. package/dist/tools/fs/shell-read-brace.d.ts +18 -0
  262. package/dist/tools/fs/shell-read-brace.js +79 -0
  263. package/dist/tools/fs/shell-read-check.js +29 -11
  264. package/dist/tools/fs/shell-read-establish.js +43 -22
  265. package/dist/tools/fs/shell-read-functions.js +2 -2
  266. package/dist/tools/fs/shell-read-judge.d.ts +11 -0
  267. package/dist/tools/fs/shell-read-judge.js +3 -3
  268. package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
  269. package/dist/tools/fs/shell-read-object-path.js +119 -0
  270. package/dist/tools/fs/shell-read-plan.d.ts +18 -0
  271. package/dist/tools/fs/shell-read-plan.js +217 -104
  272. package/dist/tools/fs/shell-read-start.d.ts +76 -13
  273. package/dist/tools/fs/shell-read-start.js +97 -17
  274. package/dist/tools/fs/shell-read-word.d.ts +10 -0
  275. package/dist/tools/fs/shell-read-word.js +9 -5
  276. package/dist/tools/fs/shell-read-workdir.d.ts +54 -14
  277. package/dist/tools/fs/shell-read-workdir.js +103 -19
  278. package/dist/tools/fs/shell-read-write-targets.js +13 -8
  279. package/dist/tools/worktree.d.ts +3 -2
  280. package/dist/tools/worktree.js +7 -35
  281. package/package.json +3 -2
  282. package/test/export-surface.snapshot.json +93 -43
  283. package/wire-changes/core-stores-sql@7.62.0.json +30 -0
  284. package/wire-changes/core-stores-sql@7.63.0.json +30 -0
  285. package/wire-changes/core@7.62.0.json +2181 -0
  286. package/wire-changes/core@7.63.0.json +3523 -0
  287. package/wire-changes/mods-kernel@7.62.0.json +42 -0
  288. package/wire-changes/mods-kernel@7.63.0.json +30 -0
  289. package/wire-changes/primitives@7.62.0.json +30 -0
  290. package/wire-changes/primitives@7.63.0.json +445 -0
  291. package/dist/core/consolidate-scope.d.ts +0 -93
  292. package/dist/core/consolidate-scope.js +0 -98
  293. package/dist/core/credential-vocabulary.d.ts +0 -176
  294. package/dist/core/credential-vocabulary.js +0 -190
  295. package/dist/core/redaction-passes.d.ts +0 -82
  296. package/dist/core/redaction-passes.js +0 -377
  297. package/dist/core/runner/memory-consolidation.d.ts +0 -109
  298. package/dist/core/runner/memory-consolidation.js +0 -251
@@ -1,13 +1,45 @@
1
1
  /**
2
- * A leg's two lifecycle stations over its bus, both observations (an answer changes nothing, a failure skips the handler).
2
+ * A leg's lifecycle stations over its bus, all observations (an answer changes nothing, a failure skips the handler). Each
3
+ * entry reads first, synchronously, whether its event (or the classic event raised in its bottom) is heard — none ⇒ nothing
4
+ * is raised and nothing is awaited.
5
+ * `session.start`: the leg opened (prepared, before its first model request); `e = { cwd, sessionId, agentId? }`; its bottom
6
+ * raises `classic.SessionStart` with the same `e` and comes up as `{ cwd }`.
7
+ * `turn.start`: a model turn began, before its first model request; `e = { turn, agentId? }` (`turn` = 1 for the leg's first);
8
+ * the bottom comes up as `{ turn }`.
3
9
  * `turn.complete`: the turn's end records it ({@link noteCompletedTurn}); the next await point raises it once
4
10
  * ({@link raiseCompletedTurn}) — the turn boundary after it, or the leg's settle for a turn whose boundary never ran.
5
11
  * `e = { answer, reason, turn, isAborted, agentId?, usage? }`; the bottom comes up as `{ text: answer, usage? }`.
6
- * `session.end`: a leg's terminal settled; `e = { reason, sessionId, agentId? }`, `reason` the terminal status word.
12
+ * `session.measure`: a turn boundary measured the leg's context occupancy and it moved since the last measurement
13
+ * ({@link measureSession} — the one write `$.session.usage` reads); `e = { context, changed, agentId? }`; the bottom comes up as
14
+ * `{ changed }`.
15
+ * `session.end`: a leg's terminal settled; `e = { reason, sessionId, agentId? }`, `reason` the terminal status word; its bottom
16
+ * raises `classic.SessionEnd` with the same `e` and comes up as `{ sessionId }`.
7
17
  */
8
18
  import type { AssistantMessage } from "../../internal/llm.js";
19
+ import type { maybeCompact } from "../auto-compaction.js";
9
20
  import type { HookInvocationIdentity } from "../hooks.js";
10
21
  import { type LegModBus } from "./stations.js";
22
+ /** Raise `session.start` as the leg opens; `undefined` (nothing raised, nothing to await) when neither it nor
23
+ * `classic.SessionStart` is heard. */
24
+ export declare function raiseSessionStart(bus: LegModBus, identity: HookInvocationIdentity | undefined, start: {
25
+ readonly cwd: string;
26
+ readonly sessionId: string;
27
+ }, signal: AbortSignal | undefined): Promise<void> | undefined;
28
+ /** Raise `turn.start` for the turn beginning (`turn` = its number); `undefined` when no handler hangs on it. */
29
+ export declare function raiseStartedTurn(bus: LegModBus, identity: HookInvocationIdentity | undefined, turn: number, signal: AbortSignal | undefined): Promise<void> | undefined;
30
+ /** A leg's context occupancy as a turn boundary measured it: the compaction pass's own `contextUsage` — the three numbers the
31
+ * boundary's `context_usage` frame carries. */
32
+ export type ContextOccupancy = Readonly<NonNullable<Awaited<ReturnType<typeof maybeCompact>>["contextUsage"]>>;
33
+ /** What `session.measure`'s `changed` names: the units that moved (the leg measures one). */
34
+ export declare const SESSION_MEASURE_UNITS: readonly ["context"];
35
+ export type SessionMeasureUnit = (typeof SESSION_MEASURE_UNITS)[number];
36
+ /** Where a leg keeps its latest measurement: written once per boundary by {@link measureSession}, read by `$.session.usage`. */
37
+ export interface SessionMeasureSeat {
38
+ context?: ContextOccupancy;
39
+ }
40
+ /** Record a boundary's measurement on the seat (always), then raise `session.measure` when the occupancy moved since the
41
+ * last one (the first measurement moved from none); `undefined` when nothing is raised. */
42
+ export declare function measureSession(bus: LegModBus, seat: SessionMeasureSeat, measured: ContextOccupancy, identity: HookInvocationIdentity | undefined, signal: AbortSignal | undefined): Promise<void> | undefined;
11
43
  /** Why a model turn ended. */
12
44
  export type CompletedTurnReason = "answer" | "aborted" | "error";
13
45
  /** A model turn that ended, as `turn.complete` names it (raised once, then gone). */
@@ -34,8 +66,8 @@ export declare function noteCompletedTurn(bus: LegModBus, seat: CompletedTurnSea
34
66
  /** Raise `turn.complete` for each turn the seat holds, in order, each once (the seat is emptied first). An engine-side
35
67
  * rejection is swallowed: an observation never changes what it observes. */
36
68
  export declare function raiseCompletedTurn(bus: LegModBus, seat: CompletedTurnSeat, identity: HookInvocationIdentity | undefined, signal: AbortSignal | undefined): Promise<void>;
37
- /** Raise `session.end` as the leg's terminal settles (nothing when no handler hangs on it). */
69
+ /** Raise `session.end` as the leg's terminal settles; `undefined` when neither it nor `classic.SessionEnd` is heard. */
38
70
  export declare function raiseSessionEnd(bus: LegModBus, identity: HookInvocationIdentity | undefined, end: {
39
71
  readonly reason: string;
40
72
  readonly sessionId: string;
41
- }): Promise<void>;
73
+ }): Promise<void> | undefined;
@@ -1,4 +1,40 @@
1
- import { classicEventBase } from "./stations.js";
1
+ import { classicEventBase, observeClassic } from "./stations.js";
2
+ const hearsEither = (bus, typed, classic) => bus.hasHandlers(typed) || bus.hasHandlers(classic);
3
+ export function raiseSessionStart(bus, identity, start, signal) {
4
+ if (!hearsEither(bus, "session.start", "classic.SessionStart"))
5
+ return undefined;
6
+ const e = { ...classicEventBase(identity), cwd: start.cwd, sessionId: start.sessionId };
7
+ const core = Object.freeze({ cwd: start.cwd });
8
+ return observeLifecycle(bus, "session.start", e, async () => {
9
+ await observeClassic(bus, "classic.SessionStart", e, signal);
10
+ return core;
11
+ }, signal);
12
+ }
13
+ export function raiseStartedTurn(bus, identity, turn, signal) {
14
+ if (!bus.hasHandlers("turn.start"))
15
+ return undefined;
16
+ const core = Object.freeze({ turn });
17
+ return observeLifecycle(bus, "turn.start", { ...classicEventBase(identity), turn }, () => core, signal);
18
+ }
19
+ export const SESSION_MEASURE_UNITS = Object.freeze(["context"]);
20
+ export function measureSession(bus, seat, measured, identity, signal) {
21
+ const before = seat.context;
22
+ const context = Object.freeze({ usedTokens: measured.usedTokens, windowTokens: measured.windowTokens, compactAtTokens: measured.compactAtTokens });
23
+ seat.context = context;
24
+ const moved = before === undefined || before.usedTokens !== context.usedTokens || before.windowTokens !== context.windowTokens || before.compactAtTokens !== context.compactAtTokens;
25
+ if (!moved || !bus.hasHandlers("session.measure"))
26
+ return undefined;
27
+ const changed = Object.freeze(["context"]);
28
+ const core = Object.freeze({ changed });
29
+ return observeLifecycle(bus, "session.measure", { ...classicEventBase(identity), context, changed }, () => core, signal);
30
+ }
31
+ async function observeLifecycle(bus, event, e, bottom, signal) {
32
+ try {
33
+ await bus.dispatch(event, e, { bottom, ...(signal !== undefined ? { signal } : {}) });
34
+ }
35
+ catch {
36
+ }
37
+ }
2
38
  const answerOf = (message) => (message?.content ?? []).flatMap((c) => (c.type === "text" ? [c.text] : [])).join("");
3
39
  export function noteCompletedTurn(bus, seat, message, turn, aborted, usage) {
4
40
  if (!bus.hasHandlers("turn.complete"))
@@ -22,14 +58,13 @@ export async function raiseCompletedTurn(bus, seat, identity, signal) {
22
58
  }
23
59
  }
24
60
  }
25
- export async function raiseSessionEnd(bus, identity, end) {
26
- if (!bus.hasHandlers("session.end"))
27
- return;
61
+ export function raiseSessionEnd(bus, identity, end) {
62
+ if (!hearsEither(bus, "session.end", "classic.SessionEnd"))
63
+ return undefined;
28
64
  const e = { ...classicEventBase(identity), reason: end.reason, sessionId: end.sessionId };
29
65
  const core = Object.freeze({ sessionId: end.sessionId });
30
- try {
31
- await bus.dispatch("session.end", e, { bottom: () => core });
32
- }
33
- catch {
34
- }
66
+ return observeLifecycle(bus, "session.end", e, async () => {
67
+ await observeClassic(bus, "classic.SessionEnd", e, undefined);
68
+ return core;
69
+ }, undefined);
35
70
  }
@@ -36,7 +36,7 @@
36
36
  * conversation the leg goes on with — stored by the port (`AgentHarness.appendMessage`), or carried by a durable park's row
37
37
  * (`heldRows`); once the park is taken, or may have been, the call throws `$.session.append: refused: …`.
38
38
  */
39
- import type { AgentMessage, RowAdmission, RowRaising } from "../../internal/harness-types.js";
39
+ import type { AgentMessage, RowAdmission, RowRaising, SessionTreeEntry } from "../../internal/harness-types.js";
40
40
  import type { AgentHarness } from "../../internal/harness.js";
41
41
  import { type FrameSettlement } from "../frame-settlement.js";
42
42
  import type { HookInvocationIdentity } from "../hooks.js";
@@ -67,6 +67,9 @@ export type SessionAppendOrigin = {
67
67
  * read is a `note` (a user-lane note, or a row of its own kind), a `delivery` (a frame with its delivery key) or an
68
68
  * `attachment`; the model's turn is a `response`, a tool's answer a `tool-result`. */
69
69
  export declare function doorOf(row: AgentMessage): SessionAppendDoor;
70
+ /** `$.session.turns()`: how many prompts a branch holds from its people — its message rows whose door ({@link doorOf}) is
71
+ * `prompt`. A steer is the engine's note on the person's behalf (`provenance: "engine-note"`), so it is not one. */
72
+ export declare function promptCountOf(branch: ReadonlyArray<SessionTreeEntry>): number;
70
73
  /** A row's maker, from its typed facts: the model, the tool that answered, the host (a prompt, an attachment the host
71
74
  * declared), else the engine. */
72
75
  export declare function originOf(row: AgentMessage): SessionAppendOrigin;
@@ -22,6 +22,13 @@ export function doorOf(row) {
22
22
  return "note";
23
23
  }
24
24
  }
25
+ export function promptCountOf(branch) {
26
+ let n = 0;
27
+ for (const entry of branch)
28
+ if (entry.type === "message" && doorOf(entry.message) === "prompt")
29
+ n += 1;
30
+ return n;
31
+ }
25
32
  const HOST = Object.freeze({ kind: "host" });
26
33
  const ENGINE = Object.freeze({ kind: "engine" });
27
34
  export function originOf(row) {
@@ -3,7 +3,7 @@ import { describeThrown } from "../tool-policy.js";
3
3
  import { extensionWords } from "../untrusted-egress.js";
4
4
  import { ENGINE_ORIGIN } from "./kernel/index.js";
5
5
  import { isPlainRecord } from "./kernel/receive.js";
6
- import { classicEventBase, failedHandlerClause, seatHears } from "./stations.js";
6
+ import { classicEventBase, failedHandlerClause, seatHears, textChanges } from "./stations.js";
7
7
  export const SESSION_RECEIVE_ORIGIN_KINDS = Object.freeze(["task", "agent", "peer", "host", "engine"]);
8
8
  const ENGINE = Object.freeze({ kind: "engine" });
9
9
  export function receiveOriginOf(p) {
@@ -47,18 +47,24 @@ export function createReceiveSeat() {
47
47
  const made = payload.received === undefined ? payload : (({ received: _r, ...rest }) => rest)(payload);
48
48
  const text = renderTaskNotificationXml(made);
49
49
  const e = { ...classicEventBase(binding.identity), origin: receiveOriginOf(made), event: eventOf(made), text };
50
- const handOns = [];
50
+ const changes = textChanges(text);
51
51
  const checkHandOn = (handed, by) => {
52
52
  const t = handed["text"];
53
53
  if (typeof t !== "string" || t.trim() === "")
54
54
  return "next() handed on a text that is not a non-blank string";
55
- handOns.push({ by: by.plugin, text: t });
55
+ changes.handedOn(by.plugin, t);
56
56
  return undefined;
57
57
  };
58
58
  const bottom = (handed) => Object.freeze({ text: handed["text"] });
59
- const checkAnswer = (a) => {
59
+ const checkAnswer = (a, handed, by, below) => {
60
60
  const read = readAnswer(a);
61
- return "why" in read ? read.why : undefined;
61
+ if ("why" in read)
62
+ return read.why;
63
+ if ("text" in read) {
64
+ const up = below.length > 0 ? readAnswer(below[below.length - 1]) : undefined;
65
+ changes.answered(by.plugin, read.text, handed["text"], up !== undefined && "text" in up ? up.text : undefined);
66
+ }
67
+ return undefined;
62
68
  };
63
69
  let outcome;
64
70
  try {
@@ -79,16 +85,7 @@ export function createReceiveSeat() {
79
85
  return consumed(binding, made, by, `extension "${extensionWords(by, 80)}" answered in a form session.receive does not take (${read.why}); the frame was not handed over (fail-closed)`);
80
86
  if (read.text === text)
81
87
  return Object.freeze({ kind: "arrived", payload: made });
82
- const rewrittenBy = [];
83
- let before = text;
84
- for (const h of handOns) {
85
- if (h.text !== before && !rewrittenBy.includes(h.by))
86
- rewrittenBy.push(h.by);
87
- before = h.text;
88
- }
89
- if (read.text !== before && !rewrittenBy.includes(by))
90
- rewrittenBy.push(by);
91
- return Object.freeze({ kind: "arrived", payload: { ...made, received: Object.freeze({ text: read.text, rewrittenBy: Object.freeze(rewrittenBy) }) } });
88
+ return Object.freeze({ kind: "arrived", payload: { ...made, received: Object.freeze({ text: read.text, rewrittenBy: changes.rewrittenBy() }) } });
92
89
  };
93
90
  return {
94
91
  listens: () => seatHears(bound, "session.receive"),
@@ -1,4 +1,6 @@
1
- import type { ExecutionEnv, ReadFloor } from "../../internal/harness-types.js";
1
+ import type { AgentMessage, ExecutionEnv, ReadFloor } from "../../internal/harness-types.js";
2
+ import type { TaskAccess, TaskRegistry } from "../task-registry.js";
3
+ import type { SessionMeasureSeat } from "./lifecycle-stations.js";
2
4
  import type { AssistantMessage, Message, Model, Usage } from "../../internal/llm.js";
3
5
  import type { CwdRef } from "../../tools/fs/fs-shared.js";
4
6
  import { type PermissionResult, type ToolCallRequest } from "../tool-policy.js";
@@ -11,7 +13,7 @@ import { type ModAnswerCheck, type ModAnswerRanks, type ModBus, type ModCallEntr
11
13
  import { type SourcedOverlay } from "../../prompt-assembly/overlay.js";
12
14
  import type { BandId } from "../../prompt-assembly/catalog/schema.js";
13
15
  import type { ModParticipant } from "./kernel/dispatch.js";
14
- import { type EngineDollar, type ModelCompleteRequest, type ModelCompleteResult, type ModSeatView } from "./dollar.js";
16
+ import { type EngineDollar, type ModelCompleteRequest, type ModelCompleteResult, type ModSeatView, type SessionUsage, type SessionVersion } from "./dollar.js";
15
17
  import type { SkillSpec } from "../agent-definition.js";
16
18
  import { type SkillScopes } from "./spec-seats.js";
17
19
  /**
@@ -203,9 +205,13 @@ export declare function observePermissionDenied(input: {
203
205
  readonly signal: AbortSignal | undefined;
204
206
  readonly onHostObserverFailure: (err: Error) => void;
205
207
  }): Promise<void>;
206
- /** What a `classic.UserPromptSubmit` screen came to, as the four entrances read it. */
208
+ /** What a prompt's screen came to, as the four entrances read it: `text` is what the entrance delivers (the prompt as it
209
+ * came, or as `prompt.submit` handed it on — `rewrittenBy` then names who changed it, in the order they did); `block` the
210
+ * refusal (a `prompt.submit` drop, or `classic.UserPromptSubmit`'s block). */
207
211
  export type PromptScreen = {
208
212
  readonly kind: "answered";
213
+ readonly text: string;
214
+ readonly rewrittenBy?: readonly string[];
209
215
  readonly block?: string;
210
216
  readonly additionalContext?: string;
211
217
  } | Extract<ModDispatchOutcome, {
@@ -213,10 +219,50 @@ export type PromptScreen = {
213
219
  }> | {
214
220
  readonly kind: "aborted";
215
221
  };
222
+ /** Who changed a text a chain carried, read off the chain as it runs (a station's `checkHandOn` and `checkAnswer` feed it). */
223
+ export interface TextChanges {
224
+ /** A handler handed `text` on (down): it changed the text when that differs from what the previous hand-on (or the
225
+ * original) carried. */
226
+ handedOn(by: string, text: string): void;
227
+ /** A handler answered `text` (up): it changed the text when that differs from what its `next` answered (`below`) or, when
228
+ * it answered without one, from the text it was handed. */
229
+ answered(by: string, text: string, handed: string, below: string | undefined): void;
230
+ /** The handlers that changed the text, in the order they did (down before up), each named once. */
231
+ rewrittenBy(): readonly string[];
232
+ }
233
+ /** The one reading of who changed a text, for every station whose answer is a rewritten text (`session.receive`,
234
+ * `prompt.submit`): a handler is named for the change it made — handing a different text on, or answering a different text
235
+ * than the one that came up to it — never for carrying another handler's change up. */
236
+ export declare function textChanges(original: string): TextChanges;
237
+ /** The stations a prompt's screen is — `prompt.submit`, and `classic.UserPromptSubmit` raised in its bottom. The one list:
238
+ * the entrances raise these and nothing else on a prompt, and every reading of "is the screen heard" reads it, so a station
239
+ * added here is heard by all of them. Both are the engine bus's (`MOD_EVENT_TABLE`). */
240
+ export declare const PROMPT_SCREEN_STATIONS: readonly ModEventName[];
241
+ /** The four entrances' one predicate: does the leg hear a prompt's screen — `prompt.submit`, or `classic.UserPromptSubmit`
242
+ * raised in its bottom? The bus's reading of {@link promptScreenHeard}; {@link promptScreenDeclaredBy} is the registrations'. */
243
+ export declare function promptScreenHasHandlers(bus: LegModBus): boolean;
216
244
  /**
217
- * Raise `classic.UserPromptSubmit` (undefined when no handler hangs on it). A decision event: a handler that throws,
218
- * runs past its budget or breaks the site's contract ends the screen `failed`, and every entrance fails closed on it;
219
- * a cancelled screen ends `aborted` at once. A dispatch the engine itself could not run is `failed` too.
245
+ * Whether a set of registrations declares a prompt screen: some `uses.events` pattern — an event name or a `<prefix>.*`,
246
+ * expanded on the engine bus as admission expands it (`expandOnSide`) — selects `prompt.submit` or `classic.UserPromptSubmit`
247
+ * ({@link PROMPT_SCREEN_STATIONS}). The reading for a host that holds registrations before any bus is admitted (an acceptance
248
+ * seat that must know, before it writes a byte, whether the prompt will be screened); the bus's reading is
249
+ * {@link promptScreenHasHandlers} over what the admitted registrations hung. A declaration is the upper bound on what a
250
+ * registration hangs, so a registration that declares a station and hangs nothing on it is declared here and unheard there.
251
+ * A pattern admission would refuse (not a name, not a list, a name no bus reads) selects nothing here — admission refuses the
252
+ * registration itself, with `config.mods_invalid`.
253
+ */
254
+ export declare function promptScreenDeclaredBy(registrations: readonly {
255
+ readonly uses: {
256
+ readonly events: readonly string[];
257
+ };
258
+ }[]): boolean;
259
+ /**
260
+ * A prompt's screen at one of the four entrances (objective, live steer, a wake's message before its claim, a parked steer
261
+ * redelivered): `prompt.submit` over `e` with the prompt as `text`, its bottom raising `classic.UserPromptSubmit` on the text
262
+ * handed down; `undefined` (nothing raised) when neither is heard ({@link promptScreenHasHandlers}). A decision event: a
263
+ * handler that throws, runs past its budget or breaks the site's contract ends the screen `failed`, and every entrance fails
264
+ * closed on it; a cancelled screen ends `aborted` at once; a dispatch the engine could not run is `failed` too. What the
265
+ * classic screen refused (its block, failure or cancel) is final — a `prompt.submit` handler above it does not undo it.
220
266
  */
221
267
  export declare function screenUserPrompt(bus: LegModBus, e: UserPromptSubmitEvent, signal: AbortSignal | undefined): Promise<PromptScreen | undefined>;
222
268
  /**
@@ -299,6 +345,11 @@ export interface LegFacadeSeats {
299
345
  root(): string;
300
346
  model(): string;
301
347
  messages(): readonly Message[];
348
+ /** `$.session.messages({ agentId })`'s read ({@link agentRowsOf}). */
349
+ agentMessages(agentId: string): Promise<readonly AgentMessage[]>;
350
+ turns(): Promise<number>;
351
+ usage(): SessionUsage;
352
+ version(): SessionVersion;
302
353
  now(): number;
303
354
  tools(): readonly string[];
304
355
  agents(): readonly string[];
@@ -360,6 +411,13 @@ export interface LegFacadeInput {
360
411
  readonly lastBrainContext: () => {
361
412
  readonly messages: readonly Message[];
362
413
  } | undefined;
414
+ /** Where the leg's subagents' transcripts are read ({@link agentRowsOf}); `undefined` ⇒ there is no task list (a
415
+ * session-level pass), and the read refuses saying so. */
416
+ readonly agentSessions: AgentSessionsSeat | undefined;
417
+ /** The session's prompt count, read at the call (`promptCountOf` over its branch, `session-append.ts`). */
418
+ readonly turns: () => Promise<number>;
419
+ /** The leg's measurement seat (`measureSession` writes it at each turn boundary). */
420
+ readonly measure: SessionMeasureSeat;
363
421
  readonly activeTools: ReadonlySet<string>;
364
422
  readonly agentListing: {
365
423
  readonly entries: ReadonlyArray<{
@@ -384,6 +442,12 @@ export interface LegFacadeInput {
384
442
  /** `$.session.compact`'s host entry, over the leg's compaction station. */
385
443
  readonly sessionCompact: ModCallEntry;
386
444
  }
445
+ /** The seat a leg reads its subagents' transcripts through: its task list, only the rows its own access reaches. Each row
446
+ * carries the store its child's session lives in, so no store of the leg's own is read. */
447
+ export interface AgentSessionsSeat {
448
+ readonly registry: Pick<TaskRegistry, "anchoredSession">;
449
+ readonly access: TaskAccess;
450
+ }
387
451
  /** The engine facade's seats over a prepared leg — each one a seat the leg already has (no new capability). */
388
452
  export declare function legFacadeSeats(input: LegFacadeInput): LegFacadeSeats;
389
453
  /**
@@ -1,11 +1,12 @@
1
1
  import { types } from "node:util";
2
+ import { engineVersion } from "../version.js";
2
3
  import { resolveModel } from "../roles.js";
3
4
  import { brainToRuntime } from "../runtime.js";
4
5
  import { deliverEngineNotice } from "../engine-notice.js";
5
6
  import { extensionWords } from "../untrusted-egress.js";
6
7
  import { askApproverIdentity, describeThrown, ownArgs } from "../tool-policy.js";
7
8
  import { agentIdOf } from "../leg-identity.js";
8
- import { admitMods } from "./kernel/index.js";
9
+ import { admitMods, expandOnSide } from "./kernel/index.js";
9
10
  import { legBusOf } from "./extension-call.js";
10
11
  import { validateOverlay } from "../../prompt-assembly/overlay.js";
11
12
  import { modsInvalid } from "./kernel/registration.js";
@@ -200,7 +201,120 @@ export async function observePermissionDenied(input) {
200
201
  await observeClassic(own, "classic.PermissionDenied", e, input.signal);
201
202
  }
202
203
  const USER_PROMPT_RANKS = Object.freeze({ of: (a) => (stringMembersOf(a, ["block"]).block ? 1 : 0), top: 1 });
204
+ export function textChanges(original) {
205
+ const changers = [];
206
+ const note = (by) => {
207
+ if (!changers.includes(by))
208
+ changers.push(by);
209
+ };
210
+ let before = original;
211
+ return {
212
+ handedOn: (by, text) => {
213
+ if (text !== before)
214
+ note(by);
215
+ before = text;
216
+ },
217
+ answered: (by, text, handed, below) => {
218
+ if (text !== (below ?? handed))
219
+ note(by);
220
+ },
221
+ rewrittenBy: () => Object.freeze([...changers]),
222
+ };
223
+ }
224
+ export const PROMPT_SCREEN_STATIONS = Object.freeze(["prompt.submit", "classic.UserPromptSubmit"]);
225
+ function promptScreenHeard(hears) {
226
+ return PROMPT_SCREEN_STATIONS.some(hears);
227
+ }
228
+ export function promptScreenHasHandlers(bus) {
229
+ return promptScreenHeard((station) => bus.hasHandlers(station));
230
+ }
231
+ export function promptScreenDeclaredBy(registrations) {
232
+ const selected = new Set();
233
+ for (const registration of registrations) {
234
+ const patterns = registration?.uses?.events;
235
+ if (!Array.isArray(patterns))
236
+ continue;
237
+ for (const pattern of patterns) {
238
+ const expanded = expandOnSide(pattern, "engine");
239
+ if ("names" in expanded)
240
+ for (const name of expanded.names)
241
+ selected.add(name);
242
+ }
243
+ }
244
+ return promptScreenHeard((station) => selected.has(station));
245
+ }
246
+ const PROMPT_SUBMIT_FORM = "prompt.submit takes { text } (a string) or { drop: <reason> }";
247
+ function readSubmitAnswer(a) {
248
+ if (!isPlainRecord(a))
249
+ return { why: PROMPT_SUBMIT_FORM };
250
+ const keys = Object.keys(a);
251
+ if (keys.length === 1 && keys[0] === "drop") {
252
+ const r = a["drop"];
253
+ return typeof r === "string" && r.trim() !== "" ? { drop: r } : { why: "a drop that is not a reason (a non-empty string)" };
254
+ }
255
+ if (keys.length === 1 && keys[0] === "text") {
256
+ const t = a["text"];
257
+ return typeof t === "string" ? { text: t } : { why: "a text that is not a string" };
258
+ }
259
+ return { why: PROMPT_SUBMIT_FORM };
260
+ }
261
+ const PROMPT_SUBMIT_RANKS = Object.freeze({ of: (a) => (isPlainRecord(a) && Object.hasOwn(a, "drop") ? 1 : 0), top: 1 });
203
262
  export async function screenUserPrompt(bus, e, signal) {
263
+ if (!promptScreenHasHandlers(bus))
264
+ return undefined;
265
+ const { prompt, ...facts } = e;
266
+ const changes = textChanges(prompt);
267
+ const checkHandOn = (handed, by) => {
268
+ const t = handed["text"];
269
+ if (typeof t !== "string")
270
+ return "next() handed on a text that is not a string";
271
+ changes.handedOn(by.plugin, t);
272
+ return undefined;
273
+ };
274
+ const seen = {};
275
+ const bottom = async (handed) => {
276
+ const text = handed["text"];
277
+ const classic = await screenClassicPrompt(bus, { ...e, prompt: text }, signal);
278
+ if (classic !== undefined)
279
+ seen.classic = classic;
280
+ if (classic === undefined || (classic.kind === "answered" && !classic.block))
281
+ return Object.freeze({ text });
282
+ return Object.freeze({ drop: classic.kind === "answered" ? classic.block : "the classic.UserPromptSubmit screen did not clear the prompt" });
283
+ };
284
+ const checkAnswer = (a, handed, by, below) => {
285
+ const read = readSubmitAnswer(a);
286
+ if ("why" in read)
287
+ return read.why;
288
+ if ("text" in read) {
289
+ const up = below.length > 0 ? readSubmitAnswer(below[below.length - 1]) : undefined;
290
+ changes.answered(by.plugin, read.text, handed["text"], up !== undefined && "text" in up ? up.text : undefined);
291
+ }
292
+ return undefined;
293
+ };
294
+ let outcome;
295
+ try {
296
+ outcome = await bus.dispatch("prompt.submit", { ...facts, text: prompt }, { bottom, checkAnswer, checkHandOn, ranks: PROMPT_SUBMIT_RANKS, ...(signal !== undefined ? { signal } : {}) });
297
+ }
298
+ catch (err) {
299
+ return { kind: "failed", registration: "engine", cause: "threw", reason: `could not raise the screen: ${describeThrown(err)}`, skipped: [] };
300
+ }
301
+ const classic = seen.classic;
302
+ if (classic !== undefined && (classic.kind !== "answered" || classic.block))
303
+ return classic.kind === "answered" ? { ...classic, text: prompt } : classic;
304
+ if (outcome.kind !== "answered")
305
+ return outcome;
306
+ const read = readSubmitAnswer(outcome.answer);
307
+ const by = outcome.answeredBy ?? "engine";
308
+ const context = classic?.kind === "answered" && classic.additionalContext !== undefined ? { additionalContext: classic.additionalContext } : {};
309
+ if ("drop" in read)
310
+ return { kind: "answered", text: prompt, block: read.drop };
311
+ if ("why" in read)
312
+ return { kind: "failed", registration: by, cause: "violation", reason: read.why, skipped: [] };
313
+ if (read.text === prompt)
314
+ return { kind: "answered", text: prompt, ...context };
315
+ return { kind: "answered", text: read.text, rewrittenBy: changes.rewrittenBy(), ...context };
316
+ }
317
+ async function screenClassicPrompt(bus, e, signal) {
204
318
  let outcome;
205
319
  try {
206
320
  outcome = await dispatchClassic(bus, "classic.UserPromptSubmit", e, {
@@ -387,6 +501,10 @@ function lateView() {
387
501
  root: () => need("session.root").root(),
388
502
  model: () => need("session.model").model(),
389
503
  messages: () => need("session.messages").messages(),
504
+ agentMessages: (agentId) => need("session.messages").agentMessages(agentId),
505
+ turns: () => need("session.turns").turns(),
506
+ usage: () => need("session.usage").usage(),
507
+ version: () => need("session.version").version(),
390
508
  },
391
509
  now: () => need("clock.now").now(),
392
510
  tools: () => need("tool.list").tools(),
@@ -425,6 +543,27 @@ export async function admitLegMods(input) {
425
543
  ADMITTED_CHAINS.set(standing, chain);
426
544
  return { bus, standing, chain, skillScopes, report, bindFacade: late.bind };
427
545
  }
546
+ async function agentRowsOf(seat, agentId) {
547
+ const refused = (why) => new Error(`session.messages: agent ${agentId}: ${why}`);
548
+ if (seat === undefined)
549
+ throw refused("there is no task list here — a session-level pass has no run, so no subagents");
550
+ const anchor = seat.registry.anchoredSession(agentId, seat.access);
551
+ if (anchor === undefined)
552
+ throw refused("not one of this leg's subagents (no task list row this leg reaches has that id)");
553
+ if (anchor === null)
554
+ throw refused("its row names no session — not a subagent's row, or its session is not bound yet or was released");
555
+ const store = anchor.store;
556
+ if (store === undefined)
557
+ throw refused("its session was bound without the store that holds it");
558
+ let branch;
559
+ try {
560
+ branch = await (await store.acquire(anchor.sessionId, { requireExisting: true })).session.getBranch();
561
+ }
562
+ catch (err) {
563
+ throw refused(`its session could not be read (${describeThrown(err)})`);
564
+ }
565
+ return branch.flatMap((e) => (e.type === "message" ? [e.message] : []));
566
+ }
428
567
  function replyText(reply) {
429
568
  return reply.content.flatMap((c) => (c.type === "text" ? [c.text] : [])).join("");
430
569
  }
@@ -461,6 +600,10 @@ export function legFacadeSeats(input) {
461
600
  root: () => input.taskRoot,
462
601
  model: () => input.model.id,
463
602
  messages: () => input.lastBrainContext()?.messages ?? [],
603
+ agentMessages: (agentId) => agentRowsOf(input.agentSessions, agentId),
604
+ turns: () => input.turns(),
605
+ usage: () => Object.freeze(input.measure.context !== undefined ? { context: input.measure.context } : {}),
606
+ version: () => Object.freeze({ version: engineVersion() }),
464
607
  now: () => (input.deps.now ?? Date.now)(),
465
608
  tools: () => [...input.activeTools],
466
609
  agents: () => (input.agentListing?.entries ?? []).map((e) => e.name),
@@ -74,6 +74,13 @@ export interface StrayMembers {
74
74
  * {@link refuseStrayMembers} or {@link receiveMembers}.
75
75
  */
76
76
  export declare function strayMembersOf(given: object, words: OwnPropertyReceiptWords, keys: readonly string[]): StrayMembers | undefined;
77
+ /**
78
+ * THE MEMBER'S PRESENCE (module note): `name` is a member of `record` exactly when its value there is not `undefined` — an
79
+ * own key holding `undefined` and a missing key are one absence; `null`, `0`, `""` and `false` are values. The engine's one
80
+ * reading of whether a record carries a member; the names a caller handed over are the name judgment's question
81
+ * ({@link strayMembersOf}), not this one's.
82
+ */
83
+ export declare function memberPresent(record: object, name: string): boolean;
77
84
  /**
78
85
  * THE NAME-ONLY DOOR — the receipt's admission (not a Proxy, a plain record), then {@link strayMembersOf}: every own member
79
86
  * `keys` does not name is refused, all of them in one sentence, and no getter runs. For an object the door must judge but
@@ -28,6 +28,9 @@ export function strayMembersOf(given, words, keys) {
28
28
  const names = Reflect.ownKeys(given).filter((k) => typeof k === "symbol" || !keys.includes(k));
29
29
  return names.length === 0 ? undefined : Object.freeze({ names: Object.freeze(names), sentence: strayMembersSentence(words, names, keys) });
30
30
  }
31
+ export function memberPresent(record, name) {
32
+ return Reflect.get(record, name) !== undefined;
33
+ }
31
34
  export function refuseStrayMembers(given, words, keys, refusal = receiptRefusal) {
32
35
  admitPlainRecord(given, words);
33
36
  const stray = strayMembersOf(given, words, keys);
@@ -1,4 +1,4 @@
1
- import { boundInputHashOf, canonicalize } from "./canonical-json.js";
1
+ import { canonicalize, exactBoundInputHashOf } from "./canonical-json.js";
2
2
  import { mintCheckpointId, mintCheckpointToken, resolveCheckpointStore, resolveDeclaredFidelity } from "./checkpoint-store.js";
3
3
  import { stampCheckpointRequirements } from "./checkpoint-requirements.js";
4
4
  import { resolveDeclaredDurability } from "./wiring-manifest.js";
@@ -70,7 +70,7 @@ function syntheticCheckpoint(scope, fidelity) {
70
70
  toolCallId: `${scope}:call`,
71
71
  toolName: "SelfCheck",
72
72
  args: { probe: true, nested: { depth: 2, list: [1, 2, 3] } },
73
- boundInputHash: boundInputHashOf({ probe: true, nested: { depth: 2, list: [1, 2, 3] } }),
73
+ boundInputHash: exactBoundInputHashOf("SelfCheck", { probe: true, nested: { depth: 2, list: [1, 2, 3] } }),
74
74
  hasBidiControls: true,
75
75
  preview: { probe: true, note: "park wiring self-check display stub" },
76
76
  previewWithheld: "oversize",
@@ -82,6 +82,8 @@ export type PendingKind = (typeof PAUSE_REGISTRY)[GateKind]["pending"];
82
82
  export type ResumeGate = (typeof PAUSE_REGISTRY)[GateKind]["resume"] | "wake";
83
83
  /** Runtime twin of {@link GateKind}. */
84
84
  export declare function isGateKind(v: unknown): v is GateKind;
85
+ /** Runtime twin of {@link PendingKind}: a word of the registry's `pending` column. */
86
+ export declare function isPendingKind(v: unknown): v is PendingKind;
85
87
  /**
86
88
  * The approval cards whose parked row takes another deadline semantic than its gate kind's: a question parked under an
87
89
  * approval gate kind is not an approval, so its deadline voids it (`B`) instead of denying it (`A`). Read only on an
@@ -10,6 +10,9 @@ export const PAUSE_REGISTRY = {
10
10
  export function isGateKind(v) {
11
11
  return typeof v === "string" && Object.prototype.hasOwnProperty.call(PAUSE_REGISTRY, v);
12
12
  }
13
+ export function isPendingKind(v) {
14
+ return Object.values(PAUSE_REGISTRY).some((row) => row.pending === v);
15
+ }
13
16
  export const CARD_FACET_OVERRIDES = Object.freeze({ question: "B" });
14
17
  export function facetOf(gate) {
15
18
  const reading = parkedApprovalCardOf(gate);
@@ -32,6 +32,7 @@ import { type RuleOwner } from "./rule-owner.js";
32
32
  import type { RuleOfferShapeProblem } from "./rule-offer-read.js";
33
33
  import type { AssertAllKeysHandled } from "./ask-origin.js";
34
34
  import { type PermissionRuleStoreProvider } from "./permission-rule-provider.js";
35
+ import { type RuleRefusalCode, type RuleWriteCommitted } from "./permission-rule-store.js";
35
36
  /** One candidate rule inside an approval record: what it says (`behavior`), the exact text and where it
36
37
  * would apply. A card mints `allow` candidates only (a card is one person's yes); the settings import
37
38
  * carries all three behaviors, each entry under the list it was read from. */
@@ -597,8 +598,12 @@ export interface ImportPreview {
597
598
  * independent `alreadyRedeemed` axis (the single-leg replay marker: a dot-recorded-but-unlanded
598
599
  * retry is `alreadyRedeemed: true` AND `persisted`; a rule that pre-existed in the store is
599
600
  * `false` AND `deduped` — the two axes answer different questions and neither implies the other).
600
- * A refused row always carries its `reason`. `deduped` counts as LANDED: an equivalent rule
601
- * already standing means the consent is already in effect.
601
+ * A refused row always carries its `reason` (a sentence for a person, never parsed) and two closed words: `code`, the
602
+ * cause ({@link RuleRefusalCode}), and `committed`, what may be claimed about the bytes ({@link RuleWriteCommitted}) —
603
+ * `no` when the member's rule does not stand because of this call (nothing was written, or the store answered that
604
+ * nothing landed, or the rule's dot is no longer live), `unknown` when the write or the read-back that would have settled
605
+ * it did not settle, so the caller reconciles with `list()` rather than retrying blind. `deduped` counts as LANDED: an
606
+ * equivalent rule already standing means the consent is already in effect.
602
607
  *
603
608
  * design/382 §4.3 — on a SESSION-scope member the two landed words mean the same thing about a
604
609
  * different home: landed in / already in the session's OVERLAY (a session rule's home store), never
@@ -620,6 +625,8 @@ export type RedeemedBatchMember = {
620
625
  readonly rule: string;
621
626
  readonly scope: RuleScope;
622
627
  readonly status: "refused";
628
+ readonly code: RuleRefusalCode;
629
+ readonly committed: RuleWriteCommitted;
623
630
  readonly reason: string;
624
631
  };
625
632
  /**
@@ -688,7 +695,7 @@ export declare function prepareStarterBatch(opts: {
688
695
  * dot reuse included; the walk adds no concurrency primitive of its own;
689
696
  * · a refused member does NOT fold the batch: "all or nothing" is the CONFIRMATION's semantics
690
697
  * (one yes covered the whole offer), not the landing's transaction shape — the walk continues
691
- * and the member's row says refused, with the reason;
698
+ * and the member's row says refused, with its reason, cause (`code`) and claim (`committed`);
692
699
  * · resuming a partial walk IS re-walking: already-landed members answer `alreadyRedeemed: true`
693
700
  * and reuse their recorded dots (two concurrent walkers converge on one dot set, zero double
694
701
  * mints), unlanded members mint on;