@marktiderman/genesis-cli 1.25.0 → 1.26.1

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.
@@ -231,6 +231,13 @@ interface GenesisFacts {
231
231
  components: readonly string[];
232
232
  /** Custom properties the theme stylesheets define. */
233
233
  tokens: ReadonlySet<string>;
234
+ /**
235
+ * The colour roles among them: tokens whose value is a colour (`--primary: 243 75% 59%`,
236
+ * `--color-primary: hsl(var(--primary))`). Absent when not read.
237
+ */
238
+ colorTokens?: ReadonlySet<string>;
239
+ /** The part names genesis-ui renders (`THEME_PARTS`), from the installed design system. Absent when not found. */
240
+ themeParts?: readonly string[];
234
241
  /** Raw HTML tag → the Genesis component that replaces it. */
235
242
  rawTags: ReadonlyMap<string, string>;
236
243
  /** Tailwind palette color names (red, slate, …). */
package/dist/doctor.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DoctorConfig, l as GenesisFacts, m as PatternRule, h as DoctorPlugin, S as SourceFile, g as DoctorContext, n as PreferRule, o as DeclaringPackage, q as PackageDeclaration, F as Finding, s as FindingInput, E as ExtensionEntry, i as DoctorResult } from './config-CR4kqSCp.js';
2
- export { A as AllowEntry, C as CompanionPackage, t as ContractsConfig, f as DoctorConfigError, u as DoctorPack, c as GenesisConfigError, j as GenesisConfigFile, b as GenesisLinks, k as GenesisSupabase, L as Level, N as NativePackConfig, w as PackageRuleSetting, x as PackagesPackConfig, y as PluginSpec, z as PrimitiveEntry, R as RuleSetting, B as SupabasePackConfig, H as loadConfig, r as readGenesisConfig, I as validateConfig, v as validateLinks } from './config-CR4kqSCp.js';
1
+ import { D as DoctorConfig, l as GenesisFacts, m as PatternRule, h as DoctorPlugin, S as SourceFile, g as DoctorContext, n as PreferRule, o as DeclaringPackage, q as PackageDeclaration, F as Finding, s as FindingInput, E as ExtensionEntry, i as DoctorResult } from './config-ARs2YQ60.js';
2
+ export { A as AllowEntry, C as CompanionPackage, t as ContractsConfig, f as DoctorConfigError, u as DoctorPack, c as GenesisConfigError, j as GenesisConfigFile, b as GenesisLinks, k as GenesisSupabase, L as Level, N as NativePackConfig, w as PackageRuleSetting, x as PackagesPackConfig, y as PluginSpec, z as PrimitiveEntry, R as RuleSetting, B as SupabasePackConfig, H as loadConfig, r as readGenesisConfig, I as validateConfig, v as validateLinks } from './config-ARs2YQ60.js';
3
3
  import '@marktiderman/genesis-features';
4
4
 
5
5
  /** The installed folder of `name`, looking in node_modules from `from` upward (works with hoisting and pnpm). */
@@ -27,7 +27,7 @@ declare function parseRulesMarkdown(markdown: string): PatternRule[];
27
27
  declare function defineDoctorPlugin(plugin: DoctorPlugin): DoctorPlugin;
28
28
 
29
29
  /** Ids of the built-in rules, for `rules` overrides and `allow` entries. */
