@marktiderman/genesis-cli 1.23.0 → 1.24.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.
@@ -0,0 +1,26 @@
1
+ # Copy to .github/workflows/claude-review.yml. Replace GENESIS_SHA with the commit of the
2
+ # Genesis release you run (docs/APP-CI.md in marktiderman/genesis says how).
3
+ # Claude reviews each pull request against this app's CLAUDE.md and AGENTS.md (run
4
+ # `genesis agents` so they hold the Genesis guide). Needs the Claude GitHub app and the
5
+ # CLAUDE_CODE_OAUTH_TOKEN secret.
6
+ name: Claude Code Review
7
+
8
+ on:
9
+ pull_request:
10
+ types: [opened, ready_for_review, reopened] # add synchronize to review every push (each run is billed)
11
+
12
+ concurrency:
13
+ group: claude-review-${{ github.event.pull_request.number }}
14
+ cancel-in-progress: true
15
+
16
+ permissions: {}
17
+
18
+ jobs:
19
+ review:
20
+ permissions:
21
+ contents: read
22
+ pull-requests: write
23
+ issues: write
24
+ id-token: write
25
+ uses: marktiderman/genesis/.github/workflows/claude-review.yml@GENESIS_SHA # @marktiderman/genesis@X.Y.Z
26
+ secrets: inherit
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env bash
2
+ # Vercel "Ignored Build Step": production always builds; a preview builds only when someone asks.
3
+ #
4
+ # Copy to scripts/vercel-ignore-build.sh in the app and point vercel.json at it (the vercel.json
5
+ # beside this file). Replace GENESIS_SHA below with the commit of the Genesis release you copied it
6
+ # from (docs/APP-CI.md, "Which ref to call", says how to find it), so the next upgrade can tell
7
+ # whether your copy is behind. Edit the copy, not the defaults: set the variables below in the
8
+ # Vercel project instead.
9
+ #
10
+ # Genesis template templates/vercel/ignore-build.sh @ GENESIS_SHA # @marktiderman/genesis@X.Y.Z
11
+ #
12
+ # Vercel runs this before every build: exit 0 skips the build, exit 1 builds.
13
+ #
14
+ # 1. Production (VERCEL_ENV=production, the production branch) always builds. So does a deploy
15
+ # with VERCEL_ENV unset (system variables not exposed: production can't be told from a preview,
16
+ # and production must never be skipped) and a custom environment (VERCEL_TARGET_ENV set to
17
+ # something other than preview, such as staging).
18
+ # 2. GENESIS_PREVIEWS=off: no preview builds. GENESIS_PREVIEWS=every-pr: every preview builds.
19
+ # 3. GENESIS_PREVIEWS=on-demand (the default) builds a preview only when one of these asks:
20
+ # - the branch starts with GENESIS_PREVIEW_BRANCH_PREFIX (default `preview/`);
21
+ # - the commit message has `[preview]` in it (the commit being deployed, not earlier ones);
22
+ # - the pull request has the label GENESIS_PREVIEW_LABEL (default `preview`, any case), read
23
+ # from the GitHub API with GENESIS_PREVIEW_GITHUB_TOKEN (a fine-grained token with read access
24
+ # to pull requests on this repository). No token, a failed request or a non-GitHub repository
25
+ # skips: an error never starts a build.
26
+ # Everything else skips.
27
+ #
28
+ # Vercel doesn't redeploy when a label is added: push a commit (or redeploy the latest one) after
29
+ # labelling. Vercel passes VERCEL_GIT_* only with "Automatically expose System Environment
30
+ # Variables" on in the project's Environment Variables settings.
31
+
32
+ # The app's own defaults can live in genesis.config.json's "environments" block:
33
+ # { "environments": { "previews": "every-pr", "label": "preview", "branchPrefix": "preview/" } }
34
+ # A variable set in the Vercel project wins over the file; the file wins over the defaults here.
35
+ config() { # prints the value, __EMPTY__ for "", nothing when unset or unreadable
36
+ [ -f genesis.config.json ] && command -v node > /dev/null 2>&1 || return 0
37
+ node -e 'try { const v = ((JSON.parse(require("fs").readFileSync("genesis.config.json", "utf8")) || {}).environments || {})[process.argv[1]]; if (typeof v === "string") process.stdout.write(v === "" ? "__EMPTY__" : v) } catch {}' "$1" 2> /dev/null || true
38
+ }
39
+ setting() { # $1 variable name, $2 config key, $3 default
40
+ if [ -n "${!1+set}" ]; then printf '%s' "${!1}"; return; fi
41
+ local v
42
+ v="$(config "$2")"
43
+ [ "$v" = "__EMPTY__" ] && return
44
+ printf '%s' "${v:-$3}"
45
+ }
46
+ previews="$(setting GENESIS_PREVIEWS previews on-demand)"
47
+ [ -n "$previews" ] || previews=on-demand
48
+ label="$(setting GENESIS_PREVIEW_LABEL label preview)" # set but empty: no label check
49
+ prefix="$(setting GENESIS_PREVIEW_BRANCH_PREFIX branchPrefix preview/)" # set but empty: no branch check
50
+ token="${GENESIS_PREVIEW_GITHUB_TOKEN:-}"
51
+ api="${GENESIS_GITHUB_API_URL:-https://api.github.com}"
52
+
53
+ ref="${VERCEL_GIT_COMMIT_REF:-}"
54
+ message="${VERCEL_GIT_COMMIT_MESSAGE:-}"
55
+ pr="${VERCEL_GIT_PULL_REQUEST_ID:-}"
56
+
57
+ build() {
58
+ echo "genesis previews: build ($1)"
59
+ exit 1
60
+ }
61
+ skip() {
62
+ echo "genesis previews: skip ($1)"
63
+ exit 0
64
+ }
65
+
66
+ [ "${VERCEL_ENV:-}" = "production" ] && build "production"
67
+ [ -z "${VERCEL_ENV:-}" ] && build "VERCEL_ENV unset: expose System Environment Variables to build previews on demand"
68
+ case "${VERCEL_TARGET_ENV:-preview}" in
69
+ preview | production | development) ;;
70
+ *) build "custom environment ${VERCEL_TARGET_ENV}" ;;
71
+ esac
72
+
73
+ case "$previews" in
74
+ off) skip "GENESIS_PREVIEWS=off" ;;
75
+ every-pr) build "GENESIS_PREVIEWS=every-pr" ;;
76
+ on-demand) ;;
77
+ *) echo "genesis previews: unknown GENESIS_PREVIEWS=\"$previews\" (on-demand, every-pr or off); using on-demand" ;;
78
+ esac
79
+
80
+ if [ -n "$prefix" ] && [ -n "$ref" ]; then
81
+ case "$ref" in
82
+ "$prefix"*) build "branch $ref starts with $prefix" ;;
83
+ esac
84
+ fi
85
+
86
+ lower() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]'; }
87
+
88
+ case "$(lower "$message")" in
89
+ *"[preview]"*) build "[preview] in the commit message" ;;
90
+ esac
91
+
92
+ [ -n "$label" ] || skip "no opt-in (GENESIS_PREVIEW_LABEL is empty)"
93
+ [ "${VERCEL_GIT_PROVIDER:-github}" = "github" ] || skip "no opt-in (label check needs GitHub, not ${VERCEL_GIT_PROVIDER})"
94
+ [ -n "$token" ] || skip "no opt-in (no GENESIS_PREVIEW_GITHUB_TOKEN to read the \"$label\" label)"
95
+ owner="${VERCEL_GIT_REPO_OWNER:-}"
96
+ repo="${VERCEL_GIT_REPO_SLUG:-}"
97
+ [ -n "$owner" ] && [ -n "$repo" ] || skip "no opt-in (VERCEL_GIT_REPO_OWNER or VERCEL_GIT_REPO_SLUG is unset)"
98
+
99
+ # The pull request (by number, or the open one for this branch when Vercel has no number yet).
100
+ if [ -n "$pr" ]; then
101
+ case "$pr" in
102
+ *[!0-9]*) skip "no opt-in (VERCEL_GIT_PULL_REQUEST_ID \"$pr\" isn't a number)" ;;
103
+ esac
104
+ body="$(curl -fsS --max-time 10 \
105
+ -H "Authorization: Bearer $token" -H "Accept: application/vnd.github+json" \
106
+ "$api/repos/$owner/$repo/pulls/$pr" 2>/dev/null)" || skip "no opt-in (couldn't read pull request #$pr from GitHub)"
107
+ else
108
+ [ -n "$ref" ] || skip "no opt-in (no branch or pull request to read a label from)"
109
+ body="$(curl -fsS --max-time 10 --get \
110
+ -H "Authorization: Bearer $token" -H "Accept: application/vnd.github+json" \
111
+ --data-urlencode "state=open" --data-urlencode "head=$owner:$ref" \
112
+ "$api/repos/$owner/$repo/pulls" 2>/dev/null)" || skip "no opt-in (couldn't read the pull requests for $ref from GitHub)"
113
+ fi
114
+
115
+ # The labels' names, one per line, read with Node (which every Vercel build image has). A pull
116
+ # request list (no number) is every open pull request for this branch: a label on any of them counts.
117
+ command -v node >/dev/null 2>&1 || skip "no opt-in (no node to read GitHub's answer)"
118
+ names="$(printf '%s' "$body" | node -e '
119
+ let s = "";
120
+ process.stdin.on("data", (d) => (s += d)).on("end", () => {
121
+ const j = JSON.parse(s);
122
+ for (const pr of Array.isArray(j) ? j : [j]) for (const l of pr?.labels ?? []) console.log(String(l.name ?? ""));
123
+ });
124
+ ' 2>/dev/null)" || skip "no opt-in (GitHub's answer wasn't the JSON expected)"
125
+ want="$(lower "$label")"
126
+ while IFS= read -r name; do
127
+ [ "$(lower "$name")" = "$want" ] && build "the pull request has the \"$label\" label"
128
+ done <<EOF_NAMES
129
+ $names
130
+ EOF_NAMES
131
+ skip "no opt-in (no $prefix branch, [preview] commit or \"$label\" label)"
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://openapi.vercel.sh/vercel.json",
3
+ "ignoreCommand": "bash scripts/vercel-ignore-build.sh"
4
+ }
package/dist/vite.js CHANGED
@@ -817,6 +817,25 @@ var PRIVACY_PURPOSES = {
817
817
  "third-party advertising": "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising",
818
818
  other: "NSPrivacyCollectedDataTypePurposeOther"
819
819
  };
