@marktiderman/genesis-cli 1.17.3 → 1.18.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/vite.js CHANGED
@@ -1,12 +1,13 @@
1
- import * as path19 from 'path';
1
+ import * as path20 from 'path';
2
2
  import { spawnSync } from 'child_process';
3
3
  import { existsSync, readFileSync, statSync, realpathSync, readdirSync, lstatSync } from 'fs';
4
4
  import { builtinModules, createRequire } from 'module';
5
- import 'crypto';
5
+ import { createHash } from 'crypto';
6
6
  import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
7
- import { pathToFileURL } from 'url';
7
+ import { pathToFileURL, fileURLToPath } from 'url';
8
8
  import { overlayUpstream, readOverlayMarker } from '@marktiderman/genesis-features';
9
- import 'jiti';
9
+ import { createJiti } from 'jiti';
10
+ import 'os';
10
11
 
11
12
  var __defProp = Object.defineProperty;
12
13
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -720,19 +721,19 @@ var init_introspect = __esm({
720
721
  var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
721
722
  function buildCommands(root, config) {
722
723
  if (config.build) return config.build;
723
- const pkgFile = path19.join(root, "package.json");
724
+ const pkgFile = path20.join(root, "package.json");
724
725
  const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
725
726
  const pm = packageManager(root);
726
727
  return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
727
728
  }
728
729
  function packageManager(root) {
729
- let dir = path19.resolve(root);
730
+ let dir = path20.resolve(root);
730
731
  for (; ; ) {
731
- if (existsSync(path19.join(dir, "pnpm-lock.yaml"))) return "pnpm";
732
- if (existsSync(path19.join(dir, "bun.lock")) || existsSync(path19.join(dir, "bun.lockb"))) return "bun";
733
- if (existsSync(path19.join(dir, "yarn.lock"))) return "yarn";
734
- if (existsSync(path19.join(dir, "package-lock.json"))) return "npm";
735
- const parent = path19.dirname(dir);
732
+ if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return "pnpm";
733
+ if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return "bun";
734
+ if (existsSync(path20.join(dir, "yarn.lock"))) return "yarn";
735
+ if (existsSync(path20.join(dir, "package-lock.json"))) return "npm";
736
+ const parent = path20.dirname(dir);
736
737
  if (parent === dir) return "npm";
737
738
  dir = parent;
738
739
  }
@@ -847,25 +848,25 @@ var PACK_KEYS = {
847
848
  };
848
849
  function appPath(v, where2, fail) {
849
850
  if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
850
- if (path19.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
851
- const norm = path19.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
851
+ if (path20.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
852
+ const norm = path20.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
852
853
  if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
853
854
  return norm;
854
855
  }
855
856
  function loadConfig(root, configPath) {
856
857
  if (configPath) {
857
- const file = path19.resolve(root, configPath);
858
+ const file = path20.resolve(root, configPath);
858
859
  if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
859
860
  const json = readJson(file);
860
- const block = path19.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
861
- return { config: validateConfig(block ?? {}, file), file, dir: path19.dirname(file) };
861
+ const block = path20.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
862
+ return { config: validateConfig(block ?? {}, file), file, dir: path20.dirname(file) };
862
863
  }
863
- const own = path19.join(root, "genesis.config.json");
864
+ const own = path20.join(root, "genesis.config.json");
864
865
  if (existsSync(own)) {
865
866
  const block = readGenesisConfig(root)?.raw.doctor;
866
867
  return { config: validateConfig(block ?? {}, own), file: own, dir: root };
867
868
  }
868
- const pkg = path19.join(root, "package.json");
869
+ const pkg = path20.join(root, "package.json");
869
870
  if (existsSync(pkg)) {
870
871
  const block = readJson(pkg)?.genesis?.doctor;
871
872
  if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
@@ -874,7 +875,7 @@ function loadConfig(root, configPath) {
874
875
  }
875
876
  function doctorBlock(json, file, explicit) {
876
877
  const j = json;
877
- if (path19.basename(file) === "package.json") return j?.genesis?.doctor;
878
+ if (path20.basename(file) === "package.json") return j?.genesis?.doctor;
878
879
  return explicit ? j?.doctor ?? j : j?.doctor;
879
880
  }
880
881
  function isPackageDeclaration(block) {
@@ -891,7 +892,7 @@ function readJson(file) {
891
892
  }
892
893
  }
893
894
  function readGenesisConfig(root) {
894
- const file = path19.join(root, "genesis.config.json");
895
+ const file = path20.join(root, "genesis.config.json");
895
896
  if (!existsSync(file)) return null;
896
897
  const raw = readJson(file);
897
898
  if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
@@ -1056,7 +1057,7 @@ function validateConfig(raw, source = "config") {
1056
1057
  if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
1057
1058
  if (contracts.out !== void 0) {
1058
1059
  if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
1059
- if (path19.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
1060
+ if (path20.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
1060
1061
  }
1061
1062
  if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
1062
1063
  if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
@@ -1124,7 +1125,7 @@ function globToRegExp(glob) {
1124
1125
  }
1125
1126
  function globMatcher(globs) {
1126
1127
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1127
- return (path31) => res.some((re) => re.test(path31));
1128
+ return (path37) => res.some((re) => re.test(path37));
1128
1129
  }
1129
1130
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1130
1131
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -1164,11 +1165,11 @@ var TAILWIND_PALETTE = [
1164
1165
  "olive"
1165
1166
  ];
1166
1167
  function findPackageDir(from, name) {
1167
- let dir = path19.resolve(from);
1168
+ let dir = path20.resolve(from);
1168
1169
  for (; ; ) {
1169
- const candidate = path19.join(dir, "node_modules", name);
1170
- if (existsSync(path19.join(candidate, "package.json"))) return candidate;
1171
- const parent = path19.dirname(dir);
1170
+ const candidate = path20.join(dir, "node_modules", name);
1171
+ if (existsSync(path20.join(candidate, "package.json"))) return candidate;
1172
+ const parent = path20.dirname(dir);
1172
1173
  if (parent === dir) return null;
1173
1174
  dir = parent;
1174
1175
  }
@@ -1220,7 +1221,7 @@ function loadCompanions(root, config, uiPackage) {
1220
1221
  function readPackageExports(root, uiPackage) {
1221
1222
  const uiDir = findPackageDir(root, uiPackage);
1222
1223
  if (!uiDir) return null;
1223
- const uiPkg = JSON.parse(readFileSync(path19.join(uiDir, "package.json"), "utf8"));
1224
+ const uiPkg = JSON.parse(readFileSync(path20.join(uiDir, "package.json"), "utf8"));
1224
1225
  const subpaths = Object.values(uiPkg.exports ?? {});
1225
1226
  const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
1226
1227
  const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
@@ -1247,23 +1248,23 @@ function readPackageExports(root, uiPackage) {
1247
1248
  }
1248
1249
  if (fromSource) {
1249
1250
  for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
1250
- const next = resolveSource(path19.dirname(file), m[1]);
1251
+ const next = resolveSource(path20.dirname(file), m[1]);
1251
1252
  if (next) readEntry(next);
1252
1253
  }
1253
1254
  }
1254
1255
  };
1255
- for (const entry of typeEntries) readEntry(path19.join(uiDir, entry));
1256
+ for (const entry of typeEntries) readEntry(path20.join(uiDir, entry));
1256
1257
  if (!readAny) {
1257
1258
  const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
1258
1259
  throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
1259
1260
  }
1260
1261
  const valueDecls = /* @__PURE__ */ new Set();
1261
1262
  const typeDecls = /* @__PURE__ */ new Set();
1262
- const declRoot = typeof mainTypes === "string" ? path19.dirname(path19.join(uiDir, mainTypes)) : uiDir;
1263
+ const declRoot = typeof mainTypes === "string" ? path20.dirname(path20.join(uiDir, mainTypes)) : uiDir;
1263
1264
  const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
1264
1265
  for (const pkg of reexportedPackages) {
1265
1266
  const dir = findPackageDir(uiDir, pkg);
1266
- if (dir) walkDts(path19.join(dir, "dist"), declFiles);
1267
+ if (dir) walkDts(path20.join(dir, "dist"), declFiles);
1267
1268
  }
1268
1269
  for (const file of declFiles) {
1269
1270
  const text = readFileSync(file, "utf8");
@@ -1313,13 +1314,13 @@ function exportSource(target) {
1313
1314
  return void 0;
1314
1315
  }
1315
1316
  function resolveSource(dir, spec) {
1316
- const base = path19.resolve(dir, spec.replace(/\.js$/, ""));
1317
- const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path19.join(base, i))];
1317
+ const base = path20.resolve(dir, spec.replace(/\.js$/, ""));
1318
+ const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path20.join(base, i))];
1318
1319
  return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
1319
1320
  }
1320
1321
  function insidePackage(dir, file) {
1321
- const rel = path19.relative(path19.resolve(dir), path19.resolve(file));
1322
- return rel === "" || !rel.startsWith("..") && !path19.isAbsolute(rel);
1322
+ const rel = path20.relative(path20.resolve(dir), path20.resolve(file));
1323
+ return rel === "" || !rel.startsWith("..") && !path20.isAbsolute(rel);
1323
1324
  }
1324
1325
  function stripComments(code) {
1325
1326
  let out = "";
@@ -1355,7 +1356,7 @@ function walkSource(dir, out = []) {
1355
1356
  if (!existsSync(dir)) return out;
1356
1357
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
1357
1358
  if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
1358
- const p = path19.join(dir, entry.name);
1359
+ const p = path20.join(dir, entry.name);
1359
1360
  if (entry.isDirectory()) walkSource(p, out);
1360
1361
  else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
1361
1362
  }
@@ -1375,7 +1376,7 @@ function walkDts(dir, out = []) {
1375
1376
  if (!existsSync(dir)) return out;
1376
1377
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
1377
1378
  if (entry.name === "node_modules") continue;
1378
- const p = path19.join(dir, entry.name);
1379
+ const p = path20.join(dir, entry.name);
1379
1380
  if (entry.isDirectory()) walkDts(p, out);
1380
1381
  else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
1381
1382
  }
@@ -1392,27 +1393,27 @@ function resolveThemeFiles(root, config, uiDir) {
1392
1393
  }
1393
1394
  const files = [];
1394
1395
  const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
1395
- const themes = ds && path19.join(ds, "dist", "themes");
1396
+ const themes = ds && path20.join(ds, "dist", "themes");
1396
1397
  if (themes && existsSync(themes)) {
1397
- for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path19.join(themes, name));
1398
+ for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path20.join(themes, name));
1398
1399
  }
1399
1400
  if (files.length === 0) {
1400
1401
  throw new DoctorConfigError(
1401
1402
  `No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
1402
1403
  );
1403
1404
  }
1404
- const uiStyles = path19.join(uiDir, "dist", "styles.css");
1405
+ const uiStyles = path20.join(uiDir, "dist", "styles.css");
1405
1406
  if (existsSync(uiStyles)) files.push(uiStyles);
1406
1407
  return files;
1407
1408
  }
1408
1409
  function resolveSpec(root, spec) {
1409
- const local = path19.resolve(root, spec);
1410
- if (spec.startsWith(".") || path19.isAbsolute(spec)) return existsSync(local) ? local : null;
1410
+ const local = path20.resolve(root, spec);
1411
+ if (spec.startsWith(".") || path20.isAbsolute(spec)) return existsSync(local) ? local : null;
1411
1412
  const parts = spec.split("/");
1412
1413
  const nameLength = spec.startsWith("@") ? 2 : 1;
1413
1414
  const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
1414
1415
  if (dir) {
1415
- const file = path19.join(dir, ...parts.slice(nameLength));
1416
+ const file = path20.join(dir, ...parts.slice(nameLength));
1416
1417
  if (existsSync(file) && statSync(file).isFile()) return file;
1417
1418
  }
1418
1419
  return existsSync(local) ? local : null;
@@ -1420,7 +1421,7 @@ function resolveSpec(root, spec) {
1420
1421
  function loadPalette(root) {
1421
1422
  const names = new Set(TAILWIND_PALETTE);
1422
1423
  try {
1423
- const req = createRequire(path19.join(root, "package.json"));
1424
+ const req = createRequire(path20.join(root, "package.json"));
1424
1425
  const colors = req("tailwindcss/colors");
1425
1426
  for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
1426
1427
  if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
@@ -1606,11 +1607,56 @@ function rawBlocksOf(packageJson) {
1606
1607
  const blocks = packageJson["genesis"]["blocks"];
1607
1608
  return isObject2(blocks) ? blocks : {};
1608
1609
  }
1610
+ function declarationFields(block) {
1611
+ const c = block.contributes ?? {};
1612
+ return {
1613
+ ...block.requires ? { requires: [...block.requires] } : {},
1614
+ ...block.platforms ? { platforms: [...block.platforms] } : {},
1615
+ ...c.migrations ? { migrations: c.migrations.map((m) => ({ ...m })) } : {},
1616
+ ...c.routes ? { routes: c.routes.map((r) => ({ ...r })) } : {},
1617
+ ...c.skills ? { skills: [...c.skills] } : {},
1618
+ ...c.privacy ? { privacy: c.privacy } : {}
1619
+ };
1620
+ }
1621
+ function isBlockDef(value) {
1622
+ return isObject2(value) && typeof value["id"] === "string" && BLOCK_ID.test(value["id"]) && (value["contributes"] === void 0 || isObject2(value["contributes"])) && (isObject2(value["contributes"]) || Array.isArray(value["requires"]));
1623
+ }
1609
1624
 
1610
1625
  // src/blocks/files.ts
1626
+ var sha256 = (text) => createHash("sha256").update(text).digest("hex");
1611
1627
  function inside(parent, child) {
1612
- const rel = path19.relative(parent, child);
1613
- return rel === "" || !rel.startsWith("..") && !path19.isAbsolute(rel);
1628
+ const rel = path20.relative(parent, child);
1629
+ return rel === "" || !rel.startsWith("..") && !path20.isAbsolute(rel);
1630
+ }
1631
+ function appPath2(root, rel) {
1632
+ const safe = safeRelative(rel.replace(/^\.\//, ""));
1633
+ if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
1634
+ if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
1635
+ const realRoot = realpathSync(root);
1636
+ const target = path20.join(realRoot, ...safe.split("/"));
1637
+ const there = (p) => {
1638
+ try {
1639
+ lstatSync(p);
1640
+ return true;
1641
+ } catch {
1642
+ return false;
1643
+ }
1644
+ };
1645
+ let probe = path20.dirname(target);
1646
+ while (!there(probe)) probe = path20.dirname(probe);
1647
+ let real2;
1648
+ try {
1649
+ real2 = realpathSync(probe);
1650
+ } catch {
1651
+ throw new Error(`${rel} goes through a broken symlink (${path20.relative(realRoot, probe)}); refused`);
1652
+ }
1653
+ if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
1654
+ if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
1655
+ return target;
1656
+ }
1657
+ function readApp(root, rel) {
1658
+ const file = appPath2(root, rel);
1659
+ return existsSync(file) ? readFileSync(file, "utf8") : null;
1614
1660
  }
1615
1661
 
1616
1662
  // src/blocks/local.ts
@@ -1623,8 +1669,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
1623
1669
  return raw.map((entry, i) => {
1624
1670
  const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
1625
1671
  if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
1626
- if (path19.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
1627
- const norm = path19.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
1672
+ if (path20.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
1673
+ const norm = path20.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
1628
1674
  if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
1629
1675
  const parts = norm.split("/");
1630
1676
  if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
@@ -1635,7 +1681,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
1635
1681
  });
1636
1682
  }
1637
1683
  function localPackageGlobs(root) {
1638
- const file = path19.join(root, "genesis.config.json");
1684
+ const file = path20.join(root, "genesis.config.json");
1639
1685
  if (!existsSync(file)) return [];
1640
1686
  let raw;
1641
1687
  try {
@@ -1649,14 +1695,14 @@ function localPackageGlobs(root) {
1649
1695
  var cache = /* @__PURE__ */ new Map();
1650
1696
  function repositoryRoot(appRoot) {
1651
1697
  for (let dir = appRoot; ; ) {
1652
- if (existsSync(path19.join(dir, ".git"))) return dir;
1653
- const parent = path19.dirname(dir);
1698
+ if (existsSync(path20.join(dir, ".git"))) return dir;
1699
+ const parent = path20.dirname(dir);
1654
1700
  if (parent === dir) return appRoot;
1655
1701
  dir = parent;
1656
1702
  }
1657
1703
  }
1658
1704
  function localPackages(root) {
1659
- const appRoot = path19.resolve(root);
1705
+ const appRoot = path20.resolve(root);
1660
1706
  const globs = localPackageGlobs(appRoot);
1661
1707
  const key2 = `${appRoot}
1662
1708
  ${globs.join("\n")}`;
@@ -1665,24 +1711,24 @@ ${globs.join("\n")}`;
1665
1711
  const dirs = /* @__PURE__ */ new Set();
1666
1712
  for (const glob of globs) {
1667
1713
  if (glob.endsWith("/*") || glob === "*") {
1668
- const parent = path19.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
1714
+ const parent = path20.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
1669
1715
  if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
1670
1716
  for (const entry of readdirSync(parent).sort()) {
1671
1717
  if (entry.startsWith(".") || entry === "node_modules") continue;
1672
- dirs.add(path19.join(parent, entry));
1718
+ dirs.add(path20.join(parent, entry));
1673
1719
  }
1674
1720
  } else {
1675
- dirs.add(path19.join(appRoot, glob));
1721
+ dirs.add(path20.join(appRoot, glob));
1676
1722
  }
1677
1723
  }
1678
1724
  const real2 = realpathSync(repositoryRoot(appRoot));
1679
1725
  const out = [];
1680
1726
  const byName = /* @__PURE__ */ new Map();
1681
1727
  for (const dir of [...dirs].sort()) {
1682
- const manifest = path19.join(dir, "package.json");
1728
+ const manifest = path20.join(dir, "package.json");
1683
1729
  if (!existsSync(manifest)) continue;
1684
1730
  if (!inside(real2, realpathSync(dir))) {
1685
- throw new LocalPackagesError(`${path19.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
1731
+ throw new LocalPackagesError(`${path20.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
1686
1732
  }
1687
1733
  let pkg;
1688
1734
  try {
@@ -1691,7 +1737,7 @@ ${globs.join("\n")}`;
1691
1737
  continue;
1692
1738
  }
1693
1739
  if (typeof pkg.name !== "string" || !pkg.name) continue;
1694
- const rel = path19.relative(appRoot, dir).split(path19.sep).join("/");
1740
+ const rel = path20.relative(appRoot, dir).split(path20.sep).join("/");
1695
1741
  const other = byName.get(pkg.name);
1696
1742
  if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
1697
1743
  byName.set(pkg.name, rel);
@@ -1700,6 +1746,9 @@ ${globs.join("\n")}`;
1700
1746
  cache.set(key2, out);
1701
1747
  return out;
1702
1748
  }
1749
+ function localPackageNames(root) {
1750
+ return new Set(localPackages(root).map((p) => p.name));
1751
+ }
1703
1752
 
1704
1753
  // ../../scripts/lib/color-literals.mjs
1705
1754
  var LINE_COMMENT_EXTS = /* @__PURE__ */ new Set([".ts", ".tsx", ".jsx", ".js", ".mjs", ".cjs", ".scss", ".less"]);
@@ -1876,35 +1925,35 @@ var DEFAULT_IGNORE = [
1876
1925
  ];
1877
1926
  var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
1878
1927
  var MAX_FILE_BYTES = 2 * 1024 * 1024;
1879
- var toPosix = (p) => p.split(path19.sep).join("/");
1928
+ var toPosix = (p) => p.split(path20.sep).join("/");
1880
1929
  function scanFiles(root, config) {
1881
1930
  const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
1882
1931
  const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
1883
1932
  const files = [];
1884
1933
  const seen = /* @__PURE__ */ new Set();
1885
1934
  const visit = (abs) => {
1886
- const rel = toPosix(path19.relative(root, abs));
1935
+ const rel = toPosix(path20.relative(root, abs));
1887
1936
  if (seen.has(rel) || ignored(rel)) return;
1888
- const ext = path19.extname(abs);
1937
+ const ext = path20.extname(abs);
1889
1938
  if (!extensions.has(ext)) return;
1890
1939
  if (statSync(abs).size > MAX_FILE_BYTES) return;
1891
1940
  seen.add(rel);
1892
1941
  const text = readFileSync(abs, "utf8");
1893
1942
  files.push({ path: rel, absolutePath: abs, ext, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(ext)) });
1894
1943
  };
1895
- const walk = (dir) => {
1944
+ const walk2 = (dir) => {
1896
1945
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
1897
1946
  if (entry.isDirectory()) {
1898
- if (!SKIP_DIRS.has(entry.name)) walk(path19.join(dir, entry.name));
1947
+ if (!SKIP_DIRS.has(entry.name)) walk2(path20.join(dir, entry.name));
1899
1948
  } else if (entry.isFile()) {
1900
- visit(path19.join(dir, entry.name));
1949
+ visit(path20.join(dir, entry.name));
1901
1950
  }
1902
1951
  }
1903
1952
  };
1904
1953
  for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
1905
- const abs = path19.resolve(root, src);
1954
+ const abs = path20.resolve(root, src);
1906
1955
  if (!existsSync(abs)) continue;
1907
- if (statSync(abs).isDirectory()) walk(abs);
1956
+ if (statSync(abs).isDirectory()) walk2(abs);
1908
1957
  else visit(abs);
1909
1958
  }
1910
1959
  let local = [];
@@ -1913,7 +1962,7 @@ function scanFiles(root, config) {
1913
1962
  } catch {
1914
1963
  local = [];
1915
1964
  }
1916
- for (const pkg of local) walk(pkg.dir);
1965
+ for (const pkg of local) walk2(pkg.dir);
1917
1966
  return files;
1918
1967
  }
1919
1968
  function lineAt(text, index) {
@@ -1990,7 +2039,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
1990
2039
  const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
1991
2040
  let all = compiled;
1992
2041
  if (rulesDoc) {
1993
- const file = path19.resolve(root, rulesDoc);
2042
+ const file = path20.resolve(root, rulesDoc);
1994
2043
  if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
1995
2044
  const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
1996
2045
  const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
@@ -2048,15 +2097,177 @@ async function loadPlugins(specs, configDir) {
2048
2097
  }
2049
2098
  function resolvePlugin(id, configDir) {
2050
2099
  try {
2051
- if (id.startsWith(".") || path19.isAbsolute(id)) return resolveFrom(path19.resolve(configDir, id), configDir);
2100
+ if (id.startsWith(".") || path20.isAbsolute(id)) return resolveFrom(path20.resolve(configDir, id), configDir);
2052
2101
  return resolveFrom(id, configDir);
2053
2102
  } catch {
2054
2103
  throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
2055
2104
  }
2056
2105
  }
2057
2106
  function resolveFrom(id, from) {
2058
- return createRequire(path19.join(from, "noop.js")).resolve(id);
2107
+ return createRequire(path20.join(from, "noop.js")).resolve(id);
2108
+ }
2109
+
2110
+ // src/doctor/semver.ts
2111
+ var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
2112
+ function parseVersion(v) {
2113
+ const m = VERSION.exec(v.trim());
2114
+ return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
2115
+ }
2116
+ function compareVersions(a, b) {
2117
+ for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
2118
+ if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
2119
+ for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
2120
+ const x = a.pre[i];
2121
+ const y = b.pre[i];
2122
+ if (x === void 0) return -1;
2123
+ if (y === void 0) return 1;
2124
+ if (x === y) continue;
2125
+ const nx = /^\d+$/.test(x);
2126
+ const ny = /^\d+$/.test(y);
2127
+ if (nx && ny) return +x < +y ? -1 : 1;
2128
+ if (nx !== ny) return nx ? -1 : 1;
2129
+ return x < y ? -1 : 1;
2130
+ }
2131
+ return 0;
2132
+ }
2133
+ function partial(s) {
2134
+ const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
2135
+ if (!m) return null;
2136
+ const nums = [];
2137
+ let wild = false;
2138
+ for (const part of [m[1], m[2], m[3]]) {
2139
+ if (wild || part === void 0 || /^[xX*]$/.test(part)) {
2140
+ wild = true;
2141
+ nums.push(null);
2142
+ } else nums.push(+part);
2143
+ }
2144
+ return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
2145
+ }
2146
+ var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
2147
+ function comparators(token) {
2148
+ const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
2149
+ if (!m) return null;
2150
+ const op = m[1] ?? "";
2151
+ const p = partial(m[2]);
2152
+ if (!p) return null;
2153
+ const [major, mi, pa] = p.nums;
2154
+ if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
2155
+ const M = major;
2156
+ const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
2157
+ const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
2158
+ const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
2159
+ const out = switchOp();
2160
+ if (p.pre.length) {
2161
+ for (const c of out) if (c.v === lo) c.pre = true;
2162
+ }
2163
+ return out;
2164
+ function switchOp() {
2165
+ switch (op) {
2166
+ case "^": {
2167
+ const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
2168
+ return [
2169
+ { op: ">=", v: lo },
2170
+ { op: "<", v: bound }
2171
+ ];
2172
+ }
2173
+ case "~":
2174
+ case "~>":
2175
+ return [
2176
+ { op: ">=", v: lo },
2177
+ { op: "<", v: mi === null ? next("major") : next("minor") }
2178
+ ];
2179
+ case ">":
2180
+ return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
2181
+ case ">=":
2182
+ return [{ op: ">=", v: lo }];
2183
+ case "<":
2184
+ return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
2185
+ case "<=":
2186
+ return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
2187
+ default:
2188
+ return upper ? [
2189
+ { op: ">=", v: lo },
2190
+ { op: "<", v: upper }
2191
+ ] : [{ op: "=", v: lo }];
2192
+ }
2193
+ }
2194
+ }
2195
+ function test(c, v) {
2196
+ const d = compareVersions(v, c.v);
2197
+ return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
2198
+ }
2199
+ function parseRange(range) {
2200
+ const alts = [];
2201
+ for (const raw of range.trim().split("||")) {
2202
+ const alt = raw.trim();
2203
+ const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
2204
+ if (hyphen) {
2205
+ const from = comparators(`>=${hyphen[1]}`);
2206
+ const to = comparators(`<=${hyphen[2]}`);
2207
+ if (!from || !to) return null;
2208
+ alts.push([...from, ...to]);
2209
+ continue;
2210
+ }
2211
+ const set = [];
2212
+ for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
2213
+ const cs = comparators(token);
2214
+ if (!cs) return null;
2215
+ set.push(...cs);
2216
+ }
2217
+ alts.push(set);
2218
+ }
2219
+ return alts;
2220
+ }
2221
+ function satisfies(version, range) {
2222
+ const v = parseVersion(version);
2223
+ const alts = parseRange(range);
2224
+ if (!v || !alts) return null;
2225
+ return alts.some(
2226
+ (set) => set.every((c) => test(c, v)) && (!v.pre.length || set.some((c) => c.pre && c.v.major === v.major && c.v.minor === v.minor && c.v.patch === v.patch))
2227
+ );
2228
+ }
2229
+ var UMBRELLA_PACKAGE = "@marktiderman/genesis";
2230
+ function readReleaseManifest(root) {
2231
+ const dir = findPackageDir(root, UMBRELLA_PACKAGE);
2232
+ const file = dir && path20.join(dir, "dist", "versions.json");
2233
+ if (!file || !existsSync(file)) return null;
2234
+ return JSON.parse(readFileSync(file, "utf8"));
2235
+ }
2236
+ function checkVersionSkew(ctx) {
2237
+ const manifest = readReleaseManifest(ctx.root);
2238
+ if (!manifest) return;
2239
+ const overlays = markedOverlays(ctx);
2240
+ for (const [name, want] of Object.entries(manifest.packages)) {
2241
+ const overlay = overlays.get(name);
2242
+ if (overlay) {
2243
+ const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
2244
+ const behind = parseVersion(from) && parseVersion(want) && compareVersions(parseVersion(from), parseVersion(want)) < 0;
2245
+ if (from !== want && !behind) {
2246
+ ctx.report({
2247
+ rule: "version-skew",
2248
+ level: "warn",
2249
+ file: "package.json",
2250
+ subject: name,
2251
+ 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).`
2252
+ });
2253
+ }
2254
+ continue;
2255
+ }
2256
+ const dir = findPackageDir(ctx.root, name);
2257
+ if (!dir) continue;
2258
+ const have = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8")).version;
2259
+ if (have === want) continue;
2260
+ ctx.report({
2261
+ rule: "version-skew",
2262
+ level: "warn",
2263
+ file: "package.json",
2264
+ subject: name,
2265
+ message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
2266
+ });
2267
+ }
2059
2268
  }
2269
+
2270
+ // src/doctor/overlays.ts
2060
2271
  var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
2061
2272
  var OVERLAY_NOTICE_DAYS = 14;
2062
2273
  var OVERLAY_WARN_DAYS = 30;
@@ -2070,7 +2281,7 @@ function overlayState(name, json) {
2070
2281
  function overlaySetupProblems(root, config, dir, name, json) {
2071
2282
  const problems = [];
2072
2283
  if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
2073
- const rel = path19.relative(path19.resolve(root), path19.resolve(dir)).split(path19.sep).join("/");
2284
+ const rel = path20.relative(path20.resolve(root), path20.resolve(dir)).split(path20.sep).join("/");
2074
2285
  const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
2075
2286
  const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
2076
2287
  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})`);
@@ -2095,6 +2306,31 @@ function overlayAgeDays(since, now = /* @__PURE__ */ new Date()) {
2095
2306
  return Math.floor((today - Date.UTC(y, m - 1, d)) / 864e5);
2096
2307
  }
2097
2308
  var LOCAL_VERSION = /^(\d+\.\d+\.\d+(?:-(?!local\.)[0-9A-Za-z.-]+?)?)(?:[+-]local\.(?:0|[1-9]\d*))?$/;
2309
+ function pinnedVersion(root, name, manifests = ["package.json"]) {
2310
+ let manifest = null;
2311
+ try {
2312
+ manifest = readReleaseManifest(root);
2313
+ } catch {
2314
+ }
2315
+ const released = manifest?.packages[name];
2316
+ if (released && parseVersion(released)) return released;
2317
+ let best = null;
2318
+ for (const file of manifests) {
2319
+ let json;
2320
+ try {
2321
+ json = JSON.parse(readFileSync(path20.join(root, file), "utf8"));
2322
+ } catch {
2323
+ continue;
2324
+ }
2325
+ for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
2326
+ const spec = json[section]?.[name];
2327
+ const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
2328
+ const parsed = v && parseVersion(v);
2329
+ if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
2330
+ }
2331
+ }
2332
+ return best;
2333
+ }
2098
2334
  function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
2099
2335
  let packages;
2100
2336
  try {
@@ -2107,7 +2343,7 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
2107
2343
  const file = `${pkg.rel}/package.json`;
2108
2344
  let json;
2109
2345
  try {
2110
- json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
2346
+ json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
2111
2347
  } catch {
2112
2348
  continue;
2113
2349
  }
@@ -2150,6 +2386,18 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
2150
2386
  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`
2151
2387
  });
2152
2388
  }
2389
+ const pinned = pinnedVersion(ctx.root, pkg.name);
2390
+ const from = parseVersion(upstream);
2391
+ const to = pinned ? parseVersion(pinned) : null;
2392
+ if (from && to && compareVersions(from, to) < 0) {
2393
+ ctx.report({
2394
+ rule: "overlay-behind",
2395
+ level: "warn",
2396
+ file,
2397
+ subject: pkg.name,
2398
+ message: `the overlay of ${marker.upstream} is behind ${pkg.name}@${pinned}, the version the app now pins; run genesis upgrade, which rebases the overlay onto it (dropping what Genesis now ships) and moves the marker's upstream, or rebase it by hand`
2399
+ });
2400
+ }
2153
2401
  }
2154
2402
  }
2155
2403
 
@@ -2213,6 +2461,7 @@ var BUILTIN_RULES = [
2213
2461
  "overlay-invalid",
2214
2462
  "overlay-age",
2215
2463
  "overlay-version",
2464
+ "overlay-behind",
2216
2465
  // package rules (package-rules.ts): the rules themselves are namespaced, e.g. ui/lists-use-resource-view
2217
2466
  "package-rules-invalid",
2218
2467
  "package-rule-override",
@@ -2223,7 +2472,9 @@ var BUILTIN_RULES = [
2223
2472
  // agent guide (primitives.ts)
2224
2473
  "agent-guide-stale",
2225
2474
  // supabase pack: contracts (contracts.ts)
2226
- "contracts-stale"
2475
+ "contracts-stale",
2476
+ // genesis.lock.json against the files (lock-files.ts)
2477
+ "lock-files"
2227
2478
  ];
2228
2479
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2229
2480
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -2241,7 +2492,7 @@ function importSpecifiers(file) {
2241
2492
  }
2242
2493
  function checkProjectLayout(ctx) {
2243
2494
  for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
2244
- if (existsSync(path19.join(ctx.root, dir))) {
2495
+ if (existsSync(path20.join(ctx.root, dir))) {
2245
2496
  ctx.report({
2246
2497
  rule: "local-primitives",
2247
2498
  file: dir,
@@ -2251,7 +2502,7 @@ function checkProjectLayout(ctx) {
2251
2502
  }
2252
2503
  }
2253
2504
  for (const file of STARTER_LEFTOVERS) {
2254
- if (existsSync(path19.join(ctx.root, file))) {
2505
+ if (existsSync(path20.join(ctx.root, file))) {
2255
2506
  ctx.report({
2256
2507
  rule: "starter-leftover",
2257
2508
  level: "warn",
@@ -2341,7 +2592,7 @@ function checkTokens(ctx) {
2341
2592
  }
2342
2593
  for (const pattern of ctx.config.tokenFiles ?? []) {
2343
2594
  if (/[*?]/.test(pattern)) continue;
2344
- const abs = path19.join(ctx.root, pattern);
2595
+ const abs = path20.join(ctx.root, pattern);
2345
2596
  if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
2346
2597
  for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
2347
2598
  }
@@ -2441,14 +2692,33 @@ var appFunctionality = (type, ...more) => ({
2441
2692
  function privacyApisFor(dependencies2) {
2442
2693
  return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
2443
2694
  }
2695
+
2696
+ // src/eas-placeholders.ts
2697
+ var EAS_PLACEHOLDERS = {
2698
+ REPLACE_WITH_APP_STORE_CONNECT_APP_ID: "the app's Apple ID from App Store Connect (create the app there, then App Information \u2192 General Information \u2192 Apple ID, a number)",
2699
+ REPLACE_WITH_APPLE_TEAM_ID: "your Apple Developer Team ID (developer.apple.com \u2192 Account \u2192 Membership details, 10 characters)",
2700
+ REPLACE_WITH_PATH_TO_GOOGLE_SERVICE_ACCOUNT_JSON: "the path to your Google Play service account key, a JSON file kept out of git (Play Console \u2192 Setup \u2192 API access); or delete submit.production.android until you ship to Google Play",
2701
+ REPLACE_WITH_APP_FOLDER: "the app's code folder (src, or apps/<name> in a monorepo)"
2702
+ };
2703
+ function placeholderKey(line, placeholder) {
2704
+ return new RegExp(`"([A-Za-z0-9_]+)"\\s*:\\s*"${placeholder}"`).exec(line)?.[1] ?? null;
2705
+ }
2706
+ function findPlaceholders(file, text) {
2707
+ const out = [];
2708
+ text.split("\n").forEach((line, i) => {
2709
+ if (!file.endsWith(".json") && /^\s*#/.test(line)) return;
2710
+ for (const m of line.matchAll(/\bREPLACE_WITH_[A-Z0-9_]+/g)) out.push({ line: i + 1, text: line, placeholder: m[0] });
2711
+ });
2712
+ return out;
2713
+ }
2444
2714
  var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
2445
2715
  var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
2446
2716
  var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
2447
2717
  function resolveLocal(root, fromFile, spec) {
2448
- const bases = spec.startsWith(".") ? [path19.resolve(path19.dirname(fromFile), spec)] : [path19.join(root, spec.slice(2)), path19.join(root, "src", spec.slice(2))];
2718
+ const bases = spec.startsWith(".") ? [path20.resolve(path20.dirname(fromFile), spec)] : [path20.join(root, spec.slice(2)), path20.join(root, "src", spec.slice(2))];
2449
2719
  for (const base of bases) {
2450
- const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path19.join(base, `index${e}`))].find(
2451
- (p) => SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p)
2720
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path20.join(base, `index${e}`))].find(
2721
+ (p) => SCRIPT_EXTS2.has(path20.extname(p)) && existsSync(p)
2452
2722
  );
2453
2723
  if (hit) return hit;
2454
2724
  }
@@ -2567,29 +2837,26 @@ function checkNativePack(ctx) {
2567
2837
  checkStoreReadiness(ctx);
2568
2838
  checkEasPlaceholders(ctx);
2569
2839
  }
2570
- var EAS_PLACEHOLDER = /\bREPLACE_WITH_[A-Z0-9_]+/g;
2571
2840
  function checkEasPlaceholders(ctx) {
2572
2841
  const files = [];
2573
- if (existsSync(path19.join(ctx.root, "eas.json"))) files.push("eas.json");
2574
- const workflows = path19.join(ctx.root, ".eas", "workflows");
2842
+ if (existsSync(path20.join(ctx.root, "eas.json"))) files.push("eas.json");
2843
+ const workflows = path20.join(ctx.root, ".eas", "workflows");
2575
2844
  if (existsSync(workflows)) {
2576
2845
  for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
2577
2846
  }
2578
2847
  for (const file of files) {
2579
- const lines = readFileSync(path19.join(ctx.root, file), "utf8").split("\n");
2580
- lines.forEach((text, i) => {
2581
- if (!file.endsWith(".json") && /^\s*#/.test(text)) return;
2582
- for (const m of text.matchAll(EAS_PLACEHOLDER)) {
2583
- ctx.report({
2584
- rule: "eas-placeholder",
2585
- level: "warn",
2586
- file,
2587
- line: i + 1,
2588
- subject: m[0],
2589
- message: m[0] === "REPLACE_WITH_APP_FOLDER" ? "still names REPLACE_WITH_APP_FOLDER, so only config changes start a preview; replace it with the app's code folder (src, or apps/<name> in a monorepo)" : `still has the template placeholder ${m[0]}; replace it before the job that reads it runs (see docs/NATIVE-RELEASE.md in the Genesis repository)`
2590
- });
2591
- }
2592
- });
2848
+ for (const hit of findPlaceholders(file, readFileSync(path20.join(ctx.root, file), "utf8"))) {
2849
+ const key2 = placeholderKey(hit.text, hit.placeholder);
2850
+ const what = EAS_PLACEHOLDERS[hit.placeholder];
2851
+ ctx.report({
2852
+ rule: "eas-placeholder",
2853
+ level: "warn",
2854
+ file,
2855
+ line: hit.line,
2856
+ subject: hit.placeholder,
2857
+ message: hit.placeholder === "REPLACE_WITH_APP_FOLDER" ? `still names REPLACE_WITH_APP_FOLDER, so only config changes start a preview; replace it with ${what}` : `${key2 ? `${key2} is` : "still has"} the template placeholder ${hit.placeholder}; replace it with ${what ?? "its value (see docs/NATIVE-RELEASE.md in the Genesis repository)"} before the job that reads it runs`
2858
+ });
2859
+ }
2593
2860
  }
2594
2861
  }
2595
2862
  var RN = String.raw`["']react-native["']`;
@@ -2657,7 +2924,7 @@ function checkCustomHeaders(ctx, pkg) {
2657
2924
  if (!JSX_EXTS3.has(file.ext)) continue;
2658
2925
  const code = file.code;
2659
2926
  const hidden = HIDES_HEADER.exec(code);
2660
- if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path19.posix.dirname(file.path), file.path);
2927
+ if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path20.posix.dirname(file.path), file.path);
2661
2928
  const own = hidden ? ownHeader(code, pkg) : null;
2662
2929
  if (hidden && own) {
2663
2930
  reported.add(file.path);
@@ -2685,7 +2952,7 @@ function checkCustomHeaders(ctx, pkg) {
2685
2952
  }
2686
2953
  for (const file of ctx.files) {
2687
2954
  if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
2688
- const layout = hidingLayouts.get(path19.posix.dirname(file.path));
2955
+ const layout = hidingLayouts.get(path20.posix.dirname(file.path));
2689
2956
  const own = layout ? ownHeader(file.code, pkg) : null;
2690
2957
  if (!layout || !own) continue;
2691
2958
  ctx.report({
@@ -2707,13 +2974,13 @@ function isLoadingOnlyRoute(code) {
2707
2974
  }
2708
2975
  function routerRoot(ctx) {
2709
2976
  if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
2710
- return existsSync(path19.join(ctx.root, "src", "app")) ? "src/app" : "app";
2977
+ return existsSync(path20.join(ctx.root, "src", "app")) ? "src/app" : "app";
2711
2978
  }
2712
2979
  function checkScreenLayouts(ctx, pkg) {
2713
2980
  const layouts = nativeLayouts(pkg);
2714
2981
  if (layouts.length === 0) return;
2715
2982
  const rootDir = routerRoot(ctx);
2716
- if (!existsSync(path19.join(ctx.root, rootDir))) {
2983
+ if (!existsSync(path20.join(ctx.root, rootDir))) {
2717
2984
  ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
2718
2985
  return;
2719
2986
  }
@@ -2769,7 +3036,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
2769
3036
  function readExpoConfigs(root) {
2770
3037
  const out = [];
2771
3038
  for (const name of EXPO_CONFIGS) {
2772
- const abs = path19.join(root, name);
3039
+ const abs = path20.join(root, name);
2773
3040
  if (!existsSync(abs)) continue;
2774
3041
  const text = readFileSync(abs, "utf8");
2775
3042
  let json = null;
@@ -2803,13 +3070,13 @@ function pluginOptions(json, module) {
2803
3070
  return null;
2804
3071
  }
2805
3072
  function dependencies(root) {
2806
- const file = path19.join(root, "package.json");
3073
+ const file = path20.join(root, "package.json");
2807
3074
  if (!existsSync(file)) return /* @__PURE__ */ new Set();
2808
3075
  const pkg = JSON.parse(readFileSync(file, "utf8"));
2809
3076
  return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
2810
3077
  }
2811
3078
  function runtimeDependencies(root) {
2812
- const file = path19.join(root, "package.json");
3079
+ const file = path20.join(root, "package.json");
2813
3080
  if (!existsSync(file)) return {};
2814
3081
  return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
2815
3082
  }
@@ -2890,126 +3157,6 @@ function checkStoreReadiness(ctx) {
2890
3157
  });
2891
3158
  }
2892
3159
  }
2893
-
2894
- // src/doctor/semver.ts
2895
- var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
2896
- function parseVersion(v) {
2897
- const m = VERSION.exec(v.trim());
2898
- return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
2899
- }
2900
- function compareVersions(a, b) {
2901
- for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
2902
- if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
2903
- for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
2904
- const x = a.pre[i];
2905
- const y = b.pre[i];
2906
- if (x === void 0) return -1;
2907
- if (y === void 0) return 1;
2908
- if (x === y) continue;
2909
- const nx = /^\d+$/.test(x);
2910
- const ny = /^\d+$/.test(y);
2911
- if (nx && ny) return +x < +y ? -1 : 1;
2912
- if (nx !== ny) return nx ? -1 : 1;
2913
- return x < y ? -1 : 1;
2914
- }
2915
- return 0;
2916
- }
2917
- function partial(s) {
2918
- const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
2919
- if (!m) return null;
2920
- const nums = [];
2921
- let wild = false;
2922
- for (const part of [m[1], m[2], m[3]]) {
2923
- if (wild || part === void 0 || /^[xX*]$/.test(part)) {
2924
- wild = true;
2925
- nums.push(null);
2926
- } else nums.push(+part);
2927
- }
2928
- return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
2929
- }
2930
- var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
2931
- function comparators(token) {
2932
- const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
2933
- if (!m) return null;
2934
- const op = m[1] ?? "";
2935
- const p = partial(m[2]);
2936
- if (!p) return null;
2937
- const [major, mi, pa] = p.nums;
2938
- if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
2939
- const M = major;
2940
- const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
2941
- const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
2942
- const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
2943
- const out = switchOp();
2944
- if (p.pre.length) {
2945
- for (const c of out) if (c.v === lo) c.pre = true;
2946
- }
2947
- return out;
2948
- function switchOp() {
2949
- switch (op) {
2950
- case "^": {
2951
- const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
2952
- return [
2953
- { op: ">=", v: lo },
2954
- { op: "<", v: bound }
2955
- ];
2956
- }
2957
- case "~":
2958
- case "~>":
2959
- return [
2960
- { op: ">=", v: lo },
2961
- { op: "<", v: mi === null ? next("major") : next("minor") }
2962
- ];
2963
- case ">":
2964
- return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
2965
- case ">=":
2966
- return [{ op: ">=", v: lo }];
2967
- case "<":
2968
- return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
2969
- case "<=":
2970
- return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
2971
- default:
2972
- return upper ? [
2973
- { op: ">=", v: lo },
2974
- { op: "<", v: upper }
2975
- ] : [{ op: "=", v: lo }];
2976
- }
2977
- }
2978
- }
2979
- function test(c, v) {
2980
- const d = compareVersions(v, c.v);
2981
- return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
2982
- }
2983
- function parseRange(range) {
2984
- const alts = [];
2985
- for (const raw of range.trim().split("||")) {
2986
- const alt = raw.trim();
2987
- const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
2988
- if (hyphen) {
2989
- const from = comparators(`>=${hyphen[1]}`);
2990
- const to = comparators(`<=${hyphen[2]}`);
2991
- if (!from || !to) return null;
2992
- alts.push([...from, ...to]);
2993
- continue;
2994
- }
2995
- const set = [];
2996
- for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
2997
- const cs = comparators(token);
2998
- if (!cs) return null;
2999
- set.push(...cs);
3000
- }
3001
- alts.push(set);
3002
- }
3003
- return alts;
3004
- }
3005
- function satisfies(version, range) {
3006
- const v = parseVersion(version);
3007
- const alts = parseRange(range);
3008
- if (!v || !alts) return null;
3009
- return alts.some(
3010
- (set) => set.every((c) => test(c, v)) && (!v.pre.length || set.some((c) => c.pre && c.v.major === v.major && c.v.minor === v.minor && c.v.patch === v.patch))
3011
- );
3012
- }
3013
3160
  var TRAIL_DEPTH = 6;
3014
3161
  var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
3015
3162
  var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
@@ -3183,14 +3330,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3183
3330
  seen.add(file);
3184
3331
  const json = readJsonc(file);
3185
3332
  if (!json) return {};
3186
- const dir = path19.dirname(file);
3333
+ const dir = path20.dirname(file);
3187
3334
  let merged = {};
3188
3335
  const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
3189
3336
  for (const ext of parents) {
3190
3337
  if (typeof ext !== "string") continue;
3191
3338
  let target = null;
3192
- if (ext.startsWith(".") || path19.isAbsolute(ext)) {
3193
- const abs = path19.resolve(dir, ext);
3339
+ if (ext.startsWith(".") || path20.isAbsolute(ext)) {
3340
+ const abs = path20.resolve(dir, ext);
3194
3341
  target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3195
3342
  } else {
3196
3343
  const parts = ext.split("/");
@@ -3198,14 +3345,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3198
3345
  const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
3199
3346
  if (pkgDir) {
3200
3347
  const sub = parts.slice(nameLength).join("/");
3201
- const abs = path19.join(pkgDir, sub || "tsconfig.json");
3348
+ const abs = path20.join(pkgDir, sub || "tsconfig.json");
3202
3349
  target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3203
3350
  }
3204
3351
  }
3205
3352
  if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
3206
3353
  }
3207
3354
  const opts = json.compilerOptions ?? {};
3208
- if (typeof opts.baseUrl === "string") merged.baseUrl = path19.resolve(dir, opts.baseUrl);
3355
+ if (typeof opts.baseUrl === "string") merged.baseUrl = path20.resolve(dir, opts.baseUrl);
3209
3356
  if (opts.paths && typeof opts.paths === "object") {
3210
3357
  merged.paths = opts.paths;
3211
3358
  merged.pathsDir = dir;
@@ -3216,7 +3363,7 @@ function aliases(root) {
3216
3363
  const table = [];
3217
3364
  let baseUrl = null;
3218
3365
  for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
3219
- const file = path19.join(root, name);
3366
+ const file = path20.join(root, name);
3220
3367
  if (!existsSync(file)) continue;
3221
3368
  const config = readTsconfig(root, file);
3222
3369
  baseUrl ??= config.baseUrl ?? null;
@@ -3224,22 +3371,22 @@ function aliases(root) {
3224
3371
  for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
3225
3372
  if (!Array.isArray(targets)) continue;
3226
3373
  const exact = !pattern.endsWith("*");
3227
- table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path19.join(base, String(t).replace(/\*$/, ""))) });
3374
+ table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path20.join(base, String(t).replace(/\*$/, ""))) });
3228
3375
  }
3229
3376
  }
3230
- const pkg = readJsonc(path19.join(root, "package.json"));
3377
+ const pkg = readJsonc(path20.join(root, "package.json"));
3231
3378
  for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
3232
3379
  if (typeof target !== "string") continue;
3233
- table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path19.join(root, target.replace(/\*.*$/, ""))] });
3380
+ table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path20.join(root, target.replace(/\*.*$/, ""))] });
3234
3381
  }
3235
- for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path19.join(root, "src") + path19.sep, root + path19.sep] });
3382
+ for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path20.join(root, "src") + path20.sep, root + path20.sep] });
3236
3383
  return { table, baseUrl };
3237
3384
  }
3238
3385
  function resolveFile(base) {
3239
- const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path19.join(base, `index${e}`))];
3386
+ const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path20.join(base, `index${e}`))];
3240
3387
  if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
3241
3388
  for (const p of tries) {
3242
- if (SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
3389
+ if (SCRIPT_EXTS2.has(path20.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
3243
3390
  }
3244
3391
  return null;
3245
3392
  }
@@ -3253,7 +3400,7 @@ function createTrail(ctx) {
3253
3400
  const { table, baseUrl } = aliases(ctx.root);
3254
3401
  let declared = null;
3255
3402
  try {
3256
- const pkg = JSON.parse(readFileSync(path19.join(ctx.root, "package.json"), "utf8"));
3403
+ const pkg = JSON.parse(readFileSync(path20.join(ctx.root, "package.json"), "utf8"));
3257
3404
  declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
3258
3405
  } catch {
3259
3406
  declared = null;
@@ -3284,17 +3431,17 @@ function createTrail(ctx) {
3284
3431
  if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
3285
3432
  let resolved = null;
3286
3433
  if (spec.startsWith(".")) {
3287
- resolved = resolveFile(path19.resolve(path19.dirname(file.absolutePath), spec));
3434
+ resolved = resolveFile(path20.resolve(path20.dirname(file.absolutePath), spec));
3288
3435
  if (!resolved) lost = true;
3289
3436
  } else {
3290
3437
  const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
3291
3438
  if (alias) {
3292
3439
  for (const t of alias.targets) {
3293
- resolved = resolveFile(alias.exact ? t : path19.join(t, spec.slice(alias.prefix.length)));
3440
+ resolved = resolveFile(alias.exact ? t : path20.join(t, spec.slice(alias.prefix.length)));
3294
3441
  if (resolved) break;
3295
3442
  }
3296
3443
  }
3297
- if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path19.join(baseUrl, spec));
3444
+ if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path20.join(baseUrl, spec));
3298
3445
  if (!resolved) {
3299
3446
  const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
3300
3447
  if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
@@ -3365,27 +3512,149 @@ function createTrail(ctx) {
3365
3512
  };
3366
3513
  return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
3367
3514
  }
3515
+ function buildCatalog(packagesDir) {
3516
+ const packages = {};
3517
+ for (const dir of readdirSync(packagesDir).sort()) {
3518
+ const file = path20.join(packagesDir, dir, "package.json");
3519
+ if (!existsSync(file)) continue;
3520
+ const pkg = JSON.parse(readFileSync(file, "utf8"));
3521
+ if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
3522
+ packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
3523
+ }
3524
+ return { packages };
3525
+ }
3368
3526
 
3369
3527
  // src/blocks/discover.ts
3528
+ var CLI_PACKAGE = "@marktiderman/genesis-cli";
3529
+ function cliPackageDir() {
3530
+ let dir = path20.dirname(fileURLToPath(import.meta.url));
3531
+ for (; ; ) {
3532
+ const file = path20.join(dir, "package.json");
3533
+ if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
3534
+ const parent = path20.dirname(dir);
3535
+ if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
3536
+ dir = parent;
3537
+ }
3538
+ }
3539
+ function workspacePackagesDir() {
3540
+ const dir = path20.resolve(cliPackageDir(), "..");
3541
+ return existsSync(path20.join(dir, "features", "package.json")) && existsSync(path20.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
3542
+ }
3543
+ var catalogCache;
3544
+ function readCatalog() {
3545
+ if (catalogCache) return catalogCache;
3546
+ const workspace = workspacePackagesDir();
3547
+ if (workspace) return catalogCache = buildCatalog(workspace);
3548
+ const file = path20.join(cliPackageDir(), "dist", "genesis-catalog.json");
3549
+ catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
3550
+ return catalogCache;
3551
+ }
3370
3552
  var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
3371
3553
  function installedGenesis(root) {
3372
3554
  const found = /* @__PURE__ */ new Map();
3373
- let dir = path19.resolve(root);
3555
+ let dir = path20.resolve(root);
3374
3556
  for (; ; ) {
3375
- const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path19.join(dir, m)));
3376
- const scope = path19.join(dir, "node_modules", "@marktiderman");
3557
+ const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path20.join(dir, m)));
3558
+ const scope = path20.join(dir, "node_modules", "@marktiderman");
3377
3559
  if (existsSync(scope)) {
3378
3560
  for (const entry of readdirSync(scope)) {
3379
3561
  const name = `@marktiderman/${entry}`;
3380
3562
  if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
3381
- if (existsSync(path19.join(scope, entry, "package.json"))) found.set(name, path19.join(scope, entry));
3563
+ if (existsSync(path20.join(scope, entry, "package.json"))) found.set(name, path20.join(scope, entry));
3382
3564
  }
3383
3565
  }
3384
- const parent = path19.dirname(dir);
3566
+ const parent = path20.dirname(dir);
3385
3567
  if (atInstallRoot || parent === dir) return found;
3386
3568
  dir = parent;
3387
3569
  }
3388
3570
  }
3571
+ var declarationCache = /* @__PURE__ */ new Map();
3572
+ function declarationsOf(dir, warnings) {
3573
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
3574
+ const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
3575
+ let cached = declarationCache.get(key2);
3576
+ if (!cached) {
3577
+ cached = loadDeclarations(dir, warnings);
3578
+ declarationCache.set(key2, cached);
3579
+ }
3580
+ return cached;
3581
+ }
3582
+ async function loadDeclarations(dir, warnings) {
3583
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
3584
+ const entry = pkg.exports?.["./blocks"];
3585
+ const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
3586
+ if (typeof target !== "string") return {};
3587
+ const rel = safeRelative(target.replace(/^\.\//, ""));
3588
+ const file = rel && path20.join(dir, ...rel.split("/"));
3589
+ if (!file || !inside(dir, file) || !existsSync(file)) return {};
3590
+ try {
3591
+ const jiti = createJiti(path20.join(dir, "package.json"), { moduleCache: false });
3592
+ const mod = await jiti.import(file);
3593
+ const out = {};
3594
+ for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
3595
+ return out;
3596
+ } catch (err) {
3597
+ warnings.push(`${pkg.name}/blocks didn't load in Node (${err instanceof Error ? err.message.split("\n")[0] : String(err)}); using its package.json manifest only.`);
3598
+ return {};
3599
+ }
3600
+ }
3601
+ async function blocksOfInstalled(dir, warnings = [], options = {}) {
3602
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
3603
+ const raw = rawBlocksOf(pkg);
3604
+ const declared = await declarationsOf(dir, warnings);
3605
+ const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
3606
+ const out = [];
3607
+ for (const id of [...ids].sort()) {
3608
+ const fromJson = raw[id] ?? {};
3609
+ const manifest = tryParse(() => parseManifest(pkg.name, id, { ...fromJson, ...declared[id] }, pkg.version, options), warnings);
3610
+ if (manifest) out.push(manifest);
3611
+ }
3612
+ return out;
3613
+ }
3614
+ async function allBlocks(root, warnings = []) {
3615
+ const out = [];
3616
+ for (const local of localPackages(root)) {
3617
+ for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
3618
+ }
3619
+ const installed = installedGenesis(root);
3620
+ for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
3621
+ for (const [name, entry] of Object.entries(readCatalog().packages)) {
3622
+ if (installed.has(name)) continue;
3623
+ for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
3624
+ const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
3625
+ if (manifest) out.push({ manifest, from: "catalog" });
3626
+ }
3627
+ }
3628
+ return out;
3629
+ }
3630
+ function tryParse(parse2, warnings) {
3631
+ try {
3632
+ return parse2();
3633
+ } catch (err) {
3634
+ if (!(err instanceof ManifestError)) throw err;
3635
+ warnings.push(err.message);
3636
+ return null;
3637
+ }
3638
+ }
3639
+ function catalogBlocks(warnings = []) {
3640
+ const out = [];
3641
+ for (const [name, entry] of Object.entries(readCatalog().packages)) {
3642
+ for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
3643
+ const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
3644
+ if (manifest) out.push(manifest);
3645
+ }
3646
+ }
3647
+ return out;
3648
+ }
3649
+ async function findBlock(root, id, options = {}) {
3650
+ const all = (await allBlocks(root, options.warnings)).filter((b) => b.manifest.id === id && (!options.package || b.manifest.package === options.package));
3651
+ if (all.length === 0) {
3652
+ const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
3653
+ throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
3654
+ }
3655
+ if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
3656
+ return all[0];
3657
+ }
3389
3658
  var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
3390
3659
  var STEMS = {
3391
3660
  tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
@@ -3403,7 +3672,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
3403
3672
  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;
3404
3673
  function routesDir(ctx) {
3405
3674
  if (ctx.config.routesDir) return ctx.config.routesDir;
3406
- return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path19.join(ctx.root, d))) ?? null;
3675
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path20.join(ctx.root, d))) ?? null;
3407
3676
  }
