@marktiderman/genesis-cli 1.25.0 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vite.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
  }
@@ -2802,7 +2850,11 @@ var BUILTIN_RULES = [
2802
2850
  // an app whose database files live in another app (database.ts)
2803
2851
  "database-elsewhere",
2804
2852
  // the app's eslint config loads Genesis's lint rules (eslint-config.ts)
2805
- "genesis-eslint-config"
2853
+ "genesis-eslint-config",
2854
+ // custom views and app parts (custom-views.ts)
2855
+ "app-part-colors",
2856
+ "app-part-name",
2857
+ "custom-view-states"
2806
2858
  ];
2807
2859
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2808
2860
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -2825,7 +2877,7 @@ function checkProjectLayout(ctx) {
2825
2877
  rule: "local-primitives",
2826
2878
  file: dir,
2827
2879
  subject: dir,
2828
- message: `is a local design-system primitive folder; use ${ctx.genesis.uiPackage} (or extend it upstream)`
2880
+ message: `is a local design-system primitive folder; use ${ctx.genesis.uiPackage} for those, and keep the app's own components in another folder`
2829
2881
  });
2830
2882
  }
2831
2883
  }
@@ -6011,6 +6063,73 @@ function checkRemovedScopeNames(ctx) {
6011
6063
  }
6012
6064
  }
6013
6065
  }