820
+ var ENVIRONMENT_KEYS = /* @__PURE__ */ new Set(["previews", "label", "branchPrefix", "$comment"]);
821
+ function validateEnvironments(raw, source = "config") {
822
+ const fail = (msg) => {
823
+ throw new GenesisConfigError(`${source}: ${msg}`);
824
+ };
825
+ if (!isObject(raw)) return fail(`"environments" must be an object`);
826
+ for (const key2 of Object.keys(raw)) if (!ENVIRONMENT_KEYS.has(key2)) fail(`environments: unknown setting "${key2}" (known: previews, label, branchPrefix)`);
827
+ const out = {};
828
+ if (raw.previews !== void 0) {
829
+ if (raw.previews !== "on-demand" && raw.previews !== "every-pr" && raw.previews !== "off") fail(`environments.previews must be "on-demand", "every-pr" or "off" (got ${JSON.stringify(raw.previews)})`);
830
+ out.previews = raw.previews;
831
+ }
832
+ for (const key2 of ["label", "branchPrefix"]) {
833
+ if (raw[key2] === void 0) continue;
834
+ if (typeof raw[key2] !== "string") fail(`environments.${key2} must be a string ("" turns that check off)`);
835
+ out[key2] = raw[key2];
836
+ }
837
+ return out;
838
+ }
820
839
  var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build", "componentPackages"];
