@kungfu-tech/buildchain 4.0.0 → 4.0.1-alpha.10

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 (228) hide show
  1. package/AGENTS.md +13 -5
  2. package/actions/promote-buildchain-ref/README.md +11 -6
  3. package/actions/release-tail/README.md +8 -0
  4. package/architecture/ci-lane-change-budget.json +187 -0
  5. package/architecture/decisions/0002-next-development-transition.md +101 -0
  6. package/architecture/decisions/0003-two-phase-delivery-warrant.md +152 -0
  7. package/architecture/internal-capabilities.json +219 -7
  8. package/architecture/maintainability-policy.json +246 -29
  9. package/architecture/release-tail-contract-inventory.json +5 -2
  10. package/architecture/v3-core-mechanism-inventory.json +91 -0
  11. package/architecture/v4-adopter-delivery-parity.json +32 -5
  12. package/architecture/v4-capability-state-machine-manifest.json +73 -0
  13. package/architecture/v4-compatibility-facts-parity.json +77 -0
  14. package/architecture/v4-delivery-authority-parity.json +250 -0
  15. package/architecture/v4-delivery-warrant-shadow-fixtures.json +41 -9
  16. package/architecture/v4-floating-consumer-policy.json +81 -0
  17. package/architecture/v4-floating-consumer-policy.md +32 -0
  18. package/architecture/v4-next-development-parity.json +192 -0
  19. package/architecture/v4-publication-rehearsal-parity.json +84 -0
  20. package/architecture/v4-release-train-parity.json +1 -0
  21. package/architecture/v4-runtime-ref-resume-authority.json +64 -0
  22. package/architecture/v4-stage-capsule-qualification.json +2 -2
  23. package/architecture/v4-tail-reseal-parity.json +150 -0
  24. package/bin/buildchain.mjs +32 -3
  25. package/bin/internal/adopter-delivery-cli.mjs +70 -0
  26. package/bin/internal/command-registry.mjs +3 -0
  27. package/bin/internal/compatibility-facts-cli.mjs +101 -0
  28. package/bin/internal/trust-release-release-handlers.mjs +5 -0
  29. package/contracts/dev-delivery-authority-v2.schema.json +662 -0
  30. package/contracts/fixtures/next-development-transition-v1/anchored-manual-waiting.json +47 -0
  31. package/contracts/fixtures/next-development-transition-v1/semver-auto-planned.json +47 -0
  32. package/contracts/fixtures/next-development-transition-v1/version-model-cases.json +40 -0
  33. package/contracts/fixtures/v4-adopter-delivery-v1/archive-template.json +19 -0
  34. package/contracts/fixtures/v4-adopter-delivery-v1/bootstrap-positive.json +93 -0
  35. package/contracts/fixtures/v4-adopter-delivery-v1/gate-positive.json +29 -0
  36. package/contracts/fixtures/v4-adopter-delivery-v1/gate-unknown-selector.json +26 -0
  37. package/contracts/fixtures/v4-adopter-delivery-v1/offline-vectors.json +50 -0
  38. package/contracts/fixtures/v4-compatibility-facts-v1/shared.json +1129 -0
  39. package/contracts/fixtures/v4-floating-consumer-policy-v1/cases.json +59 -0
  40. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/artifacts/product.bin +1 -0
  41. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/config/buildchain.toml +5 -0
  42. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/documents/release-activation.json +1 -0
  43. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/documents/signed-channel.json +1 -0
  44. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/evidence/qualification.json +1 -0
  45. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/manifests/candidate.json +5 -0
  46. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/manifests/release-passport.json +1 -0
  47. package/contracts/fixtures/v4-publication-rehearsal-v1/capsule.json +707 -0
  48. package/contracts/fixtures/v4-publication-rehearsal-v1/offline-vectors.json +27 -0
  49. package/contracts/fixtures/v4-runtime-ref-resume-authority-v1/scenario.json +15 -0
  50. package/contracts/fixtures/v4-tail-reseal-v1/valid.json +229 -0
  51. package/contracts/next-development-request-v1.schema.json +66 -0
  52. package/contracts/next-development-transition-v1.schema.json +292 -0
  53. package/contracts/v4-adopter-delivery-v1.schema.json +81 -0
  54. package/contracts/v4-compatibility-facts-v1.schema.json +230 -0
  55. package/contracts/v4-floating-consumer-policy-receipt-v1.schema.json +107 -0
  56. package/contracts/v4-publication-rehearsal-capsule-v1.schema.json +233 -0
  57. package/contracts/v4-runtime-ref-resume-authority-v1.schema.json +235 -0
  58. package/contracts/v4-tail-reseal-v1.schema.json +276 -0
  59. package/dist/site/agent-index.json +5 -0
  60. package/dist/site/artifact-schemas.json +10 -0
  61. package/dist/site/buildchain-contract.json +1562 -44
  62. package/dist/site/buildchain-site.json +684 -42
  63. package/dist/site/capability-registry.json +17 -14
  64. package/dist/site/cli-registry.json +205 -3
  65. package/dist/site/controller-registry.json +62 -6
  66. package/dist/site/kfd-claims.json +551 -22
  67. package/dist/site/kfd-upstream-aggregate.json +1 -1
  68. package/dist/site/manual-registry.json +55 -9
  69. package/dist/site/node-api-registry.json +15247 -8690
  70. package/dist/site/page-registry.json +647 -29
  71. package/dist/site/public-surface-audit.json +876 -55
  72. package/dist/site/publication-authority-registry.json +44 -8
  73. package/dist/site/publication-registry.json +4 -4
  74. package/dist/site/release-provenance.json +26 -0
  75. package/dist/site/schemas/dev-delivery-authority-v2.schema.json +662 -0
  76. package/dist/site/schemas/release-tail-capabilities-v1.schema.json +199 -0
  77. package/dist/site/schemas/v4-adopter-delivery-v1.schema.json +81 -0
  78. package/dist/site/schemas/v4-compatibility-facts-v1.schema.json +230 -0
  79. package/dist/site/schemas/v4-publication-rehearsal-capsule-v1.schema.json +233 -0
  80. package/dist/site/site-manifest.json +37 -13
  81. package/dist/site/workflow-registry.json +200 -22
  82. package/docs/MAP.md +10 -2
  83. package/docs/cli-reference.md +404 -13
  84. package/docs/cli.md +8 -0
  85. package/docs/dev-alpha-candidate-patrol.md +8 -0
  86. package/docs/dev-delivery-qualification-landing-adr.md +251 -0
  87. package/docs/dev-delivery-warrant.md +361 -30
  88. package/docs/lifecycle-protocol.md +41 -0
  89. package/docs/next-development-transition.md +118 -0
  90. package/docs/node-api-reference.md +748 -322
  91. package/docs/release-tail-provider-plane.md +30 -0
  92. package/docs/reusable-build-surface.md +41 -0
  93. package/docs/runtime-train-validation.md +10 -0
  94. package/docs/v4-adopter-delivery.md +133 -0
  95. package/docs/v4-compatibility-facts.md +91 -0
  96. package/docs/v4-publication-rehearsal.md +130 -0
  97. package/docs/v4-runtime-ref-resume-authority.md +69 -0
  98. package/docs/v4-tail-reseal.md +73 -0
  99. package/docs/versioning.md +4 -2
  100. package/package.json +36 -6
  101. package/packages/core/adopter-delivery-passport.js +259 -0
  102. package/packages/core/adopter-delivery-vectors.js +158 -0
  103. package/packages/core/adopter-delivery-vectors.json +77 -0
  104. package/packages/core/artifact-signing.js +61 -0
  105. package/packages/core/buildchain-agent-manuals.js +3 -0
  106. package/packages/core/buildchain-compatibility-authority.js +336 -0
  107. package/packages/core/buildchain-compatibility-fact.js +394 -0
  108. package/packages/core/buildchain-compatibility-facts.json +217 -0
  109. package/packages/core/buildchain-compatibility-proof.js +566 -0
  110. package/packages/core/buildchain-config.js +150 -1
  111. package/packages/core/buildchain-contract.js +96 -143
  112. package/packages/core/buildchain-delivery-bootstrap.js +240 -0
  113. package/packages/core/buildchain-delivery-infrastructure.js +164 -0
  114. package/packages/core/buildchain-delivery-self-dogfood.js +395 -0
  115. package/packages/core/buildchain-publication-authority.js +1 -0
  116. package/packages/core/channel-candidate.js +8 -0
  117. package/packages/core/channel-promotion-baseline.js +55 -0
  118. package/packages/core/ci-lane-change-budget.js +247 -0
  119. package/packages/core/dev-alpha-candidate-selection.js +10 -2
  120. package/packages/core/dev-delivery-authority-candidate.js +270 -0
  121. package/packages/core/dev-delivery-authority-evidence.js +146 -0
  122. package/packages/core/dev-delivery-authority-landing.js +461 -0
  123. package/packages/core/dev-delivery-authority-observation.js +48 -0
  124. package/packages/core/dev-delivery-authority-qualification.js +591 -0
  125. package/packages/core/dev-delivery-authority-settlement.js +213 -0
  126. package/packages/core/dev-delivery-authority-state.js +583 -0
  127. package/packages/core/dev-delivery-candidate-identity.js +13 -0
  128. package/packages/core/dev-delivery-contract-surface.js +76 -0
  129. package/packages/core/dev-delivery-execution-failure.js +133 -0
  130. package/packages/core/dev-delivery-execution-transfer.js +592 -0
  131. package/packages/core/dev-delivery-landing-admission-core.js +119 -0
  132. package/packages/core/dev-delivery-landing-readback.js +598 -0
  133. package/packages/core/dev-delivery-landing-terminal-evidence.js +271 -0
  134. package/packages/core/dev-delivery-landing-testing-port.js +6 -0
  135. package/packages/core/dev-delivery-native-execution.js +110 -0
  136. package/packages/core/dev-delivery-native-proof.js +562 -0
  137. package/packages/core/dev-delivery-process-boundary.js +563 -0
  138. package/packages/core/dev-delivery-proof.js +37 -3
  139. package/packages/core/dev-delivery-provider-attempt.js +127 -0
  140. package/packages/core/dev-delivery-provider-heartbeat.js +382 -0
  141. package/packages/core/dev-delivery-warrant-cancellation.js +1 -0
  142. package/packages/core/dev-delivery-warrant-qualification.js +145 -0
  143. package/packages/core/dev-delivery-warrant-settlement.js +237 -36
  144. package/packages/core/dev-delivery-warrant-state.js +587 -0
  145. package/packages/core/dev-delivery-warrant.js +328 -370
  146. package/packages/core/github-governance-authority.js +1 -0
  147. package/packages/core/index.js +7 -0
  148. package/packages/core/kungfu-temporal-fact.js +557 -0
  149. package/packages/core/legacy-kfd-adopter-driver.js +167 -0
  150. package/packages/core/next-development-candidate-reservation.js +186 -0
  151. package/packages/core/next-development-controller.js +728 -0
  152. package/packages/core/next-development-projection.js +287 -0
  153. package/packages/core/next-development-transition.js +738 -0
  154. package/packages/core/paper-agent-entry.js +11 -5
  155. package/packages/core/paper.js +16 -5
  156. package/packages/core/publication-authority.js +5 -5
  157. package/packages/core/published-delivery-authority.js +266 -0
  158. package/packages/core/release-candidate-recovery.js +66 -11
  159. package/packages/core/release-candidate.js +79 -19
  160. package/packages/core/release-passport.js +271 -38
  161. package/packages/core/v4-adopter-delivery-parity.js +3 -3
  162. package/packages/core/v4-adopter-delivery.js +359 -0
  163. package/packages/core/v4-canonical-contracts.js +5 -0
  164. package/packages/core/v4-delivery-warrant-read-candidate.js +10 -3
  165. package/packages/core/v4-floating-consumer-evidence.js +338 -0
  166. package/packages/core/v4-floating-consumer-policy.js +569 -0
  167. package/packages/core/v4-floating-consumer-release-passport.js +153 -0
  168. package/packages/core/v4-publication-rehearsal-capsule.js +468 -0
  169. package/packages/core/v4-publication-rehearsal-provider-bindings.js +212 -0
  170. package/packages/core/v4-publication-rehearsal.js +481 -0
  171. package/packages/core/v4-runtime-ref-resume-authority.js +625 -0
  172. package/packages/core/v4-runtime-selector-persistence.js +228 -0
  173. package/packages/core/v4-tail-reseal-contract.js +26 -0
  174. package/packages/core/v4-tail-reseal-github.js +178 -0
  175. package/packages/core/v4-tail-reseal-receipt.js +225 -0
  176. package/packages/core/v4-tail-reseal.js +594 -0
  177. package/packages/core/workflow-yaml-contract.js +72 -2
  178. package/scripts/audit-publication-control-plane.mjs +31 -31
  179. package/scripts/buildchain-cli-help.mjs +41 -2
  180. package/scripts/check-ci-lane-change-budget.mjs +100 -0
  181. package/scripts/check-inventory.mjs +14 -3
  182. package/scripts/check-v4-floating-consumer-policy-contract.mjs +217 -0
  183. package/scripts/check-v4-public-dogfood-contract.mjs +6 -11
  184. package/scripts/dev-alpha-candidate-patrol.mjs +22 -1
  185. package/scripts/dev-delivery-authority-command-adapters.mjs +206 -0
  186. package/scripts/dev-delivery-authority-provider.mjs +28 -0
  187. package/scripts/dev-delivery-authority.mjs +490 -0
  188. package/scripts/dev-delivery-native-run.mjs +177 -0
  189. package/scripts/dev-delivery-process-boundary.mjs +260 -0
  190. package/scripts/dev-delivery-proof.mjs +67 -2
  191. package/scripts/dev-delivery-provider-heartbeat.mjs +215 -0
  192. package/scripts/dev-delivery-source-proof-replay.mjs +153 -0
  193. package/scripts/dev-delivery-source-proof-reuse.mjs +547 -0
  194. package/scripts/dev-delivery-two-phase-resume.mjs +345 -0
  195. package/scripts/dev-delivery-two-phase.mjs +573 -0
  196. package/scripts/dev-delivery-warrant-options.mjs +266 -0
  197. package/scripts/dev-delivery-warrant-store.mjs +231 -0
  198. package/scripts/dev-delivery-warrant.mjs +232 -194
  199. package/scripts/dev-pr-auto-merge.mjs +37 -48
  200. package/scripts/dev-pr-delivery-warrant.mjs +216 -2
  201. package/scripts/dev-pr-prequeue-guard.mjs +399 -0
  202. package/scripts/dev-qualification-patrol.mjs +9 -9
  203. package/scripts/dispatch-artifact-signing-authority.mjs +1 -1
  204. package/scripts/ensure-github-release.mjs +3 -3
  205. package/scripts/generate-channel-build-workflow.mjs +3 -0
  206. package/scripts/generate-channel-promotion-workflow.mjs +114 -14
  207. package/scripts/generate-next-development-guidance.mjs +49 -0
  208. package/scripts/generate-release-candidate-passport.mjs +192 -32
  209. package/scripts/generate-site-bundle.mjs +69 -4
  210. package/scripts/init-repo.mjs +26 -4
  211. package/scripts/inspect-artifact-signing-requests.mjs +6 -0
  212. package/scripts/next-development-self-dogfood-harness.mjs +460 -0
  213. package/scripts/next-development-self-dogfood.mjs +597 -0
  214. package/scripts/next-development-transition.mjs +47 -0
  215. package/scripts/npm-publish-transaction.mjs +103 -91
  216. package/scripts/promotion-channel-router.mjs +4 -4
  217. package/scripts/release-candidate-anchor-provenance.mjs +99 -0
  218. package/scripts/release-tail.mjs +51 -3
  219. package/scripts/release-train-self-dogfood.mjs +94 -92
  220. package/scripts/resume-from-candidate-run.mjs +565 -41
  221. package/scripts/seal-artifact-signing-requests.mjs +6 -0
  222. package/scripts/site-capability-metadata.mjs +43 -0
  223. package/scripts/stable-candidate-qualification.mjs +9 -10
  224. package/scripts/v4-consumer-policy.mjs +231 -0
  225. package/scripts/v4-publication-rehearsal-fixture.mjs +144 -0
  226. package/scripts/v4-tail-reseal-macos-rehearsal.mjs +134 -0
  227. package/scripts/v4-tail-reseal.mjs +416 -0
  228. package/templates/native-dev-delivery.yml +143 -0
