@behavioral-agentic-design-system/core 0.32.1 → 0.36.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@behavioral-agentic-design-system/core",
3
- "version": "0.32.1",
3
+ "version": "0.36.0",
4
4
  "description": "BADS core — tokens, shadcn/ui components, and the BADS template shell (app routes, customize tab, theme hooks). Forks consume this and re-export, keeping client repos to ~30 lines of glue.",
5
5
  "license": "MIT",
6
6
  "author": "Matthew Stephens <work@matthewstephens.com> (https://github.com/matthewlarn)",
@@ -36,16 +36,22 @@
36
36
  "README.md"
37
37
  ],
38
38
  "bin": {
39
- "bads-build-tokens": "scripts/build-tokens.cjs",
40
- "bads-build-fonts": "scripts/build-fonts.cjs",
41
- "bads-sync": "scripts/bads-sync.mjs",
42
39
  "bads-a11y-lint": "scripts/a11y-lint.cjs",
43
- "bads-wcag-audit": "scripts/wcag-audit.cjs",
40
+ "bads-build-fonts": "scripts/build-fonts.cjs",
41
+ "bads-build-tokens": "scripts/build-tokens.cjs",
44
42
  "bads-check-stories": "scripts/check-stories.mjs",
43
+ "bads-check-sync": "scripts/check-sync.mjs",
44
+ "bads-doctor": "scripts/bads-doctor.mjs",
45
45
  "bads-fix-stories": "scripts/fix-stories.mjs",
46
46
  "bads-generate-stories": "scripts/generate-stories.cjs",
47
+ "bads-health-report": "scripts/health-report.mjs",
48
+ "bads-lint-ethics": "scripts/lint-ethics-contract.mjs",
49
+ "bads-lint-slop": "scripts/lint-slop.mjs",
50
+ "bads-lint-token-intent": "scripts/lint-token-intent.mjs",
47
51
  "bads-oklch-to-hex": "scripts/oklch-to-hex.cjs",
48
- "bads-size-audit": "scripts/size-audit.cjs"
52
+ "bads-size-audit": "scripts/size-audit.cjs",
53
+ "bads-sync": "scripts/bads-sync.mjs",
54
+ "bads-wcag-audit": "scripts/wcag-audit.cjs"
49
55
  },
