@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/index.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import { createRequire, builtinModules } from 'module';
2
2
  import { studioSetupSql } from '@marktiderman/genesis-studio-server';
3
- import * as path19 from 'path';
3
+ import * as path20 from 'path';
4
4
  import { spawnSync } from 'child_process';
5
5
  import { existsSync, readFileSync, statSync, realpathSync, readdirSync, lstatSync } from 'fs';
6
- import 'crypto';
6
+ import { createHash } from 'crypto';
7
7
  import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
8
- import { pathToFileURL } from 'url';
8
+ import { pathToFileURL, fileURLToPath } from 'url';
9
9
  import { overlayUpstream, readOverlayMarker } from '@marktiderman/genesis-features';
10
- import 'jiti';
10
+ import { createJiti } from 'jiti';
11
+ import 'os';
11
12
 
12
13
  var __defProp = Object.defineProperty;
13
14
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -815,9 +816,9 @@ async function runScaffold(opts, fs) {
815
816
  function joinPath(...parts) {
816
817
  return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
817
818
  }
818
- function dirname(path30) {
819
- const idx = path30.lastIndexOf("/");
820
- return idx === -1 ? "." : path30.slice(0, idx);
819
+ function dirname(path36) {
820
+ const idx = path36.lastIndexOf("/");
821
+ return idx === -1 ? "." : path36.slice(0, idx);
821
822
  }
822
823
  function brandPackageJson(consumer, genesisVersion) {
823
824
  return JSON.stringify(
@@ -1408,19 +1409,19 @@ ${line}
1408
1409
  var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
1409
1410
  function buildCommands(root, config) {
1410
1411
  if (config.build) return config.build;
1411
- const pkgFile = path19.join(root, "package.json");
1412
+ const pkgFile = path20.join(root, "package.json");
1412
1413
  const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
1413
1414
  const pm = packageManager(root);
1414
1415
  return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
1415
1416
  }
1416
1417
  function packageManager(root) {
1417
- let dir = path19.resolve(root);
1418
+ let dir = path20.resolve(root);
1418
1419
  for (; ; ) {
1419
- if (existsSync(path19.join(dir, "pnpm-lock.yaml"))) return "pnpm";
1420
- if (existsSync(path19.join(dir, "bun.lock")) || existsSync(path19.join(dir, "bun.lockb"))) return "bun";
1421
- if (existsSync(path19.join(dir, "yarn.lock"))) return "yarn";
1422
- if (existsSync(path19.join(dir, "package-lock.json"))) return "npm";
1423
- const parent = path19.dirname(dir);
1420
+ if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return "pnpm";
1421
+ if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return "bun";
1422
+ if (existsSync(path20.join(dir, "yarn.lock"))) return "yarn";
1423
+ if (existsSync(path20.join(dir, "package-lock.json"))) return "npm";
1424
+ const parent = path20.dirname(dir);
1424
1425
  if (parent === dir) return "npm";
1425
1426
  dir = parent;
1426
1427
  }
@@ -1535,25 +1536,25 @@ var PACK_KEYS = {
1535
1536
  };
1536
1537
  function appPath(v, where2, fail) {
1537
1538
  if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
1538
- if (path19.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
1539
- const norm = path19.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
1539
+ if (path20.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
1540
+ const norm = path20.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
1540
1541
  if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
1541
1542
  return norm;
1542
1543
  }
1543
1544
  function loadConfig(root, configPath) {
1544
1545
  if (configPath) {
1545
- const file = path19.resolve(root, configPath);
1546
+ const file = path20.resolve(root, configPath);
1546
1547
  if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
1547
1548
  const json = readJson(file);
1548
- const block = path19.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
1549
- return { config: validateConfig(block ?? {}, file), file, dir: path19.dirname(file) };
1549
+ const block = path20.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
1550
+ return { config: validateConfig(block ?? {}, file), file, dir: path20.dirname(file) };
1550
1551
  }
1551
- const own = path19.join(root, "genesis.config.json");
1552
+ const own = path20.join(root, "genesis.config.json");
1552
1553
  if (existsSync(own)) {
1553
1554
  const block = readGenesisConfig(root)?.raw.doctor;
1554
1555
  return { config: validateConfig(block ?? {}, own), file: own, dir: root };
1555
1556
  }
1556
- const pkg = path19.join(root, "package.json");
1557
+ const pkg = path20.join(root, "package.json");
1557
1558
  if (existsSync(pkg)) {
1558
1559
  const block = readJson(pkg)?.genesis?.doctor;
1559
1560
  if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
@@ -1562,7 +1563,7 @@ function loadConfig(root, configPath) {
1562
1563
  }
1563
1564
  function doctorBlock(json, file, explicit) {
1564
1565
  const j = json;
1565
- if (path19.basename(file) === "package.json") return j?.genesis?.doctor;
1566
+ if (path20.basename(file) === "package.json") return j?.genesis?.doctor;
1566
1567
  return explicit ? j?.doctor ?? j : j?.doctor;
1567
1568
  }
1568
1569
  function isPackageDeclaration(block) {
@@ -1579,7 +1580,7 @@ function readJson(file) {
1579
1580
  }
1580
1581
  }
1581
1582
  function readGenesisConfig(root) {
1582
- const file = path19.join(root, "genesis.config.json");
1583
+ const file = path20.join(root, "genesis.config.json");
1583
1584
  if (!existsSync(file)) return null;
1584
1585
  const raw = readJson(file);
1585
1586
  if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
@@ -1744,7 +1745,7 @@ function validateConfig(raw, source = "config") {
1744
1745
  if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
1745
1746
  if (contracts.out !== void 0) {
1746
1747
  if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
1747
- if (path19.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
1748
+ if (path20.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
1748
1749
  }
1749
1750
  if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
1750
1751
  if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
@@ -1812,7 +1813,7 @@ function globToRegExp(glob) {
1812
1813
  }
1813
1814
  function globMatcher(globs) {
1814
1815
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1815
- return (path30) => res.some((re) => re.test(path30));
1816
+ return (path36) => res.some((re) => re.test(path36));
1816
1817
  }
1817
1818
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1818
1819
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -1852,11 +1853,11 @@ var TAILWIND_PALETTE = [
1852
1853
  "olive"
1853
1854
  ];
1854
1855
  function findPackageDir(from, name) {
1855
- let dir = path19.resolve(from);
1856
+ let dir = path20.resolve(from);
1856
1857
  for (; ; ) {
1857
- const candidate = path19.join(dir, "node_modules", name);
1858
- if (existsSync(path19.join(candidate, "package.json"))) return candidate;
1859
- const parent = path19.dirname(dir);
1858
+ const candidate = path20.join(dir, "node_modules", name);
1859
+ if (existsSync(path20.join(candidate, "package.json"))) return candidate;
1860
+ const parent = path20.dirname(dir);
1860
1861
  if (parent === dir) return null;
1861
1862
  dir = parent;
1862
1863
  }
@@ -1908,7 +1909,7 @@ function loadCompanions(root, config, uiPackage) {
1908
1909
  function readPackageExports(root, uiPackage) {
1909
1910
  const uiDir = findPackageDir(root, uiPackage);
1910
1911
  if (!uiDir) return null;
1911
- const uiPkg = JSON.parse(readFileSync(path19.join(uiDir, "package.json"), "utf8"));
1912
+ const uiPkg = JSON.parse(readFileSync(path20.join(uiDir, "package.json"), "utf8"));
1912
1913
  const subpaths = Object.values(uiPkg.exports ?? {});
1913
1914
  const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
1914
1915
  const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
@@ -1935,23 +1936,23 @@ function readPackageExports(root, uiPackage) {
1935
1936
  }
1936
1937
  if (fromSource) {
1937
1938
  for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
1938
- const next = resolveSource(path19.dirname(file), m[1]);
1939
+ const next = resolveSource(path20.dirname(file), m[1]);
1939
1940
  if (next) readEntry(next);
1940
1941
  }
1941
1942
  }
1942
1943
  };
1943
- for (const entry of typeEntries) readEntry(path19.join(uiDir, entry));
1944
+ for (const entry of typeEntries) readEntry(path20.join(uiDir, entry));
1944
1945
  if (!readAny) {
1945
1946
  const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
1946
1947
  throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
1947
1948
  }
1948
1949
  const valueDecls = /* @__PURE__ */ new Set();
1949
1950
  const typeDecls = /* @__PURE__ */ new Set();
1950
- const declRoot = typeof mainTypes === "string" ? path19.dirname(path19.join(uiDir, mainTypes)) : uiDir;
1951
+ const declRoot = typeof mainTypes === "string" ? path20.dirname(path20.join(uiDir, mainTypes)) : uiDir;
1951
1952
  const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
1952
1953
  for (const pkg of reexportedPackages) {
1953
1954
  const dir = findPackageDir(uiDir, pkg);
1954
- if (dir) walkDts(path19.join(dir, "dist"), declFiles);
1955
+ if (dir) walkDts(path20.join(dir, "dist"), declFiles);
1955
1956
  }
1956
1957
  for (const file of declFiles) {
1957
1958
  const text = readFileSync(file, "utf8");
@@ -2001,13 +2002,13 @@ function exportSource(target) {
2001
2002
  return void 0;
2002
2003
  }
2003
2004
  function resolveSource(dir, spec) {
2004
- const base = path19.resolve(dir, spec.replace(/\.js$/, ""));
2005
- const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path19.join(base, i))];
2005
+ const base = path20.resolve(dir, spec.replace(/\.js$/, ""));
2006
+ const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path20.join(base, i))];
2006
2007
  return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
2007
2008
  }
2008
2009
  function insidePackage(dir, file) {
2009
- const rel = path19.relative(path19.resolve(dir), path19.resolve(file));
2010
- return rel === "" || !rel.startsWith("..") && !path19.isAbsolute(rel);
2010
+ const rel = path20.relative(path20.resolve(dir), path20.resolve(file));
2011
+ return rel === "" || !rel.startsWith("..") && !path20.isAbsolute(rel);
2011
2012
  }
2012
2013
  function stripComments(code) {
2013
2014
  let out = "";
@@ -2043,7 +2044,7 @@ function walkSource(dir, out = []) {
2043
2044
  if (!existsSync(dir)) return out;
2044
2045
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
2045
2046
  if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
2046
- const p = path19.join(dir, entry.name);
2047
+ const p = path20.join(dir, entry.name);
2047
2048
  if (entry.isDirectory()) walkSource(p, out);
2048
2049
  else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
2049
2050
  }
@@ -2063,7 +2064,7 @@ function walkDts(dir, out = []) {
2063
2064
  if (!existsSync(dir)) return out;
2064
2065
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
2065
2066
  if (entry.name === "node_modules") continue;
2066
- const p = path19.join(dir, entry.name);
2067
+ const p = path20.join(dir, entry.name);
2067
2068
  if (entry.isDirectory()) walkDts(p, out);
2068
2069
  else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
2069
2070
  }
@@ -2080,27 +2081,27 @@ function resolveThemeFiles(root, config, uiDir) {
2080
2081
  }
2081
2082
  const files = [];
2082
2083
  const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
2083
- const themes = ds && path19.join(ds, "dist", "themes");
2084
+ const themes = ds && path20.join(ds, "dist", "themes");
2084
2085
  if (themes && existsSync(themes)) {
2085
- for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path19.join(themes, name));
2086
+ for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path20.join(themes, name));
2086
2087
  }
2087
2088
  if (files.length === 0) {
2088
2089
  throw new DoctorConfigError(
2089
2090
  `No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
2090
2091
  );
2091
2092
  }
2092
- const uiStyles = path19.join(uiDir, "dist", "styles.css");
2093
+ const uiStyles = path20.join(uiDir, "dist", "styles.css");
2093
2094
  if (existsSync(uiStyles)) files.push(uiStyles);
2094
2095
  return files;
2095
2096
  }
2096
2097
  function resolveSpec(root, spec) {
2097
- const local = path19.resolve(root, spec);
2098
- if (spec.startsWith(".") || path19.isAbsolute(spec)) return existsSync(local) ? local : null;
2098
+ const local = path20.resolve(root, spec);
2099
+ if (spec.startsWith(".") || path20.isAbsolute(spec)) return existsSync(local) ? local : null;
2099
2100
  const parts = spec.split("/");
2100
2101
  const nameLength = spec.startsWith("@") ? 2 : 1;
2101
2102
  const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
2102
2103
  if (dir) {
2103
- const file = path19.join(dir, ...parts.slice(nameLength));
2104
+ const file = path20.join(dir, ...parts.slice(nameLength));
2104
2105
  if (existsSync(file) && statSync(file).isFile()) return file;
2105
2106
  }
2106
2107
  return existsSync(local) ? local : null;
@@ -2108,7 +2109,7 @@ function resolveSpec(root, spec) {
2108
2109
  function loadPalette(root) {
2109
2110
  const names = new Set(TAILWIND_PALETTE);
2110
2111
  try {
2111
- const req = createRequire(path19.join(root, "package.json"));
2112
+ const req = createRequire(path20.join(root, "package.json"));
2112
2113
  const colors = req("tailwindcss/colors");
2113
2114
  for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
2114
2115
  if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
@@ -2294,11 +2295,56 @@ function rawBlocksOf(packageJson) {
2294
2295
  const blocks = packageJson["genesis"]["blocks"];
2295
2296
  return isObject2(blocks) ? blocks : {};
2296
2297
  }
2298
+ function declarationFields(block) {
2299
+ const c = block.contributes ?? {};
2300
+ return {
2301
+ ...block.requires ? { requires: [...block.requires] } : {},
2302
+ ...block.platforms ? { platforms: [...block.platforms] } : {},
2303
+ ...c.migrations ? { migrations: c.migrations.map((m) => ({ ...m })) } : {},
2304
+ ...c.routes ? { routes: c.routes.map((r) => ({ ...r })) } : {},
2305
+ ...c.skills ? { skills: [...c.skills] } : {},
2306
+ ...c.privacy ? { privacy: c.privacy } : {}
2307
+ };
2308
+ }
2309
+ function isBlockDef(value) {
2310
+ 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"]));
2311
+ }
2297
2312
 
2298
2313
  // src/blocks/files.ts
2314
+ var sha256 = (text) => createHash("sha256").update(text).digest("hex");
2299
2315
  function inside(parent, child) {
2300
- const rel = path19.relative(parent, child);
2301
- return rel === "" || !rel.startsWith("..") && !path19.isAbsolute(rel);
2316
+ const rel = path20.relative(parent, child);
2317
+ return rel === "" || !rel.startsWith("..") && !path20.isAbsolute(rel);
2318
+ }
2319
+ function appPath2(root, rel) {
2320
+ const safe = safeRelative(rel.replace(/^\.\//, ""));
2321
+ if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
2322
+ if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
2323
+ const realRoot = realpathSync(root);
2324
+ const target = path20.join(realRoot, ...safe.split("/"));
2325
+ const there = (p) => {
2326
+ try {
2327
+ lstatSync(p);
2328
+ return true;
2329
+ } catch {
2330
+ return false;
2331
+ }
2332
+ };
2333
+ let probe = path20.dirname(target);
2334
+ while (!there(probe)) probe = path20.dirname(probe);
2335
+ let real2;
2336
+ try {
2337
+ real2 = realpathSync(probe);
2338
+ } catch {
2339
+ throw new Error(`${rel} goes through a broken symlink (${path20.relative(realRoot, probe)}); refused`);
2340
+ }
2341
+ if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
2342
+ if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
2343
+ return target;
2344
+ }
2345
+ function readApp(root, rel) {
2346
+ const file = appPath2(root, rel);
2347
+ return existsSync(file) ? readFileSync(file, "utf8") : null;
2302
2348
  }
2303
2349
 
2304
2350
  // src/blocks/local.ts
@@ -2311,8 +2357,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
2311
2357
  return raw.map((entry, i) => {
2312
2358
  const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
2313
2359
  if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
2314
- if (path19.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
2315
- const norm = path19.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
2360
+ if (path20.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
2361
+ const norm = path20.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
2316
2362
  if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
2317
2363
  const parts = norm.split("/");
2318
2364
  if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
@@ -2323,7 +2369,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
2323
2369
  });
2324
2370
  }
2325
2371
  function localPackageGlobs(root) {
2326
- const file = path19.join(root, "genesis.config.json");
2372
+ const file = path20.join(root, "genesis.config.json");
2327
2373
  if (!existsSync(file)) return [];
2328
2374
  let raw;
2329
2375
  try {
@@ -2337,14 +2383,14 @@ function localPackageGlobs(root) {
2337
2383
  var cache = /* @__PURE__ */ new Map();
2338
2384
  function repositoryRoot(appRoot) {
2339
2385
  for (let dir = appRoot; ; ) {
2340
- if (existsSync(path19.join(dir, ".git"))) return dir;
2341
- const parent = path19.dirname(dir);
2386
+ if (existsSync(path20.join(dir, ".git"))) return dir;
2387
+ const parent = path20.dirname(dir);
2342
2388
  if (parent === dir) return appRoot;
2343
2389
  dir = parent;
2344
2390
  }
2345
2391
  }
2346
2392
  function localPackages(root) {
2347
- const appRoot = path19.resolve(root);
2393
+ const appRoot = path20.resolve(root);
2348
2394
  const globs = localPackageGlobs(appRoot);
2349
2395
  const key2 = `${appRoot}
2350
2396
  ${globs.join("\n")}`;
@@ -2353,24 +2399,24 @@ ${globs.join("\n")}`;
2353
2399
  const dirs = /* @__PURE__ */ new Set();
2354
2400
  for (const glob of globs) {
2355
2401
  if (glob.endsWith("/*") || glob === "*") {
2356
- const parent = path19.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
2402
+ const parent = path20.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
2357
2403
  if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
2358
2404
  for (const entry of readdirSync(parent).sort()) {
2359
2405
  if (entry.startsWith(".") || entry === "node_modules") continue;
2360
- dirs.add(path19.join(parent, entry));
2406
+ dirs.add(path20.join(parent, entry));
2361
2407
  }
2362
2408
  } else {
2363
- dirs.add(path19.join(appRoot, glob));
2409
+ dirs.add(path20.join(appRoot, glob));
2364
2410
  }
2365
2411
  }
2366
2412
  const real2 = realpathSync(repositoryRoot(appRoot));
2367
2413
  const out = [];
2368
2414
  const byName = /* @__PURE__ */ new Map();
2369
2415
  for (const dir of [...dirs].sort()) {
2370
- const manifest = path19.join(dir, "package.json");
2416
+ const manifest = path20.join(dir, "package.json");
2371
2417
  if (!existsSync(manifest)) continue;
2372
2418
  if (!inside(real2, realpathSync(dir))) {
2373
- throw new LocalPackagesError(`${path19.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
2419
+ throw new LocalPackagesError(`${path20.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
2374
2420
  }
2375
2421
  let pkg;
2376
2422
  try {
@@ -2379,7 +2425,7 @@ ${globs.join("\n")}`;
2379
2425
  continue;
2380
2426
  }
2381
2427
  if (typeof pkg.name !== "string" || !pkg.name) continue;
2382
- const rel = path19.relative(appRoot, dir).split(path19.sep).join("/");
2428
+ const rel = path20.relative(appRoot, dir).split(path20.sep).join("/");
2383
2429
  const other = byName.get(pkg.name);
2384
2430
  if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
2385
2431
  byName.set(pkg.name, rel);
@@ -2388,6 +2434,9 @@ ${globs.join("\n")}`;
2388
2434
  cache.set(key2, out);
2389
2435
  return out;
2390
2436
  }
2437
+ function localPackageNames(root) {
2438
+ return new Set(localPackages(root).map((p) => p.name));
2439
+ }
2391
2440
 
2392
2441
  // ../../scripts/lib/color-literals.mjs
2393
2442
  var LINE_COMMENT_EXTS = /* @__PURE__ */ new Set([".ts", ".tsx", ".jsx", ".js", ".mjs", ".cjs", ".scss", ".less"]);
@@ -2564,35 +2613,35 @@ var DEFAULT_IGNORE = [
2564
2613
  ];
2565
2614
  var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
2566
2615
  var MAX_FILE_BYTES = 2 * 1024 * 1024;
2567
- var toPosix = (p) => p.split(path19.sep).join("/");
2616
+ var toPosix = (p) => p.split(path20.sep).join("/");
2568
2617
  function scanFiles(root, config) {
2569
2618
  const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
2570
2619
  const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
2571
2620
  const files = [];
2572
2621
  const seen = /* @__PURE__ */ new Set();
2573
2622
  const visit = (abs) => {
2574
- const rel = toPosix(path19.relative(root, abs));
2623
+ const rel = toPosix(path20.relative(root, abs));
2575
2624
  if (seen.has(rel) || ignored(rel)) return;
2576
- const ext = path19.extname(abs);
2625
+ const ext = path20.extname(abs);
2577
2626
  if (!extensions.has(ext)) return;
2578
2627
  if (statSync(abs).size > MAX_FILE_BYTES) return;
2579
2628
  seen.add(rel);
2580
2629
  const text = readFileSync(abs, "utf8");
2581
2630
  files.push({ path: rel, absolutePath: abs, ext, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(ext)) });
2582
2631
  };
2583
- const walk = (dir) => {
2632
+ const walk2 = (dir) => {
2584
2633
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
2585
2634
  if (entry.isDirectory()) {
2586
- if (!SKIP_DIRS.has(entry.name)) walk(path19.join(dir, entry.name));
2635
+ if (!SKIP_DIRS.has(entry.name)) walk2(path20.join(dir, entry.name));
2587
2636
  } else if (entry.isFile()) {
2588
- visit(path19.join(dir, entry.name));
2637
+ visit(path20.join(dir, entry.name));
2589
2638
  }
2590
2639
  }
2591
2640
  };
2592
2641
  for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
2593
- const abs = path19.resolve(root, src);
2642
+ const abs = path20.resolve(root, src);
2594
2643
  if (!existsSync(abs)) continue;
2595
- if (statSync(abs).isDirectory()) walk(abs);
2644
+ if (statSync(abs).isDirectory()) walk2(abs);
2596
2645
  else visit(abs);
2597
2646
  }
2598
2647
  let local = [];
@@ -2601,7 +2650,7 @@ function scanFiles(root, config) {
2601
2650
  } catch {
2602
2651
  local = [];
2603
2652
  }
2604
- for (const pkg of local) walk(pkg.dir);
2653
+ for (const pkg of local) walk2(pkg.dir);
2605
2654
  return files;
2606
2655
  }
2607
2656
  function lineAt(text, index) {
@@ -2678,7 +2727,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
2678
2727
  const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
2679
2728
  let all = compiled;
2680
2729
  if (rulesDoc) {
2681
- const file = path19.resolve(root, rulesDoc);
2730
+ const file = path20.resolve(root, rulesDoc);
2682
2731
  if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
2683
2732
  const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
2684
2733
  const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
@@ -2739,15 +2788,177 @@ async function loadPlugins(specs, configDir) {
2739
2788
  }
2740
2789
  function resolvePlugin(id, configDir) {
2741
2790
  try {
2742
- if (id.startsWith(".") || path19.isAbsolute(id)) return resolveFrom(path19.resolve(configDir, id), configDir);
2791
+ if (id.startsWith(".") || path20.isAbsolute(id)) return resolveFrom(path20.resolve(configDir, id), configDir);
2743
2792
  return resolveFrom(id, configDir);
2744
2793
  } catch {
2745
2794
  throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
2746
2795
  }
2747
2796
  }
2748
2797
  function resolveFrom(id, from) {
2749
- return createRequire(path19.join(from, "noop.js")).resolve(id);
2798
+ return createRequire(path20.join(from, "noop.js")).resolve(id);
2799
+ }
2800
+
2801
+ // src/doctor/semver.ts
2802
+ var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
2803
+ function parseVersion(v) {
2804
+ const m = VERSION.exec(v.trim());
2805
+ return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
2806
+ }
2807
+ function compareVersions(a, b) {
2808
+ for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
2809
+ if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
2810
+ for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
2811
+ const x = a.pre[i];
2812
+ const y = b.pre[i];
2813
+ if (x === void 0) return -1;
2814
+ if (y === void 0) return 1;
2815
+ if (x === y) continue;
2816
+ const nx = /^\d+$/.test(x);
2817
+ const ny = /^\d+$/.test(y);
2818
+ if (nx && ny) return +x < +y ? -1 : 1;
2819
+ if (nx !== ny) return nx ? -1 : 1;
2820
+ return x < y ? -1 : 1;
2821
+ }
2822
+ return 0;
2823
+ }
2824
+ function partial(s) {
2825
+ const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
2826
+ if (!m) return null;
2827
+ const nums = [];
2828
+ let wild = false;
2829
+ for (const part of [m[1], m[2], m[3]]) {
2830
+ if (wild || part === void 0 || /^[xX*]$/.test(part)) {
2831
+ wild = true;
2832
+ nums.push(null);
2833
+ } else nums.push(+part);
2834
+ }
2835
+ return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
2836
+ }
2837
+ var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
2838
+ function comparators(token) {
2839
+ const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
2840
+ if (!m) return null;
2841
+ const op = m[1] ?? "";
2842
+ const p = partial(m[2]);
2843
+ if (!p) return null;
2844
+ const [major, mi, pa] = p.nums;
2845
+ if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
2846
+ const M = major;
2847
+ const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
2848
+ 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"]);
2849
+ const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
2850
+ const out = switchOp();
2851
+ if (p.pre.length) {
2852
+ for (const c of out) if (c.v === lo) c.pre = true;
2853
+ }
2854
+ return out;
2855
+ function switchOp() {
2856
+ switch (op) {
2857
+ case "^": {
2858
+ const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
2859
+ return [
2860
+ { op: ">=", v: lo },
2861
+ { op: "<", v: bound }
2862
+ ];
2863
+ }
2864
+ case "~":
2865
+ case "~>":
2866
+ return [
2867
+ { op: ">=", v: lo },
2868
+ { op: "<", v: mi === null ? next("major") : next("minor") }
2869
+ ];
2870
+ case ">":
2871
+ return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
2872
+ case ">=":
2873
+ return [{ op: ">=", v: lo }];
2874
+ case "<":
2875
+ return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
2876
+ case "<=":
2877
+ return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
2878
+ default:
2879
+ return upper ? [
2880
+ { op: ">=", v: lo },
2881
+ { op: "<", v: upper }
2882
+ ] : [{ op: "=", v: lo }];
2883
+ }
2884
+ }
2885
+ }
2886
+ function test(c, v) {
2887
+ const d = compareVersions(v, c.v);
2888
+ return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
2889
+ }
2890
+ function parseRange(range) {
2891
+ const alts = [];
2892
+ for (const raw of range.trim().split("||")) {
2893
+ const alt = raw.trim();
2894
+ const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
2895
+ if (hyphen) {
2896
+ const from = comparators(`>=${hyphen[1]}`);
2897
+ const to = comparators(`<=${hyphen[2]}`);
2898
+ if (!from || !to) return null;
2899
+ alts.push([...from, ...to]);
2900
+ continue;
2901
+ }
2902
+ const set = [];
2903
+ for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
2904
+ const cs = comparators(token);
2905
+ if (!cs) return null;
2906
+ set.push(...cs);
2907
+ }
2908
+ alts.push(set);
2909
+ }
2910
+ return alts;
2911
+ }
2912
+ function satisfies(version, range) {
2913
+ const v = parseVersion(version);
2914
+ const alts = parseRange(range);
2915
+ if (!v || !alts) return null;
2916
+ return alts.some(
2917
+ (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))
2918
+ );
2919
+ }
2920
+ var UMBRELLA_PACKAGE = "@marktiderman/genesis";
2921
+ function readReleaseManifest(root) {
2922
+ const dir = findPackageDir(root, UMBRELLA_PACKAGE);
2923
+ const file = dir && path20.join(dir, "dist", "versions.json");
2924
+ if (!file || !existsSync(file)) return null;
2925
+ return JSON.parse(readFileSync(file, "utf8"));
2926
+ }
2927
+ function checkVersionSkew(ctx) {
2928
+ const manifest = readReleaseManifest(ctx.root);
2929
+ if (!manifest) return;
2930
+ const overlays = markedOverlays(ctx);
2931
+ for (const [name, want] of Object.entries(manifest.packages)) {
2932
+ const overlay = overlays.get(name);
2933
+ if (overlay) {
2934
+ const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
2935
+ const behind = parseVersion(from) && parseVersion(want) && compareVersions(parseVersion(from), parseVersion(want)) < 0;
2936
+ if (from !== want && !behind) {
2937
+ ctx.report({
2938
+ rule: "version-skew",
2939
+ level: "warn",
2940
+ file: "package.json",
2941
+ subject: name,
2942
+ 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).`
2943
+ });
2944
+ }
2945
+ continue;
2946
+ }
2947
+ const dir = findPackageDir(ctx.root, name);
2948
+ if (!dir) continue;
2949
+ const have = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8")).version;
2950
+ if (have === want) continue;
2951
+ ctx.report({
2952
+ rule: "version-skew",
2953
+ level: "warn",
2954
+ file: "package.json",
2955
+ subject: name,
2956
+ message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
2957
+ });
2958
+ }
2750
2959
  }
2960
+
2961
+ // src/doctor/overlays.ts
2751
2962
  var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
2752
2963
  var OVERLAY_NOTICE_DAYS = 14;
2753
2964
  var OVERLAY_WARN_DAYS = 30;
@@ -2761,7 +2972,7 @@ function overlayState(name, json) {
2761
2972
  function overlaySetupProblems(root, config, dir, name, json) {
2762
2973
  const problems = [];
2763
2974
  if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
2764
- const rel = path19.relative(path19.resolve(root), path19.resolve(dir)).split(path19.sep).join("/");
2975
+ const rel = path20.relative(path20.resolve(root), path20.resolve(dir)).split(path20.sep).join("/");
2765
2976
  const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
2766
2977
  const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
2767
2978
  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})`);
@@ -2786,6 +2997,31 @@ function overlayAgeDays(since, now = /* @__PURE__ */ new Date()) {
2786
2997
  return Math.floor((today - Date.UTC(y, m - 1, d)) / 864e5);
2787
2998
  }
2788
2999
  var LOCAL_VERSION = /^(\d+\.\d+\.\d+(?:-(?!local\.)[0-9A-Za-z.-]+?)?)(?:[+-]local\.(?:0|[1-9]\d*))?$/;
3000
+ function pinnedVersion(root, name, manifests = ["package.json"]) {
3001
+ let manifest = null;
3002
+ try {
3003
+ manifest = readReleaseManifest(root);
3004
+ } catch {
3005
+ }
3006
+ const released = manifest?.packages[name];
3007
+ if (released && parseVersion(released)) return released;
3008
+ let best = null;
3009
+ for (const file of manifests) {
3010
+ let json;
3011
+ try {
3012
+ json = JSON.parse(readFileSync(path20.join(root, file), "utf8"));
3013
+ } catch {
3014
+ continue;
3015
+ }
3016
+ for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
3017
+ const spec = json[section]?.[name];
3018
+ const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
3019
+ const parsed = v && parseVersion(v);
3020
+ if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
3021
+ }
3022
+ }
3023
+ return best;
3024
+ }
2789
3025
  function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
2790
3026
  let packages;
2791
3027
  try {
@@ -2798,7 +3034,7 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
2798
3034
  const file = `${pkg.rel}/package.json`;
2799
3035
  let json;
2800
3036
  try {
2801
- json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
3037
+ json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
2802
3038
  } catch {
2803
3039
  continue;
2804
3040
  }
@@ -2841,6 +3077,18 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
2841
3077
  message: `the overlay of ${marker.upstream} is version ${version || "(none)"}; use ${upstream}+local.N (or ${upstream} itself) so it reads as a local build of ${upstream} and still satisfies peer ranges`
2842
3078
  });
2843
3079
  }
3080
+ const pinned = pinnedVersion(ctx.root, pkg.name);
3081
+ const from = parseVersion(upstream);
3082
+ const to = pinned ? parseVersion(pinned) : null;
3083
+ if (from && to && compareVersions(from, to) < 0) {
3084
+ ctx.report({
3085
+ rule: "overlay-behind",
3086
+ level: "warn",
3087
+ file,
3088
+ subject: pkg.name,
3089
+ 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`
3090
+ });
3091
+ }
2844
3092
  }
2845
3093
  }
2846
3094
 
@@ -2904,6 +3152,7 @@ var BUILTIN_RULES = [
2904
3152
  "overlay-invalid",
2905
3153
  "overlay-age",
2906
3154
  "overlay-version",
3155
+ "overlay-behind",
2907
3156
  // package rules (package-rules.ts): the rules themselves are namespaced, e.g. ui/lists-use-resource-view
2908
3157
  "package-rules-invalid",
2909
3158
  "package-rule-override",
@@ -2914,7 +3163,9 @@ var BUILTIN_RULES = [
2914
3163
  // agent guide (primitives.ts)
2915
3164
  "agent-guide-stale",
2916
3165
  // supabase pack: contracts (contracts.ts)
2917
- "contracts-stale"
3166
+ "contracts-stale",
3167
+ // genesis.lock.json against the files (lock-files.ts)
3168
+ "lock-files"
2918
3169
  ];
2919
3170
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2920
3171
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -2932,7 +3183,7 @@ function importSpecifiers(file) {
2932
3183
  }
2933
3184
  function checkProjectLayout(ctx) {
2934
3185
  for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
2935
- if (existsSync(path19.join(ctx.root, dir))) {
3186
+ if (existsSync(path20.join(ctx.root, dir))) {
2936
3187
  ctx.report({
2937
3188
  rule: "local-primitives",
2938
3189
  file: dir,
@@ -2942,7 +3193,7 @@ function checkProjectLayout(ctx) {
2942
3193
  }
2943
3194
  }
2944
3195
  for (const file of STARTER_LEFTOVERS) {
2945
- if (existsSync(path19.join(ctx.root, file))) {
3196
+ if (existsSync(path20.join(ctx.root, file))) {
2946
3197
  ctx.report({
2947
3198
  rule: "starter-leftover",
2948
3199
  level: "warn",
@@ -3032,7 +3283,7 @@ function checkTokens(ctx) {
3032
3283
  }
3033
3284
  for (const pattern of ctx.config.tokenFiles ?? []) {
3034
3285
  if (/[*?]/.test(pattern)) continue;
3035
- const abs = path19.join(ctx.root, pattern);
3286
+ const abs = path20.join(ctx.root, pattern);
3036
3287
  if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
3037
3288
  for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
3038
3289
  }
@@ -3132,14 +3383,33 @@ var appFunctionality = (type, ...more) => ({
3132
3383
  function privacyApisFor(dependencies2) {
3133
3384
  return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
3134
3385
  }
3386
+
3387
+ // src/eas-placeholders.ts
3388
+ var EAS_PLACEHOLDERS = {
3389
+ 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)",
3390
+ REPLACE_WITH_APPLE_TEAM_ID: "your Apple Developer Team ID (developer.apple.com \u2192 Account \u2192 Membership details, 10 characters)",
3391
+ 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",
3392
+ REPLACE_WITH_APP_FOLDER: "the app's code folder (src, or apps/<name> in a monorepo)"
3393
+ };
3394
+ function placeholderKey(line, placeholder) {
3395
+ return new RegExp(`"([A-Za-z0-9_]+)"\\s*:\\s*"${placeholder}"`).exec(line)?.[1] ?? null;
3396
+ }
3397
+ function findPlaceholders(file, text) {
3398
+ const out = [];
3399
+ text.split("\n").forEach((line, i) => {
3400
+ if (!file.endsWith(".json") && /^\s*#/.test(line)) return;
3401
+ for (const m of line.matchAll(/\bREPLACE_WITH_[A-Z0-9_]+/g)) out.push({ line: i + 1, text: line, placeholder: m[0] });
3402
+ });
3403
+ return out;
3404
+ }
3135
3405
  var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
3136
3406
  var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
3137
3407
  var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
3138
3408
  function resolveLocal(root, fromFile, spec) {
3139
- const bases = spec.startsWith(".") ? [path19.resolve(path19.dirname(fromFile), spec)] : [path19.join(root, spec.slice(2)), path19.join(root, "src", spec.slice(2))];
3409
+ const bases = spec.startsWith(".") ? [path20.resolve(path20.dirname(fromFile), spec)] : [path20.join(root, spec.slice(2)), path20.join(root, "src", spec.slice(2))];
3140
3410
  for (const base of bases) {
3141
- const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path19.join(base, `index${e}`))].find(
3142
- (p) => SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p)
3411
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path20.join(base, `index${e}`))].find(
3412
+ (p) => SCRIPT_EXTS2.has(path20.extname(p)) && existsSync(p)
3143
3413
  );
3144
3414
  if (hit) return hit;
3145
3415
  }
@@ -3258,29 +3528,26 @@ function checkNativePack(ctx) {
3258
3528
  checkStoreReadiness(ctx);
3259
3529
  checkEasPlaceholders(ctx);
3260
3530
  }
3261
- var EAS_PLACEHOLDER = /\bREPLACE_WITH_[A-Z0-9_]+/g;
3262
3531
  function checkEasPlaceholders(ctx) {
3263
3532
  const files = [];
3264
- if (existsSync(path19.join(ctx.root, "eas.json"))) files.push("eas.json");
3265
- const workflows = path19.join(ctx.root, ".eas", "workflows");
3533
+ if (existsSync(path20.join(ctx.root, "eas.json"))) files.push("eas.json");
3534
+ const workflows = path20.join(ctx.root, ".eas", "workflows");
3266
3535
  if (existsSync(workflows)) {
3267
3536
  for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
3268
3537
  }
3269
3538
  for (const file of files) {
3270
- const lines = readFileSync(path19.join(ctx.root, file), "utf8").split("\n");
3271
- lines.forEach((text, i) => {
3272
- if (!file.endsWith(".json") && /^\s*#/.test(text)) return;
3273
- for (const m of text.matchAll(EAS_PLACEHOLDER)) {
3274
- ctx.report({
3275
- rule: "eas-placeholder",
3276
- level: "warn",
3277
- file,
3278
- line: i + 1,
3279
- subject: m[0],
3280
- 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)`
3281
- });
3282
- }
3283
- });
3539
+ for (const hit of findPlaceholders(file, readFileSync(path20.join(ctx.root, file), "utf8"))) {
3540
+ const key2 = placeholderKey(hit.text, hit.placeholder);
3541
+ const what = EAS_PLACEHOLDERS[hit.placeholder];
3542
+ ctx.report({
3543
+ rule: "eas-placeholder",
3544
+ level: "warn",
3545
+ file,
3546
+ line: hit.line,
3547
+ subject: hit.placeholder,
3548
+ 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`
3549
+ });
3550
+ }
3284
3551
  }
3285
3552
  }
3286
3553
  var RN = String.raw`["']react-native["']`;
@@ -3348,7 +3615,7 @@ function checkCustomHeaders(ctx, pkg) {
3348
3615
  if (!JSX_EXTS3.has(file.ext)) continue;
3349
3616
  const code = file.code;
3350
3617
  const hidden = HIDES_HEADER.exec(code);
3351
- if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path19.posix.dirname(file.path), file.path);
3618
+ if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path20.posix.dirname(file.path), file.path);
3352
3619
  const own = hidden ? ownHeader(code, pkg) : null;
3353
3620
  if (hidden && own) {
3354
3621
  reported.add(file.path);
@@ -3376,7 +3643,7 @@ function checkCustomHeaders(ctx, pkg) {
3376
3643
  }
3377
3644
  for (const file of ctx.files) {
3378
3645
  if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
3379
- const layout = hidingLayouts.get(path19.posix.dirname(file.path));
3646
+ const layout = hidingLayouts.get(path20.posix.dirname(file.path));
3380
3647
  const own = layout ? ownHeader(file.code, pkg) : null;
3381
3648
  if (!layout || !own) continue;
3382
3649
  ctx.report({
@@ -3398,13 +3665,13 @@ function isLoadingOnlyRoute(code) {
3398
3665
  }
3399
3666
  function routerRoot(ctx) {
3400
3667
  if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
3401
- return existsSync(path19.join(ctx.root, "src", "app")) ? "src/app" : "app";
3668
+ return existsSync(path20.join(ctx.root, "src", "app")) ? "src/app" : "app";
3402
3669
  }
3403
3670
  function checkScreenLayouts(ctx, pkg) {
3404
3671
  const layouts = nativeLayouts(pkg);
3405
3672
  if (layouts.length === 0) return;
3406
3673
  const rootDir = routerRoot(ctx);
3407
- if (!existsSync(path19.join(ctx.root, rootDir))) {
3674
+ if (!existsSync(path20.join(ctx.root, rootDir))) {
3408
3675
  ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
3409
3676
  return;
3410
3677
  }
@@ -3460,7 +3727,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
3460
3727
  function readExpoConfigs(root) {
3461
3728
  const out = [];
3462
3729
  for (const name of EXPO_CONFIGS) {
3463
- const abs = path19.join(root, name);
3730
+ const abs = path20.join(root, name);
3464
3731
  if (!existsSync(abs)) continue;
3465
3732
  const text = readFileSync(abs, "utf8");
3466
3733
  let json = null;
@@ -3494,13 +3761,13 @@ function pluginOptions(json, module) {
3494
3761
  return null;
3495
3762
  }
3496
3763
  function dependencies(root) {
3497
- const file = path19.join(root, "package.json");
3764
+ const file = path20.join(root, "package.json");
3498
3765
  if (!existsSync(file)) return /* @__PURE__ */ new Set();
3499
3766
  const pkg = JSON.parse(readFileSync(file, "utf8"));
3500
3767
  return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
3501
3768
  }
3502
3769
  function runtimeDependencies(root) {
3503
- const file = path19.join(root, "package.json");
3770
+ const file = path20.join(root, "package.json");
3504
3771
  if (!existsSync(file)) return {};
3505
3772
  return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
3506
3773
  }
@@ -3581,126 +3848,6 @@ function checkStoreReadiness(ctx) {
3581
3848
  });
3582
3849
  }
3583
3850
  }
3584
-
3585
- // src/doctor/semver.ts
3586
- var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
3587
- function parseVersion(v) {
3588
- const m = VERSION.exec(v.trim());
3589
- return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
3590
- }
3591
- function compareVersions(a, b) {
3592
- for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
3593
- if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
3594
- for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
3595
- const x = a.pre[i];
3596
- const y = b.pre[i];
3597
- if (x === void 0) return -1;
3598
- if (y === void 0) return 1;
3599
- if (x === y) continue;
3600
- const nx = /^\d+$/.test(x);
3601
- const ny = /^\d+$/.test(y);
3602
- if (nx && ny) return +x < +y ? -1 : 1;
3603
- if (nx !== ny) return nx ? -1 : 1;
3604
- return x < y ? -1 : 1;
3605
- }
3606
- return 0;
3607
- }
3608
- function partial(s) {
3609
- const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
3610
- if (!m) return null;
3611
- const nums = [];
3612
- let wild = false;
3613
- for (const part of [m[1], m[2], m[3]]) {
3614
- if (wild || part === void 0 || /^[xX*]$/.test(part)) {
3615
- wild = true;
3616
- nums.push(null);
3617
- } else nums.push(+part);
3618
- }
3619
- return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
3620
- }
3621
- var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
3622
- function comparators(token) {
3623
- const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
3624
- if (!m) return null;
3625
- const op = m[1] ?? "";
3626
- const p = partial(m[2]);
3627
- if (!p) return null;
3628
- const [major, mi, pa] = p.nums;
3629
- if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
3630
- const M = major;
3631
- const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
3632
- 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"]);
3633
- const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
3634
- const out = switchOp();
3635
- if (p.pre.length) {
3636
- for (const c of out) if (c.v === lo) c.pre = true;
3637
- }
3638
- return out;
3639
- function switchOp() {
3640
- switch (op) {
3641
- case "^": {
3642
- const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
3643
- return [
3644
- { op: ">=", v: lo },
3645
- { op: "<", v: bound }
3646
- ];
3647
- }
3648
- case "~":
3649
- case "~>":
3650
- return [
3651
- { op: ">=", v: lo },
3652
- { op: "<", v: mi === null ? next("major") : next("minor") }
3653
- ];
3654
- case ">":
3655
- return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
3656
- case ">=":
3657
- return [{ op: ">=", v: lo }];
3658
- case "<":
3659
- return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
3660
- case "<=":
3661
- return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
3662
- default:
3663
- return upper ? [
3664
- { op: ">=", v: lo },
3665
- { op: "<", v: upper }
3666
- ] : [{ op: "=", v: lo }];
3667
- }
3668
- }
3669
- }
3670
- function test(c, v) {
3671
- const d = compareVersions(v, c.v);
3672
- return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
3673
- }
3674
- function parseRange(range) {
3675
- const alts = [];
3676
- for (const raw of range.trim().split("||")) {
3677
- const alt = raw.trim();
3678
- const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
3679
- if (hyphen) {
3680
- const from = comparators(`>=${hyphen[1]}`);
3681
- const to = comparators(`<=${hyphen[2]}`);
3682
- if (!from || !to) return null;
3683
- alts.push([...from, ...to]);
3684
- continue;
3685
- }
3686
- const set = [];
3687
- for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
3688
- const cs = comparators(token);
3689
- if (!cs) return null;
3690
- set.push(...cs);
3691
- }
3692
- alts.push(set);
3693
- }
3694
- return alts;
3695
- }
3696
- function satisfies(version, range) {
3697
- const v = parseVersion(version);
3698
- const alts = parseRange(range);
3699
- if (!v || !alts) return null;
3700
- return alts.some(
3701
- (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))
3702
- );
3703
- }
3704
3851
  var TRAIL_DEPTH = 6;
3705
3852
  var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
3706
3853
  var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
@@ -3874,14 +4021,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3874
4021
  seen.add(file);
3875
4022
  const json = readJsonc(file);
3876
4023
  if (!json) return {};
3877
- const dir = path19.dirname(file);
4024
+ const dir = path20.dirname(file);
3878
4025
  let merged = {};
3879
4026
  const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
3880
4027
  for (const ext of parents) {
3881
4028
  if (typeof ext !== "string") continue;
3882
4029
  let target = null;
3883
- if (ext.startsWith(".") || path19.isAbsolute(ext)) {
3884
- const abs = path19.resolve(dir, ext);
4030
+ if (ext.startsWith(".") || path20.isAbsolute(ext)) {
4031
+ const abs = path20.resolve(dir, ext);
3885
4032
  target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3886
4033
  } else {
3887
4034
  const parts = ext.split("/");
@@ -3889,14 +4036,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3889
4036
  const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
3890
4037
  if (pkgDir) {
3891
4038
  const sub = parts.slice(nameLength).join("/");
3892
- const abs = path19.join(pkgDir, sub || "tsconfig.json");
4039
+ const abs = path20.join(pkgDir, sub || "tsconfig.json");
3893
4040
  target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3894
4041
  }
3895
4042
  }
3896
4043
  if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
3897
4044
  }
3898
4045
  const opts = json.compilerOptions ?? {};
3899
- if (typeof opts.baseUrl === "string") merged.baseUrl = path19.resolve(dir, opts.baseUrl);
4046
+ if (typeof opts.baseUrl === "string") merged.baseUrl = path20.resolve(dir, opts.baseUrl);
3900
4047
  if (opts.paths && typeof opts.paths === "object") {
3901
4048
  merged.paths = opts.paths;
3902
4049
  merged.pathsDir = dir;
@@ -3907,7 +4054,7 @@ function aliases(root) {
3907
4054
  const table = [];
3908
4055
  let baseUrl = null;
3909
4056
  for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
3910
- const file = path19.join(root, name);
4057
+ const file = path20.join(root, name);
3911
4058
  if (!existsSync(file)) continue;
3912
4059
  const config = readTsconfig(root, file);
3913
4060
  baseUrl ??= config.baseUrl ?? null;
@@ -3915,22 +4062,22 @@ function aliases(root) {
3915
4062
  for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
3916
4063
  if (!Array.isArray(targets)) continue;
3917
4064
  const exact = !pattern.endsWith("*");
3918
- table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path19.join(base, String(t).replace(/\*$/, ""))) });
4065
+ table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path20.join(base, String(t).replace(/\*$/, ""))) });
3919
4066
  }
3920
4067
  }
3921
- const pkg = readJsonc(path19.join(root, "package.json"));
4068
+ const pkg = readJsonc(path20.join(root, "package.json"));
3922
4069
  for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
3923
4070
  if (typeof target !== "string") continue;
3924
- table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path19.join(root, target.replace(/\*.*$/, ""))] });
4071
+ table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path20.join(root, target.replace(/\*.*$/, ""))] });
3925
4072
  }
3926
- for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path19.join(root, "src") + path19.sep, root + path19.sep] });
4073
+ for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path20.join(root, "src") + path20.sep, root + path20.sep] });
3927
4074
  return { table, baseUrl };