6066
+
6067
+ // src/doctor/custom-views.ts
6068
+ var JSX_EXTS4 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
6069
+ var CUSTOM_VIEW = /<CustomView\b|\buseCustomView\s*[<(]/;
6070
+ var APP_PART = /data-slot\s*=\s*\{?\s*["'`]app-/;
6071
+ 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;
6072
+ 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;
6073
+ var VARIABLE = /var\(\s*(--[A-Za-z0-9_-]+)/g;
6074
+ function checkAppParts(ctx) {
6075
+ const roles = ctx.genesis.colorTokens;
6076
+ const genesisParts = new Set(ctx.genesis.themeParts ?? []);
6077
+ const overlays = markedOverlays(ctx);
6078
+ for (const file of ctx.files) {
6079
+ if (!JSX_EXTS4.has(file.ext) && file.ext !== ".ts" && file.ext !== ".js") continue;
6080
+ if (insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
6081
+ const code = file.code;
6082
+ if (JSX_EXTS4.has(file.ext)) {
6083
+ for (const m of code.matchAll(/\bdata-slot\s*=\s*(?:\{\s*)?["'`]([^"'`$]+)["'`]/g)) {
6084
+ const name = m[1];
6085
+ if (name.startsWith("app-")) continue;
6086
+ const clash = genesisParts.has(name);
6087
+ ctx.report({
6088
+ rule: "app-part-name",
6089
+ level: "warn",
6090
+ file: file.path,
6091
+ line: lineAt(code, m.index ?? 0),
6092
+ subject: name,
6093
+ 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)`
6094
+ });
6095
+ }
6096
+ }
6097
+ if (roles && roles.size && (CUSTOM_VIEW.test(code) || APP_PART.test(code))) {
6098
+ const seen = /* @__PURE__ */ new Set();
6099
+ const check = (value, at) => {
6100
+ for (const v of value.matchAll(VARIABLE)) {
6101
+ const name = v[1];
6102
+ if (roles.has(name)) continue;
6103
+ const line = lineAt(code, at);
6104
+ if (seen.has(`${line}:${name}`)) continue;
6105
+ seen.add(`${line}:${name}`);
6106
+ ctx.report({
6107
+ rule: "app-part-colors",
6108
+ level: "warn",
6109
+ file: file.path,
6110
+ line,
6111
+ subject: name,
6112
+ 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`
6113
+ });
6114
+ }
6115
+ };
6116
+ for (const m of code.matchAll(COLOUR_KEY)) check(m[3], m.index ?? 0);
6117
+ for (const m of code.matchAll(COLOUR_UTILITY)) check(m[1], m.index ?? 0);
6118
+ }
6119
+ if (JSX_EXTS4.has(file.ext) && CUSTOM_VIEW.test(code)) {
6120
+ for (const m of code.matchAll(/\bstatus\s*[!=]={1,2}\s*["'`](loading|empty|error)["'`]/g)) {
6121
+ ctx.report({
6122
+ rule: "custom-view-states",
6123
+ level: "warn",
6124
+ file: file.path,
6125
+ line: lineAt(code, m.index ?? 0),
6126
+ subject: m[1],
6127
+ 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)`
6128
+ });
6129
+ }
6130
+ }
6131
+ }
6132
+ }
6014
6133
  var SCRIPT_EXTS6 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
6015
6134
  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;
6016
6135
  var REEXPORT = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\nexport\s+(?:type\s+)?\{([^}]*)\}/g;
@@ -6480,7 +6599,7 @@ var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
6480
6599
  var CORE = [
6481
6600
  {
6482
6601
  need: "anything, before building it",
6483
- use: 'search what exists: `genesis features find <term>`, this catalog, and the "Available but unused" list in `genesis doctor --verbose`',
6602
+ 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',
6484
6603
  docs: `${GENESIS_DOCS}/FRAMEWORK.md`,
6485
6604
  from: "genesis-cli"
6486
6605
  },
@@ -6505,9 +6624,15 @@ var CORE = [
6505
6624
  rule: "raw-color",
6506
6625
  from: "genesis-cli"
6507
6626
  },
6627
+ {
6628
+ need: "a Genesis piece that is close but doesn't quite fit",
6629
+ use: "extend it: a prop, a variant, a slot, or your own component that wraps it; never a parallel copy beside it",
6630
+ docs: `${GENESIS_DOCS}/FRAMEWORK.md`,
6631
+ from: "genesis-cli"
6632
+ },
6508
6633
  {
6509
6634
  need: "something no primitive covers",
6510
- use: "write the gap up for Genesis (an issue or a proposal) first, then invent in the app, on Genesis primitives",
6635
+ 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",
6511
6636
  docs: `${GENESIS_DOCS}/FRAMEWORK.md`,
6512
6637
  from: "genesis-cli"
6513
6638
  }
@@ -6550,10 +6675,12 @@ var AGENTS_START = "<!-- genesis-primitives:start -->";
6550
6675
  var AGENTS_END = "<!-- genesis-primitives:end -->";
6551
6676
  var RULES = [
6552
6677
  `Use the Genesis primitive for the need first: reuse, then extend, then invent (G1 to G6 in ${GENESIS_DOCS}/FRAMEWORK.md).`,
6678
+ "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.",
6553
6679
  "Never copy an older screen as a template. Old screens predate the primitives; the doctor flags what they did.",
6554
6680
  "A list screen is a view (`defineView`) rendered by `ResourceView`; a record view is `RecordView`; on the phone, `NativeResourceView`.",
6555
6681
  "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.",
6556
- "When no primitive fits, write the gap up for Genesis before inventing, then invent in the app on Genesis primitives.",
6682
+ "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.",
6683
+ "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.",
6557
6684
  "Run `genesis doctor` before you finish; it enforces these rules."
6558
6685
  ];
6559
6686
  function skillDescription(text) {
@@ -7698,6 +7825,7 @@ function builtinChecks(config, options = {}) {
7698
7825
  { name: "resource-view-trees", check: checkTreeViews },
7699
7826
  { name: "studio-server-imports", check: checkStudioServerImports },
7700
7827
  { name: "removed-scope-names", check: checkRemovedScopeNames },
7828
+ { name: "app-parts", check: checkAppParts },
7701
7829
  { name: "stability-imports", check: checkStabilityImports },
7702
7830
  { name: "agent-guide", check: (ctx) => {
7703
7831
  checkAgentGuide(ctx);