@kungfu-tech/buildchain 4.0.1-alpha.2 → 4.0.1-alpha.21

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 (203) hide show
  1. package/actions/release-tail/README.md +8 -0
  2. package/architecture/ci-lane-change-budget.json +187 -0
  3. package/architecture/decisions/0002-next-development-transition.md +101 -0
  4. package/architecture/decisions/0003-two-phase-delivery-warrant.md +152 -0
  5. package/architecture/internal-capabilities.json +211 -8
  6. package/architecture/maintainability-policy.json +113 -28
  7. package/architecture/release-tail-contract-inventory.json +5 -2
  8. package/architecture/v3-core-mechanism-inventory.json +91 -0
  9. package/architecture/v4-adopter-delivery-parity.json +32 -5
  10. package/architecture/v4-capability-state-machine-manifest.json +73 -0
  11. package/architecture/v4-compatibility-facts-parity.json +77 -0
  12. package/architecture/v4-delivery-authority-parity.json +250 -0
  13. package/architecture/v4-delivery-warrant-shadow-fixtures.json +41 -9
  14. package/architecture/v4-floating-consumer-policy.json +6 -0
  15. package/architecture/v4-next-development-parity.json +192 -0
  16. package/architecture/v4-publication-rehearsal-parity.json +84 -0
  17. package/architecture/v4-release-train-parity.json +1 -0
  18. package/architecture/v4-tail-reseal-parity.json +150 -0
  19. package/bin/buildchain.mjs +32 -3
  20. package/bin/internal/adopter-delivery-cli.mjs +70 -0
  21. package/bin/internal/command-registry.mjs +3 -0
  22. package/bin/internal/compatibility-facts-cli.mjs +101 -0
  23. package/contracts/dev-delivery-authority-v2.schema.json +662 -0
  24. package/contracts/fixtures/next-development-transition-v1/anchored-manual-waiting.json +47 -0
  25. package/contracts/fixtures/next-development-transition-v1/semver-auto-planned.json +47 -0
  26. package/contracts/fixtures/next-development-transition-v1/version-model-cases.json +40 -0
  27. package/contracts/fixtures/v4-adopter-delivery-v1/archive-template.json +19 -0
  28. package/contracts/fixtures/v4-adopter-delivery-v1/bootstrap-positive.json +93 -0
  29. package/contracts/fixtures/v4-adopter-delivery-v1/gate-positive.json +29 -0
  30. package/contracts/fixtures/v4-adopter-delivery-v1/gate-unknown-selector.json +26 -0
  31. package/contracts/fixtures/v4-adopter-delivery-v1/offline-vectors.json +50 -0
  32. package/contracts/fixtures/v4-compatibility-facts-v1/shared.json +1129 -0
  33. package/contracts/fixtures/v4-floating-consumer-policy-v1/cases.json +7 -1
  34. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/artifacts/product.bin +1 -0
  35. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/config/buildchain.toml +5 -0
  36. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/documents/release-activation.json +1 -0
  37. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/documents/signed-channel.json +1 -0
  38. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/evidence/qualification.json +1 -0
  39. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/manifests/candidate.json +5 -0
  40. package/contracts/fixtures/v4-publication-rehearsal-v1/candidate/manifests/release-passport.json +1 -0
  41. package/contracts/fixtures/v4-publication-rehearsal-v1/capsule.json +707 -0
  42. package/contracts/fixtures/v4-publication-rehearsal-v1/offline-vectors.json +27 -0
  43. package/contracts/fixtures/v4-tail-reseal-v1/valid.json +229 -0
  44. package/contracts/next-development-request-v1.schema.json +66 -0
  45. package/contracts/next-development-transition-v1.schema.json +292 -0
  46. package/contracts/v4-adopter-delivery-v1.schema.json +81 -0
  47. package/contracts/v4-compatibility-facts-v1.schema.json +230 -0
  48. package/contracts/v4-floating-consumer-policy-receipt-v1.schema.json +4 -2
  49. package/contracts/v4-publication-rehearsal-capsule-v1.schema.json +233 -0
  50. package/contracts/v4-tail-reseal-v1.schema.json +276 -0
  51. package/dist/site/agent-index.json +5 -0
  52. package/dist/site/artifact-schemas.json +10 -0
  53. package/dist/site/buildchain-contract.json +1475 -27
  54. package/dist/site/buildchain-site.json +627 -31
  55. package/dist/site/capability-registry.json +17 -14
  56. package/dist/site/cli-registry.json +205 -3
  57. package/dist/site/kfd-claims.json +490 -16
  58. package/dist/site/kfd-upstream-aggregate.json +1 -1
  59. package/dist/site/manual-registry.json +52 -6
  60. package/dist/site/node-api-registry.json +14736 -8851
  61. package/dist/site/page-registry.json +593 -21
  62. package/dist/site/public-surface-audit.json +837 -48
  63. package/dist/site/publication-authority-registry.json +44 -8
  64. package/dist/site/publication-registry.json +4 -4
  65. package/dist/site/release-provenance.json +24 -0
  66. package/dist/site/schemas/dev-delivery-authority-v2.schema.json +662 -0
  67. package/dist/site/schemas/release-tail-capabilities-v1.schema.json +199 -0
  68. package/dist/site/schemas/v4-adopter-delivery-v1.schema.json +81 -0
  69. package/dist/site/schemas/v4-compatibility-facts-v1.schema.json +230 -0
  70. package/dist/site/schemas/v4-publication-rehearsal-capsule-v1.schema.json +233 -0
  71. package/dist/site/site-manifest.json +34 -10
  72. package/dist/site/workflow-registry.json +160 -10
  73. package/docs/MAP.md +8 -2
  74. package/docs/cli-reference.md +404 -13
  75. package/docs/cli.md +8 -0
  76. package/docs/dev-alpha-candidate-patrol.md +8 -0
  77. package/docs/dev-delivery-qualification-landing-adr.md +251 -0
  78. package/docs/dev-delivery-warrant.md +351 -38
  79. package/docs/next-development-transition.md +118 -0
  80. package/docs/node-api-reference.md +646 -293
  81. package/docs/release-tail-provider-plane.md +30 -0
  82. package/docs/v4-adopter-delivery.md +133 -0
  83. package/docs/v4-compatibility-facts.md +91 -0
  84. package/docs/v4-publication-rehearsal.md +130 -0
  85. package/docs/v4-tail-reseal.md +73 -0
  86. package/docs/versioning.md +4 -3
  87. package/package.json +34 -6
  88. package/packages/core/adopter-delivery-passport.js +259 -0
  89. package/packages/core/adopter-delivery-vectors.js +158 -0
  90. package/packages/core/adopter-delivery-vectors.json +77 -0
  91. package/packages/core/buildchain-agent-manuals.js +3 -0
  92. package/packages/core/buildchain-compatibility-authority.js +336 -0
  93. package/packages/core/buildchain-compatibility-fact.js +394 -0
  94. package/packages/core/buildchain-compatibility-facts.json +217 -0
  95. package/packages/core/buildchain-compatibility-proof.js +566 -0
  96. package/packages/core/buildchain-config.js +84 -0
  97. package/packages/core/buildchain-contract.js +96 -143
  98. package/packages/core/buildchain-delivery-bootstrap.js +240 -0
  99. package/packages/core/buildchain-delivery-infrastructure.js +164 -0
  100. package/packages/core/buildchain-delivery-self-dogfood.js +395 -0
  101. package/packages/core/buildchain-publication-authority.js +1 -0
  102. package/packages/core/channel-candidate.js +8 -0
  103. package/packages/core/channel-promotion-baseline.js +55 -0
  104. package/packages/core/ci-lane-change-budget.js +247 -0
  105. package/packages/core/dev-alpha-candidate-selection.js +10 -2
  106. package/packages/core/dev-delivery-authority-candidate.js +270 -0
  107. package/packages/core/dev-delivery-authority-evidence.js +146 -0
  108. package/packages/core/dev-delivery-authority-landing.js +461 -0
  109. package/packages/core/dev-delivery-authority-observation.js +48 -0
  110. package/packages/core/dev-delivery-authority-qualification.js +591 -0
  111. package/packages/core/dev-delivery-authority-settlement.js +213 -0
  112. package/packages/core/dev-delivery-authority-state.js +583 -0
  113. package/packages/core/dev-delivery-candidate-identity.js +13 -0
  114. package/packages/core/dev-delivery-contract-surface.js +76 -0
  115. package/packages/core/dev-delivery-execution-failure.js +133 -0
  116. package/packages/core/dev-delivery-execution-transfer.js +592 -0
  117. package/packages/core/dev-delivery-landing-admission-core.js +119 -0
  118. package/packages/core/dev-delivery-landing-readback.js +598 -0
  119. package/packages/core/dev-delivery-landing-terminal-evidence.js +271 -0
  120. package/packages/core/dev-delivery-landing-testing-port.js +6 -0
  121. package/packages/core/dev-delivery-native-execution.js +110 -0
  122. package/packages/core/dev-delivery-native-proof.js +562 -0
  123. package/packages/core/dev-delivery-process-boundary.js +563 -0
  124. package/packages/core/dev-delivery-provider-attempt.js +127 -0
  125. package/packages/core/dev-delivery-provider-heartbeat.js +382 -0
  126. package/packages/core/dev-delivery-warrant-cancellation.js +1 -0
  127. package/packages/core/dev-delivery-warrant-qualification.js +145 -0
  128. package/packages/core/dev-delivery-warrant-settlement.js +237 -36
  129. package/packages/core/dev-delivery-warrant-state.js +587 -0
  130. package/packages/core/dev-delivery-warrant.js +328 -370
  131. package/packages/core/github-governance-authority.js +1 -0
  132. package/packages/core/index.js +5 -0
  133. package/packages/core/kungfu-temporal-fact.js +557 -0
  134. package/packages/core/legacy-kfd-adopter-driver.js +167 -0
  135. package/packages/core/next-development-candidate-reservation.js +186 -0
  136. package/packages/core/next-development-controller.js +728 -0
  137. package/packages/core/next-development-projection.js +287 -0
  138. package/packages/core/next-development-transition.js +738 -0
  139. package/packages/core/paper-agent-entry.js +11 -5
  140. package/packages/core/paper.js +16 -5
  141. package/packages/core/published-delivery-authority.js +266 -0
  142. package/packages/core/release-candidate-recovery.js +70 -15
  143. package/packages/core/release-candidate.js +2 -2
  144. package/packages/core/release-passport.js +36 -9
  145. package/packages/core/v4-adopter-delivery-parity.js +3 -3
  146. package/packages/core/v4-adopter-delivery.js +359 -0
  147. package/packages/core/v4-canonical-contracts.js +5 -0
  148. package/packages/core/v4-delivery-warrant-read-candidate.js +10 -3
  149. package/packages/core/v4-floating-consumer-evidence.js +18 -4
  150. package/packages/core/v4-floating-consumer-policy.js +143 -20
  151. package/packages/core/v4-floating-consumer-release-passport.js +32 -5
  152. package/packages/core/v4-publication-rehearsal-capsule.js +468 -0
  153. package/packages/core/v4-publication-rehearsal-provider-bindings.js +212 -0
  154. package/packages/core/v4-publication-rehearsal.js +481 -0
  155. package/packages/core/v4-tail-reseal-contract.js +26 -0
  156. package/packages/core/v4-tail-reseal-github.js +178 -0
  157. package/packages/core/v4-tail-reseal-receipt.js +225 -0
  158. package/packages/core/v4-tail-reseal.js +594 -0
  159. package/packages/core/workflow-yaml-contract.js +24 -2
  160. package/scripts/buildchain-cli-help.mjs +41 -2
  161. package/scripts/check-ci-lane-change-budget.mjs +100 -0
  162. package/scripts/check-inventory.mjs +14 -3
  163. package/scripts/check-v4-floating-consumer-policy-contract.mjs +23 -4
  164. package/scripts/dev-alpha-candidate-patrol.mjs +22 -1
  165. package/scripts/dev-delivery-authority-command-adapters.mjs +206 -0
  166. package/scripts/dev-delivery-authority-provider.mjs +28 -0
  167. package/scripts/dev-delivery-authority.mjs +490 -0
  168. package/scripts/dev-delivery-native-run.mjs +177 -0
  169. package/scripts/dev-delivery-process-boundary.mjs +260 -0
  170. package/scripts/dev-delivery-proof.mjs +67 -2
  171. package/scripts/dev-delivery-provider-heartbeat.mjs +215 -0
  172. package/scripts/dev-delivery-source-proof-replay.mjs +153 -0
  173. package/scripts/dev-delivery-source-proof-reuse.mjs +13 -97
  174. package/scripts/dev-delivery-two-phase-resume.mjs +345 -0
  175. package/scripts/dev-delivery-two-phase.mjs +573 -0
  176. package/scripts/dev-delivery-warrant-options.mjs +266 -0
  177. package/scripts/dev-delivery-warrant-store.mjs +231 -0
  178. package/scripts/dev-delivery-warrant.mjs +232 -194
  179. package/scripts/dev-pr-auto-merge.mjs +1 -1
  180. package/scripts/dev-pr-delivery-warrant.mjs +11 -0
  181. package/scripts/dev-qualification-patrol.mjs +9 -9
  182. package/scripts/dispatch-artifact-signing-authority.mjs +1 -1
  183. package/scripts/generate-channel-promotion-workflow.mjs +2 -2
  184. package/scripts/generate-next-development-guidance.mjs +49 -0
  185. package/scripts/generate-release-candidate-passport.mjs +152 -0
  186. package/scripts/generate-site-bundle.mjs +69 -4
  187. package/scripts/init-repo.mjs +22 -4
  188. package/scripts/next-development-self-dogfood-harness.mjs +460 -0
  189. package/scripts/next-development-self-dogfood.mjs +597 -0
  190. package/scripts/next-development-transition.mjs +47 -0
  191. package/scripts/npm-publish-transaction.mjs +2 -2
  192. package/scripts/promotion-channel-router.mjs +4 -4
  193. package/scripts/release-candidate-anchor-provenance.mjs +99 -0
  194. package/scripts/release-tail.mjs +51 -3
  195. package/scripts/release-train-self-dogfood.mjs +94 -92
  196. package/scripts/resume-from-candidate-run.mjs +557 -30
  197. package/scripts/site-capability-metadata.mjs +41 -0
  198. package/scripts/stable-candidate-qualification.mjs +9 -10
  199. package/scripts/v4-consumer-policy.mjs +5 -5
  200. package/scripts/v4-publication-rehearsal-fixture.mjs +144 -0
  201. package/scripts/v4-tail-reseal-macos-rehearsal.mjs +134 -0
  202. package/scripts/v4-tail-reseal.mjs +416 -0
  203. package/templates/native-dev-delivery.yml +143 -0