3408
3677
  var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
3409
3678
  function flavorOf(dir, rels) {
@@ -3538,7 +3807,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
3538
3807
  });
3539
3808
  if (typeof raw === "string") {
3540
3809
  if (!packageDir) fail(`points at ${raw}, but the package folder is unknown`);
3541
- const file = path19.resolve(packageDir, raw);
3810
+ const file = path20.resolve(packageDir, raw);
3542
3811
  if (!inside(packageDir, file)) fail(`points outside the package (${raw})`);
3543
3812
  if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
3544
3813
  let parsed;
@@ -3587,7 +3856,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
3587
3856
  if (typeof c.plugin === "string") {
3588
3857
  if (!packageDir) plugin = c.plugin;
3589
3858
  else {
3590
- plugin = path19.resolve(packageDir, c.plugin);
3859
+ plugin = path20.resolve(packageDir, c.plugin);
3591
3860
  if (!inside(packageDir, plugin)) fail(`plugin points outside the package (${c.plugin})`);
3592
3861
  }
3593
3862
  }
@@ -3637,7 +3906,7 @@ function checkPattern(v, where2, fail) {
3637
3906
  }
3638
3907
  var discoveryCache = /* @__PURE__ */ new Map();
3639
3908
  function readDeclaringPackage(dir, local) {
3640
- const file = path19.join(dir, "package.json");
3909
+ const file = path20.join(dir, "package.json");
3641
3910
  let stamp;
3642
3911
  let real2;
3643
3912
  try {
@@ -3660,7 +3929,7 @@ ${local}`;
3660
3929
  const pkg = {
3661
3930
  name: json.name,
3662
3931
  version: typeof json.version === "string" ? json.version : "0.0.0",
3663
- dir: path19.resolve(dir),
3932
+ dir: path20.resolve(dir),
3664
3933
  namespace: ruleNamespace(json.name),
3665
3934
  local,
3666
3935
  private: json.private === true,
@@ -3674,7 +3943,7 @@ ${local}`;
3674
3943
  if (raw !== void 0) {
3675
3944
  const ignored = [];
3676
3945
  try {
3677
- pkg.declaration = validateDeclaration(raw, json.name, path19.resolve(dir), ignored);
3946
+ pkg.declaration = validateDeclaration(raw, json.name, path20.resolve(dir), ignored);
3678
3947
  if (ignored.length) pkg.ignored = ignored;
3679
3948
  } catch (err) {
3680
3949
  pkg.error = err.message;
@@ -3693,14 +3962,14 @@ function discoverPackages(root) {
3693
3962
  for (const dir of installed) {
3694
3963
  let scope;
3695
3964
  try {
3696
- scope = path19.dirname(realpathSync(dir));
3965
+ scope = path20.dirname(realpathSync(dir));
3697
3966
  } catch {
3698
3967
  continue;
3699
3968
  }
3700
- if (path19.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
3969
+ if (path20.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
3701
3970
  for (const entry of readdirSync(scope)) {
3702
3971
  if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
3703
- const pkg = readDeclaringPackage(path19.join(scope, entry), false);
3972
+ const pkg = readDeclaringPackage(path20.join(scope, entry), false);
3704
3973
  if (pkg) byName.set(pkg.name, pkg);
3705
3974
  }
3706
3975
  }
@@ -3884,10 +4153,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
3884
4153
  var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
3885
4154
  function sourceFiles(dir, rel = "") {
3886
4155
  const out = [];
3887
- for (const entry of readdirSync(path19.join(dir, rel)).sort()) {
4156
+ for (const entry of readdirSync(path20.join(dir, rel)).sort()) {
3888
4157
  if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
3889
4158
  const child = rel ? `${rel}/${entry}` : entry;
3890
- const stat = lstatSync(path19.join(dir, child));
4159
+ const stat = lstatSync(path20.join(dir, child));
3891
4160
  if (stat.isSymbolicLink()) continue;
3892
4161
  if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
3893
4162
  else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
@@ -3910,13 +4179,13 @@ function matchPattern(pattern, spec) {
3910
4179
  return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
3911
4180
  }
3912
4181
  function tsconfigPaths(dir) {
3913
- const file = path19.join(dir, "tsconfig.json");
4182
+ const file = path20.join(dir, "tsconfig.json");
3914
4183
  if (!existsSync(file)) return [];
3915
4184
  try {
3916
4185
  const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
3917
4186
  const options = JSON.parse(text).compilerOptions ?? {};
3918
- const base = path19.resolve(dir, options.baseUrl ?? ".");
3919
- return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path19.resolve(base, t)) }));
4187
+ const base = path20.resolve(dir, options.baseUrl ?? ".");
4188
+ return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path20.resolve(base, t)) }));
3920
4189
  } catch {
3921
4190
  return [];
3922
4191
  }
@@ -3930,8 +4199,8 @@ function checkImports2(ctx, pkg, json) {
3930
4199
  const hit = matchPattern(pattern, spec);
3931
4200
  if (hit === null) continue;
3932
4201
  return targets.some((t) => {
3933
- const rel = path19.relative(pkg.dir, t.replace("*", hit));
3934
- return !rel.startsWith("..") && !path19.isAbsolute(rel);
4202
+ const rel = path20.relative(pkg.dir, t.replace("*", hit));
4203
+ return !rel.startsWith("..") && !path20.isAbsolute(rel);
3935
4204
  });
3936
4205
  }
3937
4206
  return null;
@@ -3944,7 +4213,7 @@ function checkImports2(ctx, pkg, json) {
3944
4213
  ...Object.keys(json.optionalDependencies ?? {})
3945
4214
  ]);
3946
4215
  for (const file of sourceFiles(pkg.dir)) {
3947
- const code = stripForImports(readFileSync(path19.join(pkg.dir, file), "utf8"));
4216
+ const code = stripForImports(readFileSync(path20.join(pkg.dir, file), "utf8"));
3948
4217
  if (code === null) continue;
3949
4218
  const at = `${pkg.rel}/${file}`;
3950
4219
  const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
@@ -3969,9 +4238,9 @@ function checkImports2(ctx, pkg, json) {
3969
4238
  continue;
3970
4239
  }
3971
4240
  if (spec.startsWith(".")) {
3972
- const target = path19.resolve(pkg.dir, path19.dirname(file), spec);
3973
- const rel = path19.relative(pkg.dir, target);
3974
- if (rel.startsWith("..") || path19.isAbsolute(rel)) {
4241
+ const target = path20.resolve(pkg.dir, path20.dirname(file), spec);
4242
+ const rel = path20.relative(pkg.dir, target);
4243
+ if (rel.startsWith("..") || path20.isAbsolute(rel)) {
3975
4244
  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` });
3976
4245
  }
3977
4246
  continue;
@@ -4008,12 +4277,12 @@ function checkMigrations(ctx, pkg, json, locals) {
4008
4277
  const from = own ? "" : ` (in ${m.package})`;
4009
4278
  if (typeof m.file === "string" && typeof m.test !== "string") {
4010
4279
  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` });
4011
- } else if (typeof m.test === "string" && !existsSync(path19.join(home, m.test))) {
4280
+ } else if (typeof m.test === "string" && !existsSync(path20.join(home, m.test))) {
4012
4281
  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` });
4013
4282
  }
4014
4283
  }
4015
4284
  }
4016
- const dir = path19.join(pkg.dir, "migrations");
4285
+ const dir = path20.join(pkg.dir, "migrations");
4017
4286
  if (!existsSync(dir)) return;
4018
4287
  const seen = /* @__PURE__ */ new Map();
4019
4288
  for (const name of readdirSync(dir).sort()) {
@@ -4022,21 +4291,21 @@ function checkMigrations(ctx, pkg, json, locals) {
4022
4291
  const other = seen.get(m[1]);
4023
4292
  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` });
4024
4293
  else seen.set(m[1], name);
4025
- if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path19.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
4294
+ if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path20.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
4026
4295
  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")})` });
4027
4296
  }
4028
4297
  }
4029
4298
  }