3928
4075
  }
3929
4076
  function resolveFile(base) {
3930
- const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path19.join(base, `index${e}`))];
4077
+ const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path20.join(base, `index${e}`))];
3931
4078
  if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
3932
4079
  for (const p of tries) {
3933
- if (SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
4080
+ if (SCRIPT_EXTS2.has(path20.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
3934
4081
  }
3935
4082
  return null;
3936
4083
  }
@@ -3944,7 +4091,7 @@ function createTrail(ctx) {
3944
4091
  const { table, baseUrl } = aliases(ctx.root);
3945
4092
  let declared = null;
3946
4093
  try {
3947
- const pkg = JSON.parse(readFileSync(path19.join(ctx.root, "package.json"), "utf8"));
4094
+ const pkg = JSON.parse(readFileSync(path20.join(ctx.root, "package.json"), "utf8"));
3948
4095
  declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
3949
4096
  } catch {
3950
4097
  declared = null;
@@ -3975,17 +4122,17 @@ function createTrail(ctx) {
3975
4122
  if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
3976
4123
  let resolved = null;
3977
4124
  if (spec.startsWith(".")) {
3978
- resolved = resolveFile(path19.resolve(path19.dirname(file.absolutePath), spec));
4125
+ resolved = resolveFile(path20.resolve(path20.dirname(file.absolutePath), spec));
3979
4126
  if (!resolved) lost = true;
3980
4127
  } else {
3981
4128
  const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
3982
4129
  if (alias) {
3983
4130
  for (const t of alias.targets) {
3984
- resolved = resolveFile(alias.exact ? t : path19.join(t, spec.slice(alias.prefix.length)));
4131
+ resolved = resolveFile(alias.exact ? t : path20.join(t, spec.slice(alias.prefix.length)));
3985
4132
  if (resolved) break;
3986
4133
  }
3987
4134
  }
3988
- if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path19.join(baseUrl, spec));
4135
+ if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path20.join(baseUrl, spec));
3989
4136
  if (!resolved) {
3990
4137
  const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
3991
4138
  if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
@@ -4056,27 +4203,149 @@ function createTrail(ctx) {
4056
4203
  };
4057
4204
  return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
4058
4205
  }
4206
+ function buildCatalog(packagesDir) {
4207
+ const packages = {};
4208
+ for (const dir of readdirSync(packagesDir).sort()) {
4209
+ const file = path20.join(packagesDir, dir, "package.json");
4210
+ if (!existsSync(file)) continue;
4211
+ const pkg = JSON.parse(readFileSync(file, "utf8"));
4212
+ if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
4213
+ packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
4214
+ }
4215
+ return { packages };
4216
+ }
4059
4217
 
4060
4218
  // src/blocks/discover.ts
4219
+ var CLI_PACKAGE = "@marktiderman/genesis-cli";
4220
+ function cliPackageDir() {
4221
+ let dir = path20.dirname(fileURLToPath(import.meta.url));
4222
+ for (; ; ) {
4223
+ const file = path20.join(dir, "package.json");
4224
+ if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
4225
+ const parent = path20.dirname(dir);
4226
+ if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
4227
+ dir = parent;
4228
+ }
4229
+ }
4230
+ function workspacePackagesDir() {
4231
+ const dir = path20.resolve(cliPackageDir(), "..");
4232
+ return existsSync(path20.join(dir, "features", "package.json")) && existsSync(path20.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
4233
+ }
4234
+ var catalogCache;
4235
+ function readCatalog() {
4236
+ if (catalogCache) return catalogCache;
4237
+ const workspace = workspacePackagesDir();
4238
+ if (workspace) return catalogCache = buildCatalog(workspace);
4239
+ const file = path20.join(cliPackageDir(), "dist", "genesis-catalog.json");
4240
+ catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
4241
+ return catalogCache;
4242
+ }
4061
4243
  var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
4062
4244
  function installedGenesis(root) {
4063
4245
  const found = /* @__PURE__ */ new Map();
4064
- let dir = path19.resolve(root);
4246
+ let dir = path20.resolve(root);
4065
4247
  for (; ; ) {
4066
- const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path19.join(dir, m)));
4067
- const scope = path19.join(dir, "node_modules", "@marktiderman");
4248
+ const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path20.join(dir, m)));
4249
+ const scope = path20.join(dir, "node_modules", "@marktiderman");
4068
4250
  if (existsSync(scope)) {
4069
4251
  for (const entry of readdirSync(scope)) {
4070
4252
  const name = `@marktiderman/${entry}`;
4071
4253
  if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
4072
- if (existsSync(path19.join(scope, entry, "package.json"))) found.set(name, path19.join(scope, entry));
4254
+ if (existsSync(path20.join(scope, entry, "package.json"))) found.set(name, path20.join(scope, entry));
4073
4255
  }
4074
4256
  }
4075
- const parent = path19.dirname(dir);
4257
+ const parent = path20.dirname(dir);
4076
4258
  if (atInstallRoot || parent === dir) return found;
4077
4259
  dir = parent;
4078
4260
  }
4079
4261
  }
4262
+ var declarationCache = /* @__PURE__ */ new Map();
4263
+ function declarationsOf(dir, warnings) {
4264
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
4265
+ const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
4266
+ let cached = declarationCache.get(key2);
4267
+ if (!cached) {
4268
+ cached = loadDeclarations(dir, warnings);
4269
+ declarationCache.set(key2, cached);
4270
+ }
4271
+ return cached;
4272
+ }
4273
+ async function loadDeclarations(dir, warnings) {
4274
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
4275
+ const entry = pkg.exports?.["./blocks"];
4276
+ const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
4277
+ if (typeof target !== "string") return {};
4278
+ const rel = safeRelative(target.replace(/^\.\//, ""));
4279
+ const file = rel && path20.join(dir, ...rel.split("/"));
4280
+ if (!file || !inside(dir, file) || !existsSync(file)) return {};
4281
+ try {
4282
+ const jiti = createJiti(path20.join(dir, "package.json"), { moduleCache: false });
4283
+ const mod = await jiti.import(file);
4284
+ const out = {};
4285
+ for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
4286
+ return out;
4287
+ } catch (err) {
4288
+ 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.`);
4289
+ return {};
4290
+ }
4291
+ }
4292
+ async function blocksOfInstalled(dir, warnings = [], options = {}) {
4293
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
4294
+ const raw = rawBlocksOf(pkg);
4295
+ const declared = await declarationsOf(dir, warnings);
4296
+ const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
4297
+ const out = [];
4298
+ for (const id of [...ids].sort()) {
4299
+ const fromJson = raw[id] ?? {};
4300
+ const manifest = tryParse(() => parseManifest(pkg.name, id, { ...fromJson, ...declared[id] }, pkg.version, options), warnings);
4301
+ if (manifest) out.push(manifest);
4302
+ }
4303
+ return out;
4304
+ }
4305
+ async function allBlocks(root, warnings = []) {
4306
+ const out = [];
4307
+ for (const local of localPackages(root)) {
4308
+ for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
4309
+ }
4310
+ const installed = installedGenesis(root);
4311
+ for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
4312
+ for (const [name, entry] of Object.entries(readCatalog().packages)) {
4313
+ if (installed.has(name)) continue;
4314
+ for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
4315
+ const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
4316
+ if (manifest) out.push({ manifest, from: "catalog" });
4317
+ }
4318
+ }
4319
+ return out;
4320
+ }
4321
+ function tryParse(parse2, warnings) {
4322
+ try {
4323
+ return parse2();
4324
+ } catch (err) {
4325
+ if (!(err instanceof ManifestError)) throw err;
4326
+ warnings.push(err.message);
4327
+ return null;
4328
+ }
4329
+ }
4330
+ function catalogBlocks(warnings = []) {
4331
+ const out = [];
4332
+ for (const [name, entry] of Object.entries(readCatalog().packages)) {
4333
+ for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
4334
+ const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
4335
+ if (manifest) out.push(manifest);
4336
+ }
4337
+ }
4338
+ return out;
4339
+ }
4340
+ async function findBlock(root, id, options = {}) {
4341
+ const all = (await allBlocks(root, options.warnings)).filter((b) => b.manifest.id === id && (!options.package || b.manifest.package === options.package));
4342
+ if (all.length === 0) {
4343
+ const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
4344
+ throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
4345
+ }
4346
+ if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
4347
+ return all[0];
4348
+ }
4080
4349
  var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
4081
4350
  var STEMS = {
4082
4351
  tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
@@ -4094,7 +4363,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
4094
4363
  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;
4095
4364
  function routesDir(ctx) {
4096
4365
  if (ctx.config.routesDir) return ctx.config.routesDir;
4097
- return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path19.join(ctx.root, d))) ?? null;
4366
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path20.join(ctx.root, d))) ?? null;
4098
4367
  }
4099
4368
  var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
4100
4369
  function flavorOf(dir, rels) {
@@ -4229,7 +4498,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
4229
4498
  });
4230
4499
  if (typeof raw === "string") {
4231
4500
  if (!packageDir) fail(`points at ${raw}, but the package folder is unknown`);
4232
- const file = path19.resolve(packageDir, raw);
4501
+ const file = path20.resolve(packageDir, raw);
4233
4502
  if (!inside(packageDir, file)) fail(`points outside the package (${raw})`);
4234
4503
  if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
4235
4504
  let parsed;
@@ -4278,7 +4547,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
4278
4547
  if (typeof c.plugin === "string") {
4279
4548
  if (!packageDir) plugin = c.plugin;
4280
4549
  else {
4281
- plugin = path19.resolve(packageDir, c.plugin);
4550
+ plugin = path20.resolve(packageDir, c.plugin);
4282
4551
  if (!inside(packageDir, plugin)) fail(`plugin points outside the package (${c.plugin})`);
4283
4552
  }
4284
4553
  }
@@ -4328,7 +4597,7 @@ function checkPattern(v, where2, fail) {
4328
4597
  }
4329
4598
  var discoveryCache = /* @__PURE__ */ new Map();
4330
4599
  function readDeclaringPackage(dir, local) {
4331
- const file = path19.join(dir, "package.json");
4600
+ const file = path20.join(dir, "package.json");
4332
4601
  let stamp;
4333
4602
  let real2;
4334
4603
  try {
@@ -4351,7 +4620,7 @@ ${local}`;
4351
4620
  const pkg = {
4352
4621
  name: json.name,
4353
4622
  version: typeof json.version === "string" ? json.version : "0.0.0",
4354
- dir: path19.resolve(dir),
4623
+ dir: path20.resolve(dir),
4355
4624
  namespace: ruleNamespace(json.name),
4356
4625
  local,
4357
4626
  private: json.private === true,
@@ -4365,7 +4634,7 @@ ${local}`;
4365
4634
  if (raw !== void 0) {
4366
4635
  const ignored = [];
4367
4636
  try {
4368
- pkg.declaration = validateDeclaration(raw, json.name, path19.resolve(dir), ignored);
4637
+ pkg.declaration = validateDeclaration(raw, json.name, path20.resolve(dir), ignored);
4369
4638
  if (ignored.length) pkg.ignored = ignored;
4370
4639
  } catch (err) {
4371
4640
  pkg.error = err.message;
@@ -4384,14 +4653,14 @@ function discoverPackages(root) {
4384
4653
  for (const dir of installed) {
4385
4654
  let scope;
4386
4655
  try {
4387
- scope = path19.dirname(realpathSync(dir));
4656
+ scope = path20.dirname(realpathSync(dir));
4388
4657
  } catch {
4389
4658
  continue;
4390
4659
  }
4391
- if (path19.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
4660
+ if (path20.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
4392
4661
  for (const entry of readdirSync(scope)) {
4393
4662
  if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
4394
- const pkg = readDeclaringPackage(path19.join(scope, entry), false);
4663
+ const pkg = readDeclaringPackage(path20.join(scope, entry), false);
4395
4664
  if (pkg) byName.set(pkg.name, pkg);
4396
4665
  }
4397
4666
  }
@@ -4575,10 +4844,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
4575
4844
  var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
4576
4845
  function sourceFiles(dir, rel = "") {
4577
4846
  const out = [];
4578
- for (const entry of readdirSync(path19.join(dir, rel)).sort()) {
4847
+ for (const entry of readdirSync(path20.join(dir, rel)).sort()) {
4579
4848
  if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
4580
4849
  const child = rel ? `${rel}/${entry}` : entry;
4581
- const stat = lstatSync(path19.join(dir, child));
4850
+ const stat = lstatSync(path20.join(dir, child));
4582
4851
  if (stat.isSymbolicLink()) continue;
4583
4852
  if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
4584
4853
  else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
@@ -4601,13 +4870,13 @@ function matchPattern(pattern, spec) {
4601
4870
  return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
4602
4871
  }
4603
4872
  function tsconfigPaths(dir) {
4604
- const file = path19.join(dir, "tsconfig.json");
4873
+ const file = path20.join(dir, "tsconfig.json");
4605
4874
  if (!existsSync(file)) return [];
4606
4875
  try {
4607
4876
  const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
4608
4877
  const options = JSON.parse(text).compilerOptions ?? {};
4609
- const base = path19.resolve(dir, options.baseUrl ?? ".");
4610
- return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path19.resolve(base, t)) }));
4878
+ const base = path20.resolve(dir, options.baseUrl ?? ".");
4879
+ return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path20.resolve(base, t)) }));
4611
4880
  } catch {
4612
4881
  return [];
4613
4882
  }
@@ -4621,8 +4890,8 @@ function checkImports2(ctx, pkg, json) {
4621
4890
  const hit = matchPattern(pattern, spec);
4622
4891
  if (hit === null) continue;
4623
4892
  return targets.some((t) => {
4624
- const rel = path19.relative(pkg.dir, t.replace("*", hit));
4625
- return !rel.startsWith("..") && !path19.isAbsolute(rel);
4893
+ const rel = path20.relative(pkg.dir, t.replace("*", hit));
4894
+ return !rel.startsWith("..") && !path20.isAbsolute(rel);
4626
4895
  });
4627
4896
  }
4628
4897
  return null;
@@ -4635,7 +4904,7 @@ function checkImports2(ctx, pkg, json) {
4635
4904
  ...Object.keys(json.optionalDependencies ?? {})
4636
4905
  ]);
4637
4906
  for (const file of sourceFiles(pkg.dir)) {
4638
- const code = stripForImports(readFileSync(path19.join(pkg.dir, file), "utf8"));
4907
+ const code = stripForImports(readFileSync(path20.join(pkg.dir, file), "utf8"));
4639
4908
  if (code === null) continue;
4640
4909
  const at = `${pkg.rel}/${file}`;
4641
4910
  const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
@@ -4660,9 +4929,9 @@ function checkImports2(ctx, pkg, json) {
4660
4929
  continue;
4661
4930
  }
4662
4931
  if (spec.startsWith(".")) {
4663
- const target = path19.resolve(pkg.dir, path19.dirname(file), spec);
4664
- const rel = path19.relative(pkg.dir, target);
4665
- if (rel.startsWith("..") || path19.isAbsolute(rel)) {
4932
+ const target = path20.resolve(pkg.dir, path20.dirname(file), spec);
4933
+ const rel = path20.relative(pkg.dir, target);
4934
+ if (rel.startsWith("..") || path20.isAbsolute(rel)) {
4666
4935
  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` });
4667
4936
  }
4668
4937
  continue;
@@ -4699,12 +4968,12 @@ function checkMigrations(ctx, pkg, json, locals) {
4699
4968
  const from = own ? "" : ` (in ${m.package})`;
4700
4969
  if (typeof m.file === "string" && typeof m.test !== "string") {
4701
4970
  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` });
4702
- } else if (typeof m.test === "string" && !existsSync(path19.join(home, m.test))) {
4971
+ } else if (typeof m.test === "string" && !existsSync(path20.join(home, m.test))) {
4703
4972
  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` });
4704
4973
  }
4705
4974
  }
4706
4975
  }
