@sema-agent/core 7.72.0 → 7.74.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 (375) hide show
  1. package/CHANGELOG.md +565 -0
  2. package/dist/agents/inherited-tool-pool.d.ts +26 -1
  3. package/dist/agents/inherited-tool-pool.js +46 -2
  4. package/dist/agents/list-agents-tool.js +1 -1
  5. package/dist/agents/parked-resume-drive.d.ts +10 -0
  6. package/dist/agents/parked-resume-drive.js +9 -0
  7. package/dist/agents/retain-ledger.d.ts +3 -0
  8. package/dist/agents/retain-ledger.js +3 -3
  9. package/dist/agents/send-message-tool.js +5 -4
  10. package/dist/agents/send-user-message-tool.d.ts +12 -0
  11. package/dist/agents/send-user-message-tool.js +67 -0
  12. package/dist/agents/subagent-steps.d.ts +9 -0
  13. package/dist/agents/subagent-steps.js +38 -0
  14. package/dist/agents/subagent.d.ts +2 -0
  15. package/dist/agents/subagent.js +43 -12
  16. package/dist/agents/verify.js +23 -8
  17. package/dist/agents/yield-adoption.js +3 -1
  18. package/dist/brain/anthropic.d.ts +42 -1
  19. package/dist/brain/anthropic.js +68 -13
  20. package/dist/brain/failover.d.ts +5 -0
  21. package/dist/brain/failover.js +51 -22
  22. package/dist/brain/model-lane.d.ts +12 -3
  23. package/dist/brain/model-lane.js +5 -5
  24. package/dist/brain/open-responses.js +7 -8
  25. package/dist/brain/openai.js +31 -24
  26. package/dist/brain/route-adjudicator.d.ts +33 -4
  27. package/dist/brain/route-adjudicator.js +49 -12
  28. package/dist/brain/stream-engine.js +166 -156
  29. package/dist/brain/stream-shared.d.ts +4 -3
  30. package/dist/brain/stream-shared.js +2 -2
  31. package/dist/core/actions-digest.d.ts +43 -0
  32. package/dist/core/actions-digest.js +22 -0
  33. package/dist/core/allow-entry.js +4 -4
  34. package/dist/core/ask-class.d.ts +2 -2
  35. package/dist/core/ask-headline.d.ts +1 -1
  36. package/dist/core/ask-origin.d.ts +44 -4
  37. package/dist/core/ask-origin.js +29 -10
  38. package/dist/core/auto-mode.d.ts +7 -9
  39. package/dist/core/auto-mode.js +114 -8
  40. package/dist/core/background-agent-store.d.ts +1 -0
  41. package/dist/core/background-agent-store.js +49 -8
  42. package/dist/core/checkpoint-features.d.ts +3 -2
  43. package/dist/core/checkpoint-features.js +1 -1
  44. package/dist/core/checkpoint-rekey.d.ts +1 -1
  45. package/dist/core/checkpoint-rekey.js +6 -1
  46. package/dist/core/checkpoint-requirements.d.ts +23 -3
  47. package/dist/core/checkpoint-requirements.js +5 -1
  48. package/dist/core/checkpoint-row-verdict.d.ts +1 -1
  49. package/dist/core/checkpoint-row-verdict.js +9 -3
  50. package/dist/core/checkpoint-store.d.ts +26 -2
  51. package/dist/core/checkpoint-store.js +9 -2
  52. package/dist/core/child-clamp-seats.d.ts +15 -0
  53. package/dist/core/child-clamp-seats.js +15 -0
  54. package/dist/core/config-refusal-codes.d.ts +1 -1
  55. package/dist/core/config-refusal-codes.js +1 -0
  56. package/dist/core/cron.js +9 -1
  57. package/dist/core/delegation-frames.d.ts +1 -0
  58. package/dist/core/delegation-frames.js +1 -1
  59. package/dist/core/deployment-shape.d.ts +7 -0
  60. package/dist/core/deployment-shape.js +19 -0
  61. package/dist/core/engine-capabilities.d.ts +13 -1
  62. package/dist/core/engine-capabilities.js +1 -1
  63. package/dist/core/engine-notice.d.ts +41 -28
  64. package/dist/core/engine-version.js +1 -1
  65. package/dist/core/entries-not-applied.d.ts +19 -7
  66. package/dist/core/entries-not-applied.js +33 -1
  67. package/dist/core/gate-fold.js +5 -4
  68. package/dist/core/gate-lanes.js +8 -12
  69. package/dist/core/gate-outcome.d.ts +8 -2
  70. package/dist/core/gate-outcome.js +10 -3
  71. package/dist/core/governance-codes.d.ts +14 -2
  72. package/dist/core/governance-codes.js +22 -6
  73. package/dist/core/hook-condition.d.ts +37 -0
  74. package/dist/core/hook-condition.js +567 -0
  75. package/dist/core/hooks.d.ts +5 -0
  76. package/dist/core/hooks.js +1 -0
  77. package/dist/core/host-instance.d.ts +23 -0
  78. package/dist/core/host-instance.js +69 -0
  79. package/dist/core/instruction-preview.d.ts +63 -0
  80. package/dist/core/instruction-preview.js +406 -0
  81. package/dist/core/leg-budget.d.ts +26 -0
  82. package/dist/core/leg-budget.js +9 -0
  83. package/dist/core/leg-identity.d.ts +51 -1
  84. package/dist/core/leg-identity.js +45 -2
  85. package/dist/core/manager-launch-check.d.ts +48 -0
  86. package/dist/core/manager-launch-check.js +64 -0
  87. package/dist/core/mcp-call-meta.d.ts +2 -2
  88. package/dist/core/mcp-injection-drop.d.ts +20 -10
  89. package/dist/core/mcp-injection-drop.js +9 -3
  90. package/dist/core/mcp-server-spec.d.ts +2 -1
  91. package/dist/core/member-outcome.d.ts +3 -2
  92. package/dist/core/member-outcome.js +1 -1
  93. package/dist/core/memory-engine/deletion-record.d.ts +46 -0
  94. package/dist/core/memory-engine/deletion-record.js +96 -0
  95. package/dist/core/memory-engine/engine.js +24 -16
  96. package/dist/core/memory-engine/file-backend.js +7 -5
  97. package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
  98. package/dist/core/memory-engine/projection-ledger.js +1 -1
  99. package/dist/core/memory-engine/scope-contract.d.ts +18 -13
  100. package/dist/core/memory-engine/scope-contract.js +18 -18
  101. package/dist/core/memory-engine/sync-client.js +26 -6
  102. package/dist/core/memory-engine/sync.d.ts +20 -2
  103. package/dist/core/memory-engine/sync.js +18 -17
  104. package/dist/core/mode-policy.d.ts +25 -6
  105. package/dist/core/mode-policy.js +33 -8
  106. package/dist/core/model-seat.d.ts +8 -5
  107. package/dist/core/model-shell.d.ts +129 -0
  108. package/dist/core/model-shell.js +249 -0
  109. package/dist/core/mods/kernel/digest.d.ts +4 -0
  110. package/dist/core/mods/kernel/digest.js +5 -0
  111. package/dist/core/mods/kernel/dispatch.d.ts +3 -0
  112. package/dist/core/mods/kernel/dispatch.js +15 -6
  113. package/dist/core/mods/kernel/events.d.ts +21 -5
  114. package/dist/core/mods/kernel/events.js +19 -10
  115. package/dist/core/mods/kernel/hash-mirror.d.ts +1 -0
  116. package/dist/core/mods/kernel/hash-mirror.js +55 -0
  117. package/dist/core/mods/kernel/index.d.ts +1 -0
  118. package/dist/core/mods/kernel/index.js +1 -0
  119. package/dist/core/mods/kernel/package-reader.d.ts +48 -0
  120. package/dist/core/mods/kernel/package-reader.js +149 -0
  121. package/dist/core/mods/kernel/site-rules.d.ts +4 -0
  122. package/dist/core/mods/kernel/site-rules.js +13 -0
  123. package/dist/core/mods/package.d.ts +7 -3
  124. package/dist/core/mods/package.js +47 -80
  125. package/dist/core/own-property-receipt.js +11 -4
  126. package/dist/core/parent-spec-seat.d.ts +13 -11
  127. package/dist/core/parent-spec-seat.js +13 -9
  128. package/dist/core/peer-seat.js +3 -3
  129. package/dist/core/peer-task-store.d.ts +365 -0
  130. package/dist/core/peer-task-store.js +682 -0
  131. package/dist/core/permission-rule-consent.js +6 -11
  132. package/dist/core/permission-rule-model.d.ts +27 -0
  133. package/dist/core/permission-rule-model.js +33 -5
  134. package/dist/core/permission-rule-org.js +13 -3
  135. package/dist/core/permission-rule-provider.d.ts +35 -33
  136. package/dist/core/permission-rule-provider.js +38 -295
  137. package/dist/core/permission-rule-store.d.ts +181 -8
  138. package/dist/core/permission-rule-store.js +420 -17
  139. package/dist/core/permission-rule-sync.js +15 -1
  140. package/dist/core/permission-rules.js +4 -1
  141. package/dist/core/project-seat.d.ts +55 -0
  142. package/dist/core/project-seat.js +96 -0
  143. package/dist/core/protocol-http-auth.d.ts +3 -2
  144. package/dist/core/protocol-http-auth.js +26 -18
  145. package/dist/core/remote-env.d.ts +4 -4
  146. package/dist/core/retain-seat.d.ts +42 -0
  147. package/dist/core/retain-seat.js +76 -0
  148. package/dist/core/retired-keys.js +1 -0
  149. package/dist/core/rewind-refusal-codes.d.ts +8 -0
  150. package/dist/core/rewind-refusal-codes.js +12 -0
  151. package/dist/core/roles.d.ts +2 -2
  152. package/dist/core/roles.js +15 -1
  153. package/dist/core/rule-offer-read.d.ts +1 -1
  154. package/dist/core/rule-offer-read.js +32 -4
  155. package/dist/core/rule-store-fault.d.ts +9 -7
  156. package/dist/core/rule-store-fault.js +8 -3
  157. package/dist/core/run-ledger-seat.d.ts +66 -0
  158. package/dist/core/run-ledger-seat.js +70 -0
  159. package/dist/core/run-ledger.d.ts +332 -0
  160. package/dist/core/run-ledger.js +550 -0
  161. package/dist/core/runner/checkpoint-scope.d.ts +14 -3
  162. package/dist/core/runner/checkpoint-scope.js +16 -6
  163. package/dist/core/runner/compact-session.js +1 -1
  164. package/dist/core/runner/construction-doors.js +8 -0
  165. package/dist/core/runner/contracts.d.ts +21 -5
  166. package/dist/core/runner/cross-boundary-lane.d.ts +8 -1
  167. package/dist/core/runner/cross-boundary-lane.js +4 -0
  168. package/dist/core/runner/delegation-owner.d.ts +30 -0
  169. package/dist/core/runner/delegation-owner.js +20 -4
  170. package/dist/core/runner/finish-reason-seat.js +4 -2
  171. package/dist/core/runner/gate-exit.d.ts +7 -0
  172. package/dist/core/runner/gate-exit.js +2 -1
  173. package/dist/core/runner/leg-frame.js +3 -0
  174. package/dist/core/runner/model-lane-seat.d.ts +3 -0
  175. package/dist/core/runner/model-lane-seat.js +4 -0
  176. package/dist/core/runner/nested-memory-lane.d.ts +22 -5
  177. package/dist/core/runner/nested-memory-lane.js +91 -30
  178. package/dist/core/runner/person-path-rows.d.ts +27 -16
  179. package/dist/core/runner/person-path-rows.js +93 -15
  180. package/dist/core/runner/prepare-caps-and-workflow.js +98 -88
  181. package/dist/core/runner/prepare-config-doors.d.ts +1 -0
  182. package/dist/core/runner/prepare-config-doors.js +13 -7
  183. package/dist/core/runner/prepare-context-lane.js +1 -0
  184. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  185. package/dist/core/runner/prepare-delegation-surface.js +6 -0
  186. package/dist/core/runner/prepare-execution-env.d.ts +3 -3
  187. package/dist/core/runner/prepare-gate-stations.d.ts +6 -0
  188. package/dist/core/runner/prepare-gate-stations.js +3 -1
  189. package/dist/core/runner/prepare-hands-readface.d.ts +5 -2
  190. package/dist/core/runner/prepare-hands-readface.js +15 -3
  191. package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
  192. package/dist/core/runner/prepare-inherited-gate.js +13 -5
  193. package/dist/core/runner/prepare-offload-wrappers.js +1 -1
  194. package/dist/core/runner/prepare-run-refs.d.ts +1 -1
  195. package/dist/core/runner/prepare-run-refs.js +3 -2
  196. package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
  197. package/dist/core/runner/prepare-suspend-saga.js +4 -2
  198. package/dist/core/runner/prepare-task.js +42 -30
  199. package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
  200. package/dist/core/runner/prepare-turn-wiring.js +2 -1
  201. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  202. package/dist/core/runner/prepare-wiring-manifest.js +8 -6
  203. package/dist/core/runner/resume-apply.js +11 -5
  204. package/dist/core/runner/resume-policy-outcome.js +5 -2
  205. package/dist/core/runner/resume-review-outcome.d.ts +3 -0
  206. package/dist/core/runner/resume-review-outcome.js +24 -1
  207. package/dist/core/runner/role-seat-defaulted.d.ts +3 -3
  208. package/dist/core/runner/role-seat-defaulted.js +1 -1
  209. package/dist/core/runner/rule-store-unreadable-notice.d.ts +1 -1
  210. package/dist/core/runner/rule-store-unreadable-notice.js +3 -3
  211. package/dist/core/runner/run-harness-handlers.js +4 -1
  212. package/dist/core/runner/run-identity-wiring.js +3 -2
  213. package/dist/core/runner/run-leg.js +5 -2
  214. package/dist/core/runner/run-notification-lane.js +20 -1
  215. package/dist/core/runner/run-settle-and-teardown.js +21 -12
  216. package/dist/core/runner/run-stop-and-final-verify.js +6 -0
  217. package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
  218. package/dist/core/runner/runtask.d.ts +6 -2
  219. package/dist/core/runner/runtask.js +21 -9
  220. package/dist/core/runner/shell-env-withheld.d.ts +6 -4
  221. package/dist/core/runner/shell-env-withheld.js +25 -3
  222. package/dist/core/runner/stop-tail-notice.d.ts +10 -2
  223. package/dist/core/runner/stop-tail-notice.js +9 -2
  224. package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
  225. package/dist/core/runner/stream-settle-backstop.js +1 -0
  226. package/dist/core/runner/sub-agent-deny-lists.js +9 -5
  227. package/dist/core/runner/task-start-doors.js +6 -3
  228. package/dist/core/runner/terminal-account.d.ts +6 -1
  229. package/dist/core/runner/terminal-account.js +16 -1
  230. package/dist/core/runner/tool-end-body.d.ts +1 -1
  231. package/dist/core/runner/tool-not-executed.d.ts +27 -8
  232. package/dist/core/runner/tool-not-executed.js +22 -11
  233. package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
  234. package/dist/core/runner/write-protection-station.d.ts +1 -1
  235. package/dist/core/runner/write-protection-station.js +1 -1
  236. package/dist/core/runner-deps.d.ts +17 -10
  237. package/dist/core/secret-env.d.ts +61 -37
  238. package/dist/core/secret-env.js +49 -49
  239. package/dist/core/session-checkout.d.ts +3 -0
  240. package/dist/core/session-checkout.js +1 -0
  241. package/dist/core/session-store.d.ts +12 -6
  242. package/dist/core/session-store.js +26 -6
  243. package/dist/core/session.d.ts +31 -8
  244. package/dist/core/shell-read-silence.d.ts +40 -2
  245. package/dist/core/shell-read-silence.js +23 -4
  246. package/dist/core/store-contracts/checkpoint-store-contract.js +10 -0
  247. package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
  248. package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
  249. package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
  250. package/dist/core/store-contracts/session-store-contract.js +87 -3
  251. package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
  252. package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
  253. package/dist/core/task-event.d.ts +14 -7
  254. package/dist/core/task-notification.d.ts +96 -10
  255. package/dist/core/task-notification.js +135 -6
  256. package/dist/core/task-registry-agent.d.ts +1 -0
  257. package/dist/core/task-registry-agent.js +1 -1
  258. package/dist/core/task-registry-shared.d.ts +12 -1
  259. package/dist/core/task-registry-shared.js +3 -1
  260. package/dist/core/task-registry-workflow.d.ts +1 -1
  261. package/dist/core/task-registry-workflow.js +9 -1
  262. package/dist/core/task-registry.d.ts +40 -2
  263. package/dist/core/task-registry.js +80 -15
  264. package/dist/core/task-result.d.ts +18 -3
  265. package/dist/core/task-spec-members.d.ts +3 -1
  266. package/dist/core/task-spec-members.js +19 -3
  267. package/dist/core/task-spec.d.ts +48 -22
  268. package/dist/core/tool-catalog-entries.js +2 -0
  269. package/dist/core/tool-gate-phase.d.ts +6 -3
  270. package/dist/core/tool-gate-phase.js +1 -0
  271. package/dist/core/tool-mount-facts.d.ts +8 -4
  272. package/dist/core/tool-mount-facts.js +7 -2
  273. package/dist/core/tool-mount-plan.d.ts +3 -1
  274. package/dist/core/tool-mount-plan.js +10 -3
  275. package/dist/core/tool-mount-static.d.ts +1 -1
  276. package/dist/core/tool-mount-static.js +4 -2
  277. package/dist/core/tool-result-store.d.ts +56 -3
  278. package/dist/core/tool-result-store.js +219 -25
  279. package/dist/core/tool-spec.d.ts +9 -2
  280. package/dist/core/trace.d.ts +3 -3
  281. package/dist/core/user-attachment.d.ts +5 -1
  282. package/dist/core/user-attachment.js +14 -7
  283. package/dist/core/wiring-manifest.d.ts +26 -20
  284. package/dist/core/wiring-manifest.js +7 -3
  285. package/dist/core/workflow-journal-store.d.ts +53 -10
  286. package/dist/core/workflow-journal-store.js +27 -4
  287. package/dist/core/workflow-run-store-contract.js +16 -0
  288. package/dist/core/workflow-run-store.d.ts +9 -7
  289. package/dist/core/workflow-run-store.js +4 -1
  290. package/dist/engine/execution-env/node-execution-env.d.ts +75 -1
  291. package/dist/engine/execution-env/node-execution-env.js +227 -13
  292. package/dist/engine/harness/types.d.ts +49 -1
  293. package/dist/engine/harness/types.js +10 -0
  294. package/dist/engine/llm/types.d.ts +13 -7
  295. package/dist/engine/llm/validation.d.ts +8 -1
  296. package/dist/engine/llm/validation.js +31 -2
  297. package/dist/engine/lsp/node-lsp-manager.js +2 -1
  298. package/dist/engine/session/import-validate.js +6 -1
  299. package/dist/engine/session/session.d.ts +15 -2
  300. package/dist/engine/session/session.js +34 -4
  301. package/dist/host-env.d.ts +10 -0
  302. package/dist/host-env.js +1 -0
  303. package/dist/index.d.ts +28 -9
  304. package/dist/index.js +22 -6
  305. package/dist/internal/harness-types.d.ts +1 -1
  306. package/dist/orchestration/goal.js +1 -1
  307. package/dist/orchestration/run-workflow-tool.js +40 -32
  308. package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
  309. package/dist/orchestration/workflow-park-adoption.js +47 -12
  310. package/dist/orchestration/workflow-primitives.js +10 -1
  311. package/dist/orchestration/workflow-script-runner.d.ts +2 -2
  312. package/dist/orchestration/workflow-stop.d.ts +128 -0
  313. package/dist/orchestration/workflow-stop.js +156 -0
  314. package/dist/orchestration/workflow.d.ts +31 -7
  315. package/dist/orchestration/workflow.js +119 -57
  316. package/dist/prompts/manager-recipe.d.ts +18 -0
  317. package/dist/prompts/manager-recipe.js +24 -0
  318. package/dist/shell/lex.d.ts +2 -2
  319. package/dist/shell/lex.js +1 -1
  320. package/dist/stores/file/permission-rule-store.d.ts +3 -1
  321. package/dist/stores/file/permission-rule-store.js +0 -1
  322. package/dist/stores/file/workflow-journal-store.d.ts +16 -3
  323. package/dist/stores/file/workflow-journal-store.js +93 -5
  324. package/dist/stores/file/workflow-run-store.d.ts +1 -1
  325. package/dist/tools/fs/bash-model-shell.d.ts +23 -0
  326. package/dist/tools/fs/bash-model-shell.js +25 -0
  327. package/dist/tools/fs/bash-readonly-classifier.d.ts +6 -0
  328. package/dist/tools/fs/bash-readonly-classifier.js +3 -0
  329. package/dist/tools/fs/file-write-check.js +9 -3
  330. package/dist/tools/fs/fs-bash.js +13 -11
  331. package/dist/tools/fs/index.d.ts +8 -7
  332. package/dist/tools/fs/index.js +4 -4
  333. package/dist/tools/fs/read-deny-home.d.ts +1 -1
  334. package/dist/tools/fs/read-deny-home.js +5 -5
  335. package/dist/tools/fs/read-deny.d.ts +33 -8
  336. package/dist/tools/fs/read-deny.js +114 -25
  337. package/dist/tools/fs/safety.d.ts +4 -1
  338. package/dist/tools/fs/safety.js +4 -2
  339. package/dist/tools/fs/shell-read-argv.js +1 -0
  340. package/dist/tools/fs/shell-read-check.d.ts +9 -2
  341. package/dist/tools/fs/shell-read-check.js +134 -22
  342. package/dist/tools/fs/shell-read-establish.d.ts +9 -0
  343. package/dist/tools/fs/shell-read-establish.js +21 -11
  344. package/dist/tools/fs/shell-read-judge.d.ts +13 -1
  345. package/dist/tools/fs/shell-read-judge.js +26 -7
  346. package/dist/tools/fs/shell-read-plan.d.ts +7 -3
  347. package/dist/tools/fs/shell-read-plan.js +8 -5
  348. package/dist/tools/fs/shell-read-word.d.ts +8 -0
  349. package/dist/tools/fs/shell-read-word.js +13 -4
  350. package/dist/tools/fs/shell-read-write-targets.js +17 -9
  351. package/dist/tools/monitor.js +12 -8
  352. package/dist/tools/scheduler-tools.d.ts +1 -0
  353. package/dist/tools/scheduler-tools.js +5 -2
  354. package/package.json +3 -2
  355. package/test/export-surface.snapshot.json +192 -3
  356. package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
  357. package/wire-changes/answers/core-stores-sql@7.74.0.json +7 -0
  358. package/wire-changes/answers/core@7.73.0.json +216 -0
  359. package/wire-changes/answers/core@7.74.0.json +68 -0
  360. package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
  361. package/wire-changes/answers/mods-kernel@7.74.0.json +21 -0
  362. package/wire-changes/answers/primitives@7.73.0.json +12 -0
  363. package/wire-changes/answers/primitives@7.74.0.json +7 -0
  364. package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
  365. package/wire-changes/answers/wiki-gate@7.74.0.json +8 -0
  366. package/wire-changes/core-stores-sql@7.73.0.json +326 -0
  367. package/wire-changes/core-stores-sql@7.74.0.json +143 -0
  368. package/wire-changes/core@7.73.0.json +6480 -0
  369. package/wire-changes/core@7.74.0.json +2210 -0
  370. package/wire-changes/mods-kernel@7.73.0.json +147 -0
  371. package/wire-changes/mods-kernel@7.74.0.json +421 -0
  372. package/wire-changes/primitives@7.73.0.json +227 -0
  373. package/wire-changes/primitives@7.74.0.json +174 -0
  374. package/wire-changes/wiki-gate@7.73.0.json +145 -0
  375. package/wire-changes/wiki-gate@7.74.0.json +145 -0
@@ -0,0 +1,550 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { isMemberOutcome, MEMBER_OUTCOMES, memberCoverageOf, memberCountsOf, memberOutcomeText, sealMemberOutcome } from "./member-outcome.js";
3
+ import { isSubagentActions, subagentActionsLine } from "./actions-digest.js";
4
+ import { inlineUntrusted } from "./untrusted-text.js";
5
+ import { egressText } from "./untrusted-egress.js";
6
+ import { describeRejectedValue } from "./tool-search-setting.js";
7
+ import { strayMembersOf } from "./own-property-receipt.js";
8
+ export const RUN_LEDGER_VERSION = 1;
9
+ export const RUN_LEDGER_WIRE_KEY = "_sema_run_ledger";
10
+ export const RUN_LEDGER_SELF_REPORT_MAX_CHARS = 400;
11
+ export const RUN_LEDGER_CHECKS = Object.freeze(["verified", "evidence", "unverified", "n/a"]);
12
+ export function assertRunLedgerDeclaration(v) {
13
+ if (v === undefined || v === true)
14
+ return;
15
+ throw Object.assign(new Error(`TaskSpec.runLedger must be true or absent (got ${describeRejectedValue(v)}) — declare it to carry a member ledger; leave it out otherwise.`), { code: "config.invalid_argument" });
16
+ }
17
+ export const RUN_LEDGER_NOT_KEPT_SENTENCE = "This task's first leg kept no member ledger, so this leg keeps none either: whether a task keeps one is fixed when the task starts (declare runLedger on its first leg).";
18
+ export function runLedgerIdentityOf(spec, resumed, rowTaskId) {
19
+ if (resumed === undefined && spec.runLedger !== true)
20
+ return undefined;
21
+ if (resumed !== undefined && resumed.section === undefined)
22
+ return spec.runLedger === true ? { notKept: RUN_LEDGER_NOT_KEPT_SENTENCE } : undefined;
23
+ const parked = resumed !== undefined ? readRunLedgerParked(resumed.section) : undefined;
24
+ if (resumed !== undefined && parked === undefined) {
25
+ throw Object.assign(new Error("the parked row's member ledger section does not read as a book this engine froze"), { code: "config.invalid_argument" });
26
+ }
27
+ if (resumed === undefined && rowTaskId !== undefined)
28
+ return { taskId: rowTaskId };
29
+ const named = spec.taskId;
30
+ if (named !== undefined && (typeof named !== "string" || named === "")) {
31
+ throw Object.assign(new Error(`TaskSpec.taskId must be a non-empty string on a run that keeps a member ledger (got ${describeRejectedValue(named)}) — name the task, or leave it out and the engine mints one.`), { code: "config.invalid_argument" });
32
+ }
33
+ if (parked !== undefined) {
34
+ if (named !== undefined && named !== parked.taskId) {
35
+ throw Object.assign(new Error(`this resume names task "${inlineUntrusted(named, 80)}", but the row it resumes is a leg of task "${inlineUntrusted(parked.taskId, 80)}" (the task its member ledger belongs to) — resume it under its own task id, or name none.`), { code: "config.invalid_argument" });
36
+ }
37
+ return { taskId: parked.taskId, parked };
38
+ }
39
+ return { taskId: named !== undefined && named !== spec.sessionId ? named : `rl-${randomBytes(8).toString("hex")}` };
40
+ }
41
+ export function runLedgerBookFor(spec, resumed, rowTaskId, now = Date.now) {
42
+ const id = runLedgerIdentityOf(spec, resumed, rowTaskId);
43
+ return id === undefined || "notKept" in id ? undefined : new RunLedgerBook(now, id.parked, id.taskId);
44
+ }
45
+ export function withRunLedgerTask(spec, book) {
46
+ if (book !== undefined)
47
+ return { ...spec, taskId: book.taskId, runLedger: true };
48
+ if (spec.runLedger === undefined)
49
+ return spec;
50
+ const { runLedger: _dropped, ...rest } = spec;
51
+ return rest;
52
+ }
53
+ const selfReportOf = (text) => {
54
+ if (text === undefined || text.trim() === "")
55
+ return undefined;
56
+ return inlineUntrusted(egressText("same-principal", text), RUN_LEDGER_SELF_REPORT_MAX_CHARS);
57
+ };
58
+ const labelOf = (text, fallback) => (text === undefined || text.trim() === "" ? fallback : inlineUntrusted(egressText("same-principal", text), 120));
59
+ const PARK_MAX_LISTED = 512;
60
+ const PARK_MAX_SYNC_ROWS = 64;
61
+ const PARK_MAX_ARRIVALS = 256;
62
+ const PARK_MAX_CALLS = 256;
63
+ const PARK_MAX_CLAIMS = 64;
64
+ const keepTail = (items, max) => items.length <= max ? { kept: [...items], dropped: 0 } : { kept: items.slice(items.length - max), dropped: items.length - max };
65
+ const isRec = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
66
+ const isNat = (x) => typeof x === "number" && Number.isSafeInteger(x) && x >= 0;
67
+ const isPos = (x) => typeof x === "number" && Number.isSafeInteger(x) && x >= 1;
68
+ const isOpt = (x, is) => x === undefined || is(x);
69
+ const isStr = (x) => typeof x === "string";
70
+ const isIn = (words) => (x) => typeof x === "string" && words.includes(x);
71
+ const isClaim = (c) => isRec(c) && isStr(c["about"]) && isStr(c["text"]) && isIn(["verified", "relayed", "inferred"])(c["basis"]) && isOpt(c["verdict"], isIn(["confirms", "refutes", "partial"])) && isOpt(c["evidence"], (e) => Array.isArray(e) && e.every(isStr));
72
+ const isSyncRow = (r) => isRec(r) && isStr(r["taskId"]) && isStr(r["kind"]) && isMemberOutcome(r["outcome"]) && isNat(r["settledAt"]) && isNat(r["order"]) &&
73
+ ["label", "name", "selfReport", "call"].every((k) => isOpt(r[k], isStr)) && isOpt(r["began"], isNat) && isOpt(r["actions"], isSubagentActions);
74
+ const isArrivalMark = (a) => isRec(a) && isStr(a["taskId"]) && isPos(a["cycle"]) && isNat(a["order"]) && isNat(a["settledAt"]) && isOpt(a["began"], isNat);
75
+ const isHeardCall = (c) => isRec(c) && isStr(c["id"]) && isNat(c["at"]) && isNat(c["started"]) && isNat(c["turn"]) && isOpt(c["ended"], isNat) && isOpt(c["duplicate"], (d) => d === true);
76
+ const isReport = (r) => isRec(r) && isIn(["normal", "proactive"])(r["status"]) && isStr(r["message"]) && isOpt(r["kind"], isIn(["start", "interim", "final"])) && isOpt(r["claims"], (cs) => Array.isArray(cs) && cs.every(isClaim));
77
+ const TRUNCATED_KEYS = ["listed", "syncRows", "arrivals", "calls", "claims"];
78
+ const TRUNCATED_WORDS = { subject: "a parked member ledger's truncated section", unit: "member", moment: "when the row is read" };
79
+ const isTruncated = (t) => {
80
+ if (!isRec(t))
81
+ return false;
82
+ const keys = Object.keys(t);
83
+ return keys.length > 0 && strayMembersOf(t, TRUNCATED_WORDS, TRUNCATED_KEYS) === undefined && keys.every((k) => isPos(t[k]));
84
+ };
85
+ const isListOf = (x, is) => Array.isArray(x) && x.every(is);
86
+ const isReading = (p) => Array.isArray(p) && p.length === 2 && isStr(p[0]) && isNat(p[1]);
87
+ const isParked = (v) => isRec(v) && v["v"] === 1 && isStr(v["taskId"]) && v["taskId"] !== "" && isListOf(v["listed"], isStr) && isNat(v["tick"]) && isNat(v["turn"]) && isNat(v["seq"]) && isNat(v["reports"]) &&
88
+ isListOf(v["syncRows"], isSyncRow) && isListOf(v["arrivals"], isArrivalMark) && isListOf(v["calls"], isHeardCall) && isListOf(v["claims"], (c) => isClaim(c) && isRec(c) && isListOf(c["readings"], isReading)) &&
89
+ isOpt(v["lastReport"], isReport) && isOpt(v["truncated"], isTruncated);
90
+ export function readRunLedgerParked(v) {
91
+ return isParked(v) ? v : undefined;
92
+ }
93
+ export class RunLedgerBook {
94
+ taskId;
95
+ #listed = new Set();
96
+ #syncRows = new Map();
97
+ #arrivals = new Map();
98
+ #liveFrames = new Map();
99
+ #calls = new Map();
100
+ #truncated = { listed: 0, syncRows: 0, arrivals: 0, calls: 0, claims: 0 };
101
+ #tick = 0;
102
+ #turn = 0;
103
+ #isMember = () => undefined;
104
+ #claims = [];
105
+ #reports = 0;
106
+ #lastReport;
107
+ #launch;
108
+ #registry = () => [];
109
+ #registryBound = false;
110
+ #runId;
111
+ #seq = 0;
112
+ #now;
113
+ constructor(now = Date.now, parked, taskId) {
114
+ this.#now = now;
115
+ this.taskId = parked?.taskId ?? taskId;
116
+ if (parked === undefined)
117
+ return;
118
+ if (readRunLedgerParked(parked) === undefined)
119
+ throw Object.assign(new Error("the parked row's member ledger section does not read as a book this engine froze"), { code: "config.invalid_argument" });
120
+ if (taskId !== undefined && taskId !== parked.taskId)
121
+ throw Object.assign(new Error(`the parked row's member ledger is task "${parked.taskId}"'s, not "${taskId}"'s`), { code: "config.invalid_argument" });
122
+ for (const row of parked.syncRows)
123
+ this.#syncRows.set(row.taskId, structuredClone(row));
124
+ for (const mark of parked.arrivals)
125
+ this.#arrivals.set(mark.taskId, { ...mark });
126
+ for (const { id, ...call } of parked.calls)
127
+ this.#calls.set(id, { ...call });
128
+ for (const id of parked.listed)
129
+ this.#listed.add(id);
130
+ this.#claims.push(...parked.claims.map((c) => ({ ...c, readings: c.readings.map(([t, o]) => [t, o]), ...(c.evidence !== undefined ? { evidence: [...c.evidence] } : {}) })));
131
+ this.#tick = parked.tick;
132
+ this.#turn = parked.turn;
133
+ this.#seq = parked.seq;
134
+ this.#reports = parked.reports;
135
+ if (parked.lastReport !== undefined)
136
+ this.#lastReport = structuredClone(parked.lastReport);
137
+ if (parked.truncated !== undefined) {
138
+ this.#truncated.listed = parked.truncated.listed ?? 0;
139
+ this.#truncated.syncRows = parked.truncated.syncRows ?? 0;
140
+ this.#truncated.arrivals = parked.truncated.arrivals ?? 0;
141
+ this.#truncated.calls = parked.truncated.calls ?? 0;
142
+ this.#truncated.claims = parked.truncated.claims ?? 0;
143
+ }
144
+ }
145
+ parkSection() {
146
+ if (this.taskId === undefined)
147
+ throw Object.assign(new Error("a member ledger book no leg minted cannot be parked: it belongs to no task"), { code: "internal.run_ledger_unbound" });
148
+ this.#listing();
149
+ const listedCut = keepTail([...this.#listed], PARK_MAX_LISTED);
150
+ const syncCut = keepTail([...this.#syncRows.values()].sort((a, b) => a.order - b.order), PARK_MAX_SYNC_ROWS);
151
+ const arrivalCut = keepTail([...this.#arrivals.values()].sort((a, b) => a.order - b.order), PARK_MAX_ARRIVALS);
152
+ const callCut = keepTail([...this.#calls.entries()].sort((a, b) => a[1].started - b[1].started), PARK_MAX_CALLS);
153
+ const claimCut = keepTail(this.#claims, PARK_MAX_CLAIMS);
154
+ const totals = {
155
+ listed: this.#truncated.listed + listedCut.dropped,
156
+ syncRows: this.#truncated.syncRows + syncCut.dropped,
157
+ arrivals: this.#truncated.arrivals + arrivalCut.dropped,
158
+ calls: this.#truncated.calls + callCut.dropped,
159
+ claims: this.#truncated.claims + claimCut.dropped,
160
+ };
161
+ const truncatedEntries = TRUNCATED_KEYS.flatMap((k) => (totals[k] > 0 ? [[k, totals[k]]] : []));
162
+ const truncated = truncatedEntries.length > 0 ? Object.fromEntries(truncatedEntries) : undefined;
163
+ return {
164
+ v: 1,
165
+ taskId: this.taskId,
166
+ listed: listedCut.kept,
167
+ tick: this.#tick,
168
+ turn: this.#turn,
169
+ seq: this.#seq + 1,
170
+ reports: this.#reports,
171
+ syncRows: syncCut.kept.map((row) => structuredClone(row)),
172
+ arrivals: arrivalCut.kept.map((mark) => ({ ...mark })),
173
+ calls: callCut.kept.map(([id, call]) => ({ id, ...call })),
174
+ claims: claimCut.kept.map((c) => structuredClone(c)),
175
+ ...(this.#lastReport !== undefined ? { lastReport: structuredClone(this.#lastReport) } : {}),
176
+ ...(truncated !== undefined ? { truncated } : {}),
177
+ };
178
+ }
179
+ bind(runId, read, member) {
180
+ this.#runId = runId;
181
+ this.#registry = read;
182
+ this.#isMember = member ?? ((taskId) => read().find((r) => r.taskId === taskId));
183
+ this.#registryBound = true;
184
+ }
185
+ turnStarted() {
186
+ this.#turn = ++this.#tick;
187
+ }
188
+ setLaunch(launch) {
189
+ this.#launch = launch;
190
+ }
191
+ observeFrame(n, terminal) {
192
+ if (!terminal || (n.task_type !== "background_agent" && n.task_type !== "workflow"))
193
+ return;
194
+ const member = this.#registryBound ? this.#isMember(n.task_id) : undefined;
195
+ if (this.#registryBound && member === undefined)
196
+ return;
197
+ const prior = this.#arrivals.get(n.task_id);
198
+ if (prior !== undefined && !(n.seq !== undefined && n.seq > prior.cycle))
199
+ return;
200
+ const cycle = n.seq ?? 1;
201
+ const order = ++this.#tick;
202
+ const dispatch = this.#dispatchOf(member?.toolUseId, order);
203
+ this.#arrivals.set(n.task_id, {
204
+ taskId: n.task_id,
205
+ cycle,
206
+ order,
207
+ settledAt: this.#now(),
208
+ ...(dispatch.began !== undefined ? { began: dispatch.began } : {}),
209
+ });
210
+ const selfReport = selfReportOf(n.result);
211
+ this.#liveFrames.set(n.task_id, {
212
+ kind: n.task_type,
213
+ ...(n.spawnName !== undefined ? { name: n.spawnName } : {}),
214
+ ...(selfReport !== undefined ? { selfReport } : {}),
215
+ ...(n.actions !== undefined && isSubagentActions(n.actions) ? { actions: n.actions } : {}),
216
+ });
217
+ }
218
+ memberSettled(m) {
219
+ if (this.#syncRows.has(m.taskId))
220
+ return;
221
+ const selfReport = selfReportOf(m.selfReport);
222
+ const order = ++this.#tick;
223
+ this.#syncRows.set(m.taskId, {
224
+ taskId: m.taskId,
225
+ kind: m.kind,
226
+ label: labelOf(m.label, m.kind),
227
+ ...(m.name !== undefined ? { name: m.name } : {}),
228
+ outcome: sealMemberOutcome(m.outcome),
229
+ ...(selfReport !== undefined ? { selfReport } : {}),
230
+ ...(m.actions !== undefined ? { actions: m.actions } : {}),
231
+ settledAt: this.#now(),
232
+ order,
233
+ ...this.#dispatchOf(m.toolCallId, order),
234
+ });
235
+ }
236
+ #dispatchOf(callId, fallbackOrder) {
237
+ if (callId === undefined)
238
+ return this.#truncated.calls === 0 ? { began: fallbackOrder } : {};
239
+ const rec = this.#calls.get(callId);
240
+ const began = rec !== undefined && rec.duplicate !== true ? rec.started : undefined;
241
+ return { call: callId, ...(began !== undefined ? { began } : {}) };
242
+ }
243
+ callStarted(toolCallId) {
244
+ const dup = this.#calls.has(toolCallId);
245
+ this.#calls.set(toolCallId, { at: this.#now(), started: ++this.#tick, turn: this.#turn, ...(dup ? { duplicate: true } : {}) });
246
+ }
247
+ callResumed(toolCallId) {
248
+ const prior = this.#calls.get(toolCallId);
249
+ if (prior !== undefined && prior.ended === undefined && prior.duplicate !== true) {
250
+ prior.at = this.#now();
251
+ prior.started = ++this.#tick;
252
+ return;
253
+ }
254
+ this.callStarted(toolCallId);
255
+ }
256
+ callEnded(toolCallId) {
257
+ const c = this.#calls.get(toolCallId);
258
+ if (c !== undefined && c.ended === undefined)
259
+ c.ended = ++this.#tick;
260
+ }
261
+ acceptReport(input) {
262
+ const claims = input.report?.claims ?? [];
263
+ const issued = input.toolCallId !== undefined ? (this.#calls.get(input.toolCallId)?.turn ?? this.#turn) : this.#tick + 1;
264
+ for (const [i, c] of claims.entries()) {
265
+ const n = i + 1;
266
+ const row = this.#rowNow(c.about);
267
+ if (row === undefined) {
268
+ if (this.#truncated.syncRows > 0 && this.#listed.has(c.about)) {
269
+ return { ok: false, why: `claim ${n} is about "${inlineUntrusted(c.about, 80)}", whose synchronous member row was truncated when the run parked (${this.#truncated.syncRows} earlier synchronous rows cut) — mark the claim "relayed" or "inferred".` };
270
+ }
271
+ return { ok: false, why: `claim ${n} is about "${inlineUntrusted(c.about, 80)}", which is not a member this run dispatched — name a row's task id, as the ledger lists it.` };
272
+ }
273
+ if (c.basis !== "verified")
274
+ continue;
275
+ const about = `${row.kind === "workflow" ? "workflow" : "agent"} ${row.name !== undefined ? `"${inlineUntrusted(row.name, 60)}"` : row.taskId}`;
276
+ if (row.reclaimed)
277
+ return { ok: false, why: `claim ${n} is marked "verified", but ${about} can no longer be read from its holder — mark the claim "relayed" or "inferred".` };
278
+ if (row.running) {
279
+ const cycleLabel = row.cycleExplicit ? ` (round ${row.cycle})` : "";
280
+ return { ok: false, why: `claim ${n} is marked "verified", but ${about} is still running${cycleLabel} and has not reported yet — wait until it finishes before verifying, or mark the claim "relayed" or "inferred".` };
281
+ }
282
+ if (row.arrival === undefined) {
283
+ if (row.cycleExplicit && (row.cycle > 1 || row.hasEarlierArrival)) {
284
+ return { ok: false, why: `claim ${n} is marked "verified", but ${about}'s result for round ${row.cycle} has not arrived yet — wait until you receive it before verifying, or mark the claim "relayed".` };
285
+ }
286
+ if (this.#truncated.arrivals > 0) {
287
+ return { ok: false, why: `claim ${n} is marked "verified", but ${about}'s arrival mark is not in this book (${this.#truncated.arrivals} earlier arrival ${this.#truncated.arrivals === 1 ? "mark was" : "marks were"} truncated when the run parked) — wait for a new result or mark the claim "relayed".` };
288
+ }
289
+ return { ok: false, why: `claim ${n} is marked "verified", but ${about} has not reported yet — its result has not arrived yet. Mark it "relayed" or "inferred", or report again once it has.` };
290
+ }
291
+ if (c.verdict === undefined)
292
+ return { ok: false, why: `claim ${n} is marked "verified" but states no verdict — say whether the check confirms, refutes or partly confirms what ${about} reported.` };
293
+ const evidence = c.evidence ?? [];
294
+ if (evidence.length === 0)
295
+ return { ok: false, why: `claim ${n} is marked "verified" but cites no evidence — cite the call id of the check you ran, or another member's task id, or mark the claim "relayed".` };
296
+ for (const e of evidence) {
297
+ if (e === c.about)
298
+ return { ok: false, why: `claim ${n} cites ${about} as evidence for itself — a member's own result cannot verify it. Cite your own check, or another member that checked it.` };
299
+ if (e === input.toolCallId)
300
+ return { ok: false, why: `claim ${n} cites this report call itself as evidence — cite the check you ran before it.` };
301
+ const call = this.#calls.get(e);
302
+ if (call?.duplicate === true) {
303
+ return { ok: false, why: `claim ${n} cites "${inlineUntrusted(e, 80)}", a call id that was used more than once in this run (non-unique) — its timing cannot be verified. Run a fresh check with a unique call id, or mark the claim "relayed".` };
304
+ }
305
+ const other = call === undefined ? this.#rowNow(e) : undefined;
306
+ if (other !== undefined && other.running) {
307
+ const cycleLabel = other.cycleExplicit ? ` (round ${other.cycle})` : "";
308
+ return { ok: false, why: `claim ${n} cites ${e}, a member that is still running${cycleLabel} (a member that has not reported yet) — a check that has no result cannot verify anything.` };
309
+ }
310
+ const at = call?.at ?? other?.arrival?.settledAt;
311
+ const began = call?.started ?? other?.arrival?.began;
312
+ const done = call !== undefined ? call.ended : other?.arrival?.order;
313
+ if (other !== undefined && other.arrival !== undefined && other.arrival.began === undefined) {
314
+ if (this.#truncated.calls > 0) {
315
+ return { ok: false, why: `claim ${n} cites ${e}, whose dispatch call record was truncated when the run parked (${this.#truncated.calls} earlier call ${this.#truncated.calls === 1 ? "record was" : "records were"} cut) — cannot verify when it started. Run a fresh check, or mark the claim "relayed".` };
316
+ }
317
+ return { ok: false, why: `claim ${n} cites ${e}, whose dispatch start was not recorded by this book — cannot verify when it started. Run a fresh check, or mark the claim "relayed".` };
318
+ }
319
+ if (at === undefined || began === undefined) {
320
+ if (other !== undefined) {
321
+ const cutNote = this.#truncated.arrivals > 0 ? ` (${this.#truncated.arrivals} earlier arrival marks were truncated when the run parked)` : other.cycleExplicit && other.cycle > 1 ? ` (round ${other.cycle} has not arrived)` : "";
322
+ return { ok: false, why: `claim ${n} cites ${e}, a member that has not reported yet${cutNote} — a check that has no result cannot verify anything.` };
323
+ }
324
+ if (this.#truncated.calls > 0) {
325
+ return { ok: false, why: `claim ${n} cites "${inlineUntrusted(e, 80)}", which is not in this book's call records (${this.#truncated.calls} earlier call ${this.#truncated.calls === 1 ? "record was" : "records were"} truncated when the run parked) — run a fresh check, or mark the claim "relayed".` };
326
+ }
327
+ return { ok: false, why: `claim ${n} cites "${inlineUntrusted(e, 80)}", which is neither a call you made in this run nor a member it dispatched — cite a call id from your own tool calls or a member's task id.` };
328
+ }
329
+ if (done === undefined || !(done < issued)) {
330
+ return { ok: false, why: `claim ${n} cites "${inlineUntrusted(e, 80)}", which had not finished when this report was sent — cite a check whose result you read before reporting.` };
331
+ }
332
+ if (!(began > row.arrival.order)) {
333
+ return { ok: false, why: `claim ${n} is marked "verified" but its evidence "${inlineUntrusted(e, 80)}" ran at ${isoTime(at)}, before ${about} reported at ${isoTime(row.arrival.settledAt)} — a check made before the claim cannot verify it. Check again, or mark the claim "relayed".` };
334
+ }
335
+ if (other?.reclaimed) {
336
+ return { ok: false, why: `claim ${n} cites ${e}, a member that can no longer be read from its holder — run a fresh check, or mark the claim "relayed".` };
337
+ }
338
+ }
339
+ }
340
+ const readingsOf = (c) => [...new Set([c.about, ...(c.evidence ?? [])])].flatMap((id) => {
341
+ const view = this.#rowNow(id);
342
+ return view !== undefined && !view.running && view.arrival !== undefined ? [[id, view.cycle]] : [];
343
+ });
344
+ this.#claims.push(...claims.map((c) => ({ ...c, ...(c.evidence !== undefined ? { evidence: [...c.evidence] } : {}), readings: readingsOf(c) })));
345
+ if (input.report !== undefined)
346
+ this.#reports += 1;
347
+ this.#lastReport = {
348
+ status: input.status,
349
+ message: input.message,
350
+ ...(input.report?.kind !== undefined ? { kind: input.report.kind } : {}),
351
+ ...(claims.length > 0 ? { claims: claims.map((c) => ({ ...c })) } : {}),
352
+ };
353
+ return { ok: true };
354
+ }
355
+ #rowNow(taskId, regHint) {
356
+ const sync = this.#syncRows.get(taskId);
357
+ const mark = this.#arrivals.get(taskId);
358
+ const live = this.#liveFrames.get(taskId);
359
+ const reg = regHint ??
360
+ (this.#registryBound
361
+ ? (this.#isMember(taskId) ?? (sync !== undefined ? { taskId, kind: sync.kind, running: false, outcome: sync.outcome, cycle: 1 } : undefined))
362
+ : sync !== undefined
363
+ ? { taskId, kind: sync.kind, running: false, outcome: sync.outcome, cycle: 1 }
364
+ : mark !== undefined
365
+ ? { taskId, kind: live?.kind ?? "background_agent", running: false, cycle: mark.cycle }
366
+ : undefined);
367
+ if (reg === undefined) {
368
+ if (mark === undefined)
369
+ return undefined;
370
+ return {
371
+ taskId,
372
+ kind: live?.kind ?? "background_agent",
373
+ ...(live?.name !== undefined ? { name: live.name } : {}),
374
+ running: false,
375
+ cycle: mark.cycle,
376
+ cycleExplicit: false,
377
+ arrival: { order: mark.order, settledAt: mark.settledAt, ...(mark.began !== undefined ? { began: mark.began } : {}) },
378
+ hasEarlierArrival: false,
379
+ ...(live?.selfReport !== undefined ? { selfReport: live.selfReport } : {}),
380
+ ...(live?.actions !== undefined ? { actions: live.actions } : {}),
381
+ reclaimed: true,
382
+ };
383
+ }
384
+ const isSync = sync !== undefined && reg.outcome === sync.outcome;
385
+ const isWorkflow = reg.kind === "workflow";
386
+ const cycleExplicit = reg.cycle !== undefined;
387
+ const cycle = isSync ? 1 : (reg.cycle ?? (isWorkflow ? 1 : (mark?.cycle ?? 1)));
388
+ const name = reg.name ?? (isSync ? sync.name : live?.name);
389
+ const label = isSync ? sync.label : reg.label;
390
+ const selfReport = isSync ? sync.selfReport : live?.selfReport;
391
+ const actions = isSync ? sync.actions : live?.actions;
392
+ if (reg.running) {
393
+ return {
394
+ taskId,
395
+ kind: reg.kind,
396
+ ...(name !== undefined ? { name } : {}),
397
+ ...(label !== undefined ? { label } : {}),
398
+ running: true,
399
+ cycle,
400
+ cycleExplicit,
401
+ hasEarlierArrival: mark !== undefined,
402
+ ...(selfReport !== undefined ? { selfReport } : {}),
403
+ ...(actions !== undefined ? { actions } : {}),
404
+ };
405
+ }
406
+ const arrival = isSync
407
+ ? { order: sync.order, settledAt: sync.settledAt, ...(sync.began !== undefined ? { began: sync.began } : {}) }
408
+ : mark !== undefined && mark.cycle === cycle
409
+ ? { order: mark.order, settledAt: mark.settledAt, ...(mark.began !== undefined ? { began: mark.began } : {}) }
410
+ : undefined;
411
+ return {
412
+ taskId,
413
+ kind: reg.kind,
414
+ ...(name !== undefined ? { name } : {}),
415
+ ...(label !== undefined ? { label } : {}),
416
+ running: false,
417
+ ...(reg.outcome !== undefined ? { outcome: reg.outcome } : {}),
418
+ ...(reg.members !== undefined ? { members: reg.members } : {}),
419
+ cycle,
420
+ cycleExplicit,
421
+ ...(arrival !== undefined ? { arrival } : {}),
422
+ hasEarlierArrival: mark !== undefined,
423
+ ...(selfReport !== undefined ? { selfReport } : {}),
424
+ ...(actions !== undefined ? { actions } : {}),
425
+ };
426
+ }
427
+ #listing() {
428
+ const rows = this.#registry();
429
+ const held = new Set(rows.map((r) => r.taskId));
430
+ const own = [...this.#syncRows.values()].filter((s) => !held.has(s.taskId));
431
+ const now = [...rows.map((r) => r.taskId), ...own.map((s) => s.taskId)];
432
+ for (const id of now)
433
+ this.#listed.add(id);
434
+ const handed = new Set(now);
435
+ const unreadable = new Set([...this.#listed, ...this.#arrivals.keys(), ...this.#syncRows.keys()].filter((id) => !handed.has(id))).size;
436
+ return { rows: [...rows, ...own.map((s) => ({ taskId: s.taskId, kind: s.kind, running: false, outcome: s.outcome, cycle: 1 }))], unreadable };
437
+ }
438
+ snapshot(trigger) {
439
+ const listing = this.#listing();
440
+ const views = listing.rows.map((reg) => this.#rowNow(reg.taskId, reg));
441
+ const viewById = new Map(views.map((v) => [v.taskId, v]));
442
+ const covers = (c, taskId) => {
443
+ const view = viewById.get(taskId);
444
+ return view !== undefined && !view.running && c.readings.some(([id, cycle]) => id === taskId && cycle === view.cycle);
445
+ };
446
+ const verdictOf = new Map();
447
+ const cited = new Set();
448
+ for (const c of this.#claims) {
449
+ if (c.basis !== "verified")
450
+ continue;
451
+ if (covers(c, c.about))
452
+ verdictOf.set(c.about, c.verdict);
453
+ for (const e of c.evidence ?? [])
454
+ if (covers(c, e))
455
+ cited.add(e);
456
+ }
457
+ const verifiedAbout = new Set(verdictOf.keys());
458
+ const rows = views.map((view) => {
459
+ const outcome = view.running ? undefined : view.outcome;
460
+ const settled = outcome !== undefined;
461
+ const check = outcome?.outcome !== "completed" ? "n/a" : verifiedAbout.has(view.taskId) ? "verified" : cited.has(view.taskId) ? "evidence" : "unverified";
462
+ const verdict = check === "verified" ? verdictOf.get(view.taskId) : undefined;
463
+ return {
464
+ taskId: view.taskId,
465
+ kind: view.kind,
466
+ label: labelOf(view.label, view.kind),
467
+ ...(view.name !== undefined ? { name: view.name } : {}),
468
+ state: settled ? "settled" : "running",
469
+ ...(outcome !== undefined ? { outcome } : {}),
470
+ ...(view.selfReport !== undefined ? { selfReport: view.selfReport } : {}),
471
+ ...(view.actions !== undefined ? { actions: view.actions } : {}),
472
+ check,
473
+ ...(verdict !== undefined ? { verdict } : {}),
474
+ ...(view.members !== undefined ? { members: view.members } : {}),
475
+ ...(view.arrival !== undefined && settled ? { settledAt: view.arrival.settledAt } : {}),
476
+ };
477
+ });
478
+ this.#seq += 1;
479
+ return runLedgerOf(rows, {
480
+ ...(this.#runId !== undefined ? { runId: this.#runId } : {}),
481
+ seq: this.#seq,
482
+ trigger,
483
+ ...(listing.unreadable > 0 ? { unreadable: listing.unreadable } : {}),
484
+ reports: this.#reports,
485
+ ...(this.#lastReport !== undefined ? { lastReport: this.#lastReport } : {}),
486
+ ...(this.#launch !== undefined ? { launch: this.#launch } : {}),
487
+ });
488
+ }
489
+ }
490
+ const isoTime = (ms) => new Date(ms).toISOString().slice(11, 23);
491
+ export function runLedgerOf(rows, at) {
492
+ const final = at.trigger.kind === "run_end";
493
+ const outcomes = rows.map((r) => r.outcome);
494
+ const unreadable = at.unreadable !== undefined && at.unreadable > 0 ? at.unreadable : undefined;
495
+ const rowCoverage = memberCoverageOf(outcomes) === "complete" && rows.some((r) => r.members !== undefined && r.members.coverage !== "complete") ? "partial" : memberCoverageOf(outcomes);
496
+ const coverage = unreadable !== undefined ? "incomplete" : rowCoverage;
497
+ const open = rows.filter((r) => r.state === "running").length;
498
+ const unverified = rows.filter((r) => r.check === "unverified").length;
499
+ const contradicted = rows.filter((r) => r.verdict !== undefined && r.verdict !== "confirms").length;
500
+ const base = { v: RUN_LEDGER_VERSION, ...(at.runId !== undefined ? { runId: at.runId } : {}), seq: at.seq, trigger: at.trigger, final, open, coverage, counts: memberCountsOf(outcomes), ...(unreadable !== undefined ? { unreadable } : {}), unverified, contradicted, reports: at.reports, rows };
501
+ const headline = runLedgerHeadline(base);
502
+ const ledger = { ...base, headline, ...(at.lastReport !== undefined ? { lastReport: at.lastReport } : {}), ...(at.launch !== undefined ? { launch: at.launch } : {}) };
503
+ return Object.freeze({ ...ledger, text: runLedgerText(ledger) });
504
+ }
505
+ export function runLedgerHeadline(l) {
506
+ const contradicted = l.contradicted > 0 ? ` · ${l.contradicted} contradicted by a check` : "";
507
+ const noReport = l.final && l.reports === 0 ? " · the manager submitted no structured conclusions" : "";
508
+ const unreadable = l.unreadable !== undefined && l.unreadable > 0 ? `${l.unreadable} ${l.unreadable === 1 ? "member" : "members"} no longer readable` : "";
509
+ if (l.rows.length === 0 && unreadable === "")
510
+ return `Settled · no members were dispatched${noReport}`;
511
+ const short = l.rows.filter((r) => r.members !== undefined && r.members.coverage !== "complete").length;
512
+ const fails = [...endingsOf(l.counts), unreadable, short > 0 ? `${short} ${short === 1 ? "workflow short of its members" : "workflows short of their members"}` : ""].filter((s) => s !== "").join(", ");
513
+ const completed = l.rows.some((r) => r.outcome?.outcome === "completed");
514
+ if (l.open > 0)
515
+ return `Not finished: ${l.open} ${l.open === 1 ? "row" : "rows"} still running${fails !== "" ? ` · ${fails}` : ""}${contradicted}${l.unverified > 0 ? ` · ${l.unverified} unverified` : ""}${noReport}`;
516
+ const coverage = `coverage ${l.coverage}${fails !== "" ? ` (${fails})` : ""}`;
517
+ const checks = l.unverified > 0 ? `${l.unverified} unverified` : !completed ? "none completed" : l.contradicted > 0 ? "none unverified" : "all verified";
518
+ return `Settled · ${coverage}${contradicted} · ${checks}${noReport}`;
519
+ }
520
+ const endingsOf = (counts) => MEMBER_OUTCOMES.filter((w) => w !== "completed" && (counts[w] ?? 0) > 0).map((w) => `${counts[w]} ${w}`);
521
+ const CHECK_WORDS = { verified: "verified", evidence: "used as evidence", unverified: "not verified", "n/a": "—" };
522
+ const VERDICT_WORDS = { confirms: "confirmed", refutes: "refuted", partial: "partly confirmed" };
523
+ export function runLedgerText(l) {
524
+ const lines = [l.headline];
525
+ const withResult = l.rows.filter((r) => r.state === "settled").length;
526
+ const endings = endingsOf(l.counts);
527
+ lines.push(`${l.rows.length} ${l.rows.length === 1 ? "member" : "members"} dispatched: ${withResult} with an ending${endings.length > 0 ? ` (${endings.join(", ")} of them not completed)` : ""}, ${l.open} still running; ${l.unverified} completed without a check, ${l.contradicted} contradicted by one.`);
528
+ if (l.unreadable !== undefined && l.unreadable > 0)
529
+ lines.push(`${l.unreadable} ${l.unreadable === 1 ? "member" : "members"} this task dispatched can no longer be read from ${l.unreadable === 1 ? "its holder" : "their holder"} (reclaimed, or held by another process): the coverage is not complete.`);
530
+ for (const r of l.rows) {
531
+ const who = `${r.label}${r.name !== undefined ? ` [${inlineUntrusted(r.name, 60)}]` : ""} (${r.kind} ${r.taskId})`;
532
+ const ending = r.outcome !== undefined ? memberOutcomeText(r.outcome) : "still running";
533
+ lines.push(`- ${who}: ${ending}${r.check !== "n/a" ? ` · ${CHECK_WORDS[r.check]}` : ""}${r.verdict !== undefined ? ` (${VERDICT_WORDS[r.verdict]})` : ""}`);
534
+ if (r.members !== undefined)
535
+ lines.push(` its members: coverage ${r.members.coverage}; ${Object.entries(r.members.counts).map(([w, c]) => `${c} ${w}`).join(", ")}`);
536
+ if (r.selfReport !== undefined)
537
+ lines.push(` said: ${r.selfReport}`);
538
+ if (r.actions !== undefined)
539
+ lines.push(` did: ${subagentActionsLine(r.actions)}`);
540
+ }
541
+ if (l.lastReport !== undefined) {
542
+ lines.push(`Last report (${l.lastReport.status}${l.lastReport.kind !== undefined ? `, ${l.lastReport.kind}` : ""}): ${inlineUntrusted(l.lastReport.message, 600)}`);
543
+ for (const c of l.lastReport.claims ?? [])
544
+ lines.push(` ${c.basis}${c.verdict !== undefined ? ` (${c.verdict})` : ""} · ${inlineUntrusted(c.about, 60)}: ${inlineUntrusted(c.text, 200)}`);
545
+ }
546
+ if (l.launch !== undefined && l.launch.verdict !== "ready") {
547
+ lines.push(`Launch check: ${l.launch.verdict} — ${l.launch.items.filter((i) => i.state !== "ok").map((i) => `${i.item} ${i.state}`).join("; ")}`);
548
+ }
549
+ return lines.join("\n");
550
+ }
@@ -1,4 +1,5 @@
1
1
  import type { CompositionLeg, RunInternals } from "./contracts.js";
2
+ import type { CheckpointState } from "../checkpoint-store.js";
2
3
  /**
3
4
  * The SINGLE derivation of a durable-suspend checkpoint's scope — the LEG's scope, computed once per prepare and
4
5
  * read by every mint lane of that leg (approval park, resource and `plan_review` parks, the forceDurableGate
@@ -42,6 +43,7 @@ export type DeclaredScopeReading = {
42
43
  } | {
43
44
  readonly kind: "none";
44
45
  readonly fault: string;
46
+ readonly at?: "scope" | "ttlMs" | "undeclared";
45
47
  };
46
48
  /**
47
49
  * The ONE reading of "this opt-in names its scope": a `durableApproval` — the task's own, or the record a parked row keeps of it — names
@@ -86,6 +88,15 @@ export declare function compositionLegRecord(leg: CompositionLeg | undefined): C
86
88
  export declare function workSessionOfLeg(leg: CompositionLeg | undefined): string | undefined;
87
89
  /** Whether two composition-leg records name the same leg of the same composition for the same host session. */
88
90
  export declare function sameCompositionLeg(a: CompositionLeg, b: CompositionLeg): boolean;
89
- /** The row a resumed leg runs as ({@link RunInternals.rowTaskId}): the live seat when handed, else the parked row's record —
90
- * folded into internals so the mint at prepare, the resume screen and the throw backstop read one value. */
91
- export declare function restoreRowTaskId(internals: RunInternals | undefined, recorded: string | undefined): RunInternals | undefined;
91
+ /** The identity a resumed leg runs as, read off the parked row it resumes: the registry row it ran as ({@link RunInternals.rowTaskId}),
92
+ * its spawning task ({@link RunInternals.parentTaskId}), its tree's root address — id, box scope and occupant (one anchor: taken
93
+ * whole or not at all) — and its explicit spawn name ({@link RunInternals.explicitAgentName}), each the live seat when the resuming call hands one,
94
+ * else the row's record (`CheckpointState.rowTaskId` / `legIdentity`) — folded into internals once, so the resume screen and every
95
+ * reader of the resumed leg (its prepare's mints, its stations, the throw backstop) read one value. A row that records none leaves
96
+ * the internals as handed. */
97
+ export declare function restoreRowIdentity(internals: RunInternals | undefined, state: Pick<CheckpointState, "rowTaskId" | "legIdentity"> | undefined): RunInternals | undefined;
98
+ /** The task id a resumed leg's host declared: the resume config's, else the one the parked row records its host declared
99
+ * (`CheckpointState.legIdentity.declaredTaskId`) — so a resume that names none runs as the task that parked, never as its session. */
100
+ export declare function resumedDeclaredTaskId(config: {
101
+ readonly taskId?: string | undefined;
102
+ }, state: Pick<CheckpointState, "legIdentity">): string | undefined;
@@ -10,8 +10,10 @@ export function readDeclaredCheckpointScope(declared) {
10
10
  if (typeof declared !== "object" || declared === null)
11
11
  return { kind: "none", fault: declared === null ? "null, not an object" : `a ${typeof declared}, not an object` };
12
12
  const data = receive(declared, DECLARED_SCOPE_DATA);
13
- if (!data.ok)
14
- return { kind: "none", fault: `not plain data — ${describeFault(data.fault)}` };
13
+ if (!data.ok) {
14
+ const f = data.fault.path[0];
15
+ return f === undefined || f === "scope" ? { kind: "none", ...(f === "scope" ? { at: "scope" } : {}), fault: `not plain data — ${describeFault(data.fault)}` } : { kind: "none", at: f === "ttlMs" ? "ttlMs" : "undeclared", fault: describeFault({ kind: data.fault.kind, path: [] }) };
16
+ }
15
17
  const record = data.value;
16
18
  if (!isPlainRecord(record))
17
19
  return { kind: "none", fault: "a list, not a record" };
@@ -49,8 +51,16 @@ export function workSessionOfLeg(leg) {
49
51
  export function sameCompositionLeg(a, b) {
50
52
  return a.entry === b.entry && a.leg === b.leg && a.hostSessionId === b.hostSessionId;
51
53
  }
52
- export function restoreRowTaskId(internals, recorded) {
53
- if (internals?.rowTaskId !== undefined || recorded === undefined)
54
- return internals;
55
- return { ...(internals ?? {}), rowTaskId: recorded };
54
+ export function restoreRowIdentity(internals, state) {
55
+ const row = state?.legIdentity;
56
+ const restored = {
57
+ ...(internals?.rowTaskId === undefined && state?.rowTaskId !== undefined ? { rowTaskId: state.rowTaskId } : {}),
58
+ ...(internals?.parentTaskId === undefined && row?.parentTaskId !== undefined ? { parentTaskId: row.parentTaskId } : {}),
59
+ ...(internals?.rootSessionId === undefined && row?.rootSessionId !== undefined && row.rootSessionScope !== undefined ? { rootSessionId: row.rootSessionId, rootSessionScope: row.rootSessionScope, ...(row.rootSessionIncarnation !== undefined ? { rootSessionIncarnation: row.rootSessionIncarnation } : {}) } : {}),
60
+ ...(internals?.explicitAgentName === undefined && row?.spawnName !== undefined ? { explicitAgentName: row.spawnName } : {}),
61
+ };
62
+ return Object.keys(restored).length === 0 ? internals : { ...(internals ?? {}), ...restored };
63
+ }
64
+ export function resumedDeclaredTaskId(config, state) {
65
+ return config.taskId ?? state.legIdentity?.declaredTaskId;
56
66
  }
@@ -272,7 +272,7 @@ const PARKED = {
272
272
  undone: "a parked session's resume rewinds its branch to the checkpoint's leaf, where a summary written now would not be read, so nothing was compacted; decide the checkpoint (resume it) or expire it, then compact",
273
273
  };
274
274
  function sessionBusyRefusal(sessionId) {
275
- const e = new Error(`${VERB}: a task is running or queued on session "${sessionId}" in this Runner, or a write one of its tasks issued has not settled — compacting it now would rewrite the transcript under that work, so nothing was compacted; a running task takes the request through its own stream (TaskStream.compact), otherwise retry once it has ended and its writes have settled`);
275
+ const e = new Error(`compacting session "${sessionId}" was refused: this Runner is using the session — a task is running or queued on it, a compaction or rewind of it is in progress, or a write one of its tasks issued has not settled — and compacting now would rewrite the transcript under that work, so nothing was compacted; a running task can compact through its own stream, otherwise retry once that work has ended and its writes have settled`);
276
276
  e.code = "compact.session_busy";
277
277
  return e;
278
278
  }