@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
@@ -7,140 +7,55 @@ export function canonical(node) {
7
7
  const keys = Object.keys(node).sort();
8
8
  return `{${keys.map((k) => `${JSON.stringify(k)}:${canonical(node[k])}`).join(",")}}`;
9
9
  }
10
- const PROBE_FACTS_OFF = {
11
- policyEnabled: false,
12
- hooksEnabled: false,
13
- isolationEnabled: false,
14
- withinTaskCompactionEnabled: false,
15
- supervisorEnabled: false,
16
- orchestrationEnabled: false,
17
- awarenessEnabled: false,
18
- goalEnabled: false,
19
- worktreeIsolated: false,
20
- teammateEnabled: false,
21
- orchestrationDeferred: false,
22
- isSubagent: false,
23
- promptProfile: "simple",
24
- fableMitigations: false,
25
- readFaceOpen: false,
26
- writeFaceOpen: false,
27
- reminderMark: undefined,
28
- };
29
- const PROBE_FACTS_ON = {
30
- policyEnabled: true,
31
- hooksEnabled: true,
32
- isolationEnabled: true,
33
- withinTaskCompactionEnabled: true,
34
- supervisorEnabled: true,
35
- orchestrationEnabled: true,
36
- awarenessEnabled: true,
37
- goalEnabled: true,
38
- worktreeIsolated: true,
39
- teammateEnabled: true,
40
- orchestrationDeferred: true,
41
- isSubagent: true,
42
- promptProfile: "classic",
43
- fableMitigations: true,
44
- readFaceOpen: true,
45
- writeFaceOpen: true,
46
- reminderMark: "PROBE-FIXED-MARK-AXIS0",
47
- };
48
- const PROBE_VECTORS = [
49
- PROBE_FACTS_OFF,
50
- PROBE_FACTS_ON,
51
- ...Object.keys(PROBE_FACTS_OFF).map((k) => ({ ...PROBE_FACTS_OFF, [k]: PROBE_FACTS_ON[k] })),
52
- ];
53
- const PROBE_INPUTS_BASE = {
54
- roleBase: "\u0000probe-role\u0000",
55
- roleAppend: "\u0000probe-append\u0000",
56
- mcpInstructionsBlock: "\u0000probe-mcp\u0000",
57
- environmentBlock: "\u0000probe-env@2\u0000",
58
- memoryBlock: "\u0000probe-memory\u0000",
59
- modelGuidance: "\u0000probe-guidance\u0000",
60
- };
61
- export function computeBundledArtifactDigest(pack, declared) {
62
- const probeSection = (s) => PROBE_VECTORS.map((facts) => {
63
- const inputs = { ...PROBE_INPUTS_BASE, facts };
64
- try {
65
- if (s.admit && !s.admit(inputs))
66
- return null;
67
- return s.content(inputs) ?? null;
68
- }
69
- catch {
70
- return " probe-threw ";
71
- }
72
- });
73
- const payload = {
74
- packId: pack.packId,
75
- assemblyApi: pack.assemblyApi,
76
- ...(declared !== undefined && declared.length > 0
77
- ? { declaredSections: declared.map((d) => ({ id: d.id, slot: d.slot, chars: d.chars, ...(d.contentHash !== undefined ? { contentHash: d.contentHash } : {}) })) }
78
- : {}),
79
- sections: [...pack.sections].sort((a, b) => a.rank - b.rank).map((s) => ({
80
- id: s.id,
81
- slot: s.slot,
82
- rank: s.rank,
83
- owner: s.owner,
84
- trust: s.trust,
85
- mutability: s.mutability,
86
- cadence: s.cadence,
87
- cacheClass: s.cacheClass,
88
- carrier: s.carrier,
89
- legacyBlockId: s.blockId,
90
- probes: probeSection(s),
91
- })),
92
- };
93
- return `sha256:${createHash("sha256").update(canonical(payload)).digest("hex")}`;
10
+ export function digestOf(node) {
11
+ return `sha256:${createHash("sha256").update(canonical(node)).digest("hex")}`;
94
12
  }
95
- export function mintSessionStartEpoch(pack, declared) {
96
- return {
97
- epoch: 1,
98
- artifactDigest: computeBundledArtifactDigest(pack, declared),
99
- packId: pack.packId,
100
- assemblyApi: pack.assemblyApi,
101
- activatedBy: "session_start",
102
- };
13
+ export function catalogDigestOf(catalog) {
14
+ return digestOf({
15
+ ...catalog,
16
+ bands: [...catalog.bands].sort((a, b) => a.id.localeCompare(b.id)),
17
+ messages: [...catalog.messages].sort((a, b) => a.id.localeCompare(b.id)),
18
+ sections: [...catalog.sections].sort((a, b) => a.rank - b.rank),
19
+ });
103
20
  }
104
- export function selectCompactionEpoch(current, pack, declared, centerAdoption) {
105
- const digest = computeBundledArtifactDigest(pack, declared);
106
- if (centerAdoption === undefined && current && current.artifactDigest === digest) {
107
- return { ...current, activatedBy: "compaction" };
108
- }
109
- return {
110
- epoch: (current?.epoch ?? 0) + 1,
111
- artifactDigest: digest,
112
- packId: pack.packId,
113
- assemblyApi: pack.assemblyApi,
114
- activatedBy: "compaction",
115
- ...(centerAdoption !== undefined
116
- ? "clear" in centerAdoption
117
- ? {}
118
- : {
119
- centerArtifactDigest: centerAdoption.centerArtifactDigest,
120
- ...(centerAdoption.sourceRevision !== undefined ? { sourceRevision: centerAdoption.sourceRevision } : {}),
121
- }
122
- : current?.centerArtifactDigest !== undefined
123
- ? {
124
- centerArtifactDigest: current.centerArtifactDigest,
125
- ...(current.sourceRevision !== undefined ? { sourceRevision: current.sourceRevision } : {}),
126
- }
127
- : {}),
128
- };
21
+ export function promptIdentityOf(layers) {
22
+ return digestOf({
23
+ catalog: layers.catalog,
24
+ renderers: layers.renderers,
25
+ overlays: digestOf({ center: layers.center ?? null, deploy: layers.deploy ?? null, task: layers.task ?? null }),
26
+ binding: layers.binding,
27
+ });
129
28
  }
130
- export function resolveEpochAgainstBundled(pinned, pack, declared) {
131
- const digest = computeBundledArtifactDigest(pack, declared);
132
- if (pinned && pinned.artifactDigest === digest && pinned.packId === pack.packId && pinned.assemblyApi === pack.assemblyApi) {
133
- return { descriptor: pinned, migrated: false };
134
- }
29
+ export const PROMPT_EPOCH_ACTIVATIONS = Object.freeze(["session_start", "compaction", "code_change", "selection_change"]);
30
+ export const PROMPT_EPOCH_CHANGES = Object.freeze(["catalog", "renderers", "deploy", "task", "published_schema"]);
31
+ const DIGEST = /^sha256:[0-9a-f]{64}$/;
32
+ const isDigest = (v) => typeof v === "string" && DIGEST.test(v);
33
+ const RETIRED_DESCRIPTOR_FIELDS = Object.freeze(["artifactDigest", "packId", "assemblyApi", "centerArtifactDigest"]);
34
+ function normalizeLayers(raw) {
35
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw))
36
+ return undefined;
37
+ const r = raw;
38
+ for (const k of Object.keys(r))
39
+ if (!["catalog", "renderers", "center", "deploy", "task", "binding"].includes(k))
40
+ return undefined;
41
+ if (!isDigest(r.catalog) || !isDigest(r.binding))
42
+ return undefined;
43
+ for (const k of ["center", "deploy", "task"])
44
+ if (r[k] !== undefined && !isDigest(r[k]))
45
+ return undefined;
46
+ const rv = r.renderers;
47
+ if (rv === null || typeof rv !== "object" || Array.isArray(rv))
48
+ return undefined;
49
+ const entries = Object.entries(rv);
50
+ if (entries.length > 64 || entries.some(([k, v]) => k.length === 0 || k.length > 64 || typeof v !== "number" || !Number.isInteger(v) || v < 1 || v > 1_000_000))
51
+ return undefined;
135
52
  return {
136
- descriptor: {
137
- epoch: (pinned?.epoch ?? 0) + 1,
138
- artifactDigest: digest,
139
- packId: pack.packId,
140
- assemblyApi: pack.assemblyApi,
141
- activatedBy: "legacy_migration",
142
- },
143
- migrated: true,
53
+ catalog: r.catalog,
54
+ renderers: Object.fromEntries(entries),
55
+ ...(r.center !== undefined ? { center: r.center } : {}),
56
+ ...(r.deploy !== undefined ? { deploy: r.deploy } : {}),
57
+ ...(r.task !== undefined ? { task: r.task } : {}),
58
+ binding: r.binding,
144
59
  };
145
60
  }
146
61
  export function normalizePromptEpoch(raw) {
@@ -149,23 +64,81 @@ export function normalizePromptEpoch(raw) {
149
64
  const r = raw;
150
65
  if (typeof r.epoch !== "number" || !Number.isInteger(r.epoch) || r.epoch < 1 || r.epoch > 1_000_000_000)
151
66
  return undefined;
152
- if (typeof r.artifactDigest !== "string" || !/^sha256:[0-9a-f]{64}$/.test(r.artifactDigest))
67
+ if (!isDigest(r.identity))
153
68
  return undefined;
154
- if (typeof r.packId !== "string" || !r.packId.trim() || r.packId.length > 200)
69
+ const layers = normalizeLayers(r.layers);
70
+ if (layers === undefined || promptIdentityOf(layers) !== r.identity)
155
71
  return undefined;
156
- if (r.assemblyApi !== 1)
72
+ if (!PROMPT_EPOCH_ACTIVATIONS.some((a) => a === r.activatedBy))
157
73
  return undefined;
158
- if (r.activatedBy !== "session_start" && r.activatedBy !== "compaction" && r.activatedBy !== "legacy_migration")
74
+ const activatedBy = r.activatedBy;
75
+ let changed;
76
+ if (r.changed !== undefined) {
77
+ if (activatedBy !== "code_change" || !Array.isArray(r.changed) || r.changed.length === 0)
78
+ return undefined;
79
+ if (r.changed.some((c) => !PROMPT_EPOCH_CHANGES.some((w) => w === c)) || new Set(r.changed).size !== r.changed.length)
80
+ return undefined;
81
+ changed = [...r.changed];
82
+ }
83
+ if (r.sourceRevision !== undefined && (layers.center === undefined || typeof r.sourceRevision !== "string" || r.sourceRevision.length === 0 || r.sourceRevision.length > 500))
159
84
  return undefined;
160
- const centerArtifactDigest = typeof r.centerArtifactDigest === "string" && /^sha256:[0-9a-f]{64}$/.test(r.centerArtifactDigest) ? r.centerArtifactDigest : undefined;
161
- const sourceRevision = typeof r.sourceRevision === "string" && r.sourceRevision.length > 0 && r.sourceRevision.length <= 500 ? r.sourceRevision : undefined;
162
85
  return {
163
86
  epoch: r.epoch,
164
- artifactDigest: r.artifactDigest,
165
- packId: r.packId,
166
- assemblyApi: 1,
167
- activatedBy: r.activatedBy,
168
- ...(centerArtifactDigest !== undefined ? { centerArtifactDigest } : {}),
169
- ...(centerArtifactDigest !== undefined && sourceRevision !== undefined ? { sourceRevision } : {}),
87
+ identity: r.identity,
88
+ layers,
89
+ activatedBy,
90
+ ...(changed !== undefined ? { changed } : {}),
91
+ ...(r.sourceRevision !== undefined ? { sourceRevision: r.sourceRevision } : {}),
92
+ };
93
+ }
94
+ export function readStoredPromptEpoch(raw) {
95
+ const descriptor = normalizePromptEpoch(raw);
96
+ if (descriptor !== undefined)
97
+ return { kind: "pin", descriptor };
98
+ if (raw === null || typeof raw !== "object")
99
+ return undefined;
100
+ const r = raw;
101
+ if (!RETIRED_DESCRIPTOR_FIELDS.some((f) => f in r))
102
+ return undefined;
103
+ return { kind: "legacy", centerPinned: isDigest(r.centerArtifactDigest) };
104
+ }
105
+ function changedLayers(a, b) {
106
+ const out = [];
107
+ if (a.catalog !== b.catalog)
108
+ out.push("catalog");
109
+ if (canonical(a.renderers) !== canonical(b.renderers))
110
+ out.push("renderers");
111
+ if (a.deploy !== b.deploy)
112
+ out.push("deploy");
113
+ if (a.task !== b.task)
114
+ out.push("task");
115
+ return out;
116
+ }
117
+ function descriptorOf(epoch, layers, activatedBy, extra) {
118
+ return {
119
+ epoch,
120
+ identity: promptIdentityOf(layers),
121
+ layers,
122
+ activatedBy,
123
+ ...(extra.changed !== undefined && extra.changed.length > 0 ? { changed: [...extra.changed] } : {}),
124
+ ...(layers.center !== undefined && extra.sourceRevision !== undefined ? { sourceRevision: extra.sourceRevision } : {}),
170
125
  };
171
126
  }
127
+ export function prepareEpochRecord(stored, layers, ctx) {
128
+ if (stored === undefined)
129
+ return descriptorOf(1, layers, ctx.priorConversation ? "code_change" : "session_start", ctx);
130
+ if (stored.kind === "legacy")
131
+ return descriptorOf(1, layers, "code_change", { ...ctx, ...(stored.centerPinned ? { changed: ["published_schema"] } : {}) });
132
+ const pinned = stored.descriptor;
133
+ if (pinned.identity === promptIdentityOf(layers))
134
+ return undefined;
135
+ const changed = changedLayers(pinned.layers, layers);
136
+ return descriptorOf(pinned.epoch + 1, layers, changed.length > 0 ? "code_change" : "selection_change", { ...ctx, changed });
137
+ }
138
+ export function selectCompactionEpoch(current, layers, sourceRevision) {
139
+ if (current !== undefined && current.identity === promptIdentityOf(layers)) {
140
+ const { changed: _recordOnly, ...restated } = current;
141
+ return { ...restated, activatedBy: "compaction" };
142
+ }
143
+ return descriptorOf((current?.epoch ?? 0) + 1, layers, "compaction", sourceRevision !== undefined ? { sourceRevision } : {});
144
+ }
@@ -1,57 +1,81 @@
1
+ import type { BandId, OverlayOp } from "./catalog/schema.js";
2
+ /** A `prompt.assembled` manifest (v3) as explain reads it: the frame's own members. */
1
3
  export interface ExplainInput {
2
- constitution: "core" | "replaced" | "provider-assembled";
3
- blocks: Array<{
4
+ identity: {
5
+ artifact: string;
6
+ layers: {
7
+ center?: string;
8
+ deploy?: string;
9
+ task?: string;
10
+ };
11
+ epoch: number;
12
+ activatedBy: string;
13
+ };
14
+ selectors: {
15
+ binding?: string;
16
+ traits: readonly string[];
17
+ host: {
18
+ role: string;
19
+ form: string;
20
+ };
21
+ };
22
+ blocks: ReadonlyArray<{
4
23
  id: string;
5
24
  chars: number;
6
25
  hash: string;
7
26
  }>;
8
- sections?: Array<{
27
+ sections: ReadonlyArray<{
9
28
  id: string;
10
- slot: string;
11
- carrier: string;
12
- cadence: string;
13
- cacheClass: string;
29
+ band: string;
30
+ variant?: string;
14
31
  chars: number;
15
- hash: string;
16
- contentHash?: string;
32
+ locale: string;
33
+ contentHash: string;
34
+ chain: ReadonlyArray<{
35
+ source: string;
36
+ overlay?: string;
37
+ op?: string;
38
+ superseded?: true;
39
+ }>;
17
40
  }>;
18
- tools?: Array<{
41
+ superseded?: ReadonlyArray<{
42
+ id: string;
43
+ source: string;
44
+ by: string;
45
+ target: string;
46
+ supersededBy: string;
47
+ }>;
48
+ tools?: ReadonlyArray<{
19
49
  wireName: string;
20
50
  contractId: string;
21
51
  cardId: string;
22
52
  shapeDigest: string;
23
53
  }>;
24
- epoch?: {
25
- epoch: number;
26
- artifactDigest: string;
27
- packId: string;
28
- activatedBy: string;
29
- };
30
54
  }
31
- /** Render a `prompt.assembled` manifest (+ optional epoch pin) as a readable report. */
55
+ /** Render a `prompt.assembled` manifest as a readable report: which prompt (identity, its layers, the selector values),
56
+ * what composed it, and where each section's text came from. */
32
57
  export declare function explainPromptAssembly(input: ExplainInput): string;
33
58
  /**
34
- * the CENTER-facing read-only description of the default pack: section
35
- * metadata (id/slot/rank/ownership/locked) plus the default role-base TEXT (the append-mode
36
- * compile skeleton the web UI prepends to a user's "Role details"). Deliberately NO other section
37
- * texts (the no-prompt-bodies observability line — structure yes, prose no; the role base is
38
- * the one deliberate exception: it is the public compile input of the append mode, and its text is
39
- * this open repo's DEFAULT_SYSTEM_PROMPT). Programmatic — a static copy in the web tier would
40
- * silently drift the moment core's default prompt changes (no static copies).
59
+ * The CENTER-facing read-only description of the bundled catalog: each section's id, band, rank and what each overlay
60
+ * source class may do to it (the band's three op columns — a center editor reads `ops.center`; an empty column for
61
+ * every class is a platform-managed section), plus the default role-base TEXT (the append-mode compile skeleton the web
62
+ * UI prepends to a user's "Role details"). No other section texts. Programmatic — a static copy in the web tier would
63
+ * drift the moment the catalog changes.
41
64
  */
42
- export interface DefaultPackDescription {
43
- packId: string;
44
- /** The pack-default role base (append-mode skeleton). */
65
+ export interface CatalogDescription {
66
+ catalogId: string;
67
+ /** The catalog-default role base (append-mode skeleton). */
45
68
  roleBaseText: string;
46
69
  sections: Array<{
47
70
  id: string;
48
- slot: string;
71
+ band: BandId;
49
72
  rank: number;
50
- owner: string;
51
- trust: string;
52
- mutability: string;
53
- /** True ⇒ not deployment-writable (the UI shows the platform-managed indicator, never an editor). */
54
- locked: boolean;
73
+ /** The band's op columns: what a center artifact, a deployment's mods and a task may do to this section. */
74
+ ops: {
75
+ center: readonly OverlayOp[];
76
+ deploy: readonly OverlayOp[];
77
+ task: readonly OverlayOp[];
78
+ };
55
79
  }>;
56
80
  }
57
- export declare function describeDefaultPack(): DefaultPackDescription;
81
+ export declare function describeCatalog(): CatalogDescription;
@@ -1,23 +1,28 @@
1
1
  import { EVENT_PROMPT_REGISTRY } from "./event-registry.js";
2
- import { SEMA_DEFAULT_PACK } from "./packs/sema-default.js";
3
- import { DEFAULT_SYSTEM_PROMPT } from "../prompts/default.js";
2
+ import { bandOf } from "./bands.js";
3
+ import { SEMA_DEFAULT_CATALOG, catalogText } from "./catalog/index.js";
4
4
  function safeId(raw) {
5
- const cleaned = raw.replace(/[\u0000-\u001f\u007f]/g, "\u2400");
5
+ const cleaned = raw.replace(/[\u0000-\u001f\u007f]/g, "␀");
6
6
  return cleaned.length > 120 ? `${cleaned.slice(0, 117)}...` : cleaned;
7
7
  }
8
8
  export function explainPromptAssembly(input) {
9
9
  const lines = [];
10
- lines.push(`constitution: ${safeId(input.constitution)}${input.constitution === "core" ? "" : " (non-default — see PromptProvider tier docs)"}`);
11
- if (input.epoch) {
12
- lines.push(`epoch: #${input.epoch.epoch} on ${safeId(input.epoch.packId)} (${safeId(input.epoch.artifactDigest).slice(0, 23)}…) via ${safeId(input.epoch.activatedBy)}`);
13
- }
14
- lines.push(`system blocks (v1 view): ${input.blocks.map((b) => `${safeId(b.id)}[${b.chars}ch]`).join(" → ")}`);
15
- if (input.sections?.length) {
16
- lines.push("sections (compiled IR):");
17
- for (const s of input.sections) {
18
- lines.push(` ${safeId(s.id)} slot=${safeId(s.slot)} carrier=${safeId(s.carrier)} cadence=${safeId(s.cadence)} cache=${safeId(s.cacheClass)} ${s.chars}ch #${safeId(s.hash)}${s.contentHash !== undefined ? ` content=${safeId(s.contentHash)}` : ""}`);
10
+ const short = (d) => (d === undefined ? "none" : `${safeId(d).slice(0, 23)}…`);
11
+ lines.push(`identity: ${short(input.identity.artifact)} (record #${input.identity.epoch} via ${safeId(input.identity.activatedBy)})`);
12
+ lines.push(` layers: center=${short(input.identity.layers.center)} deploy=${short(input.identity.layers.deploy)} task=${short(input.identity.layers.task)}`);
13
+ const s = input.selectors;
14
+ lines.push(` selectors: role=${safeId(s.host.role)} form=${safeId(s.host.form)} traits=[${s.traits.map(safeId).join(", ")}]${s.binding !== undefined ? ` binding=${safeId(s.binding)}` : ""}`);
15
+ lines.push(`system blocks: ${input.blocks.map((b) => `${safeId(b.id)}[${b.chars}ch]`).join(" → ")}`);
16
+ if (input.sections.length > 0) {
17
+ lines.push("sections:");
18
+ for (const sec of input.sections) {
19
+ const chain = sec.chain.map((l) => (l.source === "bundled" ? "bundled" : `${safeId(l.source)}:${l.op ?? "?"} ${safeId(l.overlay ?? "?")}${l.superseded === true ? " (superseded)" : ""}`)).join(" > ");
20
+ lines.push(` ${safeId(sec.id)} band=${safeId(sec.band)}${sec.variant !== undefined ? ` variant=${safeId(sec.variant)}` : ""} ${sec.chars}ch ${safeId(sec.locale)} ${safeId(sec.contentHash).slice(0, 19)}… ${chain}`);
19
21
  }
20
22
  }
23
+ if (input.superseded?.length) {
24
+ lines.push(`superseded: ${input.superseded.map((o) => `${safeId(o.id)} (${safeId(o.source)}) on ${safeId(o.target)} by ${safeId(o.supersededBy)}`).join("; ")}`);
25
+ }
21
26
  if (input.tools?.length) {
22
27
  const legacy = input.tools.filter((t) => t.contractId.startsWith("legacy:"));
23
28
  lines.push(`tools: ${input.tools.length} mounted (${input.tools.length - legacy.length} contract-declared, ${legacy.length} legacy/external)`);
@@ -26,18 +31,10 @@ export function explainPromptAssembly(input) {
26
31
  lines.push(`event kinds registered: ${kinds.length} (default-on: ${kinds.filter((k) => k.defaultPolicy === "on").map((k) => k.kind).join(", ")})`);
27
32
  return lines.join("\n");
28
33
  }
29
- export function describeDefaultPack() {
34
+ export function describeCatalog() {
30
35
  return {
31
- packId: SEMA_DEFAULT_PACK.packId,
32
- roleBaseText: DEFAULT_SYSTEM_PROMPT,
33
- sections: [...SEMA_DEFAULT_PACK.sections].sort((a, b) => a.rank - b.rank).map((s) => ({
34
- id: s.id,
35
- slot: s.slot,
36
- rank: s.rank,
37
- owner: s.owner,
38
- trust: s.trust,
39
- mutability: s.mutability,
40
- locked: s.mutability === "locked",
41
- })),
36
+ catalogId: SEMA_DEFAULT_CATALOG.id,
37
+ roleBaseText: catalogText("core/role.base", "default"),
38
+ sections: [...SEMA_DEFAULT_CATALOG.sections].sort((a, b) => a.rank - b.rank).map((s) => ({ id: s.id, band: s.band, rank: s.rank, ops: bandOf(s.band).ops })),
42
39
  };
43
40
  }
@@ -0,0 +1,137 @@
1
+ import { type BandId, type CatalogSection, type OverlayOp, type OverlaySource, type VariantWhen } from "./catalog/schema.js";
2
+ /** One overlay: an operation on a target, carrying text (or a catalog message reference). */
3
+ export interface PromptOverlay {
4
+ /** `<namespace>/<name>`; the `core/` namespace is the task sugar's alone. Names an added entry. */
5
+ readonly id: string;
6
+ readonly op: OverlayOp;
7
+ /** A message id (`replace` / `append`), a band id (`add`), or a section / added-entry id (`drop`). */
8
+ readonly target: string;
9
+ /** The overlay's text (`replace` / `append` / `add`); exclusive with `message`. */
10
+ readonly text?: string;
11
+ /** A catalog message whose selected variant is the overlay's text; exclusive with `text`. */
12
+ readonly message?: string;
13
+ /** The overlay applies to this run only when this holds (the variant selector's own vocabulary, the binding
14
+ * included) — the one applicability condition of every source class. */
15
+ readonly when?: VariantWhen;
16
+ }
17
+ /** The source classes in application order (later wins). `bundled` is the catalog itself and writes no overlay. */
18
+ export declare const OVERLAY_SOURCE_ORDER: readonly ["bundled", "task", "center", "deploy"];
19
+ /** Who contributed an overlay: its source class and, within it, the contributor (`sugar`, a mods registration, the center). */
20
+ export interface OverlayOrigin {
21
+ readonly source: OverlaySource;
22
+ readonly by: string;
23
+ }
24
+ export interface SourcedOverlay {
25
+ readonly overlay: PromptOverlay;
26
+ readonly origin: OverlayOrigin;
27
+ }
28
+ /** An overlay a later one on the same target overrode (or a drop removed), or one that changed nothing this run. */
29
+ export interface SupersededOverlay {
30
+ readonly id: string;
31
+ readonly source: OverlaySource;
32
+ readonly by: string;
33
+ readonly target: string;
34
+ /** The overlay id that won, or {@link ABSENT_THIS_RUN}. */
35
+ readonly supersededBy: string;
36
+ }
37
+ /** `supersededBy` of an overlay that changed nothing this run: the selector chose no variant of its target, or of
38
+ * the catalog message it takes its text from. */
39
+ export declare const ABSENT_THIS_RUN = "(absent this run)";
40
+ /** The section a message id is placed by, when the catalog places it. */
41
+ export declare function sectionOfMessage(id: string): CatalogSection | undefined;
42
+ export interface LockedEntry {
43
+ readonly message: string;
44
+ readonly variant: string;
45
+ readonly text: string;
46
+ }
47
+ /** Every constitution entry the guard compares: each message a constitution section places, every variant, whole. */
48
+ export declare function lockedEntries(): readonly LockedEntry[];
49
+ /** The constitution entries (`message#variant`) whose canonical text `text` contains verbatim. */
50
+ export declare function lockedTextIn(text: string): string[];
51
+ /** The task sugar's one violation: a role-layer text that carries locked text (an already-assembled prompt). */
52
+ export declare function assembledRoleRefused(field: string, hits: readonly string[]): Error;
53
+ /** Receive a source's prompt data ({@link PROMPT_DATA}): its frozen copy, or the clause naming what in it is not data. */
54
+ export declare function receivePromptData(raw: unknown): {
55
+ readonly value: unknown;
56
+ } | {
57
+ readonly notData: string;
58
+ };
59
+ /** The longest binding a task may name (`TaskSpec.promptBinding`), counted in Unicode code points (`[...s].length`) — not
60
+ * in UTF-16 code units; every binding a `when.binding` list names is held to the same bound. Exported so a host screens
61
+ * with the engine's number and the engine's unit. Code points are the one unit of every character bound of the prompt
62
+ * artifact verifier ({@link codePointsOver}: a binding, an overlay id, `sourceRevision`, `evidence.intent`, a
63
+ * reference), so a character outside the BMP (an emoji, a rare CJK ideograph) counts one, not two; the overlay text
64
+ * budgets are UTF-8 bytes and are named so. */
65
+ export declare const PROMPT_BINDING_MAX_CHARS = 128;
66
+ /** The most bindings one `when.binding` list names — it bounds what a publisher can make the conflict check walk. */
67
+ export declare const PROMPT_BINDING_LIST_MAX = 64;
68
+ /** Whether `s` holds more than `max` Unicode code points — the one length unit of the prompt artifact verifier's
69
+ * character bounds. A string of at most `max` code units fits (a code point is one or two of them); one of more than
70
+ * twice `max` does not; only a string in between is counted — counted, never copied whole. */
71
+ export declare function codePointsOver(s: string, max: number): boolean;
72
+ /**
73
+ * The run's binding (`TaskSpec.promptBinding`): the scenario a `when.binding` condition reads, on an overlay of any
74
+ * source class. Its one writer is the task (a deployment names its scenario); absent ⇒ undefined. A value outside the
75
+ * grammar is refused by name (`config.prompt_selector_invalid`), never read as absent.
76
+ */
77
+ export declare function resolvePromptBinding(task: {
78
+ readonly promptBinding?: unknown;
79
+ }): string | undefined;
80
+ /** What a validation needs besides the overlay: its source class, which mods event (if any) carries it, and the
81
+ * entries lower classes added (the only entries a `drop` may name besides a built-in section). */
82
+ export interface OverlayValidationContext {
83
+ readonly source: OverlaySource;
84
+ /** The mods event the overlay arrived on; absent for the sugar and the center. */
85
+ readonly event?: "prompt.compose";
86
+ /** The request-body sugar may use the `core/` namespace; nothing else may. */
87
+ readonly sugar?: boolean;
88
+ /** Ids of entries lower source classes added (`add`) and the band each landed in. */
89
+ readonly lowerAdds?: ReadonlyMap<string, BandId>;
90
+ }
91
+ /**
92
+ * Validate one overlay for one source class. Returns the overlay (a frozen copy of its known members, its `when` in
93
+ * normal form — {@link canonicalWhen}) or why it is a violation: shape, namespace, op, text/message, `when`, target existence, band authorization (and the band's mods
94
+ * write port), and the locked-text guard.
95
+ */
96
+ export declare function validateOverlay(raw: unknown, ctx: OverlayValidationContext): {
97
+ readonly overlay: PromptOverlay;
98
+ } | {
99
+ readonly violation: string;
100
+ };
101
+ /** One added entry as the fold leaves it. */
102
+ export interface AddedEntry {
103
+ readonly id: string;
104
+ readonly band: BandId;
105
+ readonly rank: number;
106
+ readonly text: string;
107
+ readonly origin: OverlayOrigin;
108
+ }
109
+ /** One overlay in a section's history, in application order; `superseded` once a later one overrode it. The
110
+ * composition puts the catalog's own text (`bundled`) first for a catalog section. */
111
+ export interface ChainLink {
112
+ readonly source: "bundled" | OverlaySource;
113
+ readonly overlay?: string;
114
+ readonly op?: OverlayOp;
115
+ readonly superseded?: true;
116
+ }
117
+ /** The fold's result: per-message text the overlays set, dropped sections, added entries, superseded overlays. */
118
+ export interface OverlayFold {
119
+ /** Message id → its text after the overlays (absent ⇒ the selected variant's text stands). */
120
+ readonly messageText: ReadonlyMap<string, {
121
+ readonly text: string;
122
+ readonly origin: OverlayOrigin;
123
+ readonly replaced: boolean;
124
+ }>;
125
+ /** Built-in section ids a drop removed. */
126
+ readonly dropped: ReadonlySet<string>;
127
+ readonly added: readonly AddedEntry[];
128
+ readonly superseded: readonly SupersededOverlay[];
129
+ /** Section id (or added-entry id) → the overlays applied to it, in order, superseded ones marked. */
130
+ readonly chains: ReadonlyMap<string, readonly ChainLink[]>;
131
+ }
132
+ /**
133
+ * Apply sourced overlays, already validated and already in application order, over the selected texts.
134
+ * `selectedText(messageId)` answers the text the selector chose (undefined ⇒ the message is absent this run);
135
+ * `applies(overlay)` answers its `when`.
136
+ */
137
+ export declare function foldOverlays(ordered: readonly SourcedOverlay[], selectedText: (messageId: string) => string | undefined, applies: (o: PromptOverlay) => boolean, overlayText: (o: PromptOverlay) => string | undefined): OverlayFold;