@kungfu-tech/buildchain 3.0.9-alpha.2 → 3.0.9-alpha.3

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 (48) hide show
  1. package/contracts/fixtures/next-development-transition-v1/anchored-manual-waiting.json +47 -0
  2. package/contracts/fixtures/next-development-transition-v1/semver-auto-planned.json +47 -0
  3. package/contracts/fixtures/next-development-transition-v1/version-model-cases.json +40 -0
  4. package/contracts/next-development-request-v1.schema.json +66 -0
  5. package/contracts/next-development-transition-v1.schema.json +292 -0
  6. package/dist/site/buildchain-contract.json +4 -4
  7. package/dist/site/buildchain-site.json +89 -18
  8. package/dist/site/capability-registry.json +4 -3
  9. package/dist/site/kfd-claims.json +65 -5
  10. package/dist/site/kfd-upstream-aggregate.json +1 -1
  11. package/dist/site/manual-registry.json +19 -3
  12. package/dist/site/node-api-registry.json +1016 -36
  13. package/dist/site/page-registry.json +74 -11
  14. package/dist/site/public-surface-audit.json +7 -3
  15. package/dist/site/publication-registry.json +4 -4
  16. package/dist/site/release-provenance.json +3 -0
  17. package/dist/site/site-manifest.json +15 -7
  18. package/dist/site/workflow-registry.json +4 -4
  19. package/docs/MAP.md +2 -1
  20. package/docs/aws-us-elastic-runner-burst-plane.md +11 -3
  21. package/docs/dev-alpha-candidate-patrol.md +8 -0
  22. package/docs/next-development-transition.md +119 -0
  23. package/docs/node-api-reference.md +126 -73
  24. package/docs/versioning.md +1 -1
  25. package/package.json +8 -3
  26. package/packages/core/buildchain-agent-manuals.js +1 -0
  27. package/packages/core/channel-candidate.js +8 -0
  28. package/packages/core/channel-promotion-baseline.js +52 -0
  29. package/packages/core/dev-alpha-candidate-selection.js +10 -2
  30. package/packages/core/next-development-candidate-reservation.js +186 -0
  31. package/packages/core/next-development-controller.js +726 -0
  32. package/packages/core/next-development-projection.js +288 -0
  33. package/packages/core/next-development-transition.js +738 -0
  34. package/packages/core/paper-agent-entry.js +7 -4
  35. package/packages/core/paper.js +14 -7
  36. package/scripts/aws-macos-jit-controller-core.mjs +83 -2
  37. package/scripts/aws-macos-jit-controller.mjs +32 -1
  38. package/scripts/aws-macos-jit-instance-rehydrate.mjs +260 -0
  39. package/scripts/check-inventory.mjs +11 -0
  40. package/scripts/dev-alpha-candidate-patrol.mjs +22 -1
  41. package/scripts/generate-next-development-guidance.mjs +49 -0
  42. package/scripts/generate-site-bundle.mjs +2 -0
  43. package/scripts/init-repo.mjs +119 -62
  44. package/scripts/next-development-self-dogfood-harness.mjs +409 -0
  45. package/scripts/next-development-self-dogfood.mjs +532 -0
  46. package/scripts/next-development-transition.mjs +47 -0
  47. package/scripts/site-capability-metadata.mjs +3 -0
  48. package/scripts/stable-candidate-qualification.mjs +7 -7