4707
- const dir = path19.join(pkg.dir, "migrations");
4976
+ const dir = path20.join(pkg.dir, "migrations");
4708
4977
  if (!existsSync(dir)) return;
4709
4978
  const seen = /* @__PURE__ */ new Map();
4710
4979
  for (const name of readdirSync(dir).sort()) {
@@ -4713,21 +4982,21 @@ function checkMigrations(ctx, pkg, json, locals) {
4713
4982
  const other = seen.get(m[1]);
4714
4983
  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` });
4715
4984
  else seen.set(m[1], name);
4716
- if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path19.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
4985
+ if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path20.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
4717
4986
  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")})` });
4718
4987
  }
4719
4988
  }
4720
4989
  }
4721
4990
  function checkExports(ctx, pkg, json) {
4722
4991
  const targets = [];
4723
- const walk = (v) => {
4992
+ const walk2 = (v) => {
4724
4993
  if (typeof v === "string") targets.push(v);
4725
- else if (v && typeof v === "object") for (const x of Object.values(v)) walk(x);
4994
+ else if (v && typeof v === "object") for (const x of Object.values(v)) walk2(x);
4726
4995
  };
4727
- walk(json.exports);
4996
+ walk2(json.exports);
4728
4997
  for (const t of targets) {
4729
4998
  if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
4730
- if (!existsSync(path19.join(pkg.dir, t))) {
4999
+ if (!existsSync(path20.join(pkg.dir, t))) {
4731
5000
  ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
4732
5001
  }
4733
5002
  }
@@ -4745,11 +5014,11 @@ function checkBlocks(ctx, pkg, json) {
4745
5014
  function checkTaggedTests(ctx, pkg) {
4746
5015
  const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
4747
5016
  if (!tests.length) return;
4748
- const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path19.join(pkg.dir, f), "utf8")));
5017
+ const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path20.join(pkg.dir, f), "utf8")));
4749
5018
  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>` });
4750
5019
  }
4751
5020
  function checkRegistered(ctx, pkg) {
4752
- const file = path19.join(ctx.root, "features.json");
5021
+ const file = path20.join(ctx.root, "features.json");
4753
5022
  if (!existsSync(file)) return;
4754
5023
  let doc;
4755
5024
  try {
@@ -4759,7 +5028,7 @@ function checkRegistered(ctx, pkg) {
4759
5028
  }
4760
5029
  const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
4761
5030
  const forms = /* @__PURE__ */ new Set([pkg.rel]);
4762
- if (top) forms.add(path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/"));
5031
+ if (top) forms.add(path20.relative(top, realpathSync(pkg.dir)).split(path20.sep).join("/"));
4763
5032
  const covered = (doc.features ?? []).some(
4764
5033
  (f) => (f.links?.code ?? []).some((c) => {
4765
5034
  const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
@@ -4789,8 +5058,8 @@ function mergeBaseOf(root, base) {
4789
5058
  function checkChanges(ctx, pkg, json, base, mergeBase) {
4790
5059
  const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
4791
5060
  if (!top) return;
4792
- const appRelative = (fromTop) => path19.relative(realpathSync(ctx.root), path19.join(top, fromTop)).split(path19.sep).join("/");
4793
- const inRepo = path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/");
5061
+ const appRelative = (fromTop) => path20.relative(realpathSync(ctx.root), path20.join(top, fromTop)).split(path20.sep).join("/");
5062
+ const inRepo = path20.relative(top, realpathSync(pkg.dir)).split(path20.sep).join("/");
4794
5063
  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");
4795
5064
  const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
4796
5065
  const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
@@ -4813,11 +5082,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
4813
5082
  const now = typeof json.version === "string" ? parseVersion(json.version) : null;
4814
5083
  const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
4815
5084
  const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
4816
- 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)) : [];
5085
+ 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)) : [];
4817
5086
  const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
4818
5087
  const named = naming.length > 0;
4819
5088
  if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
4820
- 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` });
5089
+ 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` });
4821
5090
  }
4822
5091
  let jsonBefore = null;
4823
5092
  try {
@@ -4827,7 +5096,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
4827
5096
  }
4828
5097
  const raw = json;
4829
5098
  if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
4830
- const appInRepo = path19.relative(top, realpathSync(ctx.root)).split(path19.sep).join("/");
5099
+ const appInRepo = path20.relative(top, realpathSync(ctx.root)).split(path20.sep).join("/");
4831
5100
  const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
4832
5101
  const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
4833
5102
  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` });
