@marktiderman/genesis-cli 1.23.0 → 1.25.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/README.md +126 -16
- package/dist/cli.js +768 -85
- package/dist/cli.js.map +1 -1
- package/dist/{config-HOmiOLQc.d.ts → config-CR4kqSCp.d.ts} +65 -6
- package/dist/doctor.d.ts +103 -6
- package/dist/doctor.js +675 -48
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +20 -0
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +9 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +593 -52
- package/dist/index.js.map +1 -1
- package/dist/templates/ci/claude-review.yml +26 -0
- package/dist/templates/vercel/ignore-build.sh +131 -0
- package/dist/templates/vercel/vercel.json +4 -0
- package/dist/vite.js +586 -45
- package/dist/vite.js.map +1 -1
- package/package.json +2 -2
package/dist/doctor.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([
|
|
@@ -827,6 +846,7 @@ var KNOWN = /* @__PURE__ */ new Set([
|
|
|
827
846
|
"forbiddenImports",
|
|
828
847
|
"rules",
|
|
829
848
|
"allow",
|
|
849
|
+
"extend",
|
|
830
850
|
"patterns",
|
|
831
851
|
"plugins",
|
|
832
852
|
"packs",
|
|
@@ -841,14 +861,17 @@ var KNOWN = /* @__PURE__ */ new Set([
|
|
|
841
861
|
"$comment"
|
|
842
862
|
]);
|
|
843
863
|
var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "info", "off"]);
|
|
844
|
-
var META_RULES = /* @__PURE__ */ new Set(["allow-grew", "rules-weakened", "ratchet-skipped"]);
|
|
864
|
+
var META_RULES = /* @__PURE__ */ new Set(["allow-grew", "rules-weakened", "ratchet-skipped", "extension-invalid"]);
|
|
865
|
+
var CONFIG_RULES = /* @__PURE__ */ new Set(["stale-exception", "stale-extension", "package-rule-override"]);
|
|
866
|
+
var EXTENSION_KEYS = /* @__PURE__ */ new Set(["rule", "file", "buildsOn", "reason", "upstream"]);
|
|
867
|
+
var EXTENSION_REASON_MIN = { chars: 40, words: 6 };
|
|
845
868
|
var PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message", "newOnly"]);
|
|
846
869
|
var PACKAGE_RULE_KEYS = /* @__PURE__ */ new Set(["level", "files", "exclude", "reason"]);
|
|
847
870
|
var CONTRACT_KEYS = /* @__PURE__ */ new Set(["out", "schemas", "databaseEnv"]);
|
|
848
871
|
var PACKS = /* @__PURE__ */ new Set(["native", "supabase", "packages"]);
|
|
849
872
|
var PACK_KEYS = {
|
|
850
873
|
native: { routerRoot: "path" },
|
|
851
|
-
supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string" },
|
|
874
|
+
supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string", automaticBranching: "boolean" },
|
|
852
875
|
packages: { base: "string" }
|
|
853
876
|
};
|
|
854
877
|
function appPath(v, where2, fail) {
|
|
@@ -909,6 +932,7 @@ function readGenesisConfig(root) {
|
|
|
909
932
|
if (supabase !== true) out.supabase = supabase;
|
|
910
933
|
}
|
|
911
934
|
if (raw.appFolder !== void 0) out.appFolder = validateAppFolder(raw.appFolder, file);
|
|
935
|
+
if (raw.environments !== void 0) out.environments = validateEnvironments(raw.environments, file);
|
|
912
936
|
return out;
|
|
913
937
|
}
|
|
914
938
|
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}$/;
|
|
@@ -1051,6 +1075,30 @@ function validateConfig(raw, source = "config") {
|
|
|
1051
1075
|
}
|
|
1052
1076
|
});
|
|
1053
1077
|
}
|
|
1078
|
+
if (c.extend !== void 0) {
|
|
1079
|
+
if (!Array.isArray(c.extend)) fail(`"extend" must be a list of { rule, file, buildsOn, reason, upstream? }`);
|
|
1080
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1081
|
+
c.extend.forEach((e, i) => {
|
|
1082
|
+
const where2 = `extend[${i}]`;
|
|
1083
|
+
if (!isObject(e)) return fail(`${where2} must be an object`);
|
|
1084
|
+
for (const k of Object.keys(e)) if (!EXTENSION_KEYS.has(k)) fail(`${where2}: unknown key "${k}" (known: ${[...EXTENSION_KEYS].join(", ")})`);
|
|
1085
|
+
for (const k of ["rule", "file", "buildsOn", "reason"]) if (typeof e[k] !== "string" || !e[k].trim()) fail(`${where2} needs "${k}"`);
|
|
1086
|
+
const { rule, file, buildsOn, reason } = e;
|
|
1087
|
+
if (META_RULES.has(rule) || CONFIG_RULES.has(rule)) fail(`${where2} can't extend ${rule}: it is about the config, not the app's code`);
|
|
1088
|
+
if (!rule.includes("/")) fail(`${where2} can't extend ${rule}: only package rules declare extension points (a built-in rule's findings are fixed, or recorded as allow debt)`);
|
|
1089
|
+
if (/[*?[\]{}]/.test(file)) fail(`${where2}.file must be one file, not a glob: each extension is reviewed on its own`);
|
|
1090
|
+
e.file = appPath(file, `${where2}.file`, fail);
|
|
1091
|
+
if (!/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(buildsOn)) fail(`${where2}.buildsOn must name a Genesis export, or a part of one ("FormBuilder", "ResourceView.slots")`);
|
|
1092
|
+
const text = reason.trim();
|
|
1093
|
+
if (text.length < EXTENSION_REASON_MIN.chars || text.split(/\s+/).length < EXTENSION_REASON_MIN.words) {
|
|
1094
|
+
fail(`${where2} (${rule}) needs a reason of at least ${EXTENSION_REASON_MIN.words} words and ${EXTENSION_REASON_MIN.chars} characters: why the rule's primitive doesn't fit this file`);
|
|
1095
|
+
}
|
|
1096
|
+
if (e.upstream !== void 0 && (typeof e.upstream !== "string" || !e.upstream.trim())) fail(`${where2}.upstream must be a link to the gap's write-up`);
|
|
1097
|
+
const key2 = `${rule}\0${e.file}`;
|
|
1098
|
+
if (seen.has(key2)) fail(`${where2} extends ${rule} in ${e.file} twice`);
|
|
1099
|
+
seen.add(key2);
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1054
1102
|
if (c.patterns !== void 0) {
|
|
1055
1103
|
if (!Array.isArray(c.patterns)) fail(`"patterns" must be a list`);
|
|
1056
1104
|
c.patterns.forEach((p, i) => {
|
|
@@ -1107,6 +1155,7 @@ function validateConfig(raw, source = "config") {
|
|
|
1107
1155
|
if (!want) fail(`${pack}: unknown setting "${k}"`);
|
|
1108
1156
|
if (want === "string" && typeof v !== "string") fail(`${pack}.${k} must be a string`);
|
|
1109
1157
|
if (want === "list" && !isStringList(v)) fail(`${pack}.${k} must be a list of strings`);
|
|
1158
|
+
if (want === "boolean" && typeof v !== "boolean") fail(`${pack}.${k} must be true or false`);
|
|
1110
1159
|
if (want === "string" && !v.trim()) fail(`${pack}.${k} must not be empty`);
|
|
1111
1160
|
if (want === "path") block[k] = appPath(v, `${pack}.${k}`, fail);
|
|
1112
1161
|
}
|
|
@@ -1158,7 +1207,7 @@ function globToRegExp(glob) {
|
|
|
1158
1207
|
}
|
|
1159
1208
|
function globMatcher(globs) {
|
|
1160
1209
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1161
|
-
return (
|
|
1210
|
+
return (path49) => res.some((re) => re.test(path49));
|
|
1162
1211
|
}
|
|
1163
1212
|
var GENESIS_PACKAGE = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
|
|
1164
1213
|
var BLOCK_ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
@@ -1743,6 +1792,9 @@ function scanFiles(root, config) {
|
|
|
1743
1792
|
for (const pkg of local) walk3(pkg.dir);
|
|
1744
1793
|
return files;
|
|
1745
1794
|
}
|
|
1795
|
+
function withText(file, text) {
|
|
1796
|
+
return { ...file, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(file.ext)) };
|
|
1797
|
+
}
|
|
1746
1798
|
function lineAt(text, index) {
|
|
1747
1799
|
let line = 1;
|
|
1748
1800
|
for (let i = 0; i < index && i < text.length; i++) if (text.charCodeAt(i) === 10) line++;
|
|
@@ -2714,6 +2766,7 @@ var BUILTIN_RULES = [
|
|
|
2714
2766
|
"migration-edited",
|
|
2715
2767
|
"migration-testing-kit",
|
|
2716
2768
|
"migration-view-rls",
|
|
2769
|
+
"exposed-schema-created-later",
|
|
2717
2770
|
// packages pack
|
|
2718
2771
|
"package-app-import",
|
|
2719
2772
|
"package-undeclared-dependency",
|
|
@@ -2739,6 +2792,10 @@ var BUILTIN_RULES = [
|
|
|
2739
2792
|
"ratchet-skipped",
|
|
2740
2793
|
"allow-grew",
|
|
2741
2794
|
"rules-weakened",
|
|
2795
|
+
"extension-added",
|
|
2796
|
+
// declared extensions (extensions.ts)
|
|
2797
|
+
"stale-extension",
|
|
2798
|
+
"extension-invalid",
|
|
2742
2799
|
// agent guide (primitives.ts)
|
|
2743
2800
|
"agent-guide-stale",
|
|
2744
2801
|
// supabase pack: contracts (contracts.ts)
|
|
@@ -3027,6 +3084,34 @@ function readSource(abs) {
|
|
|
3027
3084
|
return null;
|
|
3028
3085
|
}
|
|
3029
3086
|
}
|
|
3087
|
+
var lastBlanked = null;
|
|
3088
|
+
function blankStrings(code) {
|
|
3089
|
+
if (lastBlanked?.source === code) return lastBlanked.blanked;
|
|
3090
|
+
const out = code.split("");
|
|
3091
|
+
for (let i = 0; i < code.length; i++) {
|
|
3092
|
+
const ch = code[i];
|
|
3093
|
+
if (ch !== '"' && ch !== "'" && ch !== "`") continue;
|
|
3094
|
+
let j = i - 1;
|
|
3095
|
+
while (j >= 0 && /[ \t]/.test(code[j])) j--;
|
|
3096
|
+
const before = j >= 0 ? code[j] : "\n";
|
|
3097
|
+
const word = /[\w$]/.test(before) ? /(?:^|[^\w$])(return|case|typeof|in|of|yield|await)$/.test(code.slice(Math.max(0, j - 8), j + 1)) : false;
|
|
3098
|
+
if (/[\w$)\]]/.test(before) && !word) continue;
|
|
3099
|
+
let k = i + 1;
|
|
3100
|
+
for (; k < code.length; k++) {
|
|
3101
|
+
const c = code[k];
|
|
3102
|
+
if (c === "\\") {
|
|
3103
|
+
k++;
|
|
3104
|
+
continue;
|
|
3105
|
+
}
|
|
3106
|
+
if (c === ch) break;
|
|
3107
|
+
if (c === "\n" && ch !== "`") break;
|
|
3108
|
+
}
|
|
3109
|
+
for (let x = i + 1; x < k && x < code.length; x++) if (code[x] !== "\n") out[x] = " ";
|
|
3110
|
+
i = k;
|
|
3111
|
+
}
|
|
3112
|
+
lastBlanked = { source: code, blanked: out.join("") };
|
|
3113
|
+
return lastBlanked.blanked;
|
|
3114
|
+
}
|
|
3030
3115
|
function tagEnd(code, start) {
|
|
3031
3116
|
let depth = 0;
|
|
3032
3117
|
let quote2 = null;
|
|
@@ -3048,7 +3133,8 @@ function tagEnd(code, start) {
|
|
|
3048
3133
|
}
|
|
3049
3134
|
return { end: code.length, selfClosing: false };
|
|
3050
3135
|
}
|
|
3051
|
-
function openElementsAt(
|
|
3136
|
+
function openElementsAt(source, index, track) {
|
|
3137
|
+
const code = blankStrings(source);
|
|
3052
3138
|
const open = [];
|
|
3053
3139
|
const re = /<(\/?)([A-Z][\w.]*)(?=[\s>/])/g;
|
|
3054
3140
|
for (let m = re.exec(code); m && m.index < index; m = re.exec(code)) {
|
|
@@ -3900,9 +3986,9 @@ var PackageDeclarationError = class extends Error {
|
|
|
3900
3986
|
var GENESIS = /^@marktiderman\/genesis(?:-([a-z0-9-]+))?$/;
|
|
3901
3987
|
var ID = /^[a-z0-9][a-z0-9-]*$/;
|
|
3902
3988
|
var LEVELS2 = /* @__PURE__ */ new Set(["error", "warn", "info"]);
|
|
3903
|
-
var PREFER_KEYS = /* @__PURE__ */ new Set(["id", "need", "level", "platform", "files", "exclude", "forbid", "unless", "use", "import", "docs", "why", "newOnly"]);
|
|
3989
|
+
var PREFER_KEYS = /* @__PURE__ */ new Set(["id", "need", "level", "platform", "files", "exclude", "forbid", "unless", "use", "import", "docs", "why", "newOnly", "extensible"]);
|
|
3904
3990
|
var FORBID_KEYS = /* @__PURE__ */ new Set(["jsx", "imports", "pattern"]);
|
|
3905
|
-
var UNLESS_KEYS = /* @__PURE__ */ new Set(["renders", "pattern"]);
|
|
3991
|
+
var UNLESS_KEYS = /* @__PURE__ */ new Set(["renders", "inside", "pattern"]);
|
|
3906
3992
|
var PRIMITIVE_KEYS = /* @__PURE__ */ new Set(["need", "use", "import", "docs"]);
|
|
3907
3993
|
var DECLARATION_KEYS = /* @__PURE__ */ new Set(["enforce", "reason", "prefer", "catalog", "primitives", "plugin", "$comment"]);
|
|
3908
3994
|
var SCRIPT_GLOBS = ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.mts", "**/*.cts", "**/*.mjs", "**/*.cjs"];
|
|
@@ -4011,6 +4097,9 @@ function validatePrefer(raw, where2, fail, unknownKey) {
|
|
|
4011
4097
|
if (raw.platform !== void 0 && raw.platform !== "web" && raw.platform !== "native") fail(`${at}.platform must be "web" or "native"`);
|
|
4012
4098
|
if (raw.newOnly !== void 0 && typeof raw.newOnly !== "boolean") fail(`${at}.newOnly must be true or false`);
|
|
4013
4099
|
for (const key2 of ["files", "exclude"]) if (raw[key2] !== void 0 && !isStringList2(raw[key2])) fail(`${at}.${key2} must be a list of globs`);
|
|
4100
|
+
if (raw.extensible !== void 0 && !(isStringList2(raw.extensible) && raw.extensible.every((n) => /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(n)))) {
|
|
4101
|
+
fail(`${at}.extensible must be a list of export names, or parts of one ("ResourceView.slots")`);
|
|
4102
|
+
}
|
|
4014
4103
|
if (!isObject3(raw.forbid)) fail(`${at} needs "forbid": { jsx?, imports?, pattern? }`);
|
|
4015
4104
|
const forbid = raw.forbid;
|
|
4016
4105
|
for (const key2 of Object.keys(forbid)) if (!FORBID_KEYS.has(key2)) unknownKey(`${at}.forbid`, key2);
|
|
@@ -4023,6 +4112,7 @@ function validatePrefer(raw, where2, fail, unknownKey) {
|
|
|
4023
4112
|
const unless = raw.unless;
|
|
4024
4113
|
for (const key2 of Object.keys(unless)) if (!UNLESS_KEYS.has(key2)) narrowing(`${at}.unless`, key2, UNLESS_KEYS);
|
|
4025
4114
|
if (unless.renders !== void 0 && !isStringList2(unless.renders)) fail(`${at}.unless.renders must be a list of component names`);
|
|
4115
|
+
if (unless.inside !== void 0 && !(isStringList2(unless.inside) && unless.inside.every((n) => /^[A-Z][\w.]*$/.test(n)))) fail(`${at}.unless.inside must be a list of component names`);
|
|
4026
4116
|
if (unless.pattern !== void 0) checkPattern(unless.pattern, `${at}.unless.pattern`, fail);
|
|
4027
4117
|
}
|
|
4028
4118
|
return raw;
|
|
@@ -4140,6 +4230,7 @@ function compile(rule, setting, routes) {
|
|
|
4140
4230
|
imports: (rule.forbid.imports ?? []).map(specMatcher),
|
|
4141
4231
|
...rule.forbid.pattern ? { pattern: toRegExp2(rule.forbid.pattern, "g") } : {},
|
|
4142
4232
|
unlessRenders: new Set(rule.unless?.renders ?? []),
|
|
4233
|
+
unlessInside: new Set(rule.unless?.inside ?? []),
|
|
4143
4234
|
...rule.unless?.pattern ? { unlessPattern: toRegExp2(rule.unless.pattern) } : {}
|
|
4144
4235
|
};
|
|
4145
4236
|
}
|
|
@@ -4151,10 +4242,11 @@ function messageFor(rule, found) {
|
|
|
4151
4242
|
const docs = rule.docs ? ` See ${rule.docs}` : "";
|
|
4152
4243
|
return `${found}; use ${rule.use}${from}. ${rule.why}${docs}`;
|
|
4153
4244
|
}
|
|
4245
|
+
var CHILDREN = /\{\s*(?:props\.)?children\s*\}/g;
|
|
4154
4246
|
var TOP_LEVEL = /^(export\s+(default\s+)?)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([\w$]+)/gm;
|
|
4155
4247
|
var EXPORT_LIST = /\bexport\s*\{([^}]*)\}(?!\s*from)/g;
|
|
4156
4248
|
var EXPORT_DEFAULT_NAME = /^export\s+default\s+([A-Z][\w$]*)\s*;?\s*$/gm;
|
|
4157
|
-
function wrappersIn(file, elements,
|
|
4249
|
+
function wrappersIn(file, elements, names, accept) {
|
|
4158
4250
|
const out = /* @__PURE__ */ new Map();
|
|
4159
4251
|
const decls = [...file.code.matchAll(TOP_LEVEL)];
|
|
4160
4252
|
const listed = /* @__PURE__ */ new Map();
|
|
@@ -4167,12 +4259,12 @@ function wrappersIn(file, elements, c) {
|
|
|
4167
4259
|
for (const m of file.code.matchAll(EXPORT_DEFAULT_NAME)) listed.set(m[1], [...listed.get(m[1]) ?? [], "default"]);
|
|
4168
4260
|
decls.forEach((d, i) => {
|
|
4169
4261
|
const name = d[3];
|
|
4170
|
-
if (!/^[A-Z]/.test(name) ||
|
|
4262
|
+
if (!/^[A-Z]/.test(name) || names.has(name)) return;
|
|
4171
4263
|
const end = decls[i + 1]?.index ?? file.code.length;
|
|
4172
|
-
const hit = elements.find((m) => m.index > d.index && m.index < end &&
|
|
4173
|
-
if (!hit) return;
|
|
4174
|
-
const
|
|
4175
|
-
for (const n of
|
|
4264
|
+
const hit = elements.find((m) => m.index > d.index && m.index < end && names.has(m[1]));
|
|
4265
|
+
if (!hit || accept && !accept(d.index, end)) return;
|
|
4266
|
+
const exported = [...d[1] ? [d[2] ? "default" : name] : [], ...listed.get(name) ?? []];
|
|
4267
|
+
for (const n of exported) out.set(n, hit[1]);
|
|
4176
4268
|
});
|
|
4177
4269
|
return out;
|
|
4178
4270
|
}
|
|
@@ -4180,6 +4272,32 @@ function runPrefer(ctx, c) {
|
|
|
4180
4272
|
const own = c.rule.packageDir;
|
|
4181
4273
|
const checked = ctx.files.filter((file) => SCRIPT.has(file.ext) && c.includes(file.path) && !c.excludes(file.path) && !inside(own, file.absolutePath));
|
|
4182
4274
|
const exempt = (file, rendered) => rendered.some((n) => c.unlessRenders.has(n)) || (c.unlessPattern?.test(file.code) ?? false);
|
|
4275
|
+
const scanned = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
4276
|
+
const importedBy = /* @__PURE__ */ new Map();
|
|
4277
|
+
const importsOf = (file) => {
|
|
4278
|
+
if (!importedBy.has(file)) importedBy.set(file, localImportedNames(ctx.root, file));
|
|
4279
|
+
return importedBy.get(file);
|
|
4280
|
+
};
|
|
4281
|
+
const builders = /* @__PURE__ */ new Map();
|
|
4282
|
+
const buildersIn = (abs) => {
|
|
4283
|
+
if (!builders.has(abs)) {
|
|
4284
|
+
const target = scanned.get(abs) ?? readSource(abs);
|
|
4285
|
+
const code = target ? "ext" in target ? target.code : stripBlockComments(target.code, true) : "";
|
|
4286
|
+
const childrenInside = (start, end) => [...code.slice(start, end).matchAll(CHILDREN)].some((m) => openElementsAt(code, start + m.index, (n) => c.unlessInside.has(n)).length > 0);
|
|
4287
|
+
builders.set(abs, code ? wrappersIn({ code }, [...code.matchAll(ELEMENT)], c.unlessInside, childrenInside) : /* @__PURE__ */ new Map());
|
|
4288
|
+
}
|
|
4289
|
+
return builders.get(abs);
|
|
4290
|
+
};
|
|
4291
|
+
const nestedInBuilder = (file, index) => {
|
|
4292
|
+
if (!c.unlessInside.size) return false;
|
|
4293
|
+
const imported = importsOf(file);
|
|
4294
|
+
const isBuilder = (name) => {
|
|
4295
|
+
if (c.unlessInside.has(name)) return true;
|
|
4296
|
+
const from = name.includes(".") ? void 0 : imported.get(name);
|
|
4297
|
+
return from !== void 0 && buildersIn(from.file).has(from.name);
|
|
4298
|
+
};
|
|
4299
|
+
return openElementsAt(file.code, index, isBuilder).length > 0;
|
|
4300
|
+
};
|
|
4183
4301
|
const wrappers = /* @__PURE__ */ new Map();
|
|
4184
4302
|
const renderedBy = /* @__PURE__ */ new Map();
|
|
4185
4303
|
for (const file of checked) {
|
|
@@ -4187,16 +4305,17 @@ function runPrefer(ctx, c) {
|
|
|
4187
4305
|
const elements = [...file.code.matchAll(ELEMENT)];
|
|
4188
4306
|
renderedBy.set(file, elements);
|
|
4189
4307
|
if (!c.jsx.size || exempt(file, elements.map((m) => m[1]))) continue;
|
|
4190
|
-
const found = wrappersIn(file, elements, c);
|
|
4308
|
+
const found = wrappersIn(file, elements, c.jsx);
|
|
4191
4309
|
if (found.size) wrappers.set(file.absolutePath, found);
|
|
4192
4310
|
}
|
|
4193
4311
|
for (const file of checked) {
|
|
4194
4312
|
const elements = renderedBy.get(file) ?? [];
|
|
4195
4313
|
if (exempt(file, elements.map((m) => m[1]))) continue;
|
|
4196
4314
|
const report = (line, subject, found) => ctx.report({ rule: c.rule.ruleId, level: c.level, file: file.path, line, subject, message: messageFor(c.rule, found) });
|
|
4197
|
-
const imported = wrappers.size && elements.length ?
|
|
4315
|
+
const imported = wrappers.size && elements.length ? importsOf(file) : null;
|
|
4198
4316
|
for (const m of elements) {
|
|
4199
4317
|
const name = m[1];
|
|
4318
|
+
if (nestedInBuilder(file, m.index)) continue;
|
|
4200
4319
|
if (c.jsx.has(name)) {
|
|
4201
4320
|
report(lineAt(file.code, m.index), name, `renders <${name}>`);
|
|
4202
4321
|
continue;
|
|
@@ -4213,6 +4332,7 @@ function runPrefer(ctx, c) {
|
|
|
4213
4332
|
if (c.pattern) {
|
|
4214
4333
|
c.pattern.lastIndex = 0;
|
|
4215
4334
|
for (const m of file.code.matchAll(c.pattern)) {
|
|
4335
|
+
if (nestedInBuilder(file, m.index)) continue;
|
|
4216
4336
|
const text = m[0].trim().replace(/\s+/g, " ").slice(0, 60);
|
|
4217
4337
|
report(lineAt(file.code, m.index), text, `has ${text}`);
|
|
4218
4338
|
}
|
|
@@ -4860,6 +4980,67 @@ function checkSupabasePack(ctx) {
|
|
|
4860
4980
|
checkViewInvoker(ctx, migrations, exposed);
|
|
4861
4981
|
checkDefinerSearchPath(ctx, migrations);
|
|
4862
4982
|
checkTestingKit(ctx, migrations);
|
|
4983
|
+
checkExposedSchemasCreatedLater(ctx, dir, migrations, settings.exposedSchemas, settings.automaticBranching !== false);
|
|
4984
|
+
}
|
|
4985
|
+
var PLATFORM_SCHEMAS = /* @__PURE__ */ new Set(["public", "graphql_public", "graphql", "extensions", "storage", "auth", "realtime", "vault"]);
|
|
4986
|
+
function apiSchemas(toml) {
|
|
4987
|
+
const lines = toml.split("\n");
|
|
4988
|
+
const start = lines.findIndex((l) => /^\s*\[api\]\s*(?:#.*)?$/.test(l));
|
|
4989
|
+
if (start < 0) return null;
|
|
4990
|
+
let end = lines.findIndex((l, i) => i > start && /^\s*\[/.test(l));
|
|
4991
|
+
if (end < 0) end = lines.length;
|
|
4992
|
+
const bare = (l) => {
|
|
4993
|
+
let quoted = false;
|
|
4994
|
+
for (let i = 0; i < l.length; i++) {
|
|
4995
|
+
if (l[i] === '"' && l[i - 1] !== "\\") quoted = !quoted;
|
|
4996
|
+
else if (l[i] === "#" && !quoted) return l.slice(0, i);
|
|
4997
|
+
}
|
|
4998
|
+
return l;
|
|
4999
|
+
};
|
|
5000
|
+
const body = lines.slice(start + 1, end).map(bare);
|
|
5001
|
+
const enabled = !body.some((l) => /^\s*enabled\s*=\s*false\b/.test(l));
|
|
5002
|
+
const at = body.findIndex((l) => /^\s*schemas\s*=/.test(l));
|
|
5003
|
+
if (at < 0) return { enabled, schemas: [], line: start + 1 };
|
|
5004
|
+
let list = "";
|
|
5005
|
+
for (let i = at; i < body.length; i++) {
|
|
5006
|
+
list += `${body[i]}
|
|
5007
|
+
`;
|
|
5008
|
+
if (body[i].includes("]")) break;
|
|
5009
|
+
}
|
|
5010
|
+
const inner = /\[([\s\S]*?)\]/.exec(list)?.[1] ?? "";
|
|
5011
|
+
const schemas = [...inner.matchAll(/"((?:[^"\\]|\\.)*)"|'([^']*)'/g)].map((m) => (m[1] ?? m[2]).trim().toLowerCase()).filter(Boolean);
|
|
5012
|
+
return { enabled, schemas, line: start + at + 2 };
|
|
5013
|
+
}
|
|
5014
|
+
function checkExposedSchemasCreatedLater(ctx, dir, migrations, configured, branching) {
|
|
5015
|
+
const created = /* @__PURE__ */ new Map();
|
|
5016
|
+
for (const { file, statements } of migrations) {
|
|
5017
|
+
for (const { sql, line } of statements) {
|
|
5018
|
+
const m = /^create schema (?:if not exists )?"?([\w$]+)"?/.exec(sql);
|
|
5019
|
+
if (m && m[1] !== "authorization" && !created.has(m[1])) created.set(m[1], { file, line });
|
|
5020
|
+
}
|
|
5021
|
+
}
|
|
5022
|
+
const tomlFile = path21.posix.join(path21.posix.dirname(dir), "config.toml");
|
|
5023
|
+
const tomlText = existsSync(path21.join(ctx.root, tomlFile)) ? readFileSync(path21.join(ctx.root, tomlFile), "utf8") : null;
|
|
5024
|
+
const api2 = tomlText === null ? null : apiSchemas(tomlText);
|
|
5025
|
+
const sources = [];
|
|
5026
|
+
if (api2?.enabled) for (const schema of api2.schemas) sources.push({ schema, file: tomlFile, line: api2.line, where: `${tomlFile} [api] schemas` });
|
|
5027
|
+
for (const schema of api2?.enabled === false ? [] : configured ?? []) {
|
|
5028
|
+
const s = schema.toLowerCase();
|
|
5029
|
+
if (!sources.some((x) => x.schema === s)) sources.push({ schema: s, file: "genesis.config.json", where: "doctor.supabase.exposedSchemas" });
|
|
5030
|
+
}
|
|
5031
|
+
for (const { schema, file, line, where: where2 } of sources) {
|
|
5032
|
+
if (PLATFORM_SCHEMAS.has(schema)) continue;
|
|
5033
|
+
const by = created.get(schema);
|
|
5034
|
+
if (by && !branching) continue;
|
|
5035
|
+
ctx.report({
|
|
5036
|
+
rule: "exposed-schema-created-later",
|
|
5037
|
+
level: "warn",
|
|
5038
|
+
file,
|
|
5039
|
+
...line ? { line } : {},
|
|
5040
|
+
subject: schema,
|
|
5041
|
+
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`
|
|
5042
|
+
});
|
|
5043
|
+
}
|
|
4863
5044
|
}
|
|
4864
5045
|
function checkTestingKit(ctx, migrations) {
|
|
4865
5046
|
for (const { file, statements } of migrations) {
|
|
@@ -5947,13 +6128,34 @@ function git3(root, args) {
|
|
|
5947
6128
|
return r.status === 0 ? r.stdout : null;
|
|
5948
6129
|
}
|
|
5949
6130
|
function changedSince(root, base) {
|
|
5950
|
-
const mergeBase =
|
|
6131
|
+
const mergeBase = mergeBaseOf2(root, base);
|
|
5951
6132
|
if (!mergeBase) return null;
|
|
5952
6133
|
const committed = git3(root, ["diff", "-z", "--name-only", "--relative", `${mergeBase}`, "--"]);
|
|
5953
6134
|
const untracked = git3(root, ["ls-files", "-z", "--others", "--exclude-standard"]);
|
|
5954
6135
|
if (committed === null || untracked === null) return null;
|
|
5955
6136
|
return new Set([...committed.split("\0"), ...untracked.split("\0")].filter(Boolean));
|
|
5956
6137
|
}
|
|
6138
|
+
function originsSince(root, base) {
|
|
6139
|
+
const out = /* @__PURE__ */ new Map();
|
|
6140
|
+
const mergeBase = mergeBaseOf2(root, base);
|
|
6141
|
+
if (!mergeBase) return out;
|
|
6142
|
+
const diff = git3(root, ["diff", "-z", "-M", "--name-status", "--relative", mergeBase, "--"]);
|
|
6143
|
+
if (diff === null) return out;
|
|
6144
|
+
const parts = diff.split("\0");
|
|
6145
|
+
for (let i = 0; i < parts.length; ) {
|
|
6146
|
+
const status = parts[i++] ?? "";
|
|
6147
|
+
if (!status) continue;
|
|
6148
|
+
if (status.startsWith("R") || status.startsWith("C")) {
|
|
6149
|
+
const from = parts[i++];
|
|
6150
|
+
const to = parts[i++];
|
|
6151
|
+
if (status.startsWith("R")) out.set(to, from);
|
|
6152
|
+
} else i++;
|
|
6153
|
+
}
|
|
6154
|
+
return out;
|
|
6155
|
+
}
|
|
6156
|
+
function mergeBaseOf2(root, base) {
|
|
6157
|
+
return git3(root, ["merge-base", base, "HEAD"])?.trim() || null;
|
|
6158
|
+
}
|
|
5957
6159
|
var objectOr = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
5958
6160
|
function showAt(dir, rev, file) {
|
|
5959
6161
|
const at = `${rev}:./${file}`;
|
|
@@ -5961,7 +6163,7 @@ function showAt(dir, rev, file) {
|
|
|
5961
6163
|
return git3(dir, ["show", at]);
|
|
5962
6164
|
}
|
|
5963
6165
|
function configAtBase(root, base, explicitFile) {
|
|
5964
|
-
const mergeBase =
|
|
6166
|
+
const mergeBase = mergeBaseOf2(root, base);
|
|
5965
6167
|
if (!mergeBase) return null;
|
|
5966
6168
|
const candidates = explicitFile ? [{ dir: path21.dirname(explicitFile), file: path21.basename(explicitFile), explicit: true }] : [
|
|
5967
6169
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
@@ -5982,7 +6184,12 @@ function configAtBase(root, base, explicitFile) {
|
|
|
5982
6184
|
continue;
|
|
5983
6185
|
}
|
|
5984
6186
|
const b = objectOr(block);
|
|
5985
|
-
return {
|
|
6187
|
+
return {
|
|
6188
|
+
allow: Array.isArray(b.allow) ? b.allow : [],
|
|
6189
|
+
extend: Array.isArray(b.extend) ? b.extend : [],
|
|
6190
|
+
rules: objectOr(b.rules),
|
|
6191
|
+
packageRules: objectOr(b.packageRules)
|
|
6192
|
+
};
|
|
5986
6193
|
}
|
|
5987
6194
|
return "absent";
|
|
5988
6195
|
}
|
|
@@ -5996,6 +6203,16 @@ function allowGrew(allow, before, base) {
|
|
|
5996
6203
|
message: `allow gained an entry for ${a.rule}${a.match ? ` (${a.match})` : ""} since ${base}; the list only shrinks, so fix what it hides instead`
|
|
5997
6204
|
}));
|
|
5998
6205
|
}
|
|
6206
|
+
function extensionsAdded(extend, before, base) {
|
|
6207
|
+
const had = new Set(before.map((e) => `${e.rule}\0${e.file}\0${e.buildsOn}`));
|
|
6208
|
+
return extend.filter((e) => !had.has(`${e.rule}\0${e.file}\0${e.buildsOn}`)).map((e) => ({
|
|
6209
|
+
rule: "extension-added",
|
|
6210
|
+
level: "info",
|
|
6211
|
+
file: e.file,
|
|
6212
|
+
subject: e.rule,
|
|
6213
|
+
message: `extends ${e.rule} since ${base}, building on ${e.buildsOn}: "${e.reason}"${e.upstream ? ` (upstream: ${e.upstream})` : ""}; the pull request's review accepts it, and it covers only the findings the file has now`
|
|
6214
|
+
}));
|
|
6215
|
+
}
|
|
5999
6216
|
var RANK = { off: 0, info: 1, warn: 2, error: 3 };
|
|
6000
6217
|
function rulesWeakened(config, before, base) {
|
|
6001
6218
|
const out = [];
|
|
@@ -6033,14 +6250,169 @@ var NEVER_RATCHETED = /* @__PURE__ */ new Set([
|
|
|
6033
6250
|
"plugin-error",
|
|
6034
6251
|
"build",
|
|
6035
6252
|
"agent-guide-stale",
|
|
6036
|
-
"contracts-stale"
|
|
6253
|
+
"contracts-stale",
|
|
6254
|
+
"stale-extension",
|
|
6255
|
+
"extension-added"
|
|
6037
6256
|
]);
|
|
6257
|
+
function isRatcheted(rule, config, newOnly) {
|
|
6258
|
+
return !NEVER_RATCHETED.has(rule) && (config.ratchet === true || newOnly.has(rule) || Array.isArray(config.ratchet) && config.ratchet.includes(rule));
|
|
6259
|
+
}
|
|
6260
|
+
var countKey = (file, rule) => `${file}\0${rule}`;
|
|
6261
|
+
function countFindings(findings) {
|
|
6262
|
+
const counts = /* @__PURE__ */ new Map();
|
|
6263
|
+
for (const f of findings) counts.set(countKey(f.file, f.rule), (counts.get(countKey(f.file, f.rule)) ?? 0) + 1);
|
|
6264
|
+
return counts;
|
|
6265
|
+
}
|
|
6038
6266
|
function applyRatchet(findings, options) {
|
|
6039
|
-
const { config, newOnly, changed, base, isAppPath } = options;
|
|
6040
|
-
const
|
|
6267
|
+
const { config, newOnly, changed, base, isAppPath, baseCounts, existedAtBase } = options;
|
|
6268
|
+
const originOf = options.originOf ?? ((f) => f);
|
|
6269
|
+
const counts = countFindings(findings.map((f) => ({ file: originOf(f.file), rule: f.rule })));
|
|
6041
6270
|
return findings.map((f) => {
|
|
6042
|
-
if (f.level === "info" || !
|
|
6043
|
-
return { ...f, level: "info", message: `${f.message} (ratcheted: unchanged since ${base})` };
|
|
6271
|
+
if (f.level === "info" || !isRatcheted(f.rule, config, newOnly) || !isAppPath(f.file)) return f;
|
|
6272
|
+
if (!touched(f.file, changed)) return { ...f, level: "info", message: `${f.message} (ratcheted: unchanged since ${base})` };
|
|
6273
|
+
const origin = originOf(f.file);
|
|
6274
|
+
if (!baseCounts || !existedAtBase?.(origin)) return f;
|
|
6275
|
+
const now = counts.get(countKey(origin, f.rule)) ?? 0;
|
|
6276
|
+
const was = baseCounts.get(countKey(origin, f.rule)) ?? 0;
|
|
6277
|
+
const where2 = origin === f.file ? "this file" : `the files from ${origin}`;
|
|
6278
|
+
if (now > was) return { ...f, message: `${f.message} (${now} ${f.rule} findings in ${where2}, ${was} at the merge base with ${base}: don't add to the debt)` };
|
|
6279
|
+
return { ...f, level: "info", message: `${f.message} (ratcheted: ${now} in ${where2}, ${was} at the merge base with ${base})` };
|
|
6280
|
+
});
|
|
6281
|
+
}
|
|
6282
|
+
function snapshotAtBase(root, base, files, changed, originOf = (f) => f) {
|
|
6283
|
+
const mergeBase = mergeBaseOf2(root, base);
|
|
6284
|
+
if (!mergeBase) return null;
|
|
6285
|
+
const out = [];
|
|
6286
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6287
|
+
for (const f of files) {
|
|
6288
|
+
if (!changed.has(f.path)) {
|
|
6289
|
+
if (!seen.has(f.path)) out.push(f);
|
|
6290
|
+
seen.add(f.path);
|
|
6291
|
+
continue;
|
|
6292
|
+
}
|
|
6293
|
+
const origin = originOf(f.path);
|
|
6294
|
+
if (seen.has(origin)) continue;
|
|
6295
|
+
seen.add(origin);
|
|
6296
|
+
const text = showAt(root, mergeBase, origin);
|
|
6297
|
+
if (text === null) return null;
|
|
6298
|
+
if (text !== void 0) out.push(withText({ ...f, path: origin, absolutePath: path21.join(root, origin) }, text));
|
|
6299
|
+
}
|
|
6300
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
6301
|
+
return {
|
|
6302
|
+
mergeBase,
|
|
6303
|
+
files: out,
|
|
6304
|
+
existed(file) {
|
|
6305
|
+
if (!cache2.has(file)) cache2.set(file, git3(root, ["cat-file", "-e", `${mergeBase}:./${file}`]) !== null);
|
|
6306
|
+
return cache2.get(file);
|
|
6307
|
+
}
|
|
6308
|
+
};
|
|
6309
|
+
}
|
|
6310
|
+
|
|
6311
|
+
// src/doctor/extensions.ts
|
|
6312
|
+
function pointProblem(entry, packages) {
|
|
6313
|
+
const rule = preferRules(packages).find((r) => r.ruleId === entry.rule);
|
|
6314
|
+
if (!rule?.extensible?.length) return `${entry.rule} declares no extension points, so it can't be extended (debt goes in allow, and is fixed)`;
|
|
6315
|
+
if (!rule.extensible.includes(entry.buildsOn)) return `${entry.buildsOn} isn't one of ${entry.rule}'s extension points (${rule.extensible.join(", ")})`;
|
|
6316
|
+
return null;
|
|
6317
|
+
}
|
|
6318
|
+
function extensionProblem(entry, ctx) {
|
|
6319
|
+
const point = pointProblem(entry, ctx.packages);
|
|
6320
|
+
if (point) return point;
|
|
6321
|
+
const name = entry.buildsOn.split(".")[0];
|
|
6322
|
+
const replaces = preferRules(ctx.packages).find((r) => r.forbid.jsx?.includes(name));
|
|
6323
|
+
if (replaces) return `${name} is what ${replaces.ruleId} replaces (use ${replaces.use}); a legacy component can't be built on`;
|
|
6324
|
+
const flagged = ctx.raw.find((f) => f.file === entry.file && f.subject === name);
|
|
6325
|
+
if (flagged) return `${name} is flagged in this file by ${flagged.rule}; build on a current Genesis primitive`;
|
|
6326
|
+
const file = ctx.files.find((f) => f.path === entry.file);
|
|
6327
|
+
if (!file) return `${entry.file} isn't one of the files the doctor scans`;
|
|
6328
|
+
const imported = genesisNamedImports(file.code).some((i) => i.names.includes(name));
|
|
6329
|
+
if (!imported) return `${entry.file} doesn't import ${name} from a Genesis package; buildsOn names the extension point the file uses`;
|
|
6330
|
+
if (!usesPoint(blankStrings(file.code), entry.buildsOn)) {
|
|
6331
|
+
const prop = entry.buildsOn.split(".")[1];
|
|
6332
|
+
return prop ? `${entry.file} doesn't pass ${prop} to <${name}>; an extension point is one the file uses` : `${entry.file} imports ${name} but doesn't render or call it; an extension point is one the file uses`;
|
|
6333
|
+
}
|
|
6334
|
+
return null;
|
|
6335
|
+
}
|
|
6336
|
+
var escape2 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6337
|
+
function usesPoint(code, point) {
|
|
6338
|
+
const [name, prop] = point.split(".");
|
|
6339
|
+
const n = escape2(name);
|
|
6340
|
+
if (!prop) return new RegExp(`(?<![\\w$.])<${n}(?=[\\s>/<])|(?<![\\w$.])${n}\\s*(?:<[^>()]*>)?\\s*\\(`).test(code);
|
|
6341
|
+
for (const m of code.matchAll(new RegExp(`(?<![\\w$.])<${n}(?=[\\s>/<])`, "g"))) {
|
|
6342
|
+
const { end } = tagEnd(code, m.index);
|
|
6343
|
+
if (new RegExp(`(?<![\\w$.])${escape2(prop)}\\s*=`).test(code.slice(m.index, end))) return true;
|
|
6344
|
+
}
|
|
6345
|
+
return false;
|
|
6346
|
+
}
|
|
6347
|
+
function applyExtensions(findings, ctx) {
|
|
6348
|
+
const entries = ctx.config.extend ?? [];
|
|
6349
|
+
if (!entries.length) return findings;
|
|
6350
|
+
const staleLevel = ctx.config.rules?.["stale-extension"];
|
|
6351
|
+
const covered = /* @__PURE__ */ new Set();
|
|
6352
|
+
const grew = /* @__PURE__ */ new Map();
|
|
6353
|
+
const out = [];
|
|
6354
|
+
const invalid = (entry, problem) => out.push({ rule: "extension-invalid", level: "error", file: entry.file, line: 0, subject: entry.rule, message: `the extension of ${entry.rule} isn't accepted: ${problem}` });
|
|
6355
|
+
for (const entry of entries) {
|
|
6356
|
+
if (ctx.config.rules?.[entry.rule] === "off" || ctx.config.packageRules?.[entry.rule]?.level === "off") continue;
|
|
6357
|
+
const point = pointProblem(entry, ctx.packages);
|
|
6358
|
+
if (point) {
|
|
6359
|
+
invalid(entry, point);
|
|
6360
|
+
continue;
|
|
6361
|
+
}
|
|
6362
|
+
const hits = findings.filter((f) => f.rule === entry.rule && f.file === entry.file);
|
|
6363
|
+
if (!hits.length) {
|
|
6364
|
+
if (staleLevel === "off") continue;
|
|
6365
|
+
out.push({
|
|
6366
|
+
rule: "stale-extension",
|
|
6367
|
+
level: staleLevel ?? "warn",
|
|
6368
|
+
file: entry.file,
|
|
6369
|
+
line: 0,
|
|
6370
|
+
subject: entry.rule,
|
|
6371
|
+
message: `the extension of ${entry.rule} (building on ${entry.buildsOn}) no longer matches a finding in this file; remove it from doctor.extend`
|
|
6372
|
+
});
|
|
6373
|
+
continue;
|
|
6374
|
+
}
|
|
6375
|
+
const problem = extensionProblem(entry, ctx);
|
|
6376
|
+
if (problem) {
|
|
6377
|
+
invalid(entry, problem);
|
|
6378
|
+
continue;
|
|
6379
|
+
}
|
|
6380
|
+
const limit = ctx.limit?.(entry);
|
|
6381
|
+
if (limit !== void 0 && hits.length > limit) {
|
|
6382
|
+
for (const h of hits) grew.set(h, `${h.message} (the extension of ${entry.rule} here covers the ${limit} at the merge base; this file now has ${hits.length}, so they all count)`);
|
|
6383
|
+
continue;
|
|
6384
|
+
}
|
|
6385
|
+
for (const h of hits) covered.add(h);
|
|
6386
|
+
}
|
|
6387
|
+
const kept = findings.filter((f) => !covered.has(f)).map((f) => grew.has(f) ? { ...f, message: grew.get(f) } : f);
|
|
6388
|
+
return [...kept, ...out].sort(byPlace);
|
|
6389
|
+
}
|
|
6390
|
+
var byPlace = (x, y) => x.file.localeCompare(y.file) || x.line - y.line || x.rule.localeCompare(y.rule);
|
|
6391
|
+
var RANK2 = { info: 0, warn: 1, error: 2 };
|
|
6392
|
+
function dedupeFindings(findings) {
|
|
6393
|
+
const groups = /* @__PURE__ */ new Map();
|
|
6394
|
+
const order = [];
|
|
6395
|
+
for (const f of findings) {
|
|
6396
|
+
if (f.subject === void 0 || !f.line) {
|
|
6397
|
+
order.push([f]);
|
|
6398
|
+
continue;
|
|
6399
|
+
}
|
|
6400
|
+
const key2 = `${f.file}\0${f.line}\0${f.subject}`;
|
|
6401
|
+
const list = groups.get(key2) ?? [];
|
|
6402
|
+
const group = list.find((g) => !g.some((x) => x.rule === f.rule));
|
|
6403
|
+
if (group) group.push(f);
|
|
6404
|
+
else {
|
|
6405
|
+
const fresh = [f];
|
|
6406
|
+
list.push(fresh);
|
|
6407
|
+
groups.set(key2, list);
|
|
6408
|
+
order.push(fresh);
|
|
6409
|
+
}
|
|
6410
|
+
}
|
|
6411
|
+
return order.map((group) => {
|
|
6412
|
+
if (group.length === 1) return group[0];
|
|
6413
|
+
const primary = group.reduce((a, b) => RANK2[b.level] > RANK2[a.level] ? b : a);
|
|
6414
|
+
const rules = [primary.rule, ...group.filter((g) => g !== primary).map((g) => g.rule)];
|
|
6415
|
+
return { ...primary, rules, message: `${primary.message} (also ${rules.slice(1).join(", ")})` };
|
|
6044
6416
|
});
|
|
6045
6417
|
}
|
|
6046
6418
|
var DEFAULT_CONTRACT_OUT = "resources.genesis.ts";
|
|
@@ -6110,6 +6482,20 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
6110
6482
|
}
|
|
6111
6483
|
}
|
|
6112
6484
|
var GENESIS_DOCS = "https://github.com/marktiderman/genesis/blob/main/docs";
|
|
6485
|
+
var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
6486
|
+
var CLAUDE_IMPORT = "@AGENTS.md\n";
|
|
6487
|
+
function pathTaken(file) {
|
|
6488
|
+
try {
|
|
6489
|
+
lstatSync(file);
|
|
6490
|
+
return true;
|
|
6491
|
+
} catch {
|
|
6492
|
+
try {
|
|
6493
|
+
return readdirSync(path21.dirname(file)).some((n) => n.toLowerCase() === path21.basename(file).toLowerCase());
|
|
6494
|
+
} catch {
|
|
6495
|
+
return false;
|
|
6496
|
+
}
|
|
6497
|
+
}
|
|
6498
|
+
}
|
|
6113
6499
|
var CORE = [
|
|
6114
6500
|
{
|
|
6115
6501
|
need: "anything, before building it",
|
|
@@ -6192,14 +6578,82 @@ var SKILL_PATH = ".claude/skills/genesis/SKILL.md";
|
|
|
6192
6578
|
var AGENTS_START = "<!-- genesis-primitives:start -->";
|
|
6193
6579
|
var AGENTS_END = "<!-- genesis-primitives:end -->";
|
|
6194
6580
|
var RULES = [
|
|
6195
|
-
|
|
6581
|
+
`Use the Genesis primitive for the need first: reuse, then extend, then invent (G1 to G6 in ${GENESIS_DOCS}/FRAMEWORK.md).`,
|
|
6196
6582
|
"Never copy an older screen as a template. Old screens predate the primitives; the doctor flags what they did.",
|
|
6197
6583
|
"A list screen is a view (`defineView`) rendered by `ResourceView`; a record view is `RecordView`; on the phone, `NativeResourceView`.",
|
|
6198
6584
|
"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.",
|
|
6199
6585
|
"When no primitive fits, write the gap up for Genesis before inventing, then invent in the app on Genesis primitives.",
|
|
6200
6586
|
"Run `genesis doctor` before you finish; it enforces these rules."
|
|
6201
6587
|
];
|
|
6202
|
-
function
|
|
6588
|
+
function skillDescription(text) {
|
|
6589
|
+
const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)?.[1];
|
|
6590
|
+
if (!fm) return "";
|
|
6591
|
+
const lines = fm.split(/\r?\n/);
|
|
6592
|
+
const i = lines.findIndex((l) => /^description:/.test(l));
|
|
6593
|
+
if (i < 0) return "";
|
|
6594
|
+
const first = lines[i].replace(/^description:\s*/, "").trim();
|
|
6595
|
+
if (first && !/^[>|][+-]?$/.test(first)) return first.replace(/^["']|["']$/g, "");
|
|
6596
|
+
const more = [];
|
|
6597
|
+
for (const l of lines.slice(i + 1)) {
|
|
6598
|
+
if (!/^\s+\S/.test(l)) break;
|
|
6599
|
+
more.push(l.trim());
|
|
6600
|
+
}
|
|
6601
|
+
return more.join(" ");
|
|
6602
|
+
}
|
|
6603
|
+
var GUIDE_SEARCH_LEVELS = 4;
|
|
6604
|
+
function stableGuidePath(root, p) {
|
|
6605
|
+
const real2 = (f) => {
|
|
6606
|
+
try {
|
|
6607
|
+
return realpathSync(f);
|
|
6608
|
+
} catch {
|
|
6609
|
+
return null;
|
|
6610
|
+
}
|
|
6611
|
+
};
|
|
6612
|
+
const want = real2(p.dir);
|
|
6613
|
+
for (let dir = root, level = 0; level <= GUIDE_SEARCH_LEVELS; level++) {
|
|
6614
|
+
const found = path21.join(dir, "node_modules", p.name);
|
|
6615
|
+
if (existsSync(found)) {
|
|
6616
|
+
const file = path21.join(found, "SKILL.md");
|
|
6617
|
+
return want !== null && real2(found) === want && existsSync(file) ? file : null;
|
|
6618
|
+
}
|
|
6619
|
+
if (existsSync(path21.join(dir, ".git")) || existsSync(path21.join(dir, "pnpm-workspace.yaml"))) return null;
|
|
6620
|
+
const up = path21.dirname(dir);
|
|
6621
|
+
if (up === dir) return null;
|
|
6622
|
+
dir = up;
|
|
6623
|
+
}
|
|
6624
|
+
return null;
|
|
6625
|
+
}
|
|
6626
|
+
function packageGuides(root, packages) {
|
|
6627
|
+
const guides = [];
|
|
6628
|
+
for (const p of packages) {
|
|
6629
|
+
const stable = p.local ? path21.join(p.dir, "SKILL.md") : stableGuidePath(root, p);
|
|
6630
|
+
const text = stable === null ? null : read(stable);
|
|
6631
|
+
if (stable === null || text === null) continue;
|
|
6632
|
+
const description = skillDescription(text);
|
|
6633
|
+
const at = description.indexOf("Load before");
|
|
6634
|
+
guides.push({ package: p.name, path: path21.relative(root, stable).split(path21.sep).join("/"), when: at >= 0 ? description.slice(at) : description });
|
|
6635
|
+
}
|
|
6636
|
+
return guides.sort((a, b) => a.package.localeCompare(b.package));
|
|
6637
|
+
}
|
|
6638
|
+
function unlistedGuides(root, packages) {
|
|
6639
|
+
const listed = new Set(packageGuides(root, packages).map((g) => g.package));
|
|
6640
|
+
return packages.filter((p) => !p.local && !listed.has(p.name) && existsSync(path21.join(p.dir, "SKILL.md"))).map((p) => p.name).sort();
|
|
6641
|
+
}
|
|
6642
|
+
function guidesSection(guides) {
|
|
6643
|
+
if (!guides.length) return [];
|
|
6644
|
+
return [
|
|
6645
|
+
"### Package guides (they match the installed versions)",
|
|
6646
|
+
"",
|
|
6647
|
+
"Before using a package's primitives, read its guide:",
|
|
6648
|
+
"",
|
|
6649
|
+
...guides.map((g) => `- \`${g.path}\` (${g.package}): ${g.when}`),
|
|
6650
|
+
""
|
|
6651
|
+
];
|
|
6652
|
+
}
|
|
6653
|
+
function agentRules() {
|
|
6654
|
+
return RULES;
|
|
6655
|
+
}
|
|
6656
|
+
function renderSkill(rows, guides = []) {
|
|
6203
6657
|
return [
|
|
6204
6658
|
"---",
|
|
6205
6659
|
"name: genesis",
|
|
@@ -6212,6 +6666,7 @@ function renderSkill(rows) {
|
|
|
6212
6666
|
"",
|
|
6213
6667
|
...RULES.map((r) => `- ${r}`),
|
|
6214
6668
|
"",
|
|
6669
|
+
...guidesSection(guides),
|
|
6215
6670
|
"## What to use for each need",
|
|
6216
6671
|
"",
|
|
6217
6672
|
catalogTable(rows, { docs: true }),
|
|
@@ -6220,7 +6675,7 @@ function renderSkill(rows) {
|
|
|
6220
6675
|
""
|
|
6221
6676
|
].join("\n");
|
|
6222
6677
|
}
|
|
6223
|
-
function renderAgentsBlock(rows) {
|
|
6678
|
+
function renderAgentsBlock(rows, guides = []) {
|
|
6224
6679
|
return [
|
|
6225
6680
|
AGENTS_START,
|
|
6226
6681
|
"## Building with Genesis",
|
|
@@ -6231,6 +6686,7 @@ function renderAgentsBlock(rows) {
|
|
|
6231
6686
|
"",
|
|
6232
6687
|
...RULES.map((r) => `- ${r}`),
|
|
6233
6688
|
"",
|
|
6689
|
+
...guidesSection(guides),
|
|
6234
6690
|
catalogTable(rows),
|
|
6235
6691
|
AGENTS_END
|
|
6236
6692
|
].join("\n");
|
|
@@ -6258,15 +6714,15 @@ function currentAgentsBlock(agents) {
|
|
|
6258
6714
|
if (span === "broken") return "broken";
|
|
6259
6715
|
return agents.slice(span.start, span.end).replace(/\r\n/g, "\n");
|
|
6260
6716
|
}
|
|
6261
|
-
var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
6262
6717
|
function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
6263
6718
|
const rows = primitivesCatalog(packages);
|
|
6719
|
+
const guides = packageGuides(root, packages);
|
|
6264
6720
|
const changed = [];
|
|
6265
6721
|
const agents = path21.join(root, agentsFile);
|
|
6266
6722
|
const before = read(agents);
|
|
6267
|
-
const after = mergeAgentsBlock(before, renderAgentsBlock(rows));
|
|
6723
|
+
const after = mergeAgentsBlock(before, renderAgentsBlock(rows, guides));
|
|
6268
6724
|
const skill = path21.join(root, SKILL_PATH);
|
|
6269
|
-
const skillText = renderSkill(rows);
|
|
6725
|
+
const skillText = renderSkill(rows, guides);
|
|
6270
6726
|
if (read(skill)?.replace(/\r\n/g, "\n") !== skillText) {
|
|
6271
6727
|
mkdirSync(path21.dirname(skill), { recursive: true });
|
|
6272
6728
|
writeFileSync(skill, skillText);
|
|
@@ -6276,15 +6732,44 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
6276
6732
|
writeFileSync(agents, after);
|
|
6277
6733
|
changed.push(agentsFile);
|
|
6278
6734
|
}
|
|
6735
|
+
const claude = path21.join(root, "CLAUDE.md");
|
|
6736
|
+
if (agentsFile === "AGENTS.md" && !pathTaken(claude)) {
|
|
6737
|
+
writeFileSync(claude, CLAUDE_IMPORT);
|
|
6738
|
+
changed.push("CLAUDE.md");
|
|
6739
|
+
}
|
|
6279
6740
|
return changed;
|
|
6280
6741
|
}
|
|
6742
|
+
function claudeState(root) {
|
|
6743
|
+
const file = path21.join(root, "CLAUDE.md");
|
|
6744
|
+
let names = [];
|
|
6745
|
+
try {
|
|
6746
|
+
names = readdirSync(root);
|
|
6747
|
+
} catch {
|
|
6748
|
+
}
|
|
6749
|
+
if (!names.includes("CLAUDE.md")) return names.some((n) => n.toLowerCase() === "claude.md") ? "blocked" : "missing";
|
|
6750
|
+
let text;
|
|
6751
|
+
try {
|
|
6752
|
+
text = readFileSync(file, "utf8");
|
|
6753
|
+
} catch {
|
|
6754
|
+
return "blocked";
|
|
6755
|
+
}
|
|
6756
|
+
if (/^@AGENTS\.md\b/m.test(text)) return "ok";
|
|
6757
|
+
try {
|
|
6758
|
+
if (realpathSync(file) === realpathSync(path21.join(root, "AGENTS.md"))) return "ok";
|
|
6759
|
+
} catch {
|
|
6760
|
+
}
|
|
6761
|
+
return "no-import";
|
|
6762
|
+
}
|
|
6281
6763
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
6282
6764
|
const rows = primitivesCatalog(packages);
|
|
6765
|
+
const guides = packageGuides(root, packages);
|
|
6283
6766
|
const skill = read(path21.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
6284
6767
|
const block = currentAgentsBlock(read(path21.join(root, agentsFile)));
|
|
6285
6768
|
return {
|
|
6286
|
-
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
6287
|
-
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
6769
|
+
skill: skill === null ? "missing" : skill === renderSkill(rows, guides) ? "ok" : "stale",
|
|
6770
|
+
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows, guides) ? "ok" : "stale",
|
|
6771
|
+
// Only the default AGENTS.md gets a CLAUDE.md written for it, so only then is a missing one reported.
|
|
6772
|
+
claude: agentsFile !== "AGENTS.md" ? "ok" : claudeState(root)
|
|
6288
6773
|
};
|
|
6289
6774
|
}
|
|
6290
6775
|
function checkAgentGuide(ctx) {
|
|
@@ -6302,6 +6787,104 @@ function checkAgentGuide(ctx) {
|
|
|
6302
6787
|
}[state.agents];
|
|
6303
6788
|
ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
|
|
6304
6789
|
}
|
|
6790
|
+
if (state.claude === "no-import") {
|
|
6791
|
+
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" });
|
|
6792
|
+
}
|
|
6793
|
+
if (state.claude === "missing") {
|
|
6794
|
+
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\`)` });
|
|
6795
|
+
}
|
|
6796
|
+
if (state.claude === "blocked") {
|
|
6797
|
+
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}` });
|
|
6798
|
+
}
|
|
6799
|
+
const unlisted = unlistedGuides(ctx.root, ctx.packages);
|
|
6800
|
+
if (unlisted.length) {
|
|
6801
|
+
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.` });
|
|
6802
|
+
}
|
|
6803
|
+
}
|
|
6804
|
+
var BLOCKED_FIX = "rename or replace it with a CLAUDE.md file (or remove the dangling link), then run genesis agents";
|
|
6805
|
+
var SETTINGS_PATH = ".claude/settings.json";
|
|
6806
|
+
var SUBAGENT_HOOK_COMMAND = '"$CLAUDE_PROJECT_DIR"/node_modules/.bin/genesis agents --hook subagent-start --dir "$CLAUDE_PROJECT_DIR" 2>/dev/null || true';
|
|
6807
|
+
var SUBAGENT_MATCHER = "Explore|Plan";
|
|
6808
|
+
var DENY_RULES = ["Read(./.env)", "Read(./.env.*)"];
|
|
6809
|
+
function subagentContext(root, packages) {
|
|
6810
|
+
const guides = packageGuides(root, packages);
|
|
6811
|
+
return [
|
|
6812
|
+
"This is a Genesis app. Follow these rules (the app's AGENTS.md has the full guide):",
|
|
6813
|
+
...agentRules().map((r) => `- ${r}`),
|
|
6814
|
+
...guides.length ? ["", "Package guides (they match the installed versions):", ...guides.map((g) => `- ${g.path}: ${g.when}`)] : []
|
|
6815
|
+
].join("\n");
|
|
6816
|
+
}
|
|
6817
|
+
function subagentHookOutput(root, packages) {
|
|
6818
|
+
return JSON.stringify({ hookSpecificOutput: { hookEventName: "SubagentStart", additionalContext: subagentContext(root, packages) } });
|
|
6819
|
+
}
|
|
6820
|
+
var isObject4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
6821
|
+
var isGenesisHook = (h) => typeof h.command === "string" && h.command.includes("genesis agents --hook");
|
|
6822
|
+
function checkSettingsShape(settings) {
|
|
6823
|
+
const fail = (msg) => {
|
|
6824
|
+
throw new Error(`${SETTINGS_PATH}: ${msg}; fix it by hand, then run genesis agents --hooks again.`);
|
|
6825
|
+
};
|
|
6826
|
+
if (!isObject4(settings)) fail("must be a JSON object");
|
|
6827
|
+
const s = settings;
|
|
6828
|
+
if (s.hooks !== void 0) {
|
|
6829
|
+
if (!isObject4(s.hooks)) fail('"hooks" must be an object');
|
|
6830
|
+
const start = s.hooks["SubagentStart"];
|
|
6831
|
+
if (start !== void 0) {
|
|
6832
|
+
if (!Array.isArray(start)) fail('"hooks.SubagentStart" must be a list');
|
|
6833
|
+
for (const e of start) if (!isObject4(e) || !Array.isArray(e.hooks) || !e.hooks.every(isObject4)) fail('each "hooks.SubagentStart" entry needs a "hooks" list of objects');
|
|
6834
|
+
}
|
|
6835
|
+
}
|
|
6836
|
+
if (s.permissions !== void 0) {
|
|
6837
|
+
if (!isObject4(s.permissions)) fail('"permissions" must be an object');
|
|
6838
|
+
const deny = s.permissions.deny;
|
|
6839
|
+
if (deny !== void 0 && (!Array.isArray(deny) || !deny.every((d) => typeof d === "string"))) fail('"permissions.deny" must be a list of strings');
|
|
6840
|
+
}
|
|
6841
|
+
}
|
|
6842
|
+
function mergeAgentHooks(settings) {
|
|
6843
|
+
checkSettingsShape(settings);
|
|
6844
|
+
const out = structuredClone(settings);
|
|
6845
|
+
const hooks = out.hooks ??= {};
|
|
6846
|
+
const others = (hooks["SubagentStart"] ?? []).map((e) => ({ ...e, hooks: e.hooks.filter((h) => !isGenesisHook(h)) })).filter((e) => e.hooks.length > 0);
|
|
6847
|
+
hooks["SubagentStart"] = [...others, { matcher: SUBAGENT_MATCHER, hooks: [{ type: "command", command: SUBAGENT_HOOK_COMMAND }] }];
|
|
6848
|
+
const permissions = out.permissions ??= {};
|
|
6849
|
+
const deny = permissions.deny ?? [];
|
|
6850
|
+
permissions.deny = [...deny, ...DENY_RULES.filter((r) => !deny.includes(r))];
|
|
6851
|
+
return out;
|
|
6852
|
+
}
|
|
6853
|
+
function writeAgentHooks(root) {
|
|
6854
|
+
const file = path21.join(root, SETTINGS_PATH);
|
|
6855
|
+
const before = existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
6856
|
+
let current = {};
|
|
6857
|
+
if (before !== null) {
|
|
6858
|
+
try {
|
|
6859
|
+
current = JSON.parse(before);
|
|
6860
|
+
} catch {
|
|
6861
|
+
throw new Error(`${SETTINGS_PATH} isn't valid JSON; fix it by hand, then run genesis agents --hooks again.`);
|
|
6862
|
+
}
|
|
6863
|
+
}
|
|
6864
|
+
checkSettingsShape(current);
|
|
6865
|
+
const after = `${JSON.stringify(mergeAgentHooks(current), null, 2)}
|
|
6866
|
+
`;
|
|
6867
|
+
if (before !== null && JSON.stringify(JSON.parse(before)) === JSON.stringify(JSON.parse(after))) return [];
|
|
6868
|
+
mkdirSync(path21.dirname(file), { recursive: true });
|
|
6869
|
+
writeFileSync(file, after);
|
|
6870
|
+
return [SETTINGS_PATH];
|
|
6871
|
+
}
|
|
6872
|
+
function agentHooksState(root) {
|
|
6873
|
+
let settings;
|
|
6874
|
+
try {
|
|
6875
|
+
settings = JSON.parse(readFileSync(path21.join(root, SETTINGS_PATH), "utf8"));
|
|
6876
|
+
} catch {
|
|
6877
|
+
return "none";
|
|
6878
|
+
}
|
|
6879
|
+
const start = isObject4(settings) && isObject4(settings.hooks) ? settings.hooks["SubagentStart"] : void 0;
|
|
6880
|
+
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);
|
|
6881
|
+
if (!commands.length) return "none";
|
|
6882
|
+
return commands.every((c) => c === SUBAGENT_HOOK_COMMAND) ? "ok" : "stale";
|
|
6883
|
+
}
|
|
6884
|
+
function checkAgentHooks(ctx) {
|
|
6885
|
+
if (agentHooksState(ctx.root) === "stale") {
|
|
6886
|
+
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" });
|
|
6887
|
+
}
|
|
6305
6888
|
}
|
|
6306
6889
|
|
|
6307
6890
|
// src/blocks/templates.ts
|
|
@@ -7127,14 +7710,8 @@ async function runDoctor(options = {}) {
|
|
|
7127
7710
|
}
|
|
7128
7711
|
const raw = [];
|
|
7129
7712
|
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, ...options.strict ? { strict: true } : {}, report: (f) => raw.push(f) };
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
await plugin.check(ctx);
|
|
7133
|
-
} catch (err) {
|
|
7134
|
-
if (err instanceof DoctorConfigError) throw err;
|
|
7135
|
-
raw.push({ rule: "plugin-error", file: plugin.name, message: `rule plugin "${plugin.name}" threw: ${err.message}` });
|
|
7136
|
-
}
|
|
7137
|
-
}
|
|
7713
|
+
const appChecks = [...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins];
|
|
7714
|
+
await runChecks(ctx, [...builtinChecks(config, { contracts: options.contracts ?? true, figma: options.figma ?? true }), ...appChecks]);
|
|
7138
7715
|
if (options.build) {
|
|
7139
7716
|
const failure = runBuild(root, buildCommands(root, config), options.quietBuild ?? false);
|
|
7140
7717
|
if (failure) raw.push(failure);
|
|
@@ -7144,30 +7721,57 @@ async function runDoctor(options = {}) {
|
|
|
7144
7721
|
let changed = null;
|
|
7145
7722
|
let skipped = false;
|
|
7146
7723
|
const ratchetNeeded = newOnly.size > RATCHETED_BY_DEFAULT.length || raw.some((f) => RATCHETED_BY_DEFAULT.includes(f.rule));
|
|
7147
|
-
if (options.base && (ratchetNeeded || config.ratchet)) {
|
|
7724
|
+
if (options.base && (ratchetNeeded || config.ratchet || config.extend?.length)) {
|
|
7148
7725
|
changed = options.changedFiles ? new Set(options.changedFiles) : changedSince(root, options.base);
|
|
7149
7726
|
skipped ||= !changed;
|
|
7150
7727
|
}
|
|
7151
7728
|
const configFile = "file" in loaded ? loaded.file : null;
|
|
7152
|
-
const guarded = (config.allow?.length ?? 0) + Object.keys(config.rules ?? {}).length + Object.keys(config.packageRules ?? {}).length > 0;
|
|
7729
|
+
const guarded = (config.allow?.length ?? 0) + (config.extend?.length ?? 0) + Object.keys(config.rules ?? {}).length + Object.keys(config.packageRules ?? {}).length > 0;
|
|
7153
7730
|
let configSkipped = false;
|
|
7731
|
+
let baseExtend = [];
|
|
7154
7732
|
if (options.base && configFile) {
|
|
7155
7733
|
const before = configAtBase(root, options.base, options.configPath !== void 0 ? configFile : void 0);
|
|
7734
|
+
if (before && before !== "absent") baseExtend = before.extend;
|
|
7735
|
+
if (before === "absent") raw.push(...extensionsAdded(config.extend ?? [], [], options.base));
|
|
7156
7736
|
if (before && before !== "absent") {
|
|
7157
7737
|
raw.push(...allowGrew(config.allow ?? [], before.allow, options.base));
|
|
7158
7738
|
raw.push(...rulesWeakened(config, before, options.base));
|
|
7739
|
+
raw.push(...extensionsAdded(config.extend ?? [], before.extend, options.base));
|
|
7159
7740
|
}
|
|
7160
7741
|
configSkipped = !before && guarded;
|
|
7161
7742
|
}
|
|
7162
7743
|
if (skipped || configSkipped) {
|
|
7163
7744
|
raw.push(
|
|
7164
|
-
configSkipped ? { rule: "ratchet-skipped", level: "error", file: "genesis config", message: `couldn't compare allow, rules and packageRules against ${options.base} (not a git repository, or the ref isn't fetched; in CI check out with fetch-depth: 0)` } : { rule: "ratchet-skipped", level: "warn", file: "genesis config", message: `couldn't compare against ${options.base} (not a git repository, or the ref isn't fetched); every rule ran at its full level` }
|
|
7745
|
+
configSkipped ? { rule: "ratchet-skipped", level: "error", file: "genesis config", message: `couldn't compare allow, extend, rules and packageRules against ${options.base} (not a git repository, or the ref isn't fetched; in CI check out with fetch-depth: 0)` } : { rule: "ratchet-skipped", level: "warn", file: "genesis config", message: `couldn't compare against ${options.base} (not a git repository, or the ref isn't fetched); every rule ran at its full level` }
|
|
7165
7746
|
);
|
|
7166
7747
|
}
|
|
7167
|
-
|
|
7748
|
+
const packageIds = packageRuleIds(packages);
|
|
7749
|
+
const extensionCtx = { config, files, packages, raw };
|
|
7750
|
+
const configured = applyConfig(raw, config, packageIds);
|
|
7751
|
+
let findings = applyExtensions(configured, extensionCtx);
|
|
7168
7752
|
if (options.base && changed) {
|
|
7169
|
-
|
|
7753
|
+
const isAppPath = (f) => existsSync(path21.join(root, f));
|
|
7754
|
+
const origins = options.changedFiles ? /* @__PURE__ */ new Map() : originsSince(root, options.base);
|
|
7755
|
+
const originOf = (f) => origins.get(f) ?? f;
|
|
7756
|
+
const dueRules = new Set(findings.filter((f) => f.level !== "info" && isRatcheted(f.rule, config, newOnly) && isAppPath(f.file) && touched(f.file, changed)).map((f) => f.rule));
|
|
7757
|
+
const heldExtensions = (config.extend ?? []).filter((e) => touched(e.file, changed) && baseExtend.some((b) => b.rule === e.rule && (b.file === e.file || b.file === originOf(e.file))));
|
|
7758
|
+
for (const e of heldExtensions) dueRules.add(e.rule);
|
|
7759
|
+
const snapshot = dueRules.size ? snapshotAtBase(root, options.base, files, changed, originOf) : null;
|
|
7760
|
+
let baseCounts;
|
|
7761
|
+
if (snapshot) {
|
|
7762
|
+
const before = [];
|
|
7763
|
+
await runChecks({ ...ctx, files: snapshot.files, report: (f) => before.push(f) }, baseChecks(dueRules, packageIds, packagePlugins, () => [...builtinChecks(config, { contracts: false, figma: false }), ...appChecks]));
|
|
7764
|
+
baseCounts = countFindings(applyConfig(before, config, packageIds));
|
|
7765
|
+
if (heldExtensions.length) {
|
|
7766
|
+
const counts = baseCounts;
|
|
7767
|
+
const held = new Set(heldExtensions);
|
|
7768
|
+
findings = applyExtensions(configured, { ...extensionCtx, limit: (e) => held.has(e) ? counts.get(countKey(originOf(e.file), e.rule)) ?? 0 : void 0 });
|
|
7769
|
+
}
|
|
7770
|
+
}
|
|
7771
|
+
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath, originOf, ...snapshot && baseCounts ? { baseCounts, existedAtBase: snapshot.existed } : {} });
|
|
7170
7772
|
}
|
|
7773
|
+
findings = dedupeFindings(findings);
|
|
7774
|
+
const extensionsNew = (config.extend ?? []).filter((e) => findings.some((f) => f.rule === "extension-added" && f.file === e.file && f.subject === e.rule));
|
|
7171
7775
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
7172
7776
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
7173
7777
|
const infos = findings.length - errors - warnings;
|
|
@@ -7181,9 +7785,24 @@ async function runDoctor(options = {}) {
|
|
|
7181
7785
|
primitives: primitivesSummary(packages),
|
|
7182
7786
|
errors,
|
|
7183
7787
|
warnings,
|
|
7184
|
-
infos
|
|
7788
|
+
infos,
|
|
7789
|
+
...extensionsNew.length ? { extensionsAdded: extensionsNew } : {}
|
|
7185
7790
|
};
|
|
7186
7791
|
}
|
|
7792
|
+
function baseChecks(rules, preferIds, packagePlugins, all) {
|
|
7793
|
+
if ([...rules].every((r) => preferIds.has(r))) return packagePlugins.filter((p) => p.name === "package-rules");
|
|
7794
|
+
return all();
|
|
7795
|
+
}
|
|
7796
|
+
async function runChecks(ctx, checks) {
|
|
7797
|
+
for (const plugin of checks) {
|
|
7798
|
+
try {
|
|
7799
|
+
await plugin.check(ctx);
|
|
7800
|
+
} catch (err) {
|
|
7801
|
+
if (err instanceof DoctorConfigError) throw err;
|
|
7802
|
+
ctx.report({ rule: "plugin-error", file: plugin.name, message: `rule plugin "${plugin.name}" threw: ${err.message}` });
|
|
7803
|
+
}
|
|
7804
|
+
}
|
|
7805
|
+
}
|
|
7187
7806
|
function builtinChecks(config, options = {}) {
|
|
7188
7807
|
const packs = {
|
|
7189
7808
|
native: { name: "native", check: checkNativePack },
|
|
@@ -7209,7 +7828,10 @@ function builtinChecks(config, options = {}) {
|
|
|
7209
7828
|
{ name: "studio-server-imports", check: checkStudioServerImports },
|
|
7210
7829
|
{ name: "removed-scope-names", check: checkRemovedScopeNames },
|
|
7211
7830
|
{ name: "stability-imports", check: checkStabilityImports },
|
|
7212
|
-
{ name: "agent-guide", check:
|
|
7831
|
+
{ name: "agent-guide", check: (ctx) => {
|
|
7832
|
+
checkAgentGuide(ctx);
|
|
7833
|
+
checkAgentHooks(ctx);
|
|
7834
|
+
} },
|
|
7213
7835
|
{ name: "overlays", check: (ctx) => checkOverlays(ctx) },
|
|
7214
7836
|
{ name: "lock-files", check: checkLockFiles },
|
|
7215
7837
|
{ name: "database-elsewhere", check: checkDatabaseHome },
|
|
@@ -7274,10 +7896,14 @@ function formatReport(result, options = {}) {
|
|
|
7274
7896
|
`Genesis doctor: ${g.uiPackage}@${g.uiVersion}, ${g.components.length} components, ${g.tokens.size} tokens, ${result.ruleCount} app rules; raw tags checked: ${[...g.rawTags.keys()].join(", ") || "none"}`
|
|
7275
7897
|
];
|
|
7276
7898
|
for (const f of result.findings) {
|
|
7277
|
-
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
7899
|
+
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${(f.rules ?? [f.rule]).join(", ")}] ${f.message}`);
|
|
7278
7900
|
}
|
|
7279
7901
|
lines.push(options.verbose ? `Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}` : `Available but unused: ${result.unused.length} (genesis doctor --verbose lists them)`);
|
|
7280
7902
|
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis catalog`);
|
|
7903
|
+
if (result.extensionsAdded?.length) {
|
|
7904
|
+
lines.push(`Extensions added on this branch (${result.extensionsAdded.length}); the pull request's review accepts each:`);
|
|
7905
|
+
for (const e of result.extensionsAdded) lines.push(` ${e.file} [${e.rule}] builds on ${e.buildsOn}: ${e.reason}${e.upstream ? ` (upstream: ${e.upstream})` : ""}`);
|
|
7906
|
+
}
|
|
7281
7907
|
const info = result.infos ? `, ${result.infos} info` : "";
|
|
7282
7908
|
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|
|
7283
7909
|
return lines.join("\n");
|
|
@@ -7291,7 +7917,8 @@ function toJson(result) {
|
|
|
7291
7917
|
infos: result.infos,
|
|
7292
7918
|
findings: result.findings,
|
|
7293
7919
|
unused: result.unused,
|
|
7294
|
-
primitives: result.primitives
|
|
7920
|
+
primitives: result.primitives,
|
|
7921
|
+
...result.extensionsAdded ? { extensionsAdded: result.extensionsAdded } : {}
|
|
7295
7922
|
};
|
|
7296
7923
|
}
|
|
7297
7924
|
function genesisSummary(g) {
|
|
@@ -7305,6 +7932,6 @@ function genesisSummary(g) {
|
|
|
7305
7932
|
};
|
|
7306
7933
|
}
|
|
7307
7934
|
|
|
7308
|
-
export { BUILTIN_RULES, DoctorConfigError, GenesisConfigError, PackageDeclarationError, SKILL_PATH, agentGuideState, builtinChecks, catalogTable, changedSince, clearPackageRulesCache, defineDoctorPlugin, discoverPackages, findPackageDir, formatPrimitives, formatReport, genesisInstalls, genesisSummary, globToRegExp, loadConfig, loadGenesis, nativeLayouts, parseExportNames, parseRulesMarkdown, postgresContract, postgresSource, preferRules, primitivesCatalog, primitivesSummary, readGenesisConfig, readPackageExports, readReleaseManifest, renderAgentsBlock, renderSkill, routesDir, ruleNamespace, runDoctor, satisfies, sqlStatements, toJson, validateConfig, validateDeclaration, validateLinks, webRoutes, writeAgentGuide };
|
|
7935
|
+
export { BLOCKED_FIX, BUILTIN_RULES, CLAUDE_IMPORT, DENY_RULES, DoctorConfigError, GenesisConfigError, PackageDeclarationError, SETTINGS_PATH, SKILL_PATH, SUBAGENT_HOOK_COMMAND, agentGuideState, agentHooksState, agentRules, applyExtensions, builtinChecks, catalogTable, changedSince, clearPackageRulesCache, dedupeFindings, defineDoctorPlugin, discoverPackages, extensionProblem, findPackageDir, formatPrimitives, formatReport, genesisInstalls, genesisSummary, globToRegExp, loadConfig, loadGenesis, mergeAgentHooks, nativeLayouts, packageGuides, parseExportNames, parseRulesMarkdown, postgresContract, postgresSource, preferRules, primitivesCatalog, primitivesSummary, readGenesisConfig, readPackageExports, readReleaseManifest, renderAgentsBlock, renderSkill, routesDir, ruleNamespace, runDoctor, satisfies, skillDescription, sqlStatements, subagentContext, subagentHookOutput, toJson, unlistedGuides, validateConfig, validateDeclaration, validateLinks, webRoutes, writeAgentGuide, writeAgentHooks };
|
|
7309
7936
|
//# sourceMappingURL=doctor.js.map
|
|
7310
7937
|
//# sourceMappingURL=doctor.js.map
|