@marktiderman/genesis-cli 1.17.2 → 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/doctor.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, readdirSync, statSync, realpathSync, mkdirSync, writeFileSync, 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 (path30) => res.some((re) => re.test(path30));
1128
+ return (path36) => res.some((re) => re.test(path36));
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));
@@ -2051,15 +2100,177 @@ async function loadPlugins(specs, configDir) {
2051
2100
  }
2052
2101
  function resolvePlugin(id, configDir) {
2053
2102
  try {
2054
- if (id.startsWith(".") || path19.isAbsolute(id)) return resolveFrom(path19.resolve(configDir, id), configDir);
2103
+ if (id.startsWith(".") || path20.isAbsolute(id)) return resolveFrom(path20.resolve(configDir, id), configDir);
2055
2104
  return resolveFrom(id, configDir);
2056
2105
  } catch {
2057
2106
  throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
2058
2107
  }
2059
2108
  }
2060
2109
  function resolveFrom(id, from) {
2061
- return createRequire(path19.join(from, "noop.js")).resolve(id);
2110
+ return createRequire(path20.join(from, "noop.js")).resolve(id);
2111
+ }
2112
+
2113
+ // src/doctor/semver.ts
2114
+ var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
2115
+ function parseVersion(v) {
2116
+ const m = VERSION.exec(v.trim());
2117
+ return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
2118
+ }
2119
+ function compareVersions(a, b) {
2120
+ for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
2121
+ if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
2122
+ for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
2123
+ const x = a.pre[i];
2124
+ const y = b.pre[i];
2125
+ if (x === void 0) return -1;
2126
+ if (y === void 0) return 1;
2127
+ if (x === y) continue;
2128
+ const nx = /^\d+$/.test(x);
2129
+ const ny = /^\d+$/.test(y);
2130
+ if (nx && ny) return +x < +y ? -1 : 1;
2131
+ if (nx !== ny) return nx ? -1 : 1;
2132
+ return x < y ? -1 : 1;
2133
+ }
2134
+ return 0;
2135
+ }
2136
+ function partial(s) {
2137
+ const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
2138
+ if (!m) return null;
2139
+ const nums = [];
2140
+ let wild = false;
2141
+ for (const part of [m[1], m[2], m[3]]) {
2142
+ if (wild || part === void 0 || /^[xX*]$/.test(part)) {
2143
+ wild = true;
2144
+ nums.push(null);
2145
+ } else nums.push(+part);
2146
+ }
2147
+ return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
2148
+ }
2149
+ var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
2150
+ function comparators(token) {
2151
+ const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
2152
+ if (!m) return null;
2153
+ const op = m[1] ?? "";
2154
+ const p = partial(m[2]);
2155
+ if (!p) return null;
2156
+ const [major, mi, pa] = p.nums;
2157
+ if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
2158
+ const M = major;
2159
+ const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
2160
+ 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"]);
2161
+ const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
2162
+ const out = switchOp();
2163
+ if (p.pre.length) {
2164
+ for (const c of out) if (c.v === lo) c.pre = true;
2165
+ }
2166
+ return out;
2167
+ function switchOp() {
2168
+ switch (op) {
2169
+ case "^": {
2170
+ const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
2171
+ return [
2172
+ { op: ">=", v: lo },
2173
+ { op: "<", v: bound }
2174
+ ];
2175
+ }
2176
+ case "~":
2177
+ case "~>":
2178
+ return [
2179
+ { op: ">=", v: lo },
2180
+ { op: "<", v: mi === null ? next("major") : next("minor") }
2181
+ ];
2182
+ case ">":
2183
+ return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
2184
+ case ">=":
2185
+ return [{ op: ">=", v: lo }];
2186
+ case "<":
2187
+ return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
2188
+ case "<=":
2189
+ return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
2190
+ default:
2191
+ return upper ? [
2192
+ { op: ">=", v: lo },
2193
+ { op: "<", v: upper }
2194
+ ] : [{ op: "=", v: lo }];
2195
+ }
2196
+ }
2197
+ }
2198
+ function test(c, v) {
2199
+ const d = compareVersions(v, c.v);
2200
+ return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
2201
+ }
2202
+ function parseRange(range) {
2203
+ const alts = [];
2204
+ for (const raw of range.trim().split("||")) {
2205
+ const alt = raw.trim();
2206
+ const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
2207
+ if (hyphen) {
2208
+ const from = comparators(`>=${hyphen[1]}`);
2209
+ const to = comparators(`<=${hyphen[2]}`);
2210
+ if (!from || !to) return null;
2211
+ alts.push([...from, ...to]);
2212
+ continue;
2213
+ }
2214
+ const set = [];
2215
+ for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
2216
+ const cs = comparators(token);
2217
+ if (!cs) return null;
2218
+ set.push(...cs);
2219
+ }
2220
+ alts.push(set);
2221
+ }
2222
+ return alts;
2223
+ }
2224
+ function satisfies(version, range) {
2225
+ const v = parseVersion(version);
2226
+ const alts = parseRange(range);
2227
+ if (!v || !alts) return null;
2228
+ return alts.some(
2229
+ (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))
2230
+ );
2231
+ }
2232
+ var UMBRELLA_PACKAGE = "@marktiderman/genesis";
2233
+ function readReleaseManifest(root) {
2234
+ const dir = findPackageDir(root, UMBRELLA_PACKAGE);
2235
+ const file = dir && path20.join(dir, "dist", "versions.json");
2236
+ if (!file || !existsSync(file)) return null;
2237
+ return JSON.parse(readFileSync(file, "utf8"));
2238
+ }
2239
+ function checkVersionSkew(ctx) {
2240
+ const manifest = readReleaseManifest(ctx.root);
2241
+ if (!manifest) return;
2242
+ const overlays = markedOverlays(ctx);
2243
+ for (const [name, want] of Object.entries(manifest.packages)) {
2244
+ const overlay = overlays.get(name);
2245
+ if (overlay) {
2246
+ const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
2247
+ const behind = parseVersion(from) && parseVersion(want) && compareVersions(parseVersion(from), parseVersion(want)) < 0;
2248
+ if (from !== want && !behind) {
2249
+ ctx.report({
2250
+ rule: "version-skew",
2251
+ level: "warn",
2252
+ file: "package.json",
2253
+ subject: name,
2254
+ 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).`
2255
+ });
2256
+ }
2257
+ continue;
2258
+ }
2259
+ const dir = findPackageDir(ctx.root, name);
2260
+ if (!dir) continue;
2261
+ const have = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8")).version;
2262
+ if (have === want) continue;
2263
+ ctx.report({
2264
+ rule: "version-skew",
2265
+ level: "warn",
2266
+ file: "package.json",
2267
+ subject: name,
2268
+ message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
2269
+ });
2270
+ }
2062
2271
  }
2272
+
2273
+ // src/doctor/overlays.ts
2063
2274
  var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
2064
2275
  var OVERLAY_NOTICE_DAYS = 14;
2065
2276
  var OVERLAY_WARN_DAYS = 30;
@@ -2073,7 +2284,7 @@ function overlayState(name, json) {
2073
2284
  function overlaySetupProblems(root, config, dir, name, json) {
2074
2285
  const problems = [];
2075
2286
  if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
2076
- const rel = path19.relative(path19.resolve(root), path19.resolve(dir)).split(path19.sep).join("/");
2287
+ const rel = path20.relative(path20.resolve(root), path20.resolve(dir)).split(path20.sep).join("/");
2077
2288
  const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
2078
2289
  const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
2079
2290
  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})`);
@@ -2098,6 +2309,31 @@ function overlayAgeDays(since, now = /* @__PURE__ */ new Date()) {
2098
2309
  return Math.floor((today - Date.UTC(y, m - 1, d)) / 864e5);
2099
2310
  }
2100
2311
  var LOCAL_VERSION = /^(\d+\.\d+\.\d+(?:-(?!local\.)[0-9A-Za-z.-]+?)?)(?:[+-]local\.(?:0|[1-9]\d*))?$/;
2312
+ function pinnedVersion(root, name, manifests = ["package.json"]) {
2313
+ let manifest = null;
2314
+ try {
2315
+ manifest = readReleaseManifest(root);
2316
+ } catch {
2317
+ }
2318
+ const released = manifest?.packages[name];
2319
+ if (released && parseVersion(released)) return released;
2320
+ let best = null;
2321
+ for (const file of manifests) {
2322
+ let json;
2323
+ try {
2324
+ json = JSON.parse(readFileSync(path20.join(root, file), "utf8"));
2325
+ } catch {
2326
+ continue;
2327
+ }
2328
+ for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
2329
+ const spec = json[section]?.[name];
2330
+ const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
2331
+ const parsed = v && parseVersion(v);
2332
+ if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
2333
+ }
2334
+ }
2335
+ return best;
2336
+ }
2101
2337
  function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
2102
2338
  let packages;
2103
2339
  try {
@@ -2110,7 +2346,7 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
2110
2346
  const file = `${pkg.rel}/package.json`;
2111
2347
  let json;
2112
2348
  try {
2113
- json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
2349
+ json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
2114
2350
  } catch {
2115
2351
  continue;
2116
2352
  }
@@ -2153,6 +2389,18 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
2153
2389
  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`
2154
2390
  });
2155
2391
  }
2392
+ const pinned = pinnedVersion(ctx.root, pkg.name);
2393
+ const from = parseVersion(upstream);
2394
+ const to = pinned ? parseVersion(pinned) : null;
2395
+ if (from && to && compareVersions(from, to) < 0) {
2396
+ ctx.report({
2397
+ rule: "overlay-behind",
2398
+ level: "warn",
2399
+ file,
2400
+ subject: pkg.name,
2401
+ 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`
2402
+ });
2403
+ }
2156
2404
  }