@@ -0,0 +1,288 @@
1
+ import {
2
+ NEXT_DEVELOPMENT_ADR,
3
+ NEXT_DEVELOPMENT_INVARIANT,
4
+ NEXT_DEVELOPMENT_STATES,
5
+ NEXT_DEVELOPMENT_TRANSITION_CONTRACT,
6
+ NEXT_DEVELOPMENT_VERSION_MODELS,
7
+ } from "./next-development-transition.js";
8
+ import { NEXT_DEVELOPMENT_CONTROLLER_CONTRACT } from "./next-development-controller.js";
9
+
10
+ export const NEXT_DEVELOPMENT_AGENT_SECTION_START =
11
+ "<!-- buildchain:next-development:v1:start -->";
12
+ export const NEXT_DEVELOPMENT_AGENT_SECTION_END =
13
+ "<!-- buildchain:next-development:v1:end -->";
14
+ export const NEXT_DEVELOPMENT_LOCAL_COMMAND =
15
+ "node scripts/next-development-transition.mjs materialize --cwd . --input <request.json>";
16
+
17
+ export function nextDevelopmentWorkflowHeader() {
18
+ return `# Next-development contract: ${NEXT_DEVELOPMENT_TRANSITION_CONTRACT}
19
+ # Durable controller: ${NEXT_DEVELOPMENT_CONTROLLER_CONTRACT}
20
+ # ${NEXT_DEVELOPMENT_INVARIANT}
21
+ `;
22
+ }
23
+
24
+ export function nextDevelopmentToml() {
25
+ return `[next_development]
26
+ contract = ${JSON.stringify(NEXT_DEVELOPMENT_TRANSITION_CONTRACT)}
27
+ controller_contract = ${JSON.stringify(NEXT_DEVELOPMENT_CONTROLLER_CONTRACT)}
28
+ adr = ${JSON.stringify(NEXT_DEVELOPMENT_ADR)}
29
+ invariant = ${JSON.stringify(NEXT_DEVELOPMENT_INVARIANT)}
30
+ states = ${JSON.stringify(NEXT_DEVELOPMENT_STATES)}
31
+ adapter = "scripts/next-development-transition.mjs"
32
+ adapter_environment = "BUILDCHAIN_VERSION"
33
+ source_paths = "version.files"
34
+ derived_paths = "version.derived_files"
35
+ read_only_paths = "version.manifest"
36
+ derivation_stage = "lifecycle.version-state"
37
+ verification_stage = "lifecycle.verify"
38
+ allowed_effects = ["declared-version-source-and-derived-files"]
39
+ public_side_effects = []
40
+ forbidden_ref_namespaces = ["refs/heads/alpha/", "refs/tags/"]
41
+ `;
42
+ }
43
+
44
+ export function appendNextDevelopmentToml(source) {
45
+ const current = String(source || "").trimEnd();
46
+ if (/^\[next_development\]$/mu.test(current)) {
47
+ throw new Error(
48
+ "buildchain config already contains a next_development table",
49
+ );
50
+ }
51
+ return `${current}\n\n${nextDevelopmentToml()}`;
52
+ }
53
+
54
+ export function projectNextDevelopmentToml(source) {
55
+ const current = String(source || "");
56
+ const start = current.search(/^\[next_development\]\s*$/mu);
57
+ if (start === -1) return appendNextDevelopmentToml(current);
58
+ const remainder = current.slice(start);
59
+ const firstNewline = remainder.indexOf("\n");
60
+ const nextTable = remainder
61
+ .slice(firstNewline + 1)
62
+ .search(/^\[[^\n]+\]\s*$/mu);
63
+ const end =
64
+ nextTable === -1 ? current.length : start + firstNewline + 1 + nextTable;
65
+ const prefix = current.slice(0, start).trimEnd();
66
+ const suffix = current.slice(end).trimStart();
67
+ return `${prefix}\n\n${nextDevelopmentToml()}${suffix ? `\n${suffix}` : ""}`;
68
+ }
69
+
70
+ export function assertNextDevelopmentConfig(config) {
71
+ const section = config?.next_development;
72
+ if (!section || typeof section !== "object" || Array.isArray(section)) {
73
+ throw new Error("next_development table is missing");
74
+ }
75
+ const expected = {
76
+ contract: NEXT_DEVELOPMENT_TRANSITION_CONTRACT,
77
+ controller_contract: NEXT_DEVELOPMENT_CONTROLLER_CONTRACT,
78
+ adr: NEXT_DEVELOPMENT_ADR,
79
+ invariant: NEXT_DEVELOPMENT_INVARIANT,
80
+ states: [...NEXT_DEVELOPMENT_STATES],
81
+ adapter: "scripts/next-development-transition.mjs",
82
+ adapter_environment: "BUILDCHAIN_VERSION",
83
+ source_paths: "version.files",
84
+ derived_paths: "version.derived_files",
85
+ read_only_paths: "version.manifest",
86
+ derivation_stage: "lifecycle.version-state",
87
+ verification_stage: "lifecycle.verify",
88
+ allowed_effects: ["declared-version-source-and-derived-files"],
89
+ public_side_effects: [],
90
+ forbidden_ref_namespaces: ["refs/heads/alpha/", "refs/tags/"],
91
+ };
92
+ if (JSON.stringify(section) !== JSON.stringify(expected)) {
93
+ throw new Error("next_development projection is stale or unsupported");
94
+ }
95
+ return structuredClone(section);
96
+ }
97
+
98
+ export function nextDevelopmentAgentInstructions() {
99
+ return `${NEXT_DEVELOPMENT_AGENT_SECTION_START}
100
+ ## Next-development transition (required after Alpha)
101
+
102
+ Follow \`${NEXT_DEVELOPMENT_ADR}\` and
103
+ \`${NEXT_DEVELOPMENT_TRANSITION_CONTRACT}\`. ${NEXT_DEVELOPMENT_INVARIANT}
104
+
105
+ Use only \`semver/auto\` or \`anchored/manual\`. Record \`planned\`,
106
+ \`waiting-anchor\`, \`materialized\`, \`pr-pending\`, \`merged\`, and \`verified\`
107
+ without changing the completed Alpha outcome. During preparation, never move
108
+ an Alpha branch or tag and never write outside declared source and derived
109
+ version paths. Treat the anchor manifest as read-only.
110
+
111
+ The durable controller creates one child keyed by the completed-Alpha root.
112
+ Every runner must reuse that child and its compare-and-swap checkpoints. Build
113
+ from the latest protected Dev SHA, supersede stale material before opening the
114
+ version PR, and do not record \`verified\` until protected Dev readback matches
115
+ the target version plus every declared source and derived root.
116
+
117
+ Plan locally before opting into declared-path writes:
118
+
119
+ \`\`\`sh
120
+ ${NEXT_DEVELOPMENT_LOCAL_COMMAND}
121
+ \`\`\`
122
+
123
+ Add \`--write\` only after reviewing the rooted plan. Anchored/manual consumers
124
+ must materialize and root the declared anchor manifest first.
125
+ Repository transaction adapters pass the exact target as
126
+ \`BUILDCHAIN_VERSION\`, run \`lifecycle.version-state\` when derived files are
127
+ declared, then run \`lifecycle.verify\`. The reference writer fails closed for
128
+ derived-file consumers; it does not execute arbitrary consumer commands.
129
+ ${NEXT_DEVELOPMENT_AGENT_SECTION_END}`;
130
+ }
131
+
132
+ export function mergeNextDevelopmentAgentInstructions(current = "") {
133
+ const source = String(current || "");
134
+ const section = nextDevelopmentAgentInstructions();
135
+ const start = source.indexOf(NEXT_DEVELOPMENT_AGENT_SECTION_START);
136
+ const end = source.indexOf(NEXT_DEVELOPMENT_AGENT_SECTION_END);
137
+ if ((start === -1) !== (end === -1)) {
138
+ throw new Error(
139
+ "AGENTS.md has an incomplete Buildchain next-development section",
140
+ );
141
+ }
142
+ if (start === -1) {
143
+ return source.trim()
144
+ ? `${source.trimEnd()}\n\n${section}\n`
145
+ : `# AGENTS.md\n\n${section}\n`;
146
+ }
147
+ if (
148
+ source.indexOf(NEXT_DEVELOPMENT_AGENT_SECTION_START, start + 1) !== -1 ||
149
+ source.indexOf(NEXT_DEVELOPMENT_AGENT_SECTION_END, end + 1) !== -1 ||
150
+ end < start
151
+ ) {
152
+ throw new Error(
153
+ "AGENTS.md has ambiguous Buildchain next-development sections",
154
+ );
155
+ }
156
+ return `${source.slice(0, start)}${section}${source.slice(
157
+ end + NEXT_DEVELOPMENT_AGENT_SECTION_END.length,
158
+ )}`;
159
+ }
160
+
161
+ export function nextDevelopmentManual() {
162
+ const states = NEXT_DEVELOPMENT_STATES.map((state) => `\`${state}\``).join(
163
+ ", ",
164
+ );
165
+ const models = NEXT_DEVELOPMENT_VERSION_MODELS.map(
166
+ (model) => `\`${model.strategy}/${model.next}\``,
167
+ ).join(" and ");
168
+ return `---
169
+ status: preview
170
+ period: ongoing
171
+ theme: next-development-transition
172
+ doc_type: generated-contract-guidance
173
+ source_level: generated-from-node-contract
174
+ confidence: high
175
+ sensitivity: public
176
+ evidence_grade: A
177
+ review_state: self-reviewed
178
+ last_reviewed: 2026-08-11
179
+ ---
180
+
181
+ # Next-development Transition
182
+
183
+ This document is generated from
184
+ \`packages/core/next-development-transition.js\` and
185
+ \`packages/core/next-development-controller.js\` and
186
+ \`packages/core/next-development-projection.js\`. Edit those sources and run
187
+ \`node scripts/generate-next-development-guidance.mjs\`; direct edits fail the
188
+ projection drift check.
189
+
190
+ ## Contract
191
+
192
+ - Contract: \`${NEXT_DEVELOPMENT_TRANSITION_CONTRACT}\`
193
+ - Durable controller: \`${NEXT_DEVELOPMENT_CONTROLLER_CONTRACT}\`
194
+ - ADR: [ADR 0002](../${NEXT_DEVELOPMENT_ADR})
195
+ - States: ${states}
196
+ - Legal version models: ${models}
197
+ - Invariant: ${NEXT_DEVELOPMENT_INVARIANT}
198
+
199
+ An Alpha publication is terminal success independently of this transition.
200
+ The idempotency key is a deterministic hash of the completed-Alpha root,
201
+ repository, legal model, and sorted declared paths. Incomplete Dev preparation
202
+ therefore cannot relabel Alpha N as failed, and replay cannot select a different
203
+ Alpha or path set.
204
+
205
+ ## Durable controller
206
+
207
+ \`scheduleNextDevelopmentController\` atomically creates one child for the
208
+ repository and completed-Alpha root. Identical wakes reuse it. The store
209
+ boundary requires read, create-if-absent, and compare-and-swap operations; the
210
+ controller root fences every checkpoint. Materialization uses an operation key
211
+ derived from the child, exact current protected Dev SHA, and reviewed target,
212
+ so a fresh runner can recover an already-created commit instead of rebuilding
213
+ the Alpha candidate or depending on the original runner workspace.
214
+
215
+ Before opening the protected version PR, the controller reads Dev again. A
216
+ moved head makes the prepared attempt \`superseded\`; the following wake
217
+ regenerates only declared version material from that latest SHA. After merge,
218
+ \`verified\` remains unreachable until protected Dev readback contains the
219
+ prepared commit and its target version, source roots, and derived roots exactly
220
+ match the checkpoint. The executor surface contains no Alpha publication, tag,
221
+ release, or package operation.
222
+
223
+ Alpha finalization no longer treats a non-fast-forward Dev update as successful
224
+ bookkeeping. It requires an exact checkout of the current Dev head, regenerates
225
+ the declared version lifecycle there, and uses a non-force merge or reusable
226
+ protected version PR. Candidate Patrol ignores both the generated preparation
227
+ commit and its two-parent integration commit. Before a later product candidate
228
+ can settle, Patrol reads every prepared version path at the candidate SHA and
229
+ requires the exact reserved blob identities; missing or stale state blocks
230
+ before a Release Cut or heavy candidate build.
231
+
232
+ ## Version models
233
+
234
+ \`semver/auto\` increments the Alpha sequence on the same semantic patch. For
235
+ example, completed \`1.4.2-alpha.7\` plans \`1.4.2-alpha.8\`. It must not accept an anchor or an
236
+ operator-selected target.
237
+
238
+ \`anchored/manual\` enters \`waiting-anchor\` until the caller provides both a
239
+ semantic target and the exact digest of the configured anchor manifest. The
240
+ adapter verifies the manifest already present in the checkout; it never invents
241
+ or edits upstream anchor facts. \`semver/manual\` and \`anchored/auto\` are
242
+ invalid.
243
+
244
+ ## Hosted self-dogfood and adoption
245
+
246
+ \`.github/workflows/buildchain-alpha-self-dogfood.yml\` calls the same public
247
+ \`build.yml@v3-alpha\` router as a consumer. After the hosted build succeeds, one
248
+ runner uses the real version-state adapter and checkpoints an injected transient
249
+ durable-state write failure. A separate runner restores the adapter operation
250
+ without rebuilding Alpha, supersedes it when protected Dev moves, and preserves
251
+ \`pr-pending\` while the protected PR is delayed. The final artifact roots the
252
+ exact runtime SHA, controller transaction, both legal version-model outcomes,
253
+ and an exact hosted protected Dev readback. Stable qualification recomputes and
254
+ rejects evidence that omits or drifts any of those bindings.
255
+
256
+ Production consumers, including Kungfu, adopt the proved contract through
257
+ \`kungfu-systems/buildchain/.github/workflows/build.yml@v3\`. The evidence retains
258
+ the exact resolved SHA for audit, but the committed production coordinate is the
259
+ floating major contract rather than an exact-SHA pin.
260
+
261
+ ## Local adapter
262
+
263
+ From a normal Buildchain checkout:
264
+
265
+ \`\`\`sh
266
+ ${NEXT_DEVELOPMENT_LOCAL_COMMAND}
267
+ \`\`\`
268
+
269
+ The command prints a rooted plan and performs no write by default. \`--write\`
270
+ may change only regular, non-symlink source files listed by \`version.files\`
271
+ in the loaded Buildchain config. The rooted adapter contract separately names
272
+ \`version.derived_files\` as allowed changes, \`version.manifest\` as read-only,
273
+ \`BUILDCHAIN_VERSION\` as the target input, \`lifecycle.version-state\` as the
274
+ derived-material stage, and \`lifecycle.verify\` as the truth gate. The
275
+ reference writer fails closed when derived files exist because transaction
276
+ execution is outside this contract slice. It performs no Git operation, ref
277
+ update, network request, provider call, lifecycle command, or anchor edit.
278
+
279
+ Preparing development state creates no tag, Release, public package, or
280
+ candidate. Those public effects remain outside the local adapter contract.
281
+
282
+ The request schema is
283
+ \`contracts/next-development-request-v1.schema.json\`; the durable record schema
284
+ is \`contracts/next-development-transition-v1.schema.json\`. Positive and
285
+ negative examples live under
286
+ \`contracts/fixtures/next-development-transition-v1/\`.
287
+ `;
288
+ }