@kungfu-tech/buildchain 4.1.3 → 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 (199) 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 +31 -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/publication/authority/control-plane.js +2 -2
  142. package/packages/core/publication/authority/seal.js +1 -1
  143. package/packages/core/publication/cli/dispatch.mjs +1 -12
  144. package/packages/core/publication/pipeline/actions.js +16 -9
  145. package/packages/core/publication/pipeline/apply.js +17 -9
  146. package/packages/core/publication/pipeline/context.js +29 -0
  147. package/packages/core/publication/pipeline/prepare.js +15 -6
  148. package/packages/core/publication/pipeline/recovery-materials.js +63 -1
  149. package/packages/core/publication/pipeline/recovery-prepare.js +21 -9
  150. package/packages/core/publication/pipeline/stable-entry.js +12 -7
  151. package/packages/core/publication/pipeline/stable-products.js +21 -19
  152. package/packages/core/publication/pipeline/version-actions.js +15 -6
  153. package/packages/core/publication/publication-rehearsal-projection.js +0 -9
  154. package/packages/core/release/cli/dispatch.mjs +1 -4
  155. package/packages/core/release/cli/inspection-handlers.mjs +1 -33
  156. package/packages/core/release/cli/release-handlers.mjs +2 -19
  157. package/packages/core/release/cli/verification-handlers.mjs +4 -25
  158. package/packages/core/release/next-development-projection.js +13 -13
  159. package/packages/core/release/passport/locations.js +13 -8
  160. package/packages/core/release/release-passport.js +70 -5
  161. package/packages/core/web/cli/badges.mjs +0 -4
  162. package/packages/core/web/publication-admission.js +1 -1
  163. package/packages/core/web/publication-capability.js +1 -1
  164. package/packages/core/web/readme-badges.js +1 -1
  165. package/packages/core/workflow/cli/main.mjs +1 -4
  166. package/packages/core/workflow/cli/process.mjs +1 -1
  167. package/packages/core/workflow/commands/buildchain-cli-help.mjs +2 -8
  168. package/packages/core/workflow/engine/conformance.js +1 -1
  169. package/packages/core/workflow/pipeline/build.js +21 -1
  170. package/packages/core/workflow/pipeline/delivery-observation.js +6 -2
  171. package/packages/core/workflow/workflow-taxonomy.mjs +61 -17
  172. package/scripts/check-code-layout.mjs +2 -0
  173. package/scripts/check-core-mechanism-inventory.mjs +29 -13
  174. package/scripts/check-floating-consumer-policy-contract.mjs +3 -3
  175. package/scripts/check-inventory.mjs +27 -27
  176. package/scripts/check-maintainability.mjs +28 -5
  177. package/scripts/check-public-dogfood-contract.mjs +3 -3
  178. package/scripts/check-release-topology.mjs +1 -1
  179. package/scripts/check-self-consumer-contract.mjs +7 -7
  180. package/scripts/check-universal-workflow-bootstrap.mjs +1 -1
  181. package/scripts/generate-channel-promotion-workflow.mjs +1 -1
  182. package/scripts/generate-minimal-consumer-contract.mjs +21 -1
  183. package/scripts/generate-site-bundle.mjs +2 -1
  184. package/scripts/generate-tail-reseal-fixture.mjs +3 -3
  185. package/scripts/inventory/promotion.mjs +1 -1
  186. package/scripts/next-development-self-dogfood-harness.mjs +1 -1
  187. package/scripts/next-development-self-dogfood.mjs +4 -4
  188. package/scripts/site-capability-metadata.mjs +2 -6
  189. package/scripts/source-metric-lineage.mjs +62 -7
  190. package/scripts/verify-golden-path.mjs +31 -35
  191. package/templates/native-dev-delivery.yml +1 -1
  192. package/templates/universal-buildchain-bootstrap.yml +1 -1
  193. package/packages/core/paper/operations/bootstrap.js +0 -75
  194. package/packages/core/paper/operations/plans.js +0 -213
  195. package/packages/core/paper/operations/provisioning.js +0 -113
  196. package/packages/core/paper/operations/scaffold-config.js +0 -77
  197. package/packages/core/paper/operations/scaffold-workflows.js +0 -116
  198. package/packages/core/paper/operations/workspace.js +0 -60
  199. package/packages/core/paper/paper-npm-bootstrap.js +0 -492
