@bensandee/tooling 0.102.0 → 0.103.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.
- package/dist/bin.mjs +681 -370
- package/package.json +1 -1
package/dist/bin.mjs
CHANGED
|
@@ -173,7 +173,7 @@ function loadEnvFileForBin(rawArgs, bin, io = processIo) {
|
|
|
173
173
|
// src/env-file-preload.ts
|
|
174
174
|
const envFileLoad = loadEnvFileForBin(process.argv.slice(2), {
|
|
175
175
|
name: "bst",
|
|
176
|
-
version: "0.
|
|
176
|
+
version: "0.103.0"
|
|
177
177
|
});
|
|
178
178
|
// ../cli-kit/src/logger.ts
|
|
179
179
|
const RANK = {
|
|
@@ -5800,7 +5800,7 @@ function buildManagedDevDeps(ctx) {
|
|
|
5800
5800
|
const devDeps = { ...rootDevDeps(ctx.config) };
|
|
5801
5801
|
if (!isMonorepo) Object.assign(devDeps, perPackageDevDeps(ctx.config));
|
|
5802
5802
|
if (ctx.config.stack !== "none") devDeps["@bensandee/config"] = isWorkspacePackage(ctx, "@bensandee/config") ? "workspace:*" : "0.15.1";
|
|
5803
|
-
if (!isWorkspacePackage(ctx, "@bensandee/tooling")) devDeps["@bensandee/tooling"] = "0.
|
|
5803
|
+
if (!isWorkspacePackage(ctx, "@bensandee/tooling")) devDeps["@bensandee/tooling"] = "0.103.0";
|
|
5804
5804
|
if (ctx.config.useEslintPlugin && ctx.config.stack !== "none") devDeps["@bensandee/eslint-plugin"] = isWorkspacePackage(ctx, "@bensandee/eslint-plugin") ? "workspace:*" : "0.18.0";
|
|
5805
5805
|
if (wantsAgentCli(ctx)) devDeps[AGENT_CLI_PACKAGE] = "0.3.1";
|
|
5806
5806
|
if (ctx.config.formatter === "oxfmt") devDeps["oxfmt"] = {
|
|
@@ -9597,7 +9597,7 @@ const AGENT_RULES_HEAD = [
|
|
|
9597
9597
|
"- Use pnpm, not npm/yarn/npx. Run binaries with `pnpm exec`.",
|
|
9598
9598
|
"- `mise install` provides the toolchain (`mise.toml`); a non-interactive session finds it only through mise's shims (`mise activate --shims` in the login profile)."
|
|
9599
9599
|
];
|
|
9600
|
-
const TS_TYPECAST_RULE = "-
|
|
9600
|
+
const TS_TYPECAST_RULE = "- Never overrule the type checker: no `as T` assertions and no `any`. Narrow instead, with a zod schema, a type guard, or a control-flow check. `as const` and `satisfies` are fine, because they make a type stricter, not looser.";
|
|
9601
9601
|
const AGENT_RULES_MID = [
|
|
9602
9602
|
"- Fix lint violations; don't suppress them. For `no-empty-function`, use a `{ /* no-op */ }` body, not a disable comment.",
|
|
9603
9603
|
"- Write text in any language; letters, accents and other scripts are fine. Keep out what `chars:check` denies: LLM-tell punctuation (curly quotes, ellipsis, en and em dashes, arrows, box-drawing, status glyphs) and invisible or deceptive characters (bidi controls, zero-width and tag characters, odd spaces). Write `...`, `-`/`--`, straight quotes, `->` and `-`/`|`/`+` instead. Where a denied character must survive to output, escape it for its context: `\\uXXXX` in a JS/TS/Kotlin/Java string, char or regex; `&#xXXXX;` in JSX or XML; a spliced `${'\\uXXXX'}` in a Kotlin raw string. `pnpm exec bst chars:check --fix` applies the safe rewrites (`--fix-ambiguous` for em dashes and status glyphs) and flags the rest.",
|
|
@@ -9941,7 +9941,7 @@ const HEALTH_RULE_TAIL = [
|
|
|
9941
9941
|
"",
|
|
9942
9942
|
"**An exemption takes a module or directory out of the gate.** It is listed with its count and reason in `health:summary --explain`, carries no ceiling, and is counted in no metric. `crowdedDirectories` is exemptable by directory path. A key may be a glob. Adding one is a raise too.",
|
|
9943
9943
|
"",
|
|
9944
|
-
"**A raise travels with the code that caused it.** A raise is a higher count or ceiling, a ceiling for a module that has none, a new exemption, or a higher limit. Write it with `pnpm exec bst health:raise` in the pull request whose code crossed the budget; say in the commit why, and a person merges it. Its `--exempt <leaf> --reason \"<text>\"` is for a hub by construction. Never raise a limit to pass. `--update-baseline --reset` rebuilds a baseline, never one branch.",
|
|
9944
|
+
"**A raise travels with the code that caused it.** A raise is a higher count or ceiling, a ceiling for a module that has none, a new exemption, or a higher limit. Write it with `pnpm exec bst health:raise` in the pull request whose code crossed the budget; say in the commit why, and a person merges it. Its `--exempt <leaf> --reason \"<text>\"` is for a hub by construction. Never raise a limit to pass. `--update-baseline --reset` rebuilds a baseline, never one branch. A lowering travels the same way: `pnpm exec bst health:tighten` writes it, from the measurement.",
|
|
9945
9945
|
"",
|
|
9946
9946
|
"Prefer an exemption to raising `fanInLimit` or `fanOutLimit`: an exemption names the hub in `health:summary --explain`, while a higher limit silently un-tracks every module beneath it. A per-module ceiling has no such shadow -- it ratchets one module at one count and fails again one edge later.",
|
|
9947
9947
|
"",
|
|
@@ -10402,7 +10402,7 @@ function reportFailures(failed, command) {
|
|
|
10402
10402
|
function generateMigratePrompt(results, config, detected) {
|
|
10403
10403
|
const sections = [];
|
|
10404
10404
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
10405
|
-
sections.push(`# Migration Prompt\n\n_Generated by \`@bensandee/tooling@0.
|
|
10405
|
+
sections.push(`# Migration Prompt\n\n_Generated by \`@bensandee/tooling@0.103.0 repo:sync\` on ${timestamp}_\n`);
|
|
10406
10406
|
const changed = results.filter((r) => r.action === "created" || r.action === "updated" || r.action === "archived");
|
|
10407
10407
|
if (changed.length > 0) {
|
|
10408
10408
|
const items = changed.map((r) => {
|
|
@@ -11335,7 +11335,7 @@ function createRealHealthExecutor(rootDir) {
|
|
|
11335
11335
|
};
|
|
11336
11336
|
}
|
|
11337
11337
|
// src/codebase-health/reference.ts
|
|
11338
|
-
const BASELINE_FILE$
|
|
11338
|
+
const BASELINE_FILE$3 = "health-baseline.json";
|
|
11339
11339
|
const TOOLING_FILE$1 = ".tooling.json";
|
|
11340
11340
|
function repoPrefix(executor, cwd) {
|
|
11341
11341
|
const result = executor.exec("git", ["rev-parse", "--show-prefix"], { cwd });
|
|
@@ -11416,7 +11416,7 @@ function readReference(executor, opts) {
|
|
|
11416
11416
|
kind: "unavailable",
|
|
11417
11417
|
reason: `health: cannot read the reference at the merge base with origin/${branch}. Run \`git fetch origin ${branch}\` so the default branch is present (a shallow clone or a missing remote-tracking ref makes it absent), or set .tooling.json#defaultBranch on the default branch if it has another name -- once that branch is fetched, its own copy of the setting decides, not this branch's. health:check fails closed without a reference.`
|
|
11418
11418
|
};
|
|
11419
|
-
const baselineText = showAt(executor, opts.cwd, sha, `${prefix}${BASELINE_FILE$
|
|
11419
|
+
const baselineText = showAt(executor, opts.cwd, sha, `${prefix}${BASELINE_FILE$3}`);
|
|
11420
11420
|
const toolingText = showAt(executor, opts.cwd, sha, `${prefix}${TOOLING_FILE$1}`);
|
|
11421
11421
|
const health = resolveHealthConfigFromContext({
|
|
11422
11422
|
exists: (rel) => rel === TOOLING_FILE$1 && toolingText !== void 0,
|
|
@@ -11569,7 +11569,7 @@ function baselineRaises(reference, current) {
|
|
|
11569
11569
|
}
|
|
11570
11570
|
}
|
|
11571
11571
|
if (reference.baseline !== void 0 && current.baseline === void 0) raises.push({
|
|
11572
|
-
leaf: BASELINE_FILE$
|
|
11572
|
+
leaf: BASELINE_FILE$3,
|
|
11573
11573
|
reference: "present",
|
|
11574
11574
|
current: "absent"
|
|
11575
11575
|
});
|
|
@@ -23358,13 +23358,13 @@ function serializeBaseline(baseline) {
|
|
|
23358
23358
|
}
|
|
23359
23359
|
// src/commands/coverage-check.ts
|
|
23360
23360
|
const COVERAGE_SUMMARY_FILE$1 = "coverage/coverage-summary.json";
|
|
23361
|
-
const BASELINE_FILE$
|
|
23362
|
-
const MIGRATION_NOTICE = `${BASELINE_FILE$
|
|
23361
|
+
const BASELINE_FILE$2 = "coverage-baseline.json";
|
|
23362
|
+
const MIGRATION_NOTICE = `${BASELINE_FILE$2} predates coverage.include scoping (no scope marker). Totals may have shifted because previously-untested files entered the denominator for the first time -- that is not necessarily a regression. This comparison is advisory only until the baseline is migrated: run \`pnpm test:coverage && pnpm exec bst coverage:check --update-baseline --reset\` once to adopt the honest, marked baseline. Normal gating resumes after that.`;
|
|
23363
23363
|
function applyBaselineUpdate$1(out, baselinePath, baseline, current, options) {
|
|
23364
23364
|
const { reset, floorPp } = options;
|
|
23365
23365
|
if (reset) {
|
|
23366
23366
|
writeFileSync(baselinePath, serializeBaseline(current));
|
|
23367
|
-
out.notice(`Updated ${BASELINE_FILE$
|
|
23367
|
+
out.notice(`Updated ${BASELINE_FILE$2} (--reset: unconditional).`);
|
|
23368
23368
|
} else if (floorPp !== void 0) {
|
|
23369
23369
|
const merged = mergeTotalsWithFloor(baseline.totals, current.totals, floorPp);
|
|
23370
23370
|
writeFileSync(baselinePath, serializeBaseline({
|
|
@@ -23372,10 +23372,10 @@ function applyBaselineUpdate$1(out, baselinePath, baseline, current, options) {
|
|
|
23372
23372
|
totals: merged
|
|
23373
23373
|
}));
|
|
23374
23374
|
const held = TOTAL_KEYS.filter((key) => merged[key] !== current.totals[key]);
|
|
23375
|
-
out.notice(held.length === 0 ? `Updated ${BASELINE_FILE$
|
|
23375
|
+
out.notice(held.length === 0 ? `Updated ${BASELINE_FILE$2} (floor ${String(floorPp)}%).` : `Updated ${BASELINE_FILE$2} (floor ${String(floorPp)}%; held at baseline below the floor: ${held.join(", ")}).`);
|
|
23376
23376
|
} else if (isFlatOrUp(baseline.totals, current.totals)) {
|
|
23377
23377
|
writeFileSync(baselinePath, serializeBaseline(current));
|
|
23378
|
-
out.notice(`Updated ${BASELINE_FILE$
|
|
23378
|
+
out.notice(`Updated ${BASELINE_FILE$2} (all four totals flat-or-up).`);
|
|
23379
23379
|
} else out.notice(`Skipped baseline update: at least one total dropped below baseline. Add tests or adjust coverage.exclude before updating.`);
|
|
23380
23380
|
}
|
|
23381
23381
|
const coverageCheckCommand = defineCommand({
|
|
@@ -23421,20 +23421,20 @@ const coverageCheckCommand = defineCommand({
|
|
|
23421
23421
|
return;
|
|
23422
23422
|
}
|
|
23423
23423
|
const summaryPath = path.join(targetDir, COVERAGE_SUMMARY_FILE$1);
|
|
23424
|
-
const baselinePath = path.join(targetDir, BASELINE_FILE$
|
|
23424
|
+
const baselinePath = path.join(targetDir, BASELINE_FILE$2);
|
|
23425
23425
|
if (!existsSync(summaryPath)) throw new FatalError(missingSummaryMessage(targetDir));
|
|
23426
23426
|
const current = deriveBaseline(parseV8Summary(readFileSync(summaryPath, "utf-8")), { rootDir: targetDir });
|
|
23427
23427
|
if (!existsSync(baselinePath)) {
|
|
23428
23428
|
if (args["update-baseline"] === true) {
|
|
23429
23429
|
writeFileSync(baselinePath, serializeBaseline(current));
|
|
23430
|
-
out.notice(`Created ${BASELINE_FILE$
|
|
23430
|
+
out.notice(`Created ${BASELINE_FILE$2} (no prior baseline).`);
|
|
23431
23431
|
out.json({
|
|
23432
23432
|
status: "baseline-created",
|
|
23433
23433
|
totals: current.totals
|
|
23434
23434
|
});
|
|
23435
23435
|
return;
|
|
23436
23436
|
}
|
|
23437
|
-
const message = `${BASELINE_FILE$
|
|
23437
|
+
const message = `${BASELINE_FILE$2} not found. Run with --update-baseline to create one from the current run.`;
|
|
23438
23438
|
if (args["fail-on-missing-baseline"] === false) {
|
|
23439
23439
|
out.notice(message);
|
|
23440
23440
|
out.json({
|
|
@@ -23588,6 +23588,17 @@ function serializeHealthBaseline(metrics, ceilings, sizeBudgets) {
|
|
|
23588
23588
|
if (sizeBudgets !== void 0 && Object.keys(sizeBudgets).length > 0) ordered["sizeBudgets"] = sizeBudgets;
|
|
23589
23589
|
return JSON.stringify(ordered, null, 2) + "\n";
|
|
23590
23590
|
}
|
|
23591
|
+
function healthFileFormatter(targetDir) {
|
|
23592
|
+
const detected = computeDefaults(targetDir);
|
|
23593
|
+
return createContentFormatter({
|
|
23594
|
+
targetDir,
|
|
23595
|
+
formatter: loadToolingConfig(targetDir)?.formatter ?? detected.formatter
|
|
23596
|
+
});
|
|
23597
|
+
}
|
|
23598
|
+
function writeHealthBaseline(targetDir, baseline) {
|
|
23599
|
+
const format = healthFileFormatter(targetDir);
|
|
23600
|
+
writeFileSync(path.join(targetDir, "health-baseline.json"), format("health-baseline.json", serializeHealthBaseline(baseline, baseline.moduleCeilings, baseline.sizeBudgets)));
|
|
23601
|
+
}
|
|
23591
23602
|
// src/codebase-health/exclude.ts
|
|
23592
23603
|
function normalize(rel) {
|
|
23593
23604
|
const posix = rel.replace(/\\/g, "/");
|
|
@@ -24317,8 +24328,7 @@ function compareMetrics(baseline, current, tolerance = DEFAULT_TOLERANCE, curren
|
|
|
24317
24328
|
};
|
|
24318
24329
|
}
|
|
24319
24330
|
function needsBaseMeasurement(result) {
|
|
24320
|
-
|
|
24321
|
-
return RATCHETED_METRIC_KEYS.some((key) => failedKeys.has(key) && result.uncoveredOutliers.some((o) => o.key === key));
|
|
24331
|
+
return result.uncoveredOutliers.length > 0;
|
|
24322
24332
|
}
|
|
24323
24333
|
function attributeOutliers(uncovered, base) {
|
|
24324
24334
|
if (base.status !== "measured") return {
|
|
@@ -24380,156 +24390,215 @@ function isFlatOrBetter(baseline, current, currentCeilings = {}, sizes = []) {
|
|
|
24380
24390
|
});
|
|
24381
24391
|
return metricsFlat && ceilingsFlat && sizesFlat;
|
|
24382
24392
|
}
|
|
24383
|
-
// src/codebase-health/
|
|
24384
|
-
const
|
|
24385
|
-
function
|
|
24386
|
-
|
|
24387
|
-
const tree = path.join(tmp, "tree");
|
|
24388
|
-
const index = path.join(tmp, "index");
|
|
24389
|
-
try {
|
|
24390
|
-
fs.mkdirSync(tree, { recursive: true });
|
|
24391
|
-
const gitDir = gitOutput(executor.exec("git", ["rev-parse", "--absolute-git-dir"], { cwd: targetDir }), "git rev-parse --absolute-git-dir").trim();
|
|
24392
|
-
const workRoot = gitOutput(executor.exec("git", ["rev-parse", "--show-toplevel"], { cwd: targetDir }), "git rev-parse --show-toplevel").trim();
|
|
24393
|
-
const intoCheckout = (args) => executor.exec("git", [
|
|
24394
|
-
`--git-dir=${gitDir}`,
|
|
24395
|
-
`--work-tree=${tree}`,
|
|
24396
|
-
...args
|
|
24397
|
-
], {
|
|
24398
|
-
cwd: tree,
|
|
24399
|
-
env: { GIT_INDEX_FILE: index }
|
|
24400
|
-
});
|
|
24401
|
-
gitOutput(intoCheckout(["read-tree", mergeBase]), `git read-tree ${mergeBase.slice(0, 12)}`);
|
|
24402
|
-
gitOutput(intoCheckout(["checkout-index", "-a"]), "git checkout-index -a");
|
|
24403
|
-
mirrorNodeModules(workRoot, tree);
|
|
24404
|
-
return use(tree);
|
|
24405
|
-
} finally {
|
|
24406
|
-
fs.rmSync(tmp, {
|
|
24407
|
-
recursive: true,
|
|
24408
|
-
force: true
|
|
24409
|
-
});
|
|
24410
|
-
}
|
|
24393
|
+
// src/codebase-health/raise.ts
|
|
24394
|
+
const SIZE_RAISE_FACTOR = 1.01;
|
|
24395
|
+
function sizeRaiseValue(measured) {
|
|
24396
|
+
return Math.floor(measured * SIZE_RAISE_FACTOR) + 1;
|
|
24411
24397
|
}
|
|
24412
|
-
|
|
24413
|
-
|
|
24414
|
-
|
|
24415
|
-
|
|
24398
|
+
const JsonObjectSchema = z.record(z.string(), z.unknown());
|
|
24399
|
+
const EXEMPT_LEAF_KEYS = [
|
|
24400
|
+
{
|
|
24401
|
+
prefix: "fan-in",
|
|
24402
|
+
key: "fanInOutliers"
|
|
24403
|
+
},
|
|
24404
|
+
{
|
|
24405
|
+
prefix: "fan-out",
|
|
24406
|
+
key: "fanOutOutliers"
|
|
24407
|
+
},
|
|
24408
|
+
{
|
|
24409
|
+
prefix: "crowding",
|
|
24410
|
+
key: "crowdedDirectories"
|
|
24411
|
+
}
|
|
24412
|
+
];
|
|
24413
|
+
function refuseDeniableReason(leaf, reason) {
|
|
24414
|
+
const fixed = fixText(`// ${reason}`, {
|
|
24415
|
+
offenders: resolveOffenders(),
|
|
24416
|
+
path: "health-raise.ts"
|
|
24417
|
+
});
|
|
24418
|
+
const refused = fixed.decisions.find((decision) => !decision.applied);
|
|
24419
|
+
if (refused !== void 0) throw new FatalError(`health:raise: the reason for --exempt "${leaf}" carries ${refused.hit.offender.codepoint} (${refused.hit.offender.name}): ${refused.reason ?? "this gate denies it"}. Rewrite it in ASCII.`);
|
|
24420
|
+
return fixed.text.slice(3);
|
|
24416
24421
|
}
|
|
24417
|
-
function
|
|
24418
|
-
|
|
24422
|
+
function parseExemptLeaf(leaf) {
|
|
24423
|
+
const separator = leaf.indexOf(":");
|
|
24424
|
+
const prefix = separator < 0 ? "" : leaf.slice(0, separator).trim();
|
|
24425
|
+
const path = separator < 0 ? "" : leaf.slice(separator + 1).trim();
|
|
24426
|
+
if (prefix === "size") throw new FatalError(`health:raise: --exempt "${leaf}" names a size budget, which has no module to exempt. Run without --exempt: "health:raise" widens a grown size budget by measurement.`);
|
|
24427
|
+
const named = EXEMPT_LEAF_KEYS.find((entry) => entry.prefix === prefix);
|
|
24428
|
+
if (named === void 0 || path === "") throw new FatalError(`health:raise: --exempt "${leaf}" names no exemptable leaf. Pass one "health:check" printed: "fan-in: <path>", "fan-out: <path>", "crowding: <path>".`);
|
|
24429
|
+
return {
|
|
24430
|
+
key: named.key,
|
|
24431
|
+
path
|
|
24432
|
+
};
|
|
24419
24433
|
}
|
|
24420
|
-
function
|
|
24421
|
-
|
|
24422
|
-
|
|
24423
|
-
|
|
24424
|
-
|
|
24425
|
-
} catch (_error) {
|
|
24426
|
-
return;
|
|
24427
|
-
}
|
|
24428
|
-
for (const entry of entries) {
|
|
24429
|
-
if (!entry.isDirectory() || entry.isSymbolicLink()) continue;
|
|
24430
|
-
if (entry.name === ".git" || entry.name === "node_modules") continue;
|
|
24431
|
-
mirrorTree(workingRoot, checkoutRoot, path.join(rel, entry.name));
|
|
24434
|
+
function copyCeilings$1(ceilings) {
|
|
24435
|
+
const copy = {};
|
|
24436
|
+
for (const key of RATCHETED_METRIC_KEYS) {
|
|
24437
|
+
const byModule = ceilings?.[key];
|
|
24438
|
+
if (byModule !== void 0) copy[key] = { ...byModule };
|
|
24432
24439
|
}
|
|
24440
|
+
return copy;
|
|
24433
24441
|
}
|
|
24434
|
-
function
|
|
24435
|
-
|
|
24436
|
-
|
|
24437
|
-
|
|
24438
|
-
|
|
24439
|
-
|
|
24440
|
-
|
|
24441
|
-
|
|
24442
|
-
|
|
24443
|
-
|
|
24444
|
-
|
|
24445
|
-
|
|
24446
|
-
|
|
24447
|
-
|
|
24448
|
-
|
|
24449
|
-
|
|
24450
|
-
|
|
24451
|
-
|
|
24452
|
-
|
|
24442
|
+
function writeCeiling$1(ceilings, key, module, to) {
|
|
24443
|
+
const byModule = ceilings[key] ?? {};
|
|
24444
|
+
byModule[module] = to;
|
|
24445
|
+
ceilings[key] = byModule;
|
|
24446
|
+
}
|
|
24447
|
+
function headlineFor(baseline, comparison, key, exemptCount) {
|
|
24448
|
+
const measured = comparison.metrics.find((metric) => metric.key === key)?.current;
|
|
24449
|
+
if (measured === void 0) return void 0;
|
|
24450
|
+
const remaining = Math.max(0, measured - exemptCount);
|
|
24451
|
+
return baseline[key] === void 0 ? remaining : Math.max(baseline[key] ?? 0, remaining);
|
|
24452
|
+
}
|
|
24453
|
+
function exemptionWrites(input) {
|
|
24454
|
+
const writes = [];
|
|
24455
|
+
const notes = [];
|
|
24456
|
+
for (const request of input.exemptions) {
|
|
24457
|
+
const parsed = parseExemptLeaf(request.leaf);
|
|
24458
|
+
if (parsed === void 0) continue;
|
|
24459
|
+
const recorded = input.config.exempt[parsed.key]?.[parsed.path];
|
|
24460
|
+
if (recorded !== void 0) {
|
|
24461
|
+
notes.push(`health.exempt.${parsed.key}.${parsed.path} already reads "${recorded}"; the reason was not overwritten.`);
|
|
24453
24462
|
continue;
|
|
24454
24463
|
}
|
|
24455
|
-
|
|
24456
|
-
|
|
24457
|
-
|
|
24458
|
-
|
|
24459
|
-
}
|
|
24460
|
-
function safeReadlink(file) {
|
|
24461
|
-
try {
|
|
24462
|
-
return fs.readlinkSync(file);
|
|
24463
|
-
} catch (_error) {
|
|
24464
|
-
return;
|
|
24464
|
+
writes.push({
|
|
24465
|
+
key: parsed.key,
|
|
24466
|
+
path: parsed.path,
|
|
24467
|
+
reason: refuseDeniableReason(request.leaf, request.reason)
|
|
24468
|
+
});
|
|
24465
24469
|
}
|
|
24466
|
-
}
|
|
24467
|
-
function linkRelative(link, target) {
|
|
24468
|
-
try {
|
|
24469
|
-
fs.symlinkSync(link, target);
|
|
24470
|
-
} catch (_error) {}
|
|
24471
|
-
}
|
|
24472
|
-
// src/codebase-health/base-outliers.ts
|
|
24473
|
-
function unavailable(reason) {
|
|
24474
24470
|
return {
|
|
24475
|
-
|
|
24476
|
-
|
|
24471
|
+
writes,
|
|
24472
|
+
notes
|
|
24477
24473
|
};
|
|
24478
24474
|
}
|
|
24479
|
-
function
|
|
24480
|
-
|
|
24475
|
+
function objectAt(parent, key, where) {
|
|
24476
|
+
const existing = parent[key];
|
|
24477
|
+
if (existing === void 0) return {};
|
|
24478
|
+
const parsed = JsonObjectSchema.safeParse(existing);
|
|
24479
|
+
if (!parsed.success) throw new FatalError(`health:raise: ${where}#${key} is not an object, so an exemption cannot be written there.`);
|
|
24480
|
+
return { ...parsed.data };
|
|
24481
24481
|
}
|
|
24482
|
-
function
|
|
24483
|
-
|
|
24484
|
-
|
|
24485
|
-
|
|
24486
|
-
|
|
24487
|
-
|
|
24488
|
-
|
|
24489
|
-
|
|
24490
|
-
|
|
24491
|
-
|
|
24492
|
-
|
|
24493
|
-
|
|
24494
|
-
|
|
24495
|
-
};
|
|
24496
|
-
});
|
|
24497
|
-
} catch (error) {
|
|
24498
|
-
return unavailable(describeError$1(error));
|
|
24482
|
+
function applyExemptions(tooling, writes) {
|
|
24483
|
+
if (writes.length === 0) return void 0;
|
|
24484
|
+
const file = JsonObjectSchema.safeParse(tooling ?? {});
|
|
24485
|
+
if (!file.success) throw new FatalError(`health:raise: .tooling.json is not a JSON object, so no exemption can be written.`);
|
|
24486
|
+
const result = { ...file.data };
|
|
24487
|
+
for (const write of writes) {
|
|
24488
|
+
const health = objectAt(result, "health", ".tooling.json");
|
|
24489
|
+
const exempt = objectAt(health, "exempt", ".tooling.json#health");
|
|
24490
|
+
const table = objectAt(exempt, write.key, ".tooling.json#health.exempt");
|
|
24491
|
+
table[write.path] = write.reason;
|
|
24492
|
+
exempt[write.key] = table;
|
|
24493
|
+
health["exempt"] = exempt;
|
|
24494
|
+
result["health"] = health;
|
|
24499
24495
|
}
|
|
24496
|
+
return result;
|
|
24500
24497
|
}
|
|
24501
|
-
|
|
24502
|
-
const
|
|
24503
|
-
const
|
|
24504
|
-
|
|
24505
|
-
|
|
24506
|
-
|
|
24507
|
-
|
|
24508
|
-
|
|
24509
|
-
|
|
24510
|
-
const
|
|
24511
|
-
|
|
24512
|
-
|
|
24513
|
-
|
|
24514
|
-
|
|
24515
|
-
|
|
24516
|
-
|
|
24517
|
-
for (const
|
|
24518
|
-
|
|
24519
|
-
|
|
24520
|
-
|
|
24521
|
-
|
|
24522
|
-
|
|
24523
|
-
|
|
24524
|
-
|
|
24525
|
-
|
|
24498
|
+
function planHealthRaise(input) {
|
|
24499
|
+
const ceilings = copyCeilings$1(input.baseline.moduleCeilings);
|
|
24500
|
+
const ceilingWrites = [];
|
|
24501
|
+
const headlines = {};
|
|
24502
|
+
const notes = [];
|
|
24503
|
+
const exemptions = exemptionWrites(input);
|
|
24504
|
+
notes.push(...exemptions.notes);
|
|
24505
|
+
const isExcused = (key, module) => exemptions.writes.some((write) => write.key === key && exemptKeyMatcher(write.path)(module));
|
|
24506
|
+
const exemptedCount = /* @__PURE__ */ new Map();
|
|
24507
|
+
const countExcused = (key, module) => {
|
|
24508
|
+
if (isExcused(key, module)) exemptedCount.set(key, (exemptedCount.get(key) ?? 0) + 1);
|
|
24509
|
+
};
|
|
24510
|
+
for (const outlier of input.attribution.newOutliers) countExcused(outlier.key, outlier.module);
|
|
24511
|
+
for (const ceiling of input.comparison.ceilings) if (!ceiling.pass) countExcused(ceiling.key, ceiling.module);
|
|
24512
|
+
const outlierBase = input.attribution.outlierBase;
|
|
24513
|
+
if (outlierBase.status === "unavailable") notes.push(`no "(new)" ceiling was written: the merge base ${outlierBase.mergeBase} could not be measured (${outlierBase.reason}), so nothing could be called a first crossing.`);
|
|
24514
|
+
for (const outlier of input.attribution.newOutliers) {
|
|
24515
|
+
if (isExcused(outlier.key, outlier.module)) continue;
|
|
24516
|
+
writeCeiling$1(ceilings, outlier.key, outlier.module, outlier.current);
|
|
24517
|
+
const headline = headlineFor(input.baseline, input.comparison, outlier.key, exemptedCount.get(outlier.key) ?? 0);
|
|
24518
|
+
if (headline !== void 0) headlines[outlier.key] = headline;
|
|
24519
|
+
ceilingWrites.push({
|
|
24520
|
+
key: outlier.key,
|
|
24521
|
+
module: outlier.module,
|
|
24522
|
+
value: outlier.current,
|
|
24523
|
+
...headline === void 0 ? {} : { headline }
|
|
24524
|
+
});
|
|
24526
24525
|
}
|
|
24527
|
-
|
|
24528
|
-
|
|
24529
|
-
|
|
24530
|
-
|
|
24531
|
-
|
|
24532
|
-
|
|
24526
|
+
for (const ceiling of input.comparison.ceilings) {
|
|
24527
|
+
if (ceiling.pass) continue;
|
|
24528
|
+
if (isExcused(ceiling.key, ceiling.module)) continue;
|
|
24529
|
+
writeCeiling$1(ceilings, ceiling.key, ceiling.module, ceiling.current);
|
|
24530
|
+
ceilingWrites.push({
|
|
24531
|
+
key: ceiling.key,
|
|
24532
|
+
module: ceiling.module,
|
|
24533
|
+
value: ceiling.current
|
|
24534
|
+
});
|
|
24535
|
+
}
|
|
24536
|
+
const sizeBudgets = { ...input.baseline.sizeBudgets };
|
|
24537
|
+
const sizeWrites = [];
|
|
24538
|
+
for (const size of input.comparison.sizeResults) {
|
|
24539
|
+
if (size.pass || size.measured === void 0 || size.ceiling === void 0) continue;
|
|
24540
|
+
if (size.measured <= size.ceiling) continue;
|
|
24541
|
+
const value = sizeRaiseValue(size.measured);
|
|
24542
|
+
sizeBudgets[size.id] = value;
|
|
24543
|
+
sizeWrites.push({
|
|
24544
|
+
id: size.id,
|
|
24545
|
+
value
|
|
24546
|
+
});
|
|
24547
|
+
}
|
|
24548
|
+
return {
|
|
24549
|
+
baseline: widenedBaseline(input.baseline, headlines, ceilings, sizeBudgets),
|
|
24550
|
+
tooling: applyExemptions(input.tooling, exemptions.writes),
|
|
24551
|
+
ceilings: ceilingWrites,
|
|
24552
|
+
sizes: sizeWrites,
|
|
24553
|
+
exemptions: exemptions.writes,
|
|
24554
|
+
notes
|
|
24555
|
+
};
|
|
24556
|
+
}
|
|
24557
|
+
function widenedBaseline(baseline, headlines, ceilings, sizeBudgets) {
|
|
24558
|
+
const widened = { ...baseline };
|
|
24559
|
+
for (const key of METRIC_KEYS) {
|
|
24560
|
+
const headline = headlines[key];
|
|
24561
|
+
if (headline !== void 0) widened[key] = headline;
|
|
24562
|
+
}
|
|
24563
|
+
widened.moduleCeilings = Object.keys(ceilings).length > 0 ? ceilings : void 0;
|
|
24564
|
+
widened.sizeBudgets = Object.keys(sizeBudgets).length > 0 ? sizeBudgets : void 0;
|
|
24565
|
+
return widened;
|
|
24566
|
+
}
|
|
24567
|
+
function planHasWrites(plan) {
|
|
24568
|
+
return plan.ceilings.length > 0 || plan.sizes.length > 0 || plan.exemptions.length > 0;
|
|
24569
|
+
}
|
|
24570
|
+
// src/codebase-health/render.ts
|
|
24571
|
+
const GRAPH_METRIC_KEYS$1 = METRIC_KEYS.filter((key) => key !== "crowdedDirectories");
|
|
24572
|
+
const LABELS = {
|
|
24573
|
+
crowdedDirectories: "crowded directories",
|
|
24574
|
+
circularDependencies: "circular dependencies",
|
|
24575
|
+
fanInOutliers: "fan-in outliers",
|
|
24576
|
+
fanOutOutliers: "fan-out outliers",
|
|
24577
|
+
linesOfCode: "lines of code"
|
|
24578
|
+
};
|
|
24579
|
+
const CEILING_LABELS = {
|
|
24580
|
+
crowdedDirectories: "crowding",
|
|
24581
|
+
fanInOutliers: "fan-in",
|
|
24582
|
+
fanOutOutliers: "fan-out"
|
|
24583
|
+
};
|
|
24584
|
+
function formatMetricsSummary(metrics) {
|
|
24585
|
+
const lines = ["codebase health"];
|
|
24586
|
+
for (const key of METRIC_KEYS) {
|
|
24587
|
+
const value = metrics[key];
|
|
24588
|
+
if (value === void 0) continue;
|
|
24589
|
+
lines.push(` ${LABELS[key]}: ${value}`);
|
|
24590
|
+
}
|
|
24591
|
+
for (const key of OBSERVED_KEYS) {
|
|
24592
|
+
const value = metrics[key];
|
|
24593
|
+
if (value === void 0) continue;
|
|
24594
|
+
lines.push(` ${LABELS[key]}: ${value}`);
|
|
24595
|
+
}
|
|
24596
|
+
if (metrics.coverageNote) lines.push(metrics.coverageNote);
|
|
24597
|
+
return lines.join("\n");
|
|
24598
|
+
}
|
|
24599
|
+
function formatStatus(records) {
|
|
24600
|
+
if (records.length === 0) return "health: no history recorded yet.";
|
|
24601
|
+
const lines = ["health trend (oldest first):"];
|
|
24533
24602
|
for (const r of records) lines.push(` ${r.sha.slice(0, 7)} crowded=${r.crowdedDirectories}` + (r.circularDependencies === void 0 ? "" : ` cycles=${r.circularDependencies}`) + (r.linesOfCode === void 0 ? "" : ` loc=${r.linesOfCode}`));
|
|
24534
24603
|
return lines.join("\n");
|
|
24535
24604
|
}
|
|
@@ -24587,7 +24656,6 @@ function outlierAttributionLines(attribution, failedKeys) {
|
|
|
24587
24656
|
const lines = [];
|
|
24588
24657
|
let printedAttribution = false;
|
|
24589
24658
|
for (const o of attribution.newOutliers) {
|
|
24590
|
-
if (!failedKeys.has(o.key)) continue;
|
|
24591
24659
|
lines.push(` ${CEILING_LABELS[o.key]}: ${o.module} -- -> ${o.current} (new)`);
|
|
24592
24660
|
printedAttribution = true;
|
|
24593
24661
|
}
|
|
@@ -24635,12 +24703,12 @@ function formatCompareDiff(result, details, attribution) {
|
|
|
24635
24703
|
}
|
|
24636
24704
|
const failedKeys = new Set(result.metrics.filter((m) => m.pass === false).map((m) => m.key));
|
|
24637
24705
|
lines.push(...outlierAttributionLines(attribution, failedKeys));
|
|
24638
|
-
lines.push(result.pass ? "health: PASS" : "health: FAIL");
|
|
24706
|
+
lines.push(result.pass && attribution.newOutliers.length === 0 ? "health: PASS" : "health: FAIL");
|
|
24639
24707
|
return lines.join("\n");
|
|
24640
24708
|
}
|
|
24641
24709
|
function formatGraphUnavailable(baseline, details, graphMetricsEnabled, diagnostic) {
|
|
24642
24710
|
if (!graphMetricsEnabled || details.circularDependencies !== void 0) return void 0;
|
|
24643
|
-
const missing = GRAPH_METRIC_KEYS.filter((key) => baseline[key] !== void 0);
|
|
24711
|
+
const missing = GRAPH_METRIC_KEYS$1.filter((key) => baseline[key] !== void 0);
|
|
24644
24712
|
if (missing.length === 0) return void 0;
|
|
24645
24713
|
return [`health: the dependency graph was not measured this run, but the baseline records ${missing.map((key) => LABELS[key]).join(", ")}.`, ...diagnosticDetailLines(diagnostic)].join("\n");
|
|
24646
24714
|
}
|
|
@@ -24650,7 +24718,7 @@ function diagnosticDetailLines(diagnostic) {
|
|
|
24650
24718
|
}
|
|
24651
24719
|
function formatGraphUnavailableForSummary(details, graphMetricsEnabled, diagnostic) {
|
|
24652
24720
|
if (!graphMetricsEnabled || details.circularDependencies !== void 0) return void 0;
|
|
24653
|
-
return [`health: graph metrics unavailable this run (${GRAPH_METRIC_KEYS.map((key) => LABELS[key]).join(", ")}).`, ...diagnosticDetailLines(diagnostic)].join("\n");
|
|
24721
|
+
return [`health: graph metrics unavailable this run (${GRAPH_METRIC_KEYS$1.map((key) => LABELS[key]).join(", ")}).`, ...diagnosticDetailLines(diagnostic)].join("\n");
|
|
24654
24722
|
}
|
|
24655
24723
|
function formatStaleEntries(stale) {
|
|
24656
24724
|
return stale.map((entry) => {
|
|
@@ -24691,10 +24759,318 @@ function formatUnresolvedFirstParty(entries) {
|
|
|
24691
24759
|
lines.push(` An unresolved first-party import leaves the dependency graph, improving every health`, ` metric. Fix the import, or the resolve options that were supposed to follow it.`);
|
|
24692
24760
|
return lines.join("\n");
|
|
24693
24761
|
}
|
|
24762
|
+
function formatSlack(entries) {
|
|
24763
|
+
if (entries.length === 0) return [];
|
|
24764
|
+
const lines = [`slack: ${String(entries.length)} recorded ${entries.length === 1 ? "value" : "values"} above what this run measures. Run "pnpm exec bst health:tighten" to lower them.`];
|
|
24765
|
+
for (const entry of entries) {
|
|
24766
|
+
const suffix = slackSuffix(entry.kind);
|
|
24767
|
+
const from = entry.recorded ?? "--";
|
|
24768
|
+
const to = entry.measured ?? "--";
|
|
24769
|
+
lines.push(` ${entry.leaf} ${String(from)} -> ${String(to)} ${suffix}`);
|
|
24770
|
+
}
|
|
24771
|
+
return lines;
|
|
24772
|
+
}
|
|
24773
|
+
function slackSuffix(kind) {
|
|
24774
|
+
if (kind === "dead-ceiling") return "(dead ceiling)";
|
|
24775
|
+
if (kind === "uncapped") return "(uncapped)";
|
|
24776
|
+
return "(slack)";
|
|
24777
|
+
}
|
|
24694
24778
|
const CARRIED_RAISES_FIRST_LINE = "raises carried by this branch:";
|
|
24695
24779
|
function formatCarriedRaises(raises) {
|
|
24696
24780
|
return [CARRIED_RAISES_FIRST_LINE, ...raises.map((r) => ` ${r.leaf}: ${r.reference} -> ${r.current}`)].join("\n");
|
|
24697
24781
|
}
|
|
24782
|
+
// src/codebase-health/tighten.ts
|
|
24783
|
+
const GRAPH_METRIC_KEYS = new Set(METRIC_KEYS.filter((key) => key !== "crowdedDirectories"));
|
|
24784
|
+
function isGraphMetric(key) {
|
|
24785
|
+
return GRAPH_METRIC_KEYS.has(key);
|
|
24786
|
+
}
|
|
24787
|
+
function ceilingLeaf(key, module) {
|
|
24788
|
+
return `${CEILING_LABELS[key]}: ${module}`;
|
|
24789
|
+
}
|
|
24790
|
+
function copyCeilings(ceilings) {
|
|
24791
|
+
const copy = {};
|
|
24792
|
+
for (const key of RATCHETED_METRIC_KEYS) {
|
|
24793
|
+
const byModule = ceilings?.[key];
|
|
24794
|
+
if (byModule !== void 0) copy[key] = { ...byModule };
|
|
24795
|
+
}
|
|
24796
|
+
return copy;
|
|
24797
|
+
}
|
|
24798
|
+
function writeCeiling(ceilings, key, module, to) {
|
|
24799
|
+
const byModule = ceilings[key] ?? {};
|
|
24800
|
+
byModule[module] = to;
|
|
24801
|
+
ceilings[key] = byModule;
|
|
24802
|
+
}
|
|
24803
|
+
function dropCeiling(ceilings, key, module) {
|
|
24804
|
+
const byModule = ceilings[key];
|
|
24805
|
+
if (byModule === void 0) return;
|
|
24806
|
+
delete byModule[module];
|
|
24807
|
+
if (Object.keys(byModule).length === 0) delete ceilings[key];
|
|
24808
|
+
}
|
|
24809
|
+
function slackRecords(input) {
|
|
24810
|
+
const { comparison, attribution, baseline, graphMeasured } = input;
|
|
24811
|
+
const records = [];
|
|
24812
|
+
for (const key of METRIC_KEYS) {
|
|
24813
|
+
if (!graphMeasured && isGraphMetric(key)) continue;
|
|
24814
|
+
const recorded = baseline[key];
|
|
24815
|
+
const measured = comparison.metrics.find((metric) => metric.key === key)?.current;
|
|
24816
|
+
if (recorded === void 0 || measured === void 0) continue;
|
|
24817
|
+
if (measured >= recorded) continue;
|
|
24818
|
+
records.push({
|
|
24819
|
+
kind: "count",
|
|
24820
|
+
key,
|
|
24821
|
+
leaf: key,
|
|
24822
|
+
recorded,
|
|
24823
|
+
measured
|
|
24824
|
+
});
|
|
24825
|
+
}
|
|
24826
|
+
const measuredLeaves = new Set(comparison.ceilings.map((ceiling) => ceilingLeaf(ceiling.key, ceiling.module)));
|
|
24827
|
+
for (const ceiling of comparison.ceilings) {
|
|
24828
|
+
if (!graphMeasured && isGraphMetric(ceiling.key)) continue;
|
|
24829
|
+
if (ceiling.current >= ceiling.baseline) continue;
|
|
24830
|
+
records.push({
|
|
24831
|
+
kind: "ceiling",
|
|
24832
|
+
key: ceiling.key,
|
|
24833
|
+
module: ceiling.module,
|
|
24834
|
+
leaf: ceilingLeaf(ceiling.key, ceiling.module),
|
|
24835
|
+
recorded: ceiling.baseline,
|
|
24836
|
+
measured: ceiling.current
|
|
24837
|
+
});
|
|
24838
|
+
}
|
|
24839
|
+
for (const key of RATCHETED_METRIC_KEYS) {
|
|
24840
|
+
if (!graphMeasured && isGraphMetric(key)) continue;
|
|
24841
|
+
for (const [module, recorded] of Object.entries(baseline.moduleCeilings?.[key] ?? {})) {
|
|
24842
|
+
if (measuredLeaves.has(ceilingLeaf(key, module))) continue;
|
|
24843
|
+
records.push({
|
|
24844
|
+
kind: "dead-ceiling",
|
|
24845
|
+
key,
|
|
24846
|
+
module,
|
|
24847
|
+
leaf: ceilingLeaf(key, module),
|
|
24848
|
+
recorded
|
|
24849
|
+
});
|
|
24850
|
+
}
|
|
24851
|
+
}
|
|
24852
|
+
for (const outlier of [...attribution.baseOutliers, ...attribution.unattributedOutliers]) {
|
|
24853
|
+
if (!graphMeasured && isGraphMetric(outlier.key)) continue;
|
|
24854
|
+
records.push({
|
|
24855
|
+
kind: "uncapped",
|
|
24856
|
+
key: outlier.key,
|
|
24857
|
+
module: outlier.module,
|
|
24858
|
+
leaf: ceilingLeaf(outlier.key, outlier.module),
|
|
24859
|
+
measured: outlier.current
|
|
24860
|
+
});
|
|
24861
|
+
}
|
|
24862
|
+
for (const size of comparison.sizeResults) {
|
|
24863
|
+
const recorded = baseline.sizeBudgets?.[size.id];
|
|
24864
|
+
if (recorded === void 0 || size.measured === void 0) continue;
|
|
24865
|
+
const to = sizeRaiseValue(size.measured);
|
|
24866
|
+
if (recorded <= to) continue;
|
|
24867
|
+
records.push({
|
|
24868
|
+
kind: "size",
|
|
24869
|
+
id: size.id,
|
|
24870
|
+
leaf: `size: ${size.id}`,
|
|
24871
|
+
recorded,
|
|
24872
|
+
measured: size.measured,
|
|
24873
|
+
to
|
|
24874
|
+
});
|
|
24875
|
+
}
|
|
24876
|
+
return records;
|
|
24877
|
+
}
|
|
24878
|
+
function slackEntry(record) {
|
|
24879
|
+
if (record.kind === "uncapped") return {
|
|
24880
|
+
kind: record.kind,
|
|
24881
|
+
leaf: record.leaf,
|
|
24882
|
+
measured: record.measured
|
|
24883
|
+
};
|
|
24884
|
+
if (record.kind === "dead-ceiling") return {
|
|
24885
|
+
kind: record.kind,
|
|
24886
|
+
leaf: record.leaf,
|
|
24887
|
+
recorded: record.recorded
|
|
24888
|
+
};
|
|
24889
|
+
return {
|
|
24890
|
+
kind: record.kind,
|
|
24891
|
+
leaf: record.leaf,
|
|
24892
|
+
recorded: record.recorded,
|
|
24893
|
+
measured: record.measured
|
|
24894
|
+
};
|
|
24895
|
+
}
|
|
24896
|
+
function findSlack(input) {
|
|
24897
|
+
return slackRecords(input).map(slackEntry);
|
|
24898
|
+
}
|
|
24899
|
+
function planHealthTighten(input) {
|
|
24900
|
+
const ceilings = copyCeilings(input.baseline.moduleCeilings);
|
|
24901
|
+
const sizeBudgets = { ...input.baseline.sizeBudgets };
|
|
24902
|
+
const tightened = { ...input.baseline };
|
|
24903
|
+
const lowered = [];
|
|
24904
|
+
const removed = [];
|
|
24905
|
+
const caps = [];
|
|
24906
|
+
for (const record of slackRecords(input)) switch (record.kind) {
|
|
24907
|
+
case "count":
|
|
24908
|
+
tightened[record.key] = record.measured;
|
|
24909
|
+
lowered.push({
|
|
24910
|
+
leaf: record.leaf,
|
|
24911
|
+
from: record.recorded,
|
|
24912
|
+
to: record.measured
|
|
24913
|
+
});
|
|
24914
|
+
break;
|
|
24915
|
+
case "ceiling":
|
|
24916
|
+
writeCeiling(ceilings, record.key, record.module, record.measured);
|
|
24917
|
+
lowered.push({
|
|
24918
|
+
leaf: record.leaf,
|
|
24919
|
+
from: record.recorded,
|
|
24920
|
+
to: record.measured
|
|
24921
|
+
});
|
|
24922
|
+
break;
|
|
24923
|
+
case "dead-ceiling":
|
|
24924
|
+
dropCeiling(ceilings, record.key, record.module);
|
|
24925
|
+
removed.push({
|
|
24926
|
+
key: record.key,
|
|
24927
|
+
module: record.module,
|
|
24928
|
+
value: record.recorded
|
|
24929
|
+
});
|
|
24930
|
+
break;
|
|
24931
|
+
case "uncapped":
|
|
24932
|
+
writeCeiling(ceilings, record.key, record.module, record.measured);
|
|
24933
|
+
caps.push({
|
|
24934
|
+
key: record.key,
|
|
24935
|
+
module: record.module,
|
|
24936
|
+
value: record.measured
|
|
24937
|
+
});
|
|
24938
|
+
break;
|
|
24939
|
+
case "size":
|
|
24940
|
+
sizeBudgets[record.id] = record.to;
|
|
24941
|
+
lowered.push({
|
|
24942
|
+
leaf: record.leaf,
|
|
24943
|
+
from: record.recorded,
|
|
24944
|
+
to: record.to
|
|
24945
|
+
});
|
|
24946
|
+
}
|
|
24947
|
+
tightened.moduleCeilings = Object.keys(ceilings).length > 0 ? ceilings : void 0;
|
|
24948
|
+
tightened.sizeBudgets = Object.keys(sizeBudgets).length > 0 ? sizeBudgets : void 0;
|
|
24949
|
+
return {
|
|
24950
|
+
baseline: tightened,
|
|
24951
|
+
lowered,
|
|
24952
|
+
removed,
|
|
24953
|
+
caps
|
|
24954
|
+
};
|
|
24955
|
+
}
|
|
24956
|
+
// src/codebase-health/base-checkout.ts
|
|
24957
|
+
const TEMP_PREFIX = "bst-health-base-";
|
|
24958
|
+
function withMergeBaseCheckout(executor, targetDir, mergeBase, use) {
|
|
24959
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), TEMP_PREFIX));
|
|
24960
|
+
const tree = path.join(tmp, "tree");
|
|
24961
|
+
const index = path.join(tmp, "index");
|
|
24962
|
+
try {
|
|
24963
|
+
fs.mkdirSync(tree, { recursive: true });
|
|
24964
|
+
const gitDir = gitOutput(executor.exec("git", ["rev-parse", "--absolute-git-dir"], { cwd: targetDir }), "git rev-parse --absolute-git-dir").trim();
|
|
24965
|
+
const workRoot = gitOutput(executor.exec("git", ["rev-parse", "--show-toplevel"], { cwd: targetDir }), "git rev-parse --show-toplevel").trim();
|
|
24966
|
+
const intoCheckout = (args) => executor.exec("git", [
|
|
24967
|
+
`--git-dir=${gitDir}`,
|
|
24968
|
+
`--work-tree=${tree}`,
|
|
24969
|
+
...args
|
|
24970
|
+
], {
|
|
24971
|
+
cwd: tree,
|
|
24972
|
+
env: { GIT_INDEX_FILE: index }
|
|
24973
|
+
});
|
|
24974
|
+
gitOutput(intoCheckout(["read-tree", mergeBase]), `git read-tree ${mergeBase.slice(0, 12)}`);
|
|
24975
|
+
gitOutput(intoCheckout(["checkout-index", "-a"]), "git checkout-index -a");
|
|
24976
|
+
mirrorNodeModules(workRoot, tree);
|
|
24977
|
+
return use(tree);
|
|
24978
|
+
} finally {
|
|
24979
|
+
fs.rmSync(tmp, {
|
|
24980
|
+
recursive: true,
|
|
24981
|
+
force: true
|
|
24982
|
+
});
|
|
24983
|
+
}
|
|
24984
|
+
}
|
|
24985
|
+
function gitOutput(result, command) {
|
|
24986
|
+
if (result.exitCode === 0) return result.stdout;
|
|
24987
|
+
const detail = result.stderr.trim().split("\n")[0] ?? "";
|
|
24988
|
+
throw new TransientError(`${command} failed: ${detail === "" ? `exit ${String(result.exitCode)}` : detail}`);
|
|
24989
|
+
}
|
|
24990
|
+
function mirrorNodeModules(workingRoot, checkoutRoot) {
|
|
24991
|
+
mirrorTree(workingRoot, checkoutRoot, "");
|
|
24992
|
+
}
|
|
24993
|
+
function mirrorTree(workingRoot, checkoutRoot, rel) {
|
|
24994
|
+
mirrorEntries(path.join(workingRoot, rel, "node_modules"), path.join(checkoutRoot, rel, "node_modules"));
|
|
24995
|
+
let entries;
|
|
24996
|
+
try {
|
|
24997
|
+
entries = fs.readdirSync(path.join(checkoutRoot, rel), { withFileTypes: true });
|
|
24998
|
+
} catch (_error) {
|
|
24999
|
+
return;
|
|
25000
|
+
}
|
|
25001
|
+
for (const entry of entries) {
|
|
25002
|
+
if (!entry.isDirectory() || entry.isSymbolicLink()) continue;
|
|
25003
|
+
if (entry.name === ".git" || entry.name === "node_modules") continue;
|
|
25004
|
+
mirrorTree(workingRoot, checkoutRoot, path.join(rel, entry.name));
|
|
25005
|
+
}
|
|
25006
|
+
}
|
|
25007
|
+
function mirrorEntries(source, dest) {
|
|
25008
|
+
let entries;
|
|
25009
|
+
try {
|
|
25010
|
+
entries = fs.readdirSync(source, { withFileTypes: true });
|
|
25011
|
+
} catch (_error) {
|
|
25012
|
+
return;
|
|
25013
|
+
}
|
|
25014
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
25015
|
+
for (const entry of entries) {
|
|
25016
|
+
const src = path.join(source, entry.name);
|
|
25017
|
+
const target = path.join(dest, entry.name);
|
|
25018
|
+
if (entry.isSymbolicLink()) {
|
|
25019
|
+
const link = safeReadlink(src);
|
|
25020
|
+
if (link !== void 0 && !path.isAbsolute(link)) {
|
|
25021
|
+
linkRelative(link, target);
|
|
25022
|
+
continue;
|
|
25023
|
+
}
|
|
25024
|
+
} else if (entry.isDirectory() && entry.name.startsWith("@")) {
|
|
25025
|
+
mirrorEntries(src, target);
|
|
25026
|
+
continue;
|
|
25027
|
+
}
|
|
25028
|
+
try {
|
|
25029
|
+
fs.symlinkSync(src, target, entry.isDirectory() ? "dir" : "file");
|
|
25030
|
+
} catch (_error) {}
|
|
25031
|
+
}
|
|
25032
|
+
}
|
|
25033
|
+
function safeReadlink(file) {
|
|
25034
|
+
try {
|
|
25035
|
+
return fs.readlinkSync(file);
|
|
25036
|
+
} catch (_error) {
|
|
25037
|
+
return;
|
|
25038
|
+
}
|
|
25039
|
+
}
|
|
25040
|
+
function linkRelative(link, target) {
|
|
25041
|
+
try {
|
|
25042
|
+
fs.symlinkSync(link, target);
|
|
25043
|
+
} catch (_error) {}
|
|
25044
|
+
}
|
|
25045
|
+
// src/codebase-health/base-outliers.ts
|
|
25046
|
+
function unavailable(reason) {
|
|
25047
|
+
return {
|
|
25048
|
+
status: "unavailable",
|
|
25049
|
+
reason: firstLine(reason)
|
|
25050
|
+
};
|
|
25051
|
+
}
|
|
25052
|
+
function firstLine(text) {
|
|
25053
|
+
return text.trim().split("\n")[0] ?? "";
|
|
25054
|
+
}
|
|
25055
|
+
function measureBaseOutliers(opts) {
|
|
25056
|
+
const collect = opts.collect ?? collectDetails;
|
|
25057
|
+
try {
|
|
25058
|
+
return withMergeBaseCheckout(opts.executor, opts.targetDir, opts.mergeBase, (checkoutRoot) => {
|
|
25059
|
+
const baseTarget = path.join(checkoutRoot, opts.prefix);
|
|
25060
|
+
const collectConfig = buildCollectConfig(opts.config, { tsConfig: existsSync(path.join(baseTarget, "tsconfig.json")) ? "tsconfig.json" : void 0 });
|
|
25061
|
+
const details = collect(createRealHealthExecutor(baseTarget), collectConfig);
|
|
25062
|
+
const unresolved = details.unresolvedFirstParty;
|
|
25063
|
+
if (unresolved !== void 0 && unresolved.length > 0) return unavailable(`the base cruise could not resolve ${String(unresolved.length)} first-party imports`);
|
|
25064
|
+
if (opts.config.graphMetricsEnabled && details.circularDependencies === void 0) return unavailable("the base cruise produced no graph metrics");
|
|
25065
|
+
return {
|
|
25066
|
+
status: "measured",
|
|
25067
|
+
ceilings: ceilingsFromDetails(details)
|
|
25068
|
+
};
|
|
25069
|
+
});
|
|
25070
|
+
} catch (error) {
|
|
25071
|
+
return unavailable(describeError$1(error));
|
|
25072
|
+
}
|
|
25073
|
+
}
|
|
24698
25074
|
// src/codebase-health/size.ts
|
|
24699
25075
|
function byteLength(absolute) {
|
|
24700
25076
|
try {
|
|
@@ -24772,7 +25148,7 @@ function measureOne(targetDir, id, budget, options) {
|
|
|
24772
25148
|
};
|
|
24773
25149
|
}
|
|
24774
25150
|
// src/codebase-health/measure.ts
|
|
24775
|
-
const BASELINE_FILE = "health-baseline.json";
|
|
25151
|
+
const BASELINE_FILE$1 = "health-baseline.json";
|
|
24776
25152
|
function readTargetReference(executor, targetDir, out) {
|
|
24777
25153
|
const context = detectHealthContext(targetDir);
|
|
24778
25154
|
const read = readReference(executor, {
|
|
@@ -24794,7 +25170,7 @@ function assessRaises(executor, targetDir, current, out) {
|
|
|
24794
25170
|
if (read.kind === "unavailable") throw new FatalError(read.reason);
|
|
24795
25171
|
const reference = read.reference;
|
|
24796
25172
|
if (reference.baseline === void 0) {
|
|
24797
|
-
out.notice(`${BASELINE_FILE} has no counterpart on the default branch yet, so there is nothing to raise against.`);
|
|
25173
|
+
out.notice(`${BASELINE_FILE$1} has no counterpart on the default branch yet, so there is nothing to raise against.`);
|
|
24798
25174
|
return {
|
|
24799
25175
|
fields: {
|
|
24800
25176
|
reference: {
|
|
@@ -24860,7 +25236,7 @@ function measureHealth(targetDir, config, out, opts = {}) {
|
|
|
24860
25236
|
const ceilings = ceilingsFromDetails(details);
|
|
24861
25237
|
refuseUnresolvedImports(details);
|
|
24862
25238
|
refuseEmptyScope(details, config, opts.failOnEmptySrc, out);
|
|
24863
|
-
const baselinePath = path.join(targetDir, BASELINE_FILE);
|
|
25239
|
+
const baselinePath = path.join(targetDir, BASELINE_FILE$1);
|
|
24864
25240
|
const treeBaseline = existsSync(baselinePath) ? parseHealthBaseline(readFileSync(baselinePath, "utf-8")) : void 0;
|
|
24865
25241
|
const raiseAssessment = assessRaises(executor, targetDir, {
|
|
24866
25242
|
baseline: treeBaseline,
|
|
@@ -24952,7 +25328,7 @@ function assessSwitchOff(executor, targetDir, config, out) {
|
|
|
24952
25328
|
if (read.kind === "unavailable") return void 0;
|
|
24953
25329
|
const reference = read.reference;
|
|
24954
25330
|
if (!reference.health.enabled || reference.baseline === void 0) return void 0;
|
|
24955
|
-
const baselinePath = path.join(targetDir, BASELINE_FILE);
|
|
25331
|
+
const baselinePath = path.join(targetDir, BASELINE_FILE$1);
|
|
24956
25332
|
const treeBaseline = existsSync(baselinePath) ? parseHealthBaseline(readFileSync(baselinePath, "utf-8")) : void 0;
|
|
24957
25333
|
const named = healthOverridesAt(targetDir);
|
|
24958
25334
|
const limitsOver = { ...config };
|
|
@@ -24978,10 +25354,10 @@ function sizeValuesToRecord(baseline, sizes, reset) {
|
|
|
24978
25354
|
return Object.keys(recorded).length > 0 ? recorded : void 0;
|
|
24979
25355
|
}
|
|
24980
25356
|
function handleMissingBaseline(state, updateBaseline, failOnMissingBaseline) {
|
|
24981
|
-
const {
|
|
25357
|
+
const { targetDir, config, details, current, ceilings, sizes, out } = state;
|
|
24982
25358
|
if (updateBaseline === true) {
|
|
24983
25359
|
if (config.graphMetricsEnabled && details.circularDependencies === void 0) {
|
|
24984
|
-
out.notice(`Skipped baseline creation: graph metrics are unavailable this run. Fix the cruise before creating ${BASELINE_FILE}.`);
|
|
25360
|
+
out.notice(`Skipped baseline creation: graph metrics are unavailable this run. Fix the cruise before creating ${BASELINE_FILE$1}.`);
|
|
24985
25361
|
out.json({
|
|
24986
25362
|
status: "graph-unavailable",
|
|
24987
25363
|
...state.referenceFields,
|
|
@@ -24992,8 +25368,12 @@ function handleMissingBaseline(state, updateBaseline, failOnMissingBaseline) {
|
|
|
24992
25368
|
process.exitCode = 1;
|
|
24993
25369
|
return;
|
|
24994
25370
|
}
|
|
24995
|
-
|
|
24996
|
-
|
|
25371
|
+
writeHealthBaseline(targetDir, {
|
|
25372
|
+
...current,
|
|
25373
|
+
moduleCeilings: ceilings,
|
|
25374
|
+
sizeBudgets: sizeValuesToRecord(void 0, sizes, false)
|
|
25375
|
+
});
|
|
25376
|
+
out.notice(`Created ${BASELINE_FILE$1} (no prior baseline).`);
|
|
24997
25377
|
out.json({
|
|
24998
25378
|
status: "baseline-created",
|
|
24999
25379
|
...state.referenceFields,
|
|
@@ -25003,7 +25383,7 @@ function handleMissingBaseline(state, updateBaseline, failOnMissingBaseline) {
|
|
|
25003
25383
|
reportCarriedRaises(state.referenceFields.raises, out);
|
|
25004
25384
|
return;
|
|
25005
25385
|
}
|
|
25006
|
-
const message = `${BASELINE_FILE} not found. Run with --update-baseline to create one from the current run.`;
|
|
25386
|
+
const message = `${BASELINE_FILE$1} not found. Run with --update-baseline to create one from the current run.`;
|
|
25007
25387
|
if (failOnMissingBaseline === false) {
|
|
25008
25388
|
out.notice(message);
|
|
25009
25389
|
out.json({
|
|
@@ -25018,17 +25398,43 @@ function handleMissingBaseline(state, updateBaseline, failOnMissingBaseline) {
|
|
|
25018
25398
|
reportCarriedRaises(state.referenceFields.raises, out);
|
|
25019
25399
|
throw new FatalError(message);
|
|
25020
25400
|
}
|
|
25021
|
-
function
|
|
25022
|
-
const
|
|
25401
|
+
function adoptUnrecorded(planned, recorded, current, ceilings) {
|
|
25402
|
+
const written = { ...planned };
|
|
25403
|
+
for (const key of METRIC_KEYS) {
|
|
25404
|
+
const measured = current[key];
|
|
25405
|
+
if (written[key] === void 0 && measured !== void 0) written[key] = measured;
|
|
25406
|
+
}
|
|
25407
|
+
if (recorded.moduleCeilings === void 0) written.moduleCeilings = ceilings;
|
|
25408
|
+
return written;
|
|
25409
|
+
}
|
|
25410
|
+
function applyBaselineUpdate(state, existing, reset) {
|
|
25411
|
+
const { targetDir, config, details, current, ceilings, sizes, out } = state;
|
|
25412
|
+
const { baseline, result, attribution } = existing;
|
|
25023
25413
|
if (config.graphMetricsEnabled && details.circularDependencies === void 0) {
|
|
25024
25414
|
out.notice(`Skipped baseline update: graph metrics are unavailable this run. Fix the cruise before updating.`);
|
|
25025
25415
|
process.exitCode = 1;
|
|
25026
25416
|
} else if (reset === true) {
|
|
25027
|
-
|
|
25028
|
-
|
|
25417
|
+
writeHealthBaseline(targetDir, {
|
|
25418
|
+
...current,
|
|
25419
|
+
moduleCeilings: ceilings,
|
|
25420
|
+
sizeBudgets: sizeValuesToRecord(baseline, sizes, true)
|
|
25421
|
+
});
|
|
25422
|
+
out.notice(`Reset ${BASELINE_FILE$1} to the current run.`);
|
|
25029
25423
|
} else if (isFlatOrBetter(baseline, current, ceilings, sizes)) {
|
|
25030
|
-
|
|
25031
|
-
|
|
25424
|
+
if (attribution.newOutliers.length > 0) out.notice("Skipped baseline update: an outlier crossed a limit for the first time this run. Record it with \"health:raise\", which writes the ceiling beside the reason it was earned.");
|
|
25425
|
+
else {
|
|
25426
|
+
const plan = planHealthTighten({
|
|
25427
|
+
comparison: result,
|
|
25428
|
+
attribution,
|
|
25429
|
+
baseline,
|
|
25430
|
+
graphMeasured: config.graphMetricsEnabled
|
|
25431
|
+
});
|
|
25432
|
+
writeHealthBaseline(targetDir, {
|
|
25433
|
+
...adoptUnrecorded(plan.baseline, baseline, current, ceilings),
|
|
25434
|
+
sizeBudgets: sizeValuesToRecord(plan.baseline, sizes, false)
|
|
25435
|
+
});
|
|
25436
|
+
out.notice(`Updated ${BASELINE_FILE$1} (no regressions).`);
|
|
25437
|
+
}
|
|
25032
25438
|
} else out.notice(`Skipped baseline update: a metric or ceiling regressed. Fix the regression before updating.`);
|
|
25033
25439
|
}
|
|
25034
25440
|
function collectRegressions(result, details) {
|
|
@@ -25068,7 +25474,7 @@ const healthCheckCommand = defineCommand({
|
|
|
25068
25474
|
},
|
|
25069
25475
|
json: {
|
|
25070
25476
|
type: "boolean",
|
|
25071
|
-
description: "Emit one JSON document: status (compared | disabled | baseline-created | missing-baseline | graph-unavailable). disabled carries reference and raises only when the default branch has health enabled -- switching it off is a raise -- and nothing otherwise. Every other status carries reference ({status (read | no-baseline), mergeBase}) and raises ([{leaf, reference, current}]: every way this branch's two health files are higher than the default branch's, which it carries with its own code and a person merges). baseline-created, missing-baseline and graph-unavailable carry metrics ({crowdedDirectories, circularDependencies?, fanInOutliers?, fanOutOutliers?}) and sources. compared carries pass, tolerance, metrics (a list: [{key (crowdedDirectories | circularDependencies | fanInOutliers | fanOutOutliers), baseline?, current?, delta?, pass}]), ceilings ([{key (fanInOutliers | fanOutOutliers | crowdedDirectories), module, baseline, current, pass}]), sizeBudgets ([{id, ceiling?, measured?, pass, reason?}] -- every budget .tooling.json#health.sizeBudgets declares; reason is `unrecorded` for a declared budget with no recorded value, or the measurer's own explanation when it measured nothing), outlierBase ({status (measured | not-needed | unavailable), mergeBase?, reason?}), newOutliers ([{key, module, current}], outliers not on the merge base; empty unless measured), baseOutliers ([{key, module, base, current}]) and unattributedOutliers ([{key, module, current}], every outlier with no ceiling when the base was not measured), graphMetricsEnabled, graphMetricsMissing, staleEntries ([{kind (ceiling | exemption), metric, path, count?}]), regressions ({<failing metric key>: [{module, count} | {from, to}]}) and sources. sources is {entries ([{pattern, roots, status (resolved | unmatched | unrepresentable)}]), roots, fileCount}."
|
|
25477
|
+
description: "Emit one JSON document: status (compared | disabled | baseline-created | missing-baseline | graph-unavailable). disabled carries reference and raises only when the default branch has health enabled -- switching it off is a raise -- and nothing otherwise. Every other status carries reference ({status (read | no-baseline), mergeBase}) and raises ([{leaf, reference, current}]: every way this branch's two health files are higher than the default branch's, which it carries with its own code and a person merges). baseline-created, missing-baseline and graph-unavailable carry metrics ({crowdedDirectories, circularDependencies?, fanInOutliers?, fanOutOutliers?}) and sources. compared carries pass (false when newOutliers holds an entry, even with every count flat), tolerance, metrics (a list: [{key (crowdedDirectories | circularDependencies | fanInOutliers | fanOutOutliers), baseline?, current?, delta?, pass}]), ceilings ([{key (fanInOutliers | fanOutOutliers | crowdedDirectories), module, baseline, current, pass}]), sizeBudgets ([{id, ceiling?, measured?, pass, reason?}] -- every budget .tooling.json#health.sizeBudgets declares; reason is `unrecorded` for a declared budget with no recorded value, or the measurer's own explanation when it measured nothing), outlierBase ({status (measured | not-needed | unavailable), mergeBase?, reason?}), newOutliers ([{key, module, current}], outliers not on the merge base; empty unless measured), baseOutliers ([{key, module, base, current}]) and unattributedOutliers ([{key, module, current}], every outlier with no ceiling when the base was not measured), graphMetricsEnabled, graphMetricsMissing, slack ([{kind (count | ceiling | dead-ceiling | uncapped | size), leaf, recorded?, measured?}] -- every recorded value sitting above what this run measured, in the leaf spelling the failure lines print; information only, never a finding and never the verdict), staleEntries ([{kind (ceiling | exemption), metric, path, count?}]), regressions ({<failing metric key>: [{module, count} | {from, to}]}) and sources. sources is {entries ([{pattern, roots, status (resolved | unmatched | unrepresentable)}]), roots, fileCount}."
|
|
25072
25478
|
}
|
|
25073
25479
|
},
|
|
25074
25480
|
run({ args }) {
|
|
@@ -25088,7 +25494,7 @@ const healthCheckCommand = defineCommand({
|
|
|
25088
25494
|
if (!config.graphMetricsEnabled) out.notice("health: graph metrics disabled (no JS/TS source to cruise) -- crowdedDirectories only.");
|
|
25089
25495
|
const run = measureHealth(targetDir, config, out, { failOnEmptySrc: args["fail-on-empty-src"] });
|
|
25090
25496
|
const state = {
|
|
25091
|
-
|
|
25497
|
+
targetDir,
|
|
25092
25498
|
config,
|
|
25093
25499
|
details: run.details,
|
|
25094
25500
|
current: run.current,
|
|
@@ -25097,22 +25503,31 @@ const healthCheckCommand = defineCommand({
|
|
|
25097
25503
|
out,
|
|
25098
25504
|
referenceFields: run.referenceFields
|
|
25099
25505
|
};
|
|
25100
|
-
|
|
25506
|
+
const existing = run.existing;
|
|
25507
|
+
if (existing === void 0) {
|
|
25101
25508
|
handleMissingBaseline(state, args["update-baseline"], args["fail-on-missing-baseline"]);
|
|
25102
25509
|
return;
|
|
25103
25510
|
}
|
|
25104
|
-
const { baseline, result, attribution } =
|
|
25511
|
+
const { baseline, result, attribution } = existing;
|
|
25105
25512
|
out.text(formatCompareDiff(result, run.details, attribution));
|
|
25513
|
+
const slack = findSlack({
|
|
25514
|
+
comparison: result,
|
|
25515
|
+
attribution,
|
|
25516
|
+
baseline,
|
|
25517
|
+
graphMeasured: !(config.graphMetricsEnabled && run.details.circularDependencies === void 0)
|
|
25518
|
+
});
|
|
25519
|
+
for (const line of formatSlack(slack)) out.text(line);
|
|
25106
25520
|
reportCarriedRaises(run.referenceFields.raises, out);
|
|
25107
25521
|
const regressions = collectRegressions(result, run.details);
|
|
25108
25522
|
const graphUnavailable = formatGraphUnavailable(baseline, run.details, config.graphMetricsEnabled, run.details.graphDiagnostic);
|
|
25109
25523
|
if (graphUnavailable !== void 0) out.notice(graphUnavailable);
|
|
25110
25524
|
const stale = findStaleEntries(baseline, run.details, config.exempt);
|
|
25111
25525
|
for (const warning of formatStaleEntries(stale)) out.notice(warning);
|
|
25526
|
+
const verdictPasses = result.pass && attribution.newOutliers.length === 0;
|
|
25112
25527
|
out.json({
|
|
25113
25528
|
status: "compared",
|
|
25114
25529
|
...run.referenceFields,
|
|
25115
|
-
pass:
|
|
25530
|
+
pass: verdictPasses,
|
|
25116
25531
|
tolerance: result.tolerance,
|
|
25117
25532
|
metrics: result.metrics,
|
|
25118
25533
|
ceilings: result.ceilings,
|
|
@@ -25123,191 +25538,15 @@ const healthCheckCommand = defineCommand({
|
|
|
25123
25538
|
unattributedOutliers: attribution.unattributedOutliers,
|
|
25124
25539
|
graphMetricsEnabled: config.graphMetricsEnabled,
|
|
25125
25540
|
graphMetricsMissing: graphUnavailable !== void 0,
|
|
25541
|
+
slack,
|
|
25126
25542
|
staleEntries: stale,
|
|
25127
25543
|
regressions,
|
|
25128
25544
|
sources: run.details.sources
|
|
25129
25545
|
});
|
|
25130
|
-
if (args["update-baseline"] === true) applyBaselineUpdate(state,
|
|
25131
|
-
if (!
|
|
25546
|
+
if (args["update-baseline"] === true) applyBaselineUpdate(state, existing, args.reset);
|
|
25547
|
+
if (!verdictPasses || graphUnavailable !== void 0) process.exitCode = 1;
|
|
25132
25548
|
}
|
|
25133
25549
|
});
|
|
25134
|
-
// src/codebase-health/raise.ts
|
|
25135
|
-
const SIZE_RAISE_FACTOR = 1.01;
|
|
25136
|
-
function sizeRaiseValue(measured) {
|
|
25137
|
-
return Math.floor(measured * SIZE_RAISE_FACTOR) + 1;
|
|
25138
|
-
}
|
|
25139
|
-
const JsonObjectSchema = z.record(z.string(), z.unknown());
|
|
25140
|
-
const EXEMPT_LEAF_KEYS = [
|
|
25141
|
-
{
|
|
25142
|
-
prefix: "fan-in",
|
|
25143
|
-
key: "fanInOutliers"
|
|
25144
|
-
},
|
|
25145
|
-
{
|
|
25146
|
-
prefix: "fan-out",
|
|
25147
|
-
key: "fanOutOutliers"
|
|
25148
|
-
},
|
|
25149
|
-
{
|
|
25150
|
-
prefix: "crowding",
|
|
25151
|
-
key: "crowdedDirectories"
|
|
25152
|
-
}
|
|
25153
|
-
];
|
|
25154
|
-
function refuseDeniableReason(leaf, reason) {
|
|
25155
|
-
const fixed = fixText(`// ${reason}`, {
|
|
25156
|
-
offenders: resolveOffenders(),
|
|
25157
|
-
path: "health-raise.ts"
|
|
25158
|
-
});
|
|
25159
|
-
const refused = fixed.decisions.find((decision) => !decision.applied);
|
|
25160
|
-
if (refused !== void 0) throw new FatalError(`health:raise: the reason for --exempt "${leaf}" carries ${refused.hit.offender.codepoint} (${refused.hit.offender.name}): ${refused.reason ?? "this gate denies it"}. Rewrite it in ASCII.`);
|
|
25161
|
-
return fixed.text.slice(3);
|
|
25162
|
-
}
|
|
25163
|
-
function parseExemptLeaf(leaf) {
|
|
25164
|
-
const separator = leaf.indexOf(":");
|
|
25165
|
-
const prefix = separator < 0 ? "" : leaf.slice(0, separator).trim();
|
|
25166
|
-
const path = separator < 0 ? "" : leaf.slice(separator + 1).trim();
|
|
25167
|
-
if (prefix === "size") throw new FatalError(`health:raise: --exempt "${leaf}" names a size budget, which has no module to exempt. Run without --exempt: "health:raise" widens a grown size budget by measurement.`);
|
|
25168
|
-
const named = EXEMPT_LEAF_KEYS.find((entry) => entry.prefix === prefix);
|
|
25169
|
-
if (named === void 0 || path === "") throw new FatalError(`health:raise: --exempt "${leaf}" names no exemptable leaf. Pass one "health:check" printed: "fan-in: <path>", "fan-out: <path>", "crowding: <path>".`);
|
|
25170
|
-
return {
|
|
25171
|
-
key: named.key,
|
|
25172
|
-
path
|
|
25173
|
-
};
|
|
25174
|
-
}
|
|
25175
|
-
function copyCeilings(ceilings) {
|
|
25176
|
-
const copy = {};
|
|
25177
|
-
for (const key of RATCHETED_METRIC_KEYS) {
|
|
25178
|
-
const byModule = ceilings?.[key];
|
|
25179
|
-
if (byModule !== void 0) copy[key] = { ...byModule };
|
|
25180
|
-
}
|
|
25181
|
-
return copy;
|
|
25182
|
-
}
|
|
25183
|
-
function writeCeiling(ceilings, key, module, to) {
|
|
25184
|
-
const byModule = ceilings[key] ?? {};
|
|
25185
|
-
byModule[module] = to;
|
|
25186
|
-
ceilings[key] = byModule;
|
|
25187
|
-
}
|
|
25188
|
-
function headlineFor(baseline, comparison, key, exemptCount) {
|
|
25189
|
-
const measured = comparison.metrics.find((metric) => metric.key === key)?.current;
|
|
25190
|
-
if (measured === void 0) return void 0;
|
|
25191
|
-
const remaining = Math.max(0, measured - exemptCount);
|
|
25192
|
-
return baseline[key] === void 0 ? remaining : Math.max(baseline[key] ?? 0, remaining);
|
|
25193
|
-
}
|
|
25194
|
-
function exemptionWrites(input) {
|
|
25195
|
-
const writes = [];
|
|
25196
|
-
const notes = [];
|
|
25197
|
-
for (const request of input.exemptions) {
|
|
25198
|
-
const parsed = parseExemptLeaf(request.leaf);
|
|
25199
|
-
if (parsed === void 0) continue;
|
|
25200
|
-
const recorded = input.config.exempt[parsed.key]?.[parsed.path];
|
|
25201
|
-
if (recorded !== void 0) {
|
|
25202
|
-
notes.push(`health.exempt.${parsed.key}.${parsed.path} already reads "${recorded}"; the reason was not overwritten.`);
|
|
25203
|
-
continue;
|
|
25204
|
-
}
|
|
25205
|
-
writes.push({
|
|
25206
|
-
key: parsed.key,
|
|
25207
|
-
path: parsed.path,
|
|
25208
|
-
reason: refuseDeniableReason(request.leaf, request.reason)
|
|
25209
|
-
});
|
|
25210
|
-
}
|
|
25211
|
-
return {
|
|
25212
|
-
writes,
|
|
25213
|
-
notes
|
|
25214
|
-
};
|
|
25215
|
-
}
|
|
25216
|
-
function objectAt(parent, key, where) {
|
|
25217
|
-
const existing = parent[key];
|
|
25218
|
-
if (existing === void 0) return {};
|
|
25219
|
-
const parsed = JsonObjectSchema.safeParse(existing);
|
|
25220
|
-
if (!parsed.success) throw new FatalError(`health:raise: ${where}#${key} is not an object, so an exemption cannot be written there.`);
|
|
25221
|
-
return { ...parsed.data };
|
|
25222
|
-
}
|
|
25223
|
-
function applyExemptions(tooling, writes) {
|
|
25224
|
-
if (writes.length === 0) return void 0;
|
|
25225
|
-
const file = JsonObjectSchema.safeParse(tooling ?? {});
|
|
25226
|
-
if (!file.success) throw new FatalError(`health:raise: .tooling.json is not a JSON object, so no exemption can be written.`);
|
|
25227
|
-
const result = { ...file.data };
|
|
25228
|
-
for (const write of writes) {
|
|
25229
|
-
const health = objectAt(result, "health", ".tooling.json");
|
|
25230
|
-
const exempt = objectAt(health, "exempt", ".tooling.json#health");
|
|
25231
|
-
const table = objectAt(exempt, write.key, ".tooling.json#health.exempt");
|
|
25232
|
-
table[write.path] = write.reason;
|
|
25233
|
-
exempt[write.key] = table;
|
|
25234
|
-
health["exempt"] = exempt;
|
|
25235
|
-
result["health"] = health;
|
|
25236
|
-
}
|
|
25237
|
-
return result;
|
|
25238
|
-
}
|
|
25239
|
-
function planHealthRaise(input) {
|
|
25240
|
-
const ceilings = copyCeilings(input.baseline.moduleCeilings);
|
|
25241
|
-
const ceilingWrites = [];
|
|
25242
|
-
const headlines = {};
|
|
25243
|
-
const notes = [];
|
|
25244
|
-
const exemptions = exemptionWrites(input);
|
|
25245
|
-
notes.push(...exemptions.notes);
|
|
25246
|
-
const isExcused = (key, module) => exemptions.writes.some((write) => write.key === key && exemptKeyMatcher(write.path)(module));
|
|
25247
|
-
const exemptedCount = /* @__PURE__ */ new Map();
|
|
25248
|
-
const countExcused = (key, module) => {
|
|
25249
|
-
if (isExcused(key, module)) exemptedCount.set(key, (exemptedCount.get(key) ?? 0) + 1);
|
|
25250
|
-
};
|
|
25251
|
-
for (const outlier of input.attribution.newOutliers) countExcused(outlier.key, outlier.module);
|
|
25252
|
-
for (const ceiling of input.comparison.ceilings) if (!ceiling.pass) countExcused(ceiling.key, ceiling.module);
|
|
25253
|
-
const outlierBase = input.attribution.outlierBase;
|
|
25254
|
-
if (outlierBase.status === "unavailable") notes.push(`no "(new)" ceiling was written: the merge base ${outlierBase.mergeBase} could not be measured (${outlierBase.reason}), so nothing could be called a first crossing.`);
|
|
25255
|
-
for (const outlier of input.attribution.newOutliers) {
|
|
25256
|
-
if (isExcused(outlier.key, outlier.module)) continue;
|
|
25257
|
-
writeCeiling(ceilings, outlier.key, outlier.module, outlier.current);
|
|
25258
|
-
const headline = headlineFor(input.baseline, input.comparison, outlier.key, exemptedCount.get(outlier.key) ?? 0);
|
|
25259
|
-
if (headline !== void 0) headlines[outlier.key] = headline;
|
|
25260
|
-
ceilingWrites.push({
|
|
25261
|
-
key: outlier.key,
|
|
25262
|
-
module: outlier.module,
|
|
25263
|
-
value: outlier.current,
|
|
25264
|
-
...headline === void 0 ? {} : { headline }
|
|
25265
|
-
});
|
|
25266
|
-
}
|
|
25267
|
-
for (const ceiling of input.comparison.ceilings) {
|
|
25268
|
-
if (ceiling.pass) continue;
|
|
25269
|
-
if (isExcused(ceiling.key, ceiling.module)) continue;
|
|
25270
|
-
writeCeiling(ceilings, ceiling.key, ceiling.module, ceiling.current);
|
|
25271
|
-
ceilingWrites.push({
|
|
25272
|
-
key: ceiling.key,
|
|
25273
|
-
module: ceiling.module,
|
|
25274
|
-
value: ceiling.current
|
|
25275
|
-
});
|
|
25276
|
-
}
|
|
25277
|
-
const sizeBudgets = { ...input.baseline.sizeBudgets };
|
|
25278
|
-
const sizeWrites = [];
|
|
25279
|
-
for (const size of input.comparison.sizeResults) {
|
|
25280
|
-
if (size.pass || size.measured === void 0 || size.ceiling === void 0) continue;
|
|
25281
|
-
if (size.measured <= size.ceiling) continue;
|
|
25282
|
-
const value = sizeRaiseValue(size.measured);
|
|
25283
|
-
sizeBudgets[size.id] = value;
|
|
25284
|
-
sizeWrites.push({
|
|
25285
|
-
id: size.id,
|
|
25286
|
-
value
|
|
25287
|
-
});
|
|
25288
|
-
}
|
|
25289
|
-
return {
|
|
25290
|
-
baseline: widenedBaseline(input.baseline, headlines, ceilings, sizeBudgets),
|
|
25291
|
-
tooling: applyExemptions(input.tooling, exemptions.writes),
|
|
25292
|
-
ceilings: ceilingWrites,
|
|
25293
|
-
sizes: sizeWrites,
|
|
25294
|
-
exemptions: exemptions.writes,
|
|
25295
|
-
notes
|
|
25296
|
-
};
|
|
25297
|
-
}
|
|
25298
|
-
function widenedBaseline(baseline, headlines, ceilings, sizeBudgets) {
|
|
25299
|
-
const widened = { ...baseline };
|
|
25300
|
-
for (const key of METRIC_KEYS) {
|
|
25301
|
-
const headline = headlines[key];
|
|
25302
|
-
if (headline !== void 0) widened[key] = headline;
|
|
25303
|
-
}
|
|
25304
|
-
widened.moduleCeilings = Object.keys(ceilings).length > 0 ? ceilings : void 0;
|
|
25305
|
-
widened.sizeBudgets = Object.keys(sizeBudgets).length > 0 ? sizeBudgets : void 0;
|
|
25306
|
-
return widened;
|
|
25307
|
-
}
|
|
25308
|
-
function planHasWrites(plan) {
|
|
25309
|
-
return plan.ceilings.length > 0 || plan.sizes.length > 0 || plan.exemptions.length > 0;
|
|
25310
|
-
}
|
|
25311
25550
|
// src/commands/health-raise.ts
|
|
25312
25551
|
const JsonValueSchema = z.json();
|
|
25313
25552
|
const TOOLING_FILE = ".tooling.json";
|
|
@@ -25321,13 +25560,6 @@ function collectExemptPairs(rawArgs) {
|
|
|
25321
25560
|
reason: reasons[index] ?? ""
|
|
25322
25561
|
}));
|
|
25323
25562
|
}
|
|
25324
|
-
function formatterFor(targetDir) {
|
|
25325
|
-
const detected = computeDefaults(targetDir);
|
|
25326
|
-
return createContentFormatter({
|
|
25327
|
-
targetDir,
|
|
25328
|
-
formatter: loadToolingConfig(targetDir)?.formatter ?? detected.formatter
|
|
25329
|
-
});
|
|
25330
|
-
}
|
|
25331
25563
|
function readToolingFile(targetDir) {
|
|
25332
25564
|
const full = path.join(targetDir, TOOLING_FILE);
|
|
25333
25565
|
if (!existsSync(full)) return void 0;
|
|
@@ -25343,7 +25575,7 @@ function readToolingFile(targetDir) {
|
|
|
25343
25575
|
if (!parsed.success) throw new FatalError(`health:raise: ${TOOLING_FILE} is not JSON: ${parsed.error.message}`);
|
|
25344
25576
|
return parsed.data;
|
|
25345
25577
|
}
|
|
25346
|
-
function describePlan(plan) {
|
|
25578
|
+
function describePlan$1(plan) {
|
|
25347
25579
|
const lines = [];
|
|
25348
25580
|
for (const ceiling of plan.ceilings) {
|
|
25349
25581
|
const headline = ceiling.headline === void 0 ? "" : `, ${ceiling.key} set to ${String(ceiling.headline)}`;
|
|
@@ -25407,7 +25639,7 @@ const healthRaiseCommand = defineCommand({
|
|
|
25407
25639
|
});
|
|
25408
25640
|
const dryRun = args["dry-run"] === true;
|
|
25409
25641
|
const wrote = dryRun ? [] : writePlan(targetDir, plan);
|
|
25410
|
-
for (const line of describePlan(plan)) out.text(line);
|
|
25642
|
+
for (const line of describePlan$1(plan)) out.text(line);
|
|
25411
25643
|
out.json({
|
|
25412
25644
|
status: planHasWrites(plan) ? "raised" : "nothing-to-raise",
|
|
25413
25645
|
dryRun,
|
|
@@ -25421,18 +25653,97 @@ const healthRaiseCommand = defineCommand({
|
|
|
25421
25653
|
}
|
|
25422
25654
|
});
|
|
25423
25655
|
function writePlan(targetDir, plan) {
|
|
25424
|
-
const format = formatterFor(targetDir);
|
|
25425
25656
|
const wrote = [];
|
|
25426
25657
|
if (plan.ceilings.length > 0 || plan.sizes.length > 0) {
|
|
25427
|
-
|
|
25658
|
+
writeHealthBaseline(targetDir, plan.baseline);
|
|
25428
25659
|
wrote.push("health-baseline.json");
|
|
25429
25660
|
}
|
|
25430
25661
|
if (plan.tooling !== void 0) {
|
|
25662
|
+
const format = healthFileFormatter(targetDir);
|
|
25431
25663
|
writeFileSync(path.join(targetDir, TOOLING_FILE), format(TOOLING_FILE, JSON.stringify(plan.tooling, null, 2)));
|
|
25432
25664
|
wrote.push(TOOLING_FILE);
|
|
25433
25665
|
}
|
|
25434
25666
|
return wrote;
|
|
25435
25667
|
}
|
|
25668
|
+
// src/commands/health-tighten.ts
|
|
25669
|
+
const BASELINE_FILE = "health-baseline.json";
|
|
25670
|
+
function describePlan(plan) {
|
|
25671
|
+
const lines = [];
|
|
25672
|
+
for (const lowering of plan.lowered) lines.push(`health-baseline: ${lowering.leaf} ${String(lowering.from)} -> ${String(lowering.to)}`);
|
|
25673
|
+
for (const removal of plan.removed) lines.push(`health-baseline: ${removal.key}: ${removal.module} ceiling ${String(removal.value)} removed`);
|
|
25674
|
+
for (const cap of plan.caps) lines.push(`health-baseline: ${cap.key}: ${cap.module} capped at ${String(cap.value)}`);
|
|
25675
|
+
return lines;
|
|
25676
|
+
}
|
|
25677
|
+
const healthTightenCommand = defineCommand({
|
|
25678
|
+
meta: {
|
|
25679
|
+
name: "health:tighten",
|
|
25680
|
+
description: "Shed the slack this branch's own measurement proved the baseline holds, by measurement: no number is an argument. Rewrites health-baseline.json with each recorded count and module ceiling lowered to what the run measured, dead ceilings removed, and current outliers capped; it never touches .tooling.json. Does nothing unless .tooling.json#health.enabled is true."
|
|
25681
|
+
},
|
|
25682
|
+
args: {
|
|
25683
|
+
dir: {
|
|
25684
|
+
type: "positional",
|
|
25685
|
+
valueHint: "dir",
|
|
25686
|
+
description: "Project directory (default: current directory)",
|
|
25687
|
+
required: false
|
|
25688
|
+
},
|
|
25689
|
+
"dry-run": {
|
|
25690
|
+
type: "boolean",
|
|
25691
|
+
description: "Print what would be written and write nothing"
|
|
25692
|
+
},
|
|
25693
|
+
json: {
|
|
25694
|
+
type: "boolean",
|
|
25695
|
+
description: "Emit one JSON document: status (tightened | nothing-to-tighten | disabled | graph-unavailable), dryRun, wrote ([path]), lowered ([{leaf, from, to}]), removed ([{key, module, value}]), caps ([{key, module, value}]), reference ({status (read | no-baseline), mergeBase}). disabled and graph-unavailable carry no writes."
|
|
25696
|
+
}
|
|
25697
|
+
},
|
|
25698
|
+
run({ args }) {
|
|
25699
|
+
const targetDir = path.resolve(args.dir ?? ".");
|
|
25700
|
+
const out = createCliOutput(args.json === true);
|
|
25701
|
+
const dryRun = args["dry-run"] === true;
|
|
25702
|
+
const config = resolveHealthConfig(targetDir);
|
|
25703
|
+
if (!config.enabled) {
|
|
25704
|
+
out.notice("health: disabled (set .tooling.json#health.enabled to true to enable).");
|
|
25705
|
+
out.json({
|
|
25706
|
+
status: "disabled",
|
|
25707
|
+
dryRun
|
|
25708
|
+
});
|
|
25709
|
+
return;
|
|
25710
|
+
}
|
|
25711
|
+
const run = measureHealth(targetDir, config, out);
|
|
25712
|
+
if (run.existing === void 0) throw new FatalError(`health:tighten: no ${BASELINE_FILE} to lower. Run "health:check --update-baseline" first: a tighten lowers a recorded number, and there is nothing recorded.`);
|
|
25713
|
+
if (config.graphMetricsEnabled && run.details.circularDependencies === void 0) {
|
|
25714
|
+
out.notice(`Skipped: graph metrics are unavailable this run. Fix the cruise before tightening ${BASELINE_FILE}.`);
|
|
25715
|
+
out.json({
|
|
25716
|
+
status: "graph-unavailable",
|
|
25717
|
+
dryRun,
|
|
25718
|
+
wrote: []
|
|
25719
|
+
});
|
|
25720
|
+
process.exitCode = 1;
|
|
25721
|
+
return;
|
|
25722
|
+
}
|
|
25723
|
+
const plan = planHealthTighten({
|
|
25724
|
+
comparison: run.existing.result,
|
|
25725
|
+
attribution: run.existing.attribution,
|
|
25726
|
+
baseline: run.existing.baseline,
|
|
25727
|
+
graphMeasured: config.graphMetricsEnabled
|
|
25728
|
+
});
|
|
25729
|
+
const hasWrites = plan.lowered.length > 0 || plan.removed.length > 0 || plan.caps.length > 0;
|
|
25730
|
+
const wrote = [];
|
|
25731
|
+
if (hasWrites && !dryRun) {
|
|
25732
|
+
writeHealthBaseline(targetDir, plan.baseline);
|
|
25733
|
+
wrote.push(BASELINE_FILE);
|
|
25734
|
+
}
|
|
25735
|
+
for (const line of describePlan(plan)) out.text(line);
|
|
25736
|
+
out.json({
|
|
25737
|
+
status: hasWrites ? "tightened" : "nothing-to-tighten",
|
|
25738
|
+
dryRun,
|
|
25739
|
+
wrote,
|
|
25740
|
+
lowered: plan.lowered,
|
|
25741
|
+
removed: plan.removed,
|
|
25742
|
+
caps: plan.caps,
|
|
25743
|
+
reference: run.referenceFields.reference
|
|
25744
|
+
});
|
|
25745
|
+
}
|
|
25746
|
+
});
|
|
25436
25747
|
// src/codebase-health/module-report.ts
|
|
25437
25748
|
function normalizeModulePath(raw) {
|
|
25438
25749
|
let normalized = raw.replace(/\\/g, "/");
|
|
@@ -25518,7 +25829,7 @@ function formatModuleReports(reports) {
|
|
|
25518
25829
|
}
|
|
25519
25830
|
return lines.join("\n");
|
|
25520
25831
|
}
|
|
25521
|
-
// src/commands/health-
|
|
25832
|
+
// src/commands/health-summary.ts
|
|
25522
25833
|
function readCoverageNote(targetDir) {
|
|
25523
25834
|
const file = path.join(targetDir, "coverage-baseline.json");
|
|
25524
25835
|
if (!existsSync(file)) return void 0;
|
|
@@ -25529,7 +25840,6 @@ function readCoverageNote(targetDir) {
|
|
|
25529
25840
|
return;
|
|
25530
25841
|
}
|
|
25531
25842
|
}
|
|
25532
|
-
// src/commands/health-summary.ts
|
|
25533
25843
|
function readModuleCeilings(targetDir) {
|
|
25534
25844
|
const file = path.join(targetDir, "health-baseline.json");
|
|
25535
25845
|
if (!existsSync(file)) return void 0;
|
|
@@ -29767,7 +30077,7 @@ async function runCli(config) {
|
|
|
29767
30077
|
// src/cli-main.ts
|
|
29768
30078
|
setLogLevel(resolveLogLevel({}));
|
|
29769
30079
|
setForgejoLogger(log$1);
|
|
29770
|
-
const displayVersion = "0.
|
|
30080
|
+
const displayVersion = "0.103.0";
|
|
29771
30081
|
const bstSubCommands = {
|
|
29772
30082
|
"repo:sync": syncCommand,
|
|
29773
30083
|
"checks:run": runChecksCommand,
|
|
@@ -29798,6 +30108,7 @@ const bstSubCommands = {
|
|
|
29798
30108
|
"coverage:status": coverageStatusCommand,
|
|
29799
30109
|
"health:check": healthCheckCommand,
|
|
29800
30110
|
"health:raise": healthRaiseCommand,
|
|
30111
|
+
"health:tighten": healthTightenCommand,
|
|
29801
30112
|
"health:summary": healthSummaryCommand,
|
|
29802
30113
|
"health:record": healthRecordCommand,
|
|
29803
30114
|
"health:status": healthStatusCommand,
|