50
56
  "exports": {
51
57
  ".": "./src/index.ts",
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * bads-doctor — one umbrella pass/fail summary across BADS' quality checks.
4
+ *
5
+ * WHY THIS EXISTS: BADS ships as the npm package
6
+ * @behavioral-agentic-design-system/core to client forks and prototype
7
+ * repos. The package publishes CLI bins, but only some of them are QUALITY
8
+ * CHECKS (a11y-lint, wcag-audit, check-stories, size-audit, plus three
9
+ * advisory lints below) — the rest are generators/fixers (build-tokens,
10
+ * fix-stories, oklch-to-hex, bads-sync, ...) that mutate files and must
11
+ * never be run by a health check. Today a fork (or an agent working inside
12
+ * one) has to know each check bin's name and run them one at a time,
13
+ * reading different output formats. This command wraps the checks and
14
+ * prints one compact table, because noisy per-tool output is how lint
15
+ * fatigue starts (people stop reading it) — the summary table is the point
16
+ * of this file, not a side effect.
17
+ *
18
+ * This is a PURE ADDITIVE WRAPPER: it does not change what any of the
19
+ * checks does, what it scans, or its own exit code when run directly. It
20
+ * just runs them in-process and reports on what happened.
21
+ *
22
+ * SHIPS IN THE PUBLISHED NPM PACKAGE — this file must not import anything
23
+ * from outside packages/core/. Node builtins only, no dependencies.
24
+ *
25
+ * Siblings are resolved by path relative to this file (not by assuming the
26
+ * other bins are linked onto PATH) because a consumer running
27
+ * `npx bads-doctor` may not have bads-a11y-lint etc. resolvable on PATH,
28
+ * and a fork's root package.json won't have BADS's own script names to
29
+ * shell out to via pnpm.
30
+ *
31
+ * The three advisory lints (token-intent, slop, ethics-contract) are
32
+ * ADVISORY BY HOUSE RULE — informational signal, never a merge gate here.
33
+ * They're marked `advisory: true` below rather than invoked with a
34
+ * per-script warn flag because the three scripts don't share one flag
35
+ * convention (lint-token-intent is advisory unless you pass --strict;
36
+ * lint-slop needs --warn to become advisory; lint-ethics-contract has no
37
+ * advisory flag at all — it's a hard pre-commit/CI gate elsewhere in the
38
+ * repo). The `advisory` marker is the one mechanism that works uniformly
39
+ * across all three: it renders their failures as a `warn` row and excludes
40
+ * them from the pass/fail tally, without needing each script to expose a
41
+ * flag bads-doctor can rely on.
42
+ *
43
+ * health-report.mjs is deliberately NOT included — it's a report generator
44
+ * (writes ledgers/reports/health-<YYYY-MM>.json and always "succeeds"), not
45
+ * a pass/fail check, so it doesn't belong in this CHECKS list.
46
+ *
47
+ * Usage:
48
+ * bads-doctor run all checks, print summary
49
+ * bads-doctor --verbose | -v also print each check's full output
50
+ * bads-doctor --warn always exit 0 (advisory mode)
51
+ * bads-doctor --only=<name> run just one check
52
+ * bads-doctor --help show this usage
53
+ */
54
+
55
+ import { spawnSync } from "node:child_process";
56
+ import { existsSync } from "node:fs";
57
+ import { dirname, join } from "node:path";
58
+ import { fileURLToPath } from "node:url";
59
+
60
+ const __dirname = dirname(fileURLToPath(import.meta.url));
61
+
62
+ // The CHECK bins only. Generators/fixers (build-tokens, build-fonts,
63
+ // bads-sync, fix-stories, generate-stories, oklch-to-hex) are deliberately
64
+ // excluded — running them here would mutate a consumer's tree. Same for
65
+ // health-report.mjs (a report generator, not a pass/fail check).
66
+ const CHECKS = [
67
+ { name: "a11y-lint", script: "a11y-lint.cjs", args: [] },
68
+ { name: "wcag-audit", script: "wcag-audit.cjs", args: [] },
69
+ // --all: a doctor run audits the whole tree, not just what's staged
70
+ // (the bare `check:stories` precommit mode reads `git diff --cached` and
71
+ // would trivially "pass" with nothing staged).
72
+ { name: "check-stories", script: "check-stories.mjs", args: ["--all"] },
73
+ { name: "size-audit", script: "size-audit.cjs", args: [] },
74
+ // --strict: without it, lint-token-intent always exits 0 and the doctor
75
+ // would have no real signal to report. `advisory: true` is what keeps this
76
+ // from ever failing the doctor run — see the file-header note above.
77
+ { name: "lint-token-intent", script: "lint-token-intent.mjs", args: ["--strict"], advisory: true },
78
+ { name: "lint-slop", script: "lint-slop.mjs", args: [], advisory: true },
79
+ { name: "lint-ethics", script: "lint-ethics-contract.mjs", args: [], advisory: true },
80
+ ];
81
+
82
+ function printHelp() {
83
+ console.log(`bads-doctor — run BADS' quality checks and print one pass/fail summary
84
+
85
+ Usage:
86
+ bads-doctor [options]
87
+
88
+ Runs, in order:
89
+ a11y-lint static a11y scan (hardcoded hex, missing alt, unlabeled icon buttons, ...)
90
+ wcag-audit token contrast audit vs WCAG AAA (7:1 / 4.5:1 / 3:1)
91
+ check-stories Storybook coverage rule, full-repo audit (--all)
92
+ size-audit CTA size contract, rule BADS-2 (text-xs CTAs without the escape hatch)
93
+ lint-token-intent [advisory] status-token/copy mismatches + muted-on-heading (BADS-INTENT-1/2)
94
+ lint-slop [advisory] AI-slop visual tics — gradients, springy hovers, oversized shadows (BADS-SLOP-1..6)
95
+ lint-ethics [advisory] registry ethicsContract completeness (data-entry primitives, retention, consent)
96
+
97
+ [advisory] checks report findings in the table but never fail the doctor run or its exit code —
98
+ they're informational by house rule, distinct from the four blocking checks above.
99
+
100
+ Options:
101
+ --verbose, -v print each check's full captured output before the summary table
102
+ --warn always exit 0, even if a blocking check fails (advisory mode)
103
+ --only=<name> run just one check: a11y-lint, wcag-audit, check-stories, size-audit,
104
+ lint-token-intent, lint-slop, lint-ethics
105
+ --help show this usage and exit
106
+ `);
107
+ }
108
+
109
+ function extractDetail(name, output) {
110
+ // Grep a known summary-shaped line out of each check's real output.
111
+ // Never invent a number — if nothing matches, leave the detail blank.
112
+ if (name === "wcag-audit") {
113
+ const m = output.match(/^(\d+) pass · (\d+) fail ·/m);
114
+ return m ? `${m[1]} pass · ${m[2]} fail` : "";
115
+ }
116
+ if (name === "a11y-lint") {
117
+ const m = output.match(/^(\d+ issues? across \d+ files?)\.$/m);
118
+ return m ? m[1] : "";
119
+ }
120
+ if (name === "size-audit") {
121
+ const m = output.match(/^(\d+ CTA size violations? across \d+ files?)\.$/m);
122
+ return m ? m[1] : "";
123
+ }
124
+ if (name === "check-stories") {
125
+ const missing = (output.match(/^\s*MISSING\s/gm) || []).length;
126
+ const stale = (output.match(/^\s*STALE\s/gm) || []).length;
127
+ if (missing && stale) return `${missing} missing, ${stale} stale`;
128
+ if (missing) return `${missing} component${missing === 1 ? "" : "s"} missing stories`;
129
+ if (stale) return `${stale} stale stor${stale === 1 ? "y" : "ies"}`;
130
+ return "";
131
+ }
132
+ if (name === "lint-token-intent") {
133
+ const m = output.match(/^token-intent: (\d+) candidate mismatch/m);
134
+ return m ? `${m[1]} candidate mismatch${m[1] === "1" ? "" : "es"}` : "";
135
+ }
136
+ if (name === "lint-slop") {
137
+ const m = output.match(/^lint-slop: (\d+) slop signal/m);
138
+ return m ? `${m[1]} slop signal${m[1] === "1" ? "" : "s"}` : "";
139
+ }
140
+ if (name === "lint-ethics") {
141
+ const m = output.match(/^(\d+) error\(s\), (\d+) warning\(s\)/m);
142
+ return m ? `${m[1]} error(s), ${m[2]} warning(s)` : "";
143
+ }
144
+ return "";
145
+ }
146
+
147
+ const argv = process.argv.slice(2);
148
+ if (argv.includes("--help")) {
149
+ printHelp();
150
+ process.exit(0);
151
+ }
152
+
153
+ const verbose = argv.includes("--verbose") || argv.includes("-v");
154
+ const warnMode = argv.includes("--warn");
155
+ const onlyFlag = argv.find((a) => a.startsWith("--only="));
156
+ const only = onlyFlag ? onlyFlag.slice("--only=".length) : null;
157
+
158
+ if (only && !CHECKS.some((c) => c.name === only)) {
159
+ console.error(`bads-doctor: unknown check "${only}". Valid: ${CHECKS.map((c) => c.name).join(", ")}`);
160
+ process.exit(1);
161
+ }
162
+
163
+ const toRun = only ? CHECKS.filter((c) => c.name === only) : CHECKS;
164
+
165
+ const results = toRun.map((check) => {
166
+ const scriptPath = join(__dirname, check.script);
167
+ if (!existsSync(scriptPath)) {
168
+ return { name: check.name, status: "skipped", detail: "script not found", output: "" };
169
+ }
170
+ const res = spawnSync(process.execPath, [scriptPath, ...check.args], { encoding: "utf8" });
171
+ const output = `${res.stdout || ""}${res.stderr || ""}`;
172
+ const rawStatus = res.status === 0 ? "pass" : "fail";
173
+ // advisory checks downgrade a nonzero exit to "warn" — reported, but never
174
+ // counted as a failure (see the file-header note on why this is a marker
175
+ // rather than a per-script flag).
176
+ const status = rawStatus === "fail" && check.advisory ? "warn" : rawStatus;
177
+ return {
178
+ name: check.name,
179
+ status,
180
+ detail: extractDetail(check.name, output),
181
+ output,
182
+ };
183
+ });
184
+
185
+ if (verbose) {
186
+ for (const r of results) {
187
+ console.log(`\n── ${r.name} ${"─".repeat(Math.max(1, 36 - r.name.length))}`);
188
+ console.log(r.status === "skipped" ? `(skipped: ${r.detail})` : r.output.trimEnd() || "(no output)");
189
+ }
190
+ console.log("");
191
+ }
192
+
193
+ console.log(` bads-doctor — ${toRun.length} check${toRun.length === 1 ? "" : "s"}\n`);
194
+
195
+ const nameWidth = Math.max(...results.map((r) => r.name.length)) + 3;
196
+ for (const r of results) {
197
+ const mark = r.status === "pass" ? "✓" : r.status === "warn" ? "⚠" : r.status === "fail" ? "✗" : "○";
198
+ const label = r.status === "pass" ? "pass" : r.status === "warn" ? "warn" : r.status === "fail" ? "FAIL" : "skipped";
199
+ const detail = r.detail ? ` ${r.detail}` : "";
200
+ console.log(` ${mark} ${r.name.padEnd(nameWidth)}${label.padEnd(8)}${detail}`.trimEnd());
201
+ }
202
+
203
+ const passedCount = results.filter((r) => r.status === "pass").length;
204
+ const warnedCount = results.filter((r) => r.status === "warn").length;
205
+ const failedCount = results.filter((r) => r.status === "fail").length;
206
+ const skippedCount = results.filter((r) => r.status === "skipped").length;
207
+
208
+ let tally = `${passedCount} passed · ${failedCount} failed`;
209
+ if (warnedCount) tally += ` · ${warnedCount} warned (advisory)`;
210
+ if (skippedCount) tally += ` · ${skippedCount} skipped`;
211
+ console.log(`\n ${tally}`);
212
+
213
+ if (failedCount > 0) {
214
+ console.log(`\n Run with --verbose for full output, or run a single check with --only=<name>`);
215
+ }
216
+
217
+ process.exit(warnMode ? 0 : failedCount > 0 ? 1 : 0);
@@ -820,6 +820,35 @@ html, body {
820
820
  animation: skeleton-wave var(--skeleton-wave-duration, 2s) linear infinite;
821
821
  }
822
822
 
823
+ /* Progress — striped and animated variants
824
+ Striped: diagonal 45° repeating-linear-gradient overlay on the indicator
825
+ fill. Stripe color is a semi-transparent white so it reads on every intent
826
+ (default/success/warning/error/info) without hardcoded values, and tracks
827
+ the brand primary in dark mode automatically.
828
+ Animated: adds an ambient left→right sweep on the stripe pattern (same
829
+ linear timing as skeleton-wave — easing would lurch on a seamless loop).
830
+ --progress-stripe-duration is consumer-tunable (default 1s).
831
+ Reduced motion: base layer collapses animation-duration to 0.01ms so the
832
+ stripe freezes to a static pattern — striped but not moving. That keeps the
833
+ visual distinction without vestibular risk. */
834
+ @keyframes progress-stripe {
835
+ from { background-position: 1rem 0; }
836
+ to { background-position: 0 0; }
837
+ }
838
+ [data-slot="progress-indicator"][data-striped="true"] {
839
+ background-image: repeating-linear-gradient(
840
+ 45deg,
841
+ transparent,
842
+ transparent 0.375rem,
843
+ color-mix(in oklab, white, transparent 70%) 0.375rem,
844
+ color-mix(in oklab, white, transparent 70%) 0.75rem
845
+ );
846
+ background-size: 1rem 1rem;
847
+ }
848
+ [data-slot="progress-indicator"][data-animated="true"] {
849
+ animation: progress-stripe var(--progress-stripe-duration, 1s) linear infinite;
850
+ }
851
+
823
852
  /* Prose — long-form typographic rhythm for arbitrary HTML descendants
824
853
  (MDX output, CMS articles, rendered markdown). Keyed off the .prose
825
854
  class the Prose primitive (data-slot="prose") applies — same
@@ -0,0 +1,270 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * bads-check-sync — "is this repo still current with the design system?"
4
+ *
5
+ * Runs INSIDE a consumer (a client fork or a paired prototype repo) and
6
+ * answers two questions that nothing previously answered from the consumer's
7
+ * side:
8
+ *
9
+ * 1. How far behind upstream is the @core this repo actually resolves?
10
+ * 2. Does this repo record where it came from, so a future sync can do a
11
+ * real three-way merge instead of a blind two-way diff?
12
+ *
13
+ * Question 2 is the one that matters long-term. Every template-sync tool that
14
+ * works (copier's .copier-answers.yml, cruft's .cruft.json, projen,
15
+ * Backstage's template-version annotation) depends on the downstream copy
16
+ * recording its provenance: which upstream version its customizations are
17
+ * layered on, and which paths are upstream-owned vs locally owned. Without
18
+ * that record there is no common ancestor, and every future sync degrades to
19
+ * the unresolvable two-way diff that shadcn/ui's `diff` command is stuck with
20
+ * (github.com/shadcn-ui/ui#2121, closed as unfixable for exactly this reason).
21
+ *
22
+ * Reporting only. It never edits, never fetches, never pushes. Reporting and
23
+ * repair are separate by design: a checker that silently "fixes" a deliberate
24
+ * local divergence is the documented failure mode across every drift system in
25
+ * infra (Terraform, ArgoCD, Spacelift all gate remediation behind explicit,
26
+ * narrow, individually opted-in flags).
27
+ *
28
+ * Ships as a bin in @behavioral-agentic-design-system/core, so a consumer runs
29
+ * it without copying anything in:
30
+ *
31
+ * npx bads-check-sync
32
+ * npx bads-check-sync --strict # exit 1 when behind or unrecorded
33
+ * npx bads-check-sync --json
34
+ *
35
+ * Reads only the consumer's own package.json, .client-identity.json, and the
36
+ * installed @core's package.json. No network.
37
+ */
38
+
39
+ import { existsSync, readFileSync } from "node:fs";
40
+ import { join } from "node:path";
41
+
42
+ const ROOT = process.cwd();
43
+ const PKG_NAME = "@behavioral-agentic-design-system/core";
44
+
45
+ const argv = process.argv.slice(2);
46
+ if (argv.includes("--help")) {
47
+ console.log(
48
+ [
49
+ "bads-check-sync — report how far this repo has drifted from the design system.",
50
+ "",
51
+ "Usage: npx bads-check-sync [--strict] [--json] [--help]",
52
+ "",
53
+ " (default) report and exit 0",
54
+ " --strict exit 1 if behind upstream or missing a provenance record",
55
+ " --json machine-readable output",
56
+ "",
57
+ "Reporting only: never edits, fetches, or pushes.",
58
+ ].join("\n"),
59
+ );
60
+ process.exit(0);
61
+ }
62
+ const strict = argv.includes("--strict");
63
+ const asJson = argv.includes("--json");
64
+
65
+ function readJson(p) {
66
+ try {
67
+ return JSON.parse(readFileSync(p, "utf8"));
68
+ } catch {
69
+ return null;
70
+ }
71
+ }
72
+
73
+ // A range like "^0.24.0" / "~0.24.0" / "0.24.0" -> "0.24.0". Anything exotic
74
+ // (a workspace:, link:, file: or git specifier) is reported verbatim instead of
75
+ // being guessed at — a fork on workspace:* is a real finding, not a parse error.
76
+ function parseRange(range) {
77
+ if (typeof range !== "string") return { kind: "absent" };
78
+ if (/^(workspace|link|file|git|github):/i.test(range)) {
79
+ return { kind: "local", raw: range };
80
+ }
81
+ const m = /(\d+)\.(\d+)\.(\d+)/.exec(range);
82
+ if (!m) return { kind: "unparseable", raw: range };
83
+ return { kind: "semver", raw: range, version: `${m[1]}.${m[2]}.${m[3]}`, parts: [+m[1], +m[2], +m[3]] };
84
+ }
85
+
86
+ function compare(a, b) {
87
+ for (let i = 0; i < 3; i++) {
88
+ if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1;
89
+ }
90
+ return 0;
91
+ }
92
+
93
+ const findings = [];
94
+ const result = { repo: ROOT, declared: null, installed: null, sync: "Unknown", provenance: {}, notes: [] };
95
+
96
+ // --- what does this repo ask for, and what did it actually get? -------------
97
+ const pkg = readJson(join(ROOT, "package.json"));
98
+ if (!pkg) {
99
+ console.error("FAIL bads-check-sync: no readable package.json in the current directory.");
100
+ console.error(" Run this from the root of a repo that consumes the design system.");
101
+ process.exit(2);
102
+ }
103
+
104
+ // Upstream BADS is not a consumer of itself. It pins workspace:* on purpose —
105
+ // correct there, and the exact thing this check flags as a blocker downstream —
106
+ // so identify it and stop. Same test bads-sync.mjs already uses.
107
+ const isUpstream = pkg.name === "behavioral-agentic-design-system" && !existsSync(join(ROOT, ".client-identity.json"));
108
+ if (isUpstream) {
109
+ const msg = "OK bads-check-sync: this is upstream BADS itself — nothing to sync against.";
110
+ console.log(asJson ? JSON.stringify({ upstream: true, note: msg }, null, 2) : msg);
111
+ process.exit(0);
112
+ }
113
+
114
+ const deps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
115
+ const declared = parseRange(deps[PKG_NAME]);
116
+ result.declared = declared;
117
+
118
+ const installedPkg = readJson(join(ROOT, "node_modules", PKG_NAME, "package.json"));
119
+ const installed = installedPkg?.version ?? null;
120
+ result.installed = installed;
121
+
122
+ if (declared.kind === "absent") {
123
+ findings.push({
124
+ level: "blocker",
125
+ msg: `this repo does not depend on ${PKG_NAME}`,
126
+ fix: "if it is meant to consume the design system, add the dependency; if not, this check does not apply here.",
127
+ });
128
+ result.sync = "Unknown";
129
+ } else if (declared.kind === "local") {
130
+ // The vendoring trap: a fork pinned to workspace:*/link: resolves a local
131
+ // copy and therefore receives NOTHING from published releases. It looks
132
+ // wired up and is in fact permanently frozen.
133
+ findings.push({
134
+ level: "blocker",
135
+ msg: `${PKG_NAME} is pinned to "${declared.raw}", which resolves a local copy`,
136
+ fix: "this repo will never receive a published release while pinned locally. Switch to a published range (^X.Y.Z) to rejoin the update stream.",
137
+ });
138
+ result.sync = "OutOfSync";
139
+ } else if (declared.kind === "unparseable") {
140
+ findings.push({ level: "warn", msg: `could not parse the version range "${declared.raw}"`, fix: "check the dependency spec." });
141
+ } else if (installed) {
142
+ const inst = parseRange(installed);
143
+ const cmp = compare(inst.parts, declared.parts);
144
+ result.sync = cmp < 0 ? "OutOfSync" : "InstallCurrent";
145
+ if (cmp < 0) {
146
+ findings.push({
147
+ level: "warn",
148
+ msg: `installed ${installed} is older than the declared range ${declared.raw}`,
149
+ fix: "run your package manager's install to resolve the declared range.",
150
+ });
151
+ }
152
+ } else {
153
+ result.notes.push("dependencies are not installed, so the resolved version is unknown");
154
+ }
155
+
156
+ // Two different questions live here, and conflating them is how a badly stale
157
+ // fork reads as healthy. "My install matches my package.json" is not "my
158
+ // package.json is current with the design system" — a fork five minor versions
159
+ // behind satisfies the first and fails the second.
160
+ //
161
+ // The upstream-latest half can't be answered offline from inside a consumer,
162
+ // so it is either supplied (--upstream=X.Y.Z, e.g. from CI) or explicitly
163
+ // reported as unknown. It is never assumed.
164
+ const upstreamArg = argv.find((a) => a.startsWith("--upstream="));
165
+ const upstreamLatest = upstreamArg ? upstreamArg.split("=")[1] : null;
166
+ result.upstreamLatest = upstreamLatest;
167
+
168
+ if (declared.kind === "semver") {
169
+ if (upstreamLatest) {
170
+ const up = parseRange(upstreamLatest);
171
+ if (up.kind === "semver") {
172
+ const behind = compare(declared.parts, up.parts) < 0;
173
+ result.currency = behind ? "Behind" : "Current";
174
+ if (behind) {
175
+ const minors = up.parts[1] - declared.parts[1];
176
+ findings.push({
177
+ level: "warn",
178
+ msg: `declared ${declared.version} is behind upstream ${up.version}${minors > 0 ? ` (${minors} minor version${minors === 1 ? "" : "s"})` : ""}`,
179
+ fix: "bump the dependency to pick up everything released since, then re-run your checks.",
180
+ });
181
+ }
182
+ } else {
183
+ result.currency = "Unknown";
184
+ result.notes.push(`could not parse --upstream=${upstreamLatest}`);
185
+ }
186
+ } else {
187
+ result.currency = "Unknown";
188
+ result.notes.push(
189
+ "upstream's latest version is unknown offline — pass --upstream=X.Y.Z, or run the maintainer-side fleet sweep, to learn how far behind this repo is",
190
+ );
191
+ }
192
+ }
193
+
194
+ // --- provenance: can a future sync compute an ancestor? ---------------------
195
+ const identityPath = join(ROOT, ".client-identity.json");
196
+ const identity = existsSync(identityPath) ? readJson(identityPath) : null;
197
+
198
+ if (!identity) {
199
+ result.provenance.marker = false;
200
+ result.notes.push("no .client-identity.json — upstream BADS itself, or a fork that has not been renamed");
201
+ } else {
202
+ result.provenance.marker = true;
203
+ result.provenance.name = identity.name ?? null;
204
+ result.provenance.slug = identity.slug ?? null;
205
+ result.provenance.upstreamVersion = identity.upstreamVersion ?? null;
206
+ result.provenance.ownershipMap = Boolean(identity.ownershipMap);
207
+
208
+ if (!identity.upstreamVersion) {
209
+ findings.push({
210
+ level: "info",
211
+ msg: "no `upstreamVersion` recorded in .client-identity.json",
212
+ fix: "this fork predates sync-manifest v2. Until it is recorded, a sync cannot tell which upstream state your customizations sit on top of.",
213
+ });
214
+ }
215
+ if (!identity.ownershipMap) {
216
+ findings.push({
217
+ level: "info",
218
+ msg: "no `ownershipMap` recorded in .client-identity.json",
219
+ fix: "without it, a scaffold sync cannot tell which files are yours to keep and which upstream may replay.",
220
+ });
221
+ }
222
+ }
223
+
224
+ // --- report -----------------------------------------------------------------
225
+ if (asJson) {
226
+ console.log(JSON.stringify({ ...result, findings }, null, 2));
227
+ process.exit(strict && findings.some((f) => f.level !== "info") ? 1 : 0);
228
+ }
229
+
230
+ const label = result.provenance.name || pkg.name || "this repo";
231
+ console.log(`bads-check-sync — ${label}`);
232
+ console.log("");
233
+ console.log(` design system ${declared.raw ?? "(not a dependency)"}${installed ? ` (resolved ${installed})` : ""}`);
234
+ console.log(` install ${result.sync === "InstallCurrent" ? "matches the declared range" : result.sync}`);
235
+ console.log(
236
+ ` vs upstream ${
237
+ result.currency === "Behind"
238
+ ? `behind (upstream ${result.upstreamLatest})`
239
+ : result.currency === "Current"
240
+ ? `current (upstream ${result.upstreamLatest})`
241
+ : "unknown offline — pass --upstream=X.Y.Z"
242
+ }`,
243
+ );
244
+ console.log(
245
+ ` provenance ${
246
+ result.provenance.marker
247
+ ? `${result.provenance.upstreamVersion ? `upstreamVersion ${result.provenance.upstreamVersion}` : "upstreamVersion not recorded"}, ${result.provenance.ownershipMap ? "ownershipMap present" : "ownershipMap not recorded"}`
248
+ : "no .client-identity.json"
249
+ }`,
250
+ );
251
+
252
+ for (const n of result.notes) console.log(` note ${n}`);
253
+
254
+ if (findings.length > 0) {
255
+ console.log("");
256
+ for (const f of findings) {
257
+ const tag = f.level === "blocker" ? "BLOCKER" : f.level === "warn" ? "WARN" : "note";
258
+ console.log(` [${tag}] ${f.msg}`);
259
+ console.log(` ${f.fix}`);
260
+ }
261
+ }
262
+
263
+ const actionable = findings.filter((f) => f.level !== "info");
264
+ console.log("");
265
+ if (actionable.length === 0) {
266
+ console.log("OK bads-check-sync: nothing blocking.");
267
+ } else {
268
+ console.log(`bads-check-sync: ${actionable.length} item(s) worth acting on.`);
269
+ }
270
+ process.exit(strict && actionable.length > 0 ? 1 : 0);