@kungfu-tech/buildchain 4.1.3-alpha.9 → 4.1.4-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 (205) hide show
  1. package/AGENTS.md +11 -13
  2. package/CONTRIBUTING.md +32 -9
  3. package/README.md +56 -140
  4. package/actions/release/promotion/ref/README.md +1 -1
  5. package/architecture/action-taxonomy.json +1 -1
  6. package/architecture/agent-change-map.md +32 -45
  7. package/architecture/build-orchestration.json +1 -1
  8. package/architecture/capability-state-machine-manifest.json +5 -5
  9. package/architecture/ci-lane-change-budget.json +92 -92
  10. package/architecture/code-layout.json +2 -12
  11. package/architecture/core-mechanisms.json +38 -39
  12. package/architecture/cross-platform-adopter-qualification.json +1 -1
  13. package/architecture/dev-delivery-orchestration.json +2 -2
  14. package/architecture/floating-consumer-policy.json +3 -3
  15. package/architecture/internal-capabilities.json +27 -28
  16. package/architecture/maintainability-debt.json +60 -94
  17. package/architecture/maintainability-policy.json +7 -13
  18. package/architecture/minimal-consumer-migration.json +43 -5014
  19. package/architecture/platform-stage-checkpoints.json +1 -1
  20. package/architecture/release-tail-contract.json +2 -2
  21. package/architecture/release-topology.json +33 -25
  22. package/architecture/stage-capsule-qualification.json +1 -1
  23. package/architecture/universal-workflow-bootstrap.json +60 -60
  24. package/architecture/universal-workflow-capability-policy.json +3 -3
  25. package/architecture/universal-workflow-fault-campaign.json +7 -7
  26. package/architecture/workflow-taxonomy.json +59 -60
  27. package/contracts/fixtures/v4-tail-reseal-v1/valid.json +1 -1
  28. package/dist/site/buildchain-contract.json +138 -66
  29. package/dist/site/buildchain-site.json +257 -331
  30. package/dist/site/capability-registry.json +4 -4
  31. package/dist/site/cli-registry.json +6 -142
  32. package/dist/site/controller-registry.json +19 -19
  33. package/dist/site/kfd-claims.json +481 -529
  34. package/dist/site/kfd-upstream-aggregate.json +1 -1
  35. package/dist/site/manual-registry.json +22 -22
  36. package/dist/site/node-api-registry.json +82 -339
  37. package/dist/site/page-registry.json +229 -304
  38. package/dist/site/public-surface-audit.json +544 -754
  39. package/dist/site/publication-authority-registry.json +316 -316
  40. package/dist/site/publication-registry.json +1 -1
  41. package/dist/site/site-manifest.json +23 -23
  42. package/dist/site/workflow-registry.json +1071 -1027
  43. package/docs/MAP.md +28 -20
  44. package/docs/auditable-demo.md +17 -49
  45. package/docs/bootstrap-recovery.md +46 -37
  46. package/docs/cli-reference.md +2 -46
  47. package/docs/cli.md +97 -186
  48. package/docs/code-organization.md +7 -5
  49. package/docs/dev-alpha-candidate-patrol.md +19 -42
  50. package/docs/dev-delivery-orchestration.md +15 -11
  51. package/docs/dev-delivery-qualification-landing-adr.md +10 -9
  52. package/docs/dev-delivery-warrant.md +17 -16
  53. package/docs/dev-qualification-patrol.md +25 -20
  54. package/docs/getting-started.md +80 -139
  55. package/docs/github-artifact-attestation.md +31 -81
  56. package/docs/install.md +66 -30
  57. package/docs/lifecycle-protocol.md +19 -57
  58. package/docs/migration-inventory.md +17 -45
  59. package/docs/next-development-transition.md +13 -13
  60. package/docs/node-api-reference.md +122 -138
  61. package/docs/oci-publication.md +13 -10
  62. package/docs/publication-artifacts.md +128 -486
  63. package/docs/publication-authority.md +15 -45
  64. package/docs/publish-transaction.md +13 -11
  65. package/docs/release-candidate.md +126 -355
  66. package/docs/release-discussions.md +36 -67
  67. package/docs/release-flow.md +80 -339
  68. package/docs/release-governance.md +114 -962
  69. package/docs/release-promotion-request.md +45 -43
  70. package/docs/release-propagation.md +13 -27
  71. package/docs/release-tail-provider-plane.md +38 -65
  72. package/docs/reusable-build-surface.md +78 -196
  73. package/docs/runtime-train-validation.md +8 -6
  74. package/docs/stable-candidate-patrol.md +13 -66
  75. package/docs/v4-adopter-delivery.md +15 -15
  76. package/docs/v4-declarative-release-tail-migration.md +19 -17
  77. package/docs/v4-production-release.md +11 -6
  78. package/docs/v4-publication-rehearsal.md +12 -27
  79. package/docs/v4-stage-capsule.md +14 -20
  80. package/docs/v4-tail-reseal.md +34 -20
  81. package/docs/web-surface-deployments.md +26 -264
  82. package/docs/workflow-catalog.md +31 -31
  83. package/docs/workflow-path-migration.md +10 -4
  84. package/package.json +5 -4
  85. package/packages/core/adoption/buildchain-kfd-claims.js +7 -7
  86. package/packages/core/adoption/cli/output.mjs +1 -9
  87. package/packages/core/adoption/cli/product-gate.mjs +1 -15
  88. package/packages/core/adoption/cli/project.mjs +9 -10
  89. package/packages/core/adoption/cli/standards.mjs +1 -14
  90. package/packages/core/adoption/cli/support.mjs +0 -2
  91. package/packages/core/adoption/cli/surface-register.mjs +0 -2
  92. package/packages/core/adoption/commands/init-repo.mjs +77 -485
  93. package/packages/core/adoption/consumer-init.js +279 -0
  94. package/packages/core/adoption/qualification/admission.js +1 -1
  95. package/packages/core/build/cli/cache.mjs +0 -2
  96. package/packages/core/build/cli/facts.mjs +0 -3
  97. package/packages/core/build/cli/homebrew.mjs +0 -4
  98. package/packages/core/build/cli/lifecycle.mjs +0 -3
  99. package/packages/core/build/github-artifact-attestation.js +2 -2
  100. package/packages/core/build/platform-stage-checkpoints.js +1 -1
  101. package/packages/core/build/signing/dispatch.js +1 -1
  102. package/packages/core/consumer/buildchain-config.js +9 -0
  103. package/packages/core/consumer/contract/inspection.js +351 -9
  104. package/packages/core/consumer/contract/javascript-syntax.js +439 -0
  105. package/packages/core/consumer/contract/javascript-values.js +61 -0
  106. package/packages/core/consumer/contract/javascript.js +555 -0
  107. package/packages/core/consumer/contract/local-validation.js +84 -0
  108. package/packages/core/contracts/buildchain-contract.js +39 -8
  109. package/packages/core/contracts/cli/introspection.mjs +1 -9
  110. package/packages/core/contracts/public-surface-cli.js +0 -1
  111. package/packages/core/dev-delivery/dev-delivery-contract-surface.js +2 -2
  112. package/packages/core/governance/buildchain-publication-authority.js +24 -24
  113. package/packages/core/governance/cli/doctor.mjs +58 -42
  114. package/packages/core/governance/commands/architecture.mjs +6 -1
  115. package/packages/core/governance/commands/audit-publication-control-plane.mjs +1 -1
  116. package/packages/core/governance/commands/workflow-friction-report.mjs +1 -1
  117. package/packages/core/governance/github-governance-authority.js +2 -2
  118. package/packages/core/governance/publication/collection.js +1 -1
  119. package/packages/core/index.js +1 -3
  120. package/packages/core/observability/cli/candidate.mjs +0 -2
  121. package/packages/core/observability/cli/context.mjs +0 -5
  122. package/packages/core/observability/cli/diagnostics.mjs +0 -7
  123. package/packages/core/observability/cli/events.mjs +2 -10
  124. package/packages/core/paper/commands/paper-work-fleet-cli.mjs +1 -1
  125. package/packages/core/paper/commands/paper.mjs +33 -422
  126. package/packages/core/paper/consumer-status.js +72 -0
  127. package/packages/core/paper/operations/identity.js +0 -3
  128. package/packages/core/paper/operations/migration.js +460 -0
  129. package/packages/core/paper/operations/preflight-checks.js +8 -68
  130. package/packages/core/paper/operations/scaffold.js +16 -326
  131. package/packages/core/paper/operations/status.js +27 -53
  132. package/packages/core/paper/paper-agent-entry.js +36 -147
  133. package/packages/core/paper/paper-fleet.js +24 -39
  134. package/packages/core/paper/paper-repository.js +16 -0
  135. package/packages/core/paper/paper-runtime-channels.js +1 -1
  136. package/packages/core/paper/paper-scaffold-content.js +153 -162
  137. package/packages/core/paper/paper-work.js +3 -10
  138. package/packages/core/paper/paper.js +43 -5
  139. package/packages/core/providers/github/artifact-attestation.js +1 -1
  140. package/packages/core/providers/github/pipeline-context-artifacts.js +172 -0
  141. package/packages/core/providers/github/pipeline-release-evidence.js +17 -98
  142. package/packages/core/providers/github/pipeline-stable-baseline.js +86 -0
  143. package/packages/core/providers/github/pipeline-stable-source.js +22 -4
  144. package/packages/core/providers/github/release-evidence-assets.js +97 -0
  145. package/packages/core/publication/authority/control-plane.js +2 -2
  146. package/packages/core/publication/authority/seal.js +1 -1
  147. package/packages/core/publication/cli/dispatch.mjs +1 -12
  148. package/packages/core/publication/pipeline/actions.js +16 -9
  149. package/packages/core/publication/pipeline/apply.js +17 -9
  150. package/packages/core/publication/pipeline/context.js +29 -0
  151. package/packages/core/publication/pipeline/journal.js +13 -1
  152. package/packages/core/publication/pipeline/prepare.js +15 -6
  153. package/packages/core/publication/pipeline/recovery-import.js +1 -1
  154. package/packages/core/publication/pipeline/recovery-materials.js +63 -1
  155. package/packages/core/publication/pipeline/recovery-prepare.js +21 -9
  156. package/packages/core/publication/pipeline/stable-entry.js +12 -3
  157. package/packages/core/publication/pipeline/stable-products.js +21 -19
  158. package/packages/core/publication/pipeline/version-actions.js +15 -6
  159. package/packages/core/publication/publication-rehearsal-projection.js +0 -9
  160. package/packages/core/release/cli/dispatch.mjs +1 -4
  161. package/packages/core/release/cli/inspection-handlers.mjs +1 -33
  162. package/packages/core/release/cli/release-handlers.mjs +2 -19
  163. package/packages/core/release/cli/verification-handlers.mjs +4 -25
  164. package/packages/core/release/next-development-projection.js +13 -13
  165. package/packages/core/release/passport/locations.js +13 -8
  166. package/packages/core/release/release-passport.js +70 -5
  167. package/packages/core/web/cli/badges.mjs +0 -4
  168. package/packages/core/web/publication-admission.js +1 -1
  169. package/packages/core/web/publication-capability.js +1 -1
  170. package/packages/core/web/readme-badges.js +1 -1
  171. package/packages/core/workflow/cli/main.mjs +1 -4
  172. package/packages/core/workflow/cli/process.mjs +1 -1
  173. package/packages/core/workflow/commands/buildchain-cli-help.mjs +2 -8
  174. package/packages/core/workflow/engine/conformance.js +1 -1
  175. package/packages/core/workflow/pipeline/build.js +21 -1
  176. package/packages/core/workflow/pipeline/delivery-observation.js +6 -2
  177. package/packages/core/workflow/workflow-taxonomy.mjs +61 -17
  178. package/scripts/check-code-layout.mjs +2 -0
  179. package/scripts/check-core-mechanism-inventory.mjs +29 -13
  180. package/scripts/check-floating-consumer-policy-contract.mjs +3 -3
  181. package/scripts/check-inventory.mjs +27 -27
  182. package/scripts/check-maintainability.mjs +28 -5
  183. package/scripts/check-public-dogfood-contract.mjs +3 -3
  184. package/scripts/check-release-topology.mjs +1 -1
  185. package/scripts/check-self-consumer-contract.mjs +7 -7
  186. package/scripts/check-universal-workflow-bootstrap.mjs +1 -1
  187. package/scripts/generate-channel-promotion-workflow.mjs +1 -1
  188. package/scripts/generate-minimal-consumer-contract.mjs +21 -1
  189. package/scripts/generate-site-bundle.mjs +2 -1
  190. package/scripts/generate-tail-reseal-fixture.mjs +3 -3
  191. package/scripts/inventory/promotion.mjs +1 -1
  192. package/scripts/next-development-self-dogfood-harness.mjs +1 -1
  193. package/scripts/next-development-self-dogfood.mjs +4 -4
  194. package/scripts/site-capability-metadata.mjs +2 -6
  195. package/scripts/source-metric-lineage.mjs +62 -7
  196. package/scripts/verify-golden-path.mjs +31 -35
  197. package/templates/native-dev-delivery.yml +1 -1
  198. package/templates/universal-buildchain-bootstrap.yml +1 -1
  199. package/packages/core/paper/operations/bootstrap.js +0 -75
  200. package/packages/core/paper/operations/plans.js +0 -213
  201. package/packages/core/paper/operations/provisioning.js +0 -113
  202. package/packages/core/paper/operations/scaffold-config.js +0 -77
  203. package/packages/core/paper/operations/scaffold-workflows.js +0 -116
  204. package/packages/core/paper/operations/workspace.js +0 -60
  205. package/packages/core/paper/paper-npm-bootstrap.js +0 -492