@@ -4879,7 +5148,7 @@ function checkPackagesPack(ctx) {
4879
5148
  ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
4880
5149
  }
4881
5150
  for (const pkg of packages) {
4882
- const json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
5151
+ const json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
4883
5152
  checkImports2(ctx, pkg, json);
4884
5153
  checkExports(ctx, pkg, json);
4885
5154
  checkBlocks(ctx, pkg, json);
@@ -5073,9 +5342,9 @@ function gitView(root, dir, base) {
5073
5342
  function checkSupabasePack(ctx) {
5074
5343
  const settings = ctx.config.supabase ?? {};
5075
5344
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
5076
- const abs = path19.join(ctx.root, dir);
5345
+ const abs = path20.join(ctx.root, dir);
5077
5346
  if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
5078
- const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path19.join(abs, n), "utf8")) }));
5347
+ const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path20.join(abs, n), "utf8")) }));
5079
5348
  const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
5080
5349
  const base = settings.base ?? DEFAULT_BASE;
5081
5350
  const view = gitView(ctx.root, dir, base);
@@ -5092,7 +5361,7 @@ function checkSupabasePack(ctx) {
5092
5361
  }
5093
5362
  }
5094
5363
  const since = settings.since;
5095
- const afterSince = (file) => since === void 0 || path19.posix.basename(file) >= since;
5364
+ const afterSince = (file) => since === void 0 || path20.posix.basename(file) >= since;
5096
5365
  if ("reason" in view && since === void 0) {
5097
5366
  ctx.report({
5098
5367
  rule: "migration-grants",
@@ -5370,51 +5639,12 @@ function checkDefinerSearchPath(ctx, migrations) {
5370
5639
  });
5371
5640
  }
5372
5641
  }