@@ -0,0 +1,266 @@
1
+ export function flag(args, name, fallback = "") {
2
+ const index = args.indexOf(`--${name}`);
3
+ return index === -1 ? fallback : args[index + 1] || "";
4
+ }
5
+
6
+ export function hasFlag(args, name) {
7
+ return args.includes(`--${name}`);
8
+ }
9
+
10
+ export function devDeliveryCliOptions(args = [], environment = process.env) {
11
+ const [command = "", ...rest] = args;
12
+ return {
13
+ command,
14
+ repository: flag(rest, "repository", environment.GITHUB_REPOSITORY),
15
+ branch: flag(
16
+ rest,
17
+ "branch",
18
+ environment.BUILDCHAIN_DEV_DELIVERY_BRANCH || environment.GITHUB_BASE_REF,
19
+ ),
20
+ stateRef: flag(
21
+ rest,
22
+ "state-ref",
23
+ environment.BUILDCHAIN_DEV_DELIVERY_STATE_REF,
24
+ ),
25
+ expectedOldStateRoot: flag(
26
+ rest,
27
+ "expected-old",
28
+ environment.BUILDCHAIN_DEV_DELIVERY_EXPECTED_OLD,
29
+ ),
30
+ pullRequestNumber: flag(
31
+ rest,
32
+ "pull-request",
33
+ environment.BUILDCHAIN_DEV_DELIVERY_PR_NUMBER,
34
+ ),
35
+ candidateId: flag(
36
+ rest,
37
+ "candidate-id",
38
+ environment.BUILDCHAIN_DEV_DELIVERY_CANDIDATE_ID,
39
+ ),
40
+ sourceHead: flag(
41
+ rest,
42
+ "source-head",
43
+ environment.BUILDCHAIN_DEV_DELIVERY_SOURCE_HEAD,
44
+ ),
45
+ expectedSourceHead: flag(
46
+ rest,
47
+ "expected-source-head",
48
+ environment.BUILDCHAIN_DEV_DELIVERY_EXPECTED_SOURCE_HEAD,
49
+ ),
50
+ observedSourceHead: flag(
51
+ rest,
52
+ "observed-source-head",
53
+ environment.BUILDCHAIN_DEV_DELIVERY_OBSERVED_SOURCE_HEAD,
54
+ ),
55
+ assignmentRoot: flag(
56
+ rest,
57
+ "assignment-root",
58
+ environment.BUILDCHAIN_DEV_DELIVERY_ASSIGNMENT_ROOT,
59
+ ),
60
+ initiativeRoot: flag(
61
+ rest,
62
+ "initiative-root",
63
+ environment.BUILDCHAIN_DEV_DELIVERY_INITIATIVE_ROOT,
64
+ ),
65
+ sourceIdentityRoot: flag(
66
+ rest,
67
+ "source-identity-root",
68
+ environment.BUILDCHAIN_DEV_DELIVERY_SOURCE_IDENTITY_ROOT,
69
+ ),
70
+ sourcePatchRoot: flag(
71
+ rest,
72
+ "source-patch-root",
73
+ environment.BUILDCHAIN_DEV_DELIVERY_SOURCE_PATCH_ROOT,
74
+ ),
75
+ sourceProofRoot: flag(
76
+ rest,
77
+ "source-proof-root",
78
+ environment.BUILDCHAIN_DEV_DELIVERY_SOURCE_PROOF_ROOT,
79
+ ),
80
+ sourceWorkflowRunId: flag(
81
+ rest,
82
+ "source-workflow-run-id",
83
+ environment.BUILDCHAIN_DEV_DELIVERY_SOURCE_WORKFLOW_RUN_ID,
84
+ ),
85
+ affectedPaths: flag(
86
+ rest,
87
+ "affected-paths-json",
88
+ environment.BUILDCHAIN_DEV_DELIVERY_AFFECTED_PATHS || "[]",
89
+ ),
90
+ shardEvidenceRoots: flag(
91
+ rest,
92
+ "shard-evidence-roots-json",
93
+ environment.BUILDCHAIN_DEV_DELIVERY_SHARD_EVIDENCE_ROOTS || "[]",
94
+ ),
95
+ nativeCommand: flag(
96
+ rest,
97
+ "native-command",
98
+ environment.BUILDCHAIN_DEV_DELIVERY_NATIVE_COMMAND,
99
+ ),
100
+ nativeCommandRoot: flag(
101
+ rest,
102
+ "native-command-root",
103
+ environment.BUILDCHAIN_DEV_DELIVERY_NATIVE_COMMAND_ROOT,
104
+ ),
105
+ releaseBlockerPriority: flag(
106
+ rest,
107
+ "release-blocker-priority-json",
108
+ environment.BUILDCHAIN_DEV_DELIVERY_RELEASE_BLOCKER_PRIORITY,
109
+ ),
110
+ nativeProofPath: flag(
111
+ rest,
112
+ "native-proof",
113
+ environment.BUILDCHAIN_DEV_DELIVERY_NATIVE_PROOF,
114
+ ),
115
+ nativeReuseDecisionPath: flag(
116
+ rest,
117
+ "native-reuse-decision",
118
+ environment.BUILDCHAIN_DEV_DELIVERY_NATIVE_REUSE_DECISION,
119
+ ),
120
+ currentBase: flag(
121
+ rest,
122
+ "current-base",
123
+ environment.BUILDCHAIN_DEV_DELIVERY_CURRENT_BASE,
124
+ ),
125
+ changedPaths: flag(
126
+ rest,
127
+ "changed-paths-json",
128
+ environment.BUILDCHAIN_DEV_DELIVERY_CHANGED_PATHS || "[]",
129
+ ),
130
+ graphKnown: ["1", "true", "yes", "on"].includes(
131
+ flag(rest, "graph-known", environment.BUILDCHAIN_DEV_DELIVERY_GRAPH_KNOWN)
132
+ .trim()
133
+ .toLowerCase(),
134
+ ),
135
+ attributionComplete: ["1", "true", "yes", "on"].includes(
136
+ flag(
137
+ rest,
138
+ "attribution-complete",
139
+ environment.BUILDCHAIN_DEV_DELIVERY_ATTRIBUTION_COMPLETE,
140
+ )
141
+ .trim()
142
+ .toLowerCase(),
143
+ ),
144
+ renames: flag(
145
+ rest,
146
+ "renames-json",
147
+ environment.BUILDCHAIN_DEV_DELIVERY_RENAMES || "[]",
148
+ ),
149
+ planRoot: flag(
150
+ rest,
151
+ "plan-root",
152
+ environment.BUILDCHAIN_DEV_DELIVERY_PLAN_ROOT,
153
+ ),
154
+ closureRoot: flag(
155
+ rest,
156
+ "closure-root",
157
+ environment.BUILDCHAIN_DEV_DELIVERY_CLOSURE_ROOT,
158
+ ),
159
+ dependencyRoot: flag(
160
+ rest,
161
+ "dependency-root",
162
+ environment.BUILDCHAIN_DEV_DELIVERY_DEPENDENCY_ROOT,
163
+ ),
164
+ toolchainRoot: flag(
165
+ rest,
166
+ "toolchain-root",
167
+ environment.BUILDCHAIN_DEV_DELIVERY_TOOLCHAIN_ROOT,
168
+ ),
169
+ environmentRoot: flag(
170
+ rest,
171
+ "environment-root",
172
+ environment.BUILDCHAIN_DEV_DELIVERY_ENVIRONMENT_ROOT,
173
+ ),
174
+ deliveryClass: flag(
175
+ rest,
176
+ "delivery-class",
177
+ environment.BUILDCHAIN_DEV_DELIVERY_CLASS,
178
+ ),
179
+ priority: flag(
180
+ rest,
181
+ "priority",
182
+ environment.BUILDCHAIN_DEV_DELIVERY_PRIORITY || "ordinary",
183
+ ),
184
+ fencingToken: flag(
185
+ rest,
186
+ "fencing-token",
187
+ environment.BUILDCHAIN_DEV_DELIVERY_FENCING_TOKEN,
188
+ ),
189
+ leaseGeneration: flag(
190
+ rest,
191
+ "lease-generation",
192
+ environment.BUILDCHAIN_DEV_DELIVERY_LEASE_GENERATION,
193
+ ),
194
+ leaseSeconds: flag(
195
+ rest,
196
+ "lease-seconds",
197
+ environment.BUILDCHAIN_DEV_DELIVERY_LEASE_SECONDS,
198
+ ),
199
+ outcome: flag(rest, "outcome", environment.BUILDCHAIN_DEV_DELIVERY_OUTCOME),
200
+ eventAction: flag(
201
+ rest,
202
+ "event-action",
203
+ environment.BUILDCHAIN_DEV_DELIVERY_EVENT_ACTION,
204
+ ),
205
+ evidenceRoot: flag(
206
+ rest,
207
+ "evidence-root",
208
+ environment.BUILDCHAIN_DEV_DELIVERY_EVIDENCE_ROOT,
209
+ ),
210
+ transferRoot: flag(rest, "transfer-root"),
211
+ finalizerBoundaryRoot: flag(rest, "finalizer-boundary-root"),
212
+ nativeJobId: flag(rest, "native-job-id"),
213
+ sealJobId: flag(rest, "seal-job-id"),
214
+ reason: flag(rest, "reason", environment.BUILDCHAIN_DEV_DELIVERY_REASON),
215
+ readMode: flag(
216
+ rest,
217
+ "read-mode",
218
+ environment.BUILDCHAIN_V4_WARRANT_READ_MODE || "v3",
219
+ ),
220
+ readQualificationPath: flag(
221
+ rest,
222
+ "read-qualification",
223
+ environment.BUILDCHAIN_V4_WARRANT_READ_QUALIFICATION,
224
+ ),
225
+ readQualificationRoot: flag(
226
+ rest,
227
+ "read-qualification-root",
228
+ environment.BUILDCHAIN_V4_WARRANT_READ_QUALIFICATION_ROOT,
229
+ ),
230
+ readTypescriptRevision: flag(
231
+ rest,
232
+ "read-typescript-revision",
233
+ environment.BUILDCHAIN_V4_WARRANT_TYPESCRIPT_REVISION,
234
+ ),
235
+ readRustRevision: flag(
236
+ rest,
237
+ "read-rust-revision",
238
+ environment.BUILDCHAIN_V4_WARRANT_RUST_REVISION,
239
+ ),
240
+ readValidatorVersion: flag(
241
+ rest,
242
+ "read-validator-version",
243
+ environment.BUILDCHAIN_V4_WARRANT_VALIDATOR_VERSION,
244
+ ),
245
+ readTimeoutMs: flag(
246
+ rest,
247
+ "read-timeout-ms",
248
+ environment.BUILDCHAIN_V4_WARRANT_READ_TIMEOUT_MS || "5000",
249
+ ),
250
+ readEvidenceOutput: flag(
251
+ rest,
252
+ "read-evidence-output",
253
+ environment.BUILDCHAIN_V4_WARRANT_READ_EVIDENCE ||
254
+ ".buildchain/dev-delivery/v4-read-evidence.json",
255
+ ),
256
+ now: flag(rest, "now", environment.BUILDCHAIN_DEV_DELIVERY_NOW),
257
+ outputPath: flag(
258
+ rest,
259
+ "output",
260
+ environment.BUILDCHAIN_DEV_DELIVERY_OUTPUT ||
261
+ ".buildchain/dev-delivery/result.json",
262
+ ),
263
+ execute: hasFlag(rest, "execute"),
264
+ json: hasFlag(rest, "json"),
265
+ };
266
+ }
@@ -0,0 +1,231 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import {
3
+ createDevDeliveryQueue,
4
+ devDeliveryContentRoot,
5
+ normalizeDevDeliveryQueue,
6
+ } from "../packages/core/dev-delivery-warrant.js";
7
+ import { normalizeDevDeliveryAuthorityState } from "../packages/core/dev-delivery-authority-state.js";
8
+
9
+ const STATE_PATH = "queue.json";
10
+
11
+ function text(value = "") {
12
+ return String(value ?? "").trim();
13
+ }
14
+
15
+ function exactSha(value, label) {
16
+ const normalized = text(value).toLowerCase();
17
+ if (!/^[0-9a-f]{40}$/.test(normalized)) {
18
+ throw new Error(`${label} must be a 40-character Git SHA`);
19
+ }
20
+ return normalized;
21
+ }
22
+
23
+ function normalizeRepository(value) {
24
+ const normalized = text(value);
25
+ const match = normalized.match(/^([^/\s]+)\/([^/\s]+)$/);
26
+ if (!match) {
27
+ throw new Error(
28
+ `repository must be owner/repo, got ${normalized || "<empty>"}`,
29
+ );
30
+ }
31
+ return { owner: match[1], repo: match[2], fullName: normalized };
32
+ }
33
+
34
+ function encodeRef(ref) {
35
+ return ref.split("/").map(encodeURIComponent).join("/");
36
+ }
37
+
38
+ function decodeBlob(blob) {
39
+ if (blob.encoding !== "base64")
40
+ throw new Error(
41
+ `unsupported Git blob encoding ${blob.encoding || "<empty>"}`,
42
+ );
43
+ return Buffer.from(
44
+ String(blob.content || "").replace(/\s+/g, ""),
45
+ "base64",
46
+ ).toString("utf8");
47
+ }
48
+
49
+ function validateStoredState(queue, { allowLegacyV3Readback = false } = {}) {
50
+ const body = structuredClone(queue || {});
51
+ const embeddedStateRoot = body.stateRoot;
52
+ delete body.stateRoot;
53
+ if (embeddedStateRoot !== devDeliveryContentRoot(body)) {
54
+ throw new Error("dev delivery persisted stateRoot drift");
55
+ }
56
+ if (
57
+ queue?.contract === "kungfu-buildchain-dev-delivery-authority" &&
58
+ Number(queue?.schemaVersion) === 2
59
+ ) {
60
+ normalizeDevDeliveryAuthorityState(queue);
61
+ } else {
62
+ normalizeDevDeliveryQueue(queue, { allowLegacyV3Readback });
63
+ }
64
+ return queue;
65
+ }
66
+
67
+ export class GitHubDevDeliveryStore {
68
+ constructor({
69
+ repository,
70
+ token,
71
+ apiUrl = "https://api.github.com",
72
+ fetchImpl = globalThis.fetch,
73
+ createInitialState = createDevDeliveryQueue,
74
+ } = {}) {
75
+ this.repository = normalizeRepository(repository);
76
+ if (!fetchImpl) throw new Error("fetch is required");
77
+ if (!token)
78
+ throw new Error(
79
+ "GITHUB_TOKEN is required for the GitHub dev delivery store",
80
+ );
81
+ this.token = token;
82
+ this.apiUrl = apiUrl.replace(/\/+$/, "");
83
+ this.fetch = fetchImpl;
84
+ this.createInitialState = createInitialState;
85
+ }
86
+
87
+ async request(method, requestPath, body) {
88
+ const response = await this.fetch(`${this.apiUrl}${requestPath}`, {
89
+ method,
90
+ headers: {
91
+ accept: "application/vnd.github+json",
92
+ authorization: `Bearer ${this.token}`,
93
+ "content-type": "application/json",
94
+ "x-github-api-version": "2022-11-28",
95
+ },
96
+ body: body === undefined ? undefined : JSON.stringify(body),
97
+ });
98
+ const raw = await response.text();
99
+ const data = raw ? JSON.parse(raw) : null;
100
+ if (!response.ok) {
101
+ const error = new Error(
102
+ data?.message || raw || `${method} ${requestPath} failed`,
103
+ );
104
+ error.status = response.status;
105
+ error.data = data;
106
+ throw error;
107
+ }
108
+ return data;
109
+ }
110
+
111
+ async read({ stateRef, protectedBase, now, allowLegacyV3Readback = false }) {
112
+ let ref;
113
+ try {
114
+ ref = await this.request(
115
+ "GET",
116
+ `/repos/${this.repository.fullName}/git/ref/heads/${encodeRef(stateRef)}`,
117
+ );
118
+ } catch (error) {
119
+ if (error.status !== 404) throw error;
120
+ return {
121
+ exists: false,
122
+ commitSha: "",
123
+ queue: this.createInitialState({
124
+ repository: this.repository.fullName,
125
+ protectedBase,
126
+ now,
127
+ }),
128
+ };
129
+ }
130
+ const commitSha = exactSha(ref?.object?.sha, "state ref commit");
131
+ const readback = await this.readCommit(commitSha, {
132
+ allowLegacyV3Readback,
133
+ });
134
+ return { exists: true, ...readback };
135
+ }
136
+
137
+ async readCommit(commitShaInput, { allowLegacyV3Readback = false } = {}) {
138
+ const commitSha = exactSha(commitShaInput, "state commit");
139
+ const commit = await this.request(
140
+ "GET",
141
+ `/repos/${this.repository.fullName}/git/commits/${commitSha}`,
142
+ );
143
+ const tree = await this.request(
144
+ "GET",
145
+ `/repos/${this.repository.fullName}/git/trees/${commit.tree?.sha}`,
146
+ );
147
+ const entry = (tree.tree || []).find(
148
+ (item) => item.path === STATE_PATH && item.type === "blob",
149
+ );
150
+ if (!entry?.sha)
151
+ throw new Error(`${commitSha} does not contain ${STATE_PATH}`);
152
+ const blob = await this.request(
153
+ "GET",
154
+ `/repos/${this.repository.fullName}/git/blobs/${entry.sha}`,
155
+ );
156
+ const bytes = decodeBlob(blob);
157
+ const queue = validateStoredState(JSON.parse(bytes), {
158
+ allowLegacyV3Readback,
159
+ });
160
+ return { commitSha, queue, bytes };
161
+ }
162
+
163
+ async write({
164
+ stateRef,
165
+ queue,
166
+ expectedCommitSha,
167
+ expectedStateRoot,
168
+ receiptRoot,
169
+ }) {
170
+ if (queue.stateRoot === expectedStateRoot)
171
+ throw new Error("state transition did not advance the queue root");
172
+ const parent = expectedCommitSha
173
+ ? exactSha(expectedCommitSha, "expected state commit")
174
+ : "";
175
+ validateStoredState(queue);
176
+ const expectedBytes = `${JSON.stringify(queue, null, 2)}\n`;
177
+ const blob = await this.request(
178
+ "POST",
179
+ `/repos/${this.repository.fullName}/git/blobs`,
180
+ {
181
+ content: expectedBytes,
182
+ encoding: "utf-8",
183
+ },
184
+ );
185
+ const tree = await this.request(
186
+ "POST",
187
+ `/repos/${this.repository.fullName}/git/trees`,
188
+ {
189
+ tree: [
190
+ { path: STATE_PATH, mode: "100644", type: "blob", sha: blob.sha },
191
+ ],
192
+ },
193
+ );
194
+ const commit = await this.request(
195
+ "POST",
196
+ `/repos/${this.repository.fullName}/git/commits`,
197
+ {
198
+ message: `chore(dev-delivery): advance Warrant queue ${receiptRoot.slice(0, 20)}`,
199
+ tree: tree.sha,
200
+ parents: parent ? [parent] : [],
201
+ },
202
+ );
203
+ if (expectedCommitSha) {
204
+ await this.request(
205
+ "PATCH",
206
+ `/repos/${this.repository.fullName}/git/refs/heads/${encodeRef(stateRef)}`,
207
+ { sha: commit.sha, force: false },
208
+ );
209
+ } else {
210
+ await this.request(
211
+ "POST",
212
+ `/repos/${this.repository.fullName}/git/refs`,
213
+ {
214
+ ref: `refs/heads/${stateRef}`,
215
+ sha: commit.sha,
216
+ },
217
+ );
218
+ }
219
+ const readback = await this.readCommit(commit.sha);
220
+ if (
221
+ readback.commitSha !== commit.sha ||
222
+ readback.bytes !== expectedBytes ||
223
+ !isDeepStrictEqual(readback.queue, queue)
224
+ ) {
225
+ throw new Error(
226
+ "dev delivery state commit readback mismatch after expected-old update",
227
+ );
228
+ }
229
+ return { commitSha: commit.sha, stateRoot: readback.queue.stateRoot };
230
+ }
231
+ }