4030
4299
  function checkExports(ctx, pkg, json) {
4031
4300
  const targets = [];
4032
- const walk = (v) => {
4301
+ const walk2 = (v) => {
4033
4302
  if (typeof v === "string") targets.push(v);
4034
- else if (v && typeof v === "object") for (const x of Object.values(v)) walk(x);
4303
+ else if (v && typeof v === "object") for (const x of Object.values(v)) walk2(x);
4035
4304
  };
4036
- walk(json.exports);
4305
+ walk2(json.exports);
4037
4306
  for (const t of targets) {
4038
4307
  if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
4039
- if (!existsSync(path19.join(pkg.dir, t))) {
4308
+ if (!existsSync(path20.join(pkg.dir, t))) {
4040
4309
  ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
4041
4310
  }
4042
4311
  }
@@ -4054,11 +4323,11 @@ function checkBlocks(ctx, pkg, json) {
4054
4323
  function checkTaggedTests(ctx, pkg) {
4055
4324
  const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
4056
4325
  if (!tests.length) return;
4057
- const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path19.join(pkg.dir, f), "utf8")));
4326
+ const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path20.join(pkg.dir, f), "utf8")));
4058
4327
  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>` });
4059
4328
  }
4060
4329
  function checkRegistered(ctx, pkg) {
4061
- const file = path19.join(ctx.root, "features.json");
4330
+ const file = path20.join(ctx.root, "features.json");
4062
4331
  if (!existsSync(file)) return;
4063
4332
  let doc;
4064
4333
  try {
@@ -4068,7 +4337,7 @@ function checkRegistered(ctx, pkg) {
4068
4337
  }
4069
4338
  const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
4070
4339
  const forms = /* @__PURE__ */ new Set([pkg.rel]);
4071
- if (top) forms.add(path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/"));
4340
+ if (top) forms.add(path20.relative(top, realpathSync(pkg.dir)).split(path20.sep).join("/"));
4072
4341
  const covered = (doc.features ?? []).some(
4073
4342
  (f) => (f.links?.code ?? []).some((c) => {
4074
4343
  const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
@@ -4098,8 +4367,8 @@ function mergeBaseOf(root, base) {
4098
4367
  function checkChanges(ctx, pkg, json, base, mergeBase) {
4099
4368
  const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
4100
4369
  if (!top) return;
4101
- const appRelative = (fromTop) => path19.relative(realpathSync(ctx.root), path19.join(top, fromTop)).split(path19.sep).join("/");
4102
- const inRepo = path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/");
4370
+ const appRelative = (fromTop) => path20.relative(realpathSync(ctx.root), path20.join(top, fromTop)).split(path20.sep).join("/");
4371
+ const inRepo = path20.relative(top, realpathSync(pkg.dir)).split(path20.sep).join("/");
4103
4372
  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");
4104
4373
  const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
4105
4374
  const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
@@ -4122,11 +4391,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
4122
4391
  const now = typeof json.version === "string" ? parseVersion(json.version) : null;
4123
4392
  const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
4124
4393
  const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
4125
- 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)) : [];
4394
+ 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) => path20.join(top, f)) : [];
4126
4395
  const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
4127
4396
  const named = naming.length > 0;
4128
4397
  if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
4129
- 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` });
4398
+ ctx.report({ rule: "package-unversioned-change", level: "warn", file: path20.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
4130
4399
  }
4131
4400
  let jsonBefore = null;
4132
4401
  try {
@@ -4136,7 +4405,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
4136
4405
  }
4137
4406
  const raw = json;
4138
4407
  if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
4139
- const appInRepo = path19.relative(top, realpathSync(ctx.root)).split(path19.sep).join("/");
4408
+ const appInRepo = path20.relative(top, realpathSync(ctx.root)).split(path20.sep).join("/");
4140
4409
  const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
4141
4410
  const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
4142
4411
  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` });
@@ -4188,7 +4457,7 @@ function checkPackagesPack(ctx) {
4188
4457
  ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
4189
4458
  }
4190
4459
  for (const pkg of packages) {
4191
- const json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
4460
+ const json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
4192
4461
  checkImports2(ctx, pkg, json);
4193
4462
  checkExports(ctx, pkg, json);
4194
4463
  checkBlocks(ctx, pkg, json);
@@ -4382,9 +4651,9 @@ function gitView(root, dir, base) {
4382
4651
  function checkSupabasePack(ctx) {
4383
4652
  const settings = ctx.config.supabase ?? {};
4384
4653
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
4385
- const abs = path19.join(ctx.root, dir);
4654
+ const abs = path20.join(ctx.root, dir);
4386
4655
  if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
4387
- const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path19.join(abs, n), "utf8")) }));
4656
+ const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path20.join(abs, n), "utf8")) }));
4388
4657
  const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
4389
4658
  const base = settings.base ?? DEFAULT_BASE;
4390
4659
  const view = gitView(ctx.root, dir, base);
@@ -4401,7 +4670,7 @@ function checkSupabasePack(ctx) {
4401
4670
  }
4402
4671
  }
4403
4672
  const since = settings.since;
4404
- const afterSince = (file) => since === void 0 || path19.posix.basename(file) >= since;
4673
+ const afterSince = (file) => since === void 0 || path20.posix.basename(file) >= since;
4405
4674
  if ("reason" in view && since === void 0) {
4406
4675
  ctx.report({
4407
4676
  rule: "migration-grants",
@@ -4679,51 +4948,12 @@ function checkDefinerSearchPath(ctx, migrations) {
4679
4948
  });
4680
4949
  }
4681
4950
  }
4682
- var UMBRELLA_PACKAGE = "@marktiderman/genesis";
4683
- function readReleaseManifest(root) {
4684
- const dir = findPackageDir(root, UMBRELLA_PACKAGE);
4685
- const file = dir && path19.join(dir, "dist", "versions.json");
4686
- if (!file || !existsSync(file)) return null;
4687
- return JSON.parse(readFileSync(file, "utf8"));
4688
- }
4689
- function checkVersionSkew(ctx) {
4690
- const manifest = readReleaseManifest(ctx.root);
4691
- if (!manifest) return;
4692
- const overlays = markedOverlays(ctx);
4693
- for (const [name, want] of Object.entries(manifest.packages)) {
4694
- const overlay = overlays.get(name);
4695
- if (overlay) {
4696
- const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
4697
- if (from !== want) {
4698
- ctx.report({
4699
- rule: "version-skew",
4700
- level: "warn",
4701
- file: "package.json",
4702
- subject: name,
4703
- 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).`
4704
- });
4705
- }
4706
- continue;
4707
- }
4708
- const dir = findPackageDir(ctx.root, name);
4709
- if (!dir) continue;
4710
- const have = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8")).version;
4711
- if (have === want) continue;
4712
- ctx.report({
4713
- rule: "version-skew",
4714
- level: "warn",
4715
- file: "package.json",
4716
- subject: name,
4717
- message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
4718
- });
4719
- }
4720
- }
4721
4951
  var GENESIS2 = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