@@ -0,0 +1,240 @@
1
+ import { adopterDeliveryGateDigest } from "./adopter-delivery-gate.js";
2
+ import { validateAdopterDeliveryGateResult } from "./adopter-delivery-passport.js";
3
+
4
+ export const BUILDCHAIN_DELIVERY_BOOTSTRAP_CONTRACT =
5
+ "kungfu-buildchain-delivery-infrastructure-bootstrap/v1";
6
+
7
+ const ROOT_PATTERN = /^sha256:[0-9a-f]{64}$/;
8
+ const SHA_PATTERN = /^[0-9a-f]{40}$/;
9
+ const SEMVER_PATTERN =
10
+ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
11
+
12
+ function issue(code, message) {
13
+ return { code, message };
14
+ }
15
+
16
+ function exactRoot(value) {
17
+ return ROOT_PATTERN.test(value ?? "");
18
+ }
19
+
20
+ function exactCut(cut) {
21
+ return (
22
+ cut &&
23
+ typeof cut === "object" &&
24
+ typeof cut.version === "string" &&
25
+ SHA_PATTERN.test(cut.sourceCommit ?? "") &&
26
+ exactRoot(cut.packageRoot) &&
27
+ exactRoot(cut.gateRoot) &&
28
+ typeof cut.protocol?.id === "string" &&
29
+ typeof cut.protocol?.version === "string" &&
30
+ exactRoot(cut.protocol?.root) &&
31
+ typeof cut.profile?.id === "string" &&
32
+ typeof cut.profile?.version === "string" &&
33
+ exactRoot(cut.profile?.root)
34
+ );
35
+ }
36
+
37
+ function parseSemver(value) {
38
+ const match = SEMVER_PATTERN.exec(value ?? "");
39
+ if (!match) return null;
40
+ return {
41
+ core: match.slice(1, 4).map(Number),
42
+ prerelease: match[4] ? match[4].split(".") : [],
43
+ };
44
+ }
45
+
46
+ function compareIdentifier(left, right) {
47
+ const leftNumber = /^\d+$/.test(left) ? Number(left) : null;
48
+ const rightNumber = /^\d+$/.test(right) ? Number(right) : null;
49
+ if (leftNumber !== null && rightNumber !== null) {
50
+ return Math.sign(leftNumber - rightNumber);
51
+ }
52
+ if (leftNumber !== null) return -1;
53
+ if (rightNumber !== null) return 1;
54
+ return left === right ? 0 : left < right ? -1 : 1;
55
+ }
56
+
57
+ function compareSemver(leftValue, rightValue) {
58
+ const left = parseSemver(leftValue);
59
+ const right = parseSemver(rightValue);
60
+ if (!left || !right) return null;
61
+ for (let index = 0; index < left.core.length; index += 1) {
62
+ if (left.core[index] !== right.core[index]) {
63
+ return Math.sign(left.core[index] - right.core[index]);
64
+ }
65
+ }
66
+ if (left.prerelease.length === 0 || right.prerelease.length === 0) {
67
+ if (left.prerelease.length === right.prerelease.length) return 0;
68
+ return left.prerelease.length === 0 ? 1 : -1;
69
+ }
70
+ const width = Math.max(left.prerelease.length, right.prerelease.length);
71
+ for (let index = 0; index < width; index += 1) {
72
+ if (left.prerelease[index] === undefined) return -1;
73
+ if (right.prerelease[index] === undefined) return 1;
74
+ const comparison = compareIdentifier(
75
+ left.prerelease[index],
76
+ right.prerelease[index],
77
+ );
78
+ if (comparison !== 0) return comparison;
79
+ }
80
+ return 0;
81
+ }
82
+
83
+ function sameProtocol(left, right) {
84
+ return (
85
+ left?.id === right?.id &&
86
+ left?.version === right?.version &&
87
+ left?.root === right?.root
88
+ );
89
+ }
90
+
91
+ function validTransition(transition, authority, candidate) {
92
+ if (!transition || typeof transition !== "object") return false;
93
+ const body = structuredClone(transition);
94
+ const transitionRoot = body.transitionRoot;
95
+ delete body.transitionRoot;
96
+ return (
97
+ exactRoot(transitionRoot) &&
98
+ adopterDeliveryGateDigest(body) === transitionRoot &&
99
+ body.fromGateRoot === authority.gateRoot &&
100
+ body.toGateRoot === candidate.gateRoot &&
101
+ body.fromProtocolRoot === authority.protocol.root &&
102
+ body.toProtocolRoot === candidate.protocol.root &&
103
+ body.fromProfileRoot === authority.profile.root &&
104
+ body.toProfileRoot === candidate.profile.root &&
105
+ exactRoot(body.compatibilityProofRoot) &&
106
+ exactRoot(body.independentReviewRoot)
107
+ );
108
+ }
109
+
110
+ function validateWarrant(warrant, candidate) {
111
+ return (
112
+ warrant &&
113
+ typeof warrant === "object" &&
114
+ warrant.outcome === "merged" &&
115
+ warrant.sourceHead === candidate.sourceCommit &&
116
+ exactRoot(warrant.sourceProofRoot) &&
117
+ exactRoot(warrant.nativeProofRoot) &&
118
+ exactRoot(warrant.integrationProofRoot)
119
+ );
120
+ }
121
+
122
+ export function qualifyBuildchainDeliveryInfrastructureBootstrap({
123
+ authority,
124
+ candidate,
125
+ gateResult,
126
+ warrant,
127
+ transitionEvidence,
128
+ } = {}) {
129
+ const issues = [];
130
+ if (!exactCut(authority)) {
131
+ issues.push(
132
+ issue("bootstrap.authority.cut", "N-1 authority cut is incomplete"),
133
+ );
134
+ }
135
+ if (!exactCut(candidate)) {
136
+ issues.push(
137
+ issue("bootstrap.candidate.cut", "candidate cut is incomplete"),
138
+ );
139
+ }
140
+ if (authority?.protected !== true || authority?.published !== true) {
141
+ issues.push(
142
+ issue(
143
+ "bootstrap.authority.release",
144
+ "N-1 authority must be both protected and publicly released",
145
+ ),
146
+ );
147
+ }
148
+ if (candidate?.authorityVersion !== authority?.version) {
149
+ issues.push(
150
+ issue(
151
+ "bootstrap.authority.stale",
152
+ "candidate must name the exact N-1 authority version",
153
+ ),
154
+ );
155
+ }
156
+ const versionOrder = compareSemver(authority?.version, candidate?.version);
157
+ if (versionOrder === null || versionOrder >= 0) {
158
+ issues.push(
159
+ issue(
160
+ "bootstrap.authority.order",
161
+ "N-1 authority version must precede the candidate version",
162
+ ),
163
+ );
164
+ }
165
+ if (
166
+ authority?.sourceCommit === candidate?.sourceCommit ||
167
+ authority?.packageRoot === candidate?.packageRoot
168
+ ) {
169
+ issues.push(
170
+ issue(
171
+ "bootstrap.self-authorization",
172
+ "candidate source or package cannot serve as its own N-1 authority",
173
+ ),
174
+ );
175
+ }
176
+
177
+ const gateValidation = validateAdopterDeliveryGateResult(gateResult);
178
+ if (!gateValidation.passed) {
179
+ issues.push(
180
+ issue(
181
+ "bootstrap.gate.failed",
182
+ "candidate must retain a passed public adopter delivery gate result",
183
+ ),
184
+ );
185
+ }
186
+ if (
187
+ gateResult?.artifact?.root !== candidate?.packageRoot ||
188
+ gateResult?.project?.adopterId !== "kungfu-systems/buildchain"
189
+ ) {
190
+ issues.push(
191
+ issue(
192
+ "bootstrap.gate.candidate",
193
+ "gate result must bind the exact Buildchain candidate package",
194
+ ),
195
+ );
196
+ }
197
+ if (!validateWarrant(warrant, candidate)) {
198
+ issues.push(
199
+ issue(
200
+ "bootstrap.warrant",
201
+ "merged Delivery Warrant evidence must bind the candidate source",
202
+ ),
203
+ );
204
+ }
205
+
206
+ const transitionRequired =
207
+ !sameProtocol(authority?.protocol, candidate?.protocol) ||
208
+ !sameProtocol(authority?.profile, candidate?.profile) ||
209
+ authority?.gateRoot !== candidate?.gateRoot;
210
+ if (
211
+ transitionRequired &&
212
+ !validTransition(transitionEvidence, authority, candidate)
213
+ ) {
214
+ issues.push(
215
+ issue(
216
+ "bootstrap.transition",
217
+ "gate, protocol, or profile changes require exact independent transition evidence",
218
+ ),
219
+ );
220
+ }
221
+
222
+ const result = {
223
+ schemaVersion: 1,
224
+ contract: BUILDCHAIN_DELIVERY_BOOTSTRAP_CONTRACT,
225
+ status: issues.length === 0 ? "passed" : "failed",
226
+ authority: structuredClone(authority ?? null),
227
+ candidate: structuredClone(candidate ?? null),
228
+ gateResultRoot: gateResult?.gateRoot ?? null,
229
+ warrant: structuredClone(warrant ?? null),
230
+ transitionRequired,
231
+ transitionEvidenceRoot: transitionEvidence?.transitionRoot ?? null,
232
+ issues,
233
+ qualifying: false,
234
+ selfCertified: false,
235
+ releaseAuthorized: false,
236
+ finalAuthority: "protected-n-minus-one-plus-exact-delivery-evidence",
237
+ };
238
+ result.bootstrapRoot = adopterDeliveryGateDigest(result);
239
+ return result;
240
+ }
@@ -0,0 +1,164 @@
1
+ import { semanticRoot } from "@kungfu-tech/kfd/scripts/self-conformance-contract.mjs";
2
+
3
+ import {
4
+ resolvePublishedKfdAdopterCategoryProfiles,
5
+ verifyPublishedKfdAdopterCategoryInstance,
6
+ } from "./kfd-adopter-category-driver.js";
7
+
8
+ export const BUILDCHAIN_DELIVERY_INFRASTRUCTURE_ADOPTER_ID =
9
+ "kungfu-systems/buildchain";
10
+ export const BUILDCHAIN_DELIVERY_INFRASTRUCTURE_PROFILE = Object.freeze({
11
+ id: "kfd.adopter-category/delivery-infrastructure",
12
+ version: "1.0.0",
13
+ });
14
+
15
+ const CATEGORY_INSTANCE_SCHEMA =
16
+ "https://kfd.libkungfu.dev/schemas/kfd-adopter-conformance/category-instance-manifest.schema.json";
17
+ const CATEGORY_INSTANCE_CONTRACT = "kfd.adopter-category-instance-manifest/v1";
18
+ const ROOT_PATTERN = /^sha256:[0-9a-f]{64}$/;
19
+ const CLAIM_BOUNDARY = Object.freeze({
20
+ categoryConformanceIsDeclarationOnly: true,
21
+ evidenceTransfer: false,
22
+ runtimePermission: false,
23
+ releaseAuthorization: false,
24
+ independentCertification: false,
25
+ semanticAuthorityTransfer: false,
26
+ });
27
+
28
+ function exactEvidenceReference(value, index) {
29
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
30
+ throw new TypeError(`evidence[${index}] must be an object`);
31
+ }
32
+ const fields = ["requirementId", "kind", "coordinate", "root", "observedAt"];
33
+ const actual = Object.keys(value).sort();
34
+ const expected = [...fields].sort();
35
+ if (
36
+ actual.length !== expected.length ||
37
+ actual.some((field, fieldIndex) => field !== expected[fieldIndex])
38
+ ) {
39
+ throw new TypeError(`evidence[${index}] has an invalid field set`);
40
+ }
41
+ for (const field of ["requirementId", "kind", "coordinate", "observedAt"]) {
42
+ if (typeof value[field] !== "string" || value[field].length === 0) {
43
+ throw new TypeError(`evidence[${index}].${field} must be non-empty`);
44
+ }
45
+ }
46
+ if (!ROOT_PATTERN.test(value.root ?? "")) {
47
+ throw new TypeError(`evidence[${index}].root must be a sha256 root`);
48
+ }
49
+ return structuredClone(value);
50
+ }
51
+
52
+ function releaseBound(adopterManifest, artifact, release) {
53
+ return (adopterManifest?.releaseBindings ?? []).some(
54
+ (binding) =>
55
+ semanticRoot(binding.artifact) === semanticRoot(artifact) &&
56
+ semanticRoot(binding.releasePassport) === semanticRoot(release) &&
57
+ binding.kfdPackageRoot === adopterManifest.kfdCut.package.artifactRoot,
58
+ );
59
+ }
60
+
61
+ export function createBuildchainDeliveryInfrastructureInstanceManifest({
62
+ instanceId,
63
+ adopterManifest,
64
+ source,
65
+ artifact,
66
+ release,
67
+ evidence = [],
68
+ } = {}) {
69
+ if (typeof instanceId !== "string" || instanceId.length === 0) {
70
+ throw new TypeError("instanceId must be non-empty");
71
+ }
72
+ if (
73
+ adopterManifest?.adopter?.id !==
74
+ BUILDCHAIN_DELIVERY_INFRASTRUCTURE_ADOPTER_ID
75
+ ) {
76
+ throw new TypeError(
77
+ `adopterManifest must identify ${BUILDCHAIN_DELIVERY_INFRASTRUCTURE_ADOPTER_ID}`,
78
+ );
79
+ }
80
+ if (!releaseBound(adopterManifest, artifact, release)) {
81
+ throw new TypeError(
82
+ "adopterManifest must bind the exact Buildchain artifact and release",
83
+ );
84
+ }
85
+
86
+ const selection = {
87
+ schemaVersion: 1,
88
+ contract: "kfd.adopter-category-profile-selection/v1",
89
+ profiles: [structuredClone(BUILDCHAIN_DELIVERY_INFRASTRUCTURE_PROFILE)],
90
+ };
91
+ const resolution = resolvePublishedKfdAdopterCategoryProfiles(selection);
92
+ if (!resolution.valid) {
93
+ throw new Error(
94
+ `published delivery-infrastructure profile did not resolve: ${JSON.stringify(resolution.issues)}`,
95
+ );
96
+ }
97
+
98
+ const project = {
99
+ adopterId: BUILDCHAIN_DELIVERY_INFRASTRUCTURE_ADOPTER_ID,
100
+ source: structuredClone(source),
101
+ artifact: structuredClone(artifact),
102
+ release: structuredClone(release),
103
+ };
104
+ const projectRoot = semanticRoot(project);
105
+ const adopterManifestRoot = semanticRoot(adopterManifest);
106
+ const packageRoot = adopterManifest.kfdCut.package.artifactRoot;
107
+ const requirementIds = new Set(
108
+ resolution.requirements.map((requirement) => requirement.id),
109
+ );
110
+ const suppliedEvidence = evidence.map(exactEvidenceReference);
111
+ for (const [index, entry] of suppliedEvidence.entries()) {
112
+ if (!requirementIds.has(entry.requirementId)) {
113
+ throw new TypeError(
114
+ `evidence[${index}].requirementId is not selected by the published profile`,
115
+ );
116
+ }
117
+ }
118
+
119
+ return {
120
+ $schema: CATEGORY_INSTANCE_SCHEMA,
121
+ schemaVersion: 1,
122
+ contract: CATEGORY_INSTANCE_CONTRACT,
123
+ instanceId,
124
+ rootAlgorithm: "sha256-kfd-canonical-json-v1",
125
+ project,
126
+ adopterManifest: {
127
+ contract: adopterManifest.contract,
128
+ manifestId: adopterManifest.manifestId,
129
+ root: adopterManifestRoot,
130
+ },
131
+ kfdCut: {
132
+ packageVersion: adopterManifest.kfdCut.package.version,
133
+ packageRoot,
134
+ categoryCatalogRoot: resolution.catalogRoot,
135
+ },
136
+ selection,
137
+ selectionRoot: resolution.selectionRoot,
138
+ requirements: resolution.requirements.map((requirement) => ({
139
+ id: requirement.id,
140
+ evidence: suppliedEvidence
141
+ .filter((entry) => entry.requirementId === requirement.id)
142
+ .map(({ requirementId: _requirementId, ...entry }) => ({
143
+ ...entry,
144
+ projectInstanceId: instanceId,
145
+ projectRoot,
146
+ adopterManifestRoot,
147
+ kfdPackageRoot: packageRoot,
148
+ categorySelectionRoot: resolution.selectionRoot,
149
+ })),
150
+ })),
151
+ claimBoundary: structuredClone(CLAIM_BOUNDARY),
152
+ };
153
+ }
154
+
155
+ export function verifyBuildchainDeliveryInfrastructureInstance(
156
+ manifest,
157
+ { adopterManifest, verifiedAt, maxAgeSeconds } = {},
158
+ ) {
159
+ return verifyPublishedKfdAdopterCategoryInstance(manifest, {
160
+ adopterManifest,
161
+ verifiedAt,
162
+ maxAgeSeconds,
163
+ });
164
+ }