@@ -1,492 +0,0 @@
1
- function executePaperNpmBootstrap(options = {}, runtime) {
2
- const {
3
- DEFAULT_BOOTSTRAP_VERSION,
4
- NPM_REGISTRY,
5
- PAPER_NPM_BOOTSTRAP_CONTRACT,
6
- PAPER_PATHS,
7
- bootstrapPackageShape,
8
- commandResult,
9
- expectedPaperTrustedPublisher,
10
- extractUrls,
11
- fs,
12
- jsonText,
13
- liveNpmAuthObservation,
14
- liveNpmPackageObservation,
15
- liveNpmTrustObservation,
16
- normalizePackageName,
17
- normalizeRepository,
18
- os,
19
- paperConfig,
20
- path,
21
- resolvePaperRepository,
22
- safeParseJson,
23
- readNpmPackResult,
24
- toPosix,
25
- validatePaperProvisioningAuthority,
26
- writePaperReceipt,
27
- } = runtime;
28
- const {
29
- cwd = process.cwd(),
30
- packageName = "",
31
- bootstrapVersion = DEFAULT_BOOTSTRAP_VERSION,
32
- registry = NPM_REGISTRY,
33
- repository = "",
34
- workflow = "public-release-paper.yml",
35
- environment = "",
36
- execute = false,
37
- confirmedPackage = "",
38
- userconfig = "",
39
- offline = false,
40
- } = options;
41
- const resolvedCwd = path.resolve(cwd);
42
- if (registry !== NPM_REGISTRY) {
43
- throw new Error(
44
- `paper npm bootstrap requires the official registry ${NPM_REGISTRY}`,
45
- );
46
- }
47
- if (bootstrapVersion !== DEFAULT_BOOTSTRAP_VERSION) {
48
- throw new Error(
49
- `paper npm bootstrap version is fixed at ${DEFAULT_BOOTSTRAP_VERSION}`,
50
- );
51
- }
52
- const configResult = paperConfig(resolvedCwd);
53
- if (configResult.error) throw new Error(configResult.error);
54
- const name = normalizePackageName(
55
- packageName ||
56
- configResult.loaded.config.publish?.package ||
57
- configResult.loaded.config.publish?.mainPackage,
58
- );
59
- const repo = normalizeRepository(
60
- repository || resolvePaperRepository(resolvedCwd),
61
- );
62
- const provisioning = validatePaperProvisioningAuthority(resolvedCwd);
63
- if (!provisioning.valid) {
64
- throw new Error(
65
- `paper npm bootstrap requires a valid provisioning authority: ${provisioning.errors.join("; ")}`,
66
- );
67
- }
68
- const expectedPublisher = expectedPaperTrustedPublisher(provisioning.value);
69
- if (
70
- provisioning.value.package?.name !== name ||
71
- expectedPublisher.repository !== repo ||
72
- expectedPublisher.workflow !== toPosix(workflow).replace(/^\/+/, "") ||
73
- expectedPublisher.environment !== String(environment || "")
74
- ) {
75
- throw new Error(
76
- "paper npm bootstrap coordinates differ from the exact provisioning authority",
77
- );
78
- }
79
- if (execute && confirmedPackage !== name) {
80
- throw new Error(
81
- `real npm bootstrap requires --confirm-public-package ${name}`,
82
- );
83
- }
84
- if (execute && offline) {
85
- throw new Error("real npm bootstrap cannot run with --offline");
86
- }
87
- if (execute && (!repo || !workflow)) {
88
- throw new Error(
89
- "real npm bootstrap requires GitHub repository and workflow coordinates",
90
- );
91
- }
92
- const packageObservation = offline
93
- ? {
94
- status: "unknown",
95
- exists: null,
96
- version: "",
97
- registry,
98
- errorCode: "offline",
99
- }
100
- : liveNpmPackageObservation(name, registry, resolvedCwd);
101
- const auth = offline
102
- ? {
103
- status: "unknown",
104
- authenticated: null,
105
- identity: "",
106
- errorCode: "offline",
107
- }
108
- : liveNpmAuthObservation(registry, resolvedCwd);
109
- const plan = {
110
- schemaVersion: 1,
111
- contract: PAPER_NPM_BOOTSTRAP_CONTRACT,
112
- ok: true,
113
- dryRun: !execute,
114
- externalMutation: execute,
115
- package: {
116
- name,
117
- bootstrapVersion,
118
- registry,
119
- existsBefore: packageObservation.exists,
120
- observedVersion: packageObservation.version,
121
- },
122
- repository: {
123
- github: repo,
124
- workflow,
125
- environment,
126
- },
127
- authority: {
128
- digest: provisioning.value.authorityDigest,
129
- policyDigest: provisioning.value.policy.policyDigest,
130
- },
131
- auth: {
132
- authenticated: auth.authenticated,
133
- identity: auth.identity,
134
- errorCode: auth.errorCode,
135
- },
136
- publish: {
137
- status: packageObservation.exists === true ? "existing" : "planned",
138
- distTag: "bootstrap",
139
- access: "public",
140
- },
141
- trust: {
142
- status: "planned",
143
- urls: [],
144
- },
145
- receipts: [],
146
- nextActions: execute
147
- ? []
148
- : [
149
- {
150
- id: "confirm-public-bootstrap",
151
- command: `buildchain paper bootstrap npm --execute --confirm-public-package ${name} --json`,
152
- description:
153
- "After reviewing this dry-run, bootstrap the exact public package and configure GitHub Trusted Publishing.",
154
- },
155
- ],
156
- };
157
- if (!execute) {
158
- const dryRunRoot = fs.mkdtempSync(
159
- path.join(os.tmpdir(), "buildchain-paper-bootstrap-dry-run-"),
160
- );
161
- try {
162
- fs.writeFileSync(
163
- path.join(dryRunRoot, "package.json"),
164
- jsonText(
165
- bootstrapPackageShape({
166
- packageName: name,
167
- version: bootstrapVersion,
168
- }),
169
- ),
170
- );
171
- const configArgs = userconfig ? ["--userconfig", userconfig] : [];
172
- const pack = commandResult(
173
- "npm",
174
- [
175
- "pack",
176
- "--dry-run",
177
- "--json",
178
- "--ignore-scripts",
179
- `--registry=${registry}`,
180
- ...configArgs,
181
- ],
182
- { cwd: dryRunRoot },
183
- );
184
- const publish = commandResult(
185
- "npm",
186
- [
187
- "publish",
188
- "--dry-run",
189
- "--ignore-scripts",
190
- "--access",
191
- "public",
192
- "--tag",
193
- "bootstrap",
194
- `--registry=${registry}`,
195
- ...configArgs,
196
- ],
197
- { cwd: dryRunRoot },
198
- );
199
- return {
200
- ...plan,
201
- ok: pack.ok && publish.ok,
202
- errorCode: !pack.ok
203
- ? "npm-pack-dry-run-failed"
204
- : !publish.ok
205
- ? "npm-publish-dry-run-failed"
206
- : "",
207
- dryRunChecks: {
208
- minimalPackageOnly: true,
209
- pack: {
210
- status: pack.ok ? "pass" : "fail",
211
- entryCount: (() => {
212
- const value = pack.ok ? readNpmPackResult(pack.stdout) : null;
213
- return Array.isArray(value?.files) ? value.files.length : 0;
214
- })(),
215
- },
216
- publish: {
217
- status: publish.ok ? "pass" : "fail",
218
- registry,
219
- access: "public",
220
- distTag: "bootstrap",
221
- },
222
- },
223
- };
224
- } finally {
225
- fs.rmSync(dryRunRoot, { recursive: true, force: true });
226
- }
227
- }
228
- if (packageObservation.exists === null) {
229
- return {
230
- ...plan,
231
- ok: false,
232
- errorCode: "npm-package-status-unknown",
233
- publish: {
234
- ...plan.publish,
235
- status: "blocked",
236
- },
237
- trust: {
238
- status: "blocked",
239
- urls: [],
240
- },
241
- nextActions: [
242
- {
243
- id: "verify-npm-package",
244
- command: `npm view ${name} version --json --registry=${registry}`,
245
- description:
246
- "Resolve whether the exact public package exists before any publish mutation.",
247
- },
248
- ],
249
- };
250
- }
251
- if (auth.authenticated !== true) {
252
- return {
253
- ...plan,
254
- ok: false,
255
- errorCode: "npm-auth-required",
256
- publish: {
257
- ...plan.publish,
258
- status: "blocked",
259
- },
260
- trust: {
261
- status: "blocked",
262
- urls: [],
263
- },
264
- nextActions: [
265
- {
266
- id: "authenticate-npm",
267
- command: `npm whoami --registry=${registry}`,
268
- description:
269
- "Authenticate npm without sharing token contents, then rerun the exact bootstrap command.",
270
- },
271
- ],
272
- };
273
- }
274
- const tempRoot = fs.mkdtempSync(
275
- path.join(os.tmpdir(), "buildchain-paper-bootstrap-"),
276
- );
277
- try {
278
- fs.writeFileSync(
279
- path.join(tempRoot, "package.json"),
280
- jsonText(
281
- bootstrapPackageShape({ packageName: name, version: bootstrapVersion }),
282
- ),
283
- );
284
- const configArgs = userconfig ? ["--userconfig", userconfig] : [];
285
- const pack = commandResult(
286
- "npm",
287
- [
288
- "pack",
289
- "--dry-run",
290
- "--json",
291
- "--ignore-scripts",
292
- `--registry=${registry}`,
293
- ...configArgs,
294
- ],
295
- { cwd: tempRoot },
296
- );
297
- if (!pack.ok) {
298
- return {
299
- ...plan,
300
- ok: false,
301
- errorCode: "npm-pack-dry-run-failed",
302
- publish: { ...plan.publish, status: "blocked" },
303
- trust: { status: "blocked", urls: [] },
304
- };
305
- }
306
- const publishDryRun = commandResult(
307
- "npm",
308
- [
309
- "publish",
310
- "--dry-run",
311
- "--ignore-scripts",
312
- "--access",
313
- "public",
314
- "--tag",
315
- "bootstrap",
316
- `--registry=${registry}`,
317
- ...configArgs,
318
- ],
319
- { cwd: tempRoot },
320
- );
321
- if (!publishDryRun.ok) {
322
- return {
323
- ...plan,
324
- ok: false,
325
- errorCode: "npm-publish-dry-run-failed",
326
- publish: { ...plan.publish, status: "blocked" },
327
- trust: { status: "blocked", urls: [] },
328
- };
329
- }
330
- let publishStatus =
331
- packageObservation.exists === true ? "existing" : "published";
332
- if (packageObservation.exists !== true) {
333
- const published = commandResult(
334
- "npm",
335
- [
336
- "publish",
337
- "--ignore-scripts",
338
- "--access",
339
- "public",
340
- "--tag",
341
- "bootstrap",
342
- `--registry=${registry}`,
343
- ...configArgs,
344
- ],
345
- { cwd: tempRoot, timeout: 60000 },
346
- );
347
- if (!published.ok) {
348
- const failure = {
349
- ...plan,
350
- ok: false,
351
- errorCode: "npm-publish-failed",
352
- publish: { ...plan.publish, status: "failed" },
353
- trust: { status: "blocked", urls: [] },
354
- };
355
- failure.receipts = [
356
- writePaperReceipt(resolvedCwd, PAPER_PATHS.npmBootstrap, failure),
357
- ];
358
- return failure;
359
- }
360
- }
361
- const trustArgs = [
362
- "trust",
363
- "github",
364
- name,
365
- "--repo",
366
- repo,
367
- "--file",
368
- workflow,
369
- ...(environment ? ["--env", environment] : []),
370
- "--allow-publish",
371
- "--yes",
372
- "--json",
373
- `--registry=${registry}`,
374
- ...configArgs,
375
- ];
376
- const trustCommand = commandResult("npm", trustArgs, {
377
- cwd: resolvedCwd,
378
- timeout: 60000,
379
- });
380
- const parsedTrust = safeParseJson(trustCommand.stdout);
381
- const urls = [
382
- ...extractUrls(
383
- parsedTrust || `${trustCommand.stdout}\n${trustCommand.stderr}`,
384
- ),
385
- ];
386
- const trustList =
387
- trustCommand.ok && urls.length === 0
388
- ? liveNpmTrustObservation(
389
- name,
390
- registry,
391
- resolvedCwd,
392
- expectedPublisher,
393
- )
394
- : {
395
- status: "unknown",
396
- configured: null,
397
- publishers: [],
398
- errorCode:
399
- urls.length > 0 ? "web-action-required" : "npm-trust-failed",
400
- };
401
- const trustStatus =
402
- trustCommand.ok && trustList.configured === true
403
- ? "configured"
404
- : urls.length > 0
405
- ? "action-required"
406
- : "failed";
407
- const packageAfter = liveNpmPackageObservation(name, registry, resolvedCwd);
408
- const packageVerified = packageAfter.exists === true;
409
- const receipt = {
410
- ...plan,
411
- ok: trustStatus !== "failed" && packageVerified,
412
- dryRun: false,
413
- externalMutation: true,
414
- errorCode:
415
- trustStatus === "failed"
416
- ? "npm-trust-failed"
417
- : packageVerified
418
- ? ""
419
- : "npm-package-readback-failed",
420
- package: {
421
- ...plan.package,
422
- existsAfter: packageAfter.exists,
423
- observedVersionAfter: packageAfter.version,
424
- readbackStatus: packageAfter.status,
425
- },
426
- publish: {
427
- ...plan.publish,
428
- status: publishStatus,
429
- },
430
- trust: {
431
- status: trustStatus,
432
- urls,
433
- expectedPublisher,
434
- exactBinding: trustList.exactBinding === true,
435
- publishers: trustList.publishers,
436
- },
437
- nextActions:
438
- trustStatus === "configured" && packageVerified
439
- ? [
440
- {
441
- id: "paper-preflight",
442
- command: "buildchain paper preflight --json",
443
- description:
444
- "Verify package existence and Trusted Publisher binding from live read-only sources.",
445
- },
446
- ]
447
- : trustStatus === "action-required" && packageVerified
448
- ? [
449
- {
450
- id: "complete-npm-web-action",
451
- command: "",
452
- description:
453
- "Open the exact npm URL returned below, complete the web step, then rerun preflight.",
454
- urls,
455
- },
456
- ]
457
- : !packageVerified
458
- ? [
459
- {
460
- id: "verify-npm-package-readback",
461
- command: `npm view ${name} version --json --registry=${registry}`,
462
- description:
463
- "The mutation returned but the official registry did not prove package existence; do not infer success.",
464
- },
465
- ]
466
- : [
467
- {
468
- id: "retry-npm-trust",
469
- command: `buildchain paper bootstrap npm --execute --confirm-public-package ${name} --json`,
470
- description:
471
- "The package exists; retry only the idempotent Trusted Publisher configuration path.",
472
- },
473
- ],
474
- };
475
- receipt.receipts = [
476
- writePaperReceipt(resolvedCwd, PAPER_PATHS.npmBootstrap, receipt),
477
- ];
478
- if (
479
- packageVerified &&
480
- (trustStatus === "configured" || trustStatus === "action-required")
481
- ) {
482
- receipt.receipts.push(
483
- writePaperReceipt(resolvedCwd, PAPER_PATHS.npmTrust, receipt),
484
- );
485
- }
486
- return receipt;
487
- } finally {
488
- fs.rmSync(tempRoot, { recursive: true, force: true });
489
- }
490
- }
491
-
492
- export { executePaperNpmBootstrap };