@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
@@ -0,0 +1,339 @@
1
+ import { types } from "node:util";
2
+ import { describeFault, isPlainRecord, receive } from "../core/mods/kernel/receive.js";
3
+ import { egressText } from "../core/untrusted-egress.js";
4
+ import { bandOf, isBandId } from "./bands.js";
5
+ import { SEMA_DEFAULT_CATALOG, catalogMessage } from "./catalog/index.js";
6
+ import { HOST_FORMS, HOST_ROLES, OVERLAY_OPS, PROMPT_FACT_NAMES, PROMPT_TRAITS, isWordOf, } from "./catalog/schema.js";
7
+ import { RENDERERS } from "./renderers.js";
8
+ import { canonicalWhen } from "./select.js";
9
+ export const OVERLAY_SOURCE_ORDER = Object.freeze(["bundled", "task", "center", "deploy"]);
10
+ export const ABSENT_THIS_RUN = "(absent this run)";
11
+ const SECTION_BY_ID = new Map(SEMA_DEFAULT_CATALOG.sections.map((s) => [s.id, s]));
12
+ const MESSAGE_TARGETS = (() => {
13
+ const m = new Map();
14
+ for (const s of SEMA_DEFAULT_CATALOG.sections) {
15
+ const ids = "message" in s.body ? [s.body.message] : "lines" in s.body ? s.body.lines.map((l) => l.message) : (RENDERERS[s.body.renderer].messages ?? []);
16
+ for (const id of ids)
17
+ m.set(id, { section: s });
18
+ }
19
+ return m;
20
+ })();
21
+ const MESSAGE_IDS = new Set(SEMA_DEFAULT_CATALOG.messages.map((m) => m.id));
22
+ export function sectionOfMessage(id) {
23
+ return MESSAGE_TARGETS.get(id)?.section;
24
+ }
25
+ const LOCKED = Object.freeze(SEMA_DEFAULT_CATALOG.sections
26
+ .filter((s) => s.band === "constitution" && !("renderer" in s.body))
27
+ .flatMap((s) => ("message" in s.body ? [s.body.message] : "lines" in s.body ? s.body.lines.map((l) => l.message) : []))
28
+ .flatMap((id) => catalogMessage(id).variants.map((v) => Object.freeze({ message: id, variant: v.id, text: v.text }))));
29
+ export function lockedEntries() {
30
+ return LOCKED;
31
+ }
32
+ export function lockedTextIn(text) {
33
+ const hits = [];
34
+ for (const e of LOCKED)
35
+ if (text.includes(e.text))
36
+ hits.push(`${e.message}#${e.variant}`);
37
+ return hits;
38
+ }
39
+ export function assembledRoleRefused(field, hits) {
40
+ const named = [...new Set(hits.map((h) => h.split("#")[0]))];
41
+ return Object.assign(new Error(`prompt.assembled_role_refused: ${field} contains, verbatim, the locked text of ${named.slice(0, 4).join(", ")}${named.length > 4 ? ` and ${named.length - 4} more` : ""} — the engine composes the locked sections itself; supply only the role layer (an already-assembled prompt is refused, never passed through)`), { code: "prompt.assembled_role_refused" });
42
+ }
43
+ const ID_GRAMMAR = /^[a-z0-9][a-z0-9/._-]*$/;
44
+ const OVERLAY_KEYS = new Set(["id", "op", "target", "text", "message", "when"]);
45
+ const OPS = new Set(OVERLAY_OPS);
46
+ const PROMPT_DATA = Object.freeze({ accessors: "refuse", depth: 4, others: "refuse", freeze: true, isProxy: (v) => types.isProxy(v) });
47
+ export function receivePromptData(raw) {
48
+ const r = receive(raw, PROMPT_DATA);
49
+ return r.ok ? { value: r.value } : { notData: describeFault(r.fault) };
50
+ }
51
+ export const PROMPT_BINDING_MAX_CHARS = 128;
52
+ export const PROMPT_BINDING_LIST_MAX = 64;
53
+ export function codePointsOver(s, max) {
54
+ if (s.length <= max)
55
+ return false;
56
+ if (s.length > 2 * max)
57
+ return true;
58
+ let n = 0;
59
+ for (const _ of s)
60
+ if (++n > max)
61
+ return true;
62
+ return false;
63
+ }
64
+ function bindingProblem(v) {
65
+ return typeof v !== "string" || v.trim() === "" || codePointsOver(v, PROMPT_BINDING_MAX_CHARS) ? `${str(v)} is not a non-blank string of at most ${PROMPT_BINDING_MAX_CHARS} characters (code points)` : undefined;
66
+ }
67
+ function bindingConditionProblem(b) {
68
+ if (!isPlainRecord(b))
69
+ return `"when.binding" is ${Array.isArray(b) ? "an array" : str(b)}, not { anyOf: [...] } or { noneOf: [...] }`;
70
+ const keys = Object.keys(b);
71
+ const k = keys[0];
72
+ if (keys.length !== 1 || (k !== "anyOf" && k !== "noneOf"))
73
+ return `"when.binding" carries ${keys.length === 0 ? "no list" : keys.map((x) => str(x)).join(", ")} (exactly one of anyOf, noneOf)`;
74
+ const list = b[k];
75
+ if (!Array.isArray(list) || list.length === 0)
76
+ return `"when.binding.${k}" is ${Array.isArray(list) ? "empty" : str(list)}, not a list naming at least one binding`;
77
+ if (list.length > PROMPT_BINDING_LIST_MAX)
78
+ return `"when.binding.${k}" names ${list.length} bindings (at most ${PROMPT_BINDING_LIST_MAX})`;
79
+ for (const name of list) {
80
+ const why = bindingProblem(name);
81
+ if (why !== undefined)
82
+ return `"when.binding.${k}": ${why}`;
83
+ }
84
+ if (new Set(list).size !== list.length)
85
+ return `"when.binding.${k}" names a binding twice`;
86
+ return undefined;
87
+ }
88
+ export function resolvePromptBinding(task) {
89
+ if (task.promptBinding === undefined)
90
+ return undefined;
91
+ const why = bindingProblem(task.promptBinding);
92
+ if (why !== undefined)
93
+ throw Object.assign(new Error(`TaskSpec.promptBinding ${why} (or absent)`), { code: "config.prompt_selector_invalid" });
94
+ return task.promptBinding;
95
+ }
96
+ function str(v, max = 160) {
97
+ if (typeof v !== "string")
98
+ return typeof v;
99
+ const e = egressText("same-principal", v);
100
+ return JSON.stringify(e.length > max ? `${e.slice(0, max)}…` : e);
101
+ }
102
+ function whenViolation(when) {
103
+ if (typeof when !== "object" || when === null || Array.isArray(when))
104
+ return `"when" is ${str(when)}, not an object`;
105
+ for (const k of Object.keys(when))
106
+ if (k !== "traits" && k !== "host" && k !== "facts" && k !== "binding")
107
+ return `"when" carries ${str(k)} (traits, host, facts, binding only)`;
108
+ const w = when;
109
+ if (w["traits"] !== undefined) {
110
+ const t = w["traits"];
111
+ if (typeof t !== "object" || t === null || Array.isArray(t))
112
+ return `"when.traits" is not an object`;
113
+ for (const [k, list] of Object.entries(t)) {
114
+ if (k !== "allOf" && k !== "noneOf")
115
+ return `"when.traits" carries ${str(k)} (allOf, noneOf only)`;
116
+ if (!Array.isArray(list))
117
+ return `"when.traits.${k}" is not an array`;
118
+ for (const name of list)
119
+ if (!isWordOf(PROMPT_TRAITS, name))
120
+ return `"when.traits.${k}" names ${str(name)}, not a trait (${PROMPT_TRAITS.join(", ")})`;
121
+ }
122
+ }
123
+ if (w["host"] !== undefined) {
124
+ const h = w["host"];
125
+ if (typeof h !== "object" || h === null || Array.isArray(h))
126
+ return `"when.host" is not an object`;
127
+ for (const [k, v] of Object.entries(h)) {
128
+ if (k === "role" ? !isWordOf(HOST_ROLES, v) : k === "form" ? !isWordOf(HOST_FORMS, v) : true) {
129
+ return `"when.host" carries ${str(k)} = ${str(v)} (role: ${HOST_ROLES.join(" | ")}; form: ${HOST_FORMS.join(" | ")})`;
130
+ }
131
+ }
132
+ }
133
+ if (w["facts"] !== undefined) {
134
+ const f = w["facts"];
135
+ if (typeof f !== "object" || f === null || Array.isArray(f))
136
+ return `"when.facts" is not an object`;
137
+ for (const [k, v] of Object.entries(f)) {
138
+ if (!isWordOf(PROMPT_FACT_NAMES, k))
139
+ return `"when.facts" names ${str(k)}, not a fact`;
140
+ if (typeof v !== "boolean")
141
+ return `"when.facts.${k}" is ${str(v)}, not a boolean`;
142
+ }
143
+ }
144
+ if (w["binding"] !== undefined)
145
+ return bindingConditionProblem(w["binding"]);
146
+ return undefined;
147
+ }
148
+ function textsOf(o) {
149
+ if (o.text !== undefined)
150
+ return [o.text];
151
+ if (o.message !== undefined && MESSAGE_IDS.has(o.message))
152
+ return catalogMessage(o.message).variants.map((v) => v.text);
153
+ return [];
154
+ }
155
+ export function validateOverlay(raw, ctx) {
156
+ const fail = (why) => ({ violation: why });
157
+ const received = receivePromptData(raw);
158
+ if ("notData" in received)
159
+ return fail(`an overlay is data (plain objects, arrays, strings, booleans); it holds ${received.notData}`);
160
+ const r = received.value;
161
+ if (!isPlainRecord(r))
162
+ return fail(`an overlay is an object, got ${Array.isArray(r) ? "an array" : str(r)}`);
163
+ for (const k of Object.keys(r)) {
164
+ if (OVERLAY_KEYS.has(k))
165
+ continue;
166
+ const rewrite = k === "scope" ? `; an overlay names its binding as "when": { "binding": { "anyOf": [<binding>] } }` : "";
167
+ return fail(`an overlay carries ${str(k)} (id, op, target, text, message, when only)${rewrite}`);
168
+ }
169
+ const { id, op, target, text, message, when } = r;
170
+ if (typeof id !== "string" || id.length === 0 || codePointsOver(id, 128) || !ID_GRAMMAR.test(id))
171
+ return fail(`overlay id ${str(id)} is not ^[a-z0-9][a-z0-9/._-]*$ of at most 128 characters`);
172
+ if (id.startsWith("core/") && ctx.sugar !== true)
173
+ return fail(`overlay id ${str(id)}: the core/ namespace is the engine's own`);
174
+ if (typeof op !== "string" || !OPS.has(op))
175
+ return fail(`overlay "${id}": op ${str(op)} is not one of ${OVERLAY_OPS.join(", ")}`);
176
+ if (typeof target !== "string" || target.length === 0)
177
+ return fail(`overlay "${id}": target ${str(target)} is not an id`);
178
+ const carries = op !== "drop";
179
+ if (!carries && (text !== undefined || message !== undefined))
180
+ return fail(`overlay "${id}": a drop carries no text or message`);
181
+ if (carries && (text === undefined) === (message === undefined))
182
+ return fail(`overlay "${id}": a ${op} carries exactly one of text, message`);
183
+ if (text !== undefined && (typeof text !== "string" || text.trim() === ""))
184
+ return fail(`overlay "${id}": text is ${typeof text === "string" ? "blank" : str(text)}`);
185
+ if (message !== undefined && (typeof message !== "string" || !MESSAGE_IDS.has(message)))
186
+ return fail(`overlay "${id}": message ${str(message)} is not a catalog message`);
187
+ if (when !== undefined) {
188
+ const why = whenViolation(when);
189
+ if (why !== undefined)
190
+ return fail(`overlay "${id}": ${why}`);
191
+ }
192
+ let band;
193
+ let where;
194
+ if (op === "add") {
195
+ if (!isBandId(target))
196
+ return fail(`overlay "${id}": an add targets a band; ${str(target)} is not one`);
197
+ if (bandOf(target).addRank === undefined)
198
+ return fail(`overlay "${id}": band "${target}" takes no additions`);
199
+ if (SECTION_BY_ID.has(id) || MESSAGE_IDS.has(id))
200
+ return fail(`overlay "${id}": an added entry cannot take a catalog id`);
201
+ band = target;
202
+ where = `band "${target}"`;
203
+ }
204
+ else if (op === "drop") {
205
+ const section = SECTION_BY_ID.get(target);
206
+ const added = ctx.lowerAdds?.get(target);
207
+ if (section !== undefined)
208
+ band = section.band;
209
+ else if (added !== undefined)
210
+ band = added;
211
+ else
212
+ return fail(`overlay "${id}": drop target ${str(target)} is neither a catalog section nor an entry a lower source added`);
213
+ where = `"${target}" (band "${band}")`;
214
+ }
215
+ else {
216
+ const placed = MESSAGE_TARGETS.get(target);
217
+ if (placed === undefined)
218
+ return fail(`overlay "${id}": ${op} target ${str(target)} is not a message the catalog places`);
219
+ band = placed.section.band;
220
+ where = `"${target}" (band "${band}")`;
221
+ }
222
+ const row = bandOf(band);
223
+ if (!row.ops[ctx.source].includes(op)) {
224
+ return fail(`overlay "${id}": a ${ctx.source} overlay may not ${op} ${where} (the band grants ${ctx.source} ${row.ops[ctx.source].length > 0 ? row.ops[ctx.source].join(", ") : "nothing"})`);
225
+ }
226
+ if (ctx.event !== undefined && row.modsEvent !== ctx.event)
227
+ return fail(`overlay "${id}": ${where} is written through ${row.modsEvent ?? "no mods event"}, not ${ctx.event}`);
228
+ const normalWhen = canonicalWhen(when);
229
+ const overlay = Object.freeze({
230
+ id,
231
+ op: op,
232
+ target,
233
+ ...(text !== undefined ? { text: text } : {}),
234
+ ...(message !== undefined ? { message: message } : {}),
235
+ ...(normalWhen !== undefined ? { when: normalWhen } : {}),
236
+ });
237
+ for (const t of textsOf(overlay)) {
238
+ const hits = lockedTextIn(t);
239
+ if (hits.length > 0)
240
+ return fail(`overlay "${id}": its text contains, verbatim, the locked text of ${[...new Set(hits.map((h) => h.split("#")[0]))].join(", ")}`);
241
+ }
242
+ return { overlay };
243
+ }
244
+ export function foldOverlays(ordered, selectedText, applies, overlayText) {
245
+ const messageText = new Map();
246
+ const writers = new Map();
247
+ const dropped = new Map();
248
+ const added = new Map();
249
+ const addedBy = new Map();
250
+ const addCount = new Map();
251
+ const superseded = [];
252
+ const chains = new Map();
253
+ const supersede = (w, target, by) => {
254
+ superseded.push(Object.freeze({ id: w.id, source: w.origin.source, by: w.origin.by, target, supersededBy: by }));
255
+ if (w.link !== undefined)
256
+ w.link.superseded = true;
257
+ };
258
+ const applied = (key, o, origin) => {
259
+ const link = { source: origin.source, overlay: o.id, op: o.op };
260
+ chains.set(key, [...(chains.get(key) ?? []), link]);
261
+ return { id: o.id, origin, link };
262
+ };
263
+ const sectionMessages = (sectionId) => [...MESSAGE_TARGETS.entries()].filter(([, t]) => t.section.id === sectionId).map(([m]) => m);
264
+ for (const { overlay: o, origin } of ordered) {
265
+ if (!applies(o))
266
+ continue;
267
+ const me = { id: o.id, origin };
268
+ const text = o.op === "drop" ? "" : overlayText(o);
269
+ if (text === undefined) {
270
+ supersede(me, o.target, ABSENT_THIS_RUN);
271
+ continue;
272
+ }
273
+ if (o.op === "add") {
274
+ const prior = addedBy.get(o.id);
275
+ if (prior !== undefined)
276
+ supersede(prior, o.target, o.id);
277
+ const band = o.target;
278
+ const k = addCount.get(band) ?? 0;
279
+ addCount.set(band, k + 1);
280
+ added.set(o.id, Object.freeze({ id: o.id, band, rank: bandOf(band).addRank + k * 0.001, text, origin }));
281
+ addedBy.set(o.id, applied(o.id, o, origin));
282
+ continue;
283
+ }
284
+ if (o.op === "drop") {
285
+ const entry = addedBy.get(o.target);
286
+ if (entry !== undefined) {
287
+ supersede(entry, o.target, o.id);
288
+ added.delete(o.target);
289
+ addedBy.delete(o.target);
290
+ continue;
291
+ }
292
+ if (!SECTION_BY_ID.has(o.target)) {
293
+ supersede(me, o.target, ABSENT_THIS_RUN);
294
+ continue;
295
+ }
296
+ for (const m of sectionMessages(o.target)) {
297
+ for (const w of writers.get(m) ?? [])
298
+ supersede(w, m, o.id);
299
+ writers.delete(m);
300
+ messageText.delete(m);
301
+ }
302
+ dropped.set(o.target, applied(o.target, o, origin));
303
+ continue;
304
+ }
305
+ const section = MESSAGE_TARGETS.get(o.target).section;
306
+ const drop = dropped.get(section.id);
307
+ if (o.op === "append" && drop !== undefined) {
308
+ supersede(me, o.target, drop.id);
309
+ continue;
310
+ }
311
+ if (selectedText(o.target) === undefined && !messageText.has(o.target)) {
312
+ supersede(me, o.target, ABSENT_THIS_RUN);
313
+ continue;
314
+ }
315
+ if (drop !== undefined) {
316
+ supersede(drop, section.id, o.id);
317
+ dropped.delete(section.id);
318
+ }
319
+ const writer = applied(section.id, o, origin);
320
+ if (o.op === "replace") {
321
+ for (const w of writers.get(o.target) ?? [])
322
+ supersede(w, o.target, o.id);
323
+ writers.set(o.target, [writer]);
324
+ messageText.set(o.target, { text, origin, replaced: true });
325
+ }
326
+ else {
327
+ const base = messageText.get(o.target)?.text ?? selectedText(o.target);
328
+ writers.set(o.target, [...(writers.get(o.target) ?? []), writer]);
329
+ messageText.set(o.target, { text: `${base}\n\n${text}`, origin, replaced: messageText.get(o.target)?.replaced ?? false });
330
+ }
331
+ }
332
+ return {
333
+ messageText,
334
+ dropped: new Set(dropped.keys()),
335
+ added: [...added.values()],
336
+ superseded,
337
+ chains: new Map([...chains].map(([k, links]) => [k, Object.freeze(links.map((l) => Object.freeze({ ...l })))])),
338
+ };
339
+ }
@@ -0,0 +1,21 @@
1
+ import type { RendererId } from "./catalog/schema.js";
2
+ import { type PromptSelectors } from "./select.js";
3
+ import type { SectionRenderInputs } from "./types.js";
4
+ export interface RendererSpec {
5
+ readonly id: RendererId;
6
+ readonly version: number;
7
+ readonly stability: "static" | "session" | "leg";
8
+ readonly reads: "inputs" | "facts" | "env" | "memory" | "mcp" | "mark" | "selectors";
9
+ readonly external: boolean;
10
+ /** The catalog messages this renderer's output is (an overlay targets them). */
11
+ readonly messages?: readonly string[];
12
+ }
13
+ export declare const RENDERERS: Readonly<Record<RendererId, RendererSpec>>;
14
+ /** The renderer version vector — the identity's renderer element (a changed output bumps a version). */
15
+ export declare function rendererVector(): Readonly<Record<RendererId, number>>;
16
+ /** One renderer's output for these inputs (and the variant it rendered, when it rendered a catalog message);
17
+ * undefined ⇒ the section is absent this run. */
18
+ export declare function runRenderer(id: RendererId, inputs: SectionRenderInputs, selectors: PromptSelectors): {
19
+ readonly text: string;
20
+ readonly variant?: string;
21
+ } | undefined;
@@ -0,0 +1,39 @@
1
+ import { reminderMarkDeclaration } from "../core/reminder-mint.js";
2
+ import { renderCoworkBase } from "../prompts/cowork.js";
3
+ import { catalogMessage } from "./catalog/index.js";
4
+ import { selectVariant } from "./select.js";
5
+ export const RENDERERS = {
6
+ "role-base": { id: "role-base", version: 2, stability: "session", reads: "selectors", external: false, messages: ["core/role.base"] },
7
+ "model-guidance": { id: "model-guidance", version: 1, stability: "session", reads: "inputs", external: false },
8
+ "mcp-instructions": { id: "mcp-instructions", version: 1, stability: "session", reads: "mcp", external: true },
9
+ "reminder-mark": { id: "reminder-mark", version: 1, stability: "session", reads: "mark", external: false },
10
+ environment: { id: "environment", version: 2, stability: "leg", reads: "env", external: false },
11
+ memory: { id: "memory", version: 1, stability: "leg", reads: "memory", external: false },
12
+ };
13
+ export function rendererVector() {
14
+ return Object.fromEntries(Object.values(RENDERERS).map((r) => [r.id, r.version]));
15
+ }
16
+ export function runRenderer(id, inputs, selectors) {
17
+ const plain = (text) => (text === undefined ? undefined : { text });
18
+ switch (id) {
19
+ case "role-base": {
20
+ const v = selectVariant(catalogMessage("core/role.base"), selectors);
21
+ if (v === undefined)
22
+ return undefined;
23
+ if (v.id !== "cowork")
24
+ return { text: v.text, variant: v.id };
25
+ const sections = renderCoworkBase({ tools: inputs.toolNames ?? [], workspaceFolder: inputs.workspaceFolder });
26
+ return sections.length === 0 ? undefined : { text: sections.map((s) => s.text).join("\n\n"), variant: v.id };
27
+ }
28
+ case "model-guidance":
29
+ return plain(inputs.modelGuidance);
30
+ case "mcp-instructions":
31
+ return plain(inputs.mcpInstructionsBlock);
32
+ case "reminder-mark":
33
+ return plain(inputs.facts.reminderMark !== undefined ? reminderMarkDeclaration(inputs.facts.reminderMark) : undefined);
34
+ case "environment":
35
+ return plain(inputs.environmentBlock);
36
+ case "memory":
37
+ return plain(inputs.memoryBlock);
38
+ }
39
+ }
@@ -4,8 +4,8 @@ export interface ContextUsageSection {
4
4
  id: string;
5
5
  /** The section's ESTIMATED token weight (see {@link contextUsageSections} for what that promises). */
6
6
  tokens: number;
7
- /** The section's semantic slot (`identity`, `security`, …), so a view can group without knowing every
8
- * id. Absent only if the manifest entry carried no slot. */
7
+ /** The section's band (`role`, `constitution`, `core-behavior`, …), so a view can group without knowing
8
+ * every id. Absent only if the manifest entry carried no band. */
9
9
  kind?: string;
10
10
  }
