@kungfu-tech/buildchain 4.0.2-alpha.9 → 4.0.3-alpha.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 (281) hide show
  1. package/AGENTS.md +14 -5
  2. package/CONTRIBUTING.md +58 -0
  3. package/README.md +3 -3
  4. package/actions/promote-buildchain-ref/README.md +1 -1
  5. package/actions/release-candidate-promote/README.md +31 -0
  6. package/architecture/agent-change-map.md +190 -126
  7. package/architecture/{v4-architecture-constitution.md → architecture-constitution.md} +33 -30
  8. package/architecture/{v3-core-mechanism-inventory.md → baseline-core-mechanism-inventory.md} +1 -1
  9. package/architecture/{v4-bootstrap-authority.json → bootstrap-authority.json} +3 -3
  10. package/architecture/{v3-v4-capability-closure.md → capability-parity-closure.md} +3 -3
  11. package/architecture/{v3-v4-live-capability-inventory.json → capability-parity-live-capability-inventory.json} +4 -4
  12. package/architecture/{v4-capability-state-machine-manifest.json → capability-state-machine-manifest.json} +2 -2
  13. package/architecture/{v4-capability-state-machine-manifest.schema.json → capability-state-machine-manifest.schema.json} +2 -2
  14. package/architecture/ci-lane-change-budget.json +384 -0
  15. package/architecture/{v4-cross-platform-adopter-qualification.json → cross-platform-adopter-qualification.json} +4 -4
  16. package/architecture/{v4-delivery-authority-parity.json → delivery-authority-parity.json} +17 -17
  17. package/architecture/{v4-delivery-warrant-shadow-bootstrap-plan.json → delivery-warrant-shadow-bootstrap-plan.json} +4 -4
  18. package/architecture/{v4-delivery-warrant-shadow-bootstrap-plan.md → delivery-warrant-shadow-bootstrap-plan.md} +7 -7
  19. package/architecture/{v4-floating-consumer-policy.json → floating-consumer-policy.json} +2 -2
  20. package/architecture/{v4-floating-consumer-policy.md → floating-consumer-policy.md} +1 -1
  21. package/architecture/implementation-naming.json +1273 -0
  22. package/architecture/internal-capabilities.json +201 -154
  23. package/architecture/maintainability-debt.json +205 -146
  24. package/architecture/maintainability-policy.json +37 -33
  25. package/architecture/{v4-next-development-parity.json → next-development-parity.json} +12 -12
  26. package/architecture/{v4-partial-mutation-recovery-qualification.json → partial-mutation-recovery-qualification.json} +8 -5
  27. package/architecture/{v4-platform-stage-checkpoints.json → platform-stage-checkpoints.json} +3 -3
  28. package/architecture/{v4-provider-operation-journal-contract.json → provider-operation-journal-contract.json} +10 -7
  29. package/architecture/publication-facade-patches.json +64 -0
  30. package/architecture/{v4-publication-rehearsal-parity.json → publication-rehearsal-parity.json} +4 -4
  31. package/architecture/{v4-release-activation-shadow-domain.json → release-activation-shadow-domain.json} +9 -6
  32. package/architecture/release-tail-contract-inventory.json +6 -6
  33. package/architecture/{v4-release-topology.json → release-topology.json} +163 -72
  34. package/architecture/{v4-release-train-parity.json → release-train-parity.json} +2 -2
  35. package/architecture/{v4-runtime-ref-resume-authority.json → runtime-ref-resume-authority.json} +1 -1
  36. package/architecture/{v4-runtime-semantic-closure.json → runtime-semantic-closure.json} +2 -2
  37. package/architecture/{v4-rust-libnode-bridge-evaluation.json → rust-libnode-bridge-evaluation.json} +3 -3
  38. package/architecture/{v4-rust-libnode-bridge-spike.md → rust-libnode-bridge-spike.md} +6 -6
  39. package/architecture/rust-wasm-production-authority.json +58 -0
  40. package/architecture/{v4-stable-publication-fence.json → stable-publication-fence.json} +7 -4
  41. package/architecture/{v4-stage-capsule-contract.json → stage-capsule-contract.json} +1 -1
  42. package/architecture/{v4-stage-capsule-qualification.json → stage-capsule-qualification.json} +8 -8
  43. package/architecture/{v4-stage-capsule-resume-planner.json → stage-capsule-resume-planner.json} +2 -2
  44. package/architecture/{v4-stage-capsule-store-contract.json → stage-capsule-store-contract.json} +4 -4
  45. package/architecture/{v4-tail-reseal-parity.json → tail-reseal-parity.json} +35 -33
  46. package/architecture/universal-workflow-bootstrap.json +176 -0
  47. package/architecture/universal-workflow-fault-campaign.json +72 -0
  48. package/architecture/universal-workflow-train-admission.json +40 -0
  49. package/architecture/workflow-taxonomy.json +1462 -0
  50. package/bin/buildchain.mjs +10 -10
  51. package/bin/internal/adopter-delivery-cli.mjs +9 -9
  52. package/contracts/buildchain-v2-residuals-v1.json +57 -48
  53. package/contracts/dev-delivery-authority-v2.schema.json +16 -2
  54. package/contracts/fixtures/v4-tail-reseal-v1/valid.json +1 -1
  55. package/contracts/v4-canonical-contracts-v1.schema.json +1 -0
  56. package/crates/{buildchain-v4-bridge → buildchain-host-bridge}/Cargo.lock +1 -1
  57. package/crates/{buildchain-v4-bridge → buildchain-host-bridge}/Cargo.toml +1 -1
  58. package/crates/{buildchain-v4-bridge → buildchain-host-bridge}/src/main.rs +3 -3
  59. package/dist/site/buildchain-contract.json +98 -53
  60. package/dist/site/buildchain-site.json +351 -102
  61. package/dist/site/capability-registry.json +7 -7
  62. package/dist/site/controller-registry.json +50 -13
  63. package/dist/site/kfd-claims.json +2773 -1052
  64. package/dist/site/kfd-upstream-aggregate.json +1 -1
  65. package/dist/site/manual-registry.json +14 -14
  66. package/dist/site/node-api-registry.json +13176 -10733
  67. package/dist/site/page-registry.json +332 -83
  68. package/dist/site/public-surface-audit.json +3227 -1222
  69. package/dist/site/publication-authority-registry.json +1135 -363
  70. package/dist/site/publication-registry.json +4 -4
  71. package/dist/site/release-provenance.json +18 -9
  72. package/dist/site/schemas/dev-delivery-authority-v2.schema.json +16 -2
  73. package/dist/site/site-manifest.json +18 -18
  74. package/dist/site/workflow-registry.json +5367 -1931
  75. package/docs/MAP.md +5 -3
  76. package/docs/auditable-demo.md +1 -1
  77. package/docs/cli.md +21 -8
  78. package/docs/dev-delivery-warrant.md +1 -1
  79. package/docs/engineering-housekeeper.md +3 -3
  80. package/docs/kfd-support.md +26 -2
  81. package/docs/next-development-transition.md +26 -3
  82. package/docs/node-api-reference.md +618 -358
  83. package/docs/oci-publication.md +173 -0
  84. package/docs/publication-authority.md +2 -2
  85. package/docs/publish-transaction.md +36 -3
  86. package/docs/release-candidate.md +3 -3
  87. package/docs/release-flow.md +67 -19
  88. package/docs/release-governance.md +8 -8
  89. package/docs/release-passport.md +27 -2
  90. package/docs/reusable-build-surface.md +17 -1
  91. package/docs/v4-adopter-delivery.md +4 -4
  92. package/docs/v4-canonical-contracts.md +7 -7
  93. package/docs/v4-delivery-warrant-read-candidate.md +3 -3
  94. package/docs/v4-delivery-warrant-semantic-diff.md +3 -3
  95. package/docs/v4-production-release.md +77 -8
  96. package/docs/v4-publication-rehearsal.md +3 -3
  97. package/docs/v4-runtime-ref-resume-authority.md +2 -2
  98. package/docs/v4-rust-wasm-production-authority.md +58 -0
  99. package/docs/v4-stage-capsule.md +9 -9
  100. package/docs/v4-tail-reseal.md +2 -2
  101. package/docs/workflow-catalog.md +155 -0
  102. package/docs/workflow-path-migration.md +109 -0
  103. package/package.json +39 -24
  104. package/packages/compatibility/adopter-delivery.js +16 -0
  105. package/packages/compatibility/cross-platform-adopter-qualification.js +12 -0
  106. package/packages/compatibility/floating-consumer-policy.js +14 -0
  107. package/packages/compatibility/publication-qualification.js +11 -0
  108. package/packages/compatibility/publication-rehearsal.js +18 -0
  109. package/packages/compatibility/runtime-ref-resume-authority.js +13 -0
  110. package/packages/compatibility/tail-reseal-receipt.js +7 -0
  111. package/packages/compatibility/tail-reseal.js +11 -0
  112. package/packages/core/{v4-adopter-delivery-parity.js → adopter-delivery-parity.js} +12 -12
  113. package/packages/core/{v4-adopter-delivery.js → adopter-delivery.js} +24 -24
  114. package/packages/core/artifact-verification-envelope.js +5 -5
  115. package/packages/core/buildchain-contract.js +6 -6
  116. package/packages/core/buildchain-domain.wasm +0 -0
  117. package/packages/core/buildchain-kfd-claims.js +2 -2
  118. package/packages/core/buildchain-publication-authority.js +43 -26
  119. package/packages/core/{v4-canonical-contracts.js → canonical-contracts.js} +39 -103
  120. package/packages/core/ci-lane-change-budget.js +14 -1
  121. package/packages/core/controller-evidence.js +4 -1
  122. package/packages/core/{v4-cross-platform-adopter-qualification.js → cross-platform-adopter-qualification.js} +19 -19
  123. package/packages/core/{v4-delivery-warrant-fixture-runner.js → delivery-warrant-fixture-runner.js} +36 -32
  124. package/packages/core/{v4-delivery-warrant-read-candidate.js → delivery-warrant-read-candidate.js} +40 -40
  125. package/packages/core/{v4-delivery-warrant-semantic-diff-gate.js → delivery-warrant-semantic-diff-gate.js} +58 -59
  126. package/packages/core/{v4-delivery-warrant-shadow-adapter.js → delivery-warrant-shadow-adapter.js} +15 -15
  127. package/packages/core/dev-delivery-candidate-identity.js +40 -6
  128. package/packages/core/dev-delivery-execution-transfer.js +6 -6
  129. package/packages/core/dev-delivery-native-proof.js +12 -8
  130. package/packages/core/dev-delivery-warrant-legacy-recovery.js +1 -1
  131. package/packages/core/dev-delivery-warrant-native-compatibility.js +4 -4
  132. package/packages/core/dev-delivery-warrant-state.js +14 -15
  133. package/packages/core/dev-delivery-warrant.js +15 -5
  134. package/packages/core/domain-wasm-artifact.js +7 -0
  135. package/packages/core/domain-wasm.js +216 -0
  136. package/packages/core/{v4-floating-consumer-evidence.js → floating-consumer-evidence.js} +14 -14
  137. package/packages/core/{v4-floating-consumer-policy.js → floating-consumer-policy.js} +28 -30
  138. package/packages/core/{v4-floating-consumer-release-passport.js → floating-consumer-release-passport.js} +25 -25
  139. package/packages/core/github-governance-authority.js +4 -4
  140. package/packages/core/index.js +4 -8
  141. package/packages/core/kfd-adopter-manifest.js +46 -47
  142. package/packages/core/next-development-projection.js +26 -3
  143. package/packages/core/next-development-transition.js +5 -6
  144. package/packages/core/oci-compose-qualification.js +143 -0
  145. package/packages/core/oci-publication-bundle.js +281 -0
  146. package/packages/core/oci-publication-graph.js +206 -0
  147. package/packages/core/paper-agent-entry.js +30 -4
  148. package/packages/core/paper-fleet.js +1 -1
  149. package/packages/core/paper-runtime-channels.js +348 -0
  150. package/packages/core/paper-scaffold-content.js +10 -0
  151. package/packages/core/paper.js +37 -71
  152. package/packages/core/partial-mutation-recovery-qualification.js +18 -0
  153. package/packages/core/{v4-platform-stage-checkpoints.js → platform-stage-checkpoints.js} +37 -37
  154. package/packages/core/product-publication.js +59 -0
  155. package/packages/core/{v4-protected-publication-source.js → protected-publication-source.js} +22 -24
  156. package/packages/core/provider-operation-journal.js +62 -0
  157. package/packages/core/{v4-provider-readback-idempotency.js → provider-readback-idempotency.js} +40 -125
  158. package/packages/core/public-export-compatibility.js +33 -0
  159. package/packages/core/publication-development.js +72 -0
  160. package/packages/core/{v4-publication-qualification.js → publication-qualification.js} +17 -17
  161. package/packages/core/{v4-publication-rehearsal-capsule.js → publication-rehearsal-capsule.js} +23 -23
  162. package/packages/core/publication-rehearsal-projection.js +2 -2
  163. package/packages/core/{v4-publication-rehearsal-provider-bindings.js → publication-rehearsal-provider-bindings.js} +4 -4
  164. package/packages/core/publication-rehearsal-runtime.js +21 -21
  165. package/packages/core/{v4-publication-rehearsal.js → publication-rehearsal.js} +33 -33
  166. package/packages/core/publication-sealed-bundle.js +78 -13
  167. package/packages/core/release-activation-shadow.js +32 -0
  168. package/packages/core/release-candidate.js +6 -6
  169. package/packages/core/release-invocation.js +64 -0
  170. package/packages/core/release-line-dry-run.js +1 -1
  171. package/packages/core/release-passport-contract.js +5 -5
  172. package/packages/core/release-passport.js +41 -40
  173. package/packages/core/release-tail-product-capabilities.js +9 -0
  174. package/packages/core/release-tail-provider-plane.js +68 -1048
  175. package/packages/core/{v4-runtime-ref-resume-authority.js → runtime-ref-resume-authority.js} +36 -40
  176. package/packages/core/{v4-runtime-selector-persistence.js → runtime-selector-persistence.js} +7 -7
  177. package/packages/core/stable-publication-fence.js +28 -0
  178. package/packages/core/{v4-stage-capsule-local-store.js → stage-capsule-local-store.js} +56 -54
  179. package/packages/core/{v4-stage-capsule-qualification-campaign.js → stage-capsule-qualification-campaign.js} +37 -38
  180. package/packages/core/{v4-stage-capsule-qualification.js → stage-capsule-qualification.js} +28 -29
  181. package/packages/core/{v4-stage-capsule-resume-planner.js → stage-capsule-resume-planner.js} +29 -29
  182. package/packages/core/{v4-stage-capsule-store.js → stage-capsule-store.js} +59 -56
  183. package/packages/core/{v4-stage-capsule.js → stage-capsule.js} +45 -45
  184. package/packages/core/{v4-tail-reseal-contract.js → tail-reseal-contract.js} +6 -6
  185. package/packages/core/{v4-tail-reseal-github.js → tail-reseal-github.js} +12 -12
  186. package/packages/core/{v4-tail-reseal-receipt.js → tail-reseal-receipt.js} +22 -22
  187. package/packages/core/{v4-tail-reseal.js → tail-reseal.js} +29 -29
  188. package/packages/core/universal-workflow-bootstrap.js +586 -0
  189. package/scripts/{v4-architecture.mjs → architecture.mjs} +6 -6
  190. package/scripts/binary-publication-evidence.mjs +135 -0
  191. package/scripts/{v4-bridge-bootstrap.mjs → bridge-bootstrap.mjs} +14 -18
  192. package/scripts/{v4-bridge-evidence.mjs → bridge-evidence.mjs} +8 -8
  193. package/scripts/build-contract-core.mjs +1 -14
  194. package/scripts/build-domain-wasm.mjs +177 -0
  195. package/scripts/{v3-v4-capability-catalog.mjs → capability-parity-catalog.mjs} +19 -19
  196. package/scripts/check-action-bundles.mjs +12 -2
  197. package/scripts/{check-v3-v4-capability-inventory.mjs → check-capability-parity-inventory.mjs} +42 -42
  198. package/scripts/check-ci-lane-change-budget.mjs +4 -1
  199. package/scripts/check-core-mechanism-inventory.mjs +8 -4
  200. package/scripts/{check-v4-floating-consumer-policy-contract.mjs → check-floating-consumer-policy-contract.mjs} +10 -10
  201. package/scripts/check-implementation-naming.mjs +135 -0
  202. package/scripts/check-inventory.mjs +39 -47
  203. package/scripts/check-maintainability.mjs +25 -115
  204. package/scripts/{check-v4-public-dogfood-contract.mjs → check-public-dogfood-contract.mjs} +37 -24
  205. package/scripts/{check-v4-release-topology.mjs → check-release-topology.mjs} +131 -52
  206. package/scripts/{check-v4-runtime-semantic-closure.mjs → check-runtime-semantic-closure.mjs} +23 -17
  207. package/scripts/check-universal-workflow-bootstrap.mjs +266 -0
  208. package/scripts/check-workflow-taxonomy.mjs +6 -0
  209. package/scripts/{v4-consumer-policy.mjs → consumer-policy.mjs} +15 -15
  210. package/scripts/copy-domain-wasm.mjs +14 -0
  211. package/scripts/{v4-cross-platform-adopter-qualification.mjs → cross-platform-adopter-qualification.mjs} +9 -9
  212. package/scripts/{v4-declarative-promotion-admission.mjs → declarative-promotion-admission.mjs} +4 -4
  213. package/scripts/dev-delivery-authority-command-adapters.mjs +1 -1
  214. package/scripts/dev-delivery-authority.mjs +8 -8
  215. package/scripts/dev-delivery-source-proof-reuse.mjs +2 -1
  216. package/scripts/dev-delivery-warrant-options.mjs +15 -10
  217. package/scripts/dev-delivery-warrant-store.mjs +98 -13
  218. package/scripts/dev-delivery-warrant-transition.mjs +109 -0
  219. package/scripts/dev-delivery-warrant.mjs +80 -103
  220. package/scripts/dev-pr-auto-merge.mjs +15 -15
  221. package/scripts/dev-pr-delivery-warrant.mjs +1 -1
  222. package/scripts/generate-channel-build-workflow.mjs +7 -2
  223. package/scripts/generate-channel-promotion-workflow.mjs +19 -34
  224. package/scripts/generate-release-candidate-passport.mjs +23 -23
  225. package/scripts/generate-site-bundle.mjs +28 -28
  226. package/scripts/generate-universal-workflow-facades.mjs +498 -0
  227. package/scripts/generate-workflow-taxonomy.mjs +25 -0
  228. package/scripts/github-output.mjs +31 -0
  229. package/scripts/{v4-host-adapter.mjs → host-adapter.mjs} +1 -1
  230. package/scripts/implementation-references.mjs +25 -0
  231. package/scripts/init-repo.mjs +1 -1
  232. package/scripts/maintainability-metrics.mjs +16 -5
  233. package/scripts/maintainability-public-surface.mjs +115 -0
  234. package/scripts/next-development-review.mjs +313 -0
  235. package/scripts/oci-compose-preview.mjs +261 -0
  236. package/scripts/paper-work-fleet-cli.mjs +2 -0
  237. package/scripts/{v4-platform-stage-checkpoint-rehearsal.mjs → platform-stage-checkpoint-rehearsal.mjs} +17 -17
  238. package/scripts/{v4-product-publication-intent.mjs → product-publication-intent.mjs} +28 -13
  239. package/scripts/publication-candidate-kind.mjs +93 -0
  240. package/scripts/publication-candidate-sealer.mjs +16 -1
  241. package/scripts/{v4-publication-rehearsal-fixture.mjs → publication-rehearsal-fixture.mjs} +5 -5
  242. package/scripts/publication-settlement.mjs +211 -0
  243. package/scripts/release-asset-client.mjs +91 -0
  244. package/scripts/{v4-release-candidate-adapter.mjs → release-candidate-adapter.mjs} +4 -4
  245. package/scripts/release-candidate-resolver.mjs +24 -35
  246. package/scripts/release-tail.mjs +5 -5
  247. package/scripts/resume-from-candidate-run.mjs +35 -42
  248. package/scripts/site-capability-metadata.mjs +9 -0
  249. package/scripts/source-verification-evidence.mjs +344 -0
  250. package/scripts/stable-candidate-qualification.mjs +1 -1
  251. package/scripts/{v4-stage-capsule-qualification.mjs → stage-capsule-qualification.mjs} +62 -62
  252. package/scripts/{v4-stage-capsule-resume-rehearsal.mjs → stage-capsule-resume-rehearsal.mjs} +6 -6
  253. package/scripts/{v4-tail-reseal-macos-rehearsal.mjs → tail-reseal-macos-rehearsal.mjs} +9 -9
  254. package/scripts/{v4-tail-reseal.mjs → tail-reseal.mjs} +19 -19
  255. package/scripts/universal-facade-maintainability.mjs +91 -0
  256. package/scripts/universal-workflow-backflow.mjs +212 -0
  257. package/scripts/universal-workflow-engine.mjs +620 -0
  258. package/scripts/universal-workflow-self-dogfood.mjs +205 -0
  259. package/scripts/verify-version-state-delta.mjs +175 -0
  260. package/scripts/{v4-warrant-shadow-plan.mjs → warrant-shadow-plan.mjs} +6 -6
  261. package/scripts/workflow-taxonomy.mjs +507 -0
  262. package/templates/native-dev-delivery.yml +4 -7
  263. package/templates/universal-buildchain-bootstrap-recovery.yml +282 -0
  264. package/templates/universal-buildchain-bootstrap.yml +28 -0
  265. package/actions/v4-release-candidate-promote/README.md +0 -3
  266. package/packages/core/v4-partial-mutation-recovery-qualification.js +0 -395
  267. package/packages/core/v4-product-publication.js +0 -387
  268. package/packages/core/v4-provider-operation-journal.js +0 -531
  269. package/packages/core/v4-release-activation-shadow.js +0 -519
  270. package/packages/core/v4-release-invocation.js +0 -425
  271. package/packages/core/v4-stable-publication-fence.js +0 -357
  272. /package/architecture/{v4-adopter-delivery-parity.json → adopter-delivery-parity.json} +0 -0
  273. /package/architecture/{v3-core-mechanism-inventory.json → baseline-core-mechanism-inventory.json} +0 -0
  274. /package/architecture/{v4-canonical-contract-fixtures.json → canonical-contract-fixtures.json} +0 -0
  275. /package/architecture/{v4-compatibility-facts-parity.json → compatibility-facts-parity.json} +0 -0
  276. /package/architecture/{v4-delivery-warrant-shadow-bootstrap-plan.schema.json → delivery-warrant-shadow-bootstrap-plan.schema.json} +0 -0
  277. /package/architecture/{v4-delivery-warrant-shadow-fixtures.json → delivery-warrant-shadow-fixtures.json} +0 -0
  278. /package/architecture/{v4-delivery-warrant-shadow-fixtures.schema.json → delivery-warrant-shadow-fixtures.schema.json} +0 -0
  279. /package/architecture/{v4-exception-ledger.json → exception-ledger.json} +0 -0
  280. /package/architecture/{v4-exception-ledger.schema.json → exception-ledger.schema.json} +0 -0
  281. /package/architecture/{v4-release-invocation-fixtures.json → release-invocation-fixtures.json} +0 -0
