@marktiderman/genesis-cli 1.16.1 → 1.17.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/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { createRequire, builtinModules } from 'module';
2
2
  import { studioSetupSql } from '@marktiderman/genesis-studio-server';
3
- import * as path18 from 'path';
3
+ import * as path19 from 'path';
4
4
  import { spawnSync } from 'child_process';
5
5
  import { existsSync, readFileSync, statSync, realpathSync, readdirSync, lstatSync } from 'fs';
6
6
  import 'crypto';
7
7
  import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
8
8
  import { pathToFileURL } from 'url';
9
+ import { overlayUpstream, readOverlayMarker } from '@marktiderman/genesis-features';
9
10
  import 'jiti';
10
11
 
11
12
  var __defProp = Object.defineProperty;
@@ -211,6 +212,16 @@ function parse(comment, keys, where2) {
211
212
  if (!kind) {
212
213
  throw new CommentSettingsError(`${where2}: unknown ${MARKER} setting "${key2}". Allowed: ${Object.keys(keys).join(", ")}.`);
213
214
  }
215
+ if (kind === "key") {
216
+ const list = typeof v === "string" ? [v] : v;
217
+ if (!Array.isArray(list) || list.length === 0 || !list.every((c) => typeof c === "string" && c !== "")) {
218
+ throw new CommentSettingsError(`${where2}: ${MARKER} "${key2}" must be a column name or a list of them.`);
219
+ }
220
+ const twice = list.find((c, i) => list.indexOf(c) !== i);
221
+ if (twice) throw new CommentSettingsError(`${where2}: ${MARKER} "${key2}" names "${twice}" twice.`);
222
+ settings[key2] = list;
223
+ continue;
224
+ }
214
225
  if (typeof v !== kind) throw new CommentSettingsError(`${where2}: ${MARKER} "${key2}" must be a ${kind}.`);
215
226
  settings[key2] = v;
216
227
  }
