@kungfu-tech/buildchain 4.0.1-alpha.42 → 4.0.1-alpha.54
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.
- package/architecture/agent-change-map.md +1015 -0
- package/architecture/ci-lane-change-budget.json +17 -0
- package/architecture/internal-capabilities.json +156 -11
- package/architecture/maintainability-debt.json +3229 -0
- package/architecture/maintainability-policy.json +474 -125
- package/architecture/v3-core-mechanism-inventory.json +4 -3
- package/architecture/v3-v4-capability-closure.md +59 -0
- package/architecture/v3-v4-live-capability-inventory.json +102404 -0
- package/architecture/v4-cross-platform-adopter-qualification.json +52 -0
- package/architecture/v4-delivery-warrant-shadow-fixtures.json +3 -3
- package/architecture/v4-runtime-semantic-closure.json +710 -0
- package/bin/internal/trust-release-release-handlers.mjs +5 -0
- package/contracts/fixtures/v4-tail-reseal-v1/valid.json +1 -1
- package/dist/site/buildchain-contract.json +71 -31
- package/dist/site/buildchain-site.json +38 -18
- package/dist/site/capability-registry.json +2 -2
- package/dist/site/cli-registry.json +5 -2
- package/dist/site/controller-registry.json +37 -5
- package/dist/site/kfd-claims.json +76 -14
- package/dist/site/kfd-upstream-aggregate.json +1 -1
- package/dist/site/manual-registry.json +4 -4
- package/dist/site/node-api-registry.json +1168 -203
- package/dist/site/page-registry.json +30 -10
- package/dist/site/public-surface-audit.json +46 -17
- package/dist/site/publication-registry.json +4 -4
- package/dist/site/release-provenance.json +3 -0
- package/dist/site/site-manifest.json +8 -8
- package/dist/site/workflow-registry.json +47 -18
- package/docs/cli-reference.md +4 -4
- package/docs/dev-delivery-warrant.md +12 -9
- package/docs/node-api-reference.md +224 -169
- package/docs/publish-transaction.md +11 -4
- package/docs/v4-adopter-delivery.md +23 -4
- package/package.json +6 -3
- package/packages/core/adopter-delivery-passport.js +36 -0
- package/packages/core/dev-delivery-warrant-settlement.js +5 -1
- package/packages/core/dev-delivery-warrant.js +13 -4
- package/packages/core/github-governance-authority.js +4 -4
- package/packages/core/paper-scaffold-content.js +401 -0
- package/packages/core/paper.js +12 -378
- package/packages/core/publication-control-plane-audit.js +135 -111
- package/packages/core/publication-rehearsal-projection.js +104 -0
- package/packages/core/publication-rehearsal-runtime.js +190 -0
- package/packages/core/release-candidate-recovery.js +1 -0
- package/packages/core/release-passport.js +82 -184
- package/packages/core/v4-cross-platform-adopter-qualification.js +343 -0
- package/packages/core/v4-floating-consumer-policy.js +3 -2
- package/packages/core/v4-floating-consumer-release-passport.js +119 -0
- package/scripts/audit-publication-control-plane.mjs +17 -17
- package/scripts/buildchain-cli-help.mjs +3 -0
- package/scripts/check-internal-architecture.mjs +23 -3
- package/scripts/check-inventory.mjs +21 -3
- package/scripts/check-maintainability.mjs +145 -4
- package/scripts/check-v3-v4-capability-inventory.mjs +574 -0
- package/scripts/check-v4-floating-consumer-policy-contract.mjs +10 -3
- package/scripts/check-v4-runtime-semantic-closure.mjs +266 -0
- package/scripts/generate-agent-change-map.mjs +118 -0
- package/scripts/maintainability-domain-metrics.mjs +237 -0
- package/scripts/maintainability-governance.mjs +473 -0
- package/scripts/maintainability-metrics.mjs +28 -6
- package/scripts/promotion-routing-evidence.mjs +35 -6
- package/scripts/release-line-policy.mjs +25 -15
- package/scripts/release-tail.mjs +19 -2
- package/scripts/resume-from-candidate-run.mjs +1 -1
- package/scripts/run-lifecycle-core.mjs +341 -376
- package/scripts/site-capability-metadata.mjs +3 -0
- package/scripts/v3-v4-capability-catalog.mjs +439 -0
- package/scripts/v4-cross-platform-adopter-qualification.mjs +228 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
|
|
7
|
+
export const V4_RUNTIME_SEMANTIC_CLOSURE_CONTRACT =
|
|
8
|
+
"kungfu-buildchain-v4-runtime-semantic-closure";
|
|
9
|
+
export const V4_RUNTIME_SEMANTIC_CLOSURE_PATH =
|
|
10
|
+
"architecture/v4-runtime-semantic-closure.json";
|
|
11
|
+
export const REQUIRED_RUNTIME_EVIDENCE = Object.freeze([
|
|
12
|
+
"positive",
|
|
13
|
+
"negative",
|
|
14
|
+
"failure",
|
|
15
|
+
"recovery",
|
|
16
|
+
"idempotence",
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
function loadJson(root, relativePath) {
|
|
20
|
+
return JSON.parse(fs.readFileSync(path.join(root, relativePath), "utf8"));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function sorted(values) {
|
|
24
|
+
return [...values].sort((left, right) => left.localeCompare(right));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function sameMembers(left, right) {
|
|
28
|
+
return JSON.stringify(sorted(left)) === JSON.stringify(sorted(right));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function publicSurfaceIds(root) {
|
|
32
|
+
const packageJson = loadJson(root, "package.json");
|
|
33
|
+
const cli = loadJson(root, "dist/site/cli-registry.json");
|
|
34
|
+
const workflows = loadJson(root, "dist/site/workflow-registry.json");
|
|
35
|
+
return new Set([
|
|
36
|
+
...Object.keys(packageJson.exports || {}).map((id) => `export:${id}`),
|
|
37
|
+
...(cli.commands || []).map((entry) => `cli:${entry.id}`),
|
|
38
|
+
...(workflows.workflows || []).map((entry) => `workflow:${entry.id}`),
|
|
39
|
+
...(workflows.actions || []).map((entry) => `action:${entry.id}`),
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function validateEvidence(root, mechanism, capability, issues) {
|
|
44
|
+
const sourceTests = new Set(mechanism.testPaths || []);
|
|
45
|
+
for (const dimension of REQUIRED_RUNTIME_EVIDENCE) {
|
|
46
|
+
const entries = capability.evidence?.[dimension];
|
|
47
|
+
if (!Array.isArray(entries) || entries.length === 0) {
|
|
48
|
+
issues.push(`${capability.id}: ${dimension} evidence is empty`);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
if (!entry?.path || !entry?.name) {
|
|
53
|
+
issues.push(`${capability.id}: ${dimension} evidence is incomplete`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!sourceTests.has(entry.path))
|
|
57
|
+
issues.push(
|
|
58
|
+
`${capability.id}: ${dimension} evidence is outside the reverse-scanned test set: ${entry.path}`,
|
|
59
|
+
);
|
|
60
|
+
const absolute = path.join(root, entry.path);
|
|
61
|
+
if (!fs.existsSync(absolute)) {
|
|
62
|
+
issues.push(
|
|
63
|
+
`${capability.id}: evidence path is missing: ${entry.path}`,
|
|
64
|
+
);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const source = fs.readFileSync(absolute, "utf8");
|
|
68
|
+
if (!source.includes(`test(${JSON.stringify(entry.name)}`))
|
|
69
|
+
issues.push(
|
|
70
|
+
`${capability.id}: evidence test is missing from ${entry.path}: ${entry.name}`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function validateResidualClosure(mechanism, capability, issues) {
|
|
77
|
+
const sourceResiduals = mechanism.unresolved || [];
|
|
78
|
+
const closed = capability.resolvedResiduals || [];
|
|
79
|
+
if (
|
|
80
|
+
!sameMembers(
|
|
81
|
+
sourceResiduals,
|
|
82
|
+
closed.map((entry) => entry?.source || ""),
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
issues.push(
|
|
86
|
+
`${capability.id}: resolved residual identities do not match the reverse scan`,
|
|
87
|
+
);
|
|
88
|
+
for (const entry of closed) {
|
|
89
|
+
if (!String(entry?.resolution || "").trim())
|
|
90
|
+
issues.push(`${capability.id}: residual resolution is empty`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function validateImplementation(root, mechanism, capability, issues) {
|
|
95
|
+
if (
|
|
96
|
+
!Array.isArray(capability.implementation) ||
|
|
97
|
+
capability.implementation.length === 0
|
|
98
|
+
) {
|
|
99
|
+
issues.push(`${capability.id}: implementation route is empty`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const reverseScanned = new Set(mechanism.sourcePaths || []);
|
|
103
|
+
let boundToReverseScan = false;
|
|
104
|
+
for (const relativePath of capability.implementation) {
|
|
105
|
+
if (!fs.existsSync(path.join(root, relativePath)))
|
|
106
|
+
issues.push(
|
|
107
|
+
`${capability.id}: implementation path is missing: ${relativePath}`,
|
|
108
|
+
);
|
|
109
|
+
if (reverseScanned.has(relativePath)) boundToReverseScan = true;
|
|
110
|
+
}
|
|
111
|
+
if (!boundToReverseScan)
|
|
112
|
+
issues.push(
|
|
113
|
+
`${capability.id}: implementation is not bound to a reverse-scanned v3 mechanism route`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function validateAuthority(capability, stateMachine, issues) {
|
|
118
|
+
for (const field of [
|
|
119
|
+
"exactHeadFence",
|
|
120
|
+
"immutableRootFence",
|
|
121
|
+
"providerReadbackBeforeRetry",
|
|
122
|
+
"idempotentReplay",
|
|
123
|
+
]) {
|
|
124
|
+
if (capability.invariants?.[field] !== true)
|
|
125
|
+
issues.push(`${capability.id}: ${field} must remain true`);
|
|
126
|
+
}
|
|
127
|
+
if (capability.routeKind !== "v4-native")
|
|
128
|
+
issues.push(`${capability.id}: routeKind must be v4-native`);
|
|
129
|
+
if (capability.legacyFallbackAllowed !== false)
|
|
130
|
+
issues.push(`${capability.id}: legacy fallback must remain disabled`);
|
|
131
|
+
if (capability.providerDecisionAuthorityAllowed !== false)
|
|
132
|
+
issues.push(
|
|
133
|
+
`${capability.id}: provider decision authority must remain disabled`,
|
|
134
|
+
);
|
|
135
|
+
if (stateMachine) {
|
|
136
|
+
if (capability.stateAuthority !== "single-writer-state-machine")
|
|
137
|
+
issues.push(
|
|
138
|
+
`${capability.id}: state-machine authority classification drifted`,
|
|
139
|
+
);
|
|
140
|
+
if (
|
|
141
|
+
stateMachine.writer?.authoritative !== true ||
|
|
142
|
+
stateMachine.writer?.secondWriterBudget !== 0
|
|
143
|
+
)
|
|
144
|
+
issues.push(`${capability.id}: v4 state machine is not single-writer`);
|
|
145
|
+
if (
|
|
146
|
+
!Array.isArray(stateMachine.recovery) ||
|
|
147
|
+
stateMachine.recovery.length === 0
|
|
148
|
+
)
|
|
149
|
+
issues.push(`${capability.id}: v4 state machine recovery is empty`);
|
|
150
|
+
} else if (capability.stateAuthority !== "bounded-protocol") {
|
|
151
|
+
issues.push(
|
|
152
|
+
`${capability.id}: bounded protocol authority classification drifted`,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function validateRuntimeSemanticClosure({
|
|
158
|
+
root = process.cwd(),
|
|
159
|
+
manifest = loadJson(root, V4_RUNTIME_SEMANTIC_CLOSURE_PATH),
|
|
160
|
+
v3Inventory = loadJson(root, "architecture/v3-core-mechanism-inventory.json"),
|
|
161
|
+
v4Manifest = loadJson(
|
|
162
|
+
root,
|
|
163
|
+
"architecture/v4-capability-state-machine-manifest.json",
|
|
164
|
+
),
|
|
165
|
+
} = {}) {
|
|
166
|
+
const issues = [];
|
|
167
|
+
if (
|
|
168
|
+
manifest?.schemaVersion !== 1 ||
|
|
169
|
+
manifest?.contract !== V4_RUNTIME_SEMANTIC_CLOSURE_CONTRACT
|
|
170
|
+
)
|
|
171
|
+
issues.push(
|
|
172
|
+
"runtime semantic closure contract or schemaVersion is invalid",
|
|
173
|
+
);
|
|
174
|
+
if (!sameMembers(manifest?.requiredEvidence || [], REQUIRED_RUNTIME_EVIDENCE))
|
|
175
|
+
issues.push("runtime semantic closure evidence dimensions drifted");
|
|
176
|
+
|
|
177
|
+
const mechanisms = new Map(
|
|
178
|
+
(v3Inventory.mechanisms || []).map((entry) => [entry.id, entry]),
|
|
179
|
+
);
|
|
180
|
+
const v4Capabilities = new Map(
|
|
181
|
+
(v4Manifest.capabilities || []).map((entry) => [entry.id, entry]),
|
|
182
|
+
);
|
|
183
|
+
const stateMachines = new Map(
|
|
184
|
+
(v4Manifest.stateMachines || []).map((entry) => [entry.id, entry]),
|
|
185
|
+
);
|
|
186
|
+
const capabilities = Array.isArray(manifest?.capabilities)
|
|
187
|
+
? manifest.capabilities
|
|
188
|
+
: [];
|
|
189
|
+
if (
|
|
190
|
+
!sameMembers(
|
|
191
|
+
capabilities.map((entry) => entry.id),
|
|
192
|
+
mechanisms.keys(),
|
|
193
|
+
)
|
|
194
|
+
)
|
|
195
|
+
issues.push(
|
|
196
|
+
"runtime semantic closure does not cover every v3 mechanism exactly once",
|
|
197
|
+
);
|
|
198
|
+
if (
|
|
199
|
+
!sameMembers(
|
|
200
|
+
capabilities.map((entry) => entry.id),
|
|
201
|
+
v4Capabilities.keys(),
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
issues.push(
|
|
205
|
+
"runtime semantic closure does not match the v4 capability manifest",
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const surfaces = publicSurfaceIds(root);
|
|
209
|
+
const ids = new Set();
|
|
210
|
+
for (const capability of capabilities) {
|
|
211
|
+
if (!capability?.id || ids.has(capability.id)) {
|
|
212
|
+
issues.push(
|
|
213
|
+
`runtime semantic capability id is missing or duplicated: ${capability?.id || "<empty>"}`,
|
|
214
|
+
);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
ids.add(capability.id);
|
|
218
|
+
const mechanism = mechanisms.get(capability.id);
|
|
219
|
+
const v4Capability = v4Capabilities.get(capability.id);
|
|
220
|
+
if (!mechanism || !v4Capability) continue;
|
|
221
|
+
if (capability.sourceMechanismId !== capability.id)
|
|
222
|
+
issues.push(`${capability.id}: source mechanism identity drifted`);
|
|
223
|
+
validateImplementation(root, mechanism, capability, issues);
|
|
224
|
+
validateResidualClosure(mechanism, capability, issues);
|
|
225
|
+
validateEvidence(root, mechanism, capability, issues);
|
|
226
|
+
validateAuthority(capability, stateMachines.get(capability.id), issues);
|
|
227
|
+
for (const surface of v4Capability.surfaces || []) {
|
|
228
|
+
if (!surfaces.has(surface))
|
|
229
|
+
issues.push(
|
|
230
|
+
`${capability.id}: executable v4 surface is absent: ${surface}`,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (issues.length)
|
|
236
|
+
throw new Error(
|
|
237
|
+
`v4 runtime semantic closure failed:\n- ${issues.join("\n- ")}`,
|
|
238
|
+
);
|
|
239
|
+
return {
|
|
240
|
+
capabilities: capabilities.length,
|
|
241
|
+
evidenceDimensions: capabilities.length * REQUIRED_RUNTIME_EVIDENCE.length,
|
|
242
|
+
residualsClosed: capabilities.reduce(
|
|
243
|
+
(sum, entry) => sum + entry.resolvedResiduals.length,
|
|
244
|
+
0,
|
|
245
|
+
),
|
|
246
|
+
legacyFallbacks: 0,
|
|
247
|
+
providerDecisionAuthorities: 0,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (
|
|
252
|
+
process.argv[1] &&
|
|
253
|
+
import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
|
|
254
|
+
) {
|
|
255
|
+
try {
|
|
256
|
+
const report = validateRuntimeSemanticClosure();
|
|
257
|
+
console.log(
|
|
258
|
+
`v4 runtime semantic closure passed: ${report.capabilities} capabilities, ` +
|
|
259
|
+
`${report.evidenceDimensions} evidence dimensions, ${report.residualsClosed} reverse-scan residuals closed, ` +
|
|
260
|
+
"0 legacy fallbacks, 0 provider decision authorities",
|
|
261
|
+
);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
264
|
+
process.exitCode = 1;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
|
|
7
|
+
const indexPath = "architecture/internal-capabilities.json";
|
|
8
|
+
const debtPath = "architecture/maintainability-debt.json";
|
|
9
|
+
const outputPath = "architecture/agent-change-map.md";
|
|
10
|
+
|
|
11
|
+
function list(values) {
|
|
12
|
+
if (!values?.length) return "- None.";
|
|
13
|
+
return values.map((value) => `- \`${value}\``).join("\n");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function debtRouteSection(debt) {
|
|
17
|
+
if (!debt?.surfaces) return "";
|
|
18
|
+
const defaults = debt.defaults;
|
|
19
|
+
const governedPaths = Object.entries(debt.surfaces).flatMap(
|
|
20
|
+
([domain, entries]) =>
|
|
21
|
+
Object.keys(entries).map((entry) => `${domain}: \`${entry}\``),
|
|
22
|
+
);
|
|
23
|
+
return `## Governed complexity debt routes
|
|
24
|
+
|
|
25
|
+
Owner: ${defaults.owner}
|
|
26
|
+
|
|
27
|
+
Capability: \`${defaults.capability}\`
|
|
28
|
+
|
|
29
|
+
Invariant: ${defaults.invariant}
|
|
30
|
+
|
|
31
|
+
Tests: ${defaults.tests.map((entry) => `\`${entry}\``).join(", ")}
|
|
32
|
+
|
|
33
|
+
Safe change route: ${defaults.safeChangeRoute}
|
|
34
|
+
|
|
35
|
+
### Oversized surfaces
|
|
36
|
+
|
|
37
|
+
${governedPaths.map((entry) => `- ${entry}`).join("\n")}
|
|
38
|
+
|
|
39
|
+
### Current top twenty maintenance hotspots
|
|
40
|
+
|
|
41
|
+
${debt.hotspots.map((entry) => `- \`${entry}\``).join("\n")}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function generateAgentChangeMap(index, debt = null) {
|
|
45
|
+
const capabilities = [...index.capabilities].sort((left, right) =>
|
|
46
|
+
left.id.localeCompare(right.id),
|
|
47
|
+
);
|
|
48
|
+
const sections = capabilities.map(
|
|
49
|
+
(capability) => `## ${capability.id}
|
|
50
|
+
|
|
51
|
+
Owner: ${capability.owner}
|
|
52
|
+
|
|
53
|
+
### Implementation
|
|
54
|
+
|
|
55
|
+
${list(capability.implementation)}
|
|
56
|
+
|
|
57
|
+
### Contracts
|
|
58
|
+
|
|
59
|
+
${list(capability.contracts)}
|
|
60
|
+
|
|
61
|
+
### Tests
|
|
62
|
+
|
|
63
|
+
${list(capability.tests)}
|
|
64
|
+
|
|
65
|
+
### Generated outputs
|
|
66
|
+
|
|
67
|
+
${list(capability.generatedOutputs)}
|
|
68
|
+
|
|
69
|
+
### Minimal validation
|
|
70
|
+
|
|
71
|
+
${list(capability.validationCommands)}`,
|
|
72
|
+
);
|
|
73
|
+
return `<!-- Generated by scripts/generate-agent-change-map.mjs. Do not edit directly. -->
|
|
74
|
+
# Agent Change Map
|
|
75
|
+
|
|
76
|
+
Use this index to identify the smallest implementation, contract, test, generated-output, and validation surface for a capability change. The machine-readable source of truth is \`${indexPath}\`.
|
|
77
|
+
|
|
78
|
+
${debtRouteSection(debt)}
|
|
79
|
+
|
|
80
|
+
${sections.join("\n\n")}
|
|
81
|
+
`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function run({ root = process.cwd(), mode = "check" } = {}) {
|
|
85
|
+
const index = JSON.parse(fs.readFileSync(path.join(root, indexPath), "utf8"));
|
|
86
|
+
const debt = JSON.parse(fs.readFileSync(path.join(root, debtPath), "utf8"));
|
|
87
|
+
const generated = generateAgentChangeMap(index, debt);
|
|
88
|
+
const target = path.join(root, outputPath);
|
|
89
|
+
if (mode === "write") {
|
|
90
|
+
fs.writeFileSync(target, generated);
|
|
91
|
+
return { outputPath, updated: true };
|
|
92
|
+
}
|
|
93
|
+
const current = fs.existsSync(target) ? fs.readFileSync(target, "utf8") : "";
|
|
94
|
+
if (current !== generated) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`${outputPath} is stale; run node scripts/generate-agent-change-map.mjs --write`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return { outputPath, updated: false };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (
|
|
103
|
+
process.argv[1] &&
|
|
104
|
+
import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
|
|
105
|
+
) {
|
|
106
|
+
try {
|
|
107
|
+
const mode = process.argv.includes("--write") ? "write" : "check";
|
|
108
|
+
const report = run({ mode });
|
|
109
|
+
console.log(
|
|
110
|
+
`${report.outputPath} ${report.updated ? "generated" : "is current"}`,
|
|
111
|
+
);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { generateAgentChangeMap, run };
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { parseWorkflowDocument } from "../packages/core/workflow-yaml-contract.js";
|
|
2
|
+
|
|
3
|
+
function lineCount(source) {
|
|
4
|
+
const text = String(source || "");
|
|
5
|
+
if (!text) return 0;
|
|
6
|
+
const lines = text.split(/\r?\n/u);
|
|
7
|
+
return lines.at(-1) === "" ? lines.length - 1 : lines.length;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function rustTokens(source) {
|
|
11
|
+
const tokens = [];
|
|
12
|
+
let index = 0;
|
|
13
|
+
let line = 1;
|
|
14
|
+
const advance = () => {
|
|
15
|
+
if (source[index] === "\n") line += 1;
|
|
16
|
+
index += 1;
|
|
17
|
+
};
|
|
18
|
+
while (index < source.length) {
|
|
19
|
+
if (/\s/u.test(source[index])) {
|
|
20
|
+
advance();
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (source.startsWith("//", index)) {
|
|
24
|
+
while (index < source.length && source[index] !== "\n") advance();
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (source.startsWith("/*", index)) {
|
|
28
|
+
let depth = 1;
|
|
29
|
+
advance();
|
|
30
|
+
advance();
|
|
31
|
+
while (index < source.length && depth > 0) {
|
|
32
|
+
if (source.startsWith("/*", index)) {
|
|
33
|
+
depth += 1;
|
|
34
|
+
advance();
|
|
35
|
+
advance();
|
|
36
|
+
} else if (source.startsWith("*/", index)) {
|
|
37
|
+
depth -= 1;
|
|
38
|
+
advance();
|
|
39
|
+
advance();
|
|
40
|
+
} else {
|
|
41
|
+
advance();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const raw = source.slice(index).match(/^(?:br|r)(#+)?"/u);
|
|
47
|
+
if (raw) {
|
|
48
|
+
const suffix = `"${raw[1] || ""}`;
|
|
49
|
+
for (let count = 0; count < raw[0].length; count += 1) advance();
|
|
50
|
+
while (index < source.length && !source.startsWith(suffix, index)) {
|
|
51
|
+
advance();
|
|
52
|
+
}
|
|
53
|
+
for (let count = 0; count < suffix.length; count += 1) advance();
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (source[index] === '"' || source.startsWith('b"', index)) {
|
|
57
|
+
if (source[index] === "b") advance();
|
|
58
|
+
advance();
|
|
59
|
+
while (index < source.length) {
|
|
60
|
+
if (source[index] === "\\") {
|
|
61
|
+
advance();
|
|
62
|
+
if (index < source.length) advance();
|
|
63
|
+
} else if (source[index] === '"') {
|
|
64
|
+
advance();
|
|
65
|
+
break;
|
|
66
|
+
} else {
|
|
67
|
+
advance();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const character = source.slice(index).match(/^'(?:\\.|[^'\\\n])'/u);
|
|
73
|
+
if (character) {
|
|
74
|
+
for (let count = 0; count < character[0].length; count += 1) advance();
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const identifier = source.slice(index).match(/^[A-Za-z_][A-Za-z0-9_]*/u);
|
|
78
|
+
if (identifier) {
|
|
79
|
+
tokens.push({ value: identifier[0], line });
|
|
80
|
+
index += identifier[0].length;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const operator = [
|
|
84
|
+
"=>",
|
|
85
|
+
"&&",
|
|
86
|
+
"||",
|
|
87
|
+
"::",
|
|
88
|
+
"->",
|
|
89
|
+
"<=",
|
|
90
|
+
">=",
|
|
91
|
+
"==",
|
|
92
|
+
"!=",
|
|
93
|
+
].find((candidate) => source.startsWith(candidate, index));
|
|
94
|
+
tokens.push({ value: operator || source[index], line });
|
|
95
|
+
index += (operator || source[index]).length;
|
|
96
|
+
}
|
|
97
|
+
return tokens;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function rustFunctions(tokens) {
|
|
101
|
+
const functions = [];
|
|
102
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
103
|
+
if (tokens[index].value !== "fn") continue;
|
|
104
|
+
const name =
|
|
105
|
+
tokens[index + 1]?.value || `<anonymous@${tokens[index].line}>`;
|
|
106
|
+
let body = index + 2;
|
|
107
|
+
while (body < tokens.length && !["{", ";"].includes(tokens[body].value)) {
|
|
108
|
+
body += 1;
|
|
109
|
+
}
|
|
110
|
+
if (tokens[body]?.value !== "{") continue;
|
|
111
|
+
let depth = 1;
|
|
112
|
+
let end = body + 1;
|
|
113
|
+
while (end < tokens.length && depth > 0) {
|
|
114
|
+
if (tokens[end].value === "{") depth += 1;
|
|
115
|
+
if (tokens[end].value === "}") depth -= 1;
|
|
116
|
+
end += 1;
|
|
117
|
+
}
|
|
118
|
+
if (depth !== 0) continue;
|
|
119
|
+
functions.push({ name, token: index, body, end: end - 1 });
|
|
120
|
+
}
|
|
121
|
+
return functions;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function isRustDecision(tokens, index) {
|
|
125
|
+
const value = tokens[index].value;
|
|
126
|
+
if (["if", "for", "while", "loop", "?", "=>"].includes(value)) return true;
|
|
127
|
+
if (!["&&", "||"].includes(value)) return false;
|
|
128
|
+
return !["=", "(", "{", "[", ",", ";", "return", "move"].includes(
|
|
129
|
+
tokens[index - 1]?.value,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function analyzeRust(_file, source) {
|
|
134
|
+
const tokens = rustTokens(source);
|
|
135
|
+
const parsed = rustFunctions(tokens);
|
|
136
|
+
const byStart = new Map(parsed.map((entry) => [entry.token, entry]));
|
|
137
|
+
const functions = parsed.map((entry) => {
|
|
138
|
+
let complexity = 1;
|
|
139
|
+
for (let index = entry.body + 1; index < entry.end; index += 1) {
|
|
140
|
+
const nested = byStart.get(index);
|
|
141
|
+
if (nested && nested.end <= entry.end) {
|
|
142
|
+
index = nested.end;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (isRustDecision(tokens, index)) complexity += 1;
|
|
146
|
+
}
|
|
147
|
+
const start = tokens[entry.token].line;
|
|
148
|
+
const end = tokens[entry.end].line;
|
|
149
|
+
return {
|
|
150
|
+
name: entry.name,
|
|
151
|
+
start,
|
|
152
|
+
end,
|
|
153
|
+
lines: end - start + 1,
|
|
154
|
+
complexity,
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
return {
|
|
158
|
+
lines: lineCount(source),
|
|
159
|
+
complexity: functions.reduce((total, entry) => total + entry.complexity, 0),
|
|
160
|
+
functions,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function semanticYamlLines(source) {
|
|
165
|
+
const result = [];
|
|
166
|
+
let blockIndent = null;
|
|
167
|
+
for (const [line, raw] of String(source || "")
|
|
168
|
+
.split(/\r?\n/u)
|
|
169
|
+
.entries()) {
|
|
170
|
+
const indent = raw.match(/^(\s*)/u)?.[1].length || 0;
|
|
171
|
+
if (blockIndent !== null) {
|
|
172
|
+
if (!raw.trim() || indent > blockIndent) continue;
|
|
173
|
+
blockIndent = null;
|
|
174
|
+
}
|
|
175
|
+
const text = raw.trim();
|
|
176
|
+
if (!text || text.startsWith("#")) continue;
|
|
177
|
+
result.push({ line: line + 1, indent, text });
|
|
178
|
+
if (/:\s*[>|][+-]?\s*(?:#.*)?$/u.test(raw)) blockIndent = indent;
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function analyzeWorkflow(_file, source) {
|
|
184
|
+
const lines = semanticYamlLines(source);
|
|
185
|
+
const document = parseWorkflowDocument(source);
|
|
186
|
+
const jobsEntry = lines.find(
|
|
187
|
+
(entry) => entry.indent === 0 && entry.text === "jobs:",
|
|
188
|
+
);
|
|
189
|
+
const jobs = [];
|
|
190
|
+
if (jobsEntry) {
|
|
191
|
+
const candidates = lines.filter(
|
|
192
|
+
(entry) => entry.line > jobsEntry.line && entry.indent > jobsEntry.indent,
|
|
193
|
+
);
|
|
194
|
+
const jobIndent = Math.min(...candidates.map((entry) => entry.indent));
|
|
195
|
+
for (const entry of candidates) {
|
|
196
|
+
if (
|
|
197
|
+
entry.indent === jobIndent &&
|
|
198
|
+
/^[A-Za-z0-9_.-]+:\s*(?:#.*)?$/u.test(entry.text)
|
|
199
|
+
) {
|
|
200
|
+
jobs.push(entry);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const stepsByJob = jobs.map((job, jobIndex) => {
|
|
205
|
+
const endLine = jobs[jobIndex + 1]?.line || Number.POSITIVE_INFINITY;
|
|
206
|
+
const stepRoot = lines.find(
|
|
207
|
+
(entry) =>
|
|
208
|
+
entry.line > job.line &&
|
|
209
|
+
entry.line < endLine &&
|
|
210
|
+
entry.indent > job.indent &&
|
|
211
|
+
entry.text === "steps:",
|
|
212
|
+
);
|
|
213
|
+
if (!stepRoot) return 0;
|
|
214
|
+
const stepLines = lines.filter(
|
|
215
|
+
(entry) =>
|
|
216
|
+
entry.line > stepRoot.line &&
|
|
217
|
+
entry.line < endLine &&
|
|
218
|
+
entry.indent > stepRoot.indent,
|
|
219
|
+
);
|
|
220
|
+
const stepIndent = Math.min(...stepLines.map((entry) => entry.indent));
|
|
221
|
+
return stepLines.filter(
|
|
222
|
+
(entry) => entry.indent === stepIndent && entry.text.startsWith("- "),
|
|
223
|
+
).length;
|
|
224
|
+
});
|
|
225
|
+
const decisions = lines.filter((entry) =>
|
|
226
|
+
/^(?:-\s+)?(?:if|matrix):/u.test(entry.text),
|
|
227
|
+
).length;
|
|
228
|
+
return {
|
|
229
|
+
lines: lineCount(source),
|
|
230
|
+
jobs: document.jobs.length,
|
|
231
|
+
steps: stepsByJob.reduce((total, count) => total + count, 0),
|
|
232
|
+
maxStepsPerJob: Math.max(0, ...stepsByJob),
|
|
233
|
+
decisions,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export { analyzeRust, analyzeWorkflow };
|