@@ -3,11 +3,11 @@ import crypto from "node:crypto";
3
3
  import path from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
 
6
- import { runV4DeliveryWarrantTraceFixture } from "./v4-delivery-warrant-fixture-runner.js";
6
+ import { runDeliveryWarrantTraceFixture } from "./delivery-warrant-fixture-runner.js";
7
7
 
8
- export const V4_DELIVERY_WARRANT_SHADOW_OBSERVATION_CONTRACT =
8
+ export const DELIVERY_WARRANT_SHADOW_OBSERVATION_CONTRACT =
9
9
  "buildchain-v4-delivery-warrant-shadow-observation/v1";
10
- export const V4_DELIVERY_WARRANT_SHADOW_RESULT_CONTRACT =
10
+ export const DELIVERY_WARRANT_SHADOW_RESULT_CONTRACT =
11
11
  "buildchain-v4-delivery-warrant-shadow-result/v1";
12
12
 
13
13
  const HOST_REQUEST_CONTRACT = "kungfu-buildchain-v4-host-request";
@@ -117,7 +117,7 @@ function retainUntil(recordedAt) {
117
117
  return new Date(time + RETENTION_DAYS * 24 * 60 * 60 * 1000).toISOString();
118
118
  }
119
119
 
120
- export function createV4DeliveryWarrantShadowRequest(
120
+ export function createDeliveryWarrantShadowRequest(
121
121
  bytes,
122
122
  { requestId = crypto.randomUUID(), timeoutMs = 5_000 } = {},
123
123
  ) {
@@ -203,14 +203,14 @@ function defaultHost() {
203
203
  "--locked",
204
204
  "--quiet",
205
205
  "--manifest-path",
206
- path.join(root, "crates", "buildchain-v4-contracts", "Cargo.toml"),
206
+ path.join(root, "crates", "buildchain-domain-contracts", "Cargo.toml"),
207
207
  "--",
208
208
  "host",
209
209
  ],
210
210
  };
211
211
  }