2157
2405
  }
2158
2406
 
@@ -2216,6 +2464,7 @@ var BUILTIN_RULES = [
2216
2464
  "overlay-invalid",
2217
2465
  "overlay-age",
2218
2466
  "overlay-version",
2467
+ "overlay-behind",
2219
2468
  // package rules (package-rules.ts): the rules themselves are namespaced, e.g. ui/lists-use-resource-view
2220
2469
  "package-rules-invalid",
2221
2470
  "package-rule-override",
@@ -2226,7 +2475,9 @@ var BUILTIN_RULES = [
2226
2475
  // agent guide (primitives.ts)
2227
2476
  "agent-guide-stale",
2228
2477
  // supabase pack: contracts (contracts.ts)
2229
- "contracts-stale"
2478
+ "contracts-stale",
2479
+ // genesis.lock.json against the files (lock-files.ts)
2480
+ "lock-files"
2230
2481
  ];
2231
2482
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2232
2483
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -2244,7 +2495,7 @@ function importSpecifiers(file) {
2244
2495
  }
2245
2496
  function checkProjectLayout(ctx) {
2246
2497
  for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
2247
- if (existsSync(path19.join(ctx.root, dir))) {
2498
+ if (existsSync(path20.join(ctx.root, dir))) {
2248
2499
  ctx.report({
2249
2500
  rule: "local-primitives",
2250
2501
  file: dir,
@@ -2254,7 +2505,7 @@ function checkProjectLayout(ctx) {
2254
2505
  }
2255
2506
  }
2256
2507
  for (const file of STARTER_LEFTOVERS) {
2257
- if (existsSync(path19.join(ctx.root, file))) {
2508
+ if (existsSync(path20.join(ctx.root, file))) {
2258
2509
  ctx.report({
2259
2510
  rule: "starter-leftover",
2260
2511
  level: "warn",
@@ -2344,7 +2595,7 @@ function checkTokens(ctx) {
2344
2595
  }
2345
2596
  for (const pattern of ctx.config.tokenFiles ?? []) {
2346
2597
  if (/[*?]/.test(pattern)) continue;
2347
- const abs = path19.join(ctx.root, pattern);
2598
+ const abs = path20.join(ctx.root, pattern);
2348
2599
  if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
2349
2600
  for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
2350
2601
  }
@@ -2444,14 +2695,33 @@ var appFunctionality = (type, ...more) => ({
2444
2695
  function privacyApisFor(dependencies2) {
2445
2696
  return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
2446
2697
  }
2698
+
2699
+ // src/eas-placeholders.ts
2700
+ var EAS_PLACEHOLDERS = {
2701
+ 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)",
2702
+ REPLACE_WITH_APPLE_TEAM_ID: "your Apple Developer Team ID (developer.apple.com \u2192 Account \u2192 Membership details, 10 characters)",
2703
+ 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",
2704
+ REPLACE_WITH_APP_FOLDER: "the app's code folder (src, or apps/<name> in a monorepo)"
2705
+ };
2706
+ function placeholderKey(line, placeholder) {
2707
+ return new RegExp(`"([A-Za-z0-9_]+)"\\s*:\\s*"${placeholder}"`).exec(line)?.[1] ?? null;
2708
+ }
2709
+ function findPlaceholders(file, text) {
2710
+ const out = [];
2711
+ text.split("\n").forEach((line, i) => {
2712
+ if (!file.endsWith(".json") && /^\s*#/.test(line)) return;
2713
+ for (const m of line.matchAll(/\bREPLACE_WITH_[A-Z0-9_]+/g)) out.push({ line: i + 1, text: line, placeholder: m[0] });
2714
+ });
2715
+ return out;
2716
+ }
2447
2717
  var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
2448
2718
  var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
2449
2719
  var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
2450
2720
  function resolveLocal(root, fromFile, spec) {
2451
- const bases = spec.startsWith(".") ? [path19.resolve(path19.dirname(fromFile), spec)] : [path19.join(root, spec.slice(2)), path19.join(root, "src", spec.slice(2))];
2721
+ const bases = spec.startsWith(".") ? [path20.resolve(path20.dirname(fromFile), spec)] : [path20.join(root, spec.slice(2)), path20.join(root, "src", spec.slice(2))];
2452
2722
  for (const base of bases) {
2453
- const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path19.join(base, `index${e}`))].find(
2454
- (p) => SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p)
2723
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path20.join(base, `index${e}`))].find(
2724
+ (p) => SCRIPT_EXTS2.has(path20.extname(p)) && existsSync(p)
2455
2725
  );
2456
2726
  if (hit) return hit;
2457
2727
  }
@@ -2570,29 +2840,26 @@ function checkNativePack(ctx) {
2570
2840
  checkStoreReadiness(ctx);
2571
2841
  checkEasPlaceholders(ctx);
2572
2842
  }
2573
- var EAS_PLACEHOLDER = /\bREPLACE_WITH_[A-Z0-9_]+/g;
2574
2843
  function checkEasPlaceholders(ctx) {
2575
2844
  const files = [];
2576
- if (existsSync(path19.join(ctx.root, "eas.json"))) files.push("eas.json");
2577
- const workflows = path19.join(ctx.root, ".eas", "workflows");
2845
+ if (existsSync(path20.join(ctx.root, "eas.json"))) files.push("eas.json");
2846
+ const workflows = path20.join(ctx.root, ".eas", "workflows");
2578
2847
  if (existsSync(workflows)) {
2579
2848
  for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
2580
2849
  }
2581
2850
  for (const file of files) {
2582
- const lines = readFileSync(path19.join(ctx.root, file), "utf8").split("\n");
2583
- lines.forEach((text, i) => {
2584
- if (!file.endsWith(".json") && /^\s*#/.test(text)) return;
2585
- for (const m of text.matchAll(EAS_PLACEHOLDER)) {
2586
- ctx.report({
2587
- rule: "eas-placeholder",
2588
- level: "warn",
2589
- file,
2590
- line: i + 1,
2591
- subject: m[0],
2592
- 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)`
2593
- });
2594
- }
2595
- });
2851
+ for (const hit of findPlaceholders(file, readFileSync(path20.join(ctx.root, file), "utf8"))) {
2852
+ const key2 = placeholderKey(hit.text, hit.placeholder);
2853
+ const what = EAS_PLACEHOLDERS[hit.placeholder];
2854
+ ctx.report({
2855
+ rule: "eas-placeholder",
2856
+ level: "warn",
2857
+ file,
2858
+ line: hit.line,
2859
+ subject: hit.placeholder,
2860
+ 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`
2861
+ });
2862
+ }
2596
2863
  }
2597
2864
  }
2598
2865
  var RN = String.raw`["']react-native["']`;
@@ -2660,7 +2927,7 @@ function checkCustomHeaders(ctx, pkg) {
2660
2927
  if (!JSX_EXTS3.has(file.ext)) continue;
2661
2928
  const code = file.code;
2662
2929
  const hidden = HIDES_HEADER.exec(code);
2663
- if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path19.posix.dirname(file.path), file.path);
2930
+ if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path20.posix.dirname(file.path), file.path);
2664
2931
  const own = hidden ? ownHeader(code, pkg) : null;
2665
2932
  if (hidden && own) {
2666
2933
  reported.add(file.path);
@@ -2688,7 +2955,7 @@ function checkCustomHeaders(ctx, pkg) {
2688
2955
  }
2689
2956
  for (const file of ctx.files) {
2690
2957
  if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
2691
- const layout = hidingLayouts.get(path19.posix.dirname(file.path));
2958
+ const layout = hidingLayouts.get(path20.posix.dirname(file.path));
2692
2959
  const own = layout ? ownHeader(file.code, pkg) : null;
2693
2960
  if (!layout || !own) continue;
2694
2961
  ctx.report({
@@ -2710,13 +2977,13 @@ function isLoadingOnlyRoute(code) {
2710
2977
  }
2711
2978
  function routerRoot(ctx) {
2712
2979
  if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
2713
- return existsSync(path19.join(ctx.root, "src", "app")) ? "src/app" : "app";
2980
+ return existsSync(path20.join(ctx.root, "src", "app")) ? "src/app" : "app";
2714
2981
  }
2715
2982
  function checkScreenLayouts(ctx, pkg) {
2716
2983
  const layouts = nativeLayouts(pkg);
2717
2984
  if (layouts.length === 0) return;
2718
2985
  const rootDir = routerRoot(ctx);
2719
- if (!existsSync(path19.join(ctx.root, rootDir))) {
2986
+ if (!existsSync(path20.join(ctx.root, rootDir))) {
2720
2987
  ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
2721
2988
  return;
2722
2989
  }
@@ -2772,7 +3039,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
2772
3039
  function readExpoConfigs(root) {
2773
3040
  const out = [];
2774
3041
  for (const name of EXPO_CONFIGS) {
2775
- const abs = path19.join(root, name);
3042
+ const abs = path20.join(root, name);
2776
3043
  if (!existsSync(abs)) continue;
2777
3044
  const text = readFileSync(abs, "utf8");
2778
3045
  let json = null;
@@ -2806,13 +3073,13 @@ function pluginOptions(json, module) {
2806
3073
  return null;
2807
3074
  }
2808
3075
  function dependencies(root) {
2809
- const file = path19.join(root, "package.json");
3076
+ const file = path20.join(root, "package.json");
2810
3077
  if (!existsSync(file)) return /* @__PURE__ */ new Set();
2811
3078
  const pkg = JSON.parse(readFileSync(file, "utf8"));
2812
3079
  return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
2813
3080
  }
2814
3081
  function runtimeDependencies(root) {
2815
- const file = path19.join(root, "package.json");
3082
+ const file = path20.join(root, "package.json");
2816
3083
  if (!existsSync(file)) return {};
2817
3084
  return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
2818
3085
  }
@@ -2893,126 +3160,6 @@ function checkStoreReadiness(ctx) {
2893
3160
  });
2894
3161
  }
2895
3162
  }
2896
-
2897
- // src/doctor/semver.ts
2898
- var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
2899
- function parseVersion(v) {
2900
- const m = VERSION.exec(v.trim());
2901
- return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
2902
- }
2903
- function compareVersions(a, b) {
2904
- for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
2905
- if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
2906
- for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
2907
- const x = a.pre[i];
2908
- const y = b.pre[i];
2909
- if (x === void 0) return -1;
2910
- if (y === void 0) return 1;
2911
- if (x === y) continue;
2912
- const nx = /^\d+$/.test(x);
2913
- const ny = /^\d+$/.test(y);
2914
- if (nx && ny) return +x < +y ? -1 : 1;
2915
- if (nx !== ny) return nx ? -1 : 1;
2916
- return x < y ? -1 : 1;
2917
- }
2918
- return 0;
2919
- }
2920
- function partial(s) {
2921
- const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
2922
- if (!m) return null;
2923
- const nums = [];
2924
- let wild = false;
2925
- for (const part of [m[1], m[2], m[3]]) {
2926
- if (wild || part === void 0 || /^[xX*]$/.test(part)) {
2927
- wild = true;
2928
- nums.push(null);
2929
- } else nums.push(+part);
2930
- }
2931
- return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
2932
- }
2933
- var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
2934
- function comparators(token) {
2935
- const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
2936
- if (!m) return null;
2937
- const op = m[1] ?? "";
2938
- const p = partial(m[2]);
2939
- if (!p) return null;
2940
- const [major, mi, pa] = p.nums;
2941
- if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
2942
- const M = major;
2943
- const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
2944
- 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"]);
2945
- const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
2946
- const out = switchOp();
2947
- if (p.pre.length) {
2948
- for (const c of out) if (c.v === lo) c.pre = true;
2949
- }
2950
- return out;
2951
- function switchOp() {
2952
- switch (op) {
2953
- case "^": {
2954
- const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
2955
- return [
2956
- { op: ">=", v: lo },
2957
- { op: "<", v: bound }
2958
- ];
2959
- }
2960
- case "~":
2961
- case "~>":
2962
- return [
2963
- { op: ">=", v: lo },
2964
- { op: "<", v: mi === null ? next("major") : next("minor") }
2965
- ];
2966
- case ">":
2967
- return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
2968
- case ">=":
2969
- return [{ op: ">=", v: lo }];
2970
- case "<":
2971
- return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
2972
- case "<=":
2973
- return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
2974
- default:
2975
- return upper ? [
2976
- { op: ">=", v: lo },
2977
- { op: "<", v: upper }
2978
- ] : [{ op: "=", v: lo }];
2979
- }
2980
- }
2981
- }
2982
- function test(c, v) {
2983
- const d = compareVersions(v, c.v);
2984
- return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
2985
- }
2986
- function parseRange(range) {
2987
- const alts = [];
2988
- for (const raw of range.trim().split("||")) {
2989
- const alt = raw.trim();
2990
- const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
2991
- if (hyphen) {
2992
- const from = comparators(`>=${hyphen[1]}`);
2993
- const to = comparators(`<=${hyphen[2]}`);
2994
- if (!from || !to) return null;
2995
- alts.push([...from, ...to]);
2996
- continue;
2997
- }
2998
- const set = [];
2999
- for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
3000
- const cs = comparators(token);
3001
- if (!cs) return null;
3002
- set.push(...cs);
3003
- }
3004
- alts.push(set);
3005
- }
3006
- return alts;
3007
- }
3008
- function satisfies(version, range) {
3009
- const v = parseVersion(version);
3010
- const alts = parseRange(range);
3011
- if (!v || !alts) return null;
3012
- return alts.some(
3013
- (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))
3014
- );
3015
- }
3016
3163
  var TRAIL_DEPTH = 6;
3017
3164
  var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
3018
3165
  var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
@@ -3186,14 +3333,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3186
3333
  seen.add(file);
3187
3334
  const json = readJsonc(file);
3188
3335
  if (!json) return {};
3189
- const dir = path19.dirname(file);
3336
+ const dir = path20.dirname(file);
3190
3337
  let merged = {};
3191
3338
  const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
3192
3339
  for (const ext of parents) {
3193
3340
  if (typeof ext !== "string") continue;
3194
3341
  let target = null;
3195
- if (ext.startsWith(".") || path19.isAbsolute(ext)) {
3196
- const abs = path19.resolve(dir, ext);
3342
+ if (ext.startsWith(".") || path20.isAbsolute(ext)) {
3343
+ const abs = path20.resolve(dir, ext);
3197
3344
  target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3198
3345
  } else {
3199
3346
  const parts = ext.split("/");
@@ -3201,14 +3348,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3201
3348
  const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
3202
3349
  if (pkgDir) {
3203
3350
  const sub = parts.slice(nameLength).join("/");
3204
- const abs = path19.join(pkgDir, sub || "tsconfig.json");
3351
+ const abs = path20.join(pkgDir, sub || "tsconfig.json");
3205
3352
  target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3206
3353
  }
3207
3354
  }
3208
3355
  if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
3209
3356
  }
3210
3357
  const opts = json.compilerOptions ?? {};
3211
- if (typeof opts.baseUrl === "string") merged.baseUrl = path19.resolve(dir, opts.baseUrl);
3358
+ if (typeof opts.baseUrl === "string") merged.baseUrl = path20.resolve(dir, opts.baseUrl);
3212
3359
  if (opts.paths && typeof opts.paths === "object") {
3213
3360
  merged.paths = opts.paths;
3214
3361
  merged.pathsDir = dir;
@@ -3219,7 +3366,7 @@ function aliases(root) {
3219
3366
  const table = [];
3220
3367
  let baseUrl = null;
3221
3368
  for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
3222
- const file = path19.join(root, name);
3369
+ const file = path20.join(root, name);
3223
3370
  if (!existsSync(file)) continue;
3224
3371
  const config = readTsconfig(root, file);
3225
3372
  baseUrl ??= config.baseUrl ?? null;
@@ -3227,22 +3374,22 @@ function aliases(root) {
3227
3374
  for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
3228
3375
  if (!Array.isArray(targets)) continue;
3229
3376
  const exact = !pattern.endsWith("*");
3230
- table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path19.join(base, String(t).replace(/\*$/, ""))) });
3377
+ table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path20.join(base, String(t).replace(/\*$/, ""))) });
3231
3378
  }
3232
3379
  }
3233
- const pkg = readJsonc(path19.join(root, "package.json"));
3380
+ const pkg = readJsonc(path20.join(root, "package.json"));
3234
3381
  for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
3235
3382
  if (typeof target !== "string") continue;
3236
- table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path19.join(root, target.replace(/\*.*$/, ""))] });
3383
+ table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path20.join(root, target.replace(/\*.*$/, ""))] });
3237
3384
  }
3238
- for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path19.join(root, "src") + path19.sep, root + path19.sep] });
3385
+ for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path20.join(root, "src") + path20.sep, root + path20.sep] });
3239
3386
  return { table, baseUrl };