5373
- var UMBRELLA_PACKAGE = "@marktiderman/genesis";
5374
- function readReleaseManifest(root) {
5375
- const dir = findPackageDir(root, UMBRELLA_PACKAGE);
5376
- const file = dir && path19.join(dir, "dist", "versions.json");
5377
- if (!file || !existsSync(file)) return null;
5378
- return JSON.parse(readFileSync(file, "utf8"));
5379
- }
5380
- function checkVersionSkew(ctx) {
5381
- const manifest = readReleaseManifest(ctx.root);
5382
- if (!manifest) return;
5383
- const overlays = markedOverlays(ctx);
5384
- for (const [name, want] of Object.entries(manifest.packages)) {
5385
- const overlay = overlays.get(name);
5386
- if (overlay) {
5387
- const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
5388
- if (from !== want) {
5389
- ctx.report({
5390
- rule: "version-skew",
5391
- level: "warn",
5392
- file: "package.json",
5393
- subject: name,
5394
- 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).`
5395
- });
5396
- }
5397
- continue;
5398
- }
5399
- const dir = findPackageDir(ctx.root, name);
5400
- if (!dir) continue;
5401
- const have = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8")).version;
5402
- if (have === want) continue;
5403
- ctx.report({
5404
- rule: "version-skew",
5405
- level: "warn",
5406
- file: "package.json",
5407
- subject: name,
5408
- message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
5409
- });
5410
- }
5411
- }
5412
5642
  var GENESIS2 = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
5413
5643
  var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
5414
5644
  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)$/;
5415
5645
  var readManifest = (dir) => {
5416
5646
  try {
5417
- return JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
5647
+ return JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
5418
5648
  } catch {
5419
5649
  return null;
5420
5650
  }
@@ -5428,18 +5658,18 @@ var real = (p) => {
5428
5658
  };
5429
5659
  var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
5430
5660
  function nodeModulesOf(dir) {
5431
- const parent = path19.dirname(dir);
5432
- return path19.basename(parent).startsWith("@") ? path19.dirname(parent) : parent;
5661
+ const parent = path20.dirname(dir);
5662
+ return path20.basename(parent).startsWith("@") ? path20.dirname(parent) : parent;
5433
5663
  }
5434
5664
  function packagesIn(nodeModules) {
5435
5665
  if (!existsSync(nodeModules)) return [];
5436
5666
  const out = [];
5437
5667
  for (const entry of readdirSync(nodeModules)) {
5438
5668
  if (entry.startsWith(".")) continue;
5439
- const p = path19.join(nodeModules, entry);
5669
+ const p = path20.join(nodeModules, entry);
5440
5670
  if (entry.startsWith("@")) {
5441
5671
  try {
5442
- for (const sub of readdirSync(p)) out.push(path19.join(p, sub));
5672
+ for (const sub of readdirSync(p)) out.push(path20.join(p, sub));
5443
5673
  } catch {
5444
5674
  }
5445
5675
  } else {
@@ -5451,7 +5681,7 @@ function packagesIn(nodeModules) {
5451
5681
  function genesisInstalls(root) {
5452
5682
  const copies = /* @__PURE__ */ new Map();
5453
5683
  const realRoot = real(root);
5454
- const rel = (abs) => path19.relative(realRoot, abs).split(path19.sep).join("/") || ".";
5684
+ const rel = (abs) => path20.relative(realRoot, abs).split(path20.sep).join("/") || ".";
5455
5685
  const via = /* @__PURE__ */ new Map();
5456
5686
  const record = (real2, manifest, by, range, root2) => {
5457
5687
  let copy = copies.get(real2);
@@ -5463,7 +5693,7 @@ function genesisInstalls(root) {
5463
5693
  via.get(real2).add(root2);
5464
5694
  if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
5465
5695
  };
5466
- const walk = (kind, roots) => {
5696
+ const walk2 = (kind, roots) => {
5467
5697
  const expanded = /* @__PURE__ */ new Set();
5468
5698
  const queue = [];
5469
5699
  const visit = (dir, by, range) => {
@@ -5496,7 +5726,7 @@ function genesisInstalls(root) {
5496
5726
  if (!dir) return null;
5497
5727
  if (!ownInstall || name in declared) return dir;
5498
5728
  const realDir = real(dir);
5499
- if (realDir.startsWith(realRoot + path19.sep)) return dir;
5729
+ if (realDir.startsWith(realRoot + path20.sep)) return dir;
5500
5730
  return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
5501
5731
  };
5502
5732
  const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
@@ -5504,7 +5734,7 @@ function genesisInstalls(root) {
5504
5734
  return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
5505
5735
  });
5506
5736
  const app = readManifest(root);
5507
- const ownInstall = LOCKFILES.some((f) => existsSync(path19.join(root, f)));
5737
+ const ownInstall = LOCKFILES.some((f) => existsSync(path20.join(root, f)));
5508
5738
  const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
5509
5739
  const declaredDev = Object.entries(app?.devDependencies ?? {});
5510
5740
  const runtimeDeps = {
@@ -5514,18 +5744,18 @@ function genesisInstalls(root) {
5514
5744
  ...app?.dependencies
5515
5745
  };
5516
5746
  const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
5517
- walk("runtime", rootsOf(runtimeDeps, "the app"));
5518
- const top = path19.join(root, "node_modules");
5519
- walk(
5747
+ walk2("runtime", rootsOf(runtimeDeps, "the app"));
5748
+ const top = path20.join(root, "node_modules");
5749
+ walk2(
5520
5750
  "hoisted",
5521
5751
  packagesIn(top).filter((dir) => {
5522
- const name = path19.relative(top, dir).split(path19.sep).join("/");
5752
+ const name = path20.relative(top, dir).split(path20.sep).join("/");
5523
5753
  return !(name in runtimeDeps) && !(name in devDeps);
5524
5754
  }).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
5525
5755
  );
5526
5756
  const devRoots = { ...devDeps };
5527
5757
  for (const tool of DEV_TOOLS) if (!(tool in devRoots) && tool in runtimeDeps) devRoots[tool] = runtimeDeps[tool];
5528
- walk("dev", rootsOf(devRoots, "the app (dev)"));
5758
+ walk2("dev", rootsOf(devRoots, "the app (dev)"));
5529
5759
  for (const [key2, copy] of copies) {
5530
5760
  const kinds = via.get(key2);
5531
5761
  copy.runtime = kinds.has("runtime");
@@ -5561,7 +5791,7 @@ function checkDuplicatePackages(ctx) {
5561
5791
  }
5562
5792
  }
5563
5793
  function checkPeerRanges(ctx) {
5564
- const rel = (abs) => path19.relative(ctx.root, abs).split(path19.sep).join("/");
5794
+ const rel = (abs) => path20.relative(ctx.root, abs).split(path20.sep).join("/");
5565
5795
  for (const copies of genesisInstalls(ctx.root).values()) {
5566
5796
  for (const copy of copies) {
5567
5797
  const dir = copy.absolutePath;
@@ -5943,17 +6173,17 @@ var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
5943
6173
  var MAX_BYTES = 2 * 1024 * 1024;
5944
6174
  function appScripts(root) {
5945
6175
  const out = [];
5946
- const walk = (dir) => {
6176
+ const walk2 = (dir) => {
5947
6177
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
5948
- const abs = path19.join(dir, entry.name);
6178
+ const abs = path20.join(dir, entry.name);
5949
6179
  if (entry.isDirectory()) {
5950
- if (!SKIP_DIRS3.has(entry.name)) walk(abs);
6180
+ if (!SKIP_DIRS3.has(entry.name)) walk2(abs);
5951
6181
  } else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
5952
- out.push(path19.relative(root, abs).split(path19.sep).join("/"));
6182
+ out.push(path20.relative(root, abs).split(path20.sep).join("/"));
5953
6183
  }
5954
6184
  }
5955
6185
  };
5956
- walk(root);
6186
+ walk2(root);
5957
6187
  return out;
5958
6188
  }
5959
6189
 
@@ -6037,7 +6267,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
6037
6267
  function moduleFiles(ctx) {
6038
6268
  const scanned = new Set(ctx.files.map((f) => f.path));
6039
6269
  const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
6040
- 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) }));
6270
+ 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) }));
6041
6271
  return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
6042
6272
  }
6043
6273
  function checkStudioServerImports(ctx) {
@@ -6073,7 +6303,7 @@ var REMOVED_WORDS = {
6073
6303
  };
6074
6304
  function checkRemovedScopeNames(ctx) {
6075
6305
  let augmentedMemo;
6076
- 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")));
6306
+ 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")));
6077
6307
  for (const file of ctx.files) {
6078
6308
  if (!SCRIPT_EXTS5.has(file.ext)) continue;
6079
6309
  for (const hit of findRemovedScopeNames(file.code)) {
@@ -6145,16 +6375,16 @@ function genesisNamedImports(source) {
6145
6375
  }
6146
6376
  function declarationFiles(dir, out = []) {
6147
6377
  for (const name of readdirSync(dir)) {
6148
- const full = path19.join(dir, name);
6378
+ const full = path20.join(dir, name);
6149
6379
  if (statSync(full).isDirectory()) declarationFiles(full, out);
6150
6380
  else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
6151
6381
  }
6152
6382
  return out;
6153
6383
  }
6154
6384
  function readPackageTags(dir) {
6155
- const pkg = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
6385
+ const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
6156
6386
  const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
6157
- const dist = path19.join(dir, "dist");
6387
+ const dist = path20.join(dir, "dist");
6158
6388
  if (!existsSync(dist)) return tags;
6159
6389
  for (const file of declarationFiles(dist)) {
6160
6390
  const text = readFileSync(file, "utf8");
@@ -6172,7 +6402,7 @@ function entryFile(tags, pkg, specifier) {
6172
6402
  const subpath = `.${specifier.slice(pkg.length)}` || ".";
6173
6403
  const target = tags.exports[subpath === "." ? "." : subpath];
6174
6404
  const types = typeof target === "object" && target ? target.types : null;
6175
- return typeof types === "string" ? path19.join(tags.dir, types) : null;
6405
+ return typeof types === "string" ? path20.join(tags.dir, types) : null;
6176
6406
  }
6177
6407
  function tagFor(tags, entry, name) {
6178
6408
  if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
@@ -6227,7 +6457,7 @@ function showAt(dir, rev, file) {
6227
6457
  function configAtBase(root, base, explicitFile) {
6228
6458
  const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
6229
6459
  if (!mergeBase) return null;
6230
- const candidates = explicitFile ? [{ dir: path19.dirname(explicitFile), file: path19.basename(explicitFile), explicit: true }] : [
6460
+ const candidates = explicitFile ? [{ dir: path20.dirname(explicitFile), file: path20.basename(explicitFile), explicit: true }] : [
6231
6461
  { dir: root, file: "genesis.config.json", explicit: false },
6232
6462
  { dir: root, file: "package.json", explicit: false }
6233
6463
  ];
@@ -6339,7 +6569,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
6339
6569
  const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
6340
6570
  let current = null;
6341
6571
  try {
6342
- current = lf(readFileSync(path19.join(ctx.root, out), "utf8"));
6572
+ current = lf(readFileSync(path20.join(ctx.root, out), "utf8"));
6343
6573
  } catch {
6344
6574
  current = null;
6345
6575
  }
@@ -6363,7 +6593,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
6363
6593
  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}` });
6364
6594
  return;
6365
6595
  }
6366
- const target = path19.relative(process.cwd(), path19.join(ctx.root, out)) || out;
6596
+ const target = path20.relative(process.cwd(), path20.join(ctx.root, out)) || out;
6367
6597
  const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
6368
6598
  if (current !== expected) {
6369
6599
  ctx.report({
@@ -6506,8 +6736,8 @@ function currentAgentsBlock(agents) {
6506
6736
  var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
6507
6737
  function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
6508
6738
  const rows = primitivesCatalog(packages);
6509
- const skill = read(path19.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
6510
- const block = currentAgentsBlock(read(path19.join(root, agentsFile)));
6739
+ const skill = read(path20.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
6740
+ const block = currentAgentsBlock(read(path20.join(root, agentsFile)));
6511
6741
  return {
6512
6742
  skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
6513
6743
  agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
@@ -6529,9 +6759,227 @@ function checkAgentGuide(ctx) {
6529
6759
  ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
6530
6760
  }
6531
6761
  }
6762
+ var LOCK_FILE = "genesis.lock.json";
6763
+ function emptyLock() {
6764
+ return { version: 1, blocks: {}, files: {} };
6765
+ }
6766
+ function readLock(root) {
6767
+ const file = path20.join(root, LOCK_FILE);
6768
+ if (!existsSync(file)) return emptyLock();
6769
+ const raw = JSON.parse(readFileSync(file, "utf8"));
6770
+ if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
6771
+ return {
6772
+ version: 1,
6773
+ ...raw.substitutions ? { substitutions: raw.substitutions } : {},
6774
+ blocks: raw.blocks ?? {},
6775
+ files: raw.files ?? {},
6776
+ ...raw.migrations ? { migrations: raw.migrations } : {}
6777
+ };
6778
+ }
6779
+ function parseSource(source) {
6780
+ const at = source.indexOf(":");
6781
+ if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
6782
+ return { package: source.slice(0, at), path: source.slice(at + 1) };
6783
+ }
6784
+ var CLI = "@marktiderman/genesis-cli";
6785
+ function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
6786
+ let parsed;
6787
+ try {
6788
+ parsed = parseSource(source);
6789
+ } catch (err) {
6790
+ return err instanceof Error ? err.message : String(err);
6791
+ }
6792
+ const { package: pkg, path: rel } = parsed;
6793
+ if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
6794
+ if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
6795
+ if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
6796
+ const base = rel.split("/").pop();
6797
+ if (pkg === CLI && rel.startsWith("templates/")) {
6798
+ return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
6799
+ }
6800
+ const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
6801
+ if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
6802
+ if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
6803
+ if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
6804
+ return `${key2} doesn't match its source ${source}`;
6805
+ }
6806
+
6807
+ // src/blocks/templates.ts
6808
+ function starterDir() {
6809
+ const workspace = workspacePackagesDir();
6810
+ const live = workspace && path20.join(workspace, "..", "apps", "genesis-rn-starter");
6811
+ if (live && existsSync(path20.join(live, "package.json"))) return live;
6812
+ const packaged = path20.join(cliPackageDir(), "dist", "starter");
6813
+ if (existsSync(path20.join(packaged, "package.json"))) return packaged;
6814
+ throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
6815
+ }
6816
+
6817
+ // src/blocks/starter-features.ts
6818
+ var STARTER_CONFIG = "starter.config.ts";
6819
+ var GENESIS_CONFIG = "genesis.config.json";
6820
+ var SWITCH = /^[a-zA-Z][a-zA-Z0-9]*$/;
6821
+ var BLOCK_ID2 = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
6822
+ function featuresBody(text) {
6823
+ const m = /\bfeatures:\s*\{/.exec(text);
6824
+ if (!m) return null;
6825
+ const start = m.index + m[0].length;
6826
+ const end = text.indexOf("}", start);
6827
+ return end < 0 ? null : { start, body: text.slice(start, end) };
6828
+ }
6829
+ function parseStarterFeatures(text) {
6830
+ const found = featuresBody(text);
6831
+ if (!found) return null;
6832
+ const out = {};
6833
+ for (const line of found.body.split("\n")) {
6834
+ const m = /^\s*([a-zA-Z][a-zA-Z0-9]*)\s*:\s*(true|false)\s*,?\s*(?:\/\/.*)?$/.exec(line);
6835
+ if (m) out[m[1]] = m[2] === "true";
6836
+ }
6837
+ return out;
6838
+ }
6839
+ function parseStarterBlocks(json, source = GENESIS_CONFIG) {
6840
+ let raw;
6841
+ try {
6842
+ raw = JSON.parse(json);
6843
+ } catch (err) {
6844
+ throw new Error(`${source} is not valid JSON: ${err.message}`);
6845
+ }
6846
+ const starter = raw?.starter;
6847
+ if (starter === void 0) return null;
6848
+ const blocks = starter?.blocks;
6849
+ 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`);
6850
+ const out = {};
6851
+ for (const [name, ids] of Object.entries(blocks)) {
6852
+ if (name === "$comment") continue;
6853
+ if (!SWITCH.test(name) || !Array.isArray(ids) || !ids.every((id) => typeof id === "string" && BLOCK_ID2.test(id))) {
6854
+ throw new Error(`${source}: starter.blocks.${name} must be a list of block ids`);
6855
+ }
6856
+ out[name] = ids;
6857
+ }
6858
+ return out;
6859
+ }
6860
+ function readText(file) {
6861
+ try {
6862
+ return readFileSync(file, "utf8");
6863
+ } catch {
6864
+ return null;
6865
+ }
6866
+ }
6867
+ function starterBlockMap(root) {
6868
+ if (root) {
6869
+ const file = path20.join(root, GENESIS_CONFIG);
6870
+ const text2 = readText(file);
6871
+ const own = text2 === null ? null : parseStarterBlocks(text2, file);
6872
+ if (own) return own;
6873
+ }
6874
+ let dir;
6875
+ try {
6876
+ dir = starterDir();
6877
+ } catch {
6878
+ return {};
6879
+ }
6880
+ const text = readText(path20.join(dir, GENESIS_CONFIG));
6881
+ return (text === null ? null : parseStarterBlocks(text)) ?? {};
6882
+ }
6883
+ function blocksSwitchedOff(switches, map, manifests, present) {
6884
+ const ids = new Set(present);
6885
+ const off = /* @__PURE__ */ new Map();
6886
+ for (const [name, carried] of Object.entries(map)) if (switches[name] === false) {
6887
+ for (const id of carried) if (ids.has(id)) off.set(id, name);
6888
+ }
6889
+ const requires = new Map(manifests.map((m) => [m.id, m.requires]));
6890
+ const keep = [...ids].filter((id) => !off.has(id));
6891
+ for (let i = 0; i < keep.length; i++) {
6892
+ for (const r of requires.get(keep[i]) ?? []) {
6893
+ off.delete(r);
6894
+ if (!keep.includes(r)) keep.push(r);
6895
+ }
6896
+ }
6897
+ return off;
6898
+ }
6899
+ function appBlocksSwitchedOff(root, manifests, present) {
6900
+ const text = readText(path20.join(root, STARTER_CONFIG));
6901
+ const switches = text === null ? null : parseStarterFeatures(text);
6902
+ if (!switches) return /* @__PURE__ */ new Map();
6903
+ return blocksSwitchedOff(switches, starterBlockMap(existsSync(path20.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
6904
+ }
6905
+ function blockOfSource(source, manifests) {
6906
+ const at = source.indexOf(":");
6907
+ if (at < 1) return null;
6908
+ const pkg = source.slice(0, at);
6909
+ const rel = source.slice(at + 1);
6910
+ for (const m of manifests) {
6911
+ if (m.functions.some((fn) => fn.package === pkg && rel.startsWith(`${fn.dir}/`))) return m.id;
6912
+ if (m.migrations.some((mig) => mig.package === pkg && mig.test === rel)) return m.id;
6913
+ }
6914
+ return null;
6915
+ }
6916
+
6917
+ // src/doctor/lock-files.ts
6918
+ async function checkLockFiles(ctx) {
6919
+ if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
6920
+ let lock;
6921
+ try {
6922
+ lock = readLock(ctx.root);
6923
+ } catch (err) {
6924
+ 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` });
6925
+ return;
6926
+ }
6927
+ const catalog = catalogBlocks();
6928
+ const off = appBlocksSwitchedOff(ctx.root, catalog, Object.keys(lock.blocks));
6929
+ const offManifests = [];
6930
+ for (const [id, entry] of Object.entries(lock.blocks)) {
6931
+ const feature = off.get(id);
6932
+ if (!feature) continue;
6933
+ try {
6934
+ offManifests.push((await findBlock(ctx.root, id, { package: entry.package })).manifest);
6935
+ } catch {
6936
+ offManifests.push(...catalog.filter((m) => m.id === id));
6937
+ }
6938
+ ctx.report({
6939
+ rule: "lock-files",
6940
+ level: "info",
6941
+ file: LOCK_FILE,
6942
+ subject: id,
6943
+ 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)`
6944
+ });
6945
+ }
6946
+ const local = localPackageNames(ctx.root);
6947
+ for (const [rel, entry] of Object.entries(lock.files)) {
6948
+ if (ownedKeyProblem(rel, entry.source, local)) continue;
6949
+ if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
6950
+ let text;
6951
+ try {
6952
+ text = readApp(ctx.root, rel);
6953
+ } catch {
6954
+ continue;
6955
+ }
6956
+ if (text === null) {
6957
+ if (entry.deleted) continue;
6958
+ ctx.report({
6959
+ rule: "lock-files",
6960
+ level: "warn",
6961
+ file: rel,
6962
+ subject: rel,
6963
+ 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})`
6964
+ });
6965
+ continue;
6966
+ }
6967
+ if (entry.deleted) {
6968
+ 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` });
6969
+ }
6970
+ if (sha256(text) === entry.sha256) continue;
6971
+ ctx.report({
6972
+ rule: "lock-files",
6973
+ level: "info",
6974
+ file: rel,
6975
+ subject: rel,
6976
+ 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`
6977
+ });
6978
+ }
6979
+ }
6532
6980
  var RATCHETED_BY_DEFAULT = ["deprecated-import"];
6533
6981
  async function runDoctor(options = {}) {
6534
- const root = path19.resolve(options.root ?? process.cwd());
6982
+ const root = path20.resolve(options.root ?? process.cwd());
6535
6983
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
6536
6984
  const config = loaded.config;
6537
6985
  const genesis = options.genesis ?? loadGenesis(root, config);
@@ -6585,7 +7033,7 @@ async function runDoctor(options = {}) {
6585
7033
  }
6586
7034
  let findings = applyConfig(raw, config, packageRuleIds(packages));
6587
7035
  if (options.base && changed) {
6588
- findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path19.join(root, f)) });
7036
+ findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path20.join(root, f)) });
6589
7037
  }
6590
7038
  const errors = findings.filter((f) => f.level === "error").length;
6591
7039
  const warnings = findings.filter((f) => f.level === "warn").length;
@@ -6630,6 +7078,7 @@ function builtinChecks(config, options = {}) {
6630
7078
  { name: "stability-imports", check: checkStabilityImports },
6631
7079
  { name: "agent-guide", check: checkAgentGuide },
6632
7080
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
7081
+ { name: "lock-files", check: checkLockFiles },
6633
7082
  ...(config.packs ?? []).map((p) => packs[p]),
6634
7083
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
6635
7084
  ];