30
- declare const BUILTIN_RULES: readonly ["local-primitives", "figma-routes", "starter-leftover", "forbidden-import", "raw-tag", "palette-color", "arbitrary-color", "raw-color", "undefined-token", "shadowed-export", "version-skew", "duplicate-genesis-package", "peer-range-mismatch", "hand-rolled-sub-nav", "local-genesis-copy", "resource-workspace", "page-layout", "iso-date-slice", "resource-view-tree", "studio-server-auth-import", "removed-scope-name", "scope-practice-id", "deprecated-import", "beta-import", "native-raw-primitive", "native-literal-color", "native-custom-header", "native-screen-layout", "store-readiness", "eas-placeholder", "migration-grants", "migration-rls", "migration-definer-search-path", "migration-edited", "migration-testing-kit", "migration-view-rls", "exposed-schema-created-later", "package-app-import", "package-undeclared-dependency", "package-migration-test", "package-migration-number", "package-migration-edited", "package-unregistered", "package-unversioned-change", "package-export-missing", "package-block-invalid", "package-untagged-tests", "package-doctor-declaration", "overlay-unmarked", "overlay-invalid", "overlay-age", "overlay-version", "overlay-behind", "package-rules-invalid", "package-rule-override", "ratchet-skipped", "allow-grew", "rules-weakened", "extension-added", "stale-extension", "extension-invalid", "agent-guide-stale", "contracts-stale", "lock-files", "database-elsewhere", "genesis-eslint-config"];
30
+ declare const BUILTIN_RULES: readonly ["local-primitives", "figma-routes", "starter-leftover", "forbidden-import", "raw-tag", "palette-color", "arbitrary-color", "raw-color", "undefined-token", "shadowed-export", "version-skew", "duplicate-genesis-package", "peer-range-mismatch", "hand-rolled-sub-nav", "local-genesis-copy", "resource-workspace", "page-layout", "iso-date-slice", "resource-view-tree", "studio-server-auth-import", "removed-scope-name", "scope-practice-id", "deprecated-import", "beta-import", "native-raw-primitive", "native-literal-color", "native-custom-header", "native-screen-layout", "store-readiness", "eas-placeholder", "migration-grants", "migration-rls", "migration-definer-search-path", "migration-edited", "migration-testing-kit", "migration-view-rls", "exposed-schema-created-later", "package-app-import", "package-undeclared-dependency", "package-migration-test", "package-migration-number", "package-migration-edited", "package-unregistered", "package-unversioned-change", "package-export-missing", "package-block-invalid", "package-untagged-tests", "package-doctor-declaration", "overlay-unmarked", "overlay-invalid", "overlay-age", "overlay-version", "overlay-behind", "package-rules-invalid", "package-rule-override", "ratchet-skipped", "allow-grew", "rules-weakened", "extension-added", "stale-extension", "extension-invalid", "agent-guide-stale", "contracts-stale", "lock-files", "database-elsewhere", "genesis-eslint-config", "app-part-colors", "app-part-name", "custom-view-states"];
31
31
 
32
32
  /**
33
33
  * Minimal globs for config: `*` matches within a folder, `**` across folders,
package/dist/doctor.js CHANGED
@@ -257,7 +257,7 @@ var init_comments = __esm({
257
257
  "src/introspect/comments.ts"() {
258
258
  MARKER = "@genesis";
259
259
  TABLE_KEYS = { label: "string", labelField: "string", description: "string", noun: "string", nounPlural: "string", key: "key" };
260
- FIELD_KEYS = { label: "string", description: "string", widget: "string", readonly: "boolean", sensitive: "boolean" };
260
+ FIELD_KEYS = { label: "string", description: "string", control: "string", widget: "string", readonly: "boolean", sensitive: "boolean" };
261
261
  CommentSettingsError = class extends Error {
262
262
  };
263
263
  }
@@ -616,7 +616,8 @@ function field(column, indent) {
616
616
  const description = column.settings?.description ?? column.description;
617
617
  if (label) parts.push(`label: ${quote(label)}`);
618
618
  if (description) parts.push(`description: ${quote(description)}`);
619
- if (column.settings?.widget) parts.push(`widget: ${quote(column.settings.widget)}`);
619
+ if (column.settings?.control) parts.push(`control: ${quote(column.settings.control)}`);
620
+ else if (column.settings?.widget) parts.push(`widget: ${quote(column.settings.widget)}`);
620
621
  if (column.settings?.readonly) parts.push("readOnly: true");
621
622
  if (column.settings?.sensitive) parts.push("sensitive: true");
622
623
  return `${indent}{ ${parts.join(", ")} },`;
@@ -2329,7 +2330,9 @@ function loadGenesis(root, config) {
2329
2330
  const { dir: uiDir, exports: exportNames, values, components } = pkg;
2330
2331
  const tokens = /* @__PURE__ */ new Set();
2331
2332
  const themeFiles = resolveThemeFiles(root, config, uiDir);
2332
- for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
2333
+ const themeCss = themeFiles.map((file) => readFileSync(file, "utf8"));
2334
+ for (const css of themeCss) for (const t of declaredTokens(css)) tokens.add(t);
2335
+ const colorTokens = colorRoles(themeCss);
2333
2336
  const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
2334
2337
  const rawTags = /* @__PURE__ */ new Map();
2335
2338
  for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