@@ -9,8 +9,6 @@ import {
9
9
  readBooleanFlag,
10
10
  readFlag,
11
11
  readJsonInput,
12
- readRepeatedFlag,
13
- readRepeatedJsonInputs,
14
12
  writeJsonFile,
15
13
  } from "../../contracts/cli/options.mjs";
16
14
 
@@ -10,9 +10,7 @@ import {
10
10
  printJson,
11
11
  readBooleanFlag,
12
12
  readFlag,
13
- readJsonInput,
14
13
  readRepeatedFlag,
15
- readRepeatedJsonInputs,
16
14
  writeJsonFile,
17
15
  } from "../../contracts/cli/options.mjs";
18
16
 
@@ -2,407 +2,28 @@
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { pathToFileURL } from "node:url";
5
- import { BUILDCHAIN_CONFIG_PATH } from "../../contracts/buildchain-layout.js";
6
- import { detectPackageManager, assertPackageManager } from "../../build/package-manager.js";
7
5
  import {
8
- appendNextDevelopmentToml,
9
- mergeNextDevelopmentAgentInstructions,
10
- nextDevelopmentWorkflowHeader,
11
- } from "../../release/next-development-projection.js";
12
-
13
- const BUILDCHAIN_WORKFLOW_REF = "kungfu-systems/buildchain/.github/workflows/build.yml@v4";
14
- const DEFAULT_PUBLICATION_LATEX_IMAGE = "ghcr.io/kungfu-systems/build-images/latex-pdf-builder";
15
- const DEFAULT_PUBLICATION_LATEX_DIGEST = "sha256:c20f3809e96836c1c78e97c76939d12f1de3fed0ea9b7c40c43332ec2ea480f8";
16
- const DEFAULT_PUBLICATION_LATEX_COMMAND = "latexmk -pdf -outdir=_build paper/main.tex";
17
-
18
- function posixPath(value) {
19
- return String(value || "").split(path.sep).join("/");
20
- }
21
-
22
- function repoName(cwd) {
23
- return path.basename(path.resolve(cwd));
24
- }
25
-
26
- function detectOrDefaultPackageManager(cwd, requested) {
27
- if (requested) {
28
- return assertPackageManager(requested);
29
- }
30
- try {
31
- return detectPackageManager(cwd).name;
32
- } catch {
33
- return "pnpm";
34
- }
35
- }
36
-
37
- function packageLifecycle(manager) {
38
- if (manager === "npm") {
39
- return {
40
- install: "npm ci",
41
- build: "npm run build",
42
- verify: "npm run check",
43
- };
44
- }
45
- if (manager === "yarn") {
46
- return {
47
- install: "corepack yarn install --immutable",
48
- build: "corepack yarn run build",
49
- verify: "corepack yarn run check",
50
- };
51
- }
52
- return {
53
- install: "corepack pnpm install --frozen-lockfile",
54
- build: "corepack pnpm run build",
55
- verify: "corepack pnpm run check",
56
- };
57
- }
58
-
59
- function packageToml(cwd, manager) {
60
- const lifecycle = packageLifecycle(manager);
61
- const hasPackageJson = fs.existsSync(path.join(cwd, "package.json"));
62
- const versionFiles = hasPackageJson
63
- ? `
64
- [[version.files]]
65
- type = "json"
66
- path = "package.json"
67
- key = "version"
68
- `
69
- : "";
70
- return `schema = 1
71
-
72
- [project]
73
- type = "package"
74
- name = "${repoName(cwd)}"
75
-
76
- [version]
77
- required = ${hasPackageJson ? "true" : "false"}
78
- strategy = "semver"
79
- next = "auto"
80
- ${versionFiles}
81
- [lifecycle.install]
82
- command = "${lifecycle.install}"
83
-
84
- [lifecycle.build]
85
- command = "${lifecycle.build}"
86
-
87
- [lifecycle.verify]
88
- command = "${lifecycle.verify}"
89
- `;
90
- }
91
-
92
- function nativeToml(cwd) {
93
- return `schema = 1
94
-
95
- [project]
96
- type = "package"
97
- name = "${repoName(cwd)}"
98
-
99
- [version]
100
- required = false
101
- strategy = "semver"
102
- next = "auto"
103
-
104
- [[version.files]]
105
- type = "regex"
106
- path = "CMakeLists.txt"
107
- pattern = 'project\\([^)]* VERSION (?<version>[^ )]+)'
108
- replacement = '\${version}'
109
-
110
- [lifecycle.configure]
111
- commands = [
112
- "cmake -S . -B build -DCMAKE_BUILD_TYPE=Release",
113
- ]
114
-
115
- [lifecycle.build]
116
- commands = [
117
- "cmake --build build --config Release",
118
- ]
119
-
120
- [lifecycle.verify]
121
- commands = [
122
- "ctest --test-dir build --output-on-failure",
123
- ]
124
-
125
- [diagnostics.native]
126
- enabled = true
127
- sample_process_tree = false
128
- compiler_cache = "auto"
129
- expected_tools = ["ccache", "sccache", "clang", "cl", "cmake", "ninja"]
130
- artifact_dirs = ["build", "dist"]
131
- `;
132
- }
133
-
134
- function anchoredPackageToml(cwd, manager) {
135
- const lifecycle = packageLifecycle(manager);
136
- return `schema = 1
137
-
138
- [project]
139
- type = "package"
140
- name = "${repoName(cwd)}"
141
-
142
- [version]
143
- required = true
144
- strategy = "anchored"
145
- next = "manual"
146
- manifest = "release.json"
147
-
148
- [[version.files]]
149
- type = "json"
150
- path = "package.json"
151
- key = "version"
152
-
153
- [lifecycle.install]
154
- command = "${lifecycle.install}"
155
-
156
- [lifecycle.build]
157
- command = "${lifecycle.build}"
158
-
159
- [lifecycle.verify]
160
- command = "${lifecycle.verify}"
161
- `;
162
- }
163
-
164
- function webSurfaceToml(cwd) {
165
- const name = repoName(cwd);
166
- return `schema = 1
167
-
168
- [project]
169
- type = "web-surface"
170
- name = "${name}"
171
- site = "${name}"
172
-
173
- [channels.preview]
174
- url_pattern = "https://{alias}.preview.example.com"
175
- visibility = "ephemeral"
176
- requires_auth = false
177
- noindex = true
178
-
179
- [channels.staging]
180
- url = "https://staging.example.com"
181
- visibility = "protected"
182
- access_control = "managed-network"
183
- edge_auth = "none"
184
- noindex = true
185
- promotable = true
186
-
187
- [channels.production]
188
- url = "https://example.com"
189
- visibility = "public"
190
- requires_auth = false
191
- noindex = false
192
- canonical = true
193
-
194
- [deploy.preview]
195
- adapter = "aws-s3-cloudfront"
196
- artifact_path = "dist"
197
- bucket_ref = "AWS_PREVIEW_BUCKET"
198
- distribution_ref = "AWS_PREVIEW_DISTRIBUTION"
199
-
200
- [deploy.staging]
201
- adapter = "aws-s3-cloudfront"
202
- artifact_path = "dist"
203
- bucket_ref = "AWS_STAGING_BUCKET"
204
- distribution_ref = "AWS_STAGING_DISTRIBUTION"
205
-
206
- [deploy.production]
207
- adapter = "aws-s3-cloudfront"
208
- artifact_path = "dist"
209
- bucket_ref = "AWS_PRODUCTION_BUCKET"
210
- distribution_ref = "AWS_PRODUCTION_DISTRIBUTION"
211
-
212
- [security.staging]
213
- noindex = true
214
- isolated_providers = true
215
-
216
- [lifecycle.build]
217
- command = "corepack pnpm run build"
218
-
219
- [lifecycle.verify]
220
- command = "corepack pnpm run check"
221
- `;
222
- }
223
-
224
- function infraContractToml(cwd) {
225
- const name = repoName(cwd);
226
- return `schema = 1
227
-
228
- [project]
229
- type = "infra-contract"
230
- name = "${name}"
231
-
232
- [infra]
233
- adapter = "manual-observed"
234
- adoption_mode = "manual-observed"
235
- apply = "disabled"
236
- environment = "staging"
237
- desired = ["infra/desired.json"]
238
- contract = ["infra/outputs.json"]
239
-
240
- [[consumers]]
241
- repo = "kungfu-systems/site-example"
242
- path = "infra/outputs.json"
243
- source = "infra/outputs.json"
244
-
245
- [lifecycle.verify]
246
- command = "buildchain infra-contract --mode ci"
247
- `;
248
- }
249
-
250
- function publicationArtifactToml(cwd) {
251
- const name = repoName(cwd);
252
- return `schema = 1
253
-
254
- [project]
255
- type = "publication-artifact"
256
- name = "${name}"
257
-
258
- [publication]
259
- kind = "paper"
260
- title = "${name}"
261
- primary_artifact = "_build/main.pdf"
262
- artifact_paths = ["_build/main.pdf"]
263
- metadata_paths = ["README.md", "docs/MAP.md"]
264
- source_paths = ["paper", "README.md", "LICENSE", "Makefile"]
265
- site_consumers = ["papers-site"]
266
- manifest_path = ".buildchain/publication/publication-artifact.json"
267
- source_bundle_path = ".buildchain/publication/source.tar.gz"
268
-
269
- [publication.toolchain]
270
- type = "latex-docker"
271
- image = "${DEFAULT_PUBLICATION_LATEX_IMAGE}"
272
- digest = "${DEFAULT_PUBLICATION_LATEX_DIGEST}"
273
- command = "${DEFAULT_PUBLICATION_LATEX_COMMAND}"
274
-
275
- [lifecycle.build]
276
- command = "make pdf"
277
-
278
- [lifecycle.verify]
279
- command = "make check"
280
- `;
281
- }
282
-
283
- function infraContractDesiredJson(cwd) {
284
- return `${JSON.stringify({
285
- service: repoName(cwd),
286
- environment: "staging",
287
- resources: [
288
- {
289
- kind: "static-site",
290
- name: repoName(cwd),
291
- desiredState: {
292
- hostname: "staging.example.com",
293
- accessControl: "managed-network",
294
- owner: "platform",
295
- },
296
- },
297
- ],
298
- }, null, 2)}\n`;
299
- }
300
-
301
- function infraContractOutputsJson(cwd) {
302
- return `${JSON.stringify({
303
- service: repoName(cwd),
304
- environment: "staging",
305
- observedMode: "manual-observed",
306
- outputs: {
307
- hostname: "staging.example.com",
308
- distributionId: "observed-distribution-id",
309
- bucket: "observed-bucket-name",
310
- },
311
- }, null, 2)}\n`;
312
- }
313
-
314
- function workflowArtifactPaths(type) {
315
- if (type === "infra-contract") {
316
- return `.buildchain/infra-contract-validate.json
317
- .buildchain/infra-contract-plan.json
318
- .buildchain/buildchain.infra-contract.json
319
- .buildchain/infra-contract-propagation.json
320
- .buildchain/infra-contract-propagation-apply.json
321
- .buildchain/infra-contract-evidence-bundle.json
322
- .buildchain/infra-contract-evidence-verification.json`;
323
- }
324
- if (type === "publication-artifact") {
325
- return `_build/main.pdf
326
- .buildchain/publication/publication-artifact.json
327
- .buildchain/publication/publication-artifact-passport.json
328
- .buildchain/publication/source.tar.gz`;
329
- }
330
- return `dist
331
- build/stage`;
332
- }
333
-
334
- function publicationWorkflowYaml() {
335
- return `${nextDevelopmentWorkflowHeader()}# Commit both .buildchain/contract-lock.json and .buildchain/alpha-contract-lock.json.
336
- # Persist only @v4 or @v4-alpha; pass temporary train/SHA runtimes through workflow_dispatch.
337
- name: Build
338
-
339
- on:
340
- workflow_dispatch:
341
- inputs:
342
- runtime-ref:
343
- description: "Temporary Buildchain runtime ref for trusted manual validation"
344
- required: false
345
- default: ""
346
- pull_request:
347
- push:
348
- branches:
349
- - "dev/**"
350
- - "alpha/**"
351
- - "release/**"
352
-
353
- permissions:
354
- contents: read
355
- issues: write
356
-
357
- jobs:
358
- publication:
359
- uses: kungfu-systems/buildchain/.github/workflows/public-build-publication.yml@v4
360
- with:
361
- runtime-ref: \${{ inputs.runtime-ref || '' }}
362
- toolchain-type: config
363
- verify-command: make check
364
- artifact-name: publication-artifact
365
- `;
366
- }
367
-
368
- function workflowYaml() {
369
- return `${nextDevelopmentWorkflowHeader()}# Project build settings live only in .buildchain/buildchain.toml.
370
- # Commit .buildchain/contract-lock.json and .buildchain/alpha-contract-lock.json.
371
- # The called ref selects the runtime; architecture/platform-stage-checkpoints.json owns checkpoint projections.
372
- name: Build
373
-
374
- on:
375
- workflow_dispatch:
376
- pull_request:
377
- push:
378
- branches: ["dev/**", "alpha/**", "release/**"]
379
-
380
- permissions:
381
- actions: read
382
- contents: read
383
- issues: write
384
- id-token: write
385
-
386
- jobs:
387
- build:
388
- uses: ${BUILDCHAIN_WORKFLOW_REF}
389
- `;
390
- }
391
-
392
- function writeIfAllowed(filePath, content, { force }) {
393
- if (fs.existsSync(filePath) && !force) {
394
- throw new Error(`${posixPath(filePath)} already exists; pass --force to overwrite`);
6
+ consumerAgentInstructions,
7
+ planConsumerInitialization,
8
+ } from "../consumer-init.js";
9
+ import { PIPELINE_ENTRY } from "../../consumer/contract/entries.js";
10
+
11
+ function assertWritable(cwd, relative, force) {
12
+ const parts = relative.split("/");
13
+ for (let index = 1; index <= parts.length; index++) {
14
+ const name = path.join(cwd, ...parts.slice(0, index));
15
+ const stat = fs.lstatSync(name, { throwIfNoEntry: false });
16
+ if (!stat) continue;
17
+ if (
18
+ stat.isSymbolicLink() ||
19
+ (index < parts.length ? !stat.isDirectory() : !stat.isFile())
20
+ )
21
+ throw new Error(
22
+ `${relative}: initialization requires regular files and directories`,
23
+ );
24
+ if (index === parts.length && !force)
25
+ throw new Error(`${relative} already exists; pass --force to overwrite`);
395
26
  }
396
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
397
- fs.writeFileSync(filePath, content);
398
- return filePath;
399
- }
400
-
401
- function writeManagedAgentEntry(filePath, current) {
402
- const content = mergeNextDevelopmentAgentInstructions(current);
403
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
404
- fs.writeFileSync(filePath, content);
405
- return filePath;
406
27
  }
407
28
 
408
29
  export function initBuildchainRepo({
@@ -413,104 +34,75 @@ export function initBuildchainRepo({
413
34
  runnerPreset = "github-hosted",
414
35
  artifactName = "",
415
36
  } = {}) {
416
- const resolvedCwd = path.resolve(cwd);
417
- const manager = detectOrDefaultPackageManager(resolvedCwd, packageManager);
418
- let toml = appendNextDevelopmentToml((() => {
419
- if (type === "package") {
420
- return packageToml(resolvedCwd, manager);
421
- }
422
- if (type === "native") {
423
- return nativeToml(resolvedCwd);
424
- }
425
- if (type === "web-surface") {
426
- return webSurfaceToml(resolvedCwd);
427
- }
428
- if (type === "infra-contract") {
429
- return infraContractToml(resolvedCwd);
430
- }
431
- if (type === "publication-artifact") {
432
- return publicationArtifactToml(resolvedCwd);
433
- }
434
- if (type === "anchored-package") {
435
- return anchoredPackageToml(resolvedCwd, manager);
436
- }
437
- throw new Error("init --type must be one of package, native, web-surface, infra-contract, publication-artifact, or anchored-package");
438
- })());
439
-
440
-
441
- if (type !== "publication-artifact") {
442
- const paths = workflowArtifactPaths(type).split("\n").map((entry) => entry.trim());
443
- toml += `
444
- [build]
445
- environment = ${JSON.stringify(runnerPreset)}
446
-
447
- [build.artifacts]
448
- name = ${JSON.stringify(artifactName || repoName(resolvedCwd))}
449
- paths = ${JSON.stringify(paths)}
450
- `;
451
- }
452
-
453
- const agentsPath = path.join(resolvedCwd, "AGENTS.md");
454
- const currentAgents = fs.existsSync(agentsPath)
455
- ? fs.readFileSync(agentsPath, "utf8")
456
- : "";
457
-
458
- const written = [
459
- writeIfAllowed(path.join(resolvedCwd, BUILDCHAIN_CONFIG_PATH), toml, { force }),
460
- writeIfAllowed(
461
- path.join(resolvedCwd, ".github", "workflows", "build.yml"),
462
- type === "publication-artifact"
463
- ? publicationWorkflowYaml()
464
- : workflowYaml({
465
- type,
466
- runnerPreset,
467
- artifactName,
468
- }),
469
- { force },
470
- ),
471
- writeManagedAgentEntry(agentsPath, currentAgents),
472
- ];
473
-
474
- if (type === "anchored-package" && !fs.existsSync(path.join(resolvedCwd, "release.json"))) {
475
- written.push(writeIfAllowed(path.join(resolvedCwd, "release.json"), "{\n \"upstream\": \"\",\n \"version\": \"0.0.0\"\n}\n", { force }));
476
- }
477
-
478
- if (type === "infra-contract") {
479
- written.push(
480
- writeIfAllowed(path.join(resolvedCwd, "infra", "desired.json"), infraContractDesiredJson(resolvedCwd), { force }),
481
- writeIfAllowed(path.join(resolvedCwd, "infra", "outputs.json"), infraContractOutputsJson(resolvedCwd), { force }),
37
+ const resolvedCwd = fs.realpathSync(cwd);
38
+ if (runnerPreset !== "github-hosted")
39
+ throw new Error(
40
+ "schema-2 init uses platform declarations; runner presets are internal runtime policy",
482
41
  );
42
+ const planned = planConsumerInitialization({
43
+ cwd: resolvedCwd,
44
+ type,
45
+ requestedManager: packageManager,
46
+ artifactName,
47
+ });
48
+ // Validate the entire write set first: a later conflict must not leave partial wiring.
49
+ for (const relative of Object.keys(planned.files))
50
+ assertWritable(resolvedCwd, relative, force);
51
+ const workflows = path.join(resolvedCwd, ".github/workflows");
52
+ if (fs.existsSync(workflows))
53
+ for (const file of fs.readdirSync(workflows))
54
+ if (
55
+ /\.ya?ml$/iu.test(file) &&
56
+ !Object.hasOwn(planned.files, `.github/workflows/${file}`)
57
+ )
58
+ throw new Error(
59
+ `Existing workflow ${file} is outside the generated consumer pair; migrate its product commands before initialization`,
60
+ );
61
+ assertWritable(resolvedCwd, "AGENTS.md", true);
62
+ const agents = path.join(resolvedCwd, "AGENTS.md");
63
+ planned.files["AGENTS.md"] = consumerAgentInstructions(
64
+ fs.existsSync(agents) ? fs.readFileSync(agents, "utf8") : "",
65
+ );
66
+ for (const [relative, bytes] of Object.entries(planned.files)) {
67
+ const file = path.join(resolvedCwd, relative);
68
+ fs.mkdirSync(path.dirname(file), { recursive: true });
69
+ fs.writeFileSync(file, bytes);
483
70
  }
484
-
485
71
  return {
486
- schemaVersion: 1,
72
+ schemaVersion: 2,
487
73
  type,
74
+ productType: planned.productType,
488
75
  cwd: resolvedCwd,
489
- packageManager: manager,
490
- workflowRef: BUILDCHAIN_WORKFLOW_REF,
491
- written: written.map((filePath) => posixPath(path.relative(resolvedCwd, filePath))),
76
+ packageManager: planned.manager,
77
+ workflowRef: `kungfu-systems/buildchain/${PIPELINE_ENTRY}@v4`,
78
+ written: Object.keys(planned.files),
492
79
  };
493
80
  }
494
81
 
495
82
  function readArg(name, fallback = "") {
496
83
  const index = process.argv.indexOf(`--${name}`);
497
- if (index === -1) {
498
- return fallback;
499
- }
500
- return process.argv[index + 1] || "";
84
+ return index === -1 ? fallback : process.argv[index + 1] || "";
501
85
  }
502
-
503
- if (!process.env.BUILDCHAIN_EMBEDDED_ENTRYPOINT && process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
86
+ if (
87
+ !process.env.BUILDCHAIN_EMBEDDED_ENTRYPOINT &&
88
+ process.argv[1] &&
89
+ import.meta.url === pathToFileURL(process.argv[1]).href
90
+ ) {
504
91
  try {
505
- const result = initBuildchainRepo({
506
- cwd: readArg("cwd", process.cwd()),
507
- type: readArg("type", "package"),
508
- force: process.argv.includes("--force"),
509
- packageManager: readArg("package-manager", ""),
510
- runnerPreset: readArg("runner-preset", "github-hosted"),
511
- artifactName: readArg("artifact-name", ""),
512
- });
513
- process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
92
+ console.log(
93
+ JSON.stringify(
94
+ initBuildchainRepo({
95
+ cwd: readArg("cwd", process.cwd()),
96
+ type: readArg("type", "package"),
97
+ force: process.argv.includes("--force"),
98
+ packageManager: readArg("package-manager"),
99
+ runnerPreset: readArg("runner-preset", "github-hosted"),
100
+ artifactName: readArg("artifact-name"),
101
+ }),
102
+ null,
103
+ 2,
104
+ ),
105
+ );
514
106
  } catch (error) {
515
107
  console.error(`init-repo: ${error.message}`);
516
108
  process.exitCode = 1;