@@ -225,11 +236,22 @@ function parseTableComment(comment, table) {
225
236
  function parseColumnComment(comment, column) {
226
237
  return parse(comment, FIELD_KEYS, column);
227
238
  }
239
+ function withKeySetting(table, warn) {
240
+ const key2 = table.settings?.key;
241
+ if (!key2) return table;
242
+ const columns = new Set(table.columns.map((c) => c.name));
243
+ const missing = key2.filter((k) => !columns.has(k));
244
+ if (missing.length) throw new CommentSettingsError(`${table.name}: ${MARKER} key "${missing.join('", "')}" isn't one of its columns.`);
245
+ if (table.key.length && table.key.join("\0") !== key2.join("\0")) {
246
+ warn?.(`${table.name}: ${MARKER} key (${key2.join(", ")}) differs from its primary key (${table.key.join(", ")}); the comment's key is used.`);
247
+ }
248
+ return { ...table, key: [...key2] };
249
+ }
228
250
  var MARKER, TABLE_KEYS, FIELD_KEYS, CommentSettingsError;
229
251
  var init_comments = __esm({
230
252
  "src/introspect/comments.ts"() {
231
253
  MARKER = "@genesis";
232
- TABLE_KEYS = { label: "string", labelField: "string", description: "string", noun: "string", nounPlural: "string" };
254
+ TABLE_KEYS = { label: "string", labelField: "string", description: "string", noun: "string", nounPlural: "string", key: "key" };
233
255
  FIELD_KEYS = { label: "string", description: "string", widget: "string", readonly: "boolean", sensitive: "boolean" };
234
256
  CommentSettingsError = class extends Error {
235
257
  };
@@ -260,6 +282,12 @@ var init_model = __esm({
260
282
  function where(sql, scope) {
261
283
  return "schemas" in scope ? sql`n.nspname = any(${scope.schemas})` : sql`c.oid = any(${scope.oids}::oid[])`;
262
284
  }
285
+ function linkOf(columns, refColumns, refUnique = []) {
286
+ if (columns.length === 1) return 0;
287
+ if (columns.length !== refColumns.length) return -1;
288
+ const own = columns.flatMap((c, i) => c === refColumns[i] ? [] : [i]);
289
+ return own.length === 1 && refUnique[own[0]] === true ? own[0] : -1;
290
+ }
263
291
  async function readRelations(sql, scope, into) {
264
292
  const columns = await sql`
265
293
  select c.oid::text as oid, c.relkind::text as relkind, n.nspname as schema, c.relname as table,
@@ -291,16 +319,24 @@ async function readRelations(sql, scope, into) {
291
319
  where con.contype = 'p' and ${where(sql, scope)}
292
320
  group by c.oid`;
293
321
  const links = await sql`
294
- select c.oid::text as oid, con.conkey[1]::int as attnum,
295
- rn.nspname as ref_schema, rc.relname as ref_table, ra.attname as ref_column
322
+ select c.oid::text as oid, con.conkey::int[] as attnums,
323
+ array(select a.attname::text from unnest(con.conkey) with ordinality k(attnum, ord)
324
+ join pg_attribute a on a.attrelid = c.oid and a.attnum = k.attnum order by k.ord) as columns,
325
+ array(select ra.attname::text from unnest(con.confkey) with ordinality k(attnum, ord)
326
+ join pg_attribute ra on ra.attrelid = con.confrelid and ra.attnum = k.attnum order by k.ord) as ref_columns,
327
+ array(select exists (select 1 from pg_index i
328
+ where i.indrelid = con.confrelid and i.indisunique and i.indpred is null
329
+ and i.indnkeyatts = 1 and i.indkey[0] = k.attnum)
330
+ from unnest(con.confkey) with ordinality k(attnum, ord) order by k.ord) as ref_unique,
331
+ rn.nspname as ref_schema, rc.relname as ref_table
296
332
  from pg_constraint con
297
333
  join pg_class c on c.oid = con.conrelid
298
334
  join pg_namespace n on n.oid = c.relnamespace
299
335
  join pg_class rc on rc.oid = con.confrelid
300
336
  join pg_namespace rn on rn.oid = rc.relnamespace
301
- join pg_attribute ra on ra.attrelid = rc.oid and ra.attnum = con.confkey[1]
302
- where con.contype = 'f' and array_length(con.conkey, 1) = 1
303
- and ${where(sql, scope)}`;
337
+ where con.contype = 'f'
338
+ and ${where(sql, scope)}
339
+ order by con.conname`;
304
340
  const checks = await sql`
305
341
  select c.oid::text as oid, con.conkey[1]::int as attnum, a.attname as column,
306
342
  pg_get_constraintdef(con.oid) as definition
@@ -365,9 +401,12 @@ async function readRelations(sql, scope, into) {
365
401
  const relation = into.get(k.oid);
366
402
  if (relation) relation.key = k.columns;
367
403
  }
368
- for (const l of links) {
369
- const column = into.get(l.oid)?.columns.get(l.attnum);
370
- if (column) column.references = { resource: qualifiedName(l.ref_schema, l.ref_table), field: l.ref_column };
404
+ const ordered = [...links].sort((a, b) => a.attnums.length - b.attnums.length);
405
+ for (const l of ordered) {
406
+ const at = linkOf(l.columns, l.ref_columns, l.ref_unique);
407
+ if (at < 0) continue;
408
+ const column = into.get(l.oid)?.columns.get(l.attnums[at]);
409
+ if (column && !column.references) column.references = { resource: qualifiedName(l.ref_schema, l.ref_table), field: l.ref_columns[at] };
371
410
  }
372
411
  const listed = /* @__PURE__ */ new Map();
373
412
  for (const check of checks) {
@@ -416,14 +455,14 @@ function inherit(own, source) {
416
455
  }
417
456
  function resolveViews(relations) {
418
457
  const done = /* @__PURE__ */ new Set();
419
- const resolve14 = (relation, depth) => {
458
+ const resolve16 = (relation, depth) => {
420
459
  if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
421
460
  done.add(relation.oid);
422
461
  const sources = new Set([...relation.origins.values()].map((o) => o.relation));
423
462
  if (sources.size !== 1) return;
424
463
  const source = relations.get([...sources][0]);
425
464
  if (!source) return;
426
- resolve14(source, depth + 1);
465
+ resolve16(source, depth + 1);
427
466
  const viewAttnumOf = /* @__PURE__ */ new Map();
428
467
  for (const [attnum, origin] of relation.origins) {
429
468
  const own = relation.columns.get(attnum);
@@ -446,9 +485,9 @@ function resolveViews(relations) {
446
485
  };
447
486
  if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
448
487
  };
449
- for (const relation of relations.values()) resolve14(relation, 0);
488
+ for (const relation of relations.values()) resolve16(relation, 0);
450
489
  }
451
- async function introspectPostgres(sql, schemas) {
490
+ async function introspectPostgres(sql, schemas, options = {}) {
452
491
  const relations = /* @__PURE__ */ new Map();
453
492
  const wanted = await readRelations(sql, { schemas: [...schemas] }, relations);
454
493
  for (let depth = 0; depth < MAX_VIEW_DEPTH; depth++) {
@@ -465,7 +504,7 @@ async function introspectPostgres(sql, schemas) {
465
504
  resolveViews(relations);
466
505
  return wanted.map((oid) => {
467
506
  const relation = relations.get(oid);
468
- return { ...relation.table, key: relation.key.map((attnum) => relation.columns.get(attnum).name) };
507
+ return withKeySetting({ ...relation.table, key: relation.key.map((attnum) => relation.columns.get(attnum).name) }, options.warn);
469
508
  });
470
509
  }
471
510
  var MAX_VIEW_DEPTH;
@@ -483,7 +522,7 @@ function clean(description) {
483
522
  if (!description) return void 0;
484
523
  return description.replace(NOTES, "").trim() || void 0;
485
524
  }
486
- function introspectOpenApi(doc, schema = "public") {
525
+ function introspectOpenApi(doc, schema = "public", options = {}) {
487
526
  const definitions = doc.definitions ?? doc.components?.schemas;
488
527
  if (!definitions) throw new Error("This OpenAPI document has no definitions. Is it a PostgREST (Supabase /rest/v1/) spec?");
489
528
  return Object.keys(definitions).sort().map((tableName) => {
@@ -515,7 +554,7 @@ function introspectOpenApi(doc, schema = "public") {
515
554
  };
516
555
  });
517
556
  const comment = parseTableComment(def.description, name);
518
- return {
557
+ return withKeySetting({
519
558
  name,
520
559
  schema,
521
560
  table: tableName,
@@ -523,7 +562,7 @@ function introspectOpenApi(doc, schema = "public") {
523
562
  columns,
524
563
  ...comment.description ? { description: comment.description } : {},
525
564
  ...comment.settings ? { settings: comment.settings } : {}
526
- };
565
+ }, options.warn);
527
566
  });
528
567
  }
529
568
  var PK, FK, NOTES;
@@ -776,9 +815,9 @@ async function runScaffold(opts, fs) {
776
815
  function joinPath(...parts) {
777
816
  return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
778
817
  }
779
- function dirname(path28) {
780
- const idx = path28.lastIndexOf("/");
781
- return idx === -1 ? "." : path28.slice(0, idx);
818
+ function dirname(path30) {
819
+ const idx = path30.lastIndexOf("/");
820
+ return idx === -1 ? "." : path30.slice(0, idx);
782
821
  }
783
822
  function brandPackageJson(consumer, genesisVersion) {
784
823
  return JSON.stringify(
@@ -1036,8 +1075,8 @@ function routeTags(source) {
1036
1075
  var GUARD = /<((?:[A-Z]\w*)?(?:Admin|Staff)\w*(?:Guard|Route|Only)|RequireAdmin|RequireStaff)>/;
1037
1076
  function wireStudioRoute(source, route, pageImportPath) {
1038
1077
  const tags = routeTags(source);
1039
- const relative8 = route.replace(/^\//, "");
1040
- const existing = tags.find((t) => new RegExp(`path=["'](/?${relative8.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
1078
+ const relative10 = route.replace(/^\//, "");
1079
+ const existing = tags.find((t) => new RegExp(`path=["'](/?${relative10.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
1041
1080
  if (existing) {
1042
1081
  return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
1043
1082
  }
@@ -1045,17 +1084,17 @@ function wireStudioRoute(source, route, pageImportPath) {
1045
1084
  const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
1046
1085
  if (roots.length !== 1) {
1047
1086
  return {
1048
- skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative8}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
1087
+ skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative10}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
1049
1088
  };
1050
1089
  }
1051
1090
  const layout = roots[0];
1052
1091
  const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
1053
- if (base && !relative8.startsWith(`${base}/`)) {
1092
+ if (base && !relative10.startsWith(`${base}/`)) {
1054
1093
  return {
1055
1094
  skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
1056
1095
  };
1057
1096
  }
1058
- const childPath = base ? relative8.slice(base.length + 1) : relative8;
1097
+ const childPath = base ? relative10.slice(base.length + 1) : relative10;
1059
1098
  const guard = GUARD.exec(source)?.[1];
1060
1099
  const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
1061
1100
  const before = source.slice(0, layout.close);
@@ -1369,19 +1408,19 @@ ${line}
1369
1408
  var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
1370
1409
  function buildCommands(root, config) {
1371
1410
  if (config.build) return config.build;
1372
- const pkgFile = path18.join(root, "package.json");
1411
+ const pkgFile = path19.join(root, "package.json");
1373
1412
  const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
1374
1413
  const pm = packageManager(root);
1375
1414
  return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
1376
1415
  }
1377
1416
  function packageManager(root) {
1378
- let dir = path18.resolve(root);
1417
+ let dir = path19.resolve(root);
1379
1418
  for (; ; ) {
1380
- if (existsSync(path18.join(dir, "pnpm-lock.yaml"))) return "pnpm";
1381
- if (existsSync(path18.join(dir, "bun.lock")) || existsSync(path18.join(dir, "bun.lockb"))) return "bun";
1382
- if (existsSync(path18.join(dir, "yarn.lock"))) return "yarn";
1383
- if (existsSync(path18.join(dir, "package-lock.json"))) return "npm";
1384
- const parent = path18.dirname(dir);
1419
+ if (existsSync(path19.join(dir, "pnpm-lock.yaml"))) return "pnpm";
1420
+ if (existsSync(path19.join(dir, "bun.lock")) || existsSync(path19.join(dir, "bun.lockb"))) return "bun";
1421
+ if (existsSync(path19.join(dir, "yarn.lock"))) return "yarn";
1422
+ if (existsSync(path19.join(dir, "package-lock.json"))) return "npm";
1423
+ const parent = path19.dirname(dir);
1385
1424
  if (parent === dir) return "npm";
1386
1425
  dir = parent;
1387
1426
  }
@@ -1496,25 +1535,25 @@ var PACK_KEYS = {
1496
1535
  };
1497
1536
  function appPath(v, where2, fail) {
1498
1537
  if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
1499
- if (path18.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
1500
- const norm = path18.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
1538
+ if (path19.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
1539
+ const norm = path19.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
1501
1540
  if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
1502
1541
  return norm;
1503
1542
  }
1504
1543
  function loadConfig(root, configPath) {
1505
1544
  if (configPath) {
1506
- const file = path18.resolve(root, configPath);
1545
+ const file = path19.resolve(root, configPath);
1507
1546
  if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
1508
1547
  const json = readJson(file);
1509
- const block = path18.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
1510
- return { config: validateConfig(block ?? {}, file), file, dir: path18.dirname(file) };
1548
+ const block = path19.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
1549
+ return { config: validateConfig(block ?? {}, file), file, dir: path19.dirname(file) };
1511
1550
  }
1512
- const own = path18.join(root, "genesis.config.json");
1551
+ const own = path19.join(root, "genesis.config.json");
1513
1552
  if (existsSync(own)) {
1514
1553
  const block = readGenesisConfig(root)?.raw.doctor;
1515
1554
  return { config: validateConfig(block ?? {}, own), file: own, dir: root };
1516
1555
  }
1517
- const pkg = path18.join(root, "package.json");
1556
+ const pkg = path19.join(root, "package.json");
1518
1557
  if (existsSync(pkg)) {
1519
1558
  const block = readJson(pkg)?.genesis?.doctor;
1520
1559
  if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
@@ -1523,14 +1562,14 @@ function loadConfig(root, configPath) {
1523
1562
  }
1524
1563
  function doctorBlock(json, file, explicit) {
1525
1564
  const j = json;
1526
- if (path18.basename(file) === "package.json") return j?.genesis?.doctor;
1565
+ if (path19.basename(file) === "package.json") return j?.genesis?.doctor;
1527
1566
  return explicit ? j?.doctor ?? j : j?.doctor;
1528
1567
  }
1529
1568
  function isPackageDeclaration(block) {
1530
1569
  if (typeof block === "string") return true;
1531
1570
  if (!isObject(block)) return false;
1532
1571
  const keys = Object.keys(block).filter((k) => k !== "$comment");
1533
- return keys.some((k) => ["prefer", "primitives", "plugin", "enforce"].includes(k)) && !keys.some((k) => KNOWN.has(k));
1572
+ return keys.some((k) => ["prefer", "catalog", "primitives", "plugin", "enforce"].includes(k)) && !keys.some((k) => KNOWN.has(k));
1534
1573
  }
1535
1574
  function readJson(file) {
1536
1575
  try {
@@ -1540,7 +1579,7 @@ function readJson(file) {
1540
1579
  }
1541
1580
  }
1542
1581
  function readGenesisConfig(root) {
1543
- const file = path18.join(root, "genesis.config.json");
1582
+ const file = path19.join(root, "genesis.config.json");
1544
1583
  if (!existsSync(file)) return null;
1545
1584
  const raw = readJson(file);
1546
1585
  if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
@@ -1705,7 +1744,7 @@ function validateConfig(raw, source = "config") {
1705
1744
  if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
1706
1745
  if (contracts.out !== void 0) {
1707
1746
  if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
1708
- if (path18.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
1747
+ if (path19.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
1709
1748
  }
1710
1749
  if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
1711
1750
  if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
@@ -1773,7 +1812,7 @@ function globToRegExp(glob) {
1773
1812
  }
1774
1813
  function globMatcher(globs) {
1775
1814
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1776
- return (path28) => res.some((re) => re.test(path28));
1815
+ return (path30) => res.some((re) => re.test(path30));
1777
1816
  }
1778
1817
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1779
1818
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -1813,11 +1852,11 @@ var TAILWIND_PALETTE = [
1813
1852
  "olive"
1814
1853
  ];
1815
1854
  function findPackageDir(from, name) {
1816
- let dir = path18.resolve(from);
1855
+ let dir = path19.resolve(from);
1817
1856
  for (; ; ) {
1818
- const candidate = path18.join(dir, "node_modules", name);
1819
- if (existsSync(path18.join(candidate, "package.json"))) return candidate;
1820
- const parent = path18.dirname(dir);
1857
+ const candidate = path19.join(dir, "node_modules", name);
1858
+ if (existsSync(path19.join(candidate, "package.json"))) return candidate;
1859
+ const parent = path19.dirname(dir);
1821
1860
  if (parent === dir) return null;
1822
1861
  dir = parent;
1823
1862
  }
@@ -1869,37 +1908,50 @@ function loadCompanions(root, config, uiPackage) {
1869
1908
  function readPackageExports(root, uiPackage) {
1870
1909
  const uiDir = findPackageDir(root, uiPackage);
1871
1910
  if (!uiDir) return null;
1872
- const uiPkg = JSON.parse(readFileSync(path18.join(uiDir, "package.json"), "utf8"));
1911
+ const uiPkg = JSON.parse(readFileSync(path19.join(uiDir, "package.json"), "utf8"));
1912
+ const subpaths = Object.values(uiPkg.exports ?? {});
1913
+ const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
1914
+ const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
1915
+ const entryOf = fromSource ? exportSource : exportTypes;
1873
1916
  const typeEntries = /* @__PURE__ */ new Set();
1874
- const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
1917
+ const mainTypes = fromSource ? exportSource(uiPkg.exports?.["."] ?? uiPkg.exports) ?? (isTsSource(uiPkg.main) ? uiPkg.main : void 0) : declared;
1875
1918
  if (typeof mainTypes === "string") typeEntries.add(mainTypes);
1876
- for (const target of Object.values(uiPkg.exports ?? {})) {
1877
- const t = exportTypes(target);
1919
+ for (const target of subpaths) {
1920
+ const t = entryOf(target);
1878
1921
  if (typeof t === "string" && !t.includes("*")) typeEntries.add(t);
1879
1922
  }
1880
1923
  const exportNames = /* @__PURE__ */ new Set();
1881
1924
  const reexportedPackages = /* @__PURE__ */ new Set();
1882
1925
  let readAny = false;
1883
- for (const entry of typeEntries) {
1884
- const file = path18.join(uiDir, entry);
1885
- if (!existsSync(file)) continue;
1926
+ const seen = /* @__PURE__ */ new Set();
1927
+ const readEntry = (file) => {
1928
+ if (seen.has(file) || !insidePackage(uiDir, file) || !existsSync(file)) return;
1929
+ seen.add(file);
1886
1930
  readAny = true;
1887
- const dts = readFileSync(file, "utf8");
1888
- for (const name of parseExportNames(dts)) exportNames.add(name);
1889
- for (const m of dts.matchAll(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*)\s*from\s*["']([^"'.][^"']*)["']/g)) {
1931
+ const code = fromSource ? stripComments(readFileSync(file, "utf8")) : readFileSync(file, "utf8");
1932
+ for (const name of fromSource ? parseSourceExportNames(code) : parseExportNames(code)) exportNames.add(name);
1933
+ for (const m of code.matchAll(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*)\s*from\s*["']([^"'.][^"']*)["']/g)) {
1890
1934
  reexportedPackages.add(packageName(m[1]));
1891
1935
  }
1892
- }
1936
+ if (fromSource) {
1937
+ for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
1938
+ const next = resolveSource(path19.dirname(file), m[1]);
1939
+ if (next) readEntry(next);
1940
+ }
1941
+ }
1942
+ };
1943
+ for (const entry of typeEntries) readEntry(path19.join(uiDir, entry));
1893
1944
  if (!readAny) {
1894
- throw new DoctorConfigError(`${uiPackage} has no type declarations to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
1945
+ const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
1946
+ throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
1895
1947
  }
1896
1948
  const valueDecls = /* @__PURE__ */ new Set();
1897
1949
  const typeDecls = /* @__PURE__ */ new Set();
1898
- const declRoot = typeof mainTypes === "string" ? path18.dirname(path18.join(uiDir, mainTypes)) : uiDir;
1899
- const declFiles = walkDts(declRoot);
1950
+ const declRoot = typeof mainTypes === "string" ? path19.dirname(path19.join(uiDir, mainTypes)) : uiDir;
1951
+ const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
1900
1952
  for (const pkg of reexportedPackages) {
1901
1953
  const dir = findPackageDir(uiDir, pkg);
1902
- if (dir) walkDts(path18.join(dir, "dist"), declFiles);
1954
+ if (dir) walkDts(path19.join(dir, "dist"), declFiles);
1903
1955
  }
1904
1956
  for (const file of declFiles) {
1905
1957
  const text = readFileSync(file, "utf8");
@@ -1931,6 +1983,72 @@ function packageName(specifier) {
1931
1983
  const parts = specifier.split("/");
1932
1984
  return parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
1933
1985
  }
1986
+ function parseSourceExportNames(code) {
1987
+ const names = parseExportNames(code);
1988
+ for (const m of code.matchAll(/export\s+(?:default\s+)?(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(?:var|class|function\*?)\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
1989
+ for (const m of code.matchAll(/export\s+\*\s+as\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
1990
+ return [...new Set(names)];
1991
+ }
1992
+ var TS_SOURCE = /\.(?:[cm]?tsx?)$/;
1993
+ var isTsSource = (v) => typeof v === "string" && TS_SOURCE.test(v) && !/\.d\.[cm]?ts$/.test(v);
1994
+ function exportSource(target) {
1995
+ if (isTsSource(target)) return target;
1996
+ if (!target || typeof target !== "object") return void 0;
1997
+ for (const value of Object.values(target)) {
1998
+ const nested = exportSource(value);
1999
+ if (nested) return nested;
2000
+ }
2001
+ return void 0;
2002
+ }
2003
+ function resolveSource(dir, spec) {
2004
+ const base = path19.resolve(dir, spec.replace(/\.js$/, ""));
2005
+ const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path19.join(base, i))];
2006
+ return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
2007
+ }
2008
+ function insidePackage(dir, file) {
2009
+ const rel = path19.relative(path19.resolve(dir), path19.resolve(file));
2010
+ return rel === "" || !rel.startsWith("..") && !path19.isAbsolute(rel);
2011
+ }
2012
+ function stripComments(code) {
2013
+ let out = "";
2014
+ let i = 0;
2015
+ while (i < code.length) {
2016
+ const c = code[i];
2017
+ const next = code[i + 1];
2018
+ if (c === "/" && next === "*") {
2019
+ const end = code.indexOf("*/", i + 2);
2020
+ const stop = end < 0 ? code.length : end + 2;
2021
+ out += code.slice(i, stop).replace(/[^\n]/g, " ");
2022
+ i = stop;
2023
+ } else if (c === "/" && next === "/") {
2024
+ const end = code.indexOf("\n", i);
2025
+ i = end < 0 ? code.length : end;
2026
+ } else if (c === '"' || c === "'" || c === "`") {
2027
+ let j = i + 1;
2028
+ while (j < code.length && code[j] !== c) {
2029
+ if (code[j] === "\\") j++;
2030
+ else if (c !== "`" && code[j] === "\n") break;
2031
+ j++;
2032
+ }
2033
+ out += code.slice(i, j + 1);
2034
+ i = j + 1;
2035
+ } else {
2036
+ out += c;
2037
+ i++;
2038
+ }
2039
+ }
2040
+ return out;
2041
+ }
2042
+ function walkSource(dir, out = []) {
2043
+ if (!existsSync(dir)) return out;
2044
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
2045
+ if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
2046
+ const p = path19.join(dir, entry.name);
2047
+ if (entry.isDirectory()) walkSource(p, out);
2048
+ else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
2049
+ }
2050
+ return out;
2051
+ }
1934
2052
  function exportTypes(target) {
1935
2053
  if (!target || typeof target !== "object") return void 0;
1936
2054
  const t = target;
@@ -1945,7 +2063,7 @@ function walkDts(dir, out = []) {
1945
2063
  if (!existsSync(dir)) return out;
1946
2064
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
1947
2065
  if (entry.name === "node_modules") continue;
1948
- const p = path18.join(dir, entry.name);
2066
+ const p = path19.join(dir, entry.name);
1949
2067
  if (entry.isDirectory()) walkDts(p, out);
1950
2068
  else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
1951
2069
  }
@@ -1962,27 +2080,27 @@ function resolveThemeFiles(root, config, uiDir) {
1962
2080
  }
1963
2081
  const files = [];
1964
2082
  const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
1965
- const themes = ds && path18.join(ds, "dist", "themes");
2083
+ const themes = ds && path19.join(ds, "dist", "themes");
1966
2084
  if (themes && existsSync(themes)) {
1967
- for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path18.join(themes, name));
2085
+ for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path19.join(themes, name));
1968
2086
  }
1969
2087
  if (files.length === 0) {
1970
2088
  throw new DoctorConfigError(
1971
2089
  `No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
1972
2090
  );
1973
2091
  }
1974
- const uiStyles = path18.join(uiDir, "dist", "styles.css");
2092
+ const uiStyles = path19.join(uiDir, "dist", "styles.css");
1975
2093
  if (existsSync(uiStyles)) files.push(uiStyles);
1976
2094
  return files;
1977
2095
  }
1978
2096
  function resolveSpec(root, spec) {
1979
- const local = path18.resolve(root, spec);
1980
- if (spec.startsWith(".") || path18.isAbsolute(spec)) return existsSync(local) ? local : null;
2097
+ const local = path19.resolve(root, spec);
2098
+ if (spec.startsWith(".") || path19.isAbsolute(spec)) return existsSync(local) ? local : null;
1981
2099
  const parts = spec.split("/");
1982
2100
  const nameLength = spec.startsWith("@") ? 2 : 1;
1983
2101
  const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
1984
2102
  if (dir) {
1985
- const file = path18.join(dir, ...parts.slice(nameLength));
2103
+ const file = path19.join(dir, ...parts.slice(nameLength));
1986
2104
  if (existsSync(file) && statSync(file).isFile()) return file;
1987
2105
  }
1988
2106
  return existsSync(local) ? local : null;
@@ -1990,7 +2108,7 @@ function resolveSpec(root, spec) {
1990
2108
  function loadPalette(root) {
1991
2109
  const names = new Set(TAILWIND_PALETTE);
1992
2110
  try {
1993
- const req = createRequire(path18.join(root, "package.json"));
2111
+ const req = createRequire(path19.join(root, "package.json"));
1994
2112
  const colors = req("tailwindcss/colors");
1995
2113
  for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
1996
2114
  if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
@@ -2133,7 +2251,8 @@ function parseManifest(home, id, raw, version, options = {}) {
2133
2251
  if (!isObject2(f) || typeof f["name"] !== "string" || typeof f["summary"] !== "string") problems.push(`${at}.feature: needs a name and a summary`);
2134
2252
  else {
2135
2253
  feature = { name: f["name"], summary: f["summary"] };
2136
- if (typeof f["layer"] === "string") feature.layer = f["layer"];
2254
+ const kind = f["kind"] ?? f["layer"];
2255
+ if (typeof kind === "string") feature.kind = kind === "primitive" ? "element" : kind;
2137
2256
  if (strings(f["keywords"])) feature.keywords = f["keywords"];
2138
2257
  if (strings(f["audience"])) feature.audience = f["audience"];
2139
2258
  }
@@ -2178,8 +2297,8 @@ function rawBlocksOf(packageJson) {
2178
2297
 
2179
2298
  // src/blocks/files.ts
2180
2299
  function inside(parent, child) {
2181
- const rel = path18.relative(parent, child);
2182
- return rel === "" || !rel.startsWith("..") && !path18.isAbsolute(rel);
2300
+ const rel = path19.relative(parent, child);
2301
+ return rel === "" || !rel.startsWith("..") && !path19.isAbsolute(rel);
2183
2302
  }
2184
2303
 
2185
2304
  // src/blocks/local.ts
@@ -2192,8 +2311,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
2192
2311
  return raw.map((entry, i) => {
2193
2312
  const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
2194
2313
  if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
2195
- if (path18.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
2196
- const norm = path18.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
2314
+ if (path19.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
2315
+ const norm = path19.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
2197
2316
  if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
2198
2317
  const parts = norm.split("/");
2199
2318
  if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
@@ -2204,7 +2323,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
2204
2323
  });
2205
2324
  }
2206
2325
  function localPackageGlobs(root) {
2207
- const file = path18.join(root, "genesis.config.json");
2326
+ const file = path19.join(root, "genesis.config.json");
2208
2327
  if (!existsSync(file)) return [];
2209
2328
  let raw;
2210
2329
  try {
@@ -2218,14 +2337,14 @@ function localPackageGlobs(root) {
2218
2337
  var cache = /* @__PURE__ */ new Map();
2219
2338
  function repositoryRoot(appRoot) {
2220
2339
  for (let dir = appRoot; ; ) {
2221
- if (existsSync(path18.join(dir, ".git"))) return dir;
2222
- const parent = path18.dirname(dir);
2340
+ if (existsSync(path19.join(dir, ".git"))) return dir;
2341
+ const parent = path19.dirname(dir);
2223
2342
  if (parent === dir) return appRoot;
2224
2343
  dir = parent;
2225
2344
  }
2226
2345
  }
2227
2346
  function localPackages(root) {
2228
- const appRoot = path18.resolve(root);
2347
+ const appRoot = path19.resolve(root);
2229
2348
  const globs = localPackageGlobs(appRoot);
2230
2349
  const key2 = `${appRoot}
2231
2350
  ${globs.join("\n")}`;
@@ -2234,24 +2353,24 @@ ${globs.join("\n")}`;
2234
2353
  const dirs = /* @__PURE__ */ new Set();
2235
2354
  for (const glob of globs) {
2236
2355
  if (glob.endsWith("/*") || glob === "*") {
2237
- const parent = path18.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
2356
+ const parent = path19.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
2238
2357
  if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
2239
2358
  for (const entry of readdirSync(parent).sort()) {
2240
2359
  if (entry.startsWith(".") || entry === "node_modules") continue;
2241
- dirs.add(path18.join(parent, entry));
2360
+ dirs.add(path19.join(parent, entry));
2242
2361
  }
2243
2362
  } else {
2244
- dirs.add(path18.join(appRoot, glob));
2363
+ dirs.add(path19.join(appRoot, glob));
2245
2364
  }
2246
2365
  }
2247
2366
  const real2 = realpathSync(repositoryRoot(appRoot));
2248
2367
  const out = [];
2249
2368
  const byName = /* @__PURE__ */ new Map();
2250
2369
  for (const dir of [...dirs].sort()) {
2251
- const manifest = path18.join(dir, "package.json");
2370
+ const manifest = path19.join(dir, "package.json");
2252
2371
  if (!existsSync(manifest)) continue;
2253
2372
  if (!inside(real2, realpathSync(dir))) {
2254
- throw new LocalPackagesError(`${path18.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
2373
+ throw new LocalPackagesError(`${path19.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
2255
2374
  }
2256
2375
  let pkg;
2257
2376
  try {
@@ -2260,7 +2379,7 @@ ${globs.join("\n")}`;
2260
2379
  continue;
2261
2380
  }
2262
2381
  if (typeof pkg.name !== "string" || !pkg.name) continue;
2263
- const rel = path18.relative(appRoot, dir).split(path18.sep).join("/");
2382
+ const rel = path19.relative(appRoot, dir).split(path19.sep).join("/");
2264
2383
  const other = byName.get(pkg.name);
2265
2384
  if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
2266
2385
  byName.set(pkg.name, rel);
@@ -2445,16 +2564,16 @@ var DEFAULT_IGNORE = [
2445
2564
  ];
2446
2565
  var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
2447
2566
  var MAX_FILE_BYTES = 2 * 1024 * 1024;
2448
- var toPosix = (p) => p.split(path18.sep).join("/");
2567
+ var toPosix = (p) => p.split(path19.sep).join("/");
2449
2568
  function scanFiles(root, config) {
2450
2569
  const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
2451
2570
  const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
2452
2571
  const files = [];
2453
2572
  const seen = /* @__PURE__ */ new Set();
2454
2573
  const visit = (abs) => {
2455
- const rel = toPosix(path18.relative(root, abs));
2574
+ const rel = toPosix(path19.relative(root, abs));
2456
2575
  if (seen.has(rel) || ignored(rel)) return;
2457
- const ext = path18.extname(abs);
2576
+ const ext = path19.extname(abs);
2458
2577
  if (!extensions.has(ext)) return;
2459
2578
  if (statSync(abs).size > MAX_FILE_BYTES) return;
2460
2579
  seen.add(rel);
@@ -2464,14 +2583,14 @@ function scanFiles(root, config) {
2464
2583
  const walk = (dir) => {
2465
2584
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
2466
2585
  if (entry.isDirectory()) {
2467
- if (!SKIP_DIRS.has(entry.name)) walk(path18.join(dir, entry.name));
2586
+ if (!SKIP_DIRS.has(entry.name)) walk(path19.join(dir, entry.name));
2468
2587
  } else if (entry.isFile()) {
2469
- visit(path18.join(dir, entry.name));
2588
+ visit(path19.join(dir, entry.name));
2470
2589
  }
2471
2590
  }
2472
2591
  };
2473
2592
  for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
2474
- const abs = path18.resolve(root, src);
2593
+ const abs = path19.resolve(root, src);
2475
2594
  if (!existsSync(abs)) continue;
2476
2595
  if (statSync(abs).isDirectory()) walk(abs);
2477
2596
  else visit(abs);
@@ -2559,7 +2678,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
2559
2678
  const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
2560
2679
  let all = compiled;
2561
2680
  if (rulesDoc) {
2562
- const file = path18.resolve(root, rulesDoc);
2681
+ const file = path19.resolve(root, rulesDoc);
2563
2682
  if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
2564
2683
  const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
2565
2684
  const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
@@ -2620,15 +2739,112 @@ async function loadPlugins(specs, configDir) {
2620
2739
  }
2621
2740
  function resolvePlugin(id, configDir) {
2622
2741
  try {
2623
- if (id.startsWith(".") || path18.isAbsolute(id)) return resolveFrom(path18.resolve(configDir, id), configDir);
2742
+ if (id.startsWith(".") || path19.isAbsolute(id)) return resolveFrom(path19.resolve(configDir, id), configDir);
2624
2743
  return resolveFrom(id, configDir);
2625
2744
  } catch {
2626
2745
  throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
2627
2746
  }
2628
2747
  }
2629
2748
  function resolveFrom(id, from) {
2630
- return createRequire(path18.join(from, "noop.js")).resolve(id);
2749
+ return createRequire(path19.join(from, "noop.js")).resolve(id);
2750
+ }
2751
+ var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
2752
+ var OVERLAY_NOTICE_DAYS = 14;
2753
+ var OVERLAY_WARN_DAYS = 30;
2754
+ function overlayState(name, json) {
2755
+ const raw = json?.genesis?.overlay;
2756
+ if (raw === void 0) return { kind: "none" };
2757
+ const problems = [];
2758
+ const marker = readOverlayMarker(name, raw, problems);
2759
+ return marker ? { kind: "marked", marker } : { kind: "invalid", problems };
2760
+ }
2761
+ function overlaySetupProblems(root, config, dir, name, json) {
2762
+ const problems = [];
2763
+ if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
2764
+ const rel = path19.relative(path19.resolve(root), path19.resolve(dir)).split(path19.sep).join("/");
2765
+ const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
2766
+ const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
2767
+ if (holds !== void 0) problems.push(`${name}: an overlay lives in a package folder of its own, not in ${rel || "the app root"}, which holds the app's source (${holds})`);
2768
+ return problems;
2769
+ }
2770
+ function markedOverlays(ctx) {
2771
+ const out = /* @__PURE__ */ new Map();
2772
+ for (const p of ctx.packages) {
2773
+ if (!p.local || !p.overlay) continue;
2774
+ if (overlaySetupProblems(ctx.root, ctx.config, p.dir, p.name, { private: p.private }).length) continue;
2775
+ out.set(p.name, { dir: p.dir, marker: p.overlay });
2776
+ }
2777
+ return out;
2778
+ }
2779
+ function insideOverlayOf(overlays, file, packageName3) {
2780
+ const dir = overlays.get(packageName3)?.dir;
2781
+ return dir !== void 0 && inside(dir, file.absolutePath);
2782
+ }
2783
+ function overlayAgeDays(since, now = /* @__PURE__ */ new Date()) {
2784
+ const [y, m, d] = since.split("-").map(Number);
2785
+ const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
2786
+ return Math.floor((today - Date.UTC(y, m - 1, d)) / 864e5);
2787
+ }
2788
+ var LOCAL_VERSION = /^(\d+\.\d+\.\d+(?:-(?!local\.)[0-9A-Za-z.-]+?)?)(?:[+-]local\.(?:0|[1-9]\d*))?$/;
2789
+ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
2790
+ let packages;
2791
+ try {
2792
+ packages = localPackages(ctx.root);
2793
+ } catch {
2794
+ return;
2795
+ }
2796
+ for (const pkg of packages) {
2797
+ if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
2798
+ const file = `${pkg.rel}/package.json`;
2799
+ let json;
2800
+ try {
2801
+ json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
2802
+ } catch {
2803
+ continue;
2804
+ }
2805
+ const state = overlayState(pkg.name, json);
2806
+ if (state.kind === "none") {
2807
+ ctx.report({
2808
+ rule: "overlay-unmarked",
2809
+ file,
2810
+ subject: pkg.name,
2811
+ message: `${pkg.name} is a local package with a Genesis package's name, so it shadows the published one, but it carries no overlay marker; add "genesis": { "overlay": { "upstream": "${pkg.name}@<version copied>", "since": "YYYY-MM-DD", "owner": "\u2026", "reason": "\u2026" } }, or rename it`
2812
+ });
2813
+ continue;
2814
+ }
2815
+ if (state.kind === "invalid") {
2816
+ for (const problem of state.problems) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
2817
+ continue;
2818
+ }
2819
+ const { marker } = state;
2820
+ for (const problem of overlaySetupProblems(ctx.root, ctx.config, pkg.dir, pkg.name, json)) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
2821
+ const age = overlayAgeDays(marker.since, now);
2822
+ if (age < -1) {
2823
+ ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: `${pkg.name} genesis.overlay.since: ${marker.since} is in the future; use the day the overlay was made` });
2824
+ } else if (age > OVERLAY_NOTICE_DAYS) {
2825
+ ctx.report({
2826
+ rule: "overlay-age",
2827
+ level: age > OVERLAY_WARN_DAYS ? "warn" : "info",
2828
+ file,
2829
+ subject: pkg.name,
2830
+ message: `the overlay of ${marker.upstream} is ${age} days old (since ${marker.since}, owner ${marker.owner}); promote its change to Genesis and adopt the release, or drop it (an overlay is reported after ${OVERLAY_NOTICE_DAYS} days, and after ${OVERLAY_WARN_DAYS} it warns, which fails --strict)`
2831
+ });
2832
+ }
2833
+ const upstream = overlayUpstream(marker).version;
2834
+ const version = typeof json.version === "string" ? json.version : "";
2835
+ if (LOCAL_VERSION.exec(version)?.[1] !== upstream) {
2836
+ ctx.report({
2837
+ rule: "overlay-version",
2838
+ level: "warn",
2839
+ file,
2840
+ subject: version || "(none)",
2841
+ message: `the overlay of ${marker.upstream} is version ${version || "(none)"}; use ${upstream}+local.N (or ${upstream} itself) so it reads as a local build of ${upstream} and still satisfies peer ranges`
2842
+ });
2843
+ }
2844
+ }
2631
2845
  }
2846
+
2847
+ // src/doctor/rules.ts
2632
2848
  var BUILTIN_RULES = [
2633
2849
  "local-primitives",
2634
2850
  "starter-leftover",
@@ -2654,6 +2870,9 @@ var BUILTIN_RULES = [
2654
2870
  "studio-server-auth-import",
2655
2871
  "removed-scope-name",
2656
2872
  "scope-practice-id",
2873
+ // export maturity (stability.ts)
2874
+ "deprecated-import",
2875
+ "beta-import",
2657
2876
  // native pack
2658
2877
  "native-raw-primitive",
2659
2878
  "native-literal-color",
@@ -2679,6 +2898,11 @@ var BUILTIN_RULES = [
2679
2898
  "package-block-invalid",
2680
2899
  "package-untagged-tests",
2681
2900
  "package-doctor-declaration",
2901
+ // overlays (overlays.ts)
2902
+ "overlay-unmarked",
2903
+ "overlay-invalid",
2904
+ "overlay-age",
2905
+ "overlay-version",
2682
2906
  // package rules (package-rules.ts): the rules themselves are namespaced, e.g. ui/lists-use-resource-view
2683
2907
  "package-rules-invalid",
2684
2908
  "package-rule-override",
@@ -2707,7 +2931,7 @@ function importSpecifiers(file) {
2707
2931
  }
2708
2932
  function checkProjectLayout(ctx) {
2709
2933
  for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
2710
- if (existsSync(path18.join(ctx.root, dir))) {
2934
+ if (existsSync(path19.join(ctx.root, dir))) {
2711
2935
  ctx.report({
2712
2936
  rule: "local-primitives",
2713
2937
  file: dir,
@@ -2717,7 +2941,7 @@ function checkProjectLayout(ctx) {
2717
2941
  }
2718
2942
  }
2719
2943
  for (const file of STARTER_LEFTOVERS) {
2720
- if (existsSync(path18.join(ctx.root, file))) {
2944
+ if (existsSync(path19.join(ctx.root, file))) {
2721
2945
  ctx.report({
2722
2946
  rule: "starter-leftover",
2723
2947
  level: "warn",
@@ -2747,8 +2971,9 @@ function checkImports(ctx) {
2747
2971
  function checkRawTags(ctx) {
2748
2972
  const tags = [...ctx.genesis.rawTags].map(([tag, component]) => [tag, component, new RegExp(`<${tag}(?=[\\s>/]|$)`)]);
2749
2973
  if (tags.length === 0) return;
2974
+ const overlays = markedOverlays(ctx);
2750
2975
  for (const file of ctx.files) {
2751
- if (!JSX_EXTS.has(file.ext)) continue;
2976
+ if (!JSX_EXTS.has(file.ext) || insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
2752
2977
  file.code.split("\n").forEach((text, i) => {
2753
2978
  for (const [tag, component, re] of tags) {
2754
2979
  if (re.test(text)) {
@@ -2806,7 +3031,7 @@ function checkTokens(ctx) {
2806
3031
  }
2807
3032
  for (const pattern of ctx.config.tokenFiles ?? []) {
2808
3033
  if (/[*?]/.test(pattern)) continue;
2809
- const abs = path18.join(ctx.root, pattern);
3034
+ const abs = path19.join(ctx.root, pattern);
2810
3035
  if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
2811
3036
  for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
2812
3037
  }
@@ -2823,9 +3048,10 @@ function checkTokens(ctx) {
2823
3048
  }
2824
3049
  }
2825
3050
  function checkShadowedExports(ctx) {
3051
+ const overlays = markedOverlays(ctx);
2826
3052
  const re = /\bexport\s+(?:default\s+)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)/g;
2827
3053
  for (const file of ctx.files) {
2828
- if (!SCRIPT_EXTS.has(file.ext)) continue;
3054
+ if (!SCRIPT_EXTS.has(file.ext) || insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
2829
3055
  file.code.split("\n").forEach((text, i) => {
2830
3056
  for (const m of text.matchAll(re)) {
2831
3057
  if (!ctx.genesis.values.has(m[1])) continue;
@@ -2909,10 +3135,10 @@ var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts"
2909
3135
  var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
2910
3136
  var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
2911
3137
  function resolveLocal(root, fromFile, spec) {
2912
- const bases = spec.startsWith(".") ? [path18.resolve(path18.dirname(fromFile), spec)] : [path18.join(root, spec.slice(2)), path18.join(root, "src", spec.slice(2))];
3138
+ const bases = spec.startsWith(".") ? [path19.resolve(path19.dirname(fromFile), spec)] : [path19.join(root, spec.slice(2)), path19.join(root, "src", spec.slice(2))];
2913
3139
  for (const base of bases) {
2914
- const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path18.join(base, `index${e}`))].find(
2915
- (p) => SCRIPT_EXTS2.has(path18.extname(p)) && existsSync(p)
3140
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path19.join(base, `index${e}`))].find(
3141
+ (p) => SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p)
2916
3142
  );
2917
3143
  if (hit) return hit;
2918
3144
  }
@@ -3032,6 +3258,7 @@ function checkNativePack(ctx) {
3032
3258
  }
3033
3259
  var RN = String.raw`["']react-native["']`;
3034
3260
  function checkRawPrimitives(ctx, pkg) {
3261
+ const overlays = markedOverlays(ctx);
3035
3262
  const wrapped = Object.keys(NATIVE_WRAPPED_PRIMITIVES);
3036
3263
  const named = [
3037
3264
  // import { Modal } / import RN, { Modal }; `import type { … }` doesn't match.
@@ -3045,7 +3272,7 @@ function checkRawPrimitives(ctx, pkg) {
3045
3272
  ];
3046
3273
  const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
3047
3274
  for (const file of ctx.files) {
3048
- if (!SCRIPT_EXTS3.has(file.ext)) continue;
3275
+ if (!SCRIPT_EXTS3.has(file.ext) || insideOverlayOf(overlays, file, NATIVE_UI_PACKAGE)) continue;
3049
3276
  const code = file.code;
3050
3277
  const report = (name, at) => {
3051
3278
  const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
@@ -3094,7 +3321,7 @@ function checkCustomHeaders(ctx, pkg) {
3094
3321
  if (!JSX_EXTS3.has(file.ext)) continue;
3095
3322
  const code = file.code;
3096
3323
  const hidden = HIDES_HEADER.exec(code);
3097
- if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path18.posix.dirname(file.path), file.path);
3324
+ if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path19.posix.dirname(file.path), file.path);
3098
3325
  const own = hidden ? ownHeader(code, pkg) : null;
3099
3326
  if (hidden && own) {
3100
3327
  reported.add(file.path);
@@ -3122,7 +3349,7 @@ function checkCustomHeaders(ctx, pkg) {
3122
3349
  }
3123
3350
  for (const file of ctx.files) {
3124
3351
  if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
3125
- const layout = hidingLayouts.get(path18.posix.dirname(file.path));
3352
+ const layout = hidingLayouts.get(path19.posix.dirname(file.path));
3126
3353
  const own = layout ? ownHeader(file.code, pkg) : null;
3127
3354
  if (!layout || !own) continue;
3128
3355
  ctx.report({
@@ -3144,13 +3371,13 @@ function isLoadingOnlyRoute(code) {
3144
3371
  }
3145
3372
  function routerRoot(ctx) {
3146
3373
  if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
3147
- return existsSync(path18.join(ctx.root, "src", "app")) ? "src/app" : "app";
3374
+ return existsSync(path19.join(ctx.root, "src", "app")) ? "src/app" : "app";
3148
3375
  }
3149
3376
  function checkScreenLayouts(ctx, pkg) {
3150
3377
  const layouts = nativeLayouts(pkg);
3151
3378
  if (layouts.length === 0) return;
3152
3379
  const rootDir = routerRoot(ctx);
3153
- if (!existsSync(path18.join(ctx.root, rootDir))) {
3380
+ if (!existsSync(path19.join(ctx.root, rootDir))) {
3154
3381
  ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
3155
3382
  return;
3156
3383
  }
@@ -3206,7 +3433,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
3206
3433
  function readExpoConfigs(root) {
3207
3434
  const out = [];
3208
3435
  for (const name of EXPO_CONFIGS) {
3209
- const abs = path18.join(root, name);
3436
+ const abs = path19.join(root, name);
3210
3437
  if (!existsSync(abs)) continue;
3211
3438
  const text = readFileSync(abs, "utf8");
3212
3439
  let json = null;
@@ -3240,13 +3467,13 @@ function pluginOptions(json, module) {
3240
3467
  return null;
3241
3468
  }
3242
3469
  function dependencies(root) {
3243
- const file = path18.join(root, "package.json");
3470
+ const file = path19.join(root, "package.json");
3244
3471
  if (!existsSync(file)) return /* @__PURE__ */ new Set();
3245
3472
  const pkg = JSON.parse(readFileSync(file, "utf8"));
3246
3473
  return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
3247
3474
  }
3248
3475
  function runtimeDependencies(root) {
3249
- const file = path18.join(root, "package.json");
3476
+ const file = path19.join(root, "package.json");
3250
3477
  if (!existsSync(file)) return {};
3251
3478
  return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
3252
3479
  }
@@ -3620,14 +3847,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3620
3847
  seen.add(file);
3621
3848
  const json = readJsonc(file);
3622
3849
  if (!json) return {};
3623
- const dir = path18.dirname(file);
3850
+ const dir = path19.dirname(file);
3624
3851
  let merged = {};
3625
3852
  const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
3626
3853
  for (const ext of parents) {
3627
3854
  if (typeof ext !== "string") continue;
3628
3855
  let target = null;
3629
- if (ext.startsWith(".") || path18.isAbsolute(ext)) {
3630
- const abs = path18.resolve(dir, ext);
3856
+ if (ext.startsWith(".") || path19.isAbsolute(ext)) {
3857
+ const abs = path19.resolve(dir, ext);
3631
3858
  target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3632
3859
  } else {
3633
3860
  const parts = ext.split("/");
@@ -3635,14 +3862,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3635
3862
  const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
3636
3863
  if (pkgDir) {
3637
3864
  const sub = parts.slice(nameLength).join("/");
3638
- const abs = path18.join(pkgDir, sub || "tsconfig.json");
3865
+ const abs = path19.join(pkgDir, sub || "tsconfig.json");
3639
3866
  target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3640
3867
  }
3641
3868
  }
3642
3869
  if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
3643
3870
  }
3644
3871
  const opts = json.compilerOptions ?? {};
3645
- if (typeof opts.baseUrl === "string") merged.baseUrl = path18.resolve(dir, opts.baseUrl);
3872
+ if (typeof opts.baseUrl === "string") merged.baseUrl = path19.resolve(dir, opts.baseUrl);
3646
3873
  if (opts.paths && typeof opts.paths === "object") {
3647
3874
  merged.paths = opts.paths;
3648
3875
  merged.pathsDir = dir;
@@ -3653,7 +3880,7 @@ function aliases(root) {
3653
3880
  const table = [];
3654
3881
  let baseUrl = null;
3655
3882
  for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
3656
- const file = path18.join(root, name);
3883
+ const file = path19.join(root, name);
3657
3884
  if (!existsSync(file)) continue;
3658
3885
  const config = readTsconfig(root, file);
3659
3886
  baseUrl ??= config.baseUrl ?? null;
@@ -3661,22 +3888,22 @@ function aliases(root) {
3661
3888
  for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
3662
3889
  if (!Array.isArray(targets)) continue;
3663
3890
  const exact = !pattern.endsWith("*");
3664
- table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path18.join(base, String(t).replace(/\*$/, ""))) });
3891
+ table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path19.join(base, String(t).replace(/\*$/, ""))) });
3665
3892
  }
3666
3893
  }
3667
- const pkg = readJsonc(path18.join(root, "package.json"));
3894
+ const pkg = readJsonc(path19.join(root, "package.json"));
3668
3895
  for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
3669
3896
  if (typeof target !== "string") continue;
3670
- table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path18.join(root, target.replace(/\*.*$/, ""))] });
3897
+ table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path19.join(root, target.replace(/\*.*$/, ""))] });
3671
3898
  }
3672
- for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path18.join(root, "src") + path18.sep, root + path18.sep] });
3899
+ for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path19.join(root, "src") + path19.sep, root + path19.sep] });
3673
3900
  return { table, baseUrl };
3674
3901
  }
3675
3902
  function resolveFile(base) {
3676
- const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path18.join(base, `index${e}`))];
3903
+ const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path19.join(base, `index${e}`))];
3677
3904
  if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
3678
3905
  for (const p of tries) {
3679
- if (SCRIPT_EXTS2.has(path18.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
3906
+ if (SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
3680
3907
  }
3681
3908
  return null;
3682
3909
  }
@@ -3690,7 +3917,7 @@ function createTrail(ctx) {
3690
3917
  const { table, baseUrl } = aliases(ctx.root);
3691
3918
  let declared = null;
3692
3919
  try {
3693
- const pkg = JSON.parse(readFileSync(path18.join(ctx.root, "package.json"), "utf8"));
3920
+ const pkg = JSON.parse(readFileSync(path19.join(ctx.root, "package.json"), "utf8"));
3694
3921
  declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
3695
3922
  } catch {
3696
3923
  declared = null;
@@ -3721,17 +3948,17 @@ function createTrail(ctx) {
3721
3948
  if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
3722
3949
  let resolved = null;
3723
3950
  if (spec.startsWith(".")) {
3724
- resolved = resolveFile(path18.resolve(path18.dirname(file.absolutePath), spec));
3951
+ resolved = resolveFile(path19.resolve(path19.dirname(file.absolutePath), spec));
3725
3952
  if (!resolved) lost = true;
3726
3953
  } else {
3727
3954
  const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
3728
3955
  if (alias) {
3729
3956
  for (const t of alias.targets) {
3730
- resolved = resolveFile(alias.exact ? t : path18.join(t, spec.slice(alias.prefix.length)));
3957
+ resolved = resolveFile(alias.exact ? t : path19.join(t, spec.slice(alias.prefix.length)));
3731
3958
  if (resolved) break;
3732
3959
  }
3733
3960
  }
3734
- if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path18.join(baseUrl, spec));
3961
+ if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path19.join(baseUrl, spec));
3735
3962
  if (!resolved) {
3736
3963
  const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
3737
3964
  if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
@@ -3807,18 +4034,18 @@ function createTrail(ctx) {
3807
4034
  var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
3808
4035
  function installedGenesis(root) {
3809
4036
  const found = /* @__PURE__ */ new Map();
3810
- let dir = path18.resolve(root);
4037
+ let dir = path19.resolve(root);
3811
4038
  for (; ; ) {
3812
- const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path18.join(dir, m)));
3813
- const scope = path18.join(dir, "node_modules", "@marktiderman");
4039
+ const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path19.join(dir, m)));
4040
+ const scope = path19.join(dir, "node_modules", "@marktiderman");
3814
4041
  if (existsSync(scope)) {
3815
4042
  for (const entry of readdirSync(scope)) {
3816
4043
  const name = `@marktiderman/${entry}`;
3817
4044
  if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
3818
- if (existsSync(path18.join(scope, entry, "package.json"))) found.set(name, path18.join(scope, entry));
4045
+ if (existsSync(path19.join(scope, entry, "package.json"))) found.set(name, path19.join(scope, entry));
3819
4046
  }
3820
4047
  }
3821
- const parent = path18.dirname(dir);
4048
+ const parent = path19.dirname(dir);
3822
4049
  if (atInstallRoot || parent === dir) return found;
3823
4050
  dir = parent;
3824
4051
  }
@@ -3840,7 +4067,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
3840
4067
  var OWN_CONTENT = /(?<![=-])>\s*[A-Za-z][^<>{}]*</.source + "|" + /(?<![\w$.])<(?:h[1-6]|ul|ol|table|dl|H[1-6]|[A-Z]\w*(?:Heading|Title|Table|List|Grid))(?=[\s>/])/.source;
3841
4068
  function routesDir(ctx) {
3842
4069
  if (ctx.config.routesDir) return ctx.config.routesDir;
3843
- return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path18.join(ctx.root, d))) ?? null;
4070
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path19.join(ctx.root, d))) ?? null;
3844
4071
  }
3845
4072
  var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
3846
4073
  function flavorOf(dir, rels) {
@@ -3941,7 +4168,7 @@ var PREFER_KEYS = /* @__PURE__ */ new Set(["id", "need", "level", "platform", "f
3941
4168
  var FORBID_KEYS = /* @__PURE__ */ new Set(["jsx", "imports", "pattern"]);
3942
4169
  var UNLESS_KEYS = /* @__PURE__ */ new Set(["renders", "pattern"]);
3943
4170
  var PRIMITIVE_KEYS = /* @__PURE__ */ new Set(["need", "use", "import", "docs"]);
3944
- var DECLARATION_KEYS = /* @__PURE__ */ new Set(["enforce", "reason", "prefer", "primitives", "plugin", "$comment"]);
4171
+ var DECLARATION_KEYS = /* @__PURE__ */ new Set(["enforce", "reason", "prefer", "catalog", "primitives", "plugin", "$comment"]);
3945
4172
  var SCRIPT_GLOBS = ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.mts", "**/*.cts", "**/*.mjs", "**/*.cjs"];
3946
4173
  function ruleNamespace(packageName3) {
3947
4174
  const m = GENESIS.exec(packageName3);
@@ -3954,7 +4181,7 @@ function toRegExp2(source, flags = "") {
3954
4181
  if (source.startsWith("(?i)")) return new RegExp(source.slice(4), flags + "i");
3955
4182
  return new RegExp(source, flags);
3956
4183
  }
3957
- function validateDeclaration(raw, packageName3, packageDir, ignored) {
4184
+ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
3958
4185
  const fail = (msg) => {
3959
4186
  throw new PackageDeclarationError(`${packageName3}: genesis.doctor ${msg}`);
3960
4187
  };
@@ -3974,9 +4201,9 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
3974
4201
  }
3975
4202
  });
3976
4203
  if (typeof raw === "string") {
3977
- if (!packageDir) fail(`points at ${raw}, but the package folder is unknown`);
3978
- const file = path18.resolve(packageDir, raw);
3979
- if (!inside(packageDir, file)) fail(`points outside the package (${raw})`);
4204
+ if (!packageDir2) fail(`points at ${raw}, but the package folder is unknown`);
4205
+ const file = path19.resolve(packageDir2, raw);
4206
+ if (!inside(packageDir2, file)) fail(`points outside the package (${raw})`);
3980
4207
  if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
3981
4208
  let parsed;
3982
4209
  try {
@@ -3984,7 +4211,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
3984
4211
  } catch (err) {
3985
4212
  return fail(`file ${raw} is not valid JSON: ${err.message}`);
3986
4213
  }
3987
- return validateDeclaration(parsed, packageName3, packageDir, ignored);
4214
+ return validateDeclaration(parsed, packageName3, packageDir2, ignored);
3988
4215
  }
3989
4216
  if (raw === false) fail(`is false; say why with { "enforce": false, "reason": "\u2026" }`);
3990
4217
  if (!isObject3(raw)) fail(`must be an object (or a path to a JSON file in the package)`);
@@ -3995,8 +4222,10 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
3995
4222
  if (c.reason !== void 0 && (typeof c.reason !== "string" || !c.reason.trim())) fail(`reason must be a sentence`);
3996
4223
  const prefer = c.prefer === void 0 ? [] : c.prefer;
3997
4224
  if (!Array.isArray(prefer)) fail(`prefer must be a list`);
3998
- const primitives = c.primitives === void 0 ? [] : c.primitives;
3999
- if (!Array.isArray(primitives)) fail(`primitives must be a list`);
4225
+ if (c.catalog !== void 0 && c.primitives !== void 0) fail(`declares both catalog and primitives; keep catalog (primitives is its old name)`);
4226
+ const listKey = c.catalog !== void 0 ? "catalog" : "primitives";
4227
+ const primitives = c[listKey] === void 0 ? [] : c[listKey];
4228
+ if (!Array.isArray(primitives)) fail(`${listKey} must be a list`);
4000
4229
  if (c.plugin !== void 0 && (typeof c.plugin !== "string" || !c.plugin.trim())) fail(`plugin must be a module path inside the package`);
4001
4230
  if (!enforce) {
4002
4231
  if (typeof c.reason !== "string") fail(`turns enforcement off without a reason; add "reason"`);
@@ -4011,7 +4240,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
4011
4240
  ids.add(r.id);
4012
4241
  }
4013
4242
  const entries = each(primitives, (p, i) => {
4014
- const where2 = `primitives[${i}]`;
4243
+ const where2 = `${listKey}[${i}]`;
4015
4244
  if (!isObject3(p)) return fail(`${where2} must be an object`);
4016
4245
  for (const key2 of Object.keys(p)) if (!PRIMITIVE_KEYS.has(key2)) unknownKey(where2, key2);
4017
4246
  for (const key2 of ["need", "use"]) if (typeof p[key2] !== "string" || !p[key2].trim()) fail(`${where2} needs "${key2}"`);
@@ -4020,10 +4249,10 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
4020
4249
  });
4021
4250
  let plugin;
4022
4251
  if (typeof c.plugin === "string") {
4023
- if (!packageDir) plugin = c.plugin;
4252
+ if (!packageDir2) plugin = c.plugin;
4024
4253
  else {
4025
- plugin = path18.resolve(packageDir, c.plugin);
4026
- if (!inside(packageDir, plugin)) fail(`plugin points outside the package (${c.plugin})`);
4254
+ plugin = path19.resolve(packageDir2, c.plugin);
4255
+ if (!inside(packageDir2, plugin)) fail(`plugin points outside the package (${c.plugin})`);
4027
4256
  }
4028
4257
  }
4029
4258
  return {
@@ -4072,7 +4301,7 @@ function checkPattern(v, where2, fail) {
4072
4301
  }
4073
4302
  var discoveryCache = /* @__PURE__ */ new Map();
4074
4303
  function readDeclaringPackage(dir, local) {
4075
- const file = path18.join(dir, "package.json");
4304
+ const file = path19.join(dir, "package.json");
4076
4305
  let stamp;
4077
4306
  let real2;
4078
4307
  try {
@@ -4095,17 +4324,21 @@ ${local}`;
4095
4324
  const pkg = {
4096
4325
  name: json.name,
4097
4326
  version: typeof json.version === "string" ? json.version : "0.0.0",
4098
- dir: path18.resolve(dir),
4327
+ dir: path19.resolve(dir),
4099
4328
  namespace: ruleNamespace(json.name),
4100
4329
  local,
4101
4330
  private: json.private === true,
4102
4331
  declaration: null
4103
4332
  };
4333
+ if (local) {
4334
+ const state = overlayState(json.name, json);
4335
+ if (state.kind === "marked") pkg.overlay = state.marker;
4336
+ }
4104
4337
  const raw = json.genesis?.doctor;
4105
4338
  if (raw !== void 0) {
4106
4339
  const ignored = [];
4107
4340
  try {
4108
- pkg.declaration = validateDeclaration(raw, json.name, path18.resolve(dir), ignored);
4341
+ pkg.declaration = validateDeclaration(raw, json.name, path19.resolve(dir), ignored);
4109
4342
  if (ignored.length) pkg.ignored = ignored;
4110
4343
  } catch (err) {
4111
4344
  pkg.error = err.message;
@@ -4124,14 +4357,14 @@ function discoverPackages(root) {
4124
4357
  for (const dir of installed) {
4125
4358
  let scope;
4126
4359
  try {
4127
- scope = path18.dirname(realpathSync(dir));
4360
+ scope = path19.dirname(realpathSync(dir));
4128
4361
  } catch {
4129
4362
  continue;
4130
4363
  }
4131
- if (path18.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
4364
+ if (path19.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
4132
4365
  for (const entry of readdirSync(scope)) {
4133
4366
  if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
4134
- const pkg = readDeclaringPackage(path18.join(scope, entry), false);
4367
+ const pkg = readDeclaringPackage(path19.join(scope, entry), false);
4135
4368
  if (pkg) byName.set(pkg.name, pkg);
4136
4369
  }
4137
4370
  }
@@ -4300,7 +4533,7 @@ function unknownPackageRuleSettings(config, packages, reported) {
4300
4533
  level: "warn",
4301
4534
  file: "genesis config",
4302
4535
  subject: id,
4303
- message: `packageRules names ${id}, which no installed package declares; check the id (genesis primitives lists them) or remove it`
4536
+ message: `packageRules names ${id}, which no installed package declares; check the id (genesis catalog lists them) or remove it`
4304
4537
  }));
4305
4538
  }
4306
4539
  function packageRuleIds(packages) {
@@ -4315,10 +4548,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
4315
4548
  var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
4316
4549
  function sourceFiles(dir, rel = "") {
4317
4550
  const out = [];
4318
- for (const entry of readdirSync(path18.join(dir, rel)).sort()) {
4551
+ for (const entry of readdirSync(path19.join(dir, rel)).sort()) {
4319
4552
  if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
4320
4553
  const child = rel ? `${rel}/${entry}` : entry;
4321
- const stat = lstatSync(path18.join(dir, child));
4554
+ const stat = lstatSync(path19.join(dir, child));
4322
4555
  if (stat.isSymbolicLink()) continue;
4323
4556
  if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
4324
4557
  else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
@@ -4341,13 +4574,13 @@ function matchPattern(pattern, spec) {
4341
4574
  return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
4342
4575
  }
4343
4576
  function tsconfigPaths(dir) {
4344
- const file = path18.join(dir, "tsconfig.json");
4577
+ const file = path19.join(dir, "tsconfig.json");
4345
4578
  if (!existsSync(file)) return [];
4346
4579
  try {
4347
4580
  const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
4348
4581
  const options = JSON.parse(text).compilerOptions ?? {};
4349
- const base = path18.resolve(dir, options.baseUrl ?? ".");
4350
- return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path18.resolve(base, t)) }));
4582
+ const base = path19.resolve(dir, options.baseUrl ?? ".");
4583
+ return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path19.resolve(base, t)) }));
4351
4584
  } catch {
4352
4585
  return [];
4353
4586
  }
@@ -4361,8 +4594,8 @@ function checkImports2(ctx, pkg, json) {
4361
4594
  const hit = matchPattern(pattern, spec);
4362
4595
  if (hit === null) continue;
4363
4596
  return targets.some((t) => {
4364
- const rel = path18.relative(pkg.dir, t.replace("*", hit));
4365
- return !rel.startsWith("..") && !path18.isAbsolute(rel);
4597
+ const rel = path19.relative(pkg.dir, t.replace("*", hit));
4598
+ return !rel.startsWith("..") && !path19.isAbsolute(rel);
4366
4599
  });
4367
4600
  }
4368
4601
  return null;
@@ -4375,7 +4608,7 @@ function checkImports2(ctx, pkg, json) {
4375
4608
  ...Object.keys(json.optionalDependencies ?? {})
4376
4609
  ]);
4377
4610
  for (const file of sourceFiles(pkg.dir)) {
4378
- const code = stripForImports(readFileSync(path18.join(pkg.dir, file), "utf8"));
4611
+ const code = stripForImports(readFileSync(path19.join(pkg.dir, file), "utf8"));
4379
4612
  if (code === null) continue;
4380
4613
  const at = `${pkg.rel}/${file}`;
4381
4614
  const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
@@ -4400,9 +4633,9 @@ function checkImports2(ctx, pkg, json) {
4400
4633
  continue;
4401
4634
  }
4402
4635
  if (spec.startsWith(".")) {
4403
- const target = path18.resolve(pkg.dir, path18.dirname(file), spec);
4404
- const rel = path18.relative(pkg.dir, target);
4405
- if (rel.startsWith("..") || path18.isAbsolute(rel)) {
4636
+ const target = path19.resolve(pkg.dir, path19.dirname(file), spec);
4637
+ const rel = path19.relative(pkg.dir, target);
4638
+ if (rel.startsWith("..") || path19.isAbsolute(rel)) {
4406
4639
  ctx.report({ rule: "package-app-import", file: at, line, subject: spec, message: `${pkg.name} reaches outside its folder (${spec}); move what it needs into the package or a dependency` });
4407
4640
  }
4408
4641
  continue;
@@ -4416,20 +4649,35 @@ function checkImports2(ctx, pkg, json) {
4416
4649
  });
4417
4650
  }
4418
4651
  }
4419
- function checkMigrations(ctx, pkg, json) {
4652
+ var NPM_NAME = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
4653
+ function migrationHome(pkg, named, locals) {
4654
+ if (named === void 0 || named === pkg.name) return { dir: pkg.dir };
4655
+ if (typeof named !== "string" || !NPM_NAME.test(named) || named.split("/").some((s) => s === "." || s === "..")) return { problem: `names the package ${JSON.stringify(named)}, which isn't a valid package name` };
4656
+ const dir = locals.find((l) => l.name === named)?.dir ?? findPackageDir(pkg.dir, named);
4657
+ return dir ? { dir } : { problem: `names the package ${named}, which isn't installed or a local package, so its test can't be checked` };
4658
+ }
4659
+ function checkMigrations(ctx, pkg, json, locals) {
4420
4660
  const declaredFiles = /* @__PURE__ */ new Set();
4421
4661
  for (const [id, raw] of Object.entries(rawBlocksOf(json))) {
4422
4662
  const migrations = raw.migrations ?? [];
4423
4663
  for (const m of migrations) {
4424
- if (typeof m.file === "string" && typeof m.test === "string") declaredFiles.add(m.file);
4664
+ const found = migrationHome(pkg, m.package, locals);
4665
+ if ("problem" in found) {
4666
+ ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: typeof m.file === "string" ? m.file : id, message: `${pkg.name} block ${id}: a migration ${found.problem}` });
4667
+ continue;
4668
+ }
4669
+ const home = found.dir;
4670
+ const own = home === pkg.dir;
4671
+ if (own && typeof m.file === "string" && typeof m.test === "string") declaredFiles.add(m.file);
4672
+ const from = own ? "" : ` (in ${m.package})`;
4425
4673
  if (typeof m.file === "string" && typeof m.test !== "string") {
4426
- ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.file, message: `${pkg.name} block ${id}: ${m.file} has no pgTAP test; declare one as "test" beside it` });
4427
- } else if (typeof m.test === "string" && !existsSync(path18.join(pkg.dir, m.test))) {
4428
- ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.test, message: `${pkg.name} block ${id}: its test ${m.test} doesn't exist` });
4674
+ ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.file, message: `${pkg.name} block ${id}: ${m.file}${from} has no pgTAP test; declare one as "test" beside it` });
4675
+ } else if (typeof m.test === "string" && !existsSync(path19.join(home, m.test))) {
4676
+ ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.test, message: `${pkg.name} block ${id}: its test ${m.test}${from} doesn't exist` });
4429
4677
  }
4430
4678
  }
4431
4679
  }
4432
- const dir = path18.join(pkg.dir, "migrations");
4680
+ const dir = path19.join(pkg.dir, "migrations");
4433
4681
  if (!existsSync(dir)) return;
4434
4682
  const seen = /* @__PURE__ */ new Map();
4435
4683
  for (const name of readdirSync(dir).sort()) {
@@ -4438,7 +4686,7 @@ function checkMigrations(ctx, pkg, json) {
4438
4686
  const other = seen.get(m[1]);
4439
4687
  if (other) ctx.report({ rule: "package-migration-number", file: `${pkg.rel}/migrations/${name}`, subject: m[1], message: `${pkg.name}: ${name} and ${other} share the number ${m[1]}; give each migration its own` });
4440
4688
  else seen.set(m[1], name);
4441
- if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path18.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
4689
+ if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path19.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
4442
4690
  ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/migrations/${name}`, subject: name, message: `${pkg.name}: ${name} has no pgTAP test (migrations/tests/${name.replace(/\.sql$/, ".test.sql")})` });
4443
4691
  }
4444
4692
  }
@@ -4452,7 +4700,7 @@ function checkExports(ctx, pkg, json) {
4452
4700
  walk(json.exports);
4453
4701
  for (const t of targets) {
4454
4702
  if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
4455
- if (!existsSync(path18.join(pkg.dir, t))) {
4703
+ if (!existsSync(path19.join(pkg.dir, t))) {
4456
4704
  ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
4457
4705
  }
4458
4706
  }
@@ -4470,11 +4718,11 @@ function checkBlocks(ctx, pkg, json) {
4470
4718
  function checkTaggedTests(ctx, pkg) {
4471
4719
  const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
4472
4720
  if (!tests.length) return;
4473
- const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path18.join(pkg.dir, f), "utf8")));
4721
+ const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path19.join(pkg.dir, f), "utf8")));
4474
4722
  if (!tagged) ctx.report({ rule: "package-untagged-tests", level: "warn", file: pkg.rel, message: `${pkg.name}'s tests name no feature; tag them with // @feat:<feature id>` });
4475
4723
  }
4476
4724
  function checkRegistered(ctx, pkg) {
4477
- const file = path18.join(ctx.root, "features.json");
4725
+ const file = path19.join(ctx.root, "features.json");
4478
4726
  if (!existsSync(file)) return;
4479
4727
  let doc;
4480
4728
  try {
@@ -4484,7 +4732,7 @@ function checkRegistered(ctx, pkg) {
4484
4732
  }
4485
4733
  const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
4486
4734
  const forms = /* @__PURE__ */ new Set([pkg.rel]);
4487
- if (top) forms.add(path18.relative(top, realpathSync(pkg.dir)).split(path18.sep).join("/"));
4735
+ if (top) forms.add(path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/"));
4488
4736
  const covered = (doc.features ?? []).some(
4489
4737
  (f) => (f.links?.code ?? []).some((c) => {
4490
4738
  const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
@@ -4514,8 +4762,8 @@ function mergeBaseOf(root, base) {
4514
4762
  function checkChanges(ctx, pkg, json, base, mergeBase) {
4515
4763
  const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
4516
4764
  if (!top) return;
4517
- const appRelative = (fromTop) => path18.relative(realpathSync(ctx.root), path18.join(top, fromTop)).split(path18.sep).join("/");
4518
- const inRepo = path18.relative(top, realpathSync(pkg.dir)).split(path18.sep).join("/");
4765
+ const appRelative = (fromTop) => path19.relative(realpathSync(ctx.root), path19.join(top, fromTop)).split(path19.sep).join("/");
4766
+ const inRepo = path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/");
4519
4767
  const diff = (git(top, ["diff", "--name-status", "-M", mergeBase, "--", inRepo]) ?? "").split("\n").filter(Boolean).map((row) => row.split(" ").map((cell2, i) => i === 0 ? cell2 : appRelative(cell2)).join(" ")).join("\n");
4520
4768
  const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
4521
4769
  const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
@@ -4538,11 +4786,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
4538
4786
  const now = typeof json.version === "string" ? parseVersion(json.version) : null;
4539
4787
  const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
4540
4788
  const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
4541
- const changesets = top ? (git(top, ["diff", "--name-only", "--diff-filter=A", mergeBase, "--", ".changeset"]) ?? "").split("\n").concat((git(top, ["ls-files", "--others", "--exclude-standard", "--", ".changeset"]) ?? "").split("\n")).filter((f) => f.endsWith(".md")).map((f) => path18.join(top, f)) : [];
4789
+ const changesets = top ? (git(top, ["diff", "--name-only", "--diff-filter=A", mergeBase, "--", ".changeset"]) ?? "").split("\n").concat((git(top, ["ls-files", "--others", "--exclude-standard", "--", ".changeset"]) ?? "").split("\n")).filter((f) => f.endsWith(".md")).map((f) => path19.join(top, f)) : [];
4542
4790
  const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
4543
4791
  const named = naming.length > 0;
4544
4792
  if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
4545
- ctx.report({ rule: "package-unversioned-change", level: "warn", file: path18.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
4793
+ ctx.report({ rule: "package-unversioned-change", level: "warn", file: path19.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
4546
4794
  }
4547
4795
  let jsonBefore = null;
4548
4796
  try {
@@ -4552,7 +4800,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
4552
4800
  }
4553
4801
  const raw = json;
4554
4802
  if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
4555
- const appInRepo = path18.relative(top, realpathSync(ctx.root)).split(path18.sep).join("/");
4803
+ const appInRepo = path19.relative(top, realpathSync(ctx.root)).split(path19.sep).join("/");
4556
4804
  const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
4557
4805
  const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
4558
4806
  if (!registry) ctx.report({ rule: "package-unversioned-change", level: "warn", file: `${pkg.rel}/package.json`, message: `${pkg.name}'s blocks or exports changed but features.ts didn't; update the features they belong to` });
@@ -4604,15 +4852,16 @@ function checkPackagesPack(ctx) {
4604
4852
  ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
4605
4853
  }
4606
4854
  for (const pkg of packages) {
4607
- const json = JSON.parse(readFileSync(path18.join(pkg.dir, "package.json"), "utf8"));
4855
+ const json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
4608
4856
  checkImports2(ctx, pkg, json);
4609
4857
  checkExports(ctx, pkg, json);
4610
4858
  checkBlocks(ctx, pkg, json);
4611
- checkMigrations(ctx, pkg, json);
4859
+ checkMigrations(ctx, pkg, json, packages);
4612
4860
  checkTaggedTests(ctx, pkg);
4613
4861
  checkRegistered(ctx, pkg);
4614
4862
  checkDoctorDeclaration(ctx, pkg, json);
4615
- if (base && "sha" in merge) checkChanges(ctx, pkg, json, base, merge.sha);
4863
+ const overlay = GENESIS_NAME.test(json.name) && overlayState(json.name, json).kind === "marked" && overlaySetupProblems(ctx.root, ctx.config, pkg.dir, json.name, json).length === 0;
4864
+ if (base && "sha" in merge && !overlay) checkChanges(ctx, pkg, json, base, merge.sha);
4616
4865
  }
4617
4866
  }
4618
4867
  var DEFAULT_MIGRATIONS = "supabase/migrations";
@@ -4797,9 +5046,9 @@ function gitView(root, dir, base) {
4797
5046
  function checkSupabasePack(ctx) {
4798
5047
  const settings = ctx.config.supabase ?? {};
4799
5048
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
4800
- const abs = path18.join(ctx.root, dir);
5049
+ const abs = path19.join(ctx.root, dir);
4801
5050
  if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
4802
- const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path18.join(abs, n), "utf8")) }));
5051
+ const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path19.join(abs, n), "utf8")) }));
4803
5052
  const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
4804
5053
  const base = settings.base ?? DEFAULT_BASE;
4805
5054
  const view = gitView(ctx.root, dir, base);
@@ -4816,7 +5065,7 @@ function checkSupabasePack(ctx) {
4816
5065
  }
4817
5066
  }
4818
5067
  const since = settings.since;
4819
- const afterSince = (file) => since === void 0 || path18.posix.basename(file) >= since;
5068
+ const afterSince = (file) => since === void 0 || path19.posix.basename(file) >= since;
4820
5069
  if ("reason" in view && since === void 0) {
4821
5070
  ctx.report({
4822
5071
  rule: "migration-grants",
@@ -5068,17 +5317,32 @@ function checkDefinerSearchPath(ctx, migrations) {
5068
5317
  var UMBRELLA_PACKAGE = "@marktiderman/genesis";
5069
5318
  function readReleaseManifest(root) {
5070
5319
  const dir = findPackageDir(root, UMBRELLA_PACKAGE);
5071
- const file = dir && path18.join(dir, "dist", "versions.json");
5320
+ const file = dir && path19.join(dir, "dist", "versions.json");
5072
5321
  if (!file || !existsSync(file)) return null;
5073
5322
  return JSON.parse(readFileSync(file, "utf8"));
5074
5323
  }
5075
5324
  function checkVersionSkew(ctx) {
5076
5325
  const manifest = readReleaseManifest(ctx.root);
5077
5326
  if (!manifest) return;
5327
+ const overlays = markedOverlays(ctx);
5078
5328
  for (const [name, want] of Object.entries(manifest.packages)) {
5329
+ const overlay = overlays.get(name);
5330
+ if (overlay) {
5331
+ const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
5332
+ if (from !== want) {
5333
+ ctx.report({
5334
+ rule: "version-skew",
5335
+ level: "warn",
5336
+ file: "package.json",
5337
+ subject: name,
5338
+ message: `the app's overlay of ${name} was copied from ${from}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Bring the overlay onto ${want} (or promote it and adopt the release).`
5339
+ });
5340
+ }
5341
+ continue;
5342
+ }
5079
5343
  const dir = findPackageDir(ctx.root, name);
5080
5344
  if (!dir) continue;
5081
- const have = JSON.parse(readFileSync(path18.join(dir, "package.json"), "utf8")).version;
5345
+ const have = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8")).version;
5082
5346
  if (have === want) continue;
5083
5347
  ctx.report({
5084
5348
  rule: "version-skew",
@@ -5094,7 +5358,7 @@ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
5094
5358
  var NON_SHIPPING = /^(?:@marktiderman\/genesis-cli|vitest|@vitest\/.+|jest|jest-.+|@jest\/.+|ts-jest|babel-jest|mocha|ava|c8|nyc|@playwright\/test|playwright|cypress|@testing-library\/.+|happy-dom|jsdom|msw|@types\/.+|typescript|tsx|ts-node|eslint|eslint-.+|@eslint\/.+|@typescript-eslint\/.+|typescript-eslint|prettier|prettier-.+|@biomejs\/.+|oxlint|vite|@vitejs\/.+|vite-plugin-.+|webpack|webpack-.+|rollup|@rollup\/.+|esbuild|tsup|turbo|@storybook\/.+|storybook|@changesets\/.+|husky|lint-staged|wrangler|knip|concurrently|npm-run-all2?|rimraf|cross-env|dotenv-cli)$/;
5095
5359
  var readManifest = (dir) => {
5096
5360
  try {
5097
- return JSON.parse(readFileSync(path18.join(dir, "package.json"), "utf8"));
5361
+ return JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
5098
5362
  } catch {
5099
5363
  return null;
5100
5364
  }
@@ -5108,18 +5372,18 @@ var real = (p) => {
5108
5372
  };
5109
5373
  var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
5110
5374
  function nodeModulesOf(dir) {
5111
- const parent = path18.dirname(dir);
5112
- return path18.basename(parent).startsWith("@") ? path18.dirname(parent) : parent;
5375
+ const parent = path19.dirname(dir);
5376
+ return path19.basename(parent).startsWith("@") ? path19.dirname(parent) : parent;
5113
5377
  }
5114
5378
  function packagesIn(nodeModules) {
5115
5379
  if (!existsSync(nodeModules)) return [];
5116
5380
  const out = [];
5117
5381
  for (const entry of readdirSync(nodeModules)) {
5118
5382
  if (entry.startsWith(".")) continue;
5119
- const p = path18.join(nodeModules, entry);
5383
+ const p = path19.join(nodeModules, entry);
5120
5384
  if (entry.startsWith("@")) {
5121
5385
  try {
5122
- for (const sub of readdirSync(p)) out.push(path18.join(p, sub));
5386
+ for (const sub of readdirSync(p)) out.push(path19.join(p, sub));
5123
5387
  } catch {
5124
5388
  }
5125
5389
  } else {
@@ -5131,7 +5395,7 @@ function packagesIn(nodeModules) {
5131
5395
  function genesisInstalls(root) {
5132
5396
  const copies = /* @__PURE__ */ new Map();
5133
5397
  const realRoot = real(root);
5134
- const rel = (abs) => path18.relative(realRoot, abs).split(path18.sep).join("/") || ".";
5398
+ const rel = (abs) => path19.relative(realRoot, abs).split(path19.sep).join("/") || ".";
5135
5399
  const via = /* @__PURE__ */ new Map();
5136
5400
  const record = (real2, manifest, by, range, root2) => {
5137
5401
  let copy = copies.get(real2);
@@ -5176,7 +5440,7 @@ function genesisInstalls(root) {
5176
5440
  if (!dir) return null;
5177
5441
  if (!ownInstall || name in declared) return dir;
5178
5442
  const realDir = real(dir);
5179
- if (realDir.startsWith(realRoot + path18.sep)) return dir;
5443
+ if (realDir.startsWith(realRoot + path19.sep)) return dir;
5180
5444
  return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
5181
5445
  };
5182
5446
  const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
@@ -5184,7 +5448,7 @@ function genesisInstalls(root) {
5184
5448
  return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
5185
5449
  });
5186
5450
  const app = readManifest(root);
5187
- const ownInstall = LOCKFILES.some((f) => existsSync(path18.join(root, f)));
5451
+ const ownInstall = LOCKFILES.some((f) => existsSync(path19.join(root, f)));
5188
5452
  const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
5189
5453
  const declaredDev = Object.entries(app?.devDependencies ?? {});
5190
5454
  const runtimeDeps = {
@@ -5195,11 +5459,11 @@ function genesisInstalls(root) {
5195
5459
  };
5196
5460
  const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
5197
5461
  walk("runtime", rootsOf(runtimeDeps, "the app"));
5198
- const top = path18.join(root, "node_modules");
5462
+ const top = path19.join(root, "node_modules");
5199
5463
  walk(
5200
5464
  "hoisted",
5201
5465
  packagesIn(top).filter((dir) => {
5202
- const name = path18.relative(top, dir).split(path18.sep).join("/");
5466
+ const name = path19.relative(top, dir).split(path19.sep).join("/");
5203
5467
  return !(name in runtimeDeps) && !(name in devDeps);
5204
5468
  }).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
5205
5469
  );
@@ -5241,7 +5505,7 @@ function checkDuplicatePackages(ctx) {
5241
5505
  }
5242
5506
  }
5243
5507
  function checkPeerRanges(ctx) {
5244
- const rel = (abs) => path18.relative(ctx.root, abs).split(path18.sep).join("/");
5508
+ const rel = (abs) => path19.relative(ctx.root, abs).split(path19.sep).join("/");
5245
5509
  for (const copies of genesisInstalls(ctx.root).values()) {
5246
5510
  for (const copy of copies) {
5247
5511
  const dir = copy.absolutePath;
@@ -5271,9 +5535,9 @@ var CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Dra
5271
5535
  var SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
5272
5536
  var SHELL = /<AppShell(?=[\s>/])/;
5273
5537
  var GENESIS_PACKAGE2 = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
5274
- var PAGE_LAYOUT = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)|ResourceView)$/;
5538
+ var PAGE_LAYOUT = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)|ResourceView|RecordView)$/;
5275
5539
  var EMBEDDED_RESOURCE_VIEW = /<ResourceView\b[^>]*?\blayout\s*=\s*(?:(["'`]) {8}\1|\{\s*(["'`]) {8}\2\s*\})[^>]*>/g;
5276
- var PACKAGE_SCREEN = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)|ResourceView)$/;
5540
+ var PACKAGE_SCREEN = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)|ResourceView|RecordView)$/;
5277
5541
  var isNative2 = (ctx) => ctx.config.packs?.includes("native") ?? false;
5278
5542
  var rendersRe = (names) => {
5279
5543
  const list = [...names];
@@ -5325,6 +5589,7 @@ function checkLocalGenesisCopies(ctx) {
5325
5589
  if (owner.size === 0) return;
5326
5590
  const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
5327
5591
  const routes = routesDir(ctx);
5592
+ const overlays = markedOverlays(ctx);
5328
5593
  for (const file of ctx.files) {
5329
5594
  if (!JSX_EXTS2.has(file.ext)) continue;
5330
5595
  const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE2));
@@ -5335,6 +5600,7 @@ function checkLocalGenesisCopies(ctx) {
5335
5600
  const [, exported, name] = m;
5336
5601
  const pkg = owner.get(name);
5337
5602
  if (!pkg || imported.has(name) || routeComponents.has(name)) return;
5603
+ if (insideOverlayOf(overlays, file, pkg)) return;
5338
5604
  if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
5339
5605
  const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
5340
5606
  if (!rendersJsx(body)) return;
@@ -5623,11 +5889,11 @@ function appScripts(root) {
5623
5889
  const out = [];
5624
5890
  const walk = (dir) => {
5625
5891
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
5626
- const abs = path18.join(dir, entry.name);
5892
+ const abs = path19.join(dir, entry.name);
5627
5893
  if (entry.isDirectory()) {
5628
5894
  if (!SKIP_DIRS3.has(entry.name)) walk(abs);
5629
5895
  } else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
5630
- out.push(path18.relative(root, abs).split(path18.sep).join("/"));
5896
+ out.push(path19.relative(root, abs).split(path19.sep).join("/"));
5631
5897
  }
5632
5898
  }
5633
5899
  };
@@ -5715,7 +5981,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
5715
5981
  function moduleFiles(ctx) {
5716
5982
  const scanned = new Set(ctx.files.map((f) => f.path));
5717
5983
  const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
5718
- const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path18.join(ctx.root, rel), "utf8"), true) }));
5984
+ const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path19.join(ctx.root, rel), "utf8"), true) }));
5719
5985
  return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
5720
5986
  }
5721
5987
  function checkStudioServerImports(ctx) {
@@ -5751,7 +6017,7 @@ var REMOVED_WORDS = {
5751
6017
  };
5752
6018
  function checkRemovedScopeNames(ctx) {
5753
6019
  let augmentedMemo;
5754
- const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path18.join(ctx.root, rel), "utf8")));
6020
+ const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path19.join(ctx.root, rel), "utf8")));
5755
6021
  for (const file of ctx.files) {
5756
6022
  if (!SCRIPT_EXTS5.has(file.ext)) continue;
5757
6023
  for (const hit of findRemovedScopeNames(file.code)) {
@@ -5778,6 +6044,98 @@ function checkRemovedScopeNames(ctx) {
5778
6044
  }
5779
6045
  }
5780
6046
  }
6047
+ var SCRIPT_EXTS6 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
6048
+ var DECLARATION = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\n(?:export\s+)?(?:declare\s+)?(?:abstract\s+)?(?:function|const|let|class|interface|type|enum|namespace)\s+([A-Za-z_$][\w$]*)/g;
6049
+ function stabilityTagsIn(dts) {
6050
+ const tags = /* @__PURE__ */ new Map();
6051
+ for (const m of dts.matchAll(DECLARATION)) {
6052
+ const doc = m[1].replace(/^[ \t]*\*?[ \t]*/gm, "");
6053
+ const deprecated = /^@deprecated\b[ \t]*([\s\S]*?)(?=^@|(?![\s\S]))/m.exec(doc);
6054
+ const stability = /^@stability\s+(Experimental|Beta|Stable|Deprecated)\b/im.exec(doc)?.[1]?.toLowerCase();
6055
+ const note = deprecated?.[1].replace(/\s+/g, " ").trim();
6056
+ if (deprecated) tags.set(m[2], { stability: "deprecated", ...note ? { note } : {} });
6057
+ else if (stability) tags.set(m[2], { stability });
6058
+ }
6059
+ return tags;
6060
+ }
6061
+ function genesisNamedImports(code) {
6062
+ const out = [];
6063
+ const re = /import\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']((@marktiderman\/genesis[\w-]*)(?:\/[^"']*)?)["']/g;
6064
+ for (const m of code.matchAll(re)) {
6065
+ const names = m[1].split(",").map((n) => n.trim().replace(/^type\s+/, "").split(/\s+as\s+/)[0].trim()).filter(Boolean);
6066
+ out.push({ pkg: m[3], specifier: m[2], names, line: code.slice(0, m.index).split("\n").length });
6067
+ }
6068
+ return out;
6069
+ }
6070
+ function declarationFiles(dir, out = []) {
6071
+ for (const name of readdirSync(dir)) {
6072
+ const full = path19.join(dir, name);
6073
+ if (statSync(full).isDirectory()) declarationFiles(full, out);
6074
+ else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
6075
+ }
6076
+ return out;
6077
+ }
6078
+ function packageDir(root, pkg) {
6079
+ for (let dir = path19.resolve(root); ; dir = path19.dirname(dir)) {
6080
+ const candidate = path19.join(dir, "node_modules", ...pkg.split("/"));
6081
+ if (existsSync(path19.join(candidate, "package.json"))) return candidate;
6082
+ if (path19.dirname(dir) === dir) return null;
6083
+ }
6084
+ }
6085
+ function readPackageTags(dir) {
6086
+ const pkg = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
6087
+ const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
6088
+ const dist = path19.join(dir, "dist");
6089
+ if (!existsSync(dist)) return tags;
6090
+ for (const file of declarationFiles(dist)) {
6091
+ const text = readFileSync(file, "utf8");
6092
+ tags.byFile.set(file, stabilityTagsIn(text));
6093
+ for (const m of text.matchAll(/^(?:export\s+)?(?:declare\s+)?(?:abstract\s+)?(?:function|const|let|class|interface|type|enum|namespace)\s+([A-Za-z_$][\w$]*)/gm)) {
6094
+ const files = tags.declaredIn.get(m[1]) ?? [];
6095
+ if (!files.includes(file)) files.push(file);
6096
+ tags.declaredIn.set(m[1], files);
6097
+ }
6098
+ }
6099
+ return tags;
6100
+ }
6101
+ function entryFile(tags, pkg, specifier) {
6102
+ const subpath = `.${specifier.slice(pkg.length)}` || ".";
6103
+ const target = tags.exports[subpath === "." ? "." : subpath];
6104
+ const types = typeof target === "object" && target ? target.types : null;
6105
+ return typeof types === "string" ? path19.join(tags.dir, types) : null;
6106
+ }
6107
+ function tagFor(tags, entry, name) {
6108
+ if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
6109
+ const all = (tags.declaredIn.get(name) ?? []).map((f) => tags.byFile.get(f)?.get(name));
6110
+ if (!all.length || all.some((t) => !t)) return void 0;
6111
+ return all.every((t) => t.stability === all[0].stability) ? all[0] : void 0;
6112
+ }
6113
+ function checkStabilityImports(ctx) {
6114
+ const cache2 = /* @__PURE__ */ new Map();
6115
+ const tagsOf = (pkg) => {
6116
+ if (!cache2.has(pkg)) {
6117
+ const dir = packageDir(ctx.root, pkg);
6118
+ cache2.set(pkg, dir ? readPackageTags(dir) : null);
6119
+ }
6120
+ return cache2.get(pkg);
6121
+ };
6122
+ for (const file of ctx.files) {
6123
+ if (!SCRIPT_EXTS6.has(file.ext)) continue;
6124
+ for (const { pkg, specifier, names, line } of genesisNamedImports(file.code)) {
6125
+ const tags = tagsOf(pkg);
6126
+ if (!tags) continue;
6127
+ const entry = entryFile(tags, pkg, specifier);
6128
+ for (const name of names) {
6129
+ const tag = tagFor(tags, entry, name);
6130
+ if (tag?.stability === "deprecated") {
6131
+ ctx.report({ rule: "deprecated-import", level: "warn", file: file.path, line, subject: name, message: `${name} from ${pkg} is deprecated and goes at the next major${tag.note ? `: ${tag.note}` : ""}` });
6132
+ } else if (tag && (tag.stability === "beta" || tag.stability === "experimental")) {
6133
+ ctx.report({ rule: "beta-import", level: "info", file: file.path, line, subject: name, message: `${name} from ${pkg} is ${tag.stability}: it may still change in a minor release` });
6134
+ }
6135
+ }
6136
+ }
6137
+ }
6138
+ }
5781
6139
  function git3(root, args) {
5782
6140
  const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
5783
6141
  return r.status === 0 ? r.stdout : null;
@@ -5799,7 +6157,7 @@ function showAt(dir, rev, file) {
5799
6157
  function configAtBase(root, base, explicitFile) {
5800
6158
  const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
5801
6159
  if (!mergeBase) return null;
5802
- const candidates = explicitFile ? [{ dir: path18.dirname(explicitFile), file: path18.basename(explicitFile), explicit: true }] : [
6160
+ const candidates = explicitFile ? [{ dir: path19.dirname(explicitFile), file: path19.basename(explicitFile), explicit: true }] : [
5803
6161
  { dir: root, file: "genesis.config.json", explicit: false },
5804
6162
  { dir: root, file: "package.json", explicit: false }
5805
6163
  ];
@@ -5911,7 +6269,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
5911
6269
  const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
5912
6270
  let current = null;
5913
6271
  try {
5914
- current = lf(readFileSync(path18.join(ctx.root, out), "utf8"));
6272
+ current = lf(readFileSync(path19.join(ctx.root, out), "utf8"));
5915
6273
  } catch {
5916
6274
  current = null;
5917
6275
  }
@@ -5935,7 +6293,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
5935
6293
  ctx.report({ rule: "contracts-stale", level: generation ? "error" : "warn", file: out, message: generation ? `couldn't be generated: ${message}` : `couldn't read the database through ${env}: ${message}` });
5936
6294
  return;
5937
6295
  }
5938
- const target = path18.relative(process.cwd(), path18.join(ctx.root, out)) || out;
6296
+ const target = path19.relative(process.cwd(), path19.join(ctx.root, out)) || out;
5939
6297
  const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
5940
6298
  if (current !== expected) {
5941
6299
  ctx.report({
@@ -5955,7 +6313,7 @@ var CORE = [
5955
6313
  },
5956
6314
  {
5957
6315
  need: "a page inside the app shell",
5958
- use: "a Genesis page layout (`DashboardPage`, `SettingsPage`, `FormPage`, `DetailPage`, from `@marktiderman/genesis-ui`) or `ResourceView` (from `@marktiderman/genesis-ui/data`)",
6316
+ use: "a Genesis page layout (`DashboardPage`, `SettingsPage`, `FormPage`, `DetailPage`, from `@marktiderman/genesis-ui`) or `ResourceView` / `RecordView` (from `@marktiderman/genesis-ui/data`)",
5959
6317
  import: "@marktiderman/genesis-ui",
5960
6318
  rule: "page-layout",
5961
6319
  from: "genesis-cli"
@@ -6042,7 +6400,7 @@ function renderSkill(rows) {
6042
6400
  "",
6043
6401
  catalogTable(rows, { docs: true }),
6044
6402
  "",
6045
- "`genesis primitives` prints the same list; `genesis doctor` enforces the rules named above.",
6403
+ "`genesis catalog` prints the same list; `genesis doctor` enforces the rules named above.",
6046
6404
  ""
6047
6405
  ].join("\n");
6048
6406
  }
@@ -6053,7 +6411,7 @@ function renderAgentsBlock(rows) {
6053
6411
  "",
6054
6412
  "Generated by `genesis agents` from the installed Genesis packages. Don't edit this block; run `genesis agents` after upgrading Genesis.",
6055
6413
  "",
6056
- `Before writing a screen, read \`${SKILL_PATH}\` (or run \`genesis primitives\`).`,
6414
+ `Before writing a screen, read \`${SKILL_PATH}\` (or run \`genesis catalog\`).`,
6057
6415
  "",
6058
6416
  ...RULES.map((r) => `- ${r}`),
6059
6417
  "",
@@ -6078,8 +6436,8 @@ function currentAgentsBlock(agents) {
6078
6436
  var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
6079
6437
  function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
6080
6438
  const rows = primitivesCatalog(packages);
6081
- const skill = read(path18.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
6082
- const block = currentAgentsBlock(read(path18.join(root, agentsFile)));
6439
+ const skill = read(path19.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
6440
+ const block = currentAgentsBlock(read(path19.join(root, agentsFile)));
6083
6441
  return {
6084
6442
  skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
6085
6443
  agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
@@ -6101,8 +6459,9 @@ function checkAgentGuide(ctx) {
6101
6459
  ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
6102
6460
  }
6103
6461
  }
6462
+ var RATCHETED_BY_DEFAULT = ["deprecated-import"];
6104
6463
  async function runDoctor(options = {}) {
6105
- const root = path18.resolve(options.root ?? process.cwd());
6464
+ const root = path19.resolve(options.root ?? process.cwd());
6106
6465
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
6107
6466
  const config = loaded.config;
6108
6467
  const genesis = options.genesis ?? loadGenesis(root, config);
@@ -6116,7 +6475,7 @@ async function runDoctor(options = {}) {
6116
6475
  if (builtinIds.has(p.id) || META_RULES.has(p.id)) throw new DoctorConfigError(`doctor.patterns: "${p.id}" is a built-in rule id; pick another`);
6117
6476
  }
6118
6477
  const raw = [];
6119
- const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, report: (f) => raw.push(f) };
6478
+ const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, ...options.strict ? { strict: true } : {}, report: (f) => raw.push(f) };
6120
6479
  for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
6121
6480
  try {
6122
6481
  await plugin.check(ctx);
@@ -6130,10 +6489,11 @@ async function runDoctor(options = {}) {
6130
6489
  if (failure) raw.push(failure);
6131
6490
  }
6132
6491
  raw.push(...unknownPackageRuleSettings(config, packages, raw));
6133
- const newOnly = /* @__PURE__ */ new Set([...patterns?.newOnly ?? [], ...preferRules(packages).filter((r) => r.newOnly).map((r) => r.ruleId)]);
6492
+ const newOnly = /* @__PURE__ */ new Set([...RATCHETED_BY_DEFAULT, ...patterns?.newOnly ?? [], ...preferRules(packages).filter((r) => r.newOnly).map((r) => r.ruleId)]);
6134
6493
  let changed = null;
6135
6494
  let skipped = false;
6136
- if (options.base && (newOnly.size > 0 || config.ratchet)) {
6495
+ const ratchetNeeded = newOnly.size > RATCHETED_BY_DEFAULT.length || raw.some((f) => RATCHETED_BY_DEFAULT.includes(f.rule));
6496
+ if (options.base && (ratchetNeeded || config.ratchet)) {
6137
6497
  changed = options.changedFiles ? new Set(options.changedFiles) : changedSince(root, options.base);
6138
6498
  skipped ||= !changed;
6139
6499
  }
@@ -6155,7 +6515,7 @@ async function runDoctor(options = {}) {
6155
6515
  }
6156
6516
  let findings = applyConfig(raw, config, packageRuleIds(packages));
6157
6517
  if (options.base && changed) {
6158
- findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path18.join(root, f)) });
6518
+ findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path19.join(root, f)) });
6159
6519
  }
6160
6520
  const errors = findings.filter((f) => f.level === "error").length;
6161
6521
  const warnings = findings.filter((f) => f.level === "warn").length;
@@ -6197,7 +6557,9 @@ function builtinChecks(config, options = {}) {
6197
6557
  { name: "resource-view-trees", check: checkTreeViews },
6198
6558
  { name: "studio-server-imports", check: checkStudioServerImports },
6199
6559
  { name: "removed-scope-names", check: checkRemovedScopeNames },
6560
+ { name: "stability-imports", check: checkStabilityImports },
6200
6561
  { name: "agent-guide", check: checkAgentGuide },
6562
+ { name: "overlays", check: (ctx) => checkOverlays(ctx) },
6201
6563
  ...(config.packs ?? []).map((p) => packs[p]),
6202
6564
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
6203
6565
  ];
@@ -6260,7 +6622,7 @@ function formatReport(result) {
6260
6622
  lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
6261
6623
  }
6262
6624
  lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
6263
- lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis primitives`);
6625
+ lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis catalog`);
6264
6626
  const info = result.infos ? `, ${result.infos} info` : "";
6265
6627
  lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
6266
6628
  return lines.join("\n");