212
212
 
213
- export function invokeV4RustShadowHost(
213
+ export function invokeRustShadowHost(
214
214
  request,
215
215
  { command, arguments: commandArguments, cwd = root, signal } = {},
216
216
  ) {
@@ -322,12 +322,12 @@ function skippedShadow(inputRoot, code) {
322
322
  };
323
323
  }
324
324
 
325
- export async function runV4DeliveryWarrantShadow(
325
+ export async function runDeliveryWarrantShadow(
326
326
  value,
327
327
  {
328
328
  enabled = enabledByDefault(),
329
- invokeLegacy = runV4DeliveryWarrantTraceFixture,
330
- invokeRust = invokeV4RustShadowHost,
329
+ invokeLegacy = runDeliveryWarrantTraceFixture,
330
+ invokeRust = invokeRustShadowHost,
331
331
  host = {},
332
332
  requestId,
333
333
  timeoutMs = 5_000,
@@ -343,7 +343,7 @@ export async function runV4DeliveryWarrantShadow(
343
343
  const inputRoot = sha256(bytes);
344
344
  if (!enabled) {
345
345
  return {
346
- schema: V4_DELIVERY_WARRANT_SHADOW_RESULT_CONTRACT,
346
+ schema: DELIVERY_WARRANT_SHADOW_RESULT_CONTRACT,
347
347
  authoritativeResult,
348
348
  shadow: skippedShadow(inputRoot, "shadow-disabled"),
349
349
  };
@@ -354,7 +354,7 @@ export async function runV4DeliveryWarrantShadow(
354
354
  retentionScope = publicRetention(retention);
355
355
  } catch (error) {
356
356
  return {
357
- schema: V4_DELIVERY_WARRANT_SHADOW_RESULT_CONTRACT,
357
+ schema: DELIVERY_WARRANT_SHADOW_RESULT_CONTRACT,
358
358
  authoritativeResult,
359
359
  shadow: skippedShadow(inputRoot, error.code || "input-not-public-safe"),
360
360
  };
@@ -371,13 +371,13 @@ export async function runV4DeliveryWarrantShadow(
371
371
  rustRevision: exactSource(sources.rustRevision, "rustRevision"),
372
372
  validatorVersion: exactValidator(sources.validatorVersion),
373
373
  };
374
- request = createV4DeliveryWarrantShadowRequest(bytes, {
374
+ request = createDeliveryWarrantShadowRequest(bytes, {
375
375
  requestId,
376
376
  timeoutMs,
377
377
  });
378
378
  } catch {
379
379
  return {
380
- schema: V4_DELIVERY_WARRANT_SHADOW_RESULT_CONTRACT,
380
+ schema: DELIVERY_WARRANT_SHADOW_RESULT_CONTRACT,
381
381
  authoritativeResult,
382
382
  shadow: skippedShadow(inputRoot, "shadow-config-invalid"),
383
383
  };
@@ -396,7 +396,7 @@ export async function runV4DeliveryWarrantShadow(
396
396
  }
397
397
 
398
398
  const observation = {
399
- schema: V4_DELIVERY_WARRANT_SHADOW_OBSERVATION_CONTRACT,
399
+ schema: DELIVERY_WARRANT_SHADOW_OBSERVATION_CONTRACT,
400
400
  authority: "typescript-v3",
401
401
  rustAuthority: "none",
402
402
  rustEffects: "disabled",
@@ -431,7 +431,7 @@ export async function runV4DeliveryWarrantShadow(
431
431
  }
432
432
  }
433
433
  return {
434
- schema: V4_DELIVERY_WARRANT_SHADOW_RESULT_CONTRACT,
434
+ schema: DELIVERY_WARRANT_SHADOW_RESULT_CONTRACT,
435
435
  authoritativeResult,
436
436
  shadow: {
437
437
  status,
@@ -20,7 +20,21 @@ export const EXACT_DEV_DELIVERY_PROOF_FIELDS = Object.freeze([
20
20
  "environmentRoot",
21
21
  "sourceWorkflowRunId",
22
22
  ]);
23
-
23
+ export function devDeliverySourceBinding(input = {}) {
24
+ const [sourceRoot, assignmentRoot, initiativeRoot] = [
25
+ "sourceRoot",
26
+ "assignmentRoot",
27
+ "initiativeRoot",
28
+ ].map((field) => String(input[field] || "").trim());
29
+ if (sourceRoot && !assignmentRoot && !initiativeRoot)
30
+ return { sourceRoot: exactRoot(sourceRoot, "sourceRoot") };
31
+ if (!sourceRoot && assignmentRoot && initiativeRoot)
32
+ return {
33
+ assignmentRoot: exactRoot(assignmentRoot, "assignmentRoot"),
34
+ initiativeRoot: exactRoot(initiativeRoot, "initiativeRoot"),
35
+ };
36
+ throw new Error("provide sourceRoot alone or both historical roots");
37
+ }
24
38
  export function matchesExactDevDeliveryCandidate(existing, attempted) {
25
39
  return (
26
40
  existing.sourceHead === attempted.sourceHead &&
@@ -37,6 +51,29 @@ export function matchesExactDevDeliveryCandidate(existing, attempted) {
37
51
  attempted.releaseBlockerPriority?.claimRoot
38
52
  );
39
53
  }
54
+ export function reuseExactActiveDevDeliverySourceProof(active, input) {
55
+ const phaseCompatible =
56
+ ["provisional", "qualified"].includes(active?.phase) ||
57
+ (!Object.hasOwn(active || {}, "phase") &&
58
+ active?.deliveryClass === "non-native-fast" &&
59
+ !Object.hasOwn(active || {}, "environmentRoot"));
60
+ const exact =
61
+ phaseCompatible &&
62
+ ["sourceRoot", "assignmentRoot", "initiativeRoot"].every(
63
+ (field) => active[field] === input[field],
64
+ ) &&
65
+ [
66
+ "pullRequestNumber",
67
+ "sourceIdentityRoot",
68
+ "deliveryClass",
69
+ "priority",
70
+ ].every((field) => active[field] === input[field]) &&
71
+ matchesExactDevDeliveryCandidate(active, {
72
+ ...input,
73
+ sourceProofRoot: active.sourceProofRoot,
74
+ });
75
+ return exact ? { ...input, sourceProofRoot: active.sourceProofRoot } : input;
76
+ }
40
77
 
41
78
  export function createDevDeliveryCandidateIdentity(
42
79
  input,
@@ -50,8 +87,7 @@ export function createDevDeliveryCandidateIdentity(
50
87
  input.pullRequestNumber,
51
88
  "pullRequestNumber",
52
89
  ),
53
- assignmentRoot: exactRoot(input.assignmentRoot, "assignmentRoot"),
54
- initiativeRoot: exactRoot(input.initiativeRoot, "initiativeRoot"),
90
+ ...devDeliverySourceBinding(input),
55
91
  sourceIdentityRoot: exactRoot(
56
92
  input.sourceIdentityRoot,
57
93
  "sourceIdentityRoot",
@@ -59,11 +95,10 @@ export function createDevDeliveryCandidateIdentity(
59
95
  deliveryClass: deliveryClass(input.deliveryClass),
60
96
  };
61
97
  if (input.identitySemantics) {
62
- if (text(input.identitySemantics) !== CHAINED_ATTEMPT_IDENTITY) {
98
+ if (text(input.identitySemantics) !== CHAINED_ATTEMPT_IDENTITY)
63
99
  throw new Error(
64
100
  `unsupported candidate identity semantics ${input.identitySemantics}`,
65
101
  );
66
- }
67
102
  identity.identitySemantics = CHAINED_ATTEMPT_IDENTITY;
68
103
  identity.predecessorCandidateId = exactRoot(
69
104
  input.predecessorCandidateId,
@@ -72,7 +107,6 @@ export function createDevDeliveryCandidateIdentity(
72
107
  }
73
108
  return { ...identity, candidateId: devDeliveryContentRoot(identity) };
74
109
  }
75
-
76
110
  export function validateDevDeliveryCandidateChain(candidates, terminalStates) {
77
111
  const precedingCandidates = new Map();
78
112
  const latestByPullRequest = new Map();
@@ -37,10 +37,10 @@ const FAILURE_FILES = [
37
37
  "warrant.json",
38
38
  ];
39
39
 
40
- const V4_RUNTIME_SELECTOR =
40
+ const DOMAIN_RUNTIME_SELECTOR =
41
41
  /^(?:[0-9a-f]{40}|v4|v4-alpha|train\/v4\/v4\.0\/[a-z0-9][a-z0-9._-]*)$/u;
42
42
 
43
- const V4_RUNTIME_SELECTOR_DESCRIPTION =
43
+ const RUNTIME_SELECTOR_DESCRIPTION =
44
44
  "runtime selector must be an exact immutable SHA, v4, v4-alpha, or train/v4/v4.0/<capability>";
45
45
 
46
46
  function requiredFiles(outcome) {
@@ -165,8 +165,8 @@ function runtimeBinding(input = {}) {
165
165
  resolvedSha: exactSha(input.resolvedSha, "resolved runtime SHA"),
166
166
  selectionRoot: exactRoot(input.selectionRoot, "runtime selection root"),
167
167
  };
168
- if (!V4_RUNTIME_SELECTOR.test(runtime.selector)) {
169
- throw new Error(V4_RUNTIME_SELECTOR_DESCRIPTION);
168
+ if (!DOMAIN_RUNTIME_SELECTOR.test(runtime.selector)) {
169
+ throw new Error(RUNTIME_SELECTOR_DESCRIPTION);
170
170
  }
171
171
  return runtime;
172
172
  }
@@ -207,8 +207,8 @@ function verifiedRuntimeSelection(directory, expected = {}) {
207
207
  if (JSON.stringify(selection) !== JSON.stringify(normalized)) {
208
208
  throw new Error("runtime selection is not exact canonical content");
209
209
  }
210
- if (!V4_RUNTIME_SELECTOR.test(normalized.selector)) {
211
- throw new Error(V4_RUNTIME_SELECTOR_DESCRIPTION);
210
+ if (!DOMAIN_RUNTIME_SELECTOR.test(normalized.selector)) {
211
+ throw new Error(RUNTIME_SELECTOR_DESCRIPTION);
212
212
  }
213
213
  const selectionRoot = sha256Bytes(
214
214
  Buffer.from(`${JSON.stringify(normalized, null, 2)}\n`),
@@ -30,7 +30,7 @@ export {
30
30
  };
31
31
  export const NATIVE_QUALIFICATION_PROOF_SCHEMA =
32
32
  "kungfu.buildchain.native-qualification-proof/v4";
33
- const LEGACY_NATIVE_QUALIFICATION_PROOF_V3_SCHEMA =
33
+ const LEGACY_NATIVE_QUALIFICATION_PROOF_BASELINE_SCHEMA =
34
34
  "kungfu.buildchain.native-qualification-proof/v3";
35
35
  const LEGACY_NATIVE_QUALIFICATION_PROOF_V2_SCHEMA =
36
36
  "kungfu.buildchain.native-qualification-proof/v2";
@@ -44,9 +44,13 @@ export const NATIVE_PROOF_BASE_DELTA_SCHEMA =
44
44
  "kungfu.buildchain.native-proof-base-delta/v1";
45
45
  const NATIVE_QUALIFICATION_ROOT_SEMANTICS = "semantic-native-identity-v1";
46
46
 
47
- function normalizeQualifiedWarrant(warrant, candidate, allowLegacyV3Readback) {
48
- const qualifiedV3Readback =
49
- allowLegacyV3Readback &&
47
+ function normalizeQualifiedWarrant(
48
+ warrant,
49
+ candidate,
50
+ allowLegacyBaselineReadback,
51
+ ) {
52
+ const qualifiedBaselineReadback =
53
+ allowLegacyBaselineReadback &&
50
54
  !warrant.nativeCommandContract &&
51
55
  !candidate.nativeCommandContract &&
52
56
  !warrant.nativeExecutionReceiptRoot &&
@@ -59,7 +63,7 @@ function normalizeQualifiedWarrant(warrant, candidate, allowLegacyV3Readback) {
59
63
  warrant.nativeProofReuseRoot,
60
64
  "Warrant nativeProofReuseRoot",
61
65
  );
62
- if (!qualifiedV3Readback) {
66
+ if (!qualifiedBaselineReadback) {
63
67
  warrant.nativeExecutionReceiptRoot = exactRoot(
64
68
  warrant.nativeExecutionReceiptRoot,
65
69
  "Warrant nativeExecutionReceiptRoot",
@@ -74,7 +78,7 @@ function normalizeQualifiedWarrant(warrant, candidate, allowLegacyV3Readback) {
74
78
 
75
79
  export function validateActiveDevDeliveryWarrant(
76
80
  queue,
77
- { allowLegacyV3Readback = false } = {},
81
+ { allowLegacyBaselineReadback = false } = {},
78
82
  ) {
79
83
  const warrant = queue.activeWarrant;
80
84
  if (warrant.schema !== "kungfu.buildchain.dev-delivery-warrant/v1")
@@ -110,7 +114,7 @@ export function validateActiveDevDeliveryWarrant(
110
114
  "exactly one active candidate must match the active Warrant",
111
115
  );
112
116
  if (warrant.phase === "qualified") {
113
- normalizeQualifiedWarrant(warrant, active[0], allowLegacyV3Readback);
117
+ normalizeQualifiedWarrant(warrant, active[0], allowLegacyBaselineReadback);
114
118
  } else if (
115
119
  warrant.phase === "provisional" &&
116
120
  (warrant.nativeProofRoot ||
@@ -288,7 +292,7 @@ export function verifyNativeQualificationProof(proofInput, expected = {}) {
288
292
  if (
289
293
  ![
290
294
  NATIVE_QUALIFICATION_PROOF_SCHEMA,
291
- LEGACY_NATIVE_QUALIFICATION_PROOF_V3_SCHEMA,
295
+ LEGACY_NATIVE_QUALIFICATION_PROOF_BASELINE_SCHEMA,
292
296
  LEGACY_NATIVE_QUALIFICATION_PROOF_V2_SCHEMA,
293
297
  LEGACY_NATIVE_QUALIFICATION_PROOF_SCHEMA,
294
298
  ].includes(proof.schema)
@@ -140,7 +140,7 @@ export function recoverLegacyTerminalDevDeliveryQueue(
140
140
  );
141
141
  }
142
142
  const before = normalizeDevDeliveryQueue(queueInput, {
143
- allowLegacyV3Readback: true,
143
+ allowLegacyBaselineReadback: true,
144
144
  });
145
145
  const expectedOldStateRoot = exactRoot(
146
146
  request.expectedOldStateRoot,
@@ -1,6 +1,6 @@
1
1
  export function lacksExactNativeExecutionContract(
2
2
  candidate,
3
- allowLegacyV3Readback = false,
3
+ allowLegacyBaselineReadback = false,
4
4
  ) {
5
5
  const native =
6
6
  candidate.deliveryClass !== "non-native-fast" ||
@@ -9,17 +9,17 @@ export function lacksExactNativeExecutionContract(
9
9
  return Boolean(
10
10
  native &&
11
11
  (!candidate.environmentRoot ||
12
- (!candidate.nativeCommandContract && !allowLegacyV3Readback)),
12
+ (!candidate.nativeCommandContract && !allowLegacyBaselineReadback)),
13
13
  );
14
14
  }
15
15
 
16
16
  export function lacksLiveNativeProof(
17
17
  candidate,
18
18
  status,
19
- { allowLegacyV3Readback = false, allowLegacyQueuedReadback = false } = {},
19
+ { allowLegacyV3Readback: legacyReadback = false, allowLegacyBaselineReadback = legacyReadback, allowLegacyQueuedReadback = false } = {},
20
20
  ) {
21
21
  return (
22
- lacksExactNativeExecutionContract(candidate, allowLegacyV3Readback) &&
22
+ lacksExactNativeExecutionContract(candidate, allowLegacyBaselineReadback) &&
23
23
  !(status === "queued" && allowLegacyQueuedReadback) &&
24
24
  !TERMINAL_STATES.has(status)
25
25
  );
@@ -12,6 +12,7 @@ import {
12
12
  import {
13
13
  chainedDevDeliveryAttemptInput,
14
14
  createDevDeliveryCandidateIdentity,
15
+ devDeliverySourceBinding,
15
16
  EXACT_DEV_DELIVERY_PROOF_FIELDS,
16
17
  matchesExactDevDeliveryCandidate,
17
18
  validateDevDeliveryCandidateChain,
@@ -86,8 +87,7 @@ export function issueDevDeliveryWarrant(
86
87
  candidateId: candidate.candidateId,
87
88
  pullRequestNumber: candidate.pullRequestNumber,
88
89
  sourceHead: candidate.sourceHead,
89
- assignmentRoot: candidate.assignmentRoot,
90
- initiativeRoot: candidate.initiativeRoot,
90
+ ...devDeliverySourceBinding(candidate),
91
91
  sourceIdentityRoot: candidate.sourceIdentityRoot,
92
92
  sourcePatchRoot: candidate.sourcePatchRoot,
93
93
  sourceProofRoot: candidate.sourceProofRoot,
@@ -279,7 +279,8 @@ function normalizeCandidate(input, expected) {
279
279
  }
280
280
  if (
281
281
  lacksLiveNativeProof(candidate, status, {
282
- allowLegacyV3Readback: expected.allowLegacyV3Readback,
282
+ allowLegacyBaselineReadback:
283
+ expected.allowLegacyBaselineReadback ?? expected.allowLegacyV3Readback,
283
284
  allowLegacyQueuedReadback: expected.allowLegacyQueuedNativeReadback,
284
285
  })
285
286
  )
@@ -358,12 +359,12 @@ export function normalizeDevDeliveryQueue(input, expected = {}) {
358
359
  const hasExecutionReceipt = !!queue.activeWarrant?.nativeExecutionReceiptRoot;
359
360
  const hasQualificationReceipt =
360
361
  !!queue.activeWarrant?.qualificationReceiptRoot;
361
- const allowLegacyV3Readback =
362
- expected.allowLegacyV3Readback === true &&
363
- hasExecutionReceipt === hasQualificationReceipt;
362
+ const allowLegacyBaselineReadback =
363
+ (expected.allowLegacyBaselineReadback ?? expected.allowLegacyV3Readback) ===
364
+ true && hasExecutionReceipt === hasQualificationReceipt;
364
365
  const candidateExpected = {
365
366
  ...queue,
366
- allowLegacyV3Readback,
367
+ allowLegacyBaselineReadback,
367
368
  allowLegacyQueuedNativeReadback: true,
368
369
  };
369
370
  queue.candidates = (queue.candidates || []).map((candidate) =>
@@ -372,7 +373,7 @@ export function normalizeDevDeliveryQueue(input, expected = {}) {
372
373
  validateDevDeliveryCandidateChain(queue.candidates, TERMINAL_STATES);
373
374
  queue.updatedAt = timestamp(queue.updatedAt, "queue updatedAt");
374
375
  if (queue.activeWarrant) {
375
- validateActiveDevDeliveryWarrant(queue, { allowLegacyV3Readback });
376
+ validateActiveDevDeliveryWarrant(queue, { allowLegacyBaselineReadback });
376
377
  } else if (
377
378
  queue.candidates.some((candidate) =>
378
379
  ["selected", "proving", "waiting", "blocked", "qualified"].includes(
@@ -413,8 +414,7 @@ function submissionReceipt({ before, after, candidate, action, now }) {
413
414
  candidateId: candidate.candidateId,
414
415
  pullRequestNumber: candidate.pullRequestNumber,
415
416
  sourceHead: candidate.sourceHead,
416
- assignmentRoot: candidate.assignmentRoot,
417
- initiativeRoot: candidate.initiativeRoot,
417
+ ...devDeliverySourceBinding(candidate),
418
418
  sourceIdentityRoot: candidate.sourceIdentityRoot,
419
419
  sourcePatchRoot: candidate.sourcePatchRoot,
420
420
  sourceProofRoot: candidate.sourceProofRoot,
@@ -572,12 +572,11 @@ function effectivePriority(candidate, policy, now) {
572
572
  releaseBlocker: Boolean(candidate.releaseBlockerPriority),
573
573
  };
574
574
  }
575
- export function rankDevDeliveryCandidates(
576
- queueInput,
577
- { now = new Date().toISOString(), allowLegacyV3Readback = false } = {},
578
- ) {
575
+ export function rankDevDeliveryCandidates(queueInput, options = {}) {
576
+ const { now = new Date().toISOString() } = options;
579
577
  const queue = normalizeDevDeliveryQueue(queueInput, {
580
- allowLegacyV3Readback,
578
+ allowLegacyBaselineReadback:
579
+ options.allowLegacyBaselineReadback ?? options.allowLegacyV3Readback,
581
580
  });
582
581
  const currentTime = timestamp(now, "now");
583
582
  return queue.candidates
@@ -198,8 +198,8 @@ export function selectDevDeliveryWarrant(
198
198
  candidateId: transaction.result.candidate.candidateId,
199
199
  pullRequestNumber: transaction.result.candidate.pullRequestNumber,
200
200
  sourceHead: transaction.result.candidate.sourceHead,
201
- assignmentRoot: transaction.result.candidate.assignmentRoot,
202
- initiativeRoot: transaction.result.candidate.initiativeRoot,
201
+ ...candidateSourceBinding(transaction.result.candidate),
202
+
203
203
  sourceIdentityRoot: transaction.result.candidate.sourceIdentityRoot,
204
204
  sourcePatchRoot: transaction.result.candidate.sourcePatchRoot,
205
205
  sourceProofRoot: transaction.result.candidate.sourceProofRoot,
@@ -488,6 +488,7 @@ function createDevDeliverySuccessorWake(queue, now) {
488
488
  "candidateId",
489
489
  "pullRequestNumber",
490
490
  "sourceHead",
491
+ "sourceRoot",
491
492
  "assignmentRoot",
492
493
  "initiativeRoot",
493
494
  "sourceIdentityRoot",
@@ -533,10 +534,10 @@ export const reconcileDevDeliveryTerminalEvidence =
533
534
  });
534
535
  export function observeDevDeliveryQueue(
535
536
  queueInput,
536
- { now = new Date().toISOString(), allowLegacyV3Readback = false } = {},
537
+ { now = new Date().toISOString(), allowLegacyV3Readback: legacyReadback = false, allowLegacyBaselineReadback = legacyReadback } = {},
537
538
  ) {
538
539
  const queue = normalizeDevDeliveryQueue(queueInput, {
539
- allowLegacyV3Readback,
540
+ allowLegacyBaselineReadback,
540
541
  });
541
542
  const currentTime = timestamp(now, "now");
542
543
  const states = {};
@@ -544,7 +545,7 @@ export function observeDevDeliveryQueue(
544
545
  states[candidate.status] = (states[candidate.status] || 0) + 1;
545
546
  const queued = rankDevDeliveryCandidates(queue, {
546
547
  now: currentTime,
547
- allowLegacyV3Readback,
548
+ allowLegacyBaselineReadback,
548
549
  });
549
550
  return {
550
551
  schema: "kungfu.buildchain.dev-delivery-queue-observation/v1",
@@ -586,3 +587,12 @@ export function observeDevDeliveryQueue(
586
587
  observedAt: currentTime,
587
588
  };
588
589
  }
590
+
591
+ function candidateSourceBinding(candidate) {
592
+ return candidate.sourceRoot
593
+ ? { sourceRoot: candidate.sourceRoot }
594
+ : {
595
+ assignmentRoot: candidate.assignmentRoot,
596
+ initiativeRoot: candidate.initiativeRoot,
597
+ };
598
+ }
@@ -0,0 +1,7 @@
1
+ // Generated by scripts/build-domain-wasm.mjs.
2
+ export const DOMAIN_WASM_ABI_VERSION = 1;
3
+ export const DOMAIN_WASM_RUSTC = "rustc 1.96.0 (ac68faa20 2026-05-25)";
4
+ export const DOMAIN_WASM_SOURCE_SHA256 =
5
+ "d575dc3680de68f5f165b9fe584cf63ba2498adf45d286320b797a9caccf19f9";
6
+ export const DOMAIN_WASM_SHA256 =
7
+ "e04814473796c483e82e450b651b60e63609bfca182140b333dd0e6994ae63db";
@@ -0,0 +1,216 @@
1
+ import fs from "node:fs";
2
+ import { createHash } from "node:crypto";
3
+
4
+ import {
5
+ DOMAIN_WASM_ABI_VERSION,
6
+ DOMAIN_WASM_SHA256,
7
+ } from "./domain-wasm-artifact.js";
8
+
9
+ export const DOMAIN_WASM_REQUEST_CONTRACT =
10
+ "kungfu-buildchain-v4-domain-wasm-request/v1";
11
+ export const DOMAIN_WASM_RESPONSE_CONTRACT =
12
+ "kungfu-buildchain-v4-domain-wasm-response/v1";
13
+
14
+ const WASM_URL = new URL("./buildchain-domain.wasm", import.meta.url);
15
+ const REQUIRED_EXPORTS = [
16
+ "memory",
17
+ "buildchain_domain_wasm_abi_version",
18
+ "buildchain_domain_wasm_alloc",
19
+ "buildchain_domain_wasm_dealloc",
20
+ "buildchain_domain_wasm_invoke",
21
+ "buildchain_domain_wasm_response_pointer",
22
+ "buildchain_domain_wasm_response_length",
23
+ ];
24
+
25
+ let loaded;
26
+
27
+ export class DomainWasmFault extends Error {
28
+ constructor(fault) {
29
+ super(fault?.message || "Rust/WASM domain request failed");
30
+ this.name = "DomainWasmFault";
31
+ this.fault = fault;
32
+ this.code = fault?.code || "rust-wasm-domain-failed";
33
+ this.path = fault?.path || "$";
34
+ this.retry = fault?.retry || "stop";
35
+ }
36
+ }
37
+
38
+ function failClosed(message, cause) {
39
+ const error = new Error(`Buildchain v4 Rust/WASM authority: ${message}`);
40
+ error.code = "rust-wasm-authority-unavailable";
41
+ error.cause = cause;
42
+ throw error;
43
+ }
44
+
45
+ function invalidTransport(code, path, message) {
46
+ throw new DomainWasmFault({ code, path, message, retry: "stop" });
47
+ }
48
+
49
+ function validateJsonTransport(value, path, active) {
50
+ if (value === null || typeof value === "boolean") return;
51
+ if (typeof value === "string") {
52
+ for (let index = 0; index < value.length; index += 1) {
53
+ const code = value.charCodeAt(index);
54
+ if (code >= 0xd800 && code <= 0xdbff) {
55
+ const next = value.charCodeAt(index + 1);
56
+ if (!(next >= 0xdc00 && next <= 0xdfff)) {
57
+ invalidTransport(
58
+ "unsupported-string",
59
+ path,
60
+ `${path} contains an unpaired surrogate`,
61
+ );
62
+ }
63
+ index += 1;
64
+ } else if (code >= 0xdc00 && code <= 0xdfff) {
65
+ invalidTransport(
66
+ "unsupported-string",
67
+ path,
68
+ `${path} contains an unpaired surrogate`,
69
+ );
70
+ }
71
+ }
72
+ return;
73
+ }
74
+ if (typeof value === "number") {
75
+ if (!Number.isSafeInteger(value) || Object.is(value, -0)) {
76
+ invalidTransport(
77
+ "unsupported-number",
78
+ path,
79
+ `${path} must be a safe base-10 integer and must not be negative zero`,
80
+ );
81
+ }
82
+ return;
83
+ }
84
+ if (!value || typeof value !== "object") {
85
+ invalidTransport(
86
+ "unsupported-json-value",
87
+ path,
88
+ `${path} is not a JSON value`,
89
+ );
90
+ }
91
+ if (active.has(value)) {
92
+ invalidTransport("cyclic-json-value", path, `${path} contains a cycle`);
93
+ }
94
+ active.add(value);
95
+ try {
96
+ if (Array.isArray(value)) {
97
+ for (let index = 0; index < value.length; index += 1) {
98
+ validateJsonTransport(value[index], `${path}/${index}`, active);
99
+ }
100
+ return;
101
+ }
102
+ const prototype = Object.getPrototypeOf(value);
103
+ if (prototype !== Object.prototype && prototype !== null) {
104
+ invalidTransport(
105
+ "unsupported-json-value",
106
+ path,
107
+ `${path} must be a plain object`,
108
+ );
109
+ }
110
+ for (const key of Object.keys(value)) {
111
+ if (!/^[\x20-\x7e]+$/u.test(key)) {
112
+ invalidTransport(
113
+ "unsupported-object-key",
114
+ `${path}/${key}`,
115
+ "object keys must be non-empty printable ASCII",
116
+ );
117
+ }
118
+ validateJsonTransport(value[key], `${path}/${key}`, active);
119
+ }
120
+ } finally {
121
+ active.delete(value);
122
+ }
123
+ }
124
+
125
+ function loadAuthority() {
126
+ if (loaded) return loaded;
127
+ let bytes;
128
+ try {
129
+ bytes = fs.readFileSync(WASM_URL);
130
+ } catch (error) {
131
+ failClosed(`cannot read ${WASM_URL.pathname}`, error);
132
+ }
133
+ const observedSha256 = createHash("sha256").update(bytes).digest("hex");
134
+ if (observedSha256 !== DOMAIN_WASM_SHA256) {
135
+ failClosed(
136
+ `artifact digest mismatch (expected ${DOMAIN_WASM_SHA256}, observed ${observedSha256})`,
137
+ );
138
+ }
139
+ let instance;
140
+ try {
141
+ instance = new WebAssembly.Instance(new WebAssembly.Module(bytes), {});
142
+ } catch (error) {
143
+ failClosed("artifact compilation or instantiation failed", error);
144
+ }
145
+ const missing = REQUIRED_EXPORTS.filter(
146
+ (name) => instance.exports[name] === undefined,
147
+ );
148
+ if (missing.length > 0) {
149
+ failClosed(`artifact is missing exports: ${missing.join(", ")}`);
150
+ }
151
+ const abiVersion = instance.exports.buildchain_domain_wasm_abi_version();
152
+ if (abiVersion !== DOMAIN_WASM_ABI_VERSION) {
153
+ failClosed(
154
+ `ABI mismatch (expected ${DOMAIN_WASM_ABI_VERSION}, observed ${abiVersion})`,
155
+ );
156
+ }
157
+ loaded = instance.exports;
158
+ return loaded;
159
+ }
160
+
161
+ export function invokeDomainWasm(operation, payload) {
162
+ if (
163
+ ["canonical-json", "content-root", "release-tail-root"].includes(operation)
164
+ ) {
165
+ validateJsonTransport(payload, "$/payload", new Set());
166
+ }
167
+ const authority = loadAuthority();
168
+ const input = new TextEncoder().encode(
169
+ JSON.stringify({
170
+ schema: DOMAIN_WASM_REQUEST_CONTRACT,
171
+ operation,
172
+ payload,
173
+ }),
174
+ );
175
+ const inputPointer = authority.buildchain_domain_wasm_alloc(input.byteLength);
176
+ try {
177
+ new Uint8Array(authority.memory.buffer, inputPointer, input.byteLength).set(
178
+ input,
179
+ );
180
+ try {
181
+ authority.buildchain_domain_wasm_invoke(inputPointer, input.byteLength);
182
+ } catch (error) {
183
+ failClosed(`operation '${operation}' trapped`, error);
184
+ }
185
+ const responsePointer = authority.buildchain_domain_wasm_response_pointer();
186
+ const responseLength = authority.buildchain_domain_wasm_response_length();
187
+ let response;
188
+ try {
189
+ const responseBytes = new Uint8Array(
190
+ authority.memory.buffer,
191
+ responsePointer,
192
+ responseLength,
193
+ );
194
+ response = JSON.parse(new TextDecoder().decode(responseBytes));
195
+ } catch (error) {
196
+ failClosed(
197
+ `operation '${operation}' returned an invalid response`,
198
+ error,
199
+ );
200
+ }
201
+ if (
202
+ response?.schema !== DOMAIN_WASM_RESPONSE_CONTRACT ||
203
+ typeof response.ok !== "boolean"
204
+ ) {
205
+ failClosed(`operation '${operation}' returned an unsupported response`);
206
+ }
207
+ if (!response.ok) throw new DomainWasmFault(response.fault);
208
+ return response.value;
209
+ } finally {
210
+ authority.buildchain_domain_wasm_dealloc(inputPointer, input.byteLength);
211
+ }
212
+ }
213
+
214
+ export function domainWasmInfo() {
215
+ return invokeDomainWasm("abi-info", {});
216
+ }