@@ -2345,6 +2348,8 @@ function loadGenesis(root, config) {
2345
2348
  values,
2346
2349
  components,
2347
2350
  tokens,
2351
+ colorTokens,
2352
+ ...themeParts(root) ? { themeParts: themeParts(root) } : {},
2348
2353
  rawTags,
2349
2354
  palette: loadPalette(root),
2350
2355
  companions: loadCompanions(root, config, uiPackage)
@@ -2444,6 +2449,49 @@ function parseExportNames(dts) {
2444
2449
  }
2445
2450
  return names;
2446
2451
  }
2452
+ var COLOUR_VALUE = /^(?:-?[\d.]+(?:deg)?\s+[\d.]+%\s+[\d.]+%(?:\s*\/\s*[\d.]+%?)?|#[0-9a-f]{3,8}|(?:hsla?|rgba?|oklch|oklab|lab|lch|color)\(.*\))$/i;
2453
+ function colorRoles(sheets) {
2454
+ const declared = /* @__PURE__ */ new Map();
2455
+ for (const css of sheets) {
2456
+ for (const m of css.matchAll(/(--[A-Za-z0-9_-]+)\s*:\s*([^;{}]+);/g)) {
2457
+ const list = declared.get(m[1]) ?? [];
2458
+ list.push(m[2].trim());
2459
+ declared.set(m[1], list);
2460
+ }
2461
+ }
2462
+ const roles = /* @__PURE__ */ new Set();
2463
+ for (const [name, values] of declared) if (values.some((v) => COLOUR_VALUE.test(v))) roles.add(name);
2464
+ for (let pass = 0; pass < 4; pass++) {
2465
+ for (const [name, values] of declared) {
2466
+ if (roles.has(name)) continue;
2467
+ if (values.some((v) => [...v.matchAll(/var\(\s*(--[A-Za-z0-9_-]+)/g)].some((r) => roles.has(r[1])))) roles.add(name);
2468
+ }
2469
+ }
2470
+ return roles;
2471
+ }
2472
+ var partsCache = /* @__PURE__ */ new Map();
2473
+ function themeParts(root) {
2474
+ const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
2475
+ if (!ds) return null;
2476
+ if (partsCache.has(ds)) return partsCache.get(ds);
2477
+ let found = null;
2478
+ const dist = path21.join(ds, "dist");
2479
+ try {
2480
+ for (const name of existsSync(dist) ? readdirSync(dist) : []) {
2481
+ if (!name.endsWith(".js")) continue;
2482
+ const code = readFileSync(path21.join(dist, name), "utf8");
2483
+ const at = code.indexOf("THEME_PARTS = Object.freeze([");
2484
+ if (at === -1) continue;
2485
+ const body = code.slice(at, code.indexOf("]);", at));
2486
+ found = [...body.matchAll(/\bp\(\s*"([a-z][a-z0-9-]*)"/g)].map((m) => m[1]);
2487
+ break;
2488
+ }
2489
+ } catch {
2490
+ found = null;
2491
+ }
2492
+ partsCache.set(ds, found);
2493
+ return found;
2494
+ }
2447
2495
  function declaredTokens(css) {
2448
2496
  return [...css.matchAll(/(--[A-Za-z0-9_-]+)\s*:/g)].map((m) => m[1]);
2449
2497
  }
@@ -2805,7 +2853,11 @@ var BUILTIN_RULES = [
2805
2853
  // an app whose database files live in another app (database.ts)
2806
2854
  "database-elsewhere",
2807
2855
  // the app's eslint config loads Genesis's lint rules (eslint-config.ts)
2808
- "genesis-eslint-config"
2856
+ "genesis-eslint-config",
2857
+ // custom views and app parts (custom-views.ts)
2858
+ "app-part-colors",
2859
+ "app-part-name",
2860
+ "custom-view-states"
2809
2861
  ];
2810
2862
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2811
2863
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -2828,7 +2880,7 @@ function checkProjectLayout(ctx) {
2828
2880
  rule: "local-primitives",
2829
2881
  file: dir,
2830
2882
  subject: dir,
2831
- message: `is a local design-system primitive folder; use ${ctx.genesis.uiPackage} (or extend it upstream)`
2883
+ message: `is a local design-system primitive folder; use ${ctx.genesis.uiPackage} for those, and keep the app's own components in another folder`
2832
2884
  });
2833
2885
  }
2834
2886
  }
@@ -6017,6 +6069,73 @@ function checkRemovedScopeNames(ctx) {
6017
6069
  }
6018
6070
  }
6019
6071
  }