821
840
  var STRINGS = ["uiPackage", "rulesDoc"];
822
841
  var KNOWN = /* @__PURE__ */ new Set([
@@ -848,7 +867,7 @@ var CONTRACT_KEYS = /* @__PURE__ */ new Set(["out", "schemas", "databaseEnv"]);
848
867
  var PACKS = /* @__PURE__ */ new Set(["native", "supabase", "packages"]);
849
868
  var PACK_KEYS = {
850
869
  native: { routerRoot: "path" },
851
- supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string" },
870
+ supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string", automaticBranching: "boolean" },
852
871
  packages: { base: "string" }
853
872
  };
854
873
  function appPath(v, where2, fail) {
@@ -909,6 +928,7 @@ function readGenesisConfig(root) {
909
928
  if (supabase !== true) out.supabase = supabase;
910
929
  }
911
930
  if (raw.appFolder !== void 0) out.appFolder = validateAppFolder(raw.appFolder, file);
931
+ if (raw.environments !== void 0) out.environments = validateEnvironments(raw.environments, file);
912
932
  return out;
913
933
  }
914
934
  var PLAIN_FOLDER = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,59}(?:\/[A-Za-z0-9_][A-Za-z0-9_.-]{0,59}){0,7}$/;
@@ -1107,6 +1127,7 @@ function validateConfig(raw, source = "config") {
1107
1127
  if (!want) fail(`${pack}: unknown setting "${k}"`);
1108
1128
  if (want === "string" && typeof v !== "string") fail(`${pack}.${k} must be a string`);
1109
1129
  if (want === "list" && !isStringList(v)) fail(`${pack}.${k} must be a list of strings`);
1130
+ if (want === "boolean" && typeof v !== "boolean") fail(`${pack}.${k} must be true or false`);
1110
1131
  if (want === "string" && !v.trim()) fail(`${pack}.${k} must not be empty`);
1111
1132
  if (want === "path") block[k] = appPath(v, `${pack}.${k}`, fail);
1112
1133
  }
@@ -1158,7 +1179,7 @@ function globToRegExp(glob) {
1158
1179
  }
1159
1180
  function globMatcher(globs) {
1160
1181
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1161
- return (path49) => res.some((re) => re.test(path49));
1182
+ return (path50) => res.some((re) => re.test(path50));
1162
1183
  }
1163
1184
  var GENESIS_PACKAGE = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
1164
1185
  var BLOCK_ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
@@ -2711,6 +2732,7 @@ var BUILTIN_RULES = [
2711
2732
  "migration-edited",
2712
2733
  "migration-testing-kit",
2713
2734
  "migration-view-rls",
2735
+ "exposed-schema-created-later",
2714
2736
  // packages pack
2715
2737
  "package-app-import",
2716
2738
  "package-undeclared-dependency",
@@ -4854,6 +4876,67 @@ function checkSupabasePack(ctx) {
4854
4876
  checkViewInvoker(ctx, migrations, exposed);
4855
4877
  checkDefinerSearchPath(ctx, migrations);
4856
4878
  checkTestingKit(ctx, migrations);
4879
+ checkExposedSchemasCreatedLater(ctx, dir, migrations, settings.exposedSchemas, settings.automaticBranching !== false);
4880
+ }
4881
+ var PLATFORM_SCHEMAS = /* @__PURE__ */ new Set(["public", "graphql_public", "graphql", "extensions", "storage", "auth", "realtime", "vault"]);
4882
+ function apiSchemas(toml) {
4883
+ const lines = toml.split("\n");
4884
+ const start = lines.findIndex((l) => /^\s*\[api\]\s*(?:#.*)?$/.test(l));
4885
+ if (start < 0) return null;
4886
+ let end = lines.findIndex((l, i) => i > start && /^\s*\[/.test(l));
4887
+ if (end < 0) end = lines.length;
4888
+ const bare = (l) => {
4889
+ let quoted = false;
4890
+ for (let i = 0; i < l.length; i++) {
4891
+ if (l[i] === '"' && l[i - 1] !== "\\") quoted = !quoted;
4892
+ else if (l[i] === "#" && !quoted) return l.slice(0, i);
4893
+ }
4894
+ return l;
4895
+ };
4896
+ const body = lines.slice(start + 1, end).map(bare);
4897
+ const enabled = !body.some((l) => /^\s*enabled\s*=\s*false\b/.test(l));
4898
+ const at = body.findIndex((l) => /^\s*schemas\s*=/.test(l));
4899
+ if (at < 0) return { enabled, schemas: [], line: start + 1 };
4900
+ let list = "";
4901
+ for (let i = at; i < body.length; i++) {
4902
+ list += `${body[i]}
4903
+ `;
4904
+ if (body[i].includes("]")) break;
4905
+ }
4906
+ const inner = /\[([\s\S]*?)\]/.exec(list)?.[1] ?? "";
4907
+ const schemas = [...inner.matchAll(/"((?:[^"\\]|\\.)*)"|'([^']*)'/g)].map((m) => (m[1] ?? m[2]).trim().toLowerCase()).filter(Boolean);
4908
+ return { enabled, schemas, line: start + at + 2 };
4909
+ }
4910
+ function checkExposedSchemasCreatedLater(ctx, dir, migrations, configured, branching) {
4911
+ const created = /* @__PURE__ */ new Map();
4912
+ for (const { file, statements } of migrations) {
4913
+ for (const { sql, line } of statements) {
4914
+ const m = /^create schema (?:if not exists )?"?([\w$]+)"?/.exec(sql);
4915
+ if (m && m[1] !== "authorization" && !created.has(m[1])) created.set(m[1], { file, line });
4916
+ }
4917
+ }
4918
+ const tomlFile = path21.posix.join(path21.posix.dirname(dir), "config.toml");
4919
+ const tomlText = existsSync(path21.join(ctx.root, tomlFile)) ? readFileSync(path21.join(ctx.root, tomlFile), "utf8") : null;
4920
+ const api2 = tomlText === null ? null : apiSchemas(tomlText);
4921
+ const sources = [];
4922
+ if (api2?.enabled) for (const schema of api2.schemas) sources.push({ schema, file: tomlFile, line: api2.line, where: `${tomlFile} [api] schemas` });
4923
+ for (const schema of api2?.enabled === false ? [] : configured ?? []) {
4924
+ const s = schema.toLowerCase();
4925
+ if (!sources.some((x) => x.schema === s)) sources.push({ schema: s, file: "genesis.config.json", where: "doctor.supabase.exposedSchemas" });
4926
+ }
4927
+ for (const { schema, file, line, where: where2 } of sources) {
4928
+ if (PLATFORM_SCHEMAS.has(schema)) continue;
4929
+ const by = created.get(schema);
4930
+ if (by && !branching) continue;
4931
+ ctx.report({
4932
+ rule: "exposed-schema-created-later",
4933
+ level: "warn",
4934
+ file,
4935
+ ...line ? { line } : {},
4936
+ subject: schema,
4937
+ message: by ? `${where2} exposes ${schema}, which only a migration creates (${by.file}:${by.line}); a Supabase branch points its Data API at ${schema} before it runs migrations, so a fresh preview branch fails its health check. Turn off Supabase's automatic branching (Genesis docs/APP-CI.md, "Previews"), then set doctor.supabase.automaticBranching to false` : `${where2} exposes ${schema}, which no migration creates, so a database built from the migrations can't serve it (a Supabase branch fails its health check); create it in a migration or stop exposing it`
4938
+ });
4939
+ }
4857
4940
  }
4858
4941
  function checkTestingKit(ctx, migrations) {
4859
4942
  for (const { file, statements } of migrations) {
@@ -6104,6 +6187,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
6104
6187
  }
6105
6188
  }
6106
6189
  var GENESIS_DOCS = "https://github.com/marktiderman/genesis/blob/main/docs";
6190
+ var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
6107
6191
  var CORE = [
6108
6192
  {
6109
6193
  need: "anything, before building it",
@@ -6176,14 +6260,79 @@ var SKILL_PATH = ".claude/skills/genesis/SKILL.md";
6176
6260
  var AGENTS_START = "<!-- genesis-primitives:start -->";
6177
6261
  var AGENTS_END = "<!-- genesis-primitives:end -->";
6178
6262
  var RULES = [
6179
- "Use the Genesis primitive for the need first: reuse, then extend, then invent (docs/FRAMEWORK.md, G1 to G6).",
6263
+ `Use the Genesis primitive for the need first: reuse, then extend, then invent (G1 to G6 in ${GENESIS_DOCS}/FRAMEWORK.md).`,
6180
6264
  "Never copy an older screen as a template. Old screens predate the primitives; the doctor flags what they did.",
6181
6265
  "A list screen is a view (`defineView`) rendered by `ResourceView`; a record view is `RecordView`; on the phone, `NativeResourceView`.",
6182
6266
  "Screens never call the database client (`supabase.from`, `.rpc`) directly: reads go through a view or a named data function, writes through the resource's provider rules.",
6183
6267
  "When no primitive fits, write the gap up for Genesis before inventing, then invent in the app on Genesis primitives.",
6184
6268
  "Run `genesis doctor` before you finish; it enforces these rules."
6185
6269
  ];
6186
- function renderSkill(rows) {
6270
+ function skillDescription(text) {
6271
+ const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)?.[1];
6272
+ if (!fm) return "";
6273
+ const lines = fm.split(/\r?\n/);
6274
+ const i = lines.findIndex((l) => /^description:/.test(l));
6275
+ if (i < 0) return "";
6276
+ const first = lines[i].replace(/^description:\s*/, "").trim();
6277
+ if (first && !/^[>|][+-]?$/.test(first)) return first.replace(/^["']|["']$/g, "");
6278
+ const more = [];
6279
+ for (const l of lines.slice(i + 1)) {
6280
+ if (!/^\s+\S/.test(l)) break;
6281
+ more.push(l.trim());
6282
+ }
6283
+ return more.join(" ");
6284
+ }
6285
+ var GUIDE_SEARCH_LEVELS = 4;
6286
+ function stableGuidePath(root, p) {
6287
+ const real2 = (f) => {
6288
+ try {
6289
+ return realpathSync(f);
6290
+ } catch {
6291
+ return null;
6292
+ }
6293
+ };
6294
+ const want = real2(p.dir);
6295
+ for (let dir = root, level = 0; level <= GUIDE_SEARCH_LEVELS; level++) {
6296
+ const found = path21.join(dir, "node_modules", p.name);
6297
+ if (existsSync(found)) {
6298
+ const file = path21.join(found, "SKILL.md");
6299
+ return want !== null && real2(found) === want && existsSync(file) ? file : null;
6300
+ }
6301
+ if (existsSync(path21.join(dir, ".git")) || existsSync(path21.join(dir, "pnpm-workspace.yaml"))) return null;
6302
+ const up = path21.dirname(dir);
6303
+ if (up === dir) return null;
6304
+ dir = up;
6305
+ }
6306
+ return null;
6307
+ }
6308
+ function packageGuides(root, packages) {
6309
+ const guides = [];
6310
+ for (const p of packages) {
6311
+ const stable = p.local ? path21.join(p.dir, "SKILL.md") : stableGuidePath(root, p);
6312
+ const text = stable === null ? null : read(stable);
6313
+ if (stable === null || text === null) continue;
6314
+ const description = skillDescription(text);
6315
+ const at = description.indexOf("Load before");
6316
+ guides.push({ package: p.name, path: path21.relative(root, stable).split(path21.sep).join("/"), when: at >= 0 ? description.slice(at) : description });
6317
+ }
6318
+ return guides.sort((a, b) => a.package.localeCompare(b.package));
6319
+ }
6320
+ function unlistedGuides(root, packages) {
6321
+ const listed = new Set(packageGuides(root, packages).map((g) => g.package));
6322
+ return packages.filter((p) => !p.local && !listed.has(p.name) && existsSync(path21.join(p.dir, "SKILL.md"))).map((p) => p.name).sort();
6323
+ }
6324
+ function guidesSection(guides) {
6325
+ if (!guides.length) return [];
6326
+ return [
6327
+ "### Package guides (they match the installed versions)",
6328
+ "",
6329
+ "Before using a package's primitives, read its guide:",
6330
+ "",
6331
+ ...guides.map((g) => `- \`${g.path}\` (${g.package}): ${g.when}`),
6332
+ ""
6333
+ ];
6334
+ }
6335
+ function renderSkill(rows, guides = []) {
6187
6336
  return [
6188
6337
  "---",
6189
6338
  "name: genesis",
@@ -6196,6 +6345,7 @@ function renderSkill(rows) {
6196
6345
  "",
6197
6346
  ...RULES.map((r) => `- ${r}`),
6198
6347
  "",
6348
+ ...guidesSection(guides),
6199
6349
  "## What to use for each need",
6200
6350
  "",
6201
6351
  catalogTable(rows, { docs: true }),
@@ -6204,7 +6354,7 @@ function renderSkill(rows) {
6204
6354
  ""
6205
6355
  ].join("\n");
6206
6356
  }
6207
- function renderAgentsBlock(rows) {
6357
+ function renderAgentsBlock(rows, guides = []) {
6208
6358
  return [
6209
6359
  AGENTS_START,
6210
6360
  "## Building with Genesis",
@@ -6215,6 +6365,7 @@ function renderAgentsBlock(rows) {
6215
6365
  "",
6216
6366
  ...RULES.map((r) => `- ${r}`),
6217
6367
  "",
6368
+ ...guidesSection(guides),
6218
6369
  catalogTable(rows),
6219
6370
  AGENTS_END
6220
6371
  ].join("\n");
@@ -6233,14 +6384,37 @@ function currentAgentsBlock(agents) {
6233
6384
  if (span === "broken") return "broken";
6234
6385
  return agents.slice(span.start, span.end).replace(/\r\n/g, "\n");
6235
6386
  }
6236
- var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
6387
+ function claudeState(root) {
6388
+ const file = path21.join(root, "CLAUDE.md");
6389
+ let names = [];
6390
+ try {
6391
+ names = readdirSync(root);
6392
+ } catch {
6393
+ }
6394
+ if (!names.includes("CLAUDE.md")) return names.some((n) => n.toLowerCase() === "claude.md") ? "blocked" : "missing";
6395
+ let text;
6396
+ try {
6397
+ text = readFileSync(file, "utf8");
6398
+ } catch {
6399
+ return "blocked";
6400
+ }
6401
+ if (/^@AGENTS\.md\b/m.test(text)) return "ok";
6402
+ try {
6403
+ if (realpathSync(file) === realpathSync(path21.join(root, "AGENTS.md"))) return "ok";
6404
+ } catch {
6405
+ }
6406
+ return "no-import";
6407
+ }
6237
6408
  function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
6238
6409
  const rows = primitivesCatalog(packages);
6410
+ const guides = packageGuides(root, packages);
6239
6411
  const skill = read(path21.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
6240
6412
  const block = currentAgentsBlock(read(path21.join(root, agentsFile)));
6241
6413
  return {
6242
- skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
6243
- agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
6414
+ skill: skill === null ? "missing" : skill === renderSkill(rows, guides) ? "ok" : "stale",
6415
+ agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows, guides) ? "ok" : "stale",
6416
+ // Only the default AGENTS.md gets a CLAUDE.md written for it, so only then is a missing one reported.
6417
+ claude: agentsFile !== "AGENTS.md" ? "ok" : claudeState(root)
6244
6418
  };
6245
6419
  }
6246
6420
  function checkAgentGuide(ctx) {
@@ -6258,6 +6432,41 @@ function checkAgentGuide(ctx) {
6258
6432
  }[state.agents];
6259
6433
  ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
6260
6434
  }
6435
+ if (state.claude === "no-import") {
6436
+ ctx.report({ rule: "agent-guide-stale", level: "info", file: "CLAUDE.md", message: "doesn't import AGENTS.md (`@AGENTS.md`), so reviewers and cloud project threads that read only CLAUDE.md don't see the Genesis guide" });
6437
+ }
6438
+ if (state.claude === "missing") {
6439
+ ctx.report({ rule: "agent-guide-stale", level: "warn", file: "CLAUDE.md", message: `is missing, so reviewers and cloud project threads that read only CLAUDE.md never see AGENTS.md; ${fix} (it writes \`@AGENTS.md\`)` });
6440
+ }
6441
+ if (state.claude === "blocked") {
6442
+ ctx.report({ rule: "agent-guide-stale", level: "warn", file: "CLAUDE.md", message: `can't be read: something else is in its place (another case of the name such as claude.md, a dangling link, a folder or an unreadable file), and genesis agents won't write over it; ${BLOCKED_FIX}` });
6443
+ }
6444
+ const unlisted = unlistedGuides(ctx.root, ctx.packages);
6445
+ if (unlisted.length) {
6446
+ ctx.report({ rule: "agent-guide-stale", level: "info", file: "AGENTS.md", message: `leaves out the guide of ${unlisted.join(", ")}: it's only inside pnpm's store, under a path that changes with unrelated bumps. Add the package as a direct dependency to list its guide.` });
6447
+ }
6448
+ }
6449
+ var BLOCKED_FIX = "rename or replace it with a CLAUDE.md file (or remove the dangling link), then run genesis agents";
6450
+ var SETTINGS_PATH = ".claude/settings.json";
6451
+ var SUBAGENT_HOOK_COMMAND = '"$CLAUDE_PROJECT_DIR"/node_modules/.bin/genesis agents --hook subagent-start --dir "$CLAUDE_PROJECT_DIR" 2>/dev/null || true';
6452
+ var isObject4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
6453
+ var isGenesisHook = (h) => typeof h.command === "string" && h.command.includes("genesis agents --hook");
6454
+ function agentHooksState(root) {
6455
+ let settings;
6456
+ try {
6457
+ settings = JSON.parse(readFileSync(path21.join(root, SETTINGS_PATH), "utf8"));
6458
+ } catch {
6459
+ return "none";
6460
+ }
6461
+ const start = isObject4(settings) && isObject4(settings.hooks) ? settings.hooks["SubagentStart"] : void 0;
6462
+ const commands = (Array.isArray(start) ? start : []).flatMap((e) => isObject4(e) && Array.isArray(e.hooks) ? e.hooks : []).filter((h) => isObject4(h) && isGenesisHook(h)).map((h) => h.command);
6463
+ if (!commands.length) return "none";
6464
+ return commands.every((c) => c === SUBAGENT_HOOK_COMMAND) ? "ok" : "stale";
6465
+ }
6466
+ function checkAgentHooks(ctx) {
6467
+ if (agentHooksState(ctx.root) === "stale") {
6468
+ ctx.report({ rule: "agent-guide-stale", level: "warn", file: SETTINGS_PATH, message: "has an older Genesis SubagentStart hook command; run genesis agents --hooks and commit the result" });
6469
+ }
6261
6470
  }
6262
6471
 
6263
6472
  // src/blocks/templates.ts
@@ -7165,7 +7374,10 @@ function builtinChecks(config, options = {}) {
7165
7374
  { name: "studio-server-imports", check: checkStudioServerImports },
7166
7375
  { name: "removed-scope-names", check: checkRemovedScopeNames },
7167
7376
  { name: "stability-imports", check: checkStabilityImports },
7168
- { name: "agent-guide", check: checkAgentGuide },
7377
+ { name: "agent-guide", check: (ctx) => {
7378
+ checkAgentGuide(ctx);
7379
+ checkAgentHooks(ctx);
7380
+ } },
7169
7381
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
7170
7382
  { name: "lock-files", check: checkLockFiles },
7171
7383
  { name: "database-elsewhere", check: checkDatabaseHome },