@marktiderman/genesis-cli 1.24.0 → 1.25.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/cli.js CHANGED
@@ -1029,6 +1029,7 @@ var init_migrations = __esm({
1029
1029
  var config_exports = {};
1030
1030
  __export(config_exports, {
1031
1031
  DoctorConfigError: () => DoctorConfigError,
1032
+ EXTENSION_REASON_MIN: () => EXTENSION_REASON_MIN,
1032
1033
  GenesisConfigError: () => GenesisConfigError,
1033
1034
  META_RULES: () => META_RULES,
1034
1035
  PRIVACY_DATA_TYPES: () => PRIVACY_DATA_TYPES,
@@ -1264,6 +1265,30 @@ function validateConfig(raw, source = "config") {
1264
1265
  }
1265
1266
  });
1266
1267
  }
1268
+ if (c.extend !== void 0) {
1269
+ if (!Array.isArray(c.extend)) fail(`"extend" must be a list of { rule, file, buildsOn, reason, upstream? }`);
1270
+ const seen = /* @__PURE__ */ new Set();
1271
+ c.extend.forEach((e, i) => {
1272
+ const where2 = `extend[${i}]`;
1273
+ if (!isObject2(e)) return fail(`${where2} must be an object`);
1274
+ for (const k of Object.keys(e)) if (!EXTENSION_KEYS.has(k)) fail(`${where2}: unknown key "${k}" (known: ${[...EXTENSION_KEYS].join(", ")})`);
1275
+ for (const k of ["rule", "file", "buildsOn", "reason"]) if (typeof e[k] !== "string" || !e[k].trim()) fail(`${where2} needs "${k}"`);
1276
+ const { rule, file, buildsOn, reason } = e;
1277
+ if (META_RULES.has(rule) || CONFIG_RULES.has(rule)) fail(`${where2} can't extend ${rule}: it is about the config, not the app's code`);
1278
+ if (!rule.includes("/")) fail(`${where2} can't extend ${rule}: only package rules declare extension points (a built-in rule's findings are fixed, or recorded as allow debt)`);
1279
+ if (/[*?[\]{}]/.test(file)) fail(`${where2}.file must be one file, not a glob: each extension is reviewed on its own`);
1280
+ e.file = appPath2(file, `${where2}.file`, fail);
1281
+ if (!/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(buildsOn)) fail(`${where2}.buildsOn must name a Genesis export, or a part of one ("FormBuilder", "ResourceView.slots")`);
1282
+ const text = reason.trim();
1283
+ if (text.length < EXTENSION_REASON_MIN.chars || text.split(/\s+/).length < EXTENSION_REASON_MIN.words) {
1284
+ fail(`${where2} (${rule}) needs a reason of at least ${EXTENSION_REASON_MIN.words} words and ${EXTENSION_REASON_MIN.chars} characters: why the rule's primitive doesn't fit this file`);
1285
+ }
1286
+ if (e.upstream !== void 0 && (typeof e.upstream !== "string" || !e.upstream.trim())) fail(`${where2}.upstream must be a link to the gap's write-up`);
1287
+ const key2 = `${rule}\0${e.file}`;
1288
+ if (seen.has(key2)) fail(`${where2} extends ${rule} in ${e.file} twice`);
1289
+ seen.add(key2);
1290
+ });
1291
+ }
1267
1292
  if (c.patterns !== void 0) {
1268
1293
  if (!Array.isArray(c.patterns)) fail(`"patterns" must be a list`);
1269
1294
  c.patterns.forEach((p, i) => {
@@ -1346,7 +1371,7 @@ function isObject2(v) {
1346
1371
  function isStringList(v) {
1347
1372
  return Array.isArray(v) && v.every((x) => typeof x === "string");
1348
1373
  }
1349
- var GenesisConfigError, DoctorConfigError, PRIVACY_DATA_TYPES, PRIVACY_PURPOSES, ENVIRONMENT_KEYS, STRING_LISTS, STRINGS, KNOWN, LEVELS, META_RULES, PATTERN_KEYS, PACKAGE_RULE_KEYS, CONTRACT_KEYS, PACKS, PACK_KEYS, PLAIN_FOLDER, PRIVACY_KEYS, DATA_USE_KEYS, LINK_KEYS, HOST;
1374
+ var GenesisConfigError, DoctorConfigError, PRIVACY_DATA_TYPES, PRIVACY_PURPOSES, ENVIRONMENT_KEYS, STRING_LISTS, STRINGS, KNOWN, LEVELS, META_RULES, CONFIG_RULES, EXTENSION_KEYS, EXTENSION_REASON_MIN, PATTERN_KEYS, PACKAGE_RULE_KEYS, CONTRACT_KEYS, PACKS, PACK_KEYS, PLAIN_FOLDER, PRIVACY_KEYS, DATA_USE_KEYS, LINK_KEYS, HOST;
1350
1375
  var init_config = __esm({
1351
1376
  "src/doctor/config.ts"() {
1352
1377
  GenesisConfigError = class extends Error {
@@ -1411,6 +1436,7 @@ var init_config = __esm({
1411
1436
  "forbiddenImports",
1412
1437
  "rules",
1413
1438
  "allow",
1439
+ "extend",
1414
1440
  "patterns",
1415
1441
  "plugins",
1416
1442
  "packs",
@@ -1425,7 +1451,10 @@ var init_config = __esm({
1425
1451
  "$comment"
1426
1452
  ]);
1427
1453
  LEVELS = /* @__PURE__ */ new Set(["error", "warn", "info", "off"]);
1428
- META_RULES = /* @__PURE__ */ new Set(["allow-grew", "rules-weakened", "ratchet-skipped"]);
1454
+ META_RULES = /* @__PURE__ */ new Set(["allow-grew", "rules-weakened", "ratchet-skipped", "extension-invalid"]);
1455
+ CONFIG_RULES = /* @__PURE__ */ new Set(["stale-exception", "stale-extension", "package-rule-override"]);
1456
+ EXTENSION_KEYS = /* @__PURE__ */ new Set(["rule", "file", "buildsOn", "reason", "upstream"]);
1457
+ EXTENSION_REASON_MIN = { chars: 40, words: 6 };
1429
1458
  PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message", "newOnly"]);
1430
1459
  PACKAGE_RULE_KEYS = /* @__PURE__ */ new Set(["level", "files", "exclude", "reason"]);
1431
1460
  CONTRACT_KEYS = /* @__PURE__ */ new Set(["out", "schemas", "databaseEnv"]);
@@ -2090,6 +2119,9 @@ function scanFiles(root, config) {
2090
2119
  for (const pkg of local) walk4(pkg.dir);
2091
2120
  return files;
2092
2121
  }
2122
+ function withText(file, text) {
2123
+ return { ...file, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(file.ext)) };
2124
+ }
2093
2125
  function lineAt(text, index) {
2094
2126
  let line = 1;
2095
2127
  for (let i = 0; i < index && i < text.length; i++) if (text.charCodeAt(i) === 10) line++;
@@ -4250,6 +4282,10 @@ var init_rules = __esm({
4250
4282
  "ratchet-skipped",
4251
4283
  "allow-grew",
4252
4284
  "rules-weakened",
4285
+ "extension-added",
4286
+ // declared extensions (extensions.ts)
4287
+ "stale-extension",
4288
+ "extension-invalid",
4253
4289
  // agent guide (primitives.ts)
4254
4290
  "agent-guide-stale",
4255
4291
  // supabase pack: contracts (contracts.ts)
@@ -4382,6 +4418,33 @@ function readSource(abs) {
4382
4418
  return null;
4383
4419
  }
4384
4420
  }
4421
+ function blankStrings(code) {
4422
+ if (lastBlanked?.source === code) return lastBlanked.blanked;
4423
+ const out = code.split("");
4424
+ for (let i = 0; i < code.length; i++) {
4425
+ const ch = code[i];
4426
+ if (ch !== '"' && ch !== "'" && ch !== "`") continue;
4427
+ let j = i - 1;
4428
+ while (j >= 0 && /[ \t]/.test(code[j])) j--;
4429
+ const before = j >= 0 ? code[j] : "\n";
4430
+ const word = /[\w$]/.test(before) ? /(?:^|[^\w$])(return|case|typeof|in|of|yield|await)$/.test(code.slice(Math.max(0, j - 8), j + 1)) : false;
4431
+ if (/[\w$)\]]/.test(before) && !word) continue;
4432
+ let k = i + 1;
4433
+ for (; k < code.length; k++) {
4434
+ const c = code[k];
4435
+ if (c === "\\") {
4436
+ k++;
4437
+ continue;
4438
+ }
4439
+ if (c === ch) break;
4440
+ if (c === "\n" && ch !== "`") break;
4441
+ }
4442
+ for (let x = i + 1; x < k && x < code.length; x++) if (code[x] !== "\n") out[x] = " ";
4443
+ i = k;
4444
+ }
4445
+ lastBlanked = { source: code, blanked: out.join("") };
4446
+ return lastBlanked.blanked;
4447
+ }
4385
4448
  function tagEnd(code, start) {
4386
4449
  let depth = 0;
4387
4450
  let quote2 = null;
@@ -4403,7 +4466,8 @@ function tagEnd(code, start) {
4403
4466
  }
4404
4467
  return { end: code.length, selfClosing: false };
4405
4468
  }
4406
- function openElementsAt(code, index, track) {
4469
+ function openElementsAt(source, index, track) {
4470
+ const code = blankStrings(source);
4407
4471
  const open = [];
4408
4472
  const re = /<(\/?)([A-Z][\w.]*)(?=[\s>/])/g;
4409
4473
  for (let m = re.exec(code); m && m.index < index; m = re.exec(code)) {
@@ -4442,12 +4506,13 @@ function namedImportsFrom(code, pkg) {
4442
4506
  }
4443
4507
  return out;
4444
4508
  }
4445
- var SCRIPT_EXTS2, JSX_EXTS2, RESOLVE_EXTS;
4509
+ var SCRIPT_EXTS2, JSX_EXTS2, RESOLVE_EXTS, lastBlanked;
4446
4510
  var init_source = __esm({
4447
4511
  "src/doctor/source.ts"() {
4448
4512
  SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
4449
4513
  JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
4450
4514
  RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
4515
+ lastBlanked = null;
4451
4516
  }
4452
4517
  });
4453
4518
  function nativePackage(ctx) {
@@ -5383,6 +5448,9 @@ function validatePrefer(raw, where2, fail, unknownKey) {
5383
5448
  if (raw.platform !== void 0 && raw.platform !== "web" && raw.platform !== "native") fail(`${at}.platform must be "web" or "native"`);
5384
5449
  if (raw.newOnly !== void 0 && typeof raw.newOnly !== "boolean") fail(`${at}.newOnly must be true or false`);
5385
5450
  for (const key2 of ["files", "exclude"]) if (raw[key2] !== void 0 && !isStringList2(raw[key2])) fail(`${at}.${key2} must be a list of globs`);
5451
+ if (raw.extensible !== void 0 && !(isStringList2(raw.extensible) && raw.extensible.every((n) => /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(n)))) {
5452
+ fail(`${at}.extensible must be a list of export names, or parts of one ("ResourceView.slots")`);
5453
+ }
5386
5454
  if (!isObject3(raw.forbid)) fail(`${at} needs "forbid": { jsx?, imports?, pattern? }`);
5387
5455
  const forbid = raw.forbid;
5388
5456
  for (const key2 of Object.keys(forbid)) if (!FORBID_KEYS.has(key2)) unknownKey(`${at}.forbid`, key2);
@@ -5395,6 +5463,7 @@ function validatePrefer(raw, where2, fail, unknownKey) {
5395
5463
  const unless = raw.unless;
5396
5464
  for (const key2 of Object.keys(unless)) if (!UNLESS_KEYS.has(key2)) narrowing(`${at}.unless`, key2, UNLESS_KEYS);
5397
5465
  if (unless.renders !== void 0 && !isStringList2(unless.renders)) fail(`${at}.unless.renders must be a list of component names`);
5466
+ if (unless.inside !== void 0 && !(isStringList2(unless.inside) && unless.inside.every((n) => /^[A-Z][\w.]*$/.test(n)))) fail(`${at}.unless.inside must be a list of component names`);
5398
5467
  if (unless.pattern !== void 0) checkPattern(unless.pattern, `${at}.unless.pattern`, fail);
5399
5468
  }
5400
5469
  return raw;
@@ -5510,6 +5579,7 @@ function compile(rule, setting, routes) {
5510
5579
  imports: (rule.forbid.imports ?? []).map(specMatcher),
5511
5580
  ...rule.forbid.pattern ? { pattern: toRegExp2(rule.forbid.pattern, "g") } : {},
5512
5581
  unlessRenders: new Set(rule.unless?.renders ?? []),
5582
+ unlessInside: new Set(rule.unless?.inside ?? []),
5513
5583
  ...rule.unless?.pattern ? { unlessPattern: toRegExp2(rule.unless.pattern) } : {}
5514
5584
  };
5515
5585
  }
@@ -5518,7 +5588,7 @@ function messageFor(rule, found) {
5518
5588
  const docs = rule.docs ? ` See ${rule.docs}` : "";
5519
5589
  return `${found}; use ${rule.use}${from}. ${rule.why}${docs}`;
5520
5590
  }
5521
- function wrappersIn(file, elements, c) {
5591
+ function wrappersIn(file, elements, names, accept) {
5522
5592
  const out = /* @__PURE__ */ new Map();
5523
5593
  const decls = [...file.code.matchAll(TOP_LEVEL)];
5524
5594
  const listed = /* @__PURE__ */ new Map();
@@ -5531,12 +5601,12 @@ function wrappersIn(file, elements, c) {
5531
5601
  for (const m of file.code.matchAll(EXPORT_DEFAULT_NAME)) listed.set(m[1], [...listed.get(m[1]) ?? [], "default"]);
5532
5602
  decls.forEach((d, i) => {
5533
5603
  const name = d[3];
5534
- if (!/^[A-Z]/.test(name) || c.jsx.has(name)) return;
5604
+ if (!/^[A-Z]/.test(name) || names.has(name)) return;
5535
5605
  const end = decls[i + 1]?.index ?? file.code.length;
5536
- const hit = elements.find((m) => m.index > d.index && m.index < end && c.jsx.has(m[1]));
5537
- if (!hit) return;
5538
- const names = [...d[1] ? [d[2] ? "default" : name] : [], ...listed.get(name) ?? []];
5539
- for (const n of names) out.set(n, hit[1]);
5606
+ const hit = elements.find((m) => m.index > d.index && m.index < end && names.has(m[1]));
5607
+ if (!hit || accept && !accept(d.index, end)) return;
5608
+ const exported = [...d[1] ? [d[2] ? "default" : name] : [], ...listed.get(name) ?? []];
5609
+ for (const n of exported) out.set(n, hit[1]);
5540
5610
  });
5541
5611
  return out;
5542
5612
  }
@@ -5544,6 +5614,32 @@ function runPrefer(ctx, c) {
5544
5614
  const own = c.rule.packageDir;
5545
5615
  const checked = ctx.files.filter((file) => SCRIPT.has(file.ext) && c.includes(file.path) && !c.excludes(file.path) && !inside(own, file.absolutePath));
5546
5616
  const exempt = (file, rendered) => rendered.some((n) => c.unlessRenders.has(n)) || (c.unlessPattern?.test(file.code) ?? false);
5617
+ const scanned = new Map(ctx.files.map((f) => [f.absolutePath, f]));
5618
+ const importedBy = /* @__PURE__ */ new Map();
5619
+ const importsOf = (file) => {
5620
+ if (!importedBy.has(file)) importedBy.set(file, localImportedNames(ctx.root, file));
5621
+ return importedBy.get(file);
5622
+ };
5623
+ const builders = /* @__PURE__ */ new Map();
5624
+ const buildersIn = (abs) => {
5625
+ if (!builders.has(abs)) {
5626
+ const target = scanned.get(abs) ?? readSource(abs);
5627
+ const code = target ? "ext" in target ? target.code : stripBlockComments(target.code, true) : "";
5628
+ const childrenInside = (start, end) => [...code.slice(start, end).matchAll(CHILDREN)].some((m) => openElementsAt(code, start + m.index, (n) => c.unlessInside.has(n)).length > 0);
5629
+ builders.set(abs, code ? wrappersIn({ code }, [...code.matchAll(ELEMENT)], c.unlessInside, childrenInside) : /* @__PURE__ */ new Map());
5630
+ }
5631
+ return builders.get(abs);
5632
+ };
5633
+ const nestedInBuilder = (file, index) => {
5634
+ if (!c.unlessInside.size) return false;
5635
+ const imported = importsOf(file);
5636
+ const isBuilder = (name) => {
5637
+ if (c.unlessInside.has(name)) return true;
5638
+ const from = name.includes(".") ? void 0 : imported.get(name);
5639
+ return from !== void 0 && buildersIn(from.file).has(from.name);
5640
+ };
5641
+ return openElementsAt(file.code, index, isBuilder).length > 0;
5642
+ };
5547
5643
  const wrappers = /* @__PURE__ */ new Map();
5548
5644
  const renderedBy = /* @__PURE__ */ new Map();
5549
5645
  for (const file of checked) {
@@ -5551,16 +5647,17 @@ function runPrefer(ctx, c) {
5551
5647
  const elements = [...file.code.matchAll(ELEMENT)];
5552
5648
  renderedBy.set(file, elements);
5553
5649
  if (!c.jsx.size || exempt(file, elements.map((m) => m[1]))) continue;
5554
- const found = wrappersIn(file, elements, c);
5650
+ const found = wrappersIn(file, elements, c.jsx);
5555
5651
  if (found.size) wrappers.set(file.absolutePath, found);
5556
5652
  }
5557
5653
  for (const file of checked) {
5558
5654
  const elements = renderedBy.get(file) ?? [];
5559
5655
  if (exempt(file, elements.map((m) => m[1]))) continue;
5560
5656
  const report = (line, subject, found) => ctx.report({ rule: c.rule.ruleId, level: c.level, file: file.path, line, subject, message: messageFor(c.rule, found) });
5561
- const imported = wrappers.size && elements.length ? localImportedNames(ctx.root, file) : null;
5657
+ const imported = wrappers.size && elements.length ? importsOf(file) : null;
5562
5658
  for (const m of elements) {
5563
5659
  const name = m[1];
5660
+ if (nestedInBuilder(file, m.index)) continue;
5564
5661
  if (c.jsx.has(name)) {
5565
5662
  report(lineAt(file.code, m.index), name, `renders <${name}>`);
5566
5663
  continue;
@@ -5577,6 +5674,7 @@ function runPrefer(ctx, c) {
5577
5674
  if (c.pattern) {
5578
5675
  c.pattern.lastIndex = 0;
5579
5676
  for (const m of file.code.matchAll(c.pattern)) {
5677
+ if (nestedInBuilder(file, m.index)) continue;
5580
5678
  const text = m[0].trim().replace(/\s+/g, " ").slice(0, 60);
5581
5679
  report(lineAt(file.code, m.index), text, `has ${text}`);
5582
5680
  }
@@ -5641,7 +5739,7 @@ function unknownPackageRuleSettings(config, packages, reported) {
5641
5739
  function packageRuleIds(packages) {
5642
5740
  return new Set(preferRules(packages).map((r) => r.ruleId));
5643
5741
  }
5644
- var PackageDeclarationError, GENESIS, ID, LEVELS2, PREFER_KEYS, FORBID_KEYS, UNLESS_KEYS, PRIMITIVE_KEYS, DECLARATION_KEYS, SCRIPT_GLOBS, isObject3, isStringList2, discoveryCache, specMatcher, JSX, ELEMENT, SCRIPT, TOP_LEVEL, EXPORT_LIST, EXPORT_DEFAULT_NAME, isNative;
5742
+ var PackageDeclarationError, GENESIS, ID, LEVELS2, PREFER_KEYS, FORBID_KEYS, UNLESS_KEYS, PRIMITIVE_KEYS, DECLARATION_KEYS, SCRIPT_GLOBS, isObject3, isStringList2, discoveryCache, specMatcher, JSX, ELEMENT, SCRIPT, CHILDREN, TOP_LEVEL, EXPORT_LIST, EXPORT_DEFAULT_NAME, isNative;
5645
5743
  var init_package_rules = __esm({
5646
5744
  "src/doctor/package-rules.ts"() {
5647
5745
  init_discover();
@@ -5653,6 +5751,7 @@ var init_package_rules = __esm({
5653
5751
  init_routes();
5654
5752
  init_scan();
5655
5753
  init_source();
5754
+ init_color_literals();
5656
5755
  init_rules();
5657
5756
  PackageDeclarationError = class extends Error {
5658
5757
  name = "PackageDeclarationError";
@@ -5660,9 +5759,9 @@ var init_package_rules = __esm({
5660
5759
  GENESIS = /^@marktiderman\/genesis(?:-([a-z0-9-]+))?$/;
5661
5760
  ID = /^[a-z0-9][a-z0-9-]*$/;
5662
5761
  LEVELS2 = /* @__PURE__ */ new Set(["error", "warn", "info"]);
5663
- PREFER_KEYS = /* @__PURE__ */ new Set(["id", "need", "level", "platform", "files", "exclude", "forbid", "unless", "use", "import", "docs", "why", "newOnly"]);
5762
+ PREFER_KEYS = /* @__PURE__ */ new Set(["id", "need", "level", "platform", "files", "exclude", "forbid", "unless", "use", "import", "docs", "why", "newOnly", "extensible"]);
5664
5763
  FORBID_KEYS = /* @__PURE__ */ new Set(["jsx", "imports", "pattern"]);
5665
- UNLESS_KEYS = /* @__PURE__ */ new Set(["renders", "pattern"]);
5764
+ UNLESS_KEYS = /* @__PURE__ */ new Set(["renders", "inside", "pattern"]);
5666
5765
  PRIMITIVE_KEYS = /* @__PURE__ */ new Set(["need", "use", "import", "docs"]);
5667
5766
  DECLARATION_KEYS = /* @__PURE__ */ new Set(["enforce", "reason", "prefer", "catalog", "primitives", "plugin", "$comment"]);
5668
5767
  SCRIPT_GLOBS = ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.mts", "**/*.cts", "**/*.mjs", "**/*.cjs"];
@@ -5673,6 +5772,7 @@ var init_package_rules = __esm({
5673
5772
  JSX = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
5674
5773
  ELEMENT = /(?<![\w$.])<([A-Z][\w.]*)(?=[\s>/<])/g;
5675
5774
  SCRIPT = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
5775
+ CHILDREN = /\{\s*(?:props\.)?children\s*\}/g;
5676
5776
  TOP_LEVEL = /^(export\s+(default\s+)?)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([\w$]+)/gm;
5677
5777
  EXPORT_LIST = /\bexport\s*\{([^}]*)\}(?!\s*from)/g;
5678
5778
  EXPORT_DEFAULT_NAME = /^export\s+default\s+([A-Z][\w$]*)\s*;?\s*$/gm;
@@ -8073,20 +8173,41 @@ function git3(root, args) {
8073
8173
  return r.status === 0 ? r.stdout : null;
8074
8174
  }
8075
8175
  function changedSince(root, base) {
8076
- const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
8176
+ const mergeBase = mergeBaseOf2(root, base);
8077
8177
  if (!mergeBase) return null;
8078
8178
  const committed = git3(root, ["diff", "-z", "--name-only", "--relative", `${mergeBase}`, "--"]);
8079
8179
  const untracked = git3(root, ["ls-files", "-z", "--others", "--exclude-standard"]);
8080
8180
  if (committed === null || untracked === null) return null;
8081
8181
  return new Set([...committed.split("\0"), ...untracked.split("\0")].filter(Boolean));
8082
8182
  }
8183
+ function originsSince(root, base) {
8184
+ const out = /* @__PURE__ */ new Map();
8185
+ const mergeBase = mergeBaseOf2(root, base);
8186
+ if (!mergeBase) return out;
8187
+ const diff = git3(root, ["diff", "-z", "-M", "--name-status", "--relative", mergeBase, "--"]);
8188
+ if (diff === null) return out;
8189
+ const parts = diff.split("\0");
8190
+ for (let i = 0; i < parts.length; ) {
8191
+ const status = parts[i++] ?? "";
8192
+ if (!status) continue;
8193
+ if (status.startsWith("R") || status.startsWith("C")) {
8194
+ const from = parts[i++];
8195
+ const to = parts[i++];
8196
+ if (status.startsWith("R")) out.set(to, from);
8197
+ } else i++;
8198
+ }
8199
+ return out;
8200
+ }
8201
+ function mergeBaseOf2(root, base) {
8202
+ return git3(root, ["merge-base", base, "HEAD"])?.trim() || null;
8203
+ }
8083
8204
  function showAt(dir, rev, file) {
8084
8205
  const at = `${rev}:./${file}`;
8085
8206
  if (git3(dir, ["cat-file", "-e", at]) === null) return void 0;
8086
8207
  return git3(dir, ["show", at]);
8087
8208
  }
8088
8209
  function configAtBase(root, base, explicitFile) {
8089
- const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
8210
+ const mergeBase = mergeBaseOf2(root, base);
8090
8211
  if (!mergeBase) return null;
8091
8212
  const candidates = explicitFile ? [{ dir: path30.dirname(explicitFile), file: path30.basename(explicitFile), explicit: true }] : [
8092
8213
  { dir: root, file: "genesis.config.json", explicit: false },
@@ -8107,7 +8228,12 @@ function configAtBase(root, base, explicitFile) {
8107
8228
  continue;
8108
8229
  }
8109
8230
  const b = objectOr(block);
8110
- return { allow: Array.isArray(b.allow) ? b.allow : [], rules: objectOr(b.rules), packageRules: objectOr(b.packageRules) };
8231
+ return {
8232
+ allow: Array.isArray(b.allow) ? b.allow : [],
8233
+ extend: Array.isArray(b.extend) ? b.extend : [],
8234
+ rules: objectOr(b.rules),
8235
+ packageRules: objectOr(b.packageRules)
8236
+ };
8111
8237
  }
8112
8238
  return "absent";
8113
8239
  }
@@ -8120,6 +8246,16 @@ function allowGrew(allow, before, base) {
8120
8246
  message: `allow gained an entry for ${a.rule}${a.match ? ` (${a.match})` : ""} since ${base}; the list only shrinks, so fix what it hides instead`
8121
8247
  }));
8122
8248
  }
8249
+ function extensionsAdded(extend, before, base) {
8250
+ const had = new Set(before.map((e) => `${e.rule}\0${e.file}\0${e.buildsOn}`));
8251
+ return extend.filter((e) => !had.has(`${e.rule}\0${e.file}\0${e.buildsOn}`)).map((e) => ({
8252
+ rule: "extension-added",
8253
+ level: "info",
8254
+ file: e.file,
8255
+ subject: e.rule,
8256
+ message: `extends ${e.rule} since ${base}, building on ${e.buildsOn}: "${e.reason}"${e.upstream ? ` (upstream: ${e.upstream})` : ""}; the pull request's review accepts it, and it covers only the findings the file has now`
8257
+ }));
8258
+ }
8123
8259
  function rulesWeakened(config, before, base) {
8124
8260
  const out = [];
8125
8261
  const levelIn = (c, rule) => c.rules?.[rule] ?? c.packageRules?.[rule]?.level;
@@ -8147,18 +8283,63 @@ function touched(file, changed) {
8147
8283
  for (const c of changed) if (c.startsWith(prefix)) return true;
8148
8284
  return false;
8149
8285
  }
8286
+ function isRatcheted(rule, config, newOnly) {
8287
+ return !NEVER_RATCHETED.has(rule) && (config.ratchet === true || newOnly.has(rule) || Array.isArray(config.ratchet) && config.ratchet.includes(rule));
8288
+ }
8289
+ function countFindings(findings) {
8290
+ const counts = /* @__PURE__ */ new Map();
8291
+ for (const f of findings) counts.set(countKey(f.file, f.rule), (counts.get(countKey(f.file, f.rule)) ?? 0) + 1);
8292
+ return counts;
8293
+ }
8150
8294
  function applyRatchet(findings, options) {
8151
- const { config, newOnly, changed, base, isAppPath } = options;
8152
- const ratcheted = (rule) => !NEVER_RATCHETED.has(rule) && (config.ratchet === true || newOnly.has(rule) || Array.isArray(config.ratchet) && config.ratchet.includes(rule));
8295
+ const { config, newOnly, changed, base, isAppPath, baseCounts, existedAtBase } = options;
8296
+ const originOf = options.originOf ?? ((f) => f);
8297
+ const counts = countFindings(findings.map((f) => ({ file: originOf(f.file), rule: f.rule })));
8153
8298
  return findings.map((f) => {
8154
- if (f.level === "info" || !ratcheted(f.rule) || !isAppPath(f.file) || touched(f.file, changed)) return f;
8155
- return { ...f, level: "info", message: `${f.message} (ratcheted: unchanged since ${base})` };
8299
+ if (f.level === "info" || !isRatcheted(f.rule, config, newOnly) || !isAppPath(f.file)) return f;
8300
+ if (!touched(f.file, changed)) return { ...f, level: "info", message: `${f.message} (ratcheted: unchanged since ${base})` };
8301
+ const origin = originOf(f.file);
8302
+ if (!baseCounts || !existedAtBase?.(origin)) return f;
8303
+ const now = counts.get(countKey(origin, f.rule)) ?? 0;
8304
+ const was = baseCounts.get(countKey(origin, f.rule)) ?? 0;
8305
+ const where2 = origin === f.file ? "this file" : `the files from ${origin}`;
8306
+ if (now > was) return { ...f, message: `${f.message} (${now} ${f.rule} findings in ${where2}, ${was} at the merge base with ${base}: don't add to the debt)` };
8307
+ return { ...f, level: "info", message: `${f.message} (ratcheted: ${now} in ${where2}, ${was} at the merge base with ${base})` };
8156
8308
  });
8157
8309
  }
8158
- var objectOr, allowKey, RANK, NEVER_RATCHETED;
8310
+ function snapshotAtBase(root, base, files, changed, originOf = (f) => f) {
8311
+ const mergeBase = mergeBaseOf2(root, base);
8312
+ if (!mergeBase) return null;
8313
+ const out = [];
8314
+ const seen = /* @__PURE__ */ new Set();
8315
+ for (const f of files) {
8316
+ if (!changed.has(f.path)) {
8317
+ if (!seen.has(f.path)) out.push(f);
8318
+ seen.add(f.path);
8319
+ continue;
8320
+ }
8321
+ const origin = originOf(f.path);
8322
+ if (seen.has(origin)) continue;
8323
+ seen.add(origin);
8324
+ const text = showAt(root, mergeBase, origin);
8325
+ if (text === null) return null;
8326
+ if (text !== void 0) out.push(withText({ ...f, path: origin, absolutePath: path30.join(root, origin) }, text));
8327
+ }
8328
+ const cache2 = /* @__PURE__ */ new Map();
8329
+ return {
8330
+ mergeBase,
8331
+ files: out,
8332
+ existed(file) {
8333
+ if (!cache2.has(file)) cache2.set(file, git3(root, ["cat-file", "-e", `${mergeBase}:./${file}`]) !== null);
8334
+ return cache2.get(file);
8335
+ }
8336
+ };
8337
+ }
8338
+ var objectOr, allowKey, RANK, NEVER_RATCHETED, countKey;
8159
8339
  var init_ratchet = __esm({
8160
8340
  "src/doctor/ratchet.ts"() {
8161
8341
  init_config();
8342
+ init_scan();
8162
8343
  objectOr = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
8163
8344
  allowKey = (a) => `${a.rule}\0${a.file ?? ""}\0${a.match ?? ""}`;
8164
8345
  RANK = { off: 0, info: 1, warn: 2, error: 3 };
@@ -8171,8 +8352,127 @@ var init_ratchet = __esm({
8171
8352
  "plugin-error",
8172
8353
  "build",
8173
8354
  "agent-guide-stale",
8174
- "contracts-stale"
8355
+ "contracts-stale",
8356
+ "stale-extension",
8357
+ "extension-added"
8175
8358
  ]);
8359
+ countKey = (file, rule) => `${file}\0${rule}`;
8360
+ }
8361
+ });
8362
+
8363
+ // src/doctor/extensions.ts
8364
+ function pointProblem(entry, packages) {
8365
+ const rule = preferRules(packages).find((r) => r.ruleId === entry.rule);
8366
+ if (!rule?.extensible?.length) return `${entry.rule} declares no extension points, so it can't be extended (debt goes in allow, and is fixed)`;
8367
+ if (!rule.extensible.includes(entry.buildsOn)) return `${entry.buildsOn} isn't one of ${entry.rule}'s extension points (${rule.extensible.join(", ")})`;
8368
+ return null;
8369
+ }
8370
+ function extensionProblem(entry, ctx) {
8371
+ const point = pointProblem(entry, ctx.packages);
8372
+ if (point) return point;
8373
+ const name = entry.buildsOn.split(".")[0];
8374
+ const replaces = preferRules(ctx.packages).find((r) => r.forbid.jsx?.includes(name));
8375
+ if (replaces) return `${name} is what ${replaces.ruleId} replaces (use ${replaces.use}); a legacy component can't be built on`;
8376
+ const flagged = ctx.raw.find((f) => f.file === entry.file && f.subject === name);
8377
+ if (flagged) return `${name} is flagged in this file by ${flagged.rule}; build on a current Genesis primitive`;
8378
+ const file = ctx.files.find((f) => f.path === entry.file);
8379
+ if (!file) return `${entry.file} isn't one of the files the doctor scans`;
8380
+ const imported = genesisNamedImports(file.code).some((i) => i.names.includes(name));
8381
+ if (!imported) return `${entry.file} doesn't import ${name} from a Genesis package; buildsOn names the extension point the file uses`;
8382
+ if (!usesPoint(blankStrings(file.code), entry.buildsOn)) {
8383
+ const prop = entry.buildsOn.split(".")[1];
8384
+ return prop ? `${entry.file} doesn't pass ${prop} to <${name}>; an extension point is one the file uses` : `${entry.file} imports ${name} but doesn't render or call it; an extension point is one the file uses`;
8385
+ }
8386
+ return null;
8387
+ }
8388
+ function usesPoint(code, point) {
8389
+ const [name, prop] = point.split(".");
8390
+ const n = escape2(name);
8391
+ if (!prop) return new RegExp(`(?<![\\w$.])<${n}(?=[\\s>/<])|(?<![\\w$.])${n}\\s*(?:<[^>()]*>)?\\s*\\(`).test(code);
8392
+ for (const m of code.matchAll(new RegExp(`(?<![\\w$.])<${n}(?=[\\s>/<])`, "g"))) {
8393
+ const { end } = tagEnd(code, m.index);
8394
+ if (new RegExp(`(?<![\\w$.])${escape2(prop)}\\s*=`).test(code.slice(m.index, end))) return true;
8395
+ }
8396
+ return false;
8397
+ }
8398
+ function applyExtensions(findings, ctx) {
8399
+ const entries = ctx.config.extend ?? [];
8400
+ if (!entries.length) return findings;
8401
+ const staleLevel = ctx.config.rules?.["stale-extension"];
8402
+ const covered = /* @__PURE__ */ new Set();
8403
+ const grew = /* @__PURE__ */ new Map();
8404
+ const out = [];
8405
+ const invalid = (entry, problem) => out.push({ rule: "extension-invalid", level: "error", file: entry.file, line: 0, subject: entry.rule, message: `the extension of ${entry.rule} isn't accepted: ${problem}` });
8406
+ for (const entry of entries) {
8407
+ if (ctx.config.rules?.[entry.rule] === "off" || ctx.config.packageRules?.[entry.rule]?.level === "off") continue;
8408
+ const point = pointProblem(entry, ctx.packages);
8409
+ if (point) {
8410
+ invalid(entry, point);
8411
+ continue;
8412
+ }
8413
+ const hits = findings.filter((f) => f.rule === entry.rule && f.file === entry.file);
8414
+ if (!hits.length) {
8415
+ if (staleLevel === "off") continue;
8416
+ out.push({
8417
+ rule: "stale-extension",
8418
+ level: staleLevel ?? "warn",
8419
+ file: entry.file,
8420
+ line: 0,
8421
+ subject: entry.rule,
8422
+ message: `the extension of ${entry.rule} (building on ${entry.buildsOn}) no longer matches a finding in this file; remove it from doctor.extend`
8423
+ });
8424
+ continue;
8425
+ }
8426
+ const problem = extensionProblem(entry, ctx);
8427
+ if (problem) {
8428
+ invalid(entry, problem);
8429
+ continue;
8430
+ }
8431
+ const limit = ctx.limit?.(entry);
8432
+ if (limit !== void 0 && hits.length > limit) {
8433
+ for (const h of hits) grew.set(h, `${h.message} (the extension of ${entry.rule} here covers the ${limit} at the merge base; this file now has ${hits.length}, so they all count)`);
8434
+ continue;
8435
+ }
8436
+ for (const h of hits) covered.add(h);
8437
+ }
8438
+ const kept = findings.filter((f) => !covered.has(f)).map((f) => grew.has(f) ? { ...f, message: grew.get(f) } : f);
8439
+ return [...kept, ...out].sort(byPlace);
8440
+ }
8441
+ function dedupeFindings(findings) {
8442
+ const groups = /* @__PURE__ */ new Map();
8443
+ const order = [];
8444
+ for (const f of findings) {
8445
+ if (f.subject === void 0 || !f.line) {
8446
+ order.push([f]);
8447
+ continue;
8448
+ }
8449
+ const key2 = `${f.file}\0${f.line}\0${f.subject}`;
8450
+ const list = groups.get(key2) ?? [];
8451
+ const group = list.find((g) => !g.some((x) => x.rule === f.rule));
8452
+ if (group) group.push(f);
8453
+ else {
8454
+ const fresh = [f];
8455
+ list.push(fresh);
8456
+ groups.set(key2, list);
8457
+ order.push(fresh);
8458
+ }
8459
+ }
8460
+ return order.map((group) => {
8461
+ if (group.length === 1) return group[0];
8462
+ const primary = group.reduce((a, b) => RANK2[b.level] > RANK2[a.level] ? b : a);
8463
+ const rules = [primary.rule, ...group.filter((g) => g !== primary).map((g) => g.rule)];
8464
+ return { ...primary, rules, message: `${primary.message} (also ${rules.slice(1).join(", ")})` };
8465
+ });
8466
+ }
8467
+ var escape2, byPlace, RANK2;
8468
+ var init_extensions = __esm({
8469
+ "src/doctor/extensions.ts"() {
8470
+ init_stability();
8471
+ init_source();
8472
+ init_package_rules();
8473
+ escape2 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8474
+ byPlace = (x, y) => x.file.localeCompare(y.file) || x.line - y.line || x.rule.localeCompare(y.rule);
8475
+ RANK2 = { info: 0, warn: 1, error: 2 };
8176
8476
  }
8177
8477
  });
8178
8478
  function pathTaken(file) {
@@ -9570,12 +9870,15 @@ __export(doctor_exports, {
9570
9870
  agentGuideState: () => agentGuideState,
9571
9871
  agentHooksState: () => agentHooksState,
9572
9872
  agentRules: () => agentRules,
9873
+ applyExtensions: () => applyExtensions,
9573
9874
  builtinChecks: () => builtinChecks,
9574
9875
  catalogTable: () => catalogTable,
9575
9876
  changedSince: () => changedSince,
9576
9877
  clearPackageRulesCache: () => clearPackageRulesCache,
9878
+ dedupeFindings: () => dedupeFindings,
9577
9879
  defineDoctorPlugin: () => defineDoctorPlugin,
9578
9880
  discoverPackages: () => discoverPackages,
9881
+ extensionProblem: () => extensionProblem,
9579
9882
  findPackageDir: () => findPackageDir,
9580
9883
  formatPrimitives: () => formatPrimitives,
9581
9884
  formatReport: () => formatReport,
@@ -9632,14 +9935,8 @@ async function runDoctor(options = {}) {
9632
9935
  }
9633
9936
  const raw = [];
9634
9937
  const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, ...options.strict ? { strict: true } : {}, report: (f) => raw.push(f) };
9635
- for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true, figma: options.figma ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
9636
- try {
9637
- await plugin.check(ctx);
9638
- } catch (err) {
9639
- if (err instanceof DoctorConfigError) throw err;
9640
- raw.push({ rule: "plugin-error", file: plugin.name, message: `rule plugin "${plugin.name}" threw: ${err.message}` });
9641
- }
9642
- }
9938
+ const appChecks = [...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins];
9939
+ await runChecks(ctx, [...builtinChecks(config, { contracts: options.contracts ?? true, figma: options.figma ?? true }), ...appChecks]);
9643
9940
  if (options.build) {
9644
9941
  const failure = runBuild(root, buildCommands(root, config), options.quietBuild ?? false);
9645
9942
  if (failure) raw.push(failure);
@@ -9649,30 +9946,57 @@ async function runDoctor(options = {}) {
9649
9946
  let changed = null;
9650
9947
  let skipped = false;
9651
9948
  const ratchetNeeded = newOnly.size > RATCHETED_BY_DEFAULT.length || raw.some((f) => RATCHETED_BY_DEFAULT.includes(f.rule));
9652
- if (options.base && (ratchetNeeded || config.ratchet)) {
9949
+ if (options.base && (ratchetNeeded || config.ratchet || config.extend?.length)) {
9653
9950
  changed = options.changedFiles ? new Set(options.changedFiles) : changedSince(root, options.base);
9654
9951
  skipped ||= !changed;
9655
9952
  }
9656
9953
  const configFile = "file" in loaded ? loaded.file : null;
9657
- const guarded = (config.allow?.length ?? 0) + Object.keys(config.rules ?? {}).length + Object.keys(config.packageRules ?? {}).length > 0;
9954
+ const guarded = (config.allow?.length ?? 0) + (config.extend?.length ?? 0) + Object.keys(config.rules ?? {}).length + Object.keys(config.packageRules ?? {}).length > 0;
9658
9955
  let configSkipped = false;
9956
+ let baseExtend = [];
9659
9957
  if (options.base && configFile) {
9660
9958
  const before = configAtBase(root, options.base, options.configPath !== void 0 ? configFile : void 0);
9959
+ if (before && before !== "absent") baseExtend = before.extend;
9960
+ if (before === "absent") raw.push(...extensionsAdded(config.extend ?? [], [], options.base));
9661
9961
  if (before && before !== "absent") {
9662
9962
  raw.push(...allowGrew(config.allow ?? [], before.allow, options.base));
9663
9963
  raw.push(...rulesWeakened(config, before, options.base));
9964
+ raw.push(...extensionsAdded(config.extend ?? [], before.extend, options.base));
9664
9965
  }
9665
9966
  configSkipped = !before && guarded;
9666
9967
  }
9667
9968
  if (skipped || configSkipped) {
9668
9969
  raw.push(
9669
- configSkipped ? { rule: "ratchet-skipped", level: "error", file: "genesis config", message: `couldn't compare allow, rules and packageRules against ${options.base} (not a git repository, or the ref isn't fetched; in CI check out with fetch-depth: 0)` } : { rule: "ratchet-skipped", level: "warn", file: "genesis config", message: `couldn't compare against ${options.base} (not a git repository, or the ref isn't fetched); every rule ran at its full level` }
9970
+ configSkipped ? { rule: "ratchet-skipped", level: "error", file: "genesis config", message: `couldn't compare allow, extend, rules and packageRules against ${options.base} (not a git repository, or the ref isn't fetched; in CI check out with fetch-depth: 0)` } : { rule: "ratchet-skipped", level: "warn", file: "genesis config", message: `couldn't compare against ${options.base} (not a git repository, or the ref isn't fetched); every rule ran at its full level` }
9670
9971
  );
9671
9972
  }
9672
- let findings = applyConfig(raw, config, packageRuleIds(packages));
9973
+ const packageIds = packageRuleIds(packages);
9974
+ const extensionCtx = { config, files, packages, raw };
9975
+ const configured = applyConfig(raw, config, packageIds);
9976
+ let findings = applyExtensions(configured, extensionCtx);
9673
9977
  if (options.base && changed) {
9674
- findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path30.join(root, f)) });
9675
- }
9978
+ const isAppPath = (f) => existsSync(path30.join(root, f));
9979
+ const origins = options.changedFiles ? /* @__PURE__ */ new Map() : originsSince(root, options.base);
9980
+ const originOf = (f) => origins.get(f) ?? f;
9981
+ const dueRules = new Set(findings.filter((f) => f.level !== "info" && isRatcheted(f.rule, config, newOnly) && isAppPath(f.file) && touched(f.file, changed)).map((f) => f.rule));
9982
+ const heldExtensions = (config.extend ?? []).filter((e) => touched(e.file, changed) && baseExtend.some((b) => b.rule === e.rule && (b.file === e.file || b.file === originOf(e.file))));
9983
+ for (const e of heldExtensions) dueRules.add(e.rule);
9984
+ const snapshot = dueRules.size ? snapshotAtBase(root, options.base, files, changed, originOf) : null;
9985
+ let baseCounts;
9986
+ if (snapshot) {
9987
+ const before = [];
9988
+ await runChecks({ ...ctx, files: snapshot.files, report: (f) => before.push(f) }, baseChecks(dueRules, packageIds, packagePlugins, () => [...builtinChecks(config, { contracts: false, figma: false }), ...appChecks]));
9989
+ baseCounts = countFindings(applyConfig(before, config, packageIds));
9990
+ if (heldExtensions.length) {
9991
+ const counts = baseCounts;
9992
+ const held = new Set(heldExtensions);
9993
+ findings = applyExtensions(configured, { ...extensionCtx, limit: (e) => held.has(e) ? counts.get(countKey(originOf(e.file), e.rule)) ?? 0 : void 0 });
9994
+ }
9995
+ }
9996
+ findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath, originOf, ...snapshot && baseCounts ? { baseCounts, existedAtBase: snapshot.existed } : {} });
9997
+ }
9998
+ findings = dedupeFindings(findings);
9999
+ const extensionsNew = (config.extend ?? []).filter((e) => findings.some((f) => f.rule === "extension-added" && f.file === e.file && f.subject === e.rule));
9676
10000
  const errors = findings.filter((f) => f.level === "error").length;
9677
10001
  const warnings = findings.filter((f) => f.level === "warn").length;
9678
10002
  const infos = findings.length - errors - warnings;
@@ -9686,9 +10010,24 @@ async function runDoctor(options = {}) {
9686
10010
  primitives: primitivesSummary(packages),
9687
10011
  errors,
9688
10012
  warnings,
9689
- infos
10013
+ infos,
10014
+ ...extensionsNew.length ? { extensionsAdded: extensionsNew } : {}
9690
10015
  };
9691
10016
  }
10017
+ function baseChecks(rules, preferIds, packagePlugins, all) {
10018
+ if ([...rules].every((r) => preferIds.has(r))) return packagePlugins.filter((p) => p.name === "package-rules");
10019
+ return all();
10020
+ }
10021
+ async function runChecks(ctx, checks) {
10022
+ for (const plugin of checks) {
10023
+ try {
10024
+ await plugin.check(ctx);
10025
+ } catch (err) {
10026
+ if (err instanceof DoctorConfigError) throw err;
10027
+ ctx.report({ rule: "plugin-error", file: plugin.name, message: `rule plugin "${plugin.name}" threw: ${err.message}` });
10028
+ }
10029
+ }
10030
+ }
9692
10031
  function builtinChecks(config, options = {}) {
9693
10032
  const packs = {
9694
10033
  native: { name: "native", check: checkNativePack },
@@ -9782,10 +10121,14 @@ function formatReport(result, options = {}) {
9782
10121
  `Genesis doctor: ${g.uiPackage}@${g.uiVersion}, ${g.components.length} components, ${g.tokens.size} tokens, ${result.ruleCount} app rules; raw tags checked: ${[...g.rawTags.keys()].join(", ") || "none"}`
9783
10122
  ];
9784
10123
  for (const f of result.findings) {
9785
- lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
10124
+ lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${(f.rules ?? [f.rule]).join(", ")}] ${f.message}`);
9786
10125
  }
9787
10126
  lines.push(options.verbose ? `Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}` : `Available but unused: ${result.unused.length} (genesis doctor --verbose lists them)`);
9788
10127
  lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis catalog`);
10128
+ if (result.extensionsAdded?.length) {
10129
+ lines.push(`Extensions added on this branch (${result.extensionsAdded.length}); the pull request's review accepts each:`);
10130
+ for (const e of result.extensionsAdded) lines.push(` ${e.file} [${e.rule}] builds on ${e.buildsOn}: ${e.reason}${e.upstream ? ` (upstream: ${e.upstream})` : ""}`);
10131
+ }
9789
10132
  const info = result.infos ? `, ${result.infos} info` : "";
9790
10133
  lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
9791
10134
  return lines.join("\n");
@@ -9799,7 +10142,8 @@ function toJson(result) {
9799
10142
  infos: result.infos,
9800
10143
  findings: result.findings,
9801
10144
  unused: result.unused,
9802
- primitives: result.primitives
10145
+ primitives: result.primitives,
10146
+ ...result.extensionsAdded ? { extensionsAdded: result.extensionsAdded } : {}
9803
10147
  };
9804
10148
  }
9805
10149
  function genesisSummary(g) {
@@ -9834,6 +10178,7 @@ var init_doctor = __esm({
9834
10178
  init_stability();
9835
10179
  init_package_rules();
9836
10180
  init_ratchet();
10181
+ init_extensions();
9837
10182
  init_contracts();
9838
10183
  init_primitives();
9839
10184
  init_agent_hooks();
@@ -9857,6 +10202,7 @@ var init_doctor = __esm({
9857
10202
  init_package_rules();
9858
10203
  init_primitives();
9859
10204
  init_ratchet();
10205
+ init_extensions();
9860
10206
  init_contracts();
9861
10207
  init_agent_hooks();
9862
10208
  RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];