6072
+
6073
+ // src/doctor/custom-views.ts
6074
+ var JSX_EXTS4 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
6075
+ var CUSTOM_VIEW = /<CustomView\b|\buseCustomView\s*[<(]/;
6076
+ var APP_PART = /data-slot\s*=\s*\{?\s*["'`]app-/;
6077
+ var COLOUR_KEY = /\b(color|background(?:Color)?|border(?:Top|Right|Bottom|Left|Block|Inline)?(?:Color)?|outline(?:Color)?|textDecorationColor|caretColor|accentColor|fill|stroke|columnRuleColor|boxShadow)\s*:\s*(["'`])([^"'`]*)\2/g;
6078
+ var COLOUR_UTILITY = /(?<![\w-])(?:bg|text|border(?:-[xytrbls])?|ring|ring-offset|fill|stroke|from|to|via|outline|divide|decoration|shadow|accent|caret|placeholder)-\[([^\]]*var\(--[^\]]*)\]/g;
6079
+ var VARIABLE = /var\(\s*(--[A-Za-z0-9_-]+)/g;
6080
+ function checkAppParts(ctx) {
6081
+ const roles = ctx.genesis.colorTokens;
6082
+ const genesisParts = new Set(ctx.genesis.themeParts ?? []);
6083
+ const overlays = markedOverlays(ctx);
6084
+ for (const file of ctx.files) {
6085
+ if (!JSX_EXTS4.has(file.ext) && file.ext !== ".ts" && file.ext !== ".js") continue;
6086
+ if (insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
6087
+ const code = file.code;
6088
+ if (JSX_EXTS4.has(file.ext)) {
6089
+ for (const m of code.matchAll(/\bdata-slot\s*=\s*(?:\{\s*)?["'`]([^"'`$]+)["'`]/g)) {
6090
+ const name = m[1];
6091
+ if (name.startsWith("app-")) continue;
6092
+ const clash = genesisParts.has(name);
6093
+ ctx.report({
6094
+ rule: "app-part-name",
6095
+ level: "warn",
6096
+ file: file.path,
6097
+ line: lineAt(code, m.index ?? 0),
6098
+ subject: name,
6099
+ message: clash ? `marks an app element data-slot="${name}", which is a Genesis part (THEME_PARTS): every app style's rules for it would hit this element too. Name the app's own part "app-${name}"` : `marks an app element data-slot="${name}"; name the app's own part "app-${name}", so it never collides with a Genesis part (docs/adr/0018-app-brands-styles-themes.md)`
6100
+ });
6101
+ }
6102
+ }
6103
+ if (roles && roles.size && (CUSTOM_VIEW.test(code) || APP_PART.test(code))) {
6104
+ const seen = /* @__PURE__ */ new Set();
6105
+ const check = (value, at) => {
6106
+ for (const v of value.matchAll(VARIABLE)) {
6107
+ const name = v[1];
6108
+ if (roles.has(name)) continue;
6109
+ const line = lineAt(code, at);
6110
+ if (seen.has(`${line}:${name}`)) continue;
6111
+ seen.add(`${line}:${name}`);
6112
+ ctx.report({
6113
+ rule: "app-part-colors",
6114
+ level: "warn",
6115
+ file: file.path,
6116
+ line,
6117
+ subject: name,
6118
+ message: `colours a custom view or app part with ${name}, which isn't a colour role; take colours from roles only (hsl(var(--primary)), bg-primary, text-muted-foreground) so the app brand and dark mode reach it`
6119
+ });
6120
+ }
6121
+ };
6122
+ for (const m of code.matchAll(COLOUR_KEY)) check(m[3], m.index ?? 0);
6123
+ for (const m of code.matchAll(COLOUR_UTILITY)) check(m[1], m.index ?? 0);
6124
+ }
6125
+ if (JSX_EXTS4.has(file.ext) && CUSTOM_VIEW.test(code)) {
6126
+ for (const m of code.matchAll(/\bstatus\s*[!=]={1,2}\s*["'`](loading|empty|error)["'`]/g)) {
6127
+ ctx.report({
6128
+ rule: "custom-view-states",
6129
+ level: "warn",
6130
+ file: file.path,
6131
+ line: lineAt(code, m.index ?? 0),
6132
+ subject: m[1],
6133
+ message: `draws a custom view's own ${m[1]} state; <CustomView> draws loading, empty and error in the app's style (pass its loading, empty or error prop to replace one) (docs/adr/0019-custom-views.md)`
6134
+ });
6135
+ }
6136
+ }
6137
+ }
6138
+ }
6020
6139
  var SCRIPT_EXTS6 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
6021
6140
  var DECLARATION = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\n(?:export\s+)?(?:declare\s+)?(?:abstract\s+)?(?:function|const|let|class|interface|type|enum|namespace)\s+([A-Za-z_$][\w$]*)/g;
6022
6141
  var REEXPORT = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\nexport\s+(?:type\s+)?\{([^}]*)\}/g;
@@ -6499,7 +6618,7 @@ function pathTaken(file) {
6499
6618
  var CORE = [
6500
6619
  {
6501
6620
  need: "anything, before building it",
6502
- use: 'search what exists: `genesis features find <term>`, this catalog, and the "Available but unused" list in `genesis doctor --verbose`',
6621
+ use: 'search what exists: `genesis features find <term>`, this catalog, and the "Available but unused" list in `genesis doctor --verbose`. Check the install is current first (`genesis upgrade --dry-run`): an old one hides pieces that exist',
6503
6622
  docs: `${GENESIS_DOCS}/FRAMEWORK.md`,
6504
6623
  from: "genesis-cli"
6505
6624
  },
@@ -6524,9 +6643,15 @@ var CORE = [
6524
6643
  rule: "raw-color",
6525
6644
  from: "genesis-cli"
6526
6645
  },
6646
+ {
6647
+ need: "a Genesis piece that is close but doesn't quite fit",
6648
+ use: "extend it: a prop, a variant, a slot, or your own component that wraps it; never a parallel copy beside it",
6649
+ docs: `${GENESIS_DOCS}/FRAMEWORK.md`,
6650
+ from: "genesis-cli"
6651
+ },
6527
6652
  {
6528
6653
  need: "something no primitive covers",
6529
- use: "write the gap up for Genesis (an issue or a proposal) first, then invent in the app, on Genesis primitives",
6654
+ use: "invent it in the app, on Genesis tokens and primitives; Genesis asks for no write-up first. You may add it to `docs/genesis-upstream.md` (`genesis upstream`) if you think Genesis should have it",
6530
6655
  docs: `${GENESIS_DOCS}/FRAMEWORK.md`,
6531
6656
  from: "genesis-cli"
6532
6657
  }
@@ -6579,10 +6704,12 @@ var AGENTS_START = "<!-- genesis-primitives:start -->";
6579
6704
  var AGENTS_END = "<!-- genesis-primitives:end -->";
6580
6705
  var RULES = [
6581
6706
  `Use the Genesis primitive for the need first: reuse, then extend, then invent (G1 to G6 in ${GENESIS_DOCS}/FRAMEWORK.md).`,
6707
+ "Before deciding Genesis lacks a piece, look at all of it (the catalog below, `genesis features find <term>`) and check the installed packages are current (`genesis upgrade --dry-run`). An old install hides pieces that exist; upgrade before building around a gap that is already closed.",
6582
6708
  "Never copy an older screen as a template. Old screens predate the primitives; the doctor flags what they did.",
6583
6709
  "A list screen is a view (`defineView`) rendered by `ResourceView`; a record view is `RecordView`; on the phone, `NativeResourceView`.",
6584
6710
  "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.",
6585
- "When no primitive fits, write the gap up for Genesis before inventing, then invent in the app on Genesis primitives.",
6711
+ "When a Genesis piece is close and does the same job, extend it: a prop, a variant, a slot, or your own component that wraps it. Never build a parallel copy beside it.",
6712
+ "When no Genesis piece does the job, invent it in the app: your own screens and components, on Genesis tokens and primitives. Genesis asks for no write-up or approval first (your app's own design review still applies); you may add it to `docs/genesis-upstream.md` if you think Genesis should have it.",
6586
6713
  "Run `genesis doctor` before you finish; it enforces these rules."
6587
6714
  ];
6588
6715
  function skillDescription(text) {
@@ -7827,6 +7954,7 @@ function builtinChecks(config, options = {}) {
7827
7954
  { name: "resource-view-trees", check: checkTreeViews },
7828
7955
  { name: "studio-server-imports", check: checkStudioServerImports },
7829
7956
  { name: "removed-scope-names", check: checkRemovedScopeNames },
7957
+ { name: "app-parts", check: checkAppParts },
7830
7958
  { name: "stability-imports", check: checkStabilityImports },
7831
7959
  { name: "agent-guide", check: (ctx) => {
7832
7960
  checkAgentGuide(ctx);