4722
4952
  var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
4723
4953
  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)$/;
4724
4954
  var readManifest = (dir) => {
4725
4955
  try {
4726
- return JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
4956
+ return JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
4727
4957
  } catch {
4728
4958
  return null;
4729
4959
  }
@@ -4737,18 +4967,18 @@ var real = (p) => {
4737
4967
  };
4738
4968
  var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
4739
4969
  function nodeModulesOf(dir) {
4740
- const parent = path19.dirname(dir);
4741
- return path19.basename(parent).startsWith("@") ? path19.dirname(parent) : parent;
4970
+ const parent = path20.dirname(dir);
4971
+ return path20.basename(parent).startsWith("@") ? path20.dirname(parent) : parent;
4742
4972
  }
4743
4973
  function packagesIn(nodeModules) {
4744
4974
  if (!existsSync(nodeModules)) return [];
4745
4975
  const out = [];
4746
4976
  for (const entry of readdirSync(nodeModules)) {
4747
4977
  if (entry.startsWith(".")) continue;
4748
- const p = path19.join(nodeModules, entry);
4978
+ const p = path20.join(nodeModules, entry);
4749
4979
  if (entry.startsWith("@")) {
4750
4980
  try {
4751
- for (const sub of readdirSync(p)) out.push(path19.join(p, sub));
4981
+ for (const sub of readdirSync(p)) out.push(path20.join(p, sub));
4752
4982
  } catch {
4753
4983
  }
4754
4984
  } else {
@@ -4760,7 +4990,7 @@ function packagesIn(nodeModules) {
4760
4990
  function genesisInstalls(root) {
4761
4991
  const copies = /* @__PURE__ */ new Map();
4762
4992
  const realRoot = real(root);
4763
- const rel = (abs) => path19.relative(realRoot, abs).split(path19.sep).join("/") || ".";
4993
+ const rel = (abs) => path20.relative(realRoot, abs).split(path20.sep).join("/") || ".";
4764
4994
  const via = /* @__PURE__ */ new Map();
4765
4995
  const record = (real2, manifest, by, range, root2) => {
4766
4996
  let copy = copies.get(real2);
@@ -4772,7 +5002,7 @@ function genesisInstalls(root) {
4772
5002
  via.get(real2).add(root2);
4773
5003
  if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
4774
5004
  };
4775
- const walk = (kind, roots) => {
5005
+ const walk2 = (kind, roots) => {
4776
5006
  const expanded = /* @__PURE__ */ new Set();
4777
5007
  const queue = [];
4778
5008
  const visit = (dir, by, range) => {
@@ -4805,7 +5035,7 @@ function genesisInstalls(root) {
4805
5035
  if (!dir) return null;
4806
5036
  if (!ownInstall || name in declared) return dir;
4807
5037
  const realDir = real(dir);
4808
- if (realDir.startsWith(realRoot + path19.sep)) return dir;
5038
+ if (realDir.startsWith(realRoot + path20.sep)) return dir;
4809
5039
  return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
4810
5040
  };
4811
5041
  const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
@@ -4813,7 +5043,7 @@ function genesisInstalls(root) {
4813
5043
  return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
4814
5044
  });
4815
5045
  const app = readManifest(root);
4816
- const ownInstall = LOCKFILES.some((f) => existsSync(path19.join(root, f)));
5046
+ const ownInstall = LOCKFILES.some((f) => existsSync(path20.join(root, f)));
4817
5047
  const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
4818
5048
  const declaredDev = Object.entries(app?.devDependencies ?? {});
4819
5049
  const runtimeDeps = {
@@ -4823,18 +5053,18 @@ function genesisInstalls(root) {
4823
5053
  ...app?.dependencies
4824
5054
  };
4825
5055
  const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
4826
- walk("runtime", rootsOf(runtimeDeps, "the app"));
4827
- const top = path19.join(root, "node_modules");
4828
- walk(
5056
+ walk2("runtime", rootsOf(runtimeDeps, "the app"));
5057
+ const top = path20.join(root, "node_modules");
5058
+ walk2(
4829
5059
  "hoisted",
4830
5060
  packagesIn(top).filter((dir) => {
4831
- const name = path19.relative(top, dir).split(path19.sep).join("/");
5061
+ const name = path20.relative(top, dir).split(path20.sep).join("/");
4832
5062
  return !(name in runtimeDeps) && !(name in devDeps);
4833
5063
  }).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
4834
5064
  );
4835
5065
  const devRoots = { ...devDeps };
4836
5066
  for (const tool of DEV_TOOLS) if (!(tool in devRoots) && tool in runtimeDeps) devRoots[tool] = runtimeDeps[tool];
4837
- walk("dev", rootsOf(devRoots, "the app (dev)"));
5067
+ walk2("dev", rootsOf(devRoots, "the app (dev)"));
4838
5068
  for (const [key2, copy] of copies) {
4839
5069
  const kinds = via.get(key2);
4840
5070
  copy.runtime = kinds.has("runtime");
@@ -4870,7 +5100,7 @@ function checkDuplicatePackages(ctx) {
4870
5100
  }
4871
5101
  }
4872
5102
  function checkPeerRanges(ctx) {
4873
- const rel = (abs) => path19.relative(ctx.root, abs).split(path19.sep).join("/");
5103
+ const rel = (abs) => path20.relative(ctx.root, abs).split(path20.sep).join("/");
4874
5104
  for (const copies of genesisInstalls(ctx.root).values()) {
4875
5105
  for (const copy of copies) {
4876
5106
  const dir = copy.absolutePath;
@@ -5252,17 +5482,17 @@ var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
5252
5482
  var MAX_BYTES = 2 * 1024 * 1024;
5253
5483
  function appScripts(root) {
5254
5484
  const out = [];
5255
- const walk = (dir) => {
5485
+ const walk2 = (dir) => {
5256
5486
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
5257
- const abs = path19.join(dir, entry.name);
5487
+ const abs = path20.join(dir, entry.name);
5258
5488
  if (entry.isDirectory()) {
5259
- if (!SKIP_DIRS3.has(entry.name)) walk(abs);
5489
+ if (!SKIP_DIRS3.has(entry.name)) walk2(abs);
5260
5490
  } else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
5261
- out.push(path19.relative(root, abs).split(path19.sep).join("/"));
5491
+ out.push(path20.relative(root, abs).split(path20.sep).join("/"));
5262
5492
  }
5263
5493
  }
5264
5494
  };
5265
- walk(root);
5495
+ walk2(root);
5266
5496
  return out;
5267
5497
  }
5268
5498
 
@@ -5346,7 +5576,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
5346
5576
  function moduleFiles(ctx) {
5347
5577
  const scanned = new Set(ctx.files.map((f) => f.path));
5348
5578
  const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
5349
- 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) }));
5579
+ const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path20.join(ctx.root, rel), "utf8"), true) }));
5350
5580
  return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
5351
5581
  }
5352
5582
  function checkStudioServerImports(ctx) {
@@ -5382,7 +5612,7 @@ var REMOVED_WORDS = {
5382
5612
  };
5383
5613
  function checkRemovedScopeNames(ctx) {
5384
5614
  let augmentedMemo;
5385
- 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")));
5615
+ const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path20.join(ctx.root, rel), "utf8")));
5386
5616
  for (const file of ctx.files) {
5387
5617
  if (!SCRIPT_EXTS5.has(file.ext)) continue;
5388
5618
  for (const hit of findRemovedScopeNames(file.code)) {
@@ -5454,16 +5684,16 @@ function genesisNamedImports(source) {
5454
5684
  }
5455
5685
  function declarationFiles(dir, out = []) {
5456
5686
  for (const name of readdirSync(dir)) {
5457
- const full = path19.join(dir, name);
5687
+ const full = path20.join(dir, name);
5458
5688
  if (statSync(full).isDirectory()) declarationFiles(full, out);
5459
5689
  else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
5460
5690
  }
5461
5691
  return out;
5462
5692
  }
5463
5693
  function readPackageTags(dir) {
5464
- const pkg = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
5694
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
5465
5695
  const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
5466
- const dist = path19.join(dir, "dist");
5696
+ const dist = path20.join(dir, "dist");
5467
5697
  if (!existsSync(dist)) return tags;
5468
5698
  for (const file of declarationFiles(dist)) {
5469
5699
  const text = readFileSync(file, "utf8");
@@ -5481,7 +5711,7 @@ function entryFile(tags, pkg, specifier) {
5481
5711
  const subpath = `.${specifier.slice(pkg.length)}` || ".";
5482
5712
  const target = tags.exports[subpath === "." ? "." : subpath];
5483
5713
  const types = typeof target === "object" && target ? target.types : null;
5484
- return typeof types === "string" ? path19.join(tags.dir, types) : null;
5714
+ return typeof types === "string" ? path20.join(tags.dir, types) : null;
5485
5715
  }
5486
5716
  function tagFor(tags, entry, name) {
5487
5717
  if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
@@ -5536,7 +5766,7 @@ function showAt(dir, rev, file) {
5536
5766
  function configAtBase(root, base, explicitFile) {
5537
5767
  const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
5538
5768
  if (!mergeBase) return null;
5539
- const candidates = explicitFile ? [{ dir: path19.dirname(explicitFile), file: path19.basename(explicitFile), explicit: true }] : [
5769
+ const candidates = explicitFile ? [{ dir: path20.dirname(explicitFile), file: path20.basename(explicitFile), explicit: true }] : [
5540
5770
  { dir: root, file: "genesis.config.json", explicit: false },
5541
5771
  { dir: root, file: "package.json", explicit: false }
5542
5772
  ];
@@ -5648,7 +5878,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
5648
5878
  const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
5649
5879
  let current = null;
5650
5880
  try {
5651
- current = lf(readFileSync(path19.join(ctx.root, out), "utf8"));
5881
+ current = lf(readFileSync(path20.join(ctx.root, out), "utf8"));
5652
5882
  } catch {
5653
5883
  current = null;
5654
5884
  }
@@ -5672,7 +5902,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
5672
5902
  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}` });
5673
5903
  return;
5674
5904
  }
5675
- const target = path19.relative(process.cwd(), path19.join(ctx.root, out)) || out;
5905
+ const target = path20.relative(process.cwd(), path20.join(ctx.root, out)) || out;
5676
5906
  const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
5677
5907
  if (current !== expected) {
5678
5908
  ctx.report({
@@ -5815,8 +6045,8 @@ function currentAgentsBlock(agents) {
5815
6045
  var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
5816
6046
  function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
5817
6047
  const rows = primitivesCatalog(packages);
5818
- const skill = read(path19.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
5819
- const block = currentAgentsBlock(read(path19.join(root, agentsFile)));
6048
+ const skill = read(path20.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
6049
+ const block = currentAgentsBlock(read(path20.join(root, agentsFile)));
5820
6050
  return {
5821
6051
  skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
5822
6052
  agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
@@ -5838,9 +6068,227 @@ function checkAgentGuide(ctx) {
5838
6068
  ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
5839
6069
  }
5840
6070
  }
6071
+ var LOCK_FILE = "genesis.lock.json";
6072
+ function emptyLock() {
6073
+ return { version: 1, blocks: {}, files: {} };
6074
+ }
6075
+ function readLock(root) {
6076
+ const file = path20.join(root, LOCK_FILE);
6077
+ if (!existsSync(file)) return emptyLock();
6078
+ const raw = JSON.parse(readFileSync(file, "utf8"));
6079
+ if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
6080
+ return {
6081
+ version: 1,
6082
+ ...raw.substitutions ? { substitutions: raw.substitutions } : {},
6083
+ blocks: raw.blocks ?? {},
6084
+ files: raw.files ?? {},
6085
+ ...raw.migrations ? { migrations: raw.migrations } : {}
6086
+ };
6087
+ }
6088
+ function parseSource(source) {
6089
+ const at = source.indexOf(":");
6090
+ if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
6091
+ return { package: source.slice(0, at), path: source.slice(at + 1) };
6092
+ }
6093
+ var CLI = "@marktiderman/genesis-cli";
6094
+ function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
6095
+ let parsed;
6096
+ try {
6097
+ parsed = parseSource(source);
6098
+ } catch (err) {
6099
+ return err instanceof Error ? err.message : String(err);
6100
+ }
6101
+ const { package: pkg, path: rel } = parsed;
6102
+ if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
6103
+ if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
6104
+ if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
6105
+ const base = rel.split("/").pop();
6106
+ if (pkg === CLI && rel.startsWith("templates/")) {
6107
+ return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
6108
+ }
6109
+ const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
6110
+ if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
6111
+ if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
6112
+ if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
6113
+ return `${key2} doesn't match its source ${source}`;
6114
+ }
6115
+
6116
+ // src/blocks/templates.ts
6117
+ function starterDir() {
6118
+ const workspace = workspacePackagesDir();
6119
+ const live = workspace && path20.join(workspace, "..", "apps", "genesis-rn-starter");
6120
+ if (live && existsSync(path20.join(live, "package.json"))) return live;
6121
+ const packaged = path20.join(cliPackageDir(), "dist", "starter");
6122
+ if (existsSync(path20.join(packaged, "package.json"))) return packaged;
6123
+ throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
6124
+ }
6125
+
6126
+ // src/blocks/starter-features.ts
6127
+ var STARTER_CONFIG = "starter.config.ts";
6128
+ var GENESIS_CONFIG = "genesis.config.json";
6129
+ var SWITCH = /^[a-zA-Z][a-zA-Z0-9]*$/;
6130
+ var BLOCK_ID2 = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
6131
+ function featuresBody(text) {
6132
+ const m = /\bfeatures:\s*\{/.exec(text);
6133
+ if (!m) return null;
6134
+ const start = m.index + m[0].length;
6135
+ const end = text.indexOf("}", start);
6136
+ return end < 0 ? null : { start, body: text.slice(start, end) };
6137
+ }
6138
+ function parseStarterFeatures(text) {
6139
+ const found = featuresBody(text);
6140
+ if (!found) return null;
6141
+ const out = {};
6142
+ for (const line of found.body.split("\n")) {
6143
+ const m = /^\s*([a-zA-Z][a-zA-Z0-9]*)\s*:\s*(true|false)\s*,?\s*(?:\/\/.*)?$/.exec(line);
6144
+ if (m) out[m[1]] = m[2] === "true";
6145
+ }
6146
+ return out;
6147
+ }
6148
+ function parseStarterBlocks(json, source = GENESIS_CONFIG) {
6149
+ let raw;
6150
+ try {
6151
+ raw = JSON.parse(json);
6152
+ } catch (err) {
6153
+ throw new Error(`${source} is not valid JSON: ${err.message}`);
6154
+ }
6155
+ const starter = raw?.starter;
6156
+ if (starter === void 0) return null;
6157
+ const blocks = starter?.blocks;
6158
+ if (typeof blocks !== "object" || blocks === null || Array.isArray(blocks)) throw new Error(`${source}: starter.blocks must map each feature switch to a list of block ids`);
6159
+ const out = {};
6160
+ for (const [name, ids] of Object.entries(blocks)) {
6161
+ if (name === "$comment") continue;
6162
+ if (!SWITCH.test(name) || !Array.isArray(ids) || !ids.every((id) => typeof id === "string" && BLOCK_ID2.test(id))) {
6163
+ throw new Error(`${source}: starter.blocks.${name} must be a list of block ids`);
6164
+ }
6165
+ out[name] = ids;
6166
+ }
6167
+ return out;
6168
+ }
6169
+ function readText(file) {
6170
+ try {
6171
+ return readFileSync(file, "utf8");
6172
+ } catch {
6173
+ return null;
6174
+ }
6175
+ }
6176
+ function starterBlockMap(root) {
6177
+ if (root) {
6178
+ const file = path20.join(root, GENESIS_CONFIG);
6179
+ const text2 = readText(file);
6180
+ const own = text2 === null ? null : parseStarterBlocks(text2, file);
6181
+ if (own) return own;
6182
+ }
6183
+ let dir;
6184
+ try {
6185
+ dir = starterDir();
6186
+ } catch {
6187
+ return {};
6188
+ }
6189
+ const text = readText(path20.join(dir, GENESIS_CONFIG));
6190
+ return (text === null ? null : parseStarterBlocks(text)) ?? {};
6191
+ }
6192
+ function blocksSwitchedOff(switches, map, manifests, present) {
6193
+ const ids = new Set(present);
6194
+ const off = /* @__PURE__ */ new Map();
6195
+ for (const [name, carried] of Object.entries(map)) if (switches[name] === false) {
6196
+ for (const id of carried) if (ids.has(id)) off.set(id, name);
6197
+ }
6198
+ const requires = new Map(manifests.map((m) => [m.id, m.requires]));
6199
+ const keep = [...ids].filter((id) => !off.has(id));
6200
+ for (let i = 0; i < keep.length; i++) {
6201
+ for (const r of requires.get(keep[i]) ?? []) {
6202
+ off.delete(r);
6203
+ if (!keep.includes(r)) keep.push(r);
6204
+ }
6205
+ }
6206
+ return off;
6207
+ }
6208
+ function appBlocksSwitchedOff(root, manifests, present) {
6209
+ const text = readText(path20.join(root, STARTER_CONFIG));
6210
+ const switches = text === null ? null : parseStarterFeatures(text);
6211
+ if (!switches) return /* @__PURE__ */ new Map();
6212
+ return blocksSwitchedOff(switches, starterBlockMap(existsSync(path20.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
6213
+ }
6214
+ function blockOfSource(source, manifests) {
6215
+ const at = source.indexOf(":");
6216
+ if (at < 1) return null;
6217
+ const pkg = source.slice(0, at);
6218
+ const rel = source.slice(at + 1);
6219
+ for (const m of manifests) {
6220
+ if (m.functions.some((fn) => fn.package === pkg && rel.startsWith(`${fn.dir}/`))) return m.id;
6221
+ if (m.migrations.some((mig) => mig.package === pkg && mig.test === rel)) return m.id;
6222
+ }
6223
+ return null;
6224
+ }
6225
+
6226
+ // src/doctor/lock-files.ts
6227
+ async function checkLockFiles(ctx) {
6228
+ if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
6229
+ let lock;
6230
+ try {
6231
+ lock = readLock(ctx.root);
6232
+ } catch (err) {
6233
+ ctx.report({ rule: "lock-files", level: "warn", file: LOCK_FILE, message: `can't be read (${err instanceof Error ? err.message : String(err)}); genesis upgrade and migrate can't either` });
6234
+ return;
6235
+ }
6236
+ const catalog = catalogBlocks();
6237
+ const off = appBlocksSwitchedOff(ctx.root, catalog, Object.keys(lock.blocks));
6238
+ const offManifests = [];
6239
+ for (const [id, entry] of Object.entries(lock.blocks)) {
6240
+ const feature = off.get(id);
6241
+ if (!feature) continue;
6242
+ try {
6243
+ offManifests.push((await findBlock(ctx.root, id, { package: entry.package })).manifest);
6244
+ } catch {
6245
+ offManifests.push(...catalog.filter((m) => m.id === id));
6246
+ }
6247
+ ctx.report({
6248
+ rule: "lock-files",
6249
+ level: "info",
6250
+ file: LOCK_FILE,
6251
+ subject: id,
6252
+ message: `lists the ${id} block, but features.${feature} is off in ${STARTER_CONFIG}: genesis upgrade and migrate leave it out (delete its entry if it's gone for good)`
6253
+ });
6254
+ }
6255
+ const local = localPackageNames(ctx.root);
6256
+ for (const [rel, entry] of Object.entries(lock.files)) {
6257
+ if (ownedKeyProblem(rel, entry.source, local)) continue;
6258
+ if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
6259
+ let text;
6260
+ try {
6261
+ text = readApp(ctx.root, rel);
6262
+ } catch {
6263
+ continue;
6264
+ }
6265
+ if (text === null) {
6266
+ if (entry.deleted) continue;
6267
+ ctx.report({
6268
+ rule: "lock-files",
6269
+ level: "warn",
6270
+ file: rel,
6271
+ subject: rel,
6272
+ message: `is in ${LOCK_FILE} (from ${entry.source}) but not on disk, and genesis upgrade won't bring it back. Deleted on purpose: add "deleted": true to its entry in ${LOCK_FILE}. Otherwise restore it (git checkout, or copy it from ${entry.source})`
6273
+ });
6274
+ continue;
6275
+ }
6276
+ if (entry.deleted) {
6277
+ ctx.report({ rule: "lock-files", level: "info", file: rel, subject: rel, message: `is marked "deleted": true in ${LOCK_FILE} but is on disk; remove the marker` });
6278
+ }
6279
+ if (sha256(text) === entry.sha256) continue;
6280
+ ctx.report({
6281
+ rule: "lock-files",
6282
+ level: "info",
6283
+ file: rel,
6284
+ subject: rel,
6285
+ message: entry.pending ? `differs from ${LOCK_FILE}: the last upgrade's version is waiting in ${rel}.genesis-next; resolve it into this file and delete it` : `differs from ${LOCK_FILE} (edited in the app); genesis upgrade three-way merges the next version into your edits`
6286
+ });
6287
+ }
6288
+ }
5841
6289
  var RATCHETED_BY_DEFAULT = ["deprecated-import"];
5842
6290
  async function runDoctor(options = {}) {
5843
- const root = path19.resolve(options.root ?? process.cwd());
6291
+ const root = path20.resolve(options.root ?? process.cwd());
5844
6292
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
5845
6293
  const config = loaded.config;
5846
6294
  const genesis = options.genesis ?? loadGenesis(root, config);
@@ -5894,7 +6342,7 @@ async function runDoctor(options = {}) {
5894
6342
  }
5895
6343
  let findings = applyConfig(raw, config, packageRuleIds(packages));
5896
6344
  if (options.base && changed) {
5897
- findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path19.join(root, f)) });
6345
+ findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path20.join(root, f)) });
5898
6346
  }
5899
6347
  const errors = findings.filter((f) => f.level === "error").length;
5900
6348
  const warnings = findings.filter((f) => f.level === "warn").length;
@@ -5939,6 +6387,7 @@ function builtinChecks(config, options = {}) {
5939
6387
  { name: "stability-imports", check: checkStabilityImports },
5940
6388
  { name: "agent-guide", check: checkAgentGuide },
5941
6389
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
6390
+ { name: "lock-files", check: checkLockFiles },
5942
6391
  ...(config.packs ?? []).map((p) => packs[p]),
5943
6392
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
5944
6393
  ];
@@ -6072,15 +6521,15 @@ ${formatProblems(result)}`);
6072
6521
  }
6073
6522
  }
6074
6523
  };
6075
- const explicit = /* @__PURE__ */ new Set([path19.join(root, "genesis.config.json"), ...options.configPath ? [path19.resolve(root, options.configPath)] : []]);
6524
+ const explicit = /* @__PURE__ */ new Set([path20.join(root, "genesis.config.json"), ...options.configPath ? [path20.resolve(root, options.configPath)] : []]);
6076
6525
  try {
6077
6526
  const { config } = loadConfig(root, options.configPath);
6078
- if (config.rulesDoc) explicit.add(path19.resolve(root, config.rulesDoc));
6527
+ if (config.rulesDoc) explicit.add(path20.resolve(root, config.rulesDoc));
6079
6528
  } catch {
6080
6529
  }
6081
6530
  const schedule = (file) => {
6082
- if (!explicit.has(path19.resolve(file))) {
6083
- const rel = path19.relative(root, file).split(path19.sep).join("/");
6531
+ if (!explicit.has(path20.resolve(file))) {
6532
+ const rel = path20.relative(root, file).split(path20.sep).join("/");
6084
6533
  if (rel.startsWith("..") || rel.includes("node_modules/")) return;
6085
6534
  }
6086
6535
  clearTimeout(timer);