11
11
  /**
@@ -21,6 +21,6 @@ export interface ContextUsageSection {
21
21
  */
22
22
  export declare function contextUsageSections(sections: ReadonlyArray<{
23
23
  id: string;
24
- slot?: string;
24
+ band?: string;
25
25
  chars: number;
26
26
  }> | undefined): ContextUsageSection[] | undefined;
@@ -5,6 +5,6 @@ export function contextUsageSections(sections) {
5
5
  return sections.map((s) => ({
6
6
  id: s.id,
7
7
  tokens: Math.ceil(s.chars / DEFAULT_CHARS_PER_TOKEN),
8
- ...(s.slot !== undefined ? { kind: s.slot } : {}),
8
+ ...(s.band !== undefined ? { kind: s.band } : {}),
9
9
  }));
10
10
  }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The selector: the one reading that picks, for a catalog message, the variant a run receives — and decides
3
+ * whether an overlay's `when` applies to this run (every source class alike). Four dimensions, each with exactly one
4
+ * writer, so no value ever needs a precedence order:
5
+ *
6
+ * - `traits` — derived from the run's two prompt-shape axes by {@link promptTraitsOf} (the prompt profile and the
7
+ * fable-family model); catalog data reads traits, never the axes.
8
+ * - `host` — `role` (which role base the run is assembled for; `TaskSpec.promptRole`, absent ⇒ `general`) and
9
+ * `form` (`TaskSpec.promptForm`, which every engine-built child receives through the parent spec seat; absent ⇒
10
+ * `standard`).
11
+ * - `facts` — the runtime facts prepare produces (one derived: `executionEnvironmentDeclared`).
12
+ * - `binding` — the deployment's scenario name (`TaskSpec.promptBinding`, an open vocabulary; absent ⇒ none).
13
+ *
14
+ * A `when` is a conjunction: every listed trait present, every `noneOf` trait absent, every host key equal, every
15
+ * fact equal, the binding inside its `anyOf` (or outside its `noneOf`). No disjunction across dimensions.
16
+ */
17
+ import type { PromptManifestSelectors } from "../core/trace.js";
18
+ import { type CatalogMessage, type FactConjunction, type HostForm, type HostRole, type PromptFactName, type PromptTrait, type Variant, type VariantWhen } from "./catalog/schema.js";
19
+ import type { PromptRuntimeFacts } from "./types.js";
20
+ /** The run's selector values, resolved once per assembly. */
21
+ export interface PromptSelectors {
22
+ readonly traits: ReadonlySet<PromptTrait>;
23
+ readonly host: {
24
+ readonly role: HostRole;
25
+ readonly form: HostForm;
26
+ };
27
+ readonly facts: Readonly<Record<PromptFactName, boolean>>;
28
+ readonly binding?: string;
29
+ }
30
+ /**
31
+ * The run's prompt traits, derived from the two prompt-shape axes the engine resolves today: the simple
32
+ * profile is `lean_prompt`, a fable-family model is `fable_5_mitigations`. This is the only place those
33
+ * axes become traits.
34
+ */
35
+ export declare function promptTraitsOf(facts: Pick<PromptRuntimeFacts, "promptProfile" | "fableMitigations">): ReadonlySet<PromptTrait>;
36
+ /** The predicate facts a condition may test; optional runtime facts read as false when absent. */
37
+ export declare function catalogFactsOf(facts: PromptRuntimeFacts): Readonly<Record<PromptFactName, boolean>>;
38
+ /**
39
+ * The host selector's two values as their one writer gave them: the task (`TaskSpec.promptRole` /
40
+ * `TaskSpec.promptForm`; an engine-built child's spec carries its parent's form through the parent spec seat).
41
+ * A value outside the closed set is refused by name (`config.prompt_selector_invalid`), never read as the default.
42
+ */
43
+ export declare function resolveHost(task: {
44
+ readonly promptRole?: unknown;
45
+ readonly promptForm?: unknown;
46
+ }): {
47
+ readonly role?: HostRole;
48
+ readonly form?: HostForm;
49
+ };
50
+ /** The run's selectors — their one mint: traits and facts from the runtime facts, the host from its two writers' values,
51
+ * the binding as the task's door validated it. */
52
+ export declare function selectorsOf(facts: PromptRuntimeFacts, host?: {
53
+ readonly role?: HostRole;
54
+ readonly form?: HostForm;
55
+ }, binding?: string): PromptSelectors;
56
+ /** The selectors' plain form (traits sorted): what the manifest shows, the identity's `binding` element digests and the
57
+ * `prompt.compose` event carries — one record. */
58
+ export declare function selectorRecordOf(s: PromptSelectors): PromptManifestSelectors;
59
+ export declare function factsHold(conj: FactConjunction | undefined, facts: Readonly<Record<PromptFactName, boolean>>): boolean;
60
+ /** Whether a `when` holds under the run's selectors. */
61
+ export declare function whenHolds(when: VariantWhen | undefined, s: PromptSelectors): boolean;
62
+ /**
63
+ * A `when` in its normal form — the one spelling of what it asks: every list sorted and without repeats, a conjunct that
64
+ * asks nothing (an empty `traits`, `host` or `facts`, an empty list) left out, and a condition left with no conjunct
65
+ * (`{}`) is no condition at all (`undefined`). Two conditions that hold in the same runs by construction are equal as
66
+ * values here, so the overlay door (`validateOverlay`) hands every reader — the artifact digest, the publish-side
67
+ * conflict check — the same condition. Idempotent; it never changes which runs a condition holds for.
68
+ */
69
+ export declare function canonicalWhen(when: VariantWhen | undefined): VariantWhen | undefined;
70
+ /** The variant this run receives, or undefined when no variant's `when` holds (the message is absent). */
71
+ export declare function selectVariant(message: CatalogMessage, s: PromptSelectors): Variant | undefined;
@@ -0,0 +1,106 @@
1
+ import { HOST_ROLES, isWordOf } from "./catalog/schema.js";
2
+ export function promptTraitsOf(facts) {
3
+ const traits = new Set();
4
+ if (facts.promptProfile !== "classic")
5
+ traits.add("lean_prompt");
6
+ if (facts.fableMitigations === true)
7
+ traits.add("fable_5_mitigations");
8
+ return traits;
9
+ }
10
+ export function catalogFactsOf(facts) {
11
+ return {
12
+ policyEnabled: facts.policyEnabled,
13
+ hooksEnabled: facts.hooksEnabled,
14
+ isolationEnabled: facts.isolationEnabled,
15
+ readFaceOpen: facts.readFaceOpen === true,
16
+ writeFaceOpen: facts.writeFaceOpen === true,
17
+ withinTaskCompactionEnabled: facts.withinTaskCompactionEnabled,
18
+ supervisorEnabled: facts.supervisorEnabled,
19
+ orchestrationEnabled: facts.orchestrationEnabled,
20
+ orchestrationDeferred: facts.orchestrationDeferred === true,
21
+ awarenessEnabled: facts.awarenessEnabled,
22
+ goalEnabled: facts.goalEnabled,
23
+ worktreeIsolated: facts.worktreeIsolated,
24
+ teammateEnabled: facts.teammateEnabled,
25
+ isSubagent: facts.isSubagent === true,
26
+ executionEnvironmentDeclared: facts.policyEnabled || facts.isolationEnabled,
27
+ };
28
+ }
29
+ export function resolveHost(task) {
30
+ const refuse = (key, value, allowed) => {
31
+ throw Object.assign(new Error(`TaskSpec.${key} is ${typeof value === "string" ? JSON.stringify(value.slice(0, 64)) : typeof value}; it is one of ${allowed.map((a) => `"${a}"`).join(", ")} (or absent)`), {
32
+ code: "config.prompt_selector_invalid",
33
+ });
34
+ };
35
+ const role = task.promptRole === undefined ? undefined : isWordOf(HOST_ROLES, task.promptRole) ? task.promptRole : refuse("promptRole", task.promptRole, HOST_ROLES);
36
+ const form = task.promptForm === undefined ? undefined : task.promptForm === "minimal" ? "minimal" : refuse("promptForm", task.promptForm, ["minimal"]);
37
+ return Object.freeze({ ...(role !== undefined ? { role } : {}), ...(form !== undefined ? { form } : {}) });
38
+ }
39
+ export function selectorsOf(facts, host = {}, binding) {
40
+ return Object.freeze({
41
+ traits: promptTraitsOf(facts),
42
+ host: Object.freeze({ role: host.role ?? "general", form: host.form ?? "standard" }),
43
+ facts: Object.freeze(catalogFactsOf(facts)),
44
+ ...(binding !== undefined ? { binding } : {}),
45
+ });
46
+ }
47
+ export function selectorRecordOf(s) {
48
+ return {
49
+ ...(s.binding !== undefined ? { binding: s.binding } : {}),
50
+ traits: [...s.traits].sort(),
51
+ host: { role: s.host.role, form: s.host.form },
52
+ facts: { ...s.facts },
53
+ };
54
+ }
55
+ export function factsHold(conj, facts) {
56
+ if (conj === undefined)
57
+ return true;
58
+ for (const [name, want] of Object.entries(conj))
59
+ if (facts[name] !== want)
60
+ return false;
61
+ return true;
62
+ }
63
+ function traitsHold(cond, traits) {
64
+ if (cond === undefined)
65
+ return true;
66
+ return (cond.allOf ?? []).every((t) => traits.has(t)) && !(cond.noneOf ?? []).some((t) => traits.has(t));
67
+ }
68
+ function hostHolds(cond, host) {
69
+ if (cond === undefined)
70
+ return true;
71
+ return (cond.role === undefined || cond.role === host.role) && (cond.form === undefined || cond.form === host.form);
72
+ }
73
+ function bindingHolds(cond, binding) {
74
+ if (cond === undefined)
75
+ return true;
76
+ if (cond.anyOf !== undefined)
77
+ return binding !== undefined && cond.anyOf.includes(binding);
78
+ return binding === undefined || !cond.noneOf.includes(binding);
79
+ }
80
+ export function whenHolds(when, s) {
81
+ return when === undefined || (traitsHold(when.traits, s.traits) && hostHolds(when.host, s.host) && factsHold(when.facts, s.facts) && bindingHolds(when.binding, s.binding));
82
+ }
83
+ const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
84
+ const sortedSet = (xs) => Object.freeze([...new Set(xs ?? [])].sort(byText));
85
+ export function canonicalWhen(when) {
86
+ if (when === undefined)
87
+ return undefined;
88
+ const allOf = sortedSet(when.traits?.allOf);
89
+ const noneOf = sortedSet(when.traits?.noneOf);
90
+ const hostKeys = Object.keys(when.host ?? {});
91
+ const factNames = Object.keys(when.facts ?? {}).sort(byText);
92
+ const binding = when.binding;
93
+ const out = {};
94
+ if (allOf.length > 0 || noneOf.length > 0)
95
+ out.traits = Object.freeze({ ...(allOf.length > 0 ? { allOf } : {}), ...(noneOf.length > 0 ? { noneOf } : {}) });
96
+ if (hostKeys.length > 0)
97
+ out.host = Object.freeze({ ...when.host });
98
+ if (factNames.length > 0)
99
+ out.facts = Object.freeze(Object.fromEntries(factNames.map((n) => [n, when.facts[n]])));
100
+ if (binding !== undefined)
101
+ out.binding = Object.freeze(binding.anyOf !== undefined ? { anyOf: sortedSet(binding.anyOf) } : { noneOf: sortedSet(binding.noneOf) });
102
+ return Object.keys(out).length === 0 ? undefined : Object.freeze(out);
103
+ }
104
+ export function selectVariant(message, s) {
105
+ return message.variants.find((v) => whenHolds(v.when, s));
106
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The request-body sugar: the one place the task's role-layer prompt inputs are read and turned into overlays of
3
+ * the `task` source class. Three inputs, one expression each:
4
+ *
5
+ * - the role base — `TaskSpec.systemPrompt ?? resolvedRole.systemPrompt ?? internals.defaultSystemPrompt` (the
6
+ * task's own text, else the role preset the task named, else the persona a core spawner hands its child) — a
7
+ * `replace` of `core/role.base`, applied after the selector chose the role base's variant;
8
+ * - the appended block — `TaskSpec.appendSystemPrompt` — an `add` to the `task-append` band (entry
9
+ * `core/role.append`);
10
+ *
11
+ * and nothing else reads them for assembly (`gate:sugar-single-site`). The sugar is applied first within its class,
12
+ * the task-seat mods after it. Its one possible violation is locked text: a role-layer input carrying, verbatim,
13
+ * the canonical text of a `constitution` entry is an already-assembled prompt, and the task is refused by name
14
+ * (`prompt.assembled_role_refused`) — never passed through, never silently dropped.
15
+ */
16
+ import { type SourcedOverlay } from "./overlay.js";
17
+ /** The task's role-layer prompt inputs, as prepare holds them. */
18
+ export interface SugarInputs {
19
+ readonly spec: {
20
+ readonly systemPrompt?: string;
21
+ readonly appendSystemPrompt?: string;
22
+ };
23
+ readonly resolvedRole: {
24
+ readonly systemPrompt?: string;
25
+ };
26
+ readonly internals?: {
27
+ readonly defaultSystemPrompt?: string;
28
+ };
29
+ }
30
+ /** The task-class overlays the request body carries, in application order (role base, then the appended block). */
31
+ export declare function sugarOverlays(inputs: SugarInputs): readonly SourcedOverlay[];
@@ -0,0 +1,20 @@
1
+ import { assembledRoleRefused, lockedTextIn } from "./overlay.js";
2
+ const SUGAR = { source: "task", by: "sugar" };
3
+ export function sugarOverlays(inputs) {
4
+ const roleBase = inputs.spec.systemPrompt ?? inputs.resolvedRole.systemPrompt ?? inputs.internals?.defaultSystemPrompt;
5
+ const append = inputs.spec.appendSystemPrompt;
6
+ const out = [];
7
+ if (roleBase !== undefined) {
8
+ const hits = lockedTextIn(roleBase);
9
+ if (hits.length > 0)
10
+ throw assembledRoleRefused("the task's role text (systemPrompt)", hits);
11
+ out.push({ overlay: Object.freeze({ id: "core/role.base", op: "replace", target: "core/role.base", text: roleBase }), origin: SUGAR });
12
+ }
13
+ if (append !== undefined) {
14
+ const hits = lockedTextIn(append);
15
+ if (hits.length > 0)
16
+ throw assembledRoleRefused("the task's appendSystemPrompt", hits);
17
+ out.push({ overlay: Object.freeze({ id: "core/role.append", op: "add", target: "task-append", text: append }), origin: SUGAR });
18
+ }
19
+ return Object.freeze(out);
20
+ }