3240
3387
  }
3241
3388
  function resolveFile(base) {
3242
- const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path19.join(base, `index${e}`))];
3389
+ const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path20.join(base, `index${e}`))];
3243
3390
  if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
3244
3391
  for (const p of tries) {
3245
- if (SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
3392
+ if (SCRIPT_EXTS2.has(path20.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
3246
3393
  }
3247
3394
  return null;
3248
3395
  }
@@ -3256,7 +3403,7 @@ function createTrail(ctx) {
3256
3403
  const { table, baseUrl } = aliases(ctx.root);
3257
3404
  let declared = null;
3258
3405
  try {
3259
- const pkg = JSON.parse(readFileSync(path19.join(ctx.root, "package.json"), "utf8"));
3406
+ const pkg = JSON.parse(readFileSync(path20.join(ctx.root, "package.json"), "utf8"));
3260
3407
  declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
3261
3408
  } catch {
3262
3409
  declared = null;
@@ -3287,17 +3434,17 @@ function createTrail(ctx) {
3287
3434
  if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
3288
3435
  let resolved = null;
3289
3436
  if (spec.startsWith(".")) {
3290
- resolved = resolveFile(path19.resolve(path19.dirname(file.absolutePath), spec));
3437
+ resolved = resolveFile(path20.resolve(path20.dirname(file.absolutePath), spec));
3291
3438
  if (!resolved) lost = true;
3292
3439
  } else {
3293
3440
  const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
3294
3441
  if (alias) {
3295
3442
  for (const t of alias.targets) {
3296
- resolved = resolveFile(alias.exact ? t : path19.join(t, spec.slice(alias.prefix.length)));
3443
+ resolved = resolveFile(alias.exact ? t : path20.join(t, spec.slice(alias.prefix.length)));
3297
3444
  if (resolved) break;
3298
3445
  }
3299
3446
  }
3300
- if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path19.join(baseUrl, spec));
3447
+ if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path20.join(baseUrl, spec));
3301
3448
  if (!resolved) {
3302
3449
  const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
3303
3450
  if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
@@ -3368,27 +3515,149 @@ function createTrail(ctx) {
3368
3515
  };
3369
3516
  return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
3370
3517
  }
3518
+ function buildCatalog(packagesDir) {
3519
+ const packages = {};
3520
+ for (const dir of readdirSync(packagesDir).sort()) {
3521
+ const file = path20.join(packagesDir, dir, "package.json");
3522
+ if (!existsSync(file)) continue;
3523
+ const pkg = JSON.parse(readFileSync(file, "utf8"));
3524
+ if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
3525
+ packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
3526
+ }
3527
+ return { packages };
3528
+ }
3371
3529
 
3372
3530
  // src/blocks/discover.ts
3531
+ var CLI_PACKAGE = "@marktiderman/genesis-cli";
3532
+ function cliPackageDir() {
3533
+ let dir = path20.dirname(fileURLToPath(import.meta.url));
3534
+ for (; ; ) {
3535
+ const file = path20.join(dir, "package.json");
3536
+ if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
3537
+ const parent = path20.dirname(dir);
3538
+ if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
3539
+ dir = parent;
3540
+ }
3541
+ }
3542
+ function workspacePackagesDir() {
3543
+ const dir = path20.resolve(cliPackageDir(), "..");
3544
+ return existsSync(path20.join(dir, "features", "package.json")) && existsSync(path20.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
3545
+ }
3546
+ var catalogCache;
3547
+ function readCatalog() {
3548
+ if (catalogCache) return catalogCache;
3549
+ const workspace = workspacePackagesDir();
3550
+ if (workspace) return catalogCache = buildCatalog(workspace);
3551
+ const file = path20.join(cliPackageDir(), "dist", "genesis-catalog.json");
3552
+ catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
3553
+ return catalogCache;
3554
+ }
3373
3555
  var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
3374
3556
  function installedGenesis(root) {
3375
3557
  const found = /* @__PURE__ */ new Map();
3376
- let dir = path19.resolve(root);
3558
+ let dir = path20.resolve(root);
3377
3559
  for (; ; ) {
3378
- const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path19.join(dir, m)));
3379
- const scope = path19.join(dir, "node_modules", "@marktiderman");
3560
+ const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path20.join(dir, m)));
3561
+ const scope = path20.join(dir, "node_modules", "@marktiderman");
3380
3562
  if (existsSync(scope)) {
3381
3563
  for (const entry of readdirSync(scope)) {
3382
3564
  const name = `@marktiderman/${entry}`;
3383
3565
  if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
3384
- if (existsSync(path19.join(scope, entry, "package.json"))) found.set(name, path19.join(scope, entry));
3566
+ if (existsSync(path20.join(scope, entry, "package.json"))) found.set(name, path20.join(scope, entry));
3385
3567
  }
3386
3568
  }
3387
- const parent = path19.dirname(dir);
3569
+ const parent = path20.dirname(dir);
3388
3570
  if (atInstallRoot || parent === dir) return found;
3389
3571
  dir = parent;
3390
3572
  }
3391
3573
  }
3574
+ var declarationCache = /* @__PURE__ */ new Map();
3575
+ function declarationsOf(dir, warnings) {
3576
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
3577
+ const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
3578
+ let cached = declarationCache.get(key2);
3579
+ if (!cached) {
3580
+ cached = loadDeclarations(dir, warnings);
3581
+ declarationCache.set(key2, cached);
3582
+ }
3583
+ return cached;
3584
+ }
3585
+ async function loadDeclarations(dir, warnings) {
3586
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
3587
+ const entry = pkg.exports?.["./blocks"];
3588
+ const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
3589
+ if (typeof target !== "string") return {};
3590
+ const rel = safeRelative(target.replace(/^\.\//, ""));
3591
+ const file = rel && path20.join(dir, ...rel.split("/"));
3592
+ if (!file || !inside(dir, file) || !existsSync(file)) return {};
3593
+ try {
3594
+ const jiti = createJiti(path20.join(dir, "package.json"), { moduleCache: false });
3595
+ const mod = await jiti.import(file);
3596
+ const out = {};
3597
+ for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
3598
+ return out;
3599
+ } catch (err) {
3600
+ 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.`);
3601
+ return {};
3602
+ }
3603
+ }
3604
+ async function blocksOfInstalled(dir, warnings = [], options = {}) {
3605
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
3606
+ const raw = rawBlocksOf(pkg);
3607
+ const declared = await declarationsOf(dir, warnings);
3608
+ const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
3609
+ const out = [];
3610
+ for (const id of [...ids].sort()) {
3611
+ const fromJson = raw[id] ?? {};
3612
+ const manifest = tryParse(() => parseManifest(pkg.name, id, { ...fromJson, ...declared[id] }, pkg.version, options), warnings);
3613
+ if (manifest) out.push(manifest);
3614
+ }
3615
+ return out;
3616
+ }
3617
+ async function allBlocks(root, warnings = []) {
3618
+ const out = [];
3619
+ for (const local of localPackages(root)) {
3620
+ for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
3621
+ }
3622
+ const installed = installedGenesis(root);
3623
+ for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
3624
+ for (const [name, entry] of Object.entries(readCatalog().packages)) {
3625
+ if (installed.has(name)) continue;
3626
+ for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
3627
+ const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
3628
+ if (manifest) out.push({ manifest, from: "catalog" });
3629
+ }
3630
+ }
3631
+ return out;
3632
+ }
3633
+ function tryParse(parse2, warnings) {
3634
+ try {
3635
+ return parse2();
3636
+ } catch (err) {
3637
+ if (!(err instanceof ManifestError)) throw err;
3638
+ warnings.push(err.message);
3639
+ return null;
3640
+ }
3641
+ }
3642
+ function catalogBlocks(warnings = []) {
3643
+ const out = [];
3644
+ for (const [name, entry] of Object.entries(readCatalog().packages)) {
3645
+ for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
3646
+ const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
3647
+ if (manifest) out.push(manifest);
3648
+ }
3649
+ }
3650
+ return out;
3651
+ }
3652
+ async function findBlock(root, id, options = {}) {
3653
+ const all = (await allBlocks(root, options.warnings)).filter((b) => b.manifest.id === id && (!options.package || b.manifest.package === options.package));
3654
+ if (all.length === 0) {
3655
+ const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
3656
+ throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
3657
+ }
3658
+ if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
3659
+ return all[0];
3660
+ }
3392
3661
  var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
3393
3662
  var STEMS = {
3394
3663
  tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
@@ -3406,7 +3675,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
3406
3675
  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;
3407
3676
  function routesDir(ctx) {
3408
3677
  if (ctx.config.routesDir) return ctx.config.routesDir;
3409
- return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path19.join(ctx.root, d))) ?? null;
3678
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path20.join(ctx.root, d))) ?? null;
3410
3679
  }
3411
3680
  var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
3412
3681
  function flavorOf(dir, rels) {
@@ -3541,7 +3810,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
3541
3810
  });
3542
3811
  if (typeof raw === "string") {
3543
3812
  if (!packageDir) fail(`points at ${raw}, but the package folder is unknown`);
3544
- const file = path19.resolve(packageDir, raw);
3813
+ const file = path20.resolve(packageDir, raw);
3545
3814
  if (!inside(packageDir, file)) fail(`points outside the package (${raw})`);
3546
3815
  if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
3547
3816
  let parsed;
@@ -3590,7 +3859,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
3590
3859
  if (typeof c.plugin === "string") {
3591
3860
  if (!packageDir) plugin = c.plugin;
3592
3861
  else {
3593
- plugin = path19.resolve(packageDir, c.plugin);
3862
+ plugin = path20.resolve(packageDir, c.plugin);
3594
3863
  if (!inside(packageDir, plugin)) fail(`plugin points outside the package (${c.plugin})`);
3595
3864
  }
3596
3865
  }
@@ -3640,7 +3909,7 @@ function checkPattern(v, where2, fail) {
3640
3909
  }
3641
3910
  var discoveryCache = /* @__PURE__ */ new Map();
3642
3911
  function readDeclaringPackage(dir, local) {
3643
- const file = path19.join(dir, "package.json");
3912
+ const file = path20.join(dir, "package.json");
3644
3913
  let stamp;
3645
3914
  let real2;
3646
3915
  try {
@@ -3663,7 +3932,7 @@ ${local}`;
3663
3932
  const pkg = {
3664
3933
  name: json.name,
3665
3934
  version: typeof json.version === "string" ? json.version : "0.0.0",
3666
- dir: path19.resolve(dir),
3935
+ dir: path20.resolve(dir),
3667
3936
  namespace: ruleNamespace(json.name),
3668
3937
  local,
3669
3938
  private: json.private === true,
@@ -3677,7 +3946,7 @@ ${local}`;
3677
3946
  if (raw !== void 0) {
3678
3947
  const ignored = [];
3679
3948
  try {
3680
- pkg.declaration = validateDeclaration(raw, json.name, path19.resolve(dir), ignored);
3949
+ pkg.declaration = validateDeclaration(raw, json.name, path20.resolve(dir), ignored);
3681
3950
  if (ignored.length) pkg.ignored = ignored;
3682
3951
  } catch (err) {
3683
3952
  pkg.error = err.message;
@@ -3696,14 +3965,14 @@ function discoverPackages(root) {
3696
3965
  for (const dir of installed) {
3697
3966
  let scope;
3698
3967
  try {
3699
- scope = path19.dirname(realpathSync(dir));
3968
+ scope = path20.dirname(realpathSync(dir));
3700
3969
  } catch {
3701
3970
  continue;
3702
3971
  }
3703
- if (path19.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
3972
+ if (path20.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
3704
3973
  for (const entry of readdirSync(scope)) {
3705
3974
  if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
3706
- const pkg = readDeclaringPackage(path19.join(scope, entry), false);
3975
+ const pkg = readDeclaringPackage(path20.join(scope, entry), false);
3707
3976
  if (pkg) byName.set(pkg.name, pkg);
3708
3977
  }
3709
3978
  }
@@ -3890,10 +4159,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
3890
4159
  var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
3891
4160
  function sourceFiles(dir, rel = "") {
3892
4161
  const out = [];
3893
- for (const entry of readdirSync(path19.join(dir, rel)).sort()) {
4162
+ for (const entry of readdirSync(path20.join(dir, rel)).sort()) {
3894
4163
  if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
3895
4164
  const child = rel ? `${rel}/${entry}` : entry;
3896
- const stat = lstatSync(path19.join(dir, child));
4165
+ const stat = lstatSync(path20.join(dir, child));
3897
4166
  if (stat.isSymbolicLink()) continue;
3898
4167
  if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
3899
4168
  else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
@@ -3916,13 +4185,13 @@ function matchPattern(pattern, spec) {
3916
4185
  return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
3917
4186
  }
3918
4187
  function tsconfigPaths(dir) {
3919
- const file = path19.join(dir, "tsconfig.json");
4188
+ const file = path20.join(dir, "tsconfig.json");
3920
4189
  if (!existsSync(file)) return [];
3921
4190
  try {
3922
4191
  const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
3923
4192
  const options = JSON.parse(text).compilerOptions ?? {};
3924
- const base = path19.resolve(dir, options.baseUrl ?? ".");
3925
- return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path19.resolve(base, t)) }));
4193
+ const base = path20.resolve(dir, options.baseUrl ?? ".");
4194
+ return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path20.resolve(base, t)) }));
3926
4195
  } catch {
3927
4196
  return [];
3928
4197
  }
@@ -3936,8 +4205,8 @@ function checkImports2(ctx, pkg, json) {
3936
4205
  const hit = matchPattern(pattern, spec);
3937
4206
  if (hit === null) continue;
3938
4207
  return targets.some((t) => {
3939
- const rel = path19.relative(pkg.dir, t.replace("*", hit));
3940
- return !rel.startsWith("..") && !path19.isAbsolute(rel);
4208
+ const rel = path20.relative(pkg.dir, t.replace("*", hit));
4209
+ return !rel.startsWith("..") && !path20.isAbsolute(rel);
3941
4210
  });
3942
4211
  }
3943
4212
  return null;
@@ -3950,7 +4219,7 @@ function checkImports2(ctx, pkg, json) {
3950
4219
  ...Object.keys(json.optionalDependencies ?? {})
3951
4220
  ]);
3952
4221
  for (const file of sourceFiles(pkg.dir)) {
3953
- const code = stripForImports(readFileSync(path19.join(pkg.dir, file), "utf8"));
4222
+ const code = stripForImports(readFileSync(path20.join(pkg.dir, file), "utf8"));
3954
4223
  if (code === null) continue;
3955
4224
  const at = `${pkg.rel}/${file}`;
3956
4225
  const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
@@ -3975,9 +4244,9 @@ function checkImports2(ctx, pkg, json) {
3975
4244
  continue;
3976
4245
  }
3977
4246
  if (spec.startsWith(".")) {
3978
- const target = path19.resolve(pkg.dir, path19.dirname(file), spec);
3979
- const rel = path19.relative(pkg.dir, target);
3980
- if (rel.startsWith("..") || path19.isAbsolute(rel)) {
4247
+ const target = path20.resolve(pkg.dir, path20.dirname(file), spec);
4248
+ const rel = path20.relative(pkg.dir, target);
4249
+ if (rel.startsWith("..") || path20.isAbsolute(rel)) {
3981
4250
  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` });
3982
4251
  }
3983
4252
  continue;
@@ -4014,12 +4283,12 @@ function checkMigrations(ctx, pkg, json, locals) {
4014
4283
  const from = own ? "" : ` (in ${m.package})`;
4015
4284
  if (typeof m.file === "string" && typeof m.test !== "string") {
4016
4285
  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` });
4017
- } else if (typeof m.test === "string" && !existsSync(path19.join(home, m.test))) {
4286
+ } else if (typeof m.test === "string" && !existsSync(path20.join(home, m.test))) {
4018
4287
  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` });
4019
4288
  }
4020
4289
  }
4021
4290
  }
4022
- const dir = path19.join(pkg.dir, "migrations");
4291
+ const dir = path20.join(pkg.dir, "migrations");
4023
4292
  if (!existsSync(dir)) return;
4024
4293
  const seen = /* @__PURE__ */ new Map();
4025
4294
  for (const name of readdirSync(dir).sort()) {
@@ -4028,21 +4297,21 @@ function checkMigrations(ctx, pkg, json, locals) {
4028
4297
  const other = seen.get(m[1]);
4029
4298
  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` });
4030
4299
  else seen.set(m[1], name);
4031
- if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path19.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
4300
+ if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path20.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
4032
4301
  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")})` });
4033
4302
  }
4034
4303
  }
4035
4304
  }
4036
4305
  function checkExports(ctx, pkg, json) {
4037
4306
  const targets = [];
4038
- const walk = (v) => {
4307
+ const walk2 = (v) => {
4039
4308
  if (typeof v === "string") targets.push(v);
4040
- else if (v && typeof v === "object") for (const x of Object.values(v)) walk(x);
4309
+ else if (v && typeof v === "object") for (const x of Object.values(v)) walk2(x);
4041
4310
  };
4042
- walk(json.exports);
4311
+ walk2(json.exports);
4043
4312
  for (const t of targets) {
4044
4313
  if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
4045
- if (!existsSync(path19.join(pkg.dir, t))) {
4314
+ if (!existsSync(path20.join(pkg.dir, t))) {
4046
4315
  ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
4047
4316
  }
4048
4317
  }
@@ -4060,11 +4329,11 @@ function checkBlocks(ctx, pkg, json) {
4060
4329
  function checkTaggedTests(ctx, pkg) {
4061
4330
  const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
4062
4331
  if (!tests.length) return;
4063
- const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path19.join(pkg.dir, f), "utf8")));
4332
+ const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path20.join(pkg.dir, f), "utf8")));
4064
4333
  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>` });
4065
4334
  }
4066
4335
  function checkRegistered(ctx, pkg) {
4067
- const file = path19.join(ctx.root, "features.json");
4336
+ const file = path20.join(ctx.root, "features.json");
4068
4337
  if (!existsSync(file)) return;
4069
4338
  let doc;
4070
4339
  try {
@@ -4074,7 +4343,7 @@ function checkRegistered(ctx, pkg) {
4074
4343
  }
4075
4344
  const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
4076
4345
  const forms = /* @__PURE__ */ new Set([pkg.rel]);
4077
- if (top) forms.add(path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/"));
4346
+ if (top) forms.add(path20.relative(top, realpathSync(pkg.dir)).split(path20.sep).join("/"));
4078
4347
  const covered = (doc.features ?? []).some(
4079
4348
  (f) => (f.links?.code ?? []).some((c) => {
4080
4349
  const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
@@ -4104,8 +4373,8 @@ function mergeBaseOf(root, base) {
4104
4373
  function checkChanges(ctx, pkg, json, base, mergeBase) {
4105
4374
  const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
4106
4375
  if (!top) return;
4107
- const appRelative = (fromTop) => path19.relative(realpathSync(ctx.root), path19.join(top, fromTop)).split(path19.sep).join("/");
4108
- const inRepo = path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/");
4376
+ const appRelative = (fromTop) => path20.relative(realpathSync(ctx.root), path20.join(top, fromTop)).split(path20.sep).join("/");
4377
+ const inRepo = path20.relative(top, realpathSync(pkg.dir)).split(path20.sep).join("/");
4109
4378
  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");
4110
4379
  const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
4111
4380
  const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
@@ -4128,11 +4397,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
4128
4397
  const now = typeof json.version === "string" ? parseVersion(json.version) : null;
4129
4398
  const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
4130
4399
  const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
4131
- 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)) : [];
4400
+ 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)) : [];
4132
4401
  const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
4133
4402
  const named = naming.length > 0;
4134
4403
  if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
4135
- 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` });
4404
+ 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` });
4136
4405
  }
4137
4406
  let jsonBefore = null;
4138
4407
  try {
@@ -4142,7 +4411,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
4142
4411
  }
4143
4412
  const raw = json;
4144
4413
  if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
4145
- const appInRepo = path19.relative(top, realpathSync(ctx.root)).split(path19.sep).join("/");
4414
+ const appInRepo = path20.relative(top, realpathSync(ctx.root)).split(path20.sep).join("/");
4146
4415
  const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
4147
4416
  const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
4148
4417
  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` });
@@ -4194,7 +4463,7 @@ function checkPackagesPack(ctx) {
4194
4463
  ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
4195
4464
  }
4196
4465
  for (const pkg of packages) {
4197
- const json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
4466
+ const json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
4198
4467
  checkImports2(ctx, pkg, json);
4199
4468
  checkExports(ctx, pkg, json);
4200
4469
  checkBlocks(ctx, pkg, json);
@@ -4388,9 +4657,9 @@ function gitView(root, dir, base) {
4388
4657
  function checkSupabasePack(ctx) {
4389
4658
  const settings = ctx.config.supabase ?? {};
4390
4659
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
4391
- const abs = path19.join(ctx.root, dir);
4660
+ const abs = path20.join(ctx.root, dir);
4392
4661
  if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
4393
- const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path19.join(abs, n), "utf8")) }));
4662
+ const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path20.join(abs, n), "utf8")) }));
4394
4663
  const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
4395
4664
  const base = settings.base ?? DEFAULT_BASE;
4396
4665
  const view = gitView(ctx.root, dir, base);
@@ -4407,7 +4676,7 @@ function checkSupabasePack(ctx) {
4407
4676
  }
4408
4677
  }
4409
4678
  const since = settings.since;
4410
- const afterSince = (file) => since === void 0 || path19.posix.basename(file) >= since;
4679
+ const afterSince = (file) => since === void 0 || path20.posix.basename(file) >= since;
4411
4680
  if ("reason" in view && since === void 0) {
4412
4681
  ctx.report({
4413
4682
  rule: "migration-grants",
@@ -4685,51 +4954,12 @@ function checkDefinerSearchPath(ctx, migrations) {
4685
4954
  });
4686
4955
  }
4687
4956
  }
4688
- var UMBRELLA_PACKAGE = "@marktiderman/genesis";
4689
- function readReleaseManifest(root) {
4690
- const dir = findPackageDir(root, UMBRELLA_PACKAGE);
4691
- const file = dir && path19.join(dir, "dist", "versions.json");
4692
- if (!file || !existsSync(file)) return null;
4693
- return JSON.parse(readFileSync(file, "utf8"));
4694
- }
4695
- function checkVersionSkew(ctx) {
4696
- const manifest = readReleaseManifest(ctx.root);
4697
- if (!manifest) return;
4698
- const overlays = markedOverlays(ctx);
4699
- for (const [name, want] of Object.entries(manifest.packages)) {
4700
- const overlay = overlays.get(name);
4701
- if (overlay) {
4702
- const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
4703
- if (from !== want) {
4704
- ctx.report({
4705
- rule: "version-skew",
4706
- level: "warn",
4707
- file: "package.json",
4708
- subject: name,
4709
- 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).`
4710
- });
4711
- }
4712
- continue;
4713
- }
4714
- const dir = findPackageDir(ctx.root, name);
4715
- if (!dir) continue;
4716
- const have = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8")).version;
4717
- if (have === want) continue;
4718
- ctx.report({
4719
- rule: "version-skew",
4720
- level: "warn",
4721
- file: "package.json",
4722
- subject: name,
4723
- message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
4724
- });
4725
- }
4726
- }
4727
4957
  var GENESIS2 = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
4728
4958
  var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
4729
4959
  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)$/;
4730
4960
  var readManifest = (dir) => {
4731
4961
  try {
4732
- return JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
4962
+ return JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
4733
4963
  } catch {
4734
4964
  return null;
4735
4965
  }
@@ -4743,18 +4973,18 @@ var real = (p) => {
4743
4973
  };
4744
4974
  var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
4745
4975
  function nodeModulesOf(dir) {
4746
- const parent = path19.dirname(dir);
4747
- return path19.basename(parent).startsWith("@") ? path19.dirname(parent) : parent;
4976
+ const parent = path20.dirname(dir);
4977
+ return path20.basename(parent).startsWith("@") ? path20.dirname(parent) : parent;
4748
4978
  }
4749
4979
  function packagesIn(nodeModules) {
4750
4980
  if (!existsSync(nodeModules)) return [];
4751
4981
  const out = [];
4752
4982
  for (const entry of readdirSync(nodeModules)) {
4753
4983
  if (entry.startsWith(".")) continue;
4754
- const p = path19.join(nodeModules, entry);
4984
+ const p = path20.join(nodeModules, entry);
4755
4985
  if (entry.startsWith("@")) {
4756
4986
  try {
4757
- for (const sub of readdirSync(p)) out.push(path19.join(p, sub));
4987
+ for (const sub of readdirSync(p)) out.push(path20.join(p, sub));
4758
4988
  } catch {
4759
4989
  }
4760
4990
  } else {
@@ -4766,7 +4996,7 @@ function packagesIn(nodeModules) {
4766
4996
  function genesisInstalls(root) {
4767
4997
  const copies = /* @__PURE__ */ new Map();
4768
4998
  const realRoot = real(root);
4769
- const rel = (abs) => path19.relative(realRoot, abs).split(path19.sep).join("/") || ".";
4999
+ const rel = (abs) => path20.relative(realRoot, abs).split(path20.sep).join("/") || ".";
4770
5000
  const via = /* @__PURE__ */ new Map();
4771
5001
  const record = (real2, manifest, by, range, root2) => {
4772
5002
  let copy = copies.get(real2);
@@ -4778,7 +5008,7 @@ function genesisInstalls(root) {
4778
5008
  via.get(real2).add(root2);
4779
5009
  if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
4780
5010
  };
4781
- const walk = (kind, roots) => {
5011
+ const walk2 = (kind, roots) => {
4782
5012
  const expanded = /* @__PURE__ */ new Set();
4783
5013
  const queue = [];
4784
5014
  const visit = (dir, by, range) => {
@@ -4811,7 +5041,7 @@ function genesisInstalls(root) {
4811
5041
  if (!dir) return null;
4812
5042
  if (!ownInstall || name in declared) return dir;
4813
5043
  const realDir = real(dir);
4814
- if (realDir.startsWith(realRoot + path19.sep)) return dir;
5044
+ if (realDir.startsWith(realRoot + path20.sep)) return dir;
4815
5045
  return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
4816
5046
  };
4817
5047
  const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
@@ -4819,7 +5049,7 @@ function genesisInstalls(root) {
4819
5049
  return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
4820
5050
  });
4821
5051
  const app = readManifest(root);
4822
- const ownInstall = LOCKFILES.some((f) => existsSync(path19.join(root, f)));
5052
+ const ownInstall = LOCKFILES.some((f) => existsSync(path20.join(root, f)));
4823
5053
  const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
4824
5054
  const declaredDev = Object.entries(app?.devDependencies ?? {});
4825
5055
  const runtimeDeps = {
@@ -4829,18 +5059,18 @@ function genesisInstalls(root) {
4829
5059
  ...app?.dependencies
4830
5060
  };
4831
5061
  const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
4832
- walk("runtime", rootsOf(runtimeDeps, "the app"));
4833
- const top = path19.join(root, "node_modules");
4834
- walk(
5062
+ walk2("runtime", rootsOf(runtimeDeps, "the app"));
5063
+ const top = path20.join(root, "node_modules");
5064
+ walk2(
4835
5065
  "hoisted",
4836
5066
  packagesIn(top).filter((dir) => {
4837
- const name = path19.relative(top, dir).split(path19.sep).join("/");
5067
+ const name = path20.relative(top, dir).split(path20.sep).join("/");
4838
5068
  return !(name in runtimeDeps) && !(name in devDeps);
4839
5069
  }).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
4840
5070
  );
4841
5071
  const devRoots = { ...devDeps };
4842
5072
  for (const tool of DEV_TOOLS) if (!(tool in devRoots) && tool in runtimeDeps) devRoots[tool] = runtimeDeps[tool];
4843
- walk("dev", rootsOf(devRoots, "the app (dev)"));
5073
+ walk2("dev", rootsOf(devRoots, "the app (dev)"));
4844
5074
  for (const [key2, copy] of copies) {
4845
5075
  const kinds = via.get(key2);
4846
5076
  copy.runtime = kinds.has("runtime");
@@ -4876,7 +5106,7 @@ function checkDuplicatePackages(ctx) {
4876
5106
  }
4877
5107
  }
4878
5108
  function checkPeerRanges(ctx) {
4879
- const rel = (abs) => path19.relative(ctx.root, abs).split(path19.sep).join("/");
5109
+ const rel = (abs) => path20.relative(ctx.root, abs).split(path20.sep).join("/");
4880
5110
  for (const copies of genesisInstalls(ctx.root).values()) {
4881
5111
  for (const copy of copies) {
4882
5112
  const dir = copy.absolutePath;
@@ -5258,17 +5488,17 @@ var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
5258
5488
  var MAX_BYTES = 2 * 1024 * 1024;
5259
5489
  function appScripts(root) {
5260
5490
  const out = [];
5261
- const walk = (dir) => {
5491
+ const walk2 = (dir) => {
5262
5492
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
5263
- const abs = path19.join(dir, entry.name);
5493
+ const abs = path20.join(dir, entry.name);
5264
5494
  if (entry.isDirectory()) {
5265
- if (!SKIP_DIRS3.has(entry.name)) walk(abs);
5495
+ if (!SKIP_DIRS3.has(entry.name)) walk2(abs);
5266
5496
  } else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
5267
- out.push(path19.relative(root, abs).split(path19.sep).join("/"));
5497
+ out.push(path20.relative(root, abs).split(path20.sep).join("/"));
5268
5498
  }
5269
5499
  }
5270
5500
  };
5271
- walk(root);
5501
+ walk2(root);
5272
5502
  return out;
5273
5503
  }
5274
5504
 
@@ -5352,7 +5582,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
5352
5582
  function moduleFiles(ctx) {
5353
5583
  const scanned = new Set(ctx.files.map((f) => f.path));
5354
5584
  const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
5355
- 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) }));
5585
+ 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) }));
5356
5586
  return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
5357
5587
  }
5358
5588
  function checkStudioServerImports(ctx) {
@@ -5388,7 +5618,7 @@ var REMOVED_WORDS = {
5388
5618
  };
5389
5619
  function checkRemovedScopeNames(ctx) {
5390
5620
  let augmentedMemo;
5391
- 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")));
5621
+ 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")));
5392
5622
  for (const file of ctx.files) {
5393
5623
  if (!SCRIPT_EXTS5.has(file.ext)) continue;
5394
5624
  for (const hit of findRemovedScopeNames(file.code)) {
@@ -5460,16 +5690,16 @@ function genesisNamedImports(source) {
5460
5690
  }
5461
5691
  function declarationFiles(dir, out = []) {
5462
5692
  for (const name of readdirSync(dir)) {
5463
- const full = path19.join(dir, name);
5693
+ const full = path20.join(dir, name);
5464
5694
  if (statSync(full).isDirectory()) declarationFiles(full, out);
5465
5695
  else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
5466
5696
  }
5467
5697
  return out;
5468
5698
  }
5469
5699
  function readPackageTags(dir) {
5470
- const pkg = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
5700
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
5471
5701
  const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
5472
- const dist = path19.join(dir, "dist");
5702
+ const dist = path20.join(dir, "dist");
5473
5703
  if (!existsSync(dist)) return tags;
5474
5704
  for (const file of declarationFiles(dist)) {
5475
5705
  const text = readFileSync(file, "utf8");
@@ -5487,7 +5717,7 @@ function entryFile(tags, pkg, specifier) {
5487
5717
  const subpath = `.${specifier.slice(pkg.length)}` || ".";
5488
5718
  const target = tags.exports[subpath === "." ? "." : subpath];
5489
5719
  const types = typeof target === "object" && target ? target.types : null;
5490
- return typeof types === "string" ? path19.join(tags.dir, types) : null;
5720
+ return typeof types === "string" ? path20.join(tags.dir, types) : null;
5491
5721
  }
5492
5722
  function tagFor(tags, entry, name) {
5493
5723
  if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
@@ -5542,7 +5772,7 @@ function showAt(dir, rev, file) {
5542
5772
  function configAtBase(root, base, explicitFile) {
5543
5773
  const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
5544
5774
  if (!mergeBase) return null;
5545
- const candidates = explicitFile ? [{ dir: path19.dirname(explicitFile), file: path19.basename(explicitFile), explicit: true }] : [
5775
+ const candidates = explicitFile ? [{ dir: path20.dirname(explicitFile), file: path20.basename(explicitFile), explicit: true }] : [
5546
5776
  { dir: root, file: "genesis.config.json", explicit: false },
5547
5777
  { dir: root, file: "package.json", explicit: false }
5548
5778
  ];
@@ -5654,7 +5884,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
5654
5884
  const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
5655
5885
  let current = null;
5656
5886
  try {
5657
- current = lf(readFileSync(path19.join(ctx.root, out), "utf8"));
5887
+ current = lf(readFileSync(path20.join(ctx.root, out), "utf8"));
5658
5888
  } catch {
5659
5889
  current = null;
5660
5890
  }
@@ -5678,7 +5908,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
5678
5908
  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}` });
5679
5909
  return;
5680
5910
  }
5681
- const target = path19.relative(process.cwd(), path19.join(ctx.root, out)) || out;
5911
+ const target = path20.relative(process.cwd(), path20.join(ctx.root, out)) || out;
5682
5912
  const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
5683
5913
  if (current !== expected) {
5684
5914
  ctx.report({
@@ -5841,13 +6071,13 @@ var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
5841
6071
  function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
5842
6072
  const rows = primitivesCatalog(packages);
5843
6073
  const changed = [];
5844
- const agents = path19.join(root, agentsFile);
6074
+ const agents = path20.join(root, agentsFile);
5845
6075
  const before = read(agents);
5846
6076
  const after = mergeAgentsBlock(before, renderAgentsBlock(rows));
5847
- const skill = path19.join(root, SKILL_PATH);
6077
+ const skill = path20.join(root, SKILL_PATH);
5848
6078
  const skillText = renderSkill(rows);
5849
6079
  if (read(skill)?.replace(/\r\n/g, "\n") !== skillText) {
5850
- mkdirSync(path19.dirname(skill), { recursive: true });
6080
+ mkdirSync(path20.dirname(skill), { recursive: true });
5851
6081
  writeFileSync(skill, skillText);
5852
6082
  changed.push(SKILL_PATH);
5853
6083
  }
@@ -5859,8 +6089,8 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
5859
6089
  }
5860
6090
  function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
5861
6091
  const rows = primitivesCatalog(packages);
5862
- const skill = read(path19.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
5863
- const block = currentAgentsBlock(read(path19.join(root, agentsFile)));
6092
+ const skill = read(path20.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
6093
+ const block = currentAgentsBlock(read(path20.join(root, agentsFile)));
5864
6094
  return {
5865
6095
  skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
5866
6096
  agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
@@ -5882,9 +6112,227 @@ function checkAgentGuide(ctx) {
5882
6112
  ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
5883
6113
  }
5884
6114
  }
6115
+ var LOCK_FILE = "genesis.lock.json";
6116
+ function emptyLock() {
6117
+ return { version: 1, blocks: {}, files: {} };
6118
+ }
6119
+ function readLock(root) {
6120
+ const file = path20.join(root, LOCK_FILE);
6121
+ if (!existsSync(file)) return emptyLock();
6122
+ const raw = JSON.parse(readFileSync(file, "utf8"));
6123
+ if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
6124
+ return {
6125
+ version: 1,
6126
+ ...raw.substitutions ? { substitutions: raw.substitutions } : {},
6127
+ blocks: raw.blocks ?? {},
6128
+ files: raw.files ?? {},
6129
+ ...raw.migrations ? { migrations: raw.migrations } : {}
6130
+ };
6131
+ }
6132
+ function parseSource(source) {
6133
+ const at = source.indexOf(":");
6134
+ if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
6135
+ return { package: source.slice(0, at), path: source.slice(at + 1) };
6136
+ }
6137
+ var CLI = "@marktiderman/genesis-cli";
6138
+ function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
6139
+ let parsed;
6140
+ try {
6141
+ parsed = parseSource(source);
6142
+ } catch (err) {
6143
+ return err instanceof Error ? err.message : String(err);
6144
+ }
6145
+ const { package: pkg, path: rel } = parsed;
6146
+ if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
6147
+ if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
6148
+ if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
6149
+ const base = rel.split("/").pop();
6150
+ if (pkg === CLI && rel.startsWith("templates/")) {
6151
+ return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
6152
+ }
6153
+ const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
6154
+ if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
6155
+ if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
6156
+ if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
6157
+ return `${key2} doesn't match its source ${source}`;
6158
+ }
6159
+
6160
+ // src/blocks/templates.ts
6161
+ function starterDir() {
6162
+ const workspace = workspacePackagesDir();
6163
+ const live = workspace && path20.join(workspace, "..", "apps", "genesis-rn-starter");
6164
+ if (live && existsSync(path20.join(live, "package.json"))) return live;
6165
+ const packaged = path20.join(cliPackageDir(), "dist", "starter");
6166
+ if (existsSync(path20.join(packaged, "package.json"))) return packaged;
6167
+ throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
6168
+ }
6169
+
6170
+ // src/blocks/starter-features.ts
6171
+ var STARTER_CONFIG = "starter.config.ts";
6172
+ var GENESIS_CONFIG = "genesis.config.json";
6173
+ var SWITCH = /^[a-zA-Z][a-zA-Z0-9]*$/;
6174
+ var BLOCK_ID2 = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
6175
+ function featuresBody(text) {
6176
+ const m = /\bfeatures:\s*\{/.exec(text);
6177
+ if (!m) return null;
6178
+ const start = m.index + m[0].length;
6179
+ const end = text.indexOf("}", start);
6180
+ return end < 0 ? null : { start, body: text.slice(start, end) };
6181
+ }
6182
+ function parseStarterFeatures(text) {
6183
+ const found = featuresBody(text);
6184
+ if (!found) return null;
6185
+ const out = {};
6186
+ for (const line of found.body.split("\n")) {
6187
+ const m = /^\s*([a-zA-Z][a-zA-Z0-9]*)\s*:\s*(true|false)\s*,?\s*(?:\/\/.*)?$/.exec(line);
6188
+ if (m) out[m[1]] = m[2] === "true";
6189
+ }
6190
+ return out;
6191
+ }
6192
+ function parseStarterBlocks(json, source = GENESIS_CONFIG) {
6193
+ let raw;
6194
+ try {
6195
+ raw = JSON.parse(json);
6196
+ } catch (err) {
6197
+ throw new Error(`${source} is not valid JSON: ${err.message}`);
6198
+ }
6199
+ const starter = raw?.starter;
6200
+ if (starter === void 0) return null;
6201
+ const blocks = starter?.blocks;
6202
+ 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`);
6203
+ const out = {};
6204
+ for (const [name, ids] of Object.entries(blocks)) {
6205
+ if (name === "$comment") continue;
6206
+ if (!SWITCH.test(name) || !Array.isArray(ids) || !ids.every((id) => typeof id === "string" && BLOCK_ID2.test(id))) {
6207
+ throw new Error(`${source}: starter.blocks.${name} must be a list of block ids`);
6208
+ }
6209
+ out[name] = ids;
6210
+ }
6211
+ return out;
6212
+ }
6213
+ function readText(file) {
6214
+ try {
6215
+ return readFileSync(file, "utf8");
6216
+ } catch {
6217
+ return null;
6218
+ }
6219
+ }
6220
+ function starterBlockMap(root) {
6221
+ if (root) {
6222
+ const file = path20.join(root, GENESIS_CONFIG);
6223
+ const text2 = readText(file);
6224
+ const own = text2 === null ? null : parseStarterBlocks(text2, file);
6225
+ if (own) return own;
6226
+ }
6227
+ let dir;
6228
+ try {
6229
+ dir = starterDir();
6230
+ } catch {
6231
+ return {};
6232
+ }
6233
+ const text = readText(path20.join(dir, GENESIS_CONFIG));
6234
+ return (text === null ? null : parseStarterBlocks(text)) ?? {};
6235
+ }
6236
+ function blocksSwitchedOff(switches, map, manifests, present) {
6237
+ const ids = new Set(present);
6238
+ const off = /* @__PURE__ */ new Map();
6239
+ for (const [name, carried] of Object.entries(map)) if (switches[name] === false) {
6240
+ for (const id of carried) if (ids.has(id)) off.set(id, name);
6241
+ }
6242
+ const requires = new Map(manifests.map((m) => [m.id, m.requires]));
6243
+ const keep = [...ids].filter((id) => !off.has(id));
6244
+ for (let i = 0; i < keep.length; i++) {
6245
+ for (const r of requires.get(keep[i]) ?? []) {
6246
+ off.delete(r);
6247
+ if (!keep.includes(r)) keep.push(r);
6248
+ }
6249
+ }
6250
+ return off;
6251
+ }
6252
+ function appBlocksSwitchedOff(root, manifests, present) {
6253
+ const text = readText(path20.join(root, STARTER_CONFIG));
6254
+ const switches = text === null ? null : parseStarterFeatures(text);
6255
+ if (!switches) return /* @__PURE__ */ new Map();
6256
+ return blocksSwitchedOff(switches, starterBlockMap(existsSync(path20.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
6257
+ }
6258
+ function blockOfSource(source, manifests) {
6259
+ const at = source.indexOf(":");
6260
+ if (at < 1) return null;
6261
+ const pkg = source.slice(0, at);
6262
+ const rel = source.slice(at + 1);
6263
+ for (const m of manifests) {
6264
+ if (m.functions.some((fn) => fn.package === pkg && rel.startsWith(`${fn.dir}/`))) return m.id;
6265
+ if (m.migrations.some((mig) => mig.package === pkg && mig.test === rel)) return m.id;
6266
+ }
6267
+ return null;
6268
+ }
6269
+
6270
+ // src/doctor/lock-files.ts
6271
+ async function checkLockFiles(ctx) {
6272
+ if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
6273
+ let lock;
6274
+ try {
6275
+ lock = readLock(ctx.root);
6276
+ } catch (err) {
6277
+ 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` });
6278
+ return;
6279
+ }
6280
+ const catalog = catalogBlocks();
6281
+ const off = appBlocksSwitchedOff(ctx.root, catalog, Object.keys(lock.blocks));
6282
+ const offManifests = [];
6283
+ for (const [id, entry] of Object.entries(lock.blocks)) {
6284
+ const feature = off.get(id);
6285
+ if (!feature) continue;
6286
+ try {
6287
+ offManifests.push((await findBlock(ctx.root, id, { package: entry.package })).manifest);
6288
+ } catch {
6289
+ offManifests.push(...catalog.filter((m) => m.id === id));
6290
+ }
6291
+ ctx.report({
6292
+ rule: "lock-files",
6293
+ level: "info",
6294
+ file: LOCK_FILE,
6295
+ subject: id,
6296
+ 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)`
6297
+ });
6298
+ }
6299
+ const local = localPackageNames(ctx.root);
6300
+ for (const [rel, entry] of Object.entries(lock.files)) {
6301
+ if (ownedKeyProblem(rel, entry.source, local)) continue;
6302
+ if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
6303
+ let text;
6304
+ try {
6305
+ text = readApp(ctx.root, rel);
6306
+ } catch {
6307
+ continue;
6308
+ }
6309
+ if (text === null) {
6310
+ if (entry.deleted) continue;
6311
+ ctx.report({
6312
+ rule: "lock-files",
6313
+ level: "warn",
6314
+ file: rel,
6315
+ subject: rel,
6316
+ 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})`
6317
+ });
6318
+ continue;
6319
+ }
6320
+ if (entry.deleted) {
6321
+ 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` });
6322
+ }
6323
+ if (sha256(text) === entry.sha256) continue;
6324
+ ctx.report({
6325
+ rule: "lock-files",
6326
+ level: "info",
6327
+ file: rel,
6328
+ subject: rel,
6329
+ 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`
6330
+ });
6331
+ }
6332
+ }
5885
6333
  var RATCHETED_BY_DEFAULT = ["deprecated-import"];
5886
6334
  async function runDoctor(options = {}) {
5887
- const root = path19.resolve(options.root ?? process.cwd());
6335
+ const root = path20.resolve(options.root ?? process.cwd());
5888
6336
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
5889
6337
  const config = loaded.config;
5890
6338
  const genesis = options.genesis ?? loadGenesis(root, config);
@@ -5938,7 +6386,7 @@ async function runDoctor(options = {}) {
5938
6386
  }
5939
6387
  let findings = applyConfig(raw, config, packageRuleIds(packages));
5940
6388
  if (options.base && changed) {
5941
- findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path19.join(root, f)) });
6389
+ findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path20.join(root, f)) });
5942
6390
  }
5943
6391
  const errors = findings.filter((f) => f.level === "error").length;
5944
6392
  const warnings = findings.filter((f) => f.level === "warn").length;
@@ -5983,6 +6431,7 @@ function builtinChecks(config, options = {}) {
5983
6431
  { name: "stability-imports", check: checkStabilityImports },
5984
6432
  { name: "agent-guide", check: checkAgentGuide },
5985
6433
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
6434
+ { name: "lock-files", check: checkLockFiles },
5986
6435
  ...(config.packs ?? []).map((p) => packs[p]),
5987
6436
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
5988
6437
  ];