@sema-agent/core 7.72.0 → 7.74.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/CHANGELOG.md +565 -0
  2. package/dist/agents/inherited-tool-pool.d.ts +26 -1
  3. package/dist/agents/inherited-tool-pool.js +46 -2
  4. package/dist/agents/list-agents-tool.js +1 -1
  5. package/dist/agents/parked-resume-drive.d.ts +10 -0
  6. package/dist/agents/parked-resume-drive.js +9 -0
  7. package/dist/agents/retain-ledger.d.ts +3 -0
  8. package/dist/agents/retain-ledger.js +3 -3
  9. package/dist/agents/send-message-tool.js +5 -4
  10. package/dist/agents/send-user-message-tool.d.ts +12 -0
  11. package/dist/agents/send-user-message-tool.js +67 -0
  12. package/dist/agents/subagent-steps.d.ts +9 -0
  13. package/dist/agents/subagent-steps.js +38 -0
  14. package/dist/agents/subagent.d.ts +2 -0
  15. package/dist/agents/subagent.js +43 -12
  16. package/dist/agents/verify.js +23 -8
  17. package/dist/agents/yield-adoption.js +3 -1
  18. package/dist/brain/anthropic.d.ts +42 -1
  19. package/dist/brain/anthropic.js +68 -13
  20. package/dist/brain/failover.d.ts +5 -0
  21. package/dist/brain/failover.js +51 -22
  22. package/dist/brain/model-lane.d.ts +12 -3
  23. package/dist/brain/model-lane.js +5 -5
  24. package/dist/brain/open-responses.js +7 -8
  25. package/dist/brain/openai.js +31 -24
  26. package/dist/brain/route-adjudicator.d.ts +33 -4
  27. package/dist/brain/route-adjudicator.js +49 -12
  28. package/dist/brain/stream-engine.js +166 -156
  29. package/dist/brain/stream-shared.d.ts +4 -3
  30. package/dist/brain/stream-shared.js +2 -2
  31. package/dist/core/actions-digest.d.ts +43 -0
  32. package/dist/core/actions-digest.js +22 -0
  33. package/dist/core/allow-entry.js +4 -4
  34. package/dist/core/ask-class.d.ts +2 -2
  35. package/dist/core/ask-headline.d.ts +1 -1
  36. package/dist/core/ask-origin.d.ts +44 -4
  37. package/dist/core/ask-origin.js +29 -10
  38. package/dist/core/auto-mode.d.ts +7 -9
  39. package/dist/core/auto-mode.js +114 -8
  40. package/dist/core/background-agent-store.d.ts +1 -0
  41. package/dist/core/background-agent-store.js +49 -8
  42. package/dist/core/checkpoint-features.d.ts +3 -2
  43. package/dist/core/checkpoint-features.js +1 -1
  44. package/dist/core/checkpoint-rekey.d.ts +1 -1
  45. package/dist/core/checkpoint-rekey.js +6 -1
  46. package/dist/core/checkpoint-requirements.d.ts +23 -3
  47. package/dist/core/checkpoint-requirements.js +5 -1
  48. package/dist/core/checkpoint-row-verdict.d.ts +1 -1
  49. package/dist/core/checkpoint-row-verdict.js +9 -3
  50. package/dist/core/checkpoint-store.d.ts +26 -2
  51. package/dist/core/checkpoint-store.js +9 -2
  52. package/dist/core/child-clamp-seats.d.ts +15 -0
  53. package/dist/core/child-clamp-seats.js +15 -0
  54. package/dist/core/config-refusal-codes.d.ts +1 -1
  55. package/dist/core/config-refusal-codes.js +1 -0
  56. package/dist/core/cron.js +9 -1
  57. package/dist/core/delegation-frames.d.ts +1 -0
  58. package/dist/core/delegation-frames.js +1 -1
  59. package/dist/core/deployment-shape.d.ts +7 -0
  60. package/dist/core/deployment-shape.js +19 -0
  61. package/dist/core/engine-capabilities.d.ts +13 -1
  62. package/dist/core/engine-capabilities.js +1 -1
  63. package/dist/core/engine-notice.d.ts +41 -28
  64. package/dist/core/engine-version.js +1 -1
  65. package/dist/core/entries-not-applied.d.ts +19 -7
  66. package/dist/core/entries-not-applied.js +33 -1
  67. package/dist/core/gate-fold.js +5 -4
  68. package/dist/core/gate-lanes.js +8 -12
  69. package/dist/core/gate-outcome.d.ts +8 -2
  70. package/dist/core/gate-outcome.js +10 -3
  71. package/dist/core/governance-codes.d.ts +14 -2
  72. package/dist/core/governance-codes.js +22 -6
  73. package/dist/core/hook-condition.d.ts +37 -0
  74. package/dist/core/hook-condition.js +567 -0
  75. package/dist/core/hooks.d.ts +5 -0
  76. package/dist/core/hooks.js +1 -0
  77. package/dist/core/host-instance.d.ts +23 -0
  78. package/dist/core/host-instance.js +69 -0
  79. package/dist/core/instruction-preview.d.ts +63 -0
  80. package/dist/core/instruction-preview.js +406 -0
  81. package/dist/core/leg-budget.d.ts +26 -0
  82. package/dist/core/leg-budget.js +9 -0
  83. package/dist/core/leg-identity.d.ts +51 -1
  84. package/dist/core/leg-identity.js +45 -2
  85. package/dist/core/manager-launch-check.d.ts +48 -0
  86. package/dist/core/manager-launch-check.js +64 -0
  87. package/dist/core/mcp-call-meta.d.ts +2 -2
  88. package/dist/core/mcp-injection-drop.d.ts +20 -10
  89. package/dist/core/mcp-injection-drop.js +9 -3
  90. package/dist/core/mcp-server-spec.d.ts +2 -1
  91. package/dist/core/member-outcome.d.ts +3 -2
  92. package/dist/core/member-outcome.js +1 -1
  93. package/dist/core/memory-engine/deletion-record.d.ts +46 -0
  94. package/dist/core/memory-engine/deletion-record.js +96 -0
  95. package/dist/core/memory-engine/engine.js +24 -16
  96. package/dist/core/memory-engine/file-backend.js +7 -5
  97. package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
  98. package/dist/core/memory-engine/projection-ledger.js +1 -1
  99. package/dist/core/memory-engine/scope-contract.d.ts +18 -13
  100. package/dist/core/memory-engine/scope-contract.js +18 -18
  101. package/dist/core/memory-engine/sync-client.js +26 -6
  102. package/dist/core/memory-engine/sync.d.ts +20 -2
  103. package/dist/core/memory-engine/sync.js +18 -17
  104. package/dist/core/mode-policy.d.ts +25 -6
  105. package/dist/core/mode-policy.js +33 -8
  106. package/dist/core/model-seat.d.ts +8 -5
  107. package/dist/core/model-shell.d.ts +129 -0
  108. package/dist/core/model-shell.js +249 -0
  109. package/dist/core/mods/kernel/digest.d.ts +4 -0
  110. package/dist/core/mods/kernel/digest.js +5 -0
  111. package/dist/core/mods/kernel/dispatch.d.ts +3 -0
  112. package/dist/core/mods/kernel/dispatch.js +15 -6
  113. package/dist/core/mods/kernel/events.d.ts +21 -5
  114. package/dist/core/mods/kernel/events.js +19 -10
  115. package/dist/core/mods/kernel/hash-mirror.d.ts +1 -0
  116. package/dist/core/mods/kernel/hash-mirror.js +55 -0
  117. package/dist/core/mods/kernel/index.d.ts +1 -0
  118. package/dist/core/mods/kernel/index.js +1 -0
  119. package/dist/core/mods/kernel/package-reader.d.ts +48 -0
  120. package/dist/core/mods/kernel/package-reader.js +149 -0
  121. package/dist/core/mods/kernel/site-rules.d.ts +4 -0
  122. package/dist/core/mods/kernel/site-rules.js +13 -0
  123. package/dist/core/mods/package.d.ts +7 -3
  124. package/dist/core/mods/package.js +47 -80
  125. package/dist/core/own-property-receipt.js +11 -4
  126. package/dist/core/parent-spec-seat.d.ts +13 -11
  127. package/dist/core/parent-spec-seat.js +13 -9
  128. package/dist/core/peer-seat.js +3 -3
  129. package/dist/core/peer-task-store.d.ts +365 -0
  130. package/dist/core/peer-task-store.js +682 -0
  131. package/dist/core/permission-rule-consent.js +6 -11
  132. package/dist/core/permission-rule-model.d.ts +27 -0
  133. package/dist/core/permission-rule-model.js +33 -5
  134. package/dist/core/permission-rule-org.js +13 -3
  135. package/dist/core/permission-rule-provider.d.ts +35 -33
  136. package/dist/core/permission-rule-provider.js +38 -295
  137. package/dist/core/permission-rule-store.d.ts +181 -8
  138. package/dist/core/permission-rule-store.js +420 -17
  139. package/dist/core/permission-rule-sync.js +15 -1
  140. package/dist/core/permission-rules.js +4 -1
  141. package/dist/core/project-seat.d.ts +55 -0
  142. package/dist/core/project-seat.js +96 -0
  143. package/dist/core/protocol-http-auth.d.ts +3 -2
  144. package/dist/core/protocol-http-auth.js +26 -18
  145. package/dist/core/remote-env.d.ts +4 -4
  146. package/dist/core/retain-seat.d.ts +42 -0
  147. package/dist/core/retain-seat.js +76 -0
  148. package/dist/core/retired-keys.js +1 -0
  149. package/dist/core/rewind-refusal-codes.d.ts +8 -0
  150. package/dist/core/rewind-refusal-codes.js +12 -0
  151. package/dist/core/roles.d.ts +2 -2
  152. package/dist/core/roles.js +15 -1
  153. package/dist/core/rule-offer-read.d.ts +1 -1
  154. package/dist/core/rule-offer-read.js +32 -4
  155. package/dist/core/rule-store-fault.d.ts +9 -7
  156. package/dist/core/rule-store-fault.js +8 -3
  157. package/dist/core/run-ledger-seat.d.ts +66 -0
  158. package/dist/core/run-ledger-seat.js +70 -0
  159. package/dist/core/run-ledger.d.ts +332 -0
  160. package/dist/core/run-ledger.js +550 -0
  161. package/dist/core/runner/checkpoint-scope.d.ts +14 -3
  162. package/dist/core/runner/checkpoint-scope.js +16 -6
  163. package/dist/core/runner/compact-session.js +1 -1
  164. package/dist/core/runner/construction-doors.js +8 -0
  165. package/dist/core/runner/contracts.d.ts +21 -5
  166. package/dist/core/runner/cross-boundary-lane.d.ts +8 -1
  167. package/dist/core/runner/cross-boundary-lane.js +4 -0
  168. package/dist/core/runner/delegation-owner.d.ts +30 -0
  169. package/dist/core/runner/delegation-owner.js +20 -4
  170. package/dist/core/runner/finish-reason-seat.js +4 -2
  171. package/dist/core/runner/gate-exit.d.ts +7 -0
  172. package/dist/core/runner/gate-exit.js +2 -1
  173. package/dist/core/runner/leg-frame.js +3 -0
  174. package/dist/core/runner/model-lane-seat.d.ts +3 -0
  175. package/dist/core/runner/model-lane-seat.js +4 -0
  176. package/dist/core/runner/nested-memory-lane.d.ts +22 -5
  177. package/dist/core/runner/nested-memory-lane.js +91 -30
  178. package/dist/core/runner/person-path-rows.d.ts +27 -16
  179. package/dist/core/runner/person-path-rows.js +93 -15
  180. package/dist/core/runner/prepare-caps-and-workflow.js +98 -88
  181. package/dist/core/runner/prepare-config-doors.d.ts +1 -0
  182. package/dist/core/runner/prepare-config-doors.js +13 -7
  183. package/dist/core/runner/prepare-context-lane.js +1 -0
  184. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  185. package/dist/core/runner/prepare-delegation-surface.js +6 -0
  186. package/dist/core/runner/prepare-execution-env.d.ts +3 -3
  187. package/dist/core/runner/prepare-gate-stations.d.ts +6 -0
  188. package/dist/core/runner/prepare-gate-stations.js +3 -1
  189. package/dist/core/runner/prepare-hands-readface.d.ts +5 -2
  190. package/dist/core/runner/prepare-hands-readface.js +15 -3
  191. package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
  192. package/dist/core/runner/prepare-inherited-gate.js +13 -5
  193. package/dist/core/runner/prepare-offload-wrappers.js +1 -1
  194. package/dist/core/runner/prepare-run-refs.d.ts +1 -1
  195. package/dist/core/runner/prepare-run-refs.js +3 -2
  196. package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
  197. package/dist/core/runner/prepare-suspend-saga.js +4 -2
  198. package/dist/core/runner/prepare-task.js +42 -30
  199. package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
  200. package/dist/core/runner/prepare-turn-wiring.js +2 -1
  201. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  202. package/dist/core/runner/prepare-wiring-manifest.js +8 -6
  203. package/dist/core/runner/resume-apply.js +11 -5
  204. package/dist/core/runner/resume-policy-outcome.js +5 -2
  205. package/dist/core/runner/resume-review-outcome.d.ts +3 -0
  206. package/dist/core/runner/resume-review-outcome.js +24 -1
  207. package/dist/core/runner/role-seat-defaulted.d.ts +3 -3
  208. package/dist/core/runner/role-seat-defaulted.js +1 -1
  209. package/dist/core/runner/rule-store-unreadable-notice.d.ts +1 -1
  210. package/dist/core/runner/rule-store-unreadable-notice.js +3 -3
  211. package/dist/core/runner/run-harness-handlers.js +4 -1
  212. package/dist/core/runner/run-identity-wiring.js +3 -2
  213. package/dist/core/runner/run-leg.js +5 -2
  214. package/dist/core/runner/run-notification-lane.js +20 -1
  215. package/dist/core/runner/run-settle-and-teardown.js +21 -12
  216. package/dist/core/runner/run-stop-and-final-verify.js +6 -0
  217. package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
  218. package/dist/core/runner/runtask.d.ts +6 -2
  219. package/dist/core/runner/runtask.js +21 -9
  220. package/dist/core/runner/shell-env-withheld.d.ts +6 -4
  221. package/dist/core/runner/shell-env-withheld.js +25 -3
  222. package/dist/core/runner/stop-tail-notice.d.ts +10 -2
  223. package/dist/core/runner/stop-tail-notice.js +9 -2
  224. package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
  225. package/dist/core/runner/stream-settle-backstop.js +1 -0
  226. package/dist/core/runner/sub-agent-deny-lists.js +9 -5
  227. package/dist/core/runner/task-start-doors.js +6 -3
  228. package/dist/core/runner/terminal-account.d.ts +6 -1
  229. package/dist/core/runner/terminal-account.js +16 -1
  230. package/dist/core/runner/tool-end-body.d.ts +1 -1
  231. package/dist/core/runner/tool-not-executed.d.ts +27 -8
  232. package/dist/core/runner/tool-not-executed.js +22 -11
  233. package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
  234. package/dist/core/runner/write-protection-station.d.ts +1 -1
  235. package/dist/core/runner/write-protection-station.js +1 -1
  236. package/dist/core/runner-deps.d.ts +17 -10
  237. package/dist/core/secret-env.d.ts +61 -37
  238. package/dist/core/secret-env.js +49 -49
  239. package/dist/core/session-checkout.d.ts +3 -0
  240. package/dist/core/session-checkout.js +1 -0
  241. package/dist/core/session-store.d.ts +12 -6
  242. package/dist/core/session-store.js +26 -6
  243. package/dist/core/session.d.ts +31 -8
  244. package/dist/core/shell-read-silence.d.ts +40 -2
  245. package/dist/core/shell-read-silence.js +23 -4
  246. package/dist/core/store-contracts/checkpoint-store-contract.js +10 -0
  247. package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
  248. package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
  249. package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
  250. package/dist/core/store-contracts/session-store-contract.js +87 -3
  251. package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
  252. package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
  253. package/dist/core/task-event.d.ts +14 -7
  254. package/dist/core/task-notification.d.ts +96 -10
  255. package/dist/core/task-notification.js +135 -6
  256. package/dist/core/task-registry-agent.d.ts +1 -0
  257. package/dist/core/task-registry-agent.js +1 -1
  258. package/dist/core/task-registry-shared.d.ts +12 -1
  259. package/dist/core/task-registry-shared.js +3 -1
  260. package/dist/core/task-registry-workflow.d.ts +1 -1
  261. package/dist/core/task-registry-workflow.js +9 -1
  262. package/dist/core/task-registry.d.ts +40 -2
  263. package/dist/core/task-registry.js +80 -15
  264. package/dist/core/task-result.d.ts +18 -3
  265. package/dist/core/task-spec-members.d.ts +3 -1
  266. package/dist/core/task-spec-members.js +19 -3
  267. package/dist/core/task-spec.d.ts +48 -22
  268. package/dist/core/tool-catalog-entries.js +2 -0
  269. package/dist/core/tool-gate-phase.d.ts +6 -3
  270. package/dist/core/tool-gate-phase.js +1 -0
  271. package/dist/core/tool-mount-facts.d.ts +8 -4
  272. package/dist/core/tool-mount-facts.js +7 -2
  273. package/dist/core/tool-mount-plan.d.ts +3 -1
  274. package/dist/core/tool-mount-plan.js +10 -3
  275. package/dist/core/tool-mount-static.d.ts +1 -1
  276. package/dist/core/tool-mount-static.js +4 -2
  277. package/dist/core/tool-result-store.d.ts +56 -3
  278. package/dist/core/tool-result-store.js +219 -25
  279. package/dist/core/tool-spec.d.ts +9 -2
  280. package/dist/core/trace.d.ts +3 -3
  281. package/dist/core/user-attachment.d.ts +5 -1
  282. package/dist/core/user-attachment.js +14 -7
  283. package/dist/core/wiring-manifest.d.ts +26 -20
  284. package/dist/core/wiring-manifest.js +7 -3
  285. package/dist/core/workflow-journal-store.d.ts +53 -10
  286. package/dist/core/workflow-journal-store.js +27 -4
  287. package/dist/core/workflow-run-store-contract.js +16 -0
  288. package/dist/core/workflow-run-store.d.ts +9 -7
  289. package/dist/core/workflow-run-store.js +4 -1
  290. package/dist/engine/execution-env/node-execution-env.d.ts +75 -1
  291. package/dist/engine/execution-env/node-execution-env.js +227 -13
  292. package/dist/engine/harness/types.d.ts +49 -1
  293. package/dist/engine/harness/types.js +10 -0
  294. package/dist/engine/llm/types.d.ts +13 -7
  295. package/dist/engine/llm/validation.d.ts +8 -1
  296. package/dist/engine/llm/validation.js +31 -2
  297. package/dist/engine/lsp/node-lsp-manager.js +2 -1
  298. package/dist/engine/session/import-validate.js +6 -1
  299. package/dist/engine/session/session.d.ts +15 -2
  300. package/dist/engine/session/session.js +34 -4
  301. package/dist/host-env.d.ts +10 -0
  302. package/dist/host-env.js +1 -0
  303. package/dist/index.d.ts +28 -9
  304. package/dist/index.js +22 -6
  305. package/dist/internal/harness-types.d.ts +1 -1
  306. package/dist/orchestration/goal.js +1 -1
  307. package/dist/orchestration/run-workflow-tool.js +40 -32
  308. package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
  309. package/dist/orchestration/workflow-park-adoption.js +47 -12
  310. package/dist/orchestration/workflow-primitives.js +10 -1
  311. package/dist/orchestration/workflow-script-runner.d.ts +2 -2
  312. package/dist/orchestration/workflow-stop.d.ts +128 -0
  313. package/dist/orchestration/workflow-stop.js +156 -0
  314. package/dist/orchestration/workflow.d.ts +31 -7
  315. package/dist/orchestration/workflow.js +119 -57
  316. package/dist/prompts/manager-recipe.d.ts +18 -0
  317. package/dist/prompts/manager-recipe.js +24 -0
  318. package/dist/shell/lex.d.ts +2 -2
  319. package/dist/shell/lex.js +1 -1
  320. package/dist/stores/file/permission-rule-store.d.ts +3 -1
  321. package/dist/stores/file/permission-rule-store.js +0 -1
  322. package/dist/stores/file/workflow-journal-store.d.ts +16 -3
  323. package/dist/stores/file/workflow-journal-store.js +93 -5
  324. package/dist/stores/file/workflow-run-store.d.ts +1 -1
  325. package/dist/tools/fs/bash-model-shell.d.ts +23 -0
  326. package/dist/tools/fs/bash-model-shell.js +25 -0
  327. package/dist/tools/fs/bash-readonly-classifier.d.ts +6 -0
  328. package/dist/tools/fs/bash-readonly-classifier.js +3 -0
  329. package/dist/tools/fs/file-write-check.js +9 -3
  330. package/dist/tools/fs/fs-bash.js +13 -11
  331. package/dist/tools/fs/index.d.ts +8 -7
  332. package/dist/tools/fs/index.js +4 -4
  333. package/dist/tools/fs/read-deny-home.d.ts +1 -1
  334. package/dist/tools/fs/read-deny-home.js +5 -5
  335. package/dist/tools/fs/read-deny.d.ts +33 -8
  336. package/dist/tools/fs/read-deny.js +114 -25
  337. package/dist/tools/fs/safety.d.ts +4 -1
  338. package/dist/tools/fs/safety.js +4 -2
  339. package/dist/tools/fs/shell-read-argv.js +1 -0
  340. package/dist/tools/fs/shell-read-check.d.ts +9 -2
  341. package/dist/tools/fs/shell-read-check.js +134 -22
  342. package/dist/tools/fs/shell-read-establish.d.ts +9 -0
  343. package/dist/tools/fs/shell-read-establish.js +21 -11
  344. package/dist/tools/fs/shell-read-judge.d.ts +13 -1
  345. package/dist/tools/fs/shell-read-judge.js +26 -7
  346. package/dist/tools/fs/shell-read-plan.d.ts +7 -3
  347. package/dist/tools/fs/shell-read-plan.js +8 -5
  348. package/dist/tools/fs/shell-read-word.d.ts +8 -0
  349. package/dist/tools/fs/shell-read-word.js +13 -4
  350. package/dist/tools/fs/shell-read-write-targets.js +17 -9
  351. package/dist/tools/monitor.js +12 -8
  352. package/dist/tools/scheduler-tools.d.ts +1 -0
  353. package/dist/tools/scheduler-tools.js +5 -2
  354. package/package.json +3 -2
  355. package/test/export-surface.snapshot.json +192 -3
  356. package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
  357. package/wire-changes/answers/core-stores-sql@7.74.0.json +7 -0
  358. package/wire-changes/answers/core@7.73.0.json +216 -0
  359. package/wire-changes/answers/core@7.74.0.json +68 -0
  360. package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
  361. package/wire-changes/answers/mods-kernel@7.74.0.json +21 -0
  362. package/wire-changes/answers/primitives@7.73.0.json +12 -0
  363. package/wire-changes/answers/primitives@7.74.0.json +7 -0
  364. package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
  365. package/wire-changes/answers/wiki-gate@7.74.0.json +8 -0
  366. package/wire-changes/core-stores-sql@7.73.0.json +326 -0
  367. package/wire-changes/core-stores-sql@7.74.0.json +143 -0
  368. package/wire-changes/core@7.73.0.json +6480 -0
  369. package/wire-changes/core@7.74.0.json +2210 -0
  370. package/wire-changes/mods-kernel@7.73.0.json +147 -0
  371. package/wire-changes/mods-kernel@7.74.0.json +421 -0
  372. package/wire-changes/primitives@7.73.0.json +227 -0
  373. package/wire-changes/primitives@7.74.0.json +174 -0
  374. package/wire-changes/wiki-gate@7.73.0.json +145 -0
  375. package/wire-changes/wiki-gate@7.74.0.json +145 -0
@@ -0,0 +1,55 @@
1
+ const K = new Uint32Array([
2
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe,
3
+ 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
4
+ 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
5
+ 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
6
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
7
+ ]);
8
+ const H0 = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
9
+ const rotr = (x, n) => (x >>> n) | (x << (32 - n));
10
+ export function sha256Hex(data) {
11
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
12
+ const blocks = Math.ceil((bytes.length + 9) / 64);
13
+ const padded = new Uint8Array(blocks * 64);
14
+ padded.set(bytes);
15
+ padded[bytes.length] = 0x80;
16
+ const view = new DataView(padded.buffer);
17
+ const bits = bytes.length * 8;
18
+ view.setUint32(padded.length - 8, Math.floor(bits / 0x1_0000_0000));
19
+ view.setUint32(padded.length - 4, bits >>> 0);
20
+ const h = [...H0];
21
+ const w = new Uint32Array(64);
22
+ for (let block = 0; block < blocks; block++) {
23
+ for (let t = 0; t < 16; t++)
24
+ w[t] = view.getUint32(block * 64 + t * 4);
25
+ for (let t = 16; t < 64; t++) {
26
+ const x = w[t - 15];
27
+ const y = w[t - 2];
28
+ const s0 = rotr(x, 7) ^ rotr(x, 18) ^ (x >>> 3);
29
+ const s1 = rotr(y, 17) ^ rotr(y, 19) ^ (y >>> 10);
30
+ w[t] = (w[t - 16] + s0 + w[t - 7] + s1) >>> 0;
31
+ }
32
+ let [a, b, c, d, e, f, g, hh] = h;
33
+ for (let t = 0; t < 64; t++) {
34
+ const t1 = (hh + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + ((e & f) ^ (~e & g)) + K[t] + w[t]) >>> 0;
35
+ const t2 = ((rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + ((a & b) ^ (a & c) ^ (b & c))) >>> 0;
36
+ hh = g;
37
+ g = f;
38
+ f = e;
39
+ e = (d + t1) >>> 0;
40
+ d = c;
41
+ c = b;
42
+ b = a;
43
+ a = (t1 + t2) >>> 0;
44
+ }
45
+ h[0] = (h[0] + a) >>> 0;
46
+ h[1] = (h[1] + b) >>> 0;
47
+ h[2] = (h[2] + c) >>> 0;
48
+ h[3] = (h[3] + d) >>> 0;
49
+ h[4] = (h[4] + e) >>> 0;
50
+ h[5] = (h[5] + f) >>> 0;
51
+ h[6] = (h[6] + g) >>> 0;
52
+ h[7] = (h[7] + hh) >>> 0;
53
+ }
54
+ return h.map((x) => x.toString(16).padStart(8, "0")).join("");
55
+ }
@@ -4,3 +4,4 @@ export { DEFAULT_MOD_BUDGET_MS, CATCH_BUDGET_MS, RUNAWAY_AFTER_MS, POST_ABORT_GR
4
4
  export { MOD_FAILURE_CAUSES, type ModFailureCause, type ModEventPayload, type ModAnswerCheck, type ModAnswerRanks, type ModDispatchRun, type ModAnswerer, type ModMatcher, type ModSkip, } from "./site-rules.js";
5
5
  export { ENGINE_ORIGIN, MODS_INVALID_CODE, MODS_REGISTRATION_REFUSED_CODE, MODS_REGISTRATION_REFUSED_DEPLOYMENT_CODE, MOD_TRACE_OUTCOMES, type ModTraceOutcome, type ModUses, type ModOrigin, type ModPluginFacts, type ModDollarBase, type ModTraceEntry, type ModCaughtError, type ModNext, type ModHandler, type ModHandlerOptions, type ModEventPair, type ModEventMap, type ModTypedNext, type ModTypedHandler, type On, type MappedOn, type ModRegistration, type ModAdmissionRecord, type ModSeats, } from "./registration.js";
6
6
  export { admitMods, type ModFrame, type ModBottomContext, type ModMethodBottom, type ModMethodSeat, type ModMethodBottoms, type ModCallEntry, type ModCallEntries, type ModDispatchOutcome, type ModDispatchOptions, type ModParticipant, type ModBus, type ModMountedHandler, type ModBusInput, type ModTimer, } from "./dispatch.js";
7
+ export { MOD_PACKAGE_FILES, readModPackage, type ModPackageSource, type ModPackageRead, type ModPackageUnreadMember } from "./package-reader.js";
@@ -3,3 +3,4 @@ export { DEFAULT_MOD_BUDGET_MS, CATCH_BUDGET_MS, RUNAWAY_AFTER_MS, POST_ABORT_GR
3
3
  export { MOD_FAILURE_CAUSES, } from "./site-rules.js";
4
4
  export { ENGINE_ORIGIN, MODS_INVALID_CODE, MODS_REGISTRATION_REFUSED_CODE, MODS_REGISTRATION_REFUSED_DEPLOYMENT_CODE, MOD_TRACE_OUTCOMES, } from "./registration.js";
5
5
  export { admitMods, } from "./dispatch.js";
6
+ export { MOD_PACKAGE_FILES, readModPackage } from "./package-reader.js";
@@ -0,0 +1,48 @@
1
+ import { type ModBusSide } from "./events.js";
2
+ import { type ModUses } from "./registration.js";
3
+ /** The two manifests, by their path inside the package (`/`-separated on every platform). */
4
+ export declare const MOD_PACKAGE_FILES: Readonly<{
5
+ readonly plugin: ".claude-plugin/plugin.json";
6
+ readonly hooks: "hooks/hooks.json";
7
+ }>;
8
+ /** What the host hands the reader: never read from the package. */
9
+ export interface ModPackageSource {
10
+ /** The bytes of `.claude-plugin/plugin.json` and of `hooks/hooks.json`. */
11
+ readonly plugin: Uint8Array;
12
+ readonly hooks: Uint8Array;
13
+ /** Reads the hooks module, named by its path inside the package (`hooks/…`, `/`-separated); asked once, after both manifests
14
+ * are judged. It IS the containment: it must refuse a path that leaves the package directory, a link included — the reader
15
+ * judges the name's form only, never where the bytes came from. What it throws comes out as thrown. */
16
+ readonly readModule: (path: string) => Uint8Array | Promise<Uint8Array>;
17
+ /** The bus the host reads the package for. */
18
+ readonly side: ModBusSide;
19
+ /** The digest the host pinned: other bytes are refused (`detail.digest { expected, actual }`) before a module byte is handed
20
+ * out. A match proves the bytes are the pinned ones, nothing more: the digest is not admission. */
21
+ readonly expectDigest?: string;
22
+ }
23
+ /** A member of a manifest the reader does not read, by its name as written. */
24
+ export interface ModPackageUnreadMember {
25
+ readonly file: string;
26
+ readonly name: string;
27
+ }
28
+ /** A package read: its facts as it states them, and the bytes they were read from. */
29
+ export interface ModPackageRead {
30
+ /** `plugin.json`'s `name` as stated (the kernel's screen judges it at admission). */
31
+ readonly name: unknown;
32
+ /** `hooks.json`'s `uses`: every item selects a name on the host's side, one at least of that side's own. */
33
+ readonly uses: ModUses;
34
+ /** `hooks.json`'s `contract` as stated: the importing copy compares it with its own `KERNEL_CONTRACT_VERSION`. */
35
+ readonly contract: unknown;
36
+ /** The members of the two files the reader does not read (`plugin.json`'s first, each in its parsed object's key order; a member
37
+ * of `hooks.json`'s `uses` other than `events` and `calls` by its dotted name, `uses.<name>`, after that file's own). */
38
+ readonly unread: readonly ModPackageUnreadMember[];
39
+ /** The hooks module's path inside the package (as `readModule` was asked for it) and its bytes, those the digest was taken over. */
40
+ readonly modulePath: string;
41
+ readonly module: Uint8Array;
42
+ /** The sha256 (lowercase hex) of the newline-joined sha256 of `plugin.json`, `hooks.json` and the module, in that order. */
43
+ readonly digest: string;
44
+ }
45
+ /** Read a package from its bytes; see the file's head. */
46
+ export declare function readModPackage(source: ModPackageSource): Promise<ModPackageRead>;
47
+ /** A value's kind for a sentence — never a string's text. */
48
+ export declare function kind(v: unknown): string;
@@ -0,0 +1,149 @@
1
+ import { modPackageDigest } from "./digest.js";
2
+ import { expandModPattern, expandOnSide, MOD_EVENT_TABLE } from "./events.js";
3
+ import { modsInvalid } from "./registration.js";
4
+ export const MOD_PACKAGE_FILES = Object.freeze({ plugin: ".claude-plugin/plugin.json", hooks: "hooks/hooks.json" });
5
+ const SOURCE_MEMBERS = ["plugin", "hooks", "readModule", "side", "expectDigest"];
6
+ const SHA256_HEX = /^[0-9a-f]{64}$/;
7
+ const HOST_FACT = "which is the host's to give (the seat, tier, provenance, options and budget are never read from a package)";
8
+ const HOST_FACTS = Object.freeze({ tier: HOST_FACT, provenance: HOST_FACT, seat: HOST_FACT, options: HOST_FACT, budgetMs: HOST_FACT });
9
+ const PLUGIN_SHAPE = Object.freeze({ file: MOD_PACKAGE_FILES.plugin, takes: Object.freeze(["name", "version", "description", "author"]), refuses: HOST_FACTS });
10
+ const HOOKS_SHAPE = Object.freeze({
11
+ file: MOD_PACKAGE_FILES.hooks,
12
+ takes: Object.freeze(["modules", "contract", "uses", "description"]),
13
+ refuses: Object.freeze({ ...HOST_FACTS, surface: "which names a surface module: a surface module is mounted by the client that renders it, never through hooks.json" }),
14
+ });
15
+ const USES_SHAPE = Object.freeze({ file: MOD_PACKAGE_FILES.hooks, takes: Object.freeze(["events", "calls"]), refuses: Object.freeze({}) });
16
+ const MODULE_MEMBER = `${MOD_PACKAGE_FILES.hooks}: modules[0]`;
17
+ const PATH_RULE = 'a hooks module is named by one path relative to hooks.json: "/"-separated, an optional leading "./", no empty, "." or ".." segment, no "\\" or ":", ending ".mjs"';
18
+ export async function readModPackage(source) {
19
+ const { plugin, hooks, readModule, side, expectDigest } = sourceOf(source);
20
+ const unread = [];
21
+ const pluginJson = jsonRecord(plugin, PLUGIN_SHAPE, unread);
22
+ const hooksJson = jsonRecord(hooks, HOOKS_SHAPE, unread);
23
+ const modulePath = modulePathOf(own(hooksJson, "modules"));
24
+ const uses = usesOn(own(hooksJson, "uses"), side, unread);
25
+ const answered = await readModule(modulePath);
26
+ if (!isBytes(answered))
27
+ throw modsInvalid(`${MODULE_MEMBER}: the host's readModule answered ${kind(answered)}; it answers the module's bytes`);
28
+ const module = new Uint8Array(answered);
29
+ const digest = modPackageDigest(plugin, hooks, module);
30
+ if (expectDigest !== undefined && digest !== expectDigest) {
31
+ throw Object.assign(modsInvalid(`its bytes are not the ones the host expected (digest ${digest}, expected ${expectDigest}); nothing of it is handed on`), {
32
+ detail: Object.freeze({ digest: Object.freeze({ expected: expectDigest, actual: digest }) }),
33
+ });
34
+ }
35
+ return Object.freeze({
36
+ name: own(pluginJson, "name"),
37
+ uses,
38
+ contract: own(hooksJson, "contract"),
39
+ unread: Object.freeze(unread.map((u) => Object.freeze(u))),
40
+ modulePath,
41
+ module,
42
+ digest,
43
+ });
44
+ }
45
+ function sourceOf(source) {
46
+ const form = `it is { ${SOURCE_MEMBERS.join(", ")} }`;
47
+ if (typeof source !== "object" || source === null || Array.isArray(source))
48
+ throw modsInvalid(`the package reader's argument is ${kind(source)}; ${form}`);
49
+ for (const k of Reflect.ownKeys(source)) {
50
+ if (typeof k === "symbol" || !SOURCE_MEMBERS.includes(k)) {
51
+ throw modsInvalid(`the package reader's argument carries ${typeof k === "symbol" ? "a symbol-keyed member" : JSON.stringify(k).slice(0, 66)}, a member it does not take; ${form}`);
52
+ }
53
+ }
54
+ const plugin = Reflect.get(source, "plugin");
55
+ const hooks = Reflect.get(source, "hooks");
56
+ const readModule = Reflect.get(source, "readModule");
57
+ const side = Reflect.get(source, "side");
58
+ if (!isBytes(plugin) || !isBytes(hooks))
59
+ throw modsInvalid(`the package reader's plugin and hooks are the two manifests' bytes (a Uint8Array each)`);
60
+ if (typeof readModule !== "function")
61
+ throw modsInvalid(`the package reader's readModule is ${kind(readModule)}; it is a function that reads the hooks module`);
62
+ if (side !== "engine" && side !== "surface")
63
+ throw modsInvalid(`the package reader's side is ${kind(side)}; it is the bus the host reads the package for, "engine" or "surface"`);
64
+ const expectDigest = Reflect.get(source, "expectDigest");
65
+ if (expectDigest !== undefined && (typeof expectDigest !== "string" || !SHA256_HEX.test(expectDigest))) {
66
+ throw modsInvalid(`the package reader's expectDigest is ${typeof expectDigest === "string" ? `a string of ${expectDigest.length} characters` : kind(expectDigest)}; it is a package digest, a sha256 in lowercase hex (64 characters)`);
67
+ }
68
+ return { plugin: new Uint8Array(plugin), hooks: new Uint8Array(hooks), readModule: readModule, side, expectDigest };
69
+ }
70
+ function isBytes(v) {
71
+ return ArrayBuffer.isView(v) && Object.prototype.toString.call(v) === "[object Uint8Array]";
72
+ }
73
+ function own(record, key) {
74
+ return Object.hasOwn(record, key) ? record[key] : undefined;
75
+ }
76
+ function jsonRecord(bytes, shape, unread) {
77
+ const { file, takes, refuses } = shape;
78
+ let parsed;
79
+ try {
80
+ parsed = JSON.parse(new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes));
81
+ }
82
+ catch {
83
+ throw modsInvalid(`${file}: is not JSON`);
84
+ }
85
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
86
+ throw modsInvalid(`${file}: is ${kind(parsed)}; it is a JSON object`);
87
+ unreadOf(parsed, { file, takes, refuses }, "", unread);
88
+ return parsed;
89
+ }
90
+ function unreadOf(record, shape, prefix, unread) {
91
+ const { file, takes, refuses } = shape;
92
+ for (const k of Object.keys(record)) {
93
+ if (takes.includes(k))
94
+ continue;
95
+ const why = Object.hasOwn(refuses, k) ? refuses[k] : undefined;
96
+ if (why !== undefined)
97
+ throw modsInvalid(`${file}${prefix === "" ? "" : ` ${prefix.slice(0, -1)}`}: carries "${k}", ${why}`);
98
+ unread.push({ file, name: `${prefix}${k}` });
99
+ }
100
+ }
101
+ function modulePathOf(modules) {
102
+ if (!Array.isArray(modules) || modules.length !== 1 || typeof modules[0] !== "string")
103
+ throw modsInvalid(`${MOD_PACKAGE_FILES.hooks}: modules is ${kind(modules)}; it lists exactly one path, relative to hooks.json`);
104
+ const given = modules[0];
105
+ const rest = given.startsWith("./") ? given.slice(2) : given;
106
+ const fits = rest.endsWith(".mjs") && rest.split("/").every((s) => s !== "" && s !== "." && s !== ".." && !s.includes("\\") && !s.includes(":"));
107
+ if (!fits)
108
+ throw modsInvalid(`${MODULE_MEMBER} is not a path this reader takes; ${PATH_RULE}`);
109
+ return `hooks/${rest}`;
110
+ }
111
+ function usesOn(uses, side, unread) {
112
+ const at = `${MOD_PACKAGE_FILES.hooks}: uses`;
113
+ if (typeof uses !== "object" || uses === null || Array.isArray(uses))
114
+ throw modsInvalid(`${at} is ${kind(uses)}; it declares { events, calls }, each a list of event names`);
115
+ unreadOf(uses, USES_SHAPE, "uses.", unread);
116
+ let ownSide = false;
117
+ const lists = { events: [], calls: [] };
118
+ for (const field of ["events", "calls"]) {
119
+ const list = Object.hasOwn(uses, field) ? Reflect.get(uses, field) : undefined;
120
+ if (!Array.isArray(list))
121
+ throw modsInvalid(`${at}.${field} is ${kind(list)}; it is a list of event names`);
122
+ list.forEach((item, i) => {
123
+ const where = `${at}.${field}[${i}]`;
124
+ if (typeof item !== "string")
125
+ throw modsInvalid(`${where} is ${kind(item)}; it is an event name or a "<prefix>.*" pattern`);
126
+ const selected = expandOnSide(item, side);
127
+ if ("refusal" in selected) {
128
+ throw modsInvalid("refusal" in expandModPattern(item)
129
+ ? `${where} is not an event name, or a "<prefix>.*" pattern, that selects a name the kernel knows`
130
+ : `${where} selects only the ${side === "engine" ? "surface" : "engine"} side's names, and the host reads this package for the ${side} bus`);
131
+ }
132
+ if (selected.names.some((n) => MOD_EVENT_TABLE[n].side === side))
133
+ ownSide = true;
134
+ lists[field].push(item);
135
+ });
136
+ }
137
+ if (!ownSide)
138
+ throw modsInvalid(`${at} selects no name of the ${side} side's own — only names both buses read, or none — so it does not say it is a package for the ${side} bus; a package declares one ${side} event or method at least`);
139
+ return Object.freeze({ events: Object.freeze(lists.events), calls: Object.freeze(lists.calls) });
140
+ }
141
+ export function kind(v) {
142
+ if (v === undefined)
143
+ return "absent";
144
+ if (v === null)
145
+ return "null";
146
+ if (Array.isArray(v))
147
+ return `a list of ${v.length}`;
148
+ return typeof v === "number" || typeof v === "boolean" ? String(v) : `a ${typeof v}`;
149
+ }
@@ -112,6 +112,10 @@ export declare function pinnedHandOn(pinned: readonly string[], held: ModEventPa
112
112
  };
113
113
  /** Why a handler's answer breaks the site, or undefined. No answer at all is never an answer. */
114
114
  export declare function answerViolation(answer: unknown, check: ModAnswerCheck | undefined, e: ModEventPayload, by: ModAnswerer, below: readonly unknown[], run: ModDispatchRun): string | undefined;
115
+ /** A `closed` station's reading: the handed-on payload holds the dispatch's own event's members, no other and none fewer. */
116
+ export declare function sameMembers(handed: ModEventPayload, e0: ModEventPayload): boolean;
117
+ /** An `answers` station's reading of an answer of a handler's own (received): a record of the row's members alone. Never quotes it. */
118
+ export declare function ownAnswerViolation(answer: unknown, answers: readonly string[]): string | undefined;
115
119
  /** A station's reading of what a handler hands on (and of who hands it on): its sentence, or undefined (no check, or the
116
120
  * payload passes). A check that throws is a sentence too — the station could not read the payload, so it is not handed on. */
117
121
  export declare function handOnViolation(payload: ModEventPayload, check: ((payload: ModEventPayload, by: ModAnswerer) => string | undefined) | undefined, by: ModAnswerer): string | undefined;
@@ -211,6 +211,19 @@ export function answerViolation(answer, check, e, by, below, run) {
211
211
  return "returned an answer the station cannot read";
212
212
  }
213
213
  }
214
+ export function sameMembers(handed, e0) {
215
+ const mine = Object.keys(e0);
216
+ return Object.keys(handed).length === mine.length && mine.every((k) => Object.hasOwn(handed, k));
217
+ }
218
+ export function ownAnswerViolation(answer, answers) {
219
+ const takes = answers.length === 0 ? "it answers only what its next(e) answered" : `an answer of its own is a record of ${answers.join(", ")} alone, or what its next(e) answered`;
220
+ if (answers.length === 0)
221
+ return `returned an answer of its own — ${takes}`;
222
+ if (!isPlainRecord(answer))
223
+ return `returned an answer of its own that is not a record — ${takes}`;
224
+ const outside = Object.keys(answer).filter((k) => !answers.includes(k)).length;
225
+ return outside > 0 ? `returned an answer of its own with ${outside} member(s) this station does not take — ${takes}` : undefined;
226
+ }
214
227
  export function handOnViolation(payload, check, by) {
215
228
  if (check === undefined)
216
229
  return undefined;
@@ -8,10 +8,14 @@ export interface ModPackageHost {
8
8
  readonly provenance?: string;
9
9
  /** The values handed to the package's `register(on, options)`. */
10
10
  readonly options?: unknown;
11
+ /** The package digest the host pinned (lowercase hex): a package whose bytes give another is refused, `detail.digest
12
+ * { expected, actual }`, before anything of it is imported. A match proves only that the bytes are the pinned ones — it is not
13
+ * admission: which package may run in this process is the host's decision, made before it asks for one. */
14
+ readonly expectDigest?: string;
11
15
  }
12
16
  /** A member of `plugin.json` or `hooks.json` this reader does not read: the package loaded without it. */
13
17
  export interface ModPackageUnreadKey {
14
- /** The file it stands in, relative to the package (`.claude-plugin/plugin.json` or `hooks/hooks.json`, in the platform's separator). */
18
+ /** The file it stands in, relative to the package (`.claude-plugin/plugin.json` or `hooks/hooks.json`, `/`-separated on every platform). */
15
19
  readonly file: string;
16
20
  /** The member's name, spelled as a foreign line: one line, the name whole up to 60 characters (a longer one: its first 60
17
21
  * and the cut mark; the fence's defusing of a sentinel such as `<<<` may lengthen what is kept). Never its value. */
@@ -20,13 +24,13 @@ export interface ModPackageUnreadKey {
20
24
  /** A package read into a registration, with the identity of the bytes it was read from. */
21
25
  export interface ModPackageRegistration extends EngineModRegistration {
22
26
  /**
23
- * The sha256 (lowercase hex) of the three files this reader read, in this order — `plugin.json`, `hooks.json`, the
27
+ * The sha256 (lowercase hex) of the three files the reader read, in this order — `plugin.json`, `hooks.json`, the
24
28
  * hooks module — taken as the newline-joined sha256 of each file's bytes. One changed byte in any of the three changes
25
29
  * it. The module is imported from those bytes, so this names the module that runs; what its code loads beyond them (an
26
30
  * absolute URL, a file it reads) is not among them.
27
31
  */
28
32
  readonly digest: string;
29
- /** The members of the two files this reader does not read (`plugin.json`'s first, each in its parsed object's key order),
33
+ /** The members of the two files the reader does not read (`plugin.json`'s first, each in its parsed object's key order),
30
34
  * each also told as a `mods.package_key_unread` notice. Present iff there is one. */
31
35
  readonly unread?: readonly ModPackageUnreadKey[];
32
36
  }
@@ -1,68 +1,60 @@
1
- import { createHash } from "node:crypto";
2
1
  import { constants } from "node:fs";
3
2
  import { open, stat } from "node:fs/promises";
4
- import { extname, isAbsolute, join, relative, resolve, sep } from "node:path";
5
- import { KERNEL_CONTRACT_VERSION } from "./kernel/index.js";
3
+ import { isAbsolute, relative, resolve, sep } from "node:path";
4
+ import { KERNEL_CONTRACT_VERSION, MOD_PACKAGE_FILES, MODS_INVALID_CODE, readModPackage } from "./kernel/index.js";
5
+ import { kind } from "./kernel/package-reader.js";
6
6
  import { modsInvalid } from "./kernel/registration.js";
7
7
  import { physicalPathOfAsync } from "../physical-path.js";
8
8
  import { describeThrown } from "../tool-policy.js";
9
9
  import { foreignLine } from "../protocol-http-auth.js";
10
10
  import { deliverEngineNotice } from "../engine-notice.js";
11
11
  import { callerKey } from "../caller-text.js";
12
- const PLUGIN_FILE = join(".claude-plugin", "plugin.json");
13
- const HOOKS_FILE = join("hooks", "hooks.json");
14
- const HOST_FACT = "which is the host's to give (the seat, tier, provenance, options and budget are never read from a package)";
15
- const HOST_FACTS = { tier: HOST_FACT, provenance: HOST_FACT, seat: HOST_FACT, options: HOST_FACT, budgetMs: HOST_FACT };
16
- const PLUGIN_SHAPE = { file: PLUGIN_FILE, takes: ["name", "version", "description", "author"], refuses: HOST_FACTS };
17
- const HOOKS_SHAPE = {
18
- file: HOOKS_FILE,
19
- takes: ["modules", "contract", "uses", "description"],
20
- refuses: { ...HOST_FACTS, surface: "which names a surface module: a surface module is mounted by the client that renders it, never by this engine" },
21
- };
12
+ import { refuseStrayMembers } from "../own-property-receipt.js";
22
13
  const KEY_SPELLING_MAX = 60;
23
14
  const ROOT_SPELLING_MAX = 1024;
24
- const MODULE_EXTENSION = ".mjs";
15
+ const MODULE_MEMBER = `${MOD_PACKAGE_FILES.hooks}: modules[0]`;
25
16
  const MODULE_URL_HEAD = "data:text/javascript;base64,";
26
17
  const MODULE_URL_TEXT = /data:text\/javascript;base64,[A-Za-z0-9+/=]*/g;
27
18
  export async function loadModPackage(dir, host = {}) {
19
+ closedHost(dir, host);
28
20
  const root = await realRoot(dir);
29
- const refuse = (file, why) => modsInvalid(`mod package ${root}: ${file}: ${why}`);
30
- const pluginFile = await packageFile(root, PLUGIN_FILE, refuse);
31
- const unread = [];
32
- const plugin = jsonRecord(pluginFile.bytes, PLUGIN_SHAPE, refuse, unread);
33
- const hooksFile = await packageFile(root, HOOKS_FILE, refuse);
34
- const hooks = jsonRecord(hooksFile.bytes, HOOKS_SHAPE, refuse, unread);
35
- const contract = hooks["contract"];
36
- if (contract !== KERNEL_CONTRACT_VERSION) {
37
- throw refuse(HOOKS_FILE, `contract is ${kind(contract)}; this engine's mods kernel is contract ${KERNEL_CONTRACT_VERSION}, and a package loads only under the contract it was written against`);
21
+ try {
22
+ return await loadFrom(root, host);
23
+ }
24
+ catch (err) {
25
+ if (typeof err === "object" && err !== null && Reflect.get(err, "code") === MODS_INVALID_CODE) {
26
+ const detail = Reflect.get(err, "detail");
27
+ throw Object.assign(modsInvalid(`mod package ${root}: ${err.message}`), detail !== undefined ? { detail } : {});
28
+ }
29
+ throw err;
30
+ }
31
+ }
32
+ async function loadFrom(root, host) {
33
+ const plugin = await packageFile(root, MOD_PACKAGE_FILES.plugin, MOD_PACKAGE_FILES.plugin);
34
+ const hooks = await packageFile(root, MOD_PACKAGE_FILES.hooks, MOD_PACKAGE_FILES.hooks);
35
+ const expectDigest = host.expectDigest;
36
+ const read = await readModPackage({ plugin, hooks, readModule: (path) => packageFile(root, path, MODULE_MEMBER), side: "engine", ...(expectDigest !== undefined ? { expectDigest } : {}) });
37
+ if (read.contract !== KERNEL_CONTRACT_VERSION) {
38
+ const stated = typeof read.contract === "number" ? read.contract : null;
39
+ throw Object.assign(modsInvalid(`${MOD_PACKAGE_FILES.hooks}: contract is ${kind(read.contract)}; this engine's mods kernel is contract ${KERNEL_CONTRACT_VERSION}, and a package loads only under the contract it was written against`), { detail: Object.freeze({ contract: Object.freeze({ stated, kernel: KERNEL_CONTRACT_VERSION }) }) });
38
40
  }
39
- const modules = hooks["modules"];
40
- if (!Array.isArray(modules) || modules.length !== 1 || typeof modules[0] !== "string")
41
- throw refuse(HOOKS_FILE, `modules is ${kind(modules)}; it lists exactly one path, relative to hooks.json`);
42
- const given = modules[0];
43
- const shown = foreignLine(given, 120);
44
- if (given === "" || isAbsolute(given))
45
- throw refuse(HOOKS_FILE, `modules names "${shown}"; the path is relative to hooks.json`);
46
- if (extname(given) !== MODULE_EXTENSION)
47
- throw refuse(HOOKS_FILE, `modules names "${shown}"; a hooks module is an ES module named ${MODULE_EXTENSION}`);
48
- const moduleFile = await packageFile(root, join("hooks", given), (_file, why) => refuse(HOOKS_FILE, `modules names "${shown}": ${why}`));
49
- const digest = sha256([pluginFile.bytes, hooksFile.bytes, moduleFile.bytes].map(sha256).join("\n"));
50
41
  let ns;
51
42
  try {
52
- ns = await import(`${MODULE_URL_HEAD}${moduleFile.bytes.toString("base64")}`);
43
+ ns = await import(`${MODULE_URL_HEAD}${Buffer.from(read.module.buffer, read.module.byteOffset, read.module.byteLength).toString("base64")}`);
53
44
  }
54
45
  catch (err) {
55
- const said = describeThrown(err).replace(MODULE_URL_TEXT, moduleFile.inside);
56
- throw refuse(moduleFile.inside, `could not be imported (${said}); a hooks module is imported from its own bytes, so it is one self-contained file: a relative or package import has nothing to resolve from`);
46
+ const said = describeThrown(err).replace(MODULE_URL_TEXT, MODULE_MEMBER);
47
+ throw modsInvalid(`${MODULE_MEMBER}: could not be imported (${said}); a hooks module is imported from its own bytes, so it is one self-contained file: a relative or package import has nothing to resolve from`);
57
48
  }
49
+ const unread = read.unread.map((u) => ({ file: u.file, key: foreignLine(u.name, KEY_SPELLING_MAX), name: u.name }));
58
50
  const registration = Object.freeze({
59
- name: plugin["name"],
60
- uses: hooks["uses"],
51
+ name: read.name,
52
+ uses: read.uses,
61
53
  ...(host.tier !== undefined ? { tier: host.tier } : {}),
62
54
  ...(host.provenance !== undefined ? { provenance: host.provenance } : {}),
63
55
  ...(host.options !== undefined ? { options: host.options } : {}),
64
56
  register: (typeof ns === "object" && ns !== null ? Reflect.get(ns, "register") : undefined),
65
- digest,
57
+ digest: read.digest,
66
58
  ...(unread.length > 0 ? { unread: Object.freeze(unread.map((u) => Object.freeze({ file: u.file, key: u.key }))) } : {}),
67
59
  });
68
60
  const shownRoot = foreignLine(root, ROOT_SPELLING_MAX);
@@ -75,6 +67,13 @@ export async function loadModPackage(dir, host = {}) {
75
67
  }
76
68
  return registration;
77
69
  }
70
+ const HOST_MEMBERS = ["tier", "provenance", "options", "expectDigest"];
71
+ function closedHost(dir, host) {
72
+ if (typeof host !== "object" || host === null || Array.isArray(host)) {
73
+ throw modsInvalid(`mod package ${dir}: the host's argument is ${kind(host)}; it is { ${HOST_MEMBERS.map((k) => `${k}?`).join(", ")} }`);
74
+ }
75
+ refuseStrayMembers(host, { subject: "the host's argument", unit: "member", moment: "at loadModPackage" }, HOST_MEMBERS, (sentence) => modsInvalid(`mod package ${dir}: ${sentence}`));
76
+ }
78
77
  async function realRoot(dir) {
79
78
  try {
80
79
  const root = await physicalPathOfAsync(dir);
@@ -85,61 +84,29 @@ async function realRoot(dir) {
85
84
  }
86
85
  throw modsInvalid(`mod package ${dir}: not a directory`);
87
86
  }
88
- async function packageFile(root, file, refuse) {
87
+ async function packageFile(root, path, said) {
89
88
  let real;
90
89
  try {
91
- real = await physicalPathOfAsync(resolve(root, file));
90
+ real = await physicalPathOfAsync(resolve(root, ...path.split("/")));
92
91
  }
93
92
  catch {
94
- throw refuse(file, "is not in the package; a mod package carries it");
93
+ throw modsInvalid(`${said}: is not in the package; a mod package carries it`);
95
94
  }
96
95
  const inside = relative(root, real);
97
96
  if (inside === "" || inside === ".." || inside.startsWith(`..${sep}`) || isAbsolute(inside))
98
- throw refuse(file, "resolves outside the package");
97
+ throw modsInvalid(`${said}: resolves outside the package`);
99
98
  let handle;
100
99
  try {
101
100
  handle = await open(real, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
102
101
  if (!(await handle.stat()).isFile())
103
- throw new Error("not a regular file");
104
- return { inside, bytes: await handle.readFile() };
102
+ throw Object.assign(new Error("not a regular file"), { code: "not a regular file" });
103
+ return await handle.readFile();
105
104
  }
106
105
  catch (err) {
107
- throw refuse(file, `could not be read as a regular file of the package (${describeThrown(err)})`);
106
+ const code = typeof err === "object" && err !== null ? Reflect.get(err, "code") : undefined;
107
+ throw modsInvalid(`${said}: could not be read as a regular file of the package (${typeof code === "string" ? code : describeThrown(err)})`);
108
108
  }
109
109
  finally {
110
110
  await handle?.close();
111
111
  }
112
112
  }
113
- function jsonRecord(bytes, shape, refuse, unread) {
114
- const { file, takes, refuses } = shape;
115
- let parsed;
116
- try {
117
- parsed = JSON.parse(bytes.toString("utf8"));
118
- }
119
- catch {
120
- throw refuse(file, "is not JSON");
121
- }
122
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
123
- throw refuse(file, `is ${kind(parsed)}; it is a JSON object`);
124
- for (const k of Object.keys(parsed)) {
125
- if (takes.includes(k))
126
- continue;
127
- const why = Object.hasOwn(refuses, k) ? refuses[k] : undefined;
128
- if (why !== undefined)
129
- throw refuse(file, `carries ${callerKey(k)}, ${why}`);
130
- unread.push({ file, key: foreignLine(k, KEY_SPELLING_MAX), name: k });
131
- }
132
- return parsed;
133
- }
134
- function sha256(data) {
135
- return createHash("sha256").update(data).digest("hex");
136
- }
137
- function kind(v) {
138
- if (v === undefined)
139
- return "absent";
140
- if (v === null)
141
- return "null";
142
- if (Array.isArray(v))
143
- return `a list of ${v.length}`;
144
- return typeof v === "number" || typeof v === "boolean" ? String(v) : `a ${typeof v}`;
145
- }
@@ -8,6 +8,12 @@ export function receiptRefusal(message) {
8
8
  e.code = "config.invalid_argument";
9
9
  return e;
10
10
  }
11
+ function walkRefusal(message, member) {
12
+ const e = receiptRefusal(message);
13
+ if (member !== undefined)
14
+ e.member = member;
15
+ return e;
16
+ }
11
17
  export function refuseProxy(given, words) {
12
18
  if (types.isProxy(given))
13
19
  throw receiptRefusal(`${words.subject} must be a plain object, not a Proxy: its ${words.unit}s are read once off its own descriptors, and a Proxy would run its traps in that read — refused rather than wired through it`);
@@ -51,12 +57,13 @@ function readCaptured(given, words) {
51
57
  const received = receive(given, CONFIG_RECEIPT_MODE);
52
58
  if (received.ok)
53
59
  return received.value;
54
- const name = received.fault.path[0] ?? "";
60
+ const member = received.fault.path[0];
61
+ const name = member ?? "";
55
62
  if (received.fault.kind === "getter-threw")
56
- throw receiptRefusal(`${words.subject}.${name} threw while it was read ${words.moment} — a ${words.unit} is read once, here; refused rather than wired without it`);
63
+ throw walkRefusal(`${words.subject}.${name} threw while it was read ${words.moment} — a ${words.unit} is read once, here; refused rather than wired without it`, member);
57
64
  if (received.fault.kind === "prototype-moved")
58
- throw receiptRefusal(`${words.subject}'s prototype changed while its ${words.unit}s were read ${words.moment} — refused rather than wired from a moving object`);
59
- throw receiptRefusal(`${words.subject} could not be read ${words.moment}: ${describeFault(received.fault)} — refused rather than wired without it`);
65
+ throw walkRefusal(`${words.subject}'s prototype changed while its ${words.unit}s were read ${words.moment} — refused rather than wired from a moving object`, member);
66
+ throw walkRefusal(`${words.subject} could not be read ${words.moment}: ${describeFault(received.fault)} — refused rather than wired without it`, member);
60
67
  }
61
68
  function strayMembersSentence(words, stray, keys) {
62
69
  const named = stray.map((k) => {
@@ -15,8 +15,9 @@ import { type TaskSandboxSettings } from "./command-sandbox.js";
15
15
  import type { ToolExecuteContext } from "./tool-spec.js";
16
16
  import type { FastModeLeg } from "./runner/fast-mode-seat.js";
17
17
  import type { TaskSpec } from "./types.js";
18
+ import { type ProjectSeat } from "./project-seat.js";
18
19
  /** The fields of a spec the seat carries — one `Pick`, shared by the mint's input and the apply's target. */
19
- export type ParentSpecSeatFields = Pick<TaskSpec, "principal" | "isolationScope" | "oneShot" | "clientContext" | "onQuestion" | "mods" | "additionalDirectories" | "additionalReadDirectories" | "envFacts" | "sandbox" | "memoryPersistenceCapable" | "classifyAllShell" | "memory" | "compaction" | "skillListingBudgetFraction" | "skillListingMaxDescChars" | "fileHistory" | "projectMemory" | "promptForm" | "promptBinding" | "promptLocale" | "advisorModel" | "attachments" | "language" | "instructionFamily" | "fastMode" | "projectId">;
20
+ export type ParentSpecSeatFields = Pick<TaskSpec, "principal" | "isolationScope" | "oneShot" | "clientContext" | "onQuestion" | "mods" | "additionalDirectories" | "additionalReadDirectories" | "envFacts" | "sandbox" | "memoryPersistenceCapable" | "classifyAllShell" | "memory" | "compaction" | "skillListingBudgetFraction" | "skillListingMaxDescChars" | "fileHistory" | "projectMemory" | "promptForm" | "promptBinding" | "promptLocale" | "advisorModel" | "attachments" | "language" | "instructionFamily" | "fastMode" | "project">;
20
21
  /**
21
22
  * The seat a run hands its children. Every member is the parent's own value, frozen at mint (arrays copied and
22
23
  * frozen; the facts object copied). Members present iff the parent carries them — an absent member is "nothing to
@@ -88,11 +89,12 @@ export type ParentSpecSeatFields = Pick<TaskSpec, "principal" | "isolationScope"
88
89
  * word as the stream verb (`TaskStream.setFastMode`) last set it ({@link bindParentSpecSeatFastMode}), the spec's word before a
89
90
  * leg is bound — so a toggle reaches every child started after it. Not a clamp: either word travels as written. An ORDINARY
90
91
  * member (fill law): a child's own word stands.
91
- * · `projectId` — the parent leg's project-identity verdict id, bound once after `resolveSessionProject`
92
- * ({@link bindParentSpecSeatProjectId}) so delegation spawners can pass it on `RunInternals.parentProjectId` as a
93
- * low-priority default (used only when the child declares no `projectId` and its own workspace has no marker).
94
- * Deliberately NOT copied onto `TaskSpec.projectId` by {@link applyParentSpecSeat}, because a child's own workspace
95
- * marker must beat the inherited default rather than mismatch against it.
92
+ * · `project` — the parent leg's project SEAT: its verdict's id with the texts that belong to it (`SessionProjectVerdict.seat`; a
93
+ * parent judged by its marker alone hands `{ id }`), bound once after `resolveSessionProject` ({@link bindParentSpecSeatProject}).
94
+ * Every spawner hands it on `RunInternals.parentProject` as the child's DEFAULT (its id used only when the child declares no
95
+ * `project` and its own workspace has no marker; its texts only when the child's verdict is its id) — and a waker hands its own
96
+ * to the agent it wakes. Deliberately NOT copied onto `TaskSpec.project` by {@link applyParentSpecSeat}: a declaration is compared
97
+ * with the child's marker, and a child's own workspace marker must beat the inherited default rather than mismatch against it.
96
98
  */
97
99
  export interface ParentSpecSeat {
98
100
  readonly principal?: string;
@@ -123,7 +125,7 @@ export interface ParentSpecSeat {
123
125
  readonly language?: string;
124
126
  readonly instructionFamily?: TaskSpec["instructionFamily"];
125
127
  readonly fastMode?: boolean;
126
- readonly projectId?: string;
128
+ readonly project?: ProjectSeat;
127
129
  }
128
130
  /** Refuse (by name, `config.deps_retired_key`) a seat that still carries a retired member. Read at every door a seat enters
129
131
  * by hand: the ctx reader, the apply, and the send lane's waker clamps. */
@@ -131,10 +133,10 @@ export declare function assertParentSpecSeatCurrent(seat: object | undefined): v
131
133
  /** Bind the seat a leg minted to that leg's fast mode: from now on the seat's `fastMode` is what the leg asks for at the moment it
132
134
  * is read — a child started after a toggle is filled with the toggled word. Once per seat, by the leg that minted it. */
133
135
  export declare function bindParentSpecSeatFastMode(seat: ParentSpecSeat, leg: Pick<FastModeLeg, "requested">): void;
134
- /** Bind the seat a leg minted to that leg's resolved project verdict id (`sessionProject.project?.id`): from now on the seat's
135
- * `projectId` is the leg's verdict id (whether from marker or declaration, or `undefined` when absent). Bound once per seat,
136
- * after `resolveSessionProject` runs, so mount validation still runs before the marker walk. */
137
- export declare function bindParentSpecSeatProjectId(seat: ParentSpecSeat, projectId: string | undefined): void;
136
+ /** Bind the seat a leg minted to that leg's resolved project seat (`sessionProject.seat`): from now on the seat's `project` is the
137
+ * leg's (`undefined` when the leg has no verdict). Bound once per seat, after `resolveSessionProject` runs, so mount validation still
138
+ * runs before the marker walk. */
139
+ export declare function bindParentSpecSeatProject(seat: ParentSpecSeat, project: ProjectSeat | undefined): void;
138
140
  /** Mint the seat off the parent's REBOUND spec and its frozen question face (spec over deps — the caller resolves it once,
139
141
  * the same value the parent's own question routing reads). Absent fields stay absent; `oneShot` only when `true`. `fastMode` is
140
142
  * read when it is read: the bound leg's ask ({@link bindParentSpecSeatFastMode}) — `undefined` while the leg asks for nothing and