@sema-agent/core 7.51.2 → 7.53.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 (446) hide show
  1. package/CHANGELOG.md +698 -2
  2. package/README.md +3 -1
  3. package/dist/agents/agent-transcript-tool.d.ts +1 -1
  4. package/dist/agents/cascade.js +4 -0
  5. package/dist/agents/cross-session-envelope.d.ts +8 -0
  6. package/dist/agents/cross-session-envelope.js +6 -0
  7. package/dist/agents/cross-session-judge.d.ts +21 -1
  8. package/dist/agents/cross-session-judge.js +8 -0
  9. package/dist/agents/cross-session-ref.d.ts +5 -0
  10. package/dist/agents/cross-session-ref.js +1 -0
  11. package/dist/agents/cumulative-stats.d.ts +3 -0
  12. package/dist/agents/cumulative-stats.js +3 -0
  13. package/dist/agents/list-agents-tool.d.ts +1 -1
  14. package/dist/agents/org-delivery-gate.d.ts +122 -0
  15. package/dist/agents/org-delivery-gate.js +69 -0
  16. package/dist/agents/peer-held-queue.d.ts +9 -4
  17. package/dist/agents/peer-held-queue.js +6 -5
  18. package/dist/agents/peer-session-drain.d.ts +35 -5
  19. package/dist/agents/peer-session-drain.js +271 -180
  20. package/dist/agents/read-inbox-tool.d.ts +8 -1
  21. package/dist/agents/read-inbox-tool.js +5 -1
  22. package/dist/agents/repair-loop.js +4 -0
  23. package/dist/agents/send-message-tool.d.ts +11 -16
  24. package/dist/agents/send-message-tool.js +11 -13
  25. package/dist/agents/subagent.d.ts +3 -0
  26. package/dist/agents/subagent.js +105 -76
  27. package/dist/agents/tool-filter.d.ts +58 -13
  28. package/dist/agents/tool-filter.js +34 -14
  29. package/dist/bench/metrics.d.ts +1 -0
  30. package/dist/brain/anthropic.d.ts +6 -1
  31. package/dist/brain/anthropic.js +17 -13
  32. package/dist/brain/model-presets.d.ts +4 -5
  33. package/dist/brain/model-presets.js +6 -5
  34. package/dist/brain/open-responses.js +16 -12
  35. package/dist/brain/openai.js +16 -12
  36. package/dist/brain/request-params.d.ts +12 -33
  37. package/dist/brain/request-params.js +5 -2
  38. package/dist/brain/request-route.d.ts +9 -8
  39. package/dist/brain/request-route.js +1 -0
  40. package/dist/brain/route-adjudicator.d.ts +123 -47
  41. package/dist/brain/route-adjudicator.js +171 -42
  42. package/dist/brain/route-conformance.js +2 -2
  43. package/dist/brain/routing.d.ts +24 -1
  44. package/dist/brain/routing.js +54 -19
  45. package/dist/brain/status-sink.d.ts +18 -0
  46. package/dist/brain/status-sink.js +7 -0
  47. package/dist/brain/timeout.js +5 -4
  48. package/dist/core/a2a.d.ts +5 -2
  49. package/dist/core/a2a.js +30 -13
  50. package/dist/core/allow-entry.d.ts +42 -9
  51. package/dist/core/allow-entry.js +25 -18
  52. package/dist/core/auto-compaction.d.ts +80 -20
  53. package/dist/core/auto-compaction.js +65 -18
  54. package/dist/core/auto-promote.d.ts +2 -1
  55. package/dist/core/auto-promote.js +2 -2
  56. package/dist/core/caller-tool-name.d.ts +9 -0
  57. package/dist/core/caller-tool-name.js +13 -0
  58. package/dist/core/checkpoint-requirements.d.ts +7 -1
  59. package/dist/core/checkpoint-requirements.js +2 -0
  60. package/dist/core/checkpoint-store.d.ts +57 -24
  61. package/dist/core/checkpoint-store.js +3 -3
  62. package/dist/core/child-clamp-seats.d.ts +6 -0
  63. package/dist/core/child-clamp-seats.js +2 -1
  64. package/dist/core/compliance.js +3 -1
  65. package/dist/core/credential-vocabulary.d.ts +33 -8
  66. package/dist/core/credential-vocabulary.js +32 -7
  67. package/dist/core/decision-receipt.d.ts +2 -2
  68. package/dist/core/delegation-frames.d.ts +9 -2
  69. package/dist/core/delegation-name.d.ts +18 -0
  70. package/dist/core/delegation-name.js +47 -0
  71. package/dist/core/effective-path-target.d.ts +25 -6
  72. package/dist/core/effective-path-target.js +24 -2
  73. package/dist/core/engine-capabilities.d.ts +8 -1
  74. package/dist/core/engine-capabilities.js +1 -1
  75. package/dist/core/engine-notice.d.ts +49 -21
  76. package/dist/core/frontmatter-fence.d.ts +10 -0
  77. package/dist/core/frontmatter-fence.js +6 -0
  78. package/dist/core/gate-fold.js +8 -25
  79. package/dist/core/gate-lanes.js +358 -274
  80. package/dist/core/gate-outcome.d.ts +11 -6
  81. package/dist/core/governance-codes.d.ts +11 -4
  82. package/dist/core/governance-codes.js +12 -3
  83. package/dist/core/hands-band-screen.d.ts +7 -0
  84. package/dist/core/hands-band-screen.js +32 -0
  85. package/dist/core/hooks.d.ts +283 -739
  86. package/dist/core/hooks.js +100 -193
  87. package/dist/{tools/fs → core}/image-admission.d.ts +21 -3
  88. package/dist/{tools/fs → core}/image-admission.js +24 -6
  89. package/dist/core/locked-config.d.ts +84 -32
  90. package/dist/core/locked-config.js +128 -42
  91. package/dist/core/mcp-connection-pool.d.ts +4 -1
  92. package/dist/core/mcp-connection-pool.js +7 -2
  93. package/dist/core/mcp-probe.d.ts +12 -9
  94. package/dist/core/mcp-probe.js +3 -3
  95. package/dist/core/mcp-server-spec.d.ts +104 -10
  96. package/dist/core/mcp-server-spec.js +183 -33
  97. package/dist/core/mcp.d.ts +31 -20
  98. package/dist/core/mcp.js +66 -56
  99. package/dist/core/memory-engine/data-plane.js +5 -1
  100. package/dist/core/memory-engine/distiller.js +16 -2
  101. package/dist/core/memory-engine/engine.d.ts +22 -30
  102. package/dist/core/memory-engine/engine.js +16 -10
  103. package/dist/core/memory-engine/frontmatter.d.ts +6 -0
  104. package/dist/core/memory-engine/frontmatter.js +19 -16
  105. package/dist/core/memory.d.ts +2 -2
  106. package/dist/core/mode-policy.d.ts +5 -16
  107. package/dist/core/mode-policy.js +7 -19
  108. package/dist/core/model-seat.d.ts +4 -1
  109. package/dist/core/mods/dollar.d.ts +109 -0
  110. package/dist/core/mods/dollar.js +154 -0
  111. package/dist/core/mods/host.d.ts +23 -0
  112. package/dist/core/mods/host.js +21 -0
  113. package/dist/core/mods/kernel/budget.d.ts +43 -0
  114. package/dist/core/mods/kernel/budget.js +83 -0
  115. package/dist/core/mods/kernel/dispatch.d.ts +100 -0
  116. package/dist/core/mods/kernel/dispatch.js +699 -0
  117. package/dist/core/mods/kernel/events.d.ts +245 -0
  118. package/dist/core/mods/kernel/events.js +210 -0
  119. package/dist/core/mods/kernel/index.d.ts +6 -0
  120. package/dist/core/mods/kernel/index.js +5 -0
  121. package/dist/core/mods/kernel/receive.d.ts +94 -0
  122. package/dist/core/mods/kernel/receive.js +188 -0
  123. package/dist/core/mods/kernel/registration.d.ts +131 -0
  124. package/dist/core/mods/kernel/registration.js +102 -0
  125. package/dist/core/mods/kernel/site-rules.d.ts +149 -0
  126. package/dist/core/mods/kernel/site-rules.js +296 -0
  127. package/dist/core/mods/stations.d.ts +344 -0
  128. package/dist/core/mods/stations.js +437 -0
  129. package/dist/core/mounted-mcp.d.ts +57 -0
  130. package/dist/core/mounted-mcp.js +71 -2
  131. package/dist/core/own-property-receipt.d.ts +13 -0
  132. package/dist/core/own-property-receipt.js +13 -23
  133. package/dist/core/parent-spec-seat.d.ts +18 -7
  134. package/dist/core/parent-spec-seat.js +6 -2
  135. package/dist/core/path-identity.js +2 -1
  136. package/dist/core/permission-rule-model.d.ts +58 -9
  137. package/dist/core/permission-rule-model.js +81 -7
  138. package/dist/core/permission-rule-org.d.ts +163 -33
  139. package/dist/core/permission-rule-org.js +205 -71
  140. package/dist/core/permission-rule-syntax.d.ts +15 -0
  141. package/dist/core/permission-rule-syntax.js +24 -16
  142. package/dist/core/permission-rules.d.ts +14 -2
  143. package/dist/core/permission-rules.js +63 -23
  144. package/dist/core/prompt-section-seat.d.ts +15 -27
  145. package/dist/core/prompt-section-seat.js +73 -40
  146. package/dist/core/protocol-http-auth.d.ts +3 -1
  147. package/dist/core/protocol-http-auth.js +2 -0
  148. package/dist/core/reminder-mint.d.ts +2 -2
  149. package/dist/core/remote-env.d.ts +24 -12
  150. package/dist/core/remote-env.js +1 -0
  151. package/dist/core/resume-startup-cause.d.ts +16 -1
  152. package/dist/core/resume-startup-cause.js +4 -1
  153. package/dist/core/retention.js +7 -2
  154. package/dist/core/retired-keys.d.ts +12 -2
  155. package/dist/core/retired-keys.js +15 -1
  156. package/dist/core/roles.js +60 -10
  157. package/dist/core/rule-lane-reads.js +1 -1
  158. package/dist/core/runner/announce-once-ledger.d.ts +31 -1
  159. package/dist/core/runner/announce-once-ledger.js +22 -0
  160. package/dist/core/runner/assemble-result.d.ts +9 -0
  161. package/dist/core/runner/assemble-result.js +3 -1
  162. package/dist/core/runner/call-hook-stations.d.ts +23 -27
  163. package/dist/core/runner/call-hook-stations.js +58 -42
  164. package/dist/core/runner/caller-stop-gate.d.ts +25 -0
  165. package/dist/core/runner/caller-stop-gate.js +7 -0
  166. package/dist/core/runner/compaction-seams.d.ts +8 -22
  167. package/dist/core/runner/compaction-seams.js +28 -53
  168. package/dist/core/runner/construction-doors.js +11 -1
  169. package/dist/core/runner/contracts.d.ts +86 -83
  170. package/dist/core/runner/credential-origin-seat.d.ts +2 -0
  171. package/dist/core/runner/credential-origin-seat.js +19 -0
  172. package/dist/core/runner/extra-body-dropped-seat.d.ts +2 -6
  173. package/dist/core/runner/gate-exit.d.ts +47 -36
  174. package/dist/core/runner/gate-exit.js +12 -5
  175. package/dist/core/runner/image.js +1 -2
  176. package/dist/core/runner/inline-image.js +1 -1
  177. package/dist/core/runner/mcp-redial.d.ts +52 -10
  178. package/dist/core/runner/mcp-redial.js +38 -9
  179. package/dist/core/runner/notice-seat-input.d.ts +11 -0
  180. package/dist/core/runner/notice-seat-input.js +1 -0
  181. package/dist/core/runner/permission-rule-lanes.d.ts +5 -2
  182. package/dist/core/runner/permission-rule-lanes.js +22 -10
  183. package/dist/core/runner/person-path-rows.d.ts +3 -1
  184. package/dist/core/runner/person-path-rows.js +3 -2
  185. package/dist/core/runner/prepare-acquire-reconcile.js +5 -1
  186. package/dist/core/runner/prepare-ask-lane.d.ts +5 -7
  187. package/dist/core/runner/prepare-ask-lane.js +6 -15
  188. package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -2
  189. package/dist/core/runner/prepare-caps-and-workflow.js +25 -8
  190. package/dist/core/runner/prepare-config-doors.d.ts +52 -1
  191. package/dist/core/runner/prepare-config-doors.js +168 -143
  192. package/dist/core/runner/prepare-defer-classify.js +7 -11
  193. package/dist/core/runner/prepare-delegation-surface.d.ts +2 -2
  194. package/dist/core/runner/prepare-delegation-surface.js +7 -5
  195. package/dist/core/runner/prepare-gate-stations.d.ts +8 -11
  196. package/dist/core/runner/prepare-gate-stations.js +11 -10
  197. package/dist/core/runner/prepare-hands-readface.d.ts +1 -1
  198. package/dist/core/runner/prepare-hands-readface.js +2 -1
  199. package/dist/core/runner/prepare-inherited-gate.d.ts +8 -12
  200. package/dist/core/runner/prepare-inherited-gate.js +10 -23
  201. package/dist/core/runner/prepare-listings.d.ts +1 -1
  202. package/dist/core/runner/prepare-listings.js +4 -2
  203. package/dist/core/runner/prepare-memory-engine-session.d.ts +0 -6
  204. package/dist/core/runner/prepare-memory-engine-session.js +20 -7
  205. package/dist/core/runner/prepare-memory.d.ts +3 -2
  206. package/dist/core/runner/prepare-memory.js +6 -2
  207. package/dist/core/runner/prepare-offload-wrappers.d.ts +4 -4
  208. package/dist/core/runner/prepare-offload-wrappers.js +2 -1
  209. package/dist/core/runner/prepare-park-ask.js +10 -14
  210. package/dist/core/runner/prepare-policy-chain.d.ts +17 -15
  211. package/dist/core/runner/prepare-policy-chain.js +104 -109
  212. package/dist/core/runner/prepare-project-context.d.ts +1 -1
  213. package/dist/core/runner/prepare-project-context.js +11 -12
  214. package/dist/core/runner/prepare-prompt-assembly.d.ts +45 -40
  215. package/dist/core/runner/prepare-prompt-assembly.js +138 -101
  216. package/dist/core/runner/prepare-prompt-inputs.d.ts +28 -23
  217. package/dist/core/runner/prepare-prompt-inputs.js +11 -10
  218. package/dist/core/runner/prepare-protocol-tools.d.ts +11 -7
  219. package/dist/core/runner/prepare-protocol-tools.js +20 -13
  220. package/dist/core/runner/prepare-question-face.d.ts +4 -2
  221. package/dist/core/runner/prepare-question-face.js +4 -3
  222. package/dist/core/runner/prepare-safety-scan.js +6 -10
  223. package/dist/core/runner/prepare-suspend-saga.d.ts +6 -0
  224. package/dist/core/runner/prepare-suspend-saga.js +7 -5
  225. package/dist/core/runner/prepare-task.js +41 -23
  226. package/dist/core/runner/prepare-turn-wiring.d.ts +13 -15
  227. package/dist/core/runner/prepare-turn-wiring.js +29 -27
  228. package/dist/core/runner/prepare-wiring-manifest.d.ts +13 -9
  229. package/dist/core/runner/prepare-wiring-manifest.js +14 -11
  230. package/dist/core/runner/resume-admission.d.ts +4 -1
  231. package/dist/core/runner/resume-admission.js +7 -5
  232. package/dist/core/runner/resume-apply.d.ts +5 -2
  233. package/dist/core/runner/resume-apply.js +24 -42
  234. package/dist/core/runner/resume-checkpoint-screen.d.ts +1 -0
  235. package/dist/core/runner/resume-checkpoint-screen.js +9 -1
  236. package/dist/core/runner/resume-internals-and-config.d.ts +3 -3
  237. package/dist/core/runner/resume-internals-and-config.js +3 -8
  238. package/dist/core/runner/resume-preflight.js +38 -16
  239. package/dist/core/runner/retired-runner-deps.d.ts +5 -6
  240. package/dist/core/runner/retired-runner-deps.js +4 -5
  241. package/dist/core/runner/run-brain-sinks.d.ts +3 -2
  242. package/dist/core/runner/run-brain-sinks.js +5 -1
  243. package/dist/core/runner/run-compaction-machinery.d.ts +7 -1
  244. package/dist/core/runner/run-compaction-machinery.js +7 -33
  245. package/dist/core/runner/run-harness-handlers.js +4 -2
  246. package/dist/core/runner/run-identity-wiring.d.ts +3 -1
  247. package/dist/core/runner/run-identity-wiring.js +3 -2
  248. package/dist/core/runner/run-leg.js +103 -95
  249. package/dist/core/runner/run-notification-lane.js +1 -0
  250. package/dist/core/runner/run-recovery-lanes.d.ts +3 -0
  251. package/dist/core/runner/run-recovery-lanes.js +14 -11
  252. package/dist/core/runner/run-settle-and-teardown.js +9 -28
  253. package/dist/core/runner/run-stop-and-final-verify.js +18 -25
  254. package/dist/core/runner/run-terminal-adoption.d.ts +3 -0
  255. package/dist/core/runner/run-terminal-adoption.js +34 -22
  256. package/dist/core/runner/run-tool-mount-facts.js +5 -3
  257. package/dist/core/runner/run-turn-boundary.js +32 -37
  258. package/dist/core/runner/runtask.d.ts +6 -7
  259. package/dist/core/runner/runtask.js +15 -73
  260. package/dist/core/runner/session-rule-policy.d.ts +5 -5
  261. package/dist/core/runner/session-rule-policy.js +13 -8
  262. package/dist/core/runner/side-call-account.d.ts +68 -0
  263. package/dist/core/runner/side-call-account.js +61 -0
  264. package/dist/core/runner/skills-seat.d.ts +15 -0
  265. package/dist/core/runner/skills-seat.js +57 -0
  266. package/dist/core/runner/stream-halt-verbs.js +12 -17
  267. package/dist/core/runner/stream-lifecycle-verbs.js +8 -5
  268. package/dist/core/runner/stream-steer-verb.d.ts +1 -1
  269. package/dist/core/runner/stream-steer-verb.js +20 -38
  270. package/dist/core/runner/sub-agent-deny-lists.d.ts +124 -23
  271. package/dist/core/runner/sub-agent-deny-lists.js +230 -71
  272. package/dist/core/runner/synthetic-tools.d.ts +5 -2
  273. package/dist/core/runner/synthetic-tools.js +2 -12
  274. package/dist/core/runner/tool-end-body.d.ts +5 -6
  275. package/dist/core/runner/tool-end-body.js +6 -4
  276. package/dist/core/runner/tool-not-executed.d.ts +15 -0
  277. package/dist/core/runner/tool-not-executed.js +30 -0
  278. package/dist/core/runner/tool-occurrence.d.ts +8 -7
  279. package/dist/core/runner/tool-occurrence.js +5 -5
  280. package/dist/core/runner/tool-result-media-seat.d.ts +1 -1
  281. package/dist/core/runner-deps.d.ts +43 -36
  282. package/dist/core/safety-merge-corpus.js +18 -2
  283. package/dist/core/secret-env.d.ts +88 -20
  284. package/dist/core/secret-env.js +192 -38
  285. package/dist/core/session-policy-store.d.ts +71 -16
  286. package/dist/core/session-policy-store.js +138 -28
  287. package/dist/core/session-reconcile.d.ts +4 -0
  288. package/dist/core/session-reconcile.js +2 -1
  289. package/dist/core/shell-read-silence.js +3 -32
  290. package/dist/core/side-query.d.ts +5 -3
  291. package/dist/core/skill-grant.d.ts +3 -2
  292. package/dist/core/skill-grant.js +17 -9
  293. package/dist/core/skills-directory.d.ts +31 -11
  294. package/dist/core/skills-directory.js +655 -104
  295. package/dist/core/store-contracts/mailbox-store-contract.js +13 -0
  296. package/dist/core/task-event.d.ts +49 -3
  297. package/dist/core/task-notification.js +2 -2
  298. package/dist/core/task-result.d.ts +8 -0
  299. package/dist/core/task-spec.d.ts +20 -19
  300. package/dist/core/task-stream.d.ts +14 -4
  301. package/dist/core/tighten-task-spec.d.ts +4 -3
  302. package/dist/core/tighten-task-spec.js +2 -4
  303. package/dist/core/tool-check-reading.d.ts +74 -0
  304. package/dist/core/tool-check-reading.js +80 -0
  305. package/dist/core/tool-policy.d.ts +62 -18
  306. package/dist/core/tool-policy.js +86 -15
  307. package/dist/core/tool-registry.d.ts +20 -0
  308. package/dist/core/tool-registry.js +4 -0
  309. package/dist/core/tool-spec.d.ts +10 -6
  310. package/dist/core/tools.js +2 -0
  311. package/dist/core/trace.d.ts +51 -32
  312. package/dist/core/types.d.ts +2 -2
  313. package/dist/core/types.js +1 -1
  314. package/dist/core/unc-spelling.d.ts +10 -0
  315. package/dist/core/unc-spelling.js +3 -0
  316. package/dist/core/untrusted-egress.d.ts +8 -0
  317. package/dist/core/untrusted-egress.js +4 -1
  318. package/dist/core/untrusted-text.d.ts +16 -0
  319. package/dist/core/untrusted-text.js +7 -2
  320. package/dist/core/user-attachment.d.ts +25 -4
  321. package/dist/core/user-attachment.js +63 -42
  322. package/dist/core/wiring-manifest.d.ts +18 -15
  323. package/dist/core/wiring-manifest.js +2 -2
  324. package/dist/engine/compaction/utils.js +1 -2
  325. package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
  326. package/dist/engine/execution-env/symlink-chain.js +1 -1
  327. package/dist/engine/harness/agent-harness.d.ts +1 -1
  328. package/dist/engine/harness/agent-harness.js +5 -4
  329. package/dist/engine/harness/types.d.ts +20 -16
  330. package/dist/engine/harness/types.js +7 -1
  331. package/dist/engine/llm/types.d.ts +12 -7
  332. package/dist/engine/loop/agent-loop.d.ts +12 -1
  333. package/dist/engine/loop/agent-loop.js +18 -6
  334. package/dist/engine/loop/types.d.ts +8 -2
  335. package/dist/engine/lsp/node-lsp-manager.d.ts +2 -2
  336. package/dist/engine/session/import-validate.js +3 -10
  337. package/dist/engine/session/session.d.ts +4 -4
  338. package/dist/engine/session/session.js +4 -4
  339. package/dist/index.d.ts +33 -23
  340. package/dist/index.js +23 -15
  341. package/dist/internal/harness.d.ts +2 -1
  342. package/dist/internal/harness.js +2 -1
  343. package/dist/orchestration/goal.d.ts +24 -1
  344. package/dist/orchestration/goal.js +3 -2
  345. package/dist/orchestration/run-spec.d.ts +4 -6
  346. package/dist/orchestration/run-spec.js +39 -63
  347. package/dist/orchestration/run-workflow-tool.js +1 -2
  348. package/dist/orchestration/workflow.d.ts +11 -3
  349. package/dist/orchestration/workflow.js +11 -2
  350. package/dist/prompt-assembly/artifact-store.d.ts +72 -56
  351. package/dist/prompt-assembly/artifact-store.js +60 -52
  352. package/dist/prompt-assembly/artifact.d.ts +90 -76
  353. package/dist/prompt-assembly/artifact.js +197 -145
  354. package/dist/prompt-assembly/assemble.d.ts +36 -29
  355. package/dist/prompt-assembly/assemble.js +34 -220
  356. package/dist/prompt-assembly/bands.d.ts +20 -0
  357. package/dist/prompt-assembly/bands.js +18 -0
  358. package/dist/prompt-assembly/catalog/constitution.d.ts +23 -0
  359. package/dist/prompt-assembly/catalog/constitution.js +69 -0
  360. package/dist/prompt-assembly/catalog/core-behavior.d.ts +9 -0
  361. package/dist/prompt-assembly/catalog/core-behavior.js +85 -0
  362. package/dist/prompt-assembly/catalog/index.d.ts +11 -0
  363. package/dist/prompt-assembly/catalog/index.js +60 -0
  364. package/dist/prompt-assembly/catalog/memory.d.ts +13 -0
  365. package/dist/prompt-assembly/catalog/memory.js +6 -0
  366. package/dist/prompt-assembly/catalog/modes.d.ts +15 -0
  367. package/dist/prompt-assembly/catalog/modes.js +137 -0
  368. package/dist/prompt-assembly/catalog/role.d.ts +10 -0
  369. package/dist/prompt-assembly/catalog/role.js +157 -0
  370. package/dist/prompt-assembly/catalog/schema.d.ts +138 -0
  371. package/dist/prompt-assembly/catalog/schema.js +25 -0
  372. package/dist/prompt-assembly/catalog/sections.d.ts +9 -0
  373. package/dist/prompt-assembly/catalog/sections.js +98 -0
  374. package/dist/prompt-assembly/catalog/team.d.ts +4 -0
  375. package/dist/prompt-assembly/catalog/team.js +258 -0
  376. package/dist/prompt-assembly/composer.d.ts +26 -28
  377. package/dist/prompt-assembly/composer.js +124 -46
  378. package/dist/prompt-assembly/epoch.d.ts +89 -79
  379. package/dist/prompt-assembly/epoch.js +115 -142
  380. package/dist/prompt-assembly/explain.d.ts +58 -34
  381. package/dist/prompt-assembly/explain.js +21 -24
  382. package/dist/prompt-assembly/overlay.d.ts +137 -0
  383. package/dist/prompt-assembly/overlay.js +339 -0
  384. package/dist/prompt-assembly/renderers.d.ts +21 -0
  385. package/dist/prompt-assembly/renderers.js +39 -0
  386. package/dist/prompt-assembly/section-usage.d.ts +3 -3
  387. package/dist/prompt-assembly/section-usage.js +1 -1
  388. package/dist/prompt-assembly/select.d.ts +71 -0
  389. package/dist/prompt-assembly/select.js +106 -0
  390. package/dist/prompt-assembly/sugar.d.ts +31 -0
  391. package/dist/prompt-assembly/sugar.js +20 -0
  392. package/dist/prompt-assembly/turn-snapshot.d.ts +3 -2
  393. package/dist/prompt-assembly/types.d.ts +45 -148
  394. package/dist/prompts/coordinator.d.ts +2 -21
  395. package/dist/prompts/coordinator.js +3 -255
  396. package/dist/prompts/cowork.d.ts +27 -16
  397. package/dist/prompts/cowork.js +2 -23
  398. package/dist/prompts/default.d.ts +38 -511
  399. package/dist/prompts/default.js +20 -288
  400. package/dist/prompts/supervisor.d.ts +6 -71
  401. package/dist/prompts/supervisor.js +6 -117
  402. package/dist/stores/file/permission-rule-store.d.ts +1 -1
  403. package/dist/stores/file/permission-rule-store.js +2 -1
  404. package/dist/tools/artifact/artifact-tool.js +4 -3
  405. package/dist/tools/fs/bash-readonly-classifier.d.ts +6 -5
  406. package/dist/tools/fs/dir-entries.d.ts +4 -2
  407. package/dist/tools/fs/dir-entries.js +16 -4
  408. package/dist/tools/fs/fs-bash.d.ts +1 -1
  409. package/dist/tools/fs/fs-bash.js +22 -11
  410. package/dist/tools/fs/fs-pdf.js +17 -13
  411. package/dist/tools/fs/fs-read.js +4 -3
  412. package/dist/tools/fs/fs-shared.d.ts +1 -10
  413. package/dist/tools/fs/fs-shared.js +3 -4
  414. package/dist/tools/fs/fs-write.js +2 -1
  415. package/dist/tools/fs/notebook.js +1 -1
  416. package/dist/tools/fs/pdf.d.ts +20 -10
  417. package/dist/tools/fs/pdf.js +19 -10
  418. package/dist/tools/fs/program-read-model.d.ts +68 -8
  419. package/dist/tools/fs/program-read-model.js +112 -33
  420. package/dist/tools/fs/program-read-model.rows.js +30 -10
  421. package/dist/tools/fs/read-deny-home.d.ts +25 -9
  422. package/dist/tools/fs/read-deny-home.js +28 -27
  423. package/dist/tools/fs/read-deny.d.ts +41 -11
  424. package/dist/tools/fs/read-deny.js +51 -5
  425. package/dist/tools/fs/safety.d.ts +4 -26
  426. package/dist/tools/fs/safety.js +10 -32
  427. package/dist/tools/fs/search.js +15 -10
  428. package/dist/tools/fs/shell-read-argv.d.ts +3 -2
  429. package/dist/tools/fs/shell-read-argv.js +118 -38
  430. package/dist/tools/fs/shell-read-establish.d.ts +5 -5
  431. package/dist/tools/fs/shell-read-establish.js +11 -61
  432. package/dist/tools/fs/shell-read-identity.js +6 -3
  433. package/dist/tools/fs/shell-read-judge.d.ts +13 -15
  434. package/dist/tools/fs/shell-read-judge.js +18 -4
  435. package/dist/tools/fs/shell-read-plan.d.ts +2 -2
  436. package/dist/tools/web.js +1 -1
  437. package/package.json +13 -1
  438. package/test/export-surface.snapshot.json +306 -103
  439. package/wire-changes/core@7.52.0.json +5859 -0
  440. package/wire-changes/core@7.53.0.json +1946 -0
  441. package/dist/core/hook-seats.d.ts +0 -66
  442. package/dist/core/hook-seats.js +0 -37
  443. package/dist/prompt-assembly/packs/sema-default.d.ts +0 -2
  444. package/dist/prompt-assembly/packs/sema-default.js +0 -147
  445. package/dist/prompts/simple-sections.d.ts +0 -58
  446. package/dist/prompts/simple-sections.js +0 -43
@@ -1,7 +1,7 @@
1
1
  import type { ExecutionEnv } from "../../internal/harness-types.js";
2
2
  import type { ToolEffect } from "../types.js";
3
3
  import type { NamedToolPolicy } from "../tool-policy.js";
4
- import { type SessionPermissionRules, type SessionPolicyStore, type StoredSessionRules } from "../session-policy-store.js";
4
+ import { type SessionPermissionRules, type SessionPolicyStore, type SessionRuleEntryField, type StoredSessionRules } from "../session-policy-store.js";
5
5
  import type { PathRuleBases } from "../permission-rule-model.js";
6
6
  /** The FULL path-confinable write-tool set: every catalog tool declaring a write path target — `Write` / `Edit`
7
7
  * (target `file_path`) and `NotebookEdit`, whose write target is `notebook_path` and is extracted by the shared
@@ -91,7 +91,7 @@ export interface SessionRuleSource {
91
91
  * the turn-boundary read-visibility query reuses one synthetic id for every path it screens and for every
92
92
  * turn of the run. The entry is taken ONCE, and a claimed snapshot is served only while its `rev` still
93
93
  * stands at the enforced floor; a claim from a later adjudication, whose floor has moved on, falls through
94
- * to a fresh read. A real tool call's id is minted per call and never repeats.
94
+ * to a fresh read. A real call's id is the provider's: unique within one assistant response only (`brain/tool-call-id.ts`).
95
95
  */
96
96
  export declare function createLiveSessionRules(store: SessionPolicyStore, floor: {
97
97
  sessionId: string;
@@ -112,8 +112,8 @@ export declare function createLiveSessionRules(store: SessionPolicyStore, floor:
112
112
  * - `toolAllow` (if set) → deny any call no entry admits (the matcher's allow reading in the `narrowing` posture: every
113
113
  * segment of a command line named by an entry; never the allow layer's auto-mode strip), naming the uncovered segment.
114
114
  * - an entry that reads as nothing → in no row (it guards and grants nothing; the prepare-time audit names it, or
115
- * `onEarlierGrammar`, once per distinct set, when its snapshot's own earlier grammar reads it so).
116
- * - a snapshot the shape reading refuses → deny every call, saying what it holds (never its text).
115
+ * `onEarlierGrammar(entries, bucket, grammar)`, once per distinct set, when its snapshot's own earlier grammar reads it so).
116
+ * - a snapshot that cannot be read (its shape; a `toolDeny` entry no grammar reads) → deny every call, never quoting it.
117
117
  * - `allowDirs` (if set) → a WRITE tool must land inside one of the dirs (resolved via `canonicalizeTarget`,
118
118
  * so a symlink can't carry across a write out); a write-capable tool that cannot be path-confined (e.g. `bash`)
119
119
  * is DENIED while `allowDirs` is set (fail-closed).
@@ -132,5 +132,5 @@ export declare function createSessionRulePolicy(rules: SessionPermissionRules |
132
132
  rootPath?: string;
133
133
  toolEffects?: ReadonlyMap<string, ToolEffect>;
134
134
  anchors?: PathRuleBases;
135
- onEarlierGrammar?: (entries: readonly string[]) => void;
135
+ onEarlierGrammar?: (entries: readonly string[], field: SessionRuleEntryField, grammar: number) => void;
136
136
  }): NamedToolPolicy;
@@ -1,5 +1,5 @@
1
1
  import { canonicalizeTarget, isWinFormPath, pathFamilyOf, writeTargetPath } from "../../tools/fs/safety.js";
2
- import { compileSessionRuleBucket, continuesLineage, earlierGrammarAnnouncer, readSessionRulesShape } from "../session-policy-store.js";
2
+ import { SESSION_RULES_GRAMMAR, compileSessionRuleBucket, continuesLineage, earlierGrammarAnnouncer, earlierGrammarRefusalClause, readSessionRulesShape, unreadableDenyEntries } from "../session-policy-store.js";
3
3
  import { compiledEntryName, judgeAllowEntries, uncoveredCommandSegment } from "../allow-entry.js";
4
4
  import { inlineUntrusted } from "../untrusted-text.js";
5
5
  import { callTargetReadingOf, pathTargetBaseOf, readCallTarget } from "../effective-path-target.js";
@@ -104,27 +104,30 @@ export function createLiveSessionRules(store, floor, hooks) {
104
104
  return p;
105
105
  };
106
106
  }
107
- function compileSessionRules(rules, announceEarlier) {
107
+ function compileSessionRules(rules) {
108
108
  const shaped = readSessionRulesShape(rules);
109
+ const refuseEvery = (what) => `the session rules cannot be read as rules (they hold ${what}) — every call is refused until they are rewritten`;
109
110
  if ("fault" in shaped) {
110
111
  const { field, got } = shaped.fault;
111
112
  const what = got === "not a rule bucket" ? "a key that is no rule bucket" : field === "" ? `a value that is ${got}, not an object of rule buckets` : `${field} holding ${got}`;
112
- return { deny: [], allow: undefined, allowDirs: undefined, pathRows: false, names: { deny: [], allow: [] }, unreadable: `the session rules cannot be read as rules (they hold ${what}) — every call is refused until they are rewritten` };
113
+ return { deny: [], allow: undefined, earlier: { grammar: SESSION_RULES_GRAMMAR, toolAllow: [], toolDeny: [] }, allowDirs: undefined, pathRows: false, names: { deny: [], allow: [] }, unreadable: refuseEvery(what) };
113
114
  }
114
- const { toolAllow, allowDirs } = shaped.rules;
115
+ const { toolAllow, allowDirs, grammar } = shaped.rules;
116
+ const unreadDeny = unreadableDenyEntries(shaped.rules).length;
115
117
  const denyList = compileSessionRuleBucket(shaped.rules, "toolDeny");
116
118
  const allowList = toolAllow === undefined ? undefined : compileSessionRuleBucket(shaped.rules, "toolAllow");
117
119
  const rowsOf = (behavior, list) => list.rows.map((r) => ({ behavior, entry: r.entry, compiled: r.compiled }));
118
120
  const deny = rowsOf("deny", denyList);
119
121
  const allow = allowList === undefined ? undefined : rowsOf("allow", allowList);
120
122
  const named = (list, earlier) => (list?.inert ?? []).filter((i) => (i.reason === "earlier_grammar") === earlier).map((i) => i.entry);
121
- announceEarlier(named(allowList, true));
122
123
  return {
123
124
  deny,
124
125
  allow,
126
+ earlier: { grammar, toolAllow: named(allowList, true), toolDeny: named(denyList, true) },
125
127
  allowDirs: allowDirs !== undefined && allowDirs.length > 0 ? allowDirs : undefined,
126
128
  pathRows: [...deny, ...(allow ?? [])].some((r) => r.compiled.kind === "path"),
127
129
  names: { deny: [...deny.map((r) => compiledEntryName(r.compiled)), ...named(denyList, false)], allow: [...(allow ?? []).map((r) => compiledEntryName(r.compiled)), ...named(allowList, false)] },
130
+ ...(unreadDeny > 0 ? { unreadable: refuseEvery(`${unreadDeny === 1 ? "a toolDeny entry" : `${unreadDeny} toolDeny entries`} that rule grammar ${SESSION_RULES_GRAMMAR} reads as no rule`) } : {}),
128
131
  };
129
132
  }
130
133
  export function createSessionRulePolicy(rules, opts) {
@@ -138,7 +141,9 @@ export function createSessionRulePolicy(rules, opts) {
138
141
  let compiled;
139
142
  const compile = (r) => {
140
143
  if (compiled === undefined || compiledFor !== r) {
141
- compiled = compileSessionRules(r, announceEarlier);
144
+ compiled = compileSessionRules(r);
145
+ for (const field of ["toolAllow", "toolDeny"])
146
+ announceEarlier(compiled.earlier[field], field, compiled.earlier.grammar);
142
147
  compiledFor = r;
143
148
  }
144
149
  return compiled;
@@ -147,7 +152,7 @@ export function createSessionRulePolicy(rules, opts) {
147
152
  return {
148
153
  nameSets: [{ ...(seedNames.deny.length > 0 ? { deny: seedNames.deny } : {}), ...(seedNames.allow.length > 0 ? { allow: seedNames.allow } : {}) }],
149
154
  async check(req, signal) {
150
- const { deny: denyRows, allow: allowRows, allowDirs, unreadable, pathRows } = compile(await readRules(req.toolCallId, signal));
155
+ const { deny: denyRows, allow: allowRows, earlier, allowDirs, unreadable, pathRows } = compile(await readRules(req.toolCallId, signal));
151
156
  if (unreadable !== undefined)
152
157
  return deny(req.toolName, unreadable);
153
158
  if (denyRows.length > 0 || allowRows !== undefined) {
@@ -159,7 +164,7 @@ export function createSessionRulePolicy(rules, opts) {
159
164
  return deny(req.toolName);
160
165
  if (allowRows !== undefined && judgeAllowEntries(allowRows, call, "allow", judged, "narrowing") === undefined) {
161
166
  const segment = uncoveredCommandSegment(allowRows, call, judged, "narrowing");
162
- return deny(req.toolName, segment === undefined ? "it is not in the session-rule allowlist" : `it is not in the session-rule allowlist (no entry covers ${JSON.stringify(inlineUntrusted(segment, 200))})`);
167
+ return deny(req.toolName, `it is not in the session-rule allowlist${segment === undefined ? "" : ` (no entry covers ${JSON.stringify(inlineUntrusted(segment, 200))})`}${earlierGrammarRefusalClause(earlier.toolAllow, earlier.grammar)}`);
163
168
  }
164
169
  }
165
170
  if (allowDirs) {
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The run's usage account for the model calls made BESIDE the main loop — the compaction summarizer, the permission
3
+ * classifier, a mod's `$.model.complete`: the lanes, what a reply tells the account, the one door a lane books through, and the
4
+ * ONE function behind it. The lane table says which `Stats` line keeps a lane's cost besides `costMicroUsd` (every lane folds
5
+ * into the total — it is the budget coordinate and the reported figure); it is total over the lanes by its fence, so a fourth
6
+ * lane is a row here, not a second accounting function.
7
+ */
8
+ import type { AssistantMessageDiagnostic, Model, Usage } from "../../internal/llm.js";
9
+ import { type ModelPricing } from "../pricing.js";
10
+ import type { AssertAllKeysHandled } from "../ask-origin.js";
11
+ import type { RunnerDeps, TaskSpec } from "../types.js";
12
+ import type { Stats } from "./assemble-result.js";
13
+ /** Whose model call it is: the compaction summarizer, the permission classifier, a mod's `$.model.complete`. */
14
+ export type SideCallLane = "compaction" | "classifier" | "mod";
15
+ /** The `Stats` line a lane's cost is also kept in: compaction is its own partition line; the classifier and the mods share the side-call line. */
16
+ export declare const SIDE_CALL_LANE_TOTAL: {
17
+ readonly compaction: "compactionMicroUsd";
18
+ readonly classifier: "sideCallMicroUsd";
19
+ readonly mod: "sideCallMicroUsd";
20
+ };
21
+ export type LaneTotalCoversEverySideCallLane = AssertAllKeysHandled<Exclude<SideCallLane, keyof typeof SIDE_CALL_LANE_TOTAL>>;
22
+ /** A side call's reply as the account reads it: the provider's usage (absent ⇒ none reported), the marks of what is unknown,
23
+ * and the diagnostics that say a degrading brain served it from its fallback (the model that ANSWERED is the one priced). */
24
+ export interface SideCallReply {
25
+ readonly usage?: Usage;
26
+ readonly usageMissing?: true;
27
+ readonly stopReason?: string;
28
+ readonly diagnostics?: AssistantMessageDiagnostic[];
29
+ }
30
+ /** The leg's one door onto the run's usage account: every side call's reply is booked through it, once. */
31
+ export type SideCallBook = (lane: SideCallLane, model: Model, reply: SideCallReply | undefined) => void;
32
+ /** The leg's seats a side call is priced and traced on — everything the call needs that `stats` does not carry. */
33
+ export interface SideCallAccount {
34
+ /** The run's telemetry: a call on an unpriced model taints `unpricedSpend`; the trace row goes to its tracer. */
35
+ telemetry: {
36
+ unpricedSpend: boolean;
37
+ readonly tracer: TaskSpec["tracer"];
38
+ readonly taskId: string;
39
+ };
40
+ /** The deployment's price table, read at the call (a swapped deps seat reaches legs already running). */
41
+ pricing: () => RunnerDeps["pricing"];
42
+ /** The telemetry lane's price-table door, consulted for every table a side call adopts. */
43
+ noteUnevaluablePriceTable: (p: ModelPricing) => void;
44
+ /** The deployment's model catalog: where the fallback model of a degraded reply is looked up. */
45
+ catalog: RunnerDeps["models"];
46
+ }
47
+ /** What one side call tells the account beyond its usage: the model it asked, the marks of what is unknown, and — when a
48
+ * degrading brain served the reply from another model — that model's id. */
49
+ export interface SideCallCall {
50
+ model: Model;
51
+ account: SideCallAccount;
52
+ usageMissing?: true;
53
+ stopReason?: string;
54
+ servedBy?: string;
55
+ }
56
+ /**
57
+ * THE one place a model call made beside the main loop reaches the run's account: the compaction summarizer, the
58
+ * permission classifier and a mod's `$.model.complete` all land here, each with its lane. The call is accounted exactly
59
+ * like a main-loop call (re-priced in core from the deployment's table and the model's cache family, integer
60
+ * micro-USD, never the brain's own `usage.cost`), so the reported total, the budget gate at the next turn end and the
61
+ * trace agree about what the run spent. Latency and first-token time are not modeled (there are no per-delta hooks here).
62
+ *
63
+ * `usage` absent — the reply reported none — marks the leg's stats `usageMissing` (the totals are then a lower bound:
64
+ * unknown is not free). A reply the brain itself marked `usageMissing` does the same for its zero-filled usage.
65
+ */
66
+ export declare function recordSideCallUsage(stats: Stats, usage: Usage | undefined, lane: SideCallLane, call: SideCallCall): void;
67
+ /** The leg's door: `recordSideCallUsage` bound to the leg's `stats` and account, reading what the reply itself says (its marks, and who served it). */
68
+ export declare function sideCallBookOf(stats: Stats, account: SideCallAccount): SideCallBook;
@@ -0,0 +1,61 @@
1
+ import { readDegradation } from "../../brain/degrading.js";
2
+ import { isModelPriced, modelCostToPricing } from "../pricing.js";
3
+ import { emitTrace } from "../trace.js";
4
+ import { cacheFamilyOf, usageCostMicroUsd } from "./usage-accounting.js";
5
+ export const SIDE_CALL_LANE_TOTAL = {
6
+ compaction: "compactionMicroUsd",
7
+ classifier: "sideCallMicroUsd",
8
+ mod: "sideCallMicroUsd",
9
+ };
10
+ function catalogModel(id, catalog) {
11
+ if (catalog === undefined)
12
+ return undefined;
13
+ for (const m of Object.values(catalog))
14
+ if (m.id === id)
15
+ return m;
16
+ return Object.hasOwn(catalog, id) ? catalog[id] : undefined;
17
+ }
18
+ export function recordSideCallUsage(stats, usage, lane, call) {
19
+ if (usage === undefined || call.usageMissing === true)
20
+ stats.usageMissing = true;
21
+ if (usage === undefined)
22
+ return;
23
+ const { model: requested, account } = call;
24
+ const pricing = account.pricing();
25
+ const served = call.servedBy === undefined ? requested : catalogModel(call.servedBy, account.catalog);
26
+ const modelId = served?.id ?? call.servedBy ?? requested.id;
27
+ const price = pricing?.[modelId] ?? modelCostToPricing(served?.cost);
28
+ const priced = served !== undefined ? isModelPriced(served, pricing) : pricing?.[modelId] !== undefined;
29
+ if (!priced)
30
+ account.telemetry.unpricedSpend = true;
31
+ account.noteUnevaluablePriceTable(price);
32
+ const family = served !== undefined ? cacheFamilyOf(served) : "input-excludes-cached";
33
+ const { totalInputTokens, uncachedInputTokens, costMicroUsd } = usageCostMicroUsd(family, usage, price);
34
+ stats.tokens += usage.totalTokens || 0;
35
+ stats.promptTokens += uncachedInputTokens;
36
+ stats.totalInputTokens += totalInputTokens;
37
+ stats.cachedTokens += usage.cacheRead || 0;
38
+ stats.cacheWriteTokens += usage.cacheWrite || 0;
39
+ stats.outputTokens += usage.output || 0;
40
+ stats.costMicroUsd += costMicroUsd;
41
+ const total = SIDE_CALL_LANE_TOTAL[lane];
42
+ stats[total] = (stats[total] ?? 0) + costMicroUsd;
43
+ emitTrace(account.telemetry.tracer, () => ({
44
+ kind: "brain.call", version: 1, taskId: account.telemetry.taskId, model: modelId, ...(served !== undefined ? { provider: served.provider } : {}),
45
+ promptTokens: uncachedInputTokens, totalInputTokens, completionTokens: usage.output || 0,
46
+ cacheRead: usage.cacheRead || 0, cacheWrite: usage.cacheWrite || 0,
47
+ latencyMs: 0, ...(priced ? { costMicroUsd } : {}), ...(call.stopReason !== undefined ? { stopReason: call.stopReason } : {}), ts: Date.now(),
48
+ }));
49
+ }
50
+ export function sideCallBookOf(stats, account) {
51
+ return (lane, model, reply) => {
52
+ const degradedTo = readDegradation(reply)?.to;
53
+ recordSideCallUsage(stats, reply?.usage, lane, {
54
+ model,
55
+ account,
56
+ ...(reply?.usageMissing === true ? { usageMissing: true } : {}),
57
+ ...(typeof reply?.stopReason === "string" ? { stopReason: reply.stopReason } : {}),
58
+ ...(degradedTo !== undefined && degradedTo !== model.id ? { servedBy: degradedTo } : {}),
59
+ });
60
+ };
61
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * THE reading of `TaskSpec.skills` — the one place the caller's skill objects are read. The config doors call it before any
3
+ * resource (a resume before its claim) and hand its copy on as the leg's `skills`; the disclosure block and the `Skill` tool read
4
+ * that copy through `normalizeSkills` (synthetic-tools.ts), its sorted view.
5
+ */
6
+ import type { SkillSpec } from "../agent-definition.js";
7
+ /**
8
+ * Total, and once: a value that is not a list, an entry that is not an object, a `name` / `description` / `content` that is not a
9
+ * string, or `files` that is not a list of `{ path, content }` strings refuses by name (`config.invalid_argument`, `detail.field` =
10
+ * the member's path); `baseDir` by its own reader ({@link skillBaseDirOf}, `config.skill_base_dir_invalid`). Every entry is
11
+ * screened, a later duplicate of a name included. Each field is read ONCE, BY NAME (an inherited or non-enumerable list counts;
12
+ * a rest copy would drop it). What it returns is plain data in declaration order, first of a name: every member and attachment
13
+ * copied, the two tables read ({@link readSkillTable}: a non-list is one entry that reads as nothing).
14
+ */
15
+ export declare function readSkillsSeat(skills: unknown): SkillSpec[];
@@ -0,0 +1,57 @@
1
+ import { readSkillTable } from "../skill-grant.js";
2
+ import { assertNoRetiredKeys, RETIRED_TASK_SPEC_KEYS } from "../retired-keys.js";
3
+ import { skillBaseDirOf } from "./skill-base-dir.js";
4
+ const SKILLS_SEAT = "TaskSpec.skills";
5
+ const kindOf = (v) => (v === null ? "null" : Array.isArray(v) ? "an array" : typeof v);
6
+ function skillsSeatRefusal(field, problem) {
7
+ const e = new Error(`${field} ${problem} — an entry the engine cannot read is refused rather than dropped.`);
8
+ e.code = "config.invalid_argument";
9
+ e.detail = { field };
10
+ return e;
11
+ }
12
+ function readSkillFiles(files, at) {
13
+ if (files === undefined)
14
+ return undefined;
15
+ if (!Array.isArray(files))
16
+ throw skillsSeatRefusal(at, `must be a list of { path, content } attachments (got ${kindOf(files)})`);
17
+ const out = [];
18
+ for (const [j, f] of files.entries()) {
19
+ if (typeof f !== "object" || f === null || Array.isArray(f))
20
+ throw skillsSeatRefusal(`${at}[${j}]`, `must be an attachment object { path, content } (got ${kindOf(f)})`);
21
+ const { path, content } = f;
22
+ if (typeof path !== "string")
23
+ throw skillsSeatRefusal(`${at}[${j}].path`, `must be a string (got ${kindOf(path)})`);
24
+ if (typeof content !== "string")
25
+ throw skillsSeatRefusal(`${at}[${j}].content`, `must be a string (got ${kindOf(content)})`);
26
+ out.push({ path, content });
27
+ }
28
+ return out;
29
+ }
30
+ export function readSkillsSeat(skills) {
31
+ if (skills === undefined)
32
+ return [];
33
+ if (!Array.isArray(skills))
34
+ throw skillsSeatRefusal(SKILLS_SEAT, `must be a list (got ${kindOf(skills)})`);
35
+ assertNoRetiredKeys({ skills }, RETIRED_TASK_SPEC_KEYS, "TaskSpec");
36
+ const seen = new Set();
37
+ const out = [];
38
+ for (const [i, raw] of skills.entries()) {
39
+ const at = `${SKILLS_SEAT}[${i}]`;
40
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw))
41
+ throw skillsSeatRefusal(at, `must be an object { name, description, content } (got ${kindOf(raw)})`);
42
+ const { name, description, content, allowedTools, disallowedTools, files: rawFiles, baseDir, ...rest } = raw;
43
+ void rest;
44
+ for (const [member, value] of [["name", name], ["description", description], ["content", content]]) {
45
+ if (typeof value !== "string")
46
+ throw skillsSeatRefusal(`${at}.${member}`, `must be a string (got ${kindOf(value)})`);
47
+ }
48
+ const files = readSkillFiles(rawFiles, `${at}.files`);
49
+ skillBaseDirOf(baseDir);
50
+ if (seen.has(name))
51
+ continue;
52
+ seen.add(name);
53
+ const [allowed, denied] = [readSkillTable(allowedTools), readSkillTable(disallowedTools)];
54
+ out.push({ name, description, content, ...(allowed !== undefined ? { allowedTools: allowed } : {}), ...(denied !== undefined ? { disallowedTools: denied } : {}), ...(files !== undefined ? { files } : {}), ...(baseDir !== undefined ? { baseDir } : {}) });
55
+ }
56
+ return out;
57
+ }
@@ -15,15 +15,16 @@ export function streamHaltVerbs(input) {
15
15
  throw haltRefused("the task is not running");
16
16
  const apply = () => {
17
17
  const abortOwnedBeforeHalt = h.abortController.signal.aborted;
18
- const receipt = h.harness.halt();
18
+ const receipt = h.loop.ended ? { turnCut: false, accepted: false } : h.harness.halt();
19
+ h.loop.callerStop.stop();
19
20
  if (receipt.accepted && !abortOwnedBeforeHalt) {
20
21
  h.loop.userHalted = true;
21
22
  }
22
23
  else if (!h.loop.userHalted) {
23
24
  deliverEngineNotice(runner.deps.onNotice, {
24
25
  code: "task.halt_unconsumed",
25
- message: "a user halt arrived while the run was already ending for its own reason: nothing was cut or stopped " +
26
- "by it — the run's own ending stands, and the result will not carry haltedByUser for this halt.",
26
+ message: "a user halt arrived while the run was already ending for its own reason: it cut no turn and stopped no " +
27
+ "boundary — the run's own ending stands, and the result will not carry haltedByUser for this halt.",
27
28
  detail: {
28
29
  sessionId: h.sessionId,
29
30
  runId: h.runId,
@@ -47,33 +48,27 @@ export function streamHaltVerbs(input) {
47
48
  }
48
49
  return { turnCut: receipt.turnCut };
49
50
  };
50
- try {
51
- if (live.resultValue !== undefined || h.loop.ended)
52
- throw haltRefused("the task is no longer running");
53
- return apply();
54
- }
55
- catch (e) {
56
- if (!(e instanceof Error && e.code === "invalid_state"))
57
- throw e;
58
- }
59
51
  const birthDeadline = Date.now() + READY_TIMEOUT_MS;
60
- while (live.resultValue === undefined && !h.loop.ended && Date.now() < birthDeadline) {
52
+ while (live.resultValue === undefined) {
61
53
  try {
62
54
  return apply();
63
55
  }
64
- catch (e2) {
65
- if (!(e2 instanceof Error && e2.code === "invalid_state"))
66
- throw e2;
56
+ catch (e) {
57
+ if (!(e instanceof Error && e.code === "invalid_state"))
58
+ throw e;
67
59
  }
60
+ if (Date.now() >= birthDeadline)
61
+ throw haltRefused("the task is no longer running");
68
62
  await new Promise((r) => setTimeout(r, 10));
69
63
  }
70
- throw haltRefused("the task is no longer running");
64
+ throw haltRefused("the task has already finished");
71
65
  };
72
66
  const destroy = () => (destroyOnce ??= (async () => {
73
67
  const h = live.handle ?? (await orTimeout(ready));
74
68
  if (h) {
75
69
  h.abortController.abort();
76
70
  void h.harness.abort();
71
+ h.loop.callerStop.stop();
77
72
  }
78
73
  await orTimeout(run.catch(() => { }));
79
74
  await reapSuspended();
@@ -145,12 +145,15 @@ export function streamLifecycleVerbs(input) {
145
145
  const h = live.handle ?? (await orTimeout(ready));
146
146
  if (!h)
147
147
  throw interruptRefused("the task is not running");
148
- if (live.resultValue !== undefined || h.loop.ended)
149
- throw interruptRefused("the task is no longer running");
150
- if (!h.abortController.signal.aborted)
148
+ if (live.resultValue !== undefined)
149
+ throw interruptRefused("the task has already finished");
150
+ if (!h.loop.ended && !h.abortController.signal.aborted)
151
151
  h.loop.userInterrupted = true;
152
- h.abortController.abort();
153
- void h.harness.abort();
152
+ if (!h.loop.ended) {
153
+ h.abortController.abort();
154
+ void h.harness.abort();
155
+ }
156
+ h.loop.callerStop.stop();
154
157
  };
155
158
  return { notify, optOutMemoryCapture, reconnectMcpServer, compact, detach, interrupt };
156
159
  }
@@ -3,7 +3,7 @@ import { type TaskEvent, type TaskSpec, type TaskStream } from "../types.js";
3
3
  import type { LiveHandle, RunInternals, RunnerDepsSeat, TaskStreamLiveSeat } from "./contracts.js";
4
4
  import { type SteerReplayRecord, type SteerReplayRefusalDetail } from "../steer-replay.js";
5
5
  export interface StreamSteerVerbInput {
6
- /** borrowed-readonly — the task spec (the hooks seat, `principal`, `taskId`). */
6
+ /** borrowed-readonly — the task spec (`principal`, `taskId`). */
7
7
  spec: TaskSpec;
8
8
  /** borrowed-readonly — the trusted run-internals channel (the spawning tool id the ledger frame carries). */
9
9
  internals: RunInternals | undefined;
@@ -1,14 +1,14 @@
1
1
  import { uuidv7 } from "../../internal/harness.js";
2
2
  import { snapshotActorAssertion } from "../../internal/llm.js";
3
3
  import { MAX_STEER_INPUT_ID_CHARS } from "../checkpoint-store.js";
4
- import { formatHookFeedback, hookSeatExpiredError, runHookSeat } from "../hooks.js";
4
+ import { formatHookFeedback } from "../hooks.js";
5
+ import { classicEventBase, failedHandlerClause, screenUserPrompt } from "../mods/stations.js";
5
6
  import { buildHumanInputEvent, frameMidTurnUserInput, projectHumanInput } from "../human-input-projection.js";
6
7
  import { injectionLaneOf, isSystemInjectionPriority, steerPriorityOf, SYSTEM_INJECTION_PRIORITIES } from "../task-notification.js";
7
8
  import { deliverEngineNotice } from "../types.js";
8
9
  import { inlineUntrusted, sanitizeUntrustedText } from "../untrusted-text.js";
9
10
  import { announceAcceptance, armAcceptance, nextHumanInputSeq } from "./steer-admission.js";
10
11
  import { steerReplayRefusal } from "../steer-replay.js";
11
- import { asThrownError } from "../thrown-value.js";
12
12
  export function streamSteerVerb(input) {
13
13
  const { spec, internals, queue, acceptedSteerInputs, live, ready, orTimeout, readyTimeoutMs: READY_TIMEOUT_MS, steeringError, runner } = input;
14
14
  let steerChain = Promise.resolve();
@@ -94,42 +94,24 @@ export function streamSteerVerb(input) {
94
94
  if (live.resultValue !== undefined || h.loop.ended)
95
95
  throw steeringError("the task is no longer running");
96
96
  if (mintsAFrame) {
97
- const screen = (spec.hooks ?? runner.deps.hooks)?.userPromptSubmit;
98
- if (screen !== undefined) {
99
- let decision;
100
- try {
101
- const seat = await runHookSeat("userPromptSubmit", { timeoutMs: h.hookTimeoutMs, signal: h.abortController.signal, abortEnds: true }, (sig) => screen(text, { identity: h.hookIdentity, permissionMode: h.permissionMode.observed, signal: sig, source: "steer", inputId: effectiveInputId, ...(actor !== undefined ? { actor: snapshotActorAssertion(actor) } : {}) }));
102
- if (seat.expired) {
103
- if (seat.cause === "timeout") {
104
- try {
105
- runner.deps.onError?.(hookSeatExpiredError("userPromptSubmit", h.hookTimeoutMs, seat.cause, "the steering input was NOT accepted (fail-closed) and the caller was refused typed"), { phase: "hook", sessionId: h.sessionId });
106
- }
107
- catch {
108
- }
109
- }
110
- throw steeringError(seat.cause === "timeout"
111
- ? `the deployment's userPromptSubmit hook did not answer within its ${h.hookTimeoutMs}ms bound while screening this steering input; the input was NOT accepted (fail-closed)`
112
- : `the task was cancelled while the deployment's userPromptSubmit hook was still screening this steering input; the input was NOT accepted (fail-closed)`, "steering.blocked_by_hook");
113
- }
114
- decision = seat.value;
115
- }
116
- catch (hookErr) {
117
- if (hookErr instanceof Error && hookErr.code === "steering.blocked_by_hook")
118
- throw hookErr;
119
- const err = asThrownError(hookErr);
120
- try {
121
- runner.deps.onError?.(err, { phase: "hook", sessionId: h.sessionId });
122
- }
123
- catch {
124
- }
125
- throw steeringError(`the deployment's userPromptSubmit hook crashed while screening this steering input (${inlineUntrusted(err.message)}); the input was NOT accepted (fail-closed)`, "steering.blocked_by_hook");
126
- }
127
- if (decision?.block !== undefined && decision.block !== "") {
128
- throw steeringError(`the deployment's userPromptSubmit hook blocked this steering input: ${inlineUntrusted(decision.block)}`, "steering.blocked_by_hook");
129
- }
130
- if (decision?.additionalContext !== undefined && decision.additionalContext !== "") {
131
- payload = `${formatHookFeedback(decision.additionalContext, h.reminderMark)}\n\n${payload}`;
132
- }
97
+ const screen = await screenUserPrompt(h.modBus, {
98
+ ...classicEventBase(h.hookIdentity, h.permissionMode.observed),
99
+ prompt: text,
100
+ source: "steer",
101
+ inputId: effectiveInputId,
102
+ ...(actor !== undefined ? { actor: snapshotActorAssertion(actor) } : {}),
103
+ }, h.abortController.signal);
104
+ if (screen?.kind === "aborted") {
105
+ throw steeringError(`the task was cancelled while the deployment's userPromptSubmit hook was still screening this steering input; the input was NOT accepted (fail-closed)`, "steering.blocked_by_hook");
106
+ }
107
+ if (screen?.kind === "failed") {
108
+ throw steeringError(`the deployment's userPromptSubmit hook ${failedHandlerClause(screen)} while screening this steering input; the input was NOT accepted (fail-closed)`, "steering.blocked_by_hook");
109
+ }
110
+ if (screen?.block !== undefined && screen.block !== "") {
111
+ throw steeringError(`the deployment's userPromptSubmit hook blocked this steering input: ${inlineUntrusted(screen.block)}`, "steering.blocked_by_hook");
112
+ }
113
+ if (screen?.additionalContext !== undefined && screen.additionalContext !== "") {
114
+ payload = `${formatHookFeedback(screen.additionalContext, h.reminderMark)}\n\n${payload}`;
133
115
  }
134
116
  }
135
117
  const injectFramed = async () => {