cascivo 0.3.5 → 0.4.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.
@@ -387,6 +387,157 @@ function findRequiredPropViolations(source, filename, contract) {
387
387
  return findings;
388
388
  }
389
389
  //#endregion
390
+ //#region src/utils/css-layers.ts
391
+ /** Replace comment bodies and string contents with spaces, preserving newlines. */
392
+ function blankCommentsAndStrings(source) {
393
+ let out = "";
394
+ let i = 0;
395
+ const n = source.length;
396
+ while (i < n) {
397
+ const c = source[i];
398
+ const next = source[i + 1];
399
+ if (c === "/" && next === "*") {
400
+ out += " ";
401
+ i += 2;
402
+ while (i < n && !(source[i] === "*" && source[i + 1] === "/")) {
403
+ out += source[i] === "\n" ? "\n" : " ";
404
+ i++;
405
+ }
406
+ out += " ";
407
+ i += 2;
408
+ } else if (c === "\"" || c === "'") {
409
+ const quote = c;
410
+ out += " ";
411
+ i++;
412
+ while (i < n && source[i] !== quote) {
413
+ if (source[i] === "\\") {
414
+ out += " ";
415
+ i += 2;
416
+ continue;
417
+ }
418
+ out += source[i] === "\n" ? "\n" : " ";
419
+ i++;
420
+ }
421
+ out += " ";
422
+ i++;
423
+ } else {
424
+ out += c;
425
+ i++;
426
+ }
427
+ }
428
+ return out;
429
+ }
430
+ /**
431
+ * Accessibility / user-preference media features whose overrides MUST win over
432
+ * everything — including a consumer's `cascivo.override` layer — so they are
433
+ * legitimately placed unlayered (top-level). A `@media (forced-colors: active)`
434
+ * block outside `@layer` is the sanctioned cascade idiom, not a hotfix leak.
435
+ */
436
+ const A11Y_GUARANTEE_RE = /@media[^{]*\b(forced-colors|prefers-contrast|prefers-reduced-motion|prefers-reduced-transparency|inverted-colors)\b/;
437
+ function classifyPrelude(prelude) {
438
+ const p = prelude.trim().toLowerCase();
439
+ if (p.startsWith("@layer")) return "layer";
440
+ if (A11Y_GUARANTEE_RE.test(p)) return "other";
441
+ if (p.startsWith("@media") || p.startsWith("@container") || p.startsWith("@supports") || p.startsWith("@scope")) return "group";
442
+ if (p.startsWith("@")) return "other";
443
+ return "style";
444
+ }
445
+ /**
446
+ * Return every top-level style rule that is NOT inside an `@layer` block. Only the
447
+ * outermost unlayered rule is reported (nested rules inside it are implied).
448
+ */
449
+ function findUnlayeredRules(source) {
450
+ const clean = blankCommentsAndStrings(source);
451
+ const rules = [];
452
+ const stack = [];
453
+ let preludeStart = 0;
454
+ const lineStarts = [0];
455
+ for (let i = 0; i < clean.length; i++) if (clean[i] === "\n") lineStarts.push(i + 1);
456
+ const lineOf = (idx) => {
457
+ let lo = 0;
458
+ let hi = lineStarts.length - 1;
459
+ while (lo < hi) {
460
+ const mid = lo + hi + 1 >> 1;
461
+ if (lineStarts[mid] <= idx) lo = mid;
462
+ else hi = mid - 1;
463
+ }
464
+ return lo + 1;
465
+ };
466
+ const hasAncestor = (kind) => stack.includes(kind);
467
+ for (let i = 0; i < clean.length; i++) {
468
+ const c = clean[i];
469
+ if (c === "{") {
470
+ const prelude = clean.slice(preludeStart, i);
471
+ const kind = classifyPrelude(prelude);
472
+ if (kind === "style" && !hasAncestor("layer") && !hasAncestor("other") && !hasAncestor("style")) {
473
+ const trimmed = prelude.trim().replace(/\s+/g, " ");
474
+ const startIdx = preludeStart + (prelude.length - prelude.trimStart().length);
475
+ rules.push({
476
+ line: lineOf(startIdx),
477
+ selector: trimmed.length > 60 ? `${trimmed.slice(0, 57)}…` : trimmed
478
+ });
479
+ }
480
+ stack.push(kind);
481
+ preludeStart = i + 1;
482
+ } else if (c === "}") {
483
+ stack.pop();
484
+ preludeStart = i + 1;
485
+ } else if (c === ";") preludeStart = i + 1;
486
+ }
487
+ return rules;
488
+ }
489
+ //#endregion
490
+ //#region src/audit-ai/unlayered.ts
491
+ const MESSAGE$1 = "Unlayered CSS beats every cascivo layer regardless of specificity. For a one-off override use `@layer cascivo.override { … }`; for app styles declare an app layer (e.g. cascivo.example) in your order statement. See docs/CSS-LAYERS-PITFALL.md.";
492
+ /**
493
+ * Warn on top-level style rules that live outside any `@layer` block. This is the
494
+ * consumer-facing half of the zero-unlayered guard: it teaches the fix rather than
495
+ * failing the build, because `docs/USING-WITH-TAILWIND.md` blesses deliberate
496
+ * unlayered CSS as a valid interop escape hatch. Accessibility-guarantee media
497
+ * queries (`forced-colors`, `prefers-contrast`, …) are exempt — see css-layers.ts.
498
+ */
499
+ function findUnlayeredViolations(source, filename) {
500
+ return findUnlayeredRules(source).map((rule) => ({
501
+ file: filename,
502
+ line: rule.line,
503
+ selector: rule.selector,
504
+ level: "warn",
505
+ rule: "unlayered-css",
506
+ message: MESSAGE$1
507
+ }));
508
+ }
509
+ //#endregion
510
+ //#region src/audit-ai/vendor-css.ts
511
+ const CSS_IMPORT_RE = /import\s+(?:[^'"]*?\bfrom\s+)?(['"])([^'"]+\.css(?:[?#][^'"]*)?)\1/g;
512
+ /** A bare specifier resolves into node_modules (not a relative or absolute path). */
513
+ function isBareSpecifier(spec) {
514
+ return !spec.startsWith(".") && !spec.startsWith("/");
515
+ }
516
+ const MESSAGE = "CSS imported from a package through JS/TS cannot be wrapped in an @layer, so if this package ships unlayered global CSS it beats every cascivo layer. Route it through a CSS file instead: `@import url(\"<pkg>/styles.css\") layer(vendor);`. See docs/THIRD-PARTY-CSS.md.";
517
+ /**
518
+ * Warn on bare (node_modules) `*.css` imports in JS/TS. Relative imports (the
519
+ * consumer's own CSS modules) and cascivo's own already-layered `@cascivo/*`
520
+ * stylesheets are exempt. Level `warn` — teaches the layer(vendor) recipe.
521
+ */
522
+ function findVendorCssImports(source, filename) {
523
+ const findings = [];
524
+ for (const m of source.matchAll(CSS_IMPORT_RE)) {
525
+ const spec = m[2];
526
+ if (spec === void 0) continue;
527
+ if (!isBareSpecifier(spec)) continue;
528
+ if (spec.startsWith("@cascivo/")) continue;
529
+ findings.push({
530
+ file: filename,
531
+ line: lineOf(source, m.index ?? 0),
532
+ specifier: spec,
533
+ level: "warn",
534
+ rule: "vendor-css-import",
535
+ message: MESSAGE
536
+ });
537
+ }
538
+ return findings;
539
+ }
540
+ //#endregion
390
541
  //#region src/utils/contract.ts
391
542
  const HERE = dirname(fileURLToPath(import.meta.url));
392
543
  /** Walk up from a start directory looking for the apps/site/public dir. */
@@ -458,12 +609,15 @@ function collectFiles(paths) {
458
609
  function findingsFor(file, source, contract) {
459
610
  const ext = extname(file);
460
611
  const findings = [];
461
- if (ext === ".css") findings.push(...findCssLiteralViolations(source, file, contract));
462
- else if (ext === ".tsx" || ext === ".ts") {
612
+ if (ext === ".css") {
613
+ findings.push(...findCssLiteralViolations(source, file, contract));
614
+ findings.push(...findUnlayeredViolations(source, file));
615
+ } else if (ext === ".tsx" || ext === ".ts") {
463
616
  findings.push(...findCssLiteralViolations(source, file, contract));
464
617
  findings.push(...findJsxPropViolations(source, file, contract));
465
618
  findings.push(...findRequiredPropViolations(source, file, contract));
466
619
  findings.push(...findRawStringViolations(source, file, contract));
620
+ findings.push(...findVendorCssImports(source, file));
467
621
  }
468
622
  return findings;
469
623
  }
@@ -476,6 +630,8 @@ function detail(f) {
476
630
  case "spread-suppressed": return `<${f.component} {...}> (props not checked)`;
477
631
  case "missing-prop": return `<${f.component}> requires "${f.prop}"`;
478
632
  case "raw-string": return `"${f.text}" → use labels prop / i18n`;
633
+ case "unlayered-css": return `${f.selector} { … } → wrap in @layer`;
634
+ case "vendor-css-import": return `import '${f.specifier}' → @import url(…) layer(vendor)`;
479
635
  }
480
636
  }
481
637
  function levelLabel(level) {
@@ -580,4 +736,4 @@ async function audit(args, _config) {
580
736
  //#endregion
581
737
  export { audit };
582
738
 
583
- //# sourceMappingURL=audit-InQqdY1s.mjs.map
739
+ //# sourceMappingURL=audit-jseQagw5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-jseQagw5.mjs","names":["MESSAGE"],"sources":["../src/utils/contract-pure.ts","../src/audit-ai/css-literals.ts","../src/audit-ai/jsx-props.ts","../src/audit-ai/raw-strings.ts","../src/audit-ai/required-props.ts","../src/utils/css-layers.ts","../src/audit-ai/unlayered.ts","../src/audit-ai/vendor-css.ts","../src/utils/contract.ts","../src/commands/audit.ts"],"sourcesContent":["export interface PropInfo {\n name: string\n type: string\n required: boolean\n}\n\nexport interface ComponentInfo {\n props: PropInfo[]\n /** True if any prop has required: true */\n hasRequiredProps: boolean\n /** Props that have required: true */\n requiredProps: string[]\n /** True if the component declares user-facing chrome text (intent.content) */\n hasContent: boolean\n}\n\nexport interface Contract {\n /** Map from normalized color/size value → token names */\n tokensByValue: Map<string, string[]>\n /** Map from component name (PascalCase) → component info */\n components: Map<string, ComponentInfo>\n}\n\ninterface TokenEntry {\n name: string\n resolvedDefault: string | null\n}\n\ninterface CatalogFile {\n tokens: TokenEntry[]\n}\n\ninterface RegistryPropMeta {\n name: string\n type?: string\n required?: boolean\n}\n\ninterface RegistryComponentMeta {\n name: string\n props?: RegistryPropMeta[]\n}\n\ninterface RegistryEntry {\n meta?: RegistryComponentMeta\n}\n\ninterface RegistryFile {\n components: RegistryEntry[]\n}\n\ninterface ContextComponentEntry {\n name: string\n intent?: { content?: unknown }\n}\n\ninterface ContextFile {\n components: ContextComponentEntry[]\n}\n\nexport interface BuildContractInput {\n catalog: CatalogFile\n registry: RegistryFile\n context: ContextFile\n}\n\n/** Normalize a color/size value for catalog comparison: lowercase, strip spaces. */\nexport function normalizeValue(value: string): string {\n return value.toLowerCase().replace(/\\s+/g, '')\n}\n\n/** Pure builder — assemble a Contract from already-parsed JSON. Testable without fs. */\nexport function buildContract(input: BuildContractInput): Contract {\n const tokensByValue = new Map<string, string[]>()\n for (const token of input.catalog.tokens) {\n if (token.resolvedDefault == null) continue\n const key = normalizeValue(token.resolvedDefault)\n const list = tokensByValue.get(key)\n if (list) list.push(token.name)\n else tokensByValue.set(key, [token.name])\n }\n\n const contentNames = new Set<string>()\n for (const c of input.context.components) {\n if (c.intent?.content) contentNames.add(c.name)\n }\n\n const components = new Map<string, ComponentInfo>()\n for (const entry of input.registry.components) {\n const meta = entry.meta\n if (!meta?.name) continue\n const props: PropInfo[] = (meta.props ?? []).map((p) => ({\n name: p.name,\n type: p.type ?? 'unknown',\n required: p.required === true,\n }))\n const requiredProps = props.filter((p) => p.required).map((p) => p.name)\n components.set(meta.name, {\n props,\n requiredProps,\n hasRequiredProps: requiredProps.length > 0,\n hasContent: contentNames.has(meta.name),\n })\n }\n\n return { tokensByValue, components }\n}\n","import type { Contract } from '../utils/contract-pure.js'\nimport { normalizeValue } from '../utils/contract-pure.js'\n\nexport interface LiteralFinding {\n file: string\n line: number\n property: string\n value: string\n level: 'error' | 'info'\n rule: 'hardcoded-value'\n /** only when exactly one catalog match */\n suggestedToken?: string\n /** when multiple catalog matches → info */\n allMatches?: string[]\n}\n\n/** Visual CSS properties whose literal values should be tokens. */\nconst VISUAL_PROPS = new Set([\n 'color',\n 'background',\n 'background-color',\n 'border-color',\n 'box-shadow',\n 'border-radius',\n 'font-size',\n 'gap',\n 'padding',\n 'margin',\n 'width',\n 'height',\n])\n\n/** Inline-style camelCase → kebab-case for the props we care about. */\nconst INLINE_PROP_MAP: Record<string, string> = {\n color: 'color',\n background: 'background',\n backgroundColor: 'background-color',\n borderColor: 'border-color',\n boxShadow: 'box-shadow',\n borderRadius: 'border-radius',\n fontSize: 'font-size',\n gap: 'gap',\n padding: 'padding',\n margin: 'margin',\n width: 'width',\n height: 'height',\n}\n\n/** A literal value worth checking: hex, oklch/rgb/hsl(a), or px/rem number. */\nfunction isLiteralValue(value: string): boolean {\n const v = value.trim()\n if (v.includes('var(')) return false\n if (/^#[0-9a-fA-F]{3,8}$/.test(v)) return true\n if (/^(oklch|oklab|rgb|rgba|hsl|hsla)\\(/i.test(v)) return true\n if (/^-?\\d*\\.?\\d+(px|rem)$/.test(v)) return true\n return false\n}\n\nfunction classify(\n value: string,\n contract: Contract,\n): Pick<LiteralFinding, 'level' | 'suggestedToken' | 'allMatches'> | null {\n const matches = contract.tokensByValue.get(normalizeValue(value))\n if (!matches || matches.length === 0) return null\n const first = matches[0]\n if (matches.length === 1 && first) return { level: 'error', suggestedToken: first }\n return { level: 'info', allMatches: matches }\n}\n\n/**\n * Detect literal color/size values in CSS declarations and TSX inline styles\n * that exactly match a known cascade token. Heuristic, line-based — no full\n * CSS/JS parse. Values with no catalog match are NOT flagged (arbitrary brand\n * values are allowed).\n */\nexport function findCssLiteralViolations(\n source: string,\n filename: string,\n contract: Contract,\n): LiteralFinding[] {\n const findings: LiteralFinding[] = []\n const lines = source.split('\\n')\n\n // CSS declaration: `property: value;` (also matches the kebab props inside style=\"...\")\n const cssDecl = /(^|[;{\\s])([a-z-]+)\\s*:\\s*([^;}{]+?)\\s*(?=[;}]|$)/gi\n // Inline JSX style object: `color: '#fff'` or `color: \"#fff\"`\n const inlineDecl = /([A-Za-z][A-Za-z]*)\\s*:\\s*(['\"])([^'\"]+)\\2/g\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]\n if (line === undefined) continue\n const seen = new Set<string>()\n\n for (const m of line.matchAll(cssDecl)) {\n if (m[2] === undefined || m[3] === undefined) continue\n const prop = m[2].toLowerCase()\n const rawValue = m[3].trim()\n if (!VISUAL_PROPS.has(prop)) continue\n if (!isLiteralValue(rawValue)) continue\n const cls = classify(rawValue, contract)\n if (!cls) continue\n const key = `${prop}|${rawValue}`\n seen.add(key)\n findings.push({\n file: filename,\n line: i + 1,\n property: prop,\n value: rawValue,\n rule: 'hardcoded-value',\n ...cls,\n })\n }\n\n for (const m of line.matchAll(inlineDecl)) {\n if (m[1] === undefined || m[3] === undefined) continue\n const prop = INLINE_PROP_MAP[m[1]]\n if (!prop) continue\n const rawValue = m[3].trim()\n if (!isLiteralValue(rawValue)) continue\n const key = `${prop}|${rawValue}`\n if (seen.has(key)) continue\n const cls = classify(rawValue, contract)\n if (!cls) continue\n findings.push({\n file: filename,\n line: i + 1,\n property: prop,\n value: rawValue,\n rule: 'hardcoded-value',\n ...cls,\n })\n }\n }\n\n return findings\n}\n","import type { Contract } from '../utils/contract-pure.js'\n\nexport interface PropFinding {\n file: string\n line: number\n component: string\n prop: string\n level: 'error' | 'info'\n rule: 'unknown-prop' | 'spread-suppressed'\n message: string\n}\n\n/** Props always allowed on any cascade component (DOM passthrough / React intrinsics). */\nconst PASSTHROUGH = new Set(['className', 'style', 'id', 'ref', 'key', 'children'])\n\nfunction isPassthrough(prop: string): boolean {\n if (PASSTHROUGH.has(prop)) return true\n if (prop.startsWith('data-')) return true\n if (prop.startsWith('aria-')) return true\n if (/^on[A-Z]/.test(prop)) return true\n return false\n}\n\n/** Names imported from @cascivo/react in this source. */\nexport function importedCascadeComponents(source: string): Set<string> {\n const names = new Set<string>()\n const importRe = /import\\s*\\{([^}]*)\\}\\s*from\\s*['\"]@cascivo\\/react['\"]/g\n for (const m of source.matchAll(importRe)) {\n const group = m[1]\n if (group === undefined) continue\n for (const raw of group.split(',')) {\n const name = raw\n .trim()\n .split(/\\s+as\\s+/)[0]\n ?.trim()\n if (name) names.add(name)\n }\n }\n return names\n}\n\n/** Find each opening tag for `comp`, returning its attribute substring + start index. */\nexport interface OpeningTag {\n attrs: string\n index: number\n hasSpread: boolean\n}\n\nexport function findOpeningTags(source: string, comp: string): OpeningTag[] {\n const tags: OpeningTag[] = []\n const re = new RegExp(`<${comp}(?=[\\\\s/>])`, 'g')\n for (const m of source.matchAll(re)) {\n const start = m.index ?? 0\n // Walk forward to the matching '>' that closes the opening tag, respecting\n // nested braces (JSX expressions) and quoted strings.\n let i = start + m[0].length\n let depth = 0\n let quote = ''\n let attrs = ''\n let closed = false\n for (; i < source.length; i++) {\n const ch = source[i]\n if (quote) {\n if (ch === quote) quote = ''\n attrs += ch\n continue\n }\n if (ch === '\"' || ch === \"'\" || ch === '`') {\n quote = ch\n attrs += ch\n continue\n }\n if (ch === '{') depth++\n else if (ch === '}') depth--\n else if (ch === '>' && depth === 0) {\n closed = true\n break\n }\n attrs += ch\n }\n if (!closed) continue\n const cleanAttrs = attrs.replace(/\\/$/, '')\n tags.push({ attrs: cleanAttrs, index: start, hasSpread: /\\{\\s*\\.\\.\\./.test(cleanAttrs) })\n }\n return tags\n}\n\n/** Extract top-level attribute names from an opening-tag attribute string. */\nexport function extractAttrNames(attrs: string): string[] {\n const names: string[] = []\n let depth = 0\n let quote = ''\n let token = ''\n const flush = () => {\n const name = token.trim().split('=')[0]?.trim()\n if (name && /^[A-Za-z]/.test(name)) names.push(name)\n token = ''\n }\n for (let i = 0; i < attrs.length; i++) {\n const ch = attrs[i]\n if (ch === undefined) continue\n if (quote) {\n if (ch === quote) quote = ''\n continue\n }\n if (ch === '\"' || ch === \"'\" || ch === '`') {\n quote = ch\n continue\n }\n if (ch === '{') {\n depth++\n continue\n }\n if (ch === '}') {\n depth--\n continue\n }\n if (depth > 0) continue\n if (ch === '=') {\n flush()\n // skip the value: handled by quote/brace state on next chars; reset token\n token = ''\n continue\n }\n if (/\\s/.test(ch)) {\n if (token.trim()) flush()\n continue\n }\n token += ch\n }\n if (token.trim()) flush()\n return names\n}\n\nexport function lineOf(source: string, index: number): number {\n let line = 1\n for (let i = 0; i < index && i < source.length; i++) {\n if (source[i] === '\\n') line++\n }\n return line\n}\n\n/**\n * Check JSX usages of imported cascade components for unknown props.\n * Heuristic — regex/brace-aware scan, not a full AST. Elements using a spread\n * (`{...rest}`) are reported as info and skipped (props can't be statically known).\n */\nexport function findJsxPropViolations(\n source: string,\n filename: string,\n contract: Contract,\n): PropFinding[] {\n const findings: PropFinding[] = []\n const tracked = importedCascadeComponents(source)\n\n for (const comp of tracked) {\n const info = contract.components.get(comp)\n if (!info) continue\n const known = new Set(info.props.map((p) => p.name))\n\n for (const tag of findOpeningTags(source, comp)) {\n const line = lineOf(source, tag.index)\n if (tag.hasSpread) {\n findings.push({\n file: filename,\n line,\n component: comp,\n prop: '...',\n level: 'info',\n rule: 'spread-suppressed',\n message: `<${comp}> uses a spread — prop checks skipped`,\n })\n continue\n }\n for (const name of extractAttrNames(tag.attrs)) {\n if (isPassthrough(name)) continue\n if (known.has(name)) continue\n findings.push({\n file: filename,\n line,\n component: comp,\n prop: name,\n level: 'error',\n rule: 'unknown-prop',\n message: `<${comp}> has unknown prop \"${name}\"`,\n })\n }\n }\n }\n\n return findings\n}\n","import type { Contract } from '../utils/contract-pure.js'\nimport { findOpeningTags, importedCascadeComponents, lineOf } from './jsx-props.js'\n\nexport interface RawStringFinding {\n file: string\n line: number\n component: string\n text: string\n level: 'warn'\n rule: 'raw-string'\n message: string\n}\n\n/** Looks like English prose worth flagging: ≥2 whitespace-separated words, letters/spaces only. */\nfunction looksLikeProse(text: string): boolean {\n const trimmed = text.trim()\n if (!/^[A-Za-z][A-Za-z\\s]*$/.test(trimmed)) return false\n return trimmed.split(/\\s+/).length >= 2\n}\n\n/**\n * Conservative raw-string check: for cascade components that own user-facing\n * chrome text (intent.content), warn when a literal multi-word English child\n * appears, suggesting the labels prop / i18n. Never errors. Only inspects the\n * immediate text directly after the opening tag (no nested element traversal).\n */\nexport function findRawStringViolations(\n source: string,\n filename: string,\n contract: Contract,\n): RawStringFinding[] {\n const findings: RawStringFinding[] = []\n const tracked = importedCascadeComponents(source)\n\n for (const comp of tracked) {\n const info = contract.components.get(comp)\n if (!info?.hasContent) continue\n\n for (const tag of findOpeningTags(source, comp)) {\n // Locate the end of this opening tag in the source.\n const openEnd = source.indexOf('>', tag.index)\n if (openEnd === -1) continue\n if (source[openEnd - 1] === '/') continue // self-closing, no children\n\n // Grab text up to the next tag/expression boundary.\n const after = source.slice(openEnd + 1)\n const stop = after.search(/[<{]/)\n const child = (stop === -1 ? after : after.slice(0, stop)).trim()\n if (!child || !looksLikeProse(child)) continue\n\n findings.push({\n file: filename,\n line: lineOf(source, openEnd),\n component: comp,\n text: child,\n level: 'warn',\n rule: 'raw-string',\n message: `<${comp}> raw text \"${child}\" — use the labels prop / i18n`,\n })\n }\n }\n\n return findings\n}\n","import type { Contract } from '../utils/contract-pure.js'\nimport {\n extractAttrNames,\n findOpeningTags,\n importedCascadeComponents,\n lineOf,\n} from './jsx-props.js'\n\nexport interface RequiredPropFinding {\n file: string\n line: number\n component: string\n prop: string\n level: 'error'\n rule: 'missing-prop'\n message: string\n}\n\n/**\n * Flag cascade elements that omit a prop the component marks required.\n * Elements using a spread are skipped (the prop may arrive via the spread).\n */\nexport function findRequiredPropViolations(\n source: string,\n filename: string,\n contract: Contract,\n): RequiredPropFinding[] {\n const findings: RequiredPropFinding[] = []\n const tracked = importedCascadeComponents(source)\n\n for (const comp of tracked) {\n const info = contract.components.get(comp)\n if (!info?.hasRequiredProps) continue\n\n for (const tag of findOpeningTags(source, comp)) {\n if (tag.hasSpread) continue\n const present = new Set(extractAttrNames(tag.attrs))\n const line = lineOf(source, tag.index)\n for (const req of info.requiredProps) {\n if (present.has(req)) continue\n findings.push({\n file: filename,\n line,\n component: comp,\n prop: req,\n level: 'error',\n rule: 'missing-prop',\n message: `<${comp}> requires \"${req}\"`,\n })\n }\n }\n }\n\n return findings\n}\n","/**\n * Zero-dependency scanner for **unlayered style rules** in a CSS source.\n *\n * cascivo ships everything inside `@layer` blocks. Unlayered author CSS beats\n * every layered rule regardless of specificity (CSS cascade-layer semantics), so\n * a single unlayered style rule silently overrides the whole design system. This\n * scanner finds top-level style rules that live outside any `@layer` block.\n *\n * It is line-based and brace-tracking, not a full CSS parse — good enough because\n * we only need to know, for each `{`, whether an `@layer` block is an ancestor.\n *\n * Transparent to layering: `@media`, `@container`, `@supports`, `@scope` — a rule\n * inside these is layered iff the group is inside a layer. Ignored entirely:\n * `@keyframes`/`@font-face`/`@property`/`@page`/etc. (their inner blocks are not\n * style rules we govern). `@import`/`@charset`/`@layer;` statements are not blocks.\n */\n\nexport interface UnlayeredRule {\n /** 1-indexed line of the rule's selector. */\n line: number\n /** The selector text (trimmed, truncated) for the report. */\n selector: string\n}\n\n/** Replace comment bodies and string contents with spaces, preserving newlines. */\nfunction blankCommentsAndStrings(source: string): string {\n let out = ''\n let i = 0\n const n = source.length\n while (i < n) {\n const c = source[i]!\n const next = source[i + 1]\n if (c === '/' && next === '*') {\n out += ' '\n i += 2\n while (i < n && !(source[i] === '*' && source[i + 1] === '/')) {\n out += source[i] === '\\n' ? '\\n' : ' '\n i++\n }\n out += ' '\n i += 2\n } else if (c === '\"' || c === \"'\") {\n const quote = c\n out += ' '\n i++\n while (i < n && source[i] !== quote) {\n if (source[i] === '\\\\') {\n out += ' '\n i += 2\n continue\n }\n out += source[i] === '\\n' ? '\\n' : ' '\n i++\n }\n out += ' '\n i++\n } else {\n out += c\n i++\n }\n }\n return out\n}\n\ntype FrameKind = 'layer' | 'group' | 'style' | 'other'\n\n/**\n * Accessibility / user-preference media features whose overrides MUST win over\n * everything — including a consumer's `cascivo.override` layer — so they are\n * legitimately placed unlayered (top-level). A `@media (forced-colors: active)`\n * block outside `@layer` is the sanctioned cascade idiom, not a hotfix leak.\n */\nconst A11Y_GUARANTEE_RE =\n /@media[^{]*\\b(forced-colors|prefers-contrast|prefers-reduced-motion|prefers-reduced-transparency|inverted-colors)\\b/\n\nfunction classifyPrelude(prelude: string): FrameKind {\n const p = prelude.trim().toLowerCase()\n if (p.startsWith('@layer')) return 'layer'\n // A11y-guarantee media queries are an exempt (non-flagging) context.\n if (A11Y_GUARANTEE_RE.test(p)) return 'other'\n if (\n p.startsWith('@media') ||\n p.startsWith('@container') ||\n p.startsWith('@supports') ||\n p.startsWith('@scope')\n ) {\n return 'group'\n }\n if (p.startsWith('@')) return 'other'\n return 'style'\n}\n\n/**\n * Return every top-level style rule that is NOT inside an `@layer` block. Only the\n * outermost unlayered rule is reported (nested rules inside it are implied).\n */\nexport function findUnlayeredRules(source: string): UnlayeredRule[] {\n const clean = blankCommentsAndStrings(source)\n const rules: UnlayeredRule[] = []\n const stack: FrameKind[] = []\n\n let preludeStart = 0\n const lineStarts: number[] = [0]\n for (let i = 0; i < clean.length; i++) {\n if (clean[i] === '\\n') lineStarts.push(i + 1)\n }\n const lineOf = (idx: number): number => {\n // binary search over lineStarts\n let lo = 0\n let hi = lineStarts.length - 1\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1\n if (lineStarts[mid]! <= idx) lo = mid\n else hi = mid - 1\n }\n return lo + 1\n }\n\n const hasAncestor = (kind: FrameKind): boolean => stack.includes(kind)\n\n for (let i = 0; i < clean.length; i++) {\n const c = clean[i]\n if (c === '{') {\n const prelude = clean.slice(preludeStart, i)\n const kind = classifyPrelude(prelude)\n if (\n kind === 'style' &&\n !hasAncestor('layer') &&\n !hasAncestor('other') &&\n !hasAncestor('style')\n ) {\n const trimmed = prelude.trim().replace(/\\s+/g, ' ')\n const startIdx = preludeStart + (prelude.length - prelude.trimStart().length)\n rules.push({\n line: lineOf(startIdx),\n selector: trimmed.length > 60 ? `${trimmed.slice(0, 57)}…` : trimmed,\n })\n }\n stack.push(kind)\n preludeStart = i + 1\n } else if (c === '}') {\n stack.pop()\n preludeStart = i + 1\n } else if (c === ';') {\n // A statement terminator (@import, `@layer a, b;`, or a declaration inside a\n // block). Reset the prelude window so the next `{` sees a clean selector.\n preludeStart = i + 1\n }\n }\n\n return rules\n}\n","import { findUnlayeredRules } from '../utils/css-layers.js'\n\nexport interface UnlayeredFinding {\n file: string\n line: number\n selector: string\n level: 'warn'\n rule: 'unlayered-css'\n message: string\n}\n\nconst MESSAGE =\n 'Unlayered CSS beats every cascivo layer regardless of specificity. ' +\n 'For a one-off override use `@layer cascivo.override { … }`; for app styles declare ' +\n 'an app layer (e.g. cascivo.example) in your order statement. See docs/CSS-LAYERS-PITFALL.md.'\n\n/**\n * Warn on top-level style rules that live outside any `@layer` block. This is the\n * consumer-facing half of the zero-unlayered guard: it teaches the fix rather than\n * failing the build, because `docs/USING-WITH-TAILWIND.md` blesses deliberate\n * unlayered CSS as a valid interop escape hatch. Accessibility-guarantee media\n * queries (`forced-colors`, `prefers-contrast`, …) are exempt — see css-layers.ts.\n */\nexport function findUnlayeredViolations(source: string, filename: string): UnlayeredFinding[] {\n return findUnlayeredRules(source).map((rule) => ({\n file: filename,\n line: rule.line,\n selector: rule.selector,\n level: 'warn',\n rule: 'unlayered-css',\n message: MESSAGE,\n }))\n}\n","import { lineOf } from './jsx-props.js'\n\nexport interface VendorCssFinding {\n file: string\n line: number\n specifier: string\n level: 'warn'\n rule: 'vendor-css-import'\n message: string\n}\n\n// `import '<spec>'` or `import x from '<spec>'` where <spec> ends in .css\n// (optionally with a ?query / #hash). Captures the specifier.\nconst CSS_IMPORT_RE = /import\\s+(?:[^'\"]*?\\bfrom\\s+)?(['\"])([^'\"]+\\.css(?:[?#][^'\"]*)?)\\1/g\n\n/** A bare specifier resolves into node_modules (not a relative or absolute path). */\nfunction isBareSpecifier(spec: string): boolean {\n return !spec.startsWith('.') && !spec.startsWith('/')\n}\n\nconst MESSAGE =\n 'CSS imported from a package through JS/TS cannot be wrapped in an @layer, so if this ' +\n 'package ships unlayered global CSS it beats every cascivo layer. Route it through a CSS ' +\n 'file instead: `@import url(\"<pkg>/styles.css\") layer(vendor);`. See docs/THIRD-PARTY-CSS.md.'\n\n/**\n * Warn on bare (node_modules) `*.css` imports in JS/TS. Relative imports (the\n * consumer's own CSS modules) and cascivo's own already-layered `@cascivo/*`\n * stylesheets are exempt. Level `warn` — teaches the layer(vendor) recipe.\n */\nexport function findVendorCssImports(source: string, filename: string): VendorCssFinding[] {\n const findings: VendorCssFinding[] = []\n for (const m of source.matchAll(CSS_IMPORT_RE)) {\n const spec = m[2]\n if (spec === undefined) continue\n if (!isBareSpecifier(spec)) continue\n // cascivo's own stylesheets ship the layer statement + fully-layered rules.\n if (spec.startsWith('@cascivo/')) continue\n findings.push({\n file: filename,\n line: lineOf(source, m.index ?? 0),\n specifier: spec,\n level: 'warn',\n rule: 'vendor-css-import',\n message: MESSAGE,\n })\n }\n return findings\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport type { BuildContractInput, ComponentInfo, Contract, PropInfo } from './contract-pure.js'\nexport { buildContract, normalizeValue } from './contract-pure.js'\nimport type { Contract } from './contract-pure.js'\nimport { buildContract } from './contract-pure.js'\n\nconst HERE = dirname(fileURLToPath(import.meta.url))\n\n/** Walk up from a start directory looking for the apps/site/public dir. */\nfunction findDocsPublic(startDir: string): string | null {\n let dir = startDir\n for (let i = 0; i < 10; i++) {\n const candidate = join(dir, 'apps', 'site', 'public')\n if (existsSync(candidate)) return candidate\n dir = join(dir, '..')\n }\n return null\n}\n\n/** Walk up from a start directory looking for registry.json at the repo root. */\nfunction findRegistry(startDir: string): string | null {\n let dir = startDir\n for (let i = 0; i < 10; i++) {\n const candidate = join(dir, 'registry.json')\n if (existsSync(candidate)) return candidate\n dir = join(dir, '..')\n }\n return null\n}\n\n/**\n * Load the published cascade contract from local generated artifacts:\n * - token catalog (apps/site/public/tokens.catalog.json) → value→token map\n * - registry.json (repo root) → component prop index\n * - context bundle (apps/site/public/context.json) → which components have chrome text\n */\nexport async function loadContract(options?: {\n catalogPath?: string\n contextPath?: string\n registryPath?: string\n}): Promise<Contract> {\n const docsPublic = findDocsPublic(HERE) ?? findDocsPublic(process.cwd())\n const catalogPath =\n options?.catalogPath ?? (docsPublic ? join(docsPublic, 'tokens.catalog.json') : null)\n const contextPath = options?.contextPath ?? (docsPublic ? join(docsPublic, 'context.json') : null)\n const registryPath = options?.registryPath ?? findRegistry(HERE) ?? findRegistry(process.cwd())\n\n if (!catalogPath || !existsSync(catalogPath)) {\n throw new Error('token catalog not found (apps/site/public/tokens.catalog.json)')\n }\n if (!registryPath || !existsSync(registryPath)) {\n throw new Error('registry.json not found')\n }\n if (!contextPath || !existsSync(contextPath)) {\n throw new Error('context bundle not found (apps/site/public/context.json)')\n }\n\n const catalog = JSON.parse(readFileSync(catalogPath, 'utf8')) as Parameters<\n typeof buildContract\n >[0]['catalog']\n const registry = JSON.parse(readFileSync(registryPath, 'utf8')) as Parameters<\n typeof buildContract\n >[0]['registry']\n const context = JSON.parse(readFileSync(contextPath, 'utf8')) as Parameters<\n typeof buildContract\n >[0]['context']\n\n return buildContract({ catalog, registry, context })\n}\n","import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'\nimport { extname, join } from 'node:path'\nimport type { LiteralFinding } from '../audit-ai/css-literals.js'\nimport { findCssLiteralViolations } from '../audit-ai/css-literals.js'\nimport type { PropFinding } from '../audit-ai/jsx-props.js'\nimport { findJsxPropViolations } from '../audit-ai/jsx-props.js'\nimport type { RawStringFinding } from '../audit-ai/raw-strings.js'\nimport { findRawStringViolations } from '../audit-ai/raw-strings.js'\nimport type { RequiredPropFinding } from '../audit-ai/required-props.js'\nimport { findRequiredPropViolations } from '../audit-ai/required-props.js'\nimport type { UnlayeredFinding } from '../audit-ai/unlayered.js'\nimport { findUnlayeredViolations } from '../audit-ai/unlayered.js'\nimport type { VendorCssFinding } from '../audit-ai/vendor-css.js'\nimport { findVendorCssImports } from '../audit-ai/vendor-css.js'\nimport type { CascadeConfig } from '../utils/config.js'\nimport type { Contract } from '../utils/contract.js'\nimport { loadContract } from '../utils/contract.js'\n\nexport type Finding =\n | LiteralFinding\n | PropFinding\n | RequiredPropFinding\n | RawStringFinding\n | UnlayeredFinding\n | VendorCssFinding\n\nconst SKIP_DIRS = new Set(['node_modules', 'dist', '.git', 'build', '.next', 'coverage'])\n\nfunction collectFiles(paths: string[]): string[] {\n const out: string[] = []\n const walk = (p: string) => {\n if (!existsSync(p)) return\n const s = statSync(p)\n if (s.isDirectory()) {\n const base = p.split('/').pop() ?? ''\n if (SKIP_DIRS.has(base)) return\n for (const entry of readdirSync(p)) walk(join(p, entry))\n return\n }\n const ext = extname(p)\n if (ext === '.css' || ext === '.tsx' || ext === '.ts') out.push(p)\n }\n for (const p of paths) walk(p)\n return out\n}\n\nfunction findingsFor(file: string, source: string, contract: Contract): Finding[] {\n const ext = extname(file)\n const findings: Finding[] = []\n if (ext === '.css') {\n findings.push(...findCssLiteralViolations(source, file, contract))\n findings.push(...findUnlayeredViolations(source, file))\n } else if (ext === '.tsx' || ext === '.ts') {\n findings.push(...findCssLiteralViolations(source, file, contract))\n findings.push(...findJsxPropViolations(source, file, contract))\n findings.push(...findRequiredPropViolations(source, file, contract))\n findings.push(...findRawStringViolations(source, file, contract))\n findings.push(...findVendorCssImports(source, file))\n }\n return findings\n}\n\nfunction detail(f: Finding): string {\n switch (f.rule) {\n case 'hardcoded-value':\n if (f.suggestedToken) return `${f.value} → var(${f.suggestedToken})`\n return `${f.value} → ${f.allMatches?.join(' | ') ?? '(ambiguous)'}`\n case 'unknown-prop':\n return `<${f.component} ${f.prop}>`\n case 'spread-suppressed':\n return `<${f.component} {...}> (props not checked)`\n case 'missing-prop':\n return `<${f.component}> requires \"${f.prop}\"`\n case 'raw-string':\n return `\"${f.text}\" → use labels prop / i18n`\n case 'unlayered-css':\n return `${f.selector} { … } → wrap in @layer`\n case 'vendor-css-import':\n return `import '${f.specifier}' → @import url(…) layer(vendor)`\n }\n}\n\nfunction levelLabel(level: Finding['level']): string {\n return level === 'warn' ? 'warn' : level\n}\n\nfunction renderFindings(findings: Finding[]): void {\n if (findings.length === 0) {\n console.log('cascade audit --ai: no findings.')\n return\n }\n const rows = findings.map((f) => ({\n loc: `${f.file}:${f.line}`,\n level: levelLabel(f.level),\n rule: f.rule,\n detail: detail(f),\n }))\n const locW = Math.max(...rows.map((r) => r.loc.length), 8)\n const lvlW = Math.max(...rows.map((r) => r.level.length), 5)\n const ruleW = Math.max(...rows.map((r) => r.rule.length), 4)\n for (const r of rows) {\n console.log(\n `${r.loc.padEnd(locW)} ${r.level.padEnd(lvlW)} ${r.rule.padEnd(ruleW)} ${r.detail}`,\n )\n }\n console.log('---')\n const errors = findings.filter((f) => f.level === 'error').length\n const warnings = findings.filter((f) => f.level === 'warn').length\n const infos = findings.filter((f) => f.level === 'info').length\n const parts = [\n `${errors} error${errors === 1 ? '' : 's'}`,\n `${warnings} warning${warnings === 1 ? '' : 's'}`,\n ]\n if (infos) parts.push(`${infos} info`)\n console.log(parts.join(', '))\n}\n\nfunction escapeRe(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Pure literal→token rewrite. Only rewrites simple `property: #hex;` style\n * declarations where exactly one token matches. Returns the new source and how\n * many findings were resolved (verified by re-running the checker).\n */\nexport function fixCssLiterals(\n source: string,\n file: string,\n contract: Contract,\n): { source: string; fixed: number } {\n const fixable = findCssLiteralViolations(source, file, contract).filter(\n (f) => f.level === 'error' && f.suggestedToken && /^#[0-9a-fA-F]{3,8}$/.test(f.value),\n )\n let next = source\n for (const f of fixable) {\n // Only rewrite a full-value declaration: `prop: #hex;` (or end of block).\n const re = new RegExp(`(${escapeRe(f.property)}\\\\s*:\\\\s*)${escapeRe(f.value)}(\\\\s*[;}])`, 'gi')\n next = next.replace(re, `$1var(${f.suggestedToken})$2`)\n }\n if (next === source) return { source, fixed: 0 }\n const remaining = findCssLiteralViolations(next, file, contract).filter(\n (f) => f.level === 'error' && f.suggestedToken,\n ).length\n return { source: next, fixed: fixable.length - remaining }\n}\n\n/** Apply {@link fixCssLiterals} to each .css file on disk. */\nfunction applyFixes(files: string[], contract: Contract): number {\n let fixed = 0\n for (const file of files) {\n if (extname(file) !== '.css') continue\n const { source, fixed: n } = fixCssLiterals(readFileSync(file, 'utf8'), file, contract)\n if (n > 0) {\n writeFileSync(file, source)\n fixed += n\n }\n }\n return fixed\n}\n\nexport async function audit(args: string[], _config: CascadeConfig): Promise<void> {\n if (!args.includes('--ai')) {\n console.log('cascivo audit: use --ai to audit AI-generated code against the cascivo contract')\n return\n }\n\n const jsonOutput = args.includes('--json')\n const fixMode = args.includes('--fix')\n const levelIdx = args.indexOf('--level')\n const minLevel = levelIdx >= 0 ? (args[levelIdx + 1] ?? 'error') : 'error'\n\n const paths = args.filter((a, i) => {\n if (a.startsWith('--')) return false\n if (levelIdx >= 0 && i === levelIdx + 1) return false\n return true\n })\n\n let contract: Contract\n try {\n contract = await loadContract()\n } catch (e) {\n console.error(`Contract unavailable: ${e instanceof Error ? e.message : String(e)}`)\n process.exitCode = 2\n return\n }\n\n const files = collectFiles(paths.length ? paths : [process.cwd()])\n\n if (fixMode) {\n const n = applyFixes(files, contract)\n console.log(`cascade audit --ai --fix: rewrote ${n} literal${n === 1 ? '' : 's'} to tokens.`)\n }\n\n const allFindings: Finding[] = []\n for (const file of files) {\n allFindings.push(...findingsFor(file, readFileSync(file, 'utf8'), contract))\n }\n\n if (jsonOutput) {\n console.log(JSON.stringify(allFindings, null, 2))\n } else {\n renderFindings(allFindings)\n }\n\n const hasErrors = allFindings.some((f) => f.level === 'error')\n if (minLevel === 'error' && hasErrors) process.exitCode = 1\n if (minLevel === 'warn' && allFindings.some((f) => f.level !== 'info')) process.exitCode = 1\n}\n"],"mappings":";;;;;AAmEA,SAAgB,eAAe,OAAuB;CACpD,OAAO,MAAM,YAAY,CAAC,CAAC,QAAQ,QAAQ,EAAE;AAC/C;;AAGA,SAAgB,cAAc,OAAqC;CACjE,MAAM,gCAAgB,IAAI,IAAsB;CAChD,KAAK,MAAM,SAAS,MAAM,QAAQ,QAAQ;EACxC,IAAI,MAAM,mBAAmB,MAAM;EACnC,MAAM,MAAM,eAAe,MAAM,eAAe;EAChD,MAAM,OAAO,cAAc,IAAI,GAAG;EAClC,IAAI,MAAM,KAAK,KAAK,MAAM,IAAI;OACzB,cAAc,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC;CAC1C;CAEA,MAAM,+BAAe,IAAI,IAAY;CACrC,KAAK,MAAM,KAAK,MAAM,QAAQ,YAC5B,IAAI,EAAE,QAAQ,SAAS,aAAa,IAAI,EAAE,IAAI;CAGhD,MAAM,6BAAa,IAAI,IAA2B;CAClD,KAAK,MAAM,SAAS,MAAM,SAAS,YAAY;EAC7C,MAAM,OAAO,MAAM;EACnB,IAAI,CAAC,MAAM,MAAM;EACjB,MAAM,SAAqB,KAAK,SAAS,CAAC,EAAA,CAAG,KAAK,OAAO;GACvD,MAAM,EAAE;GACR,MAAM,EAAE,QAAQ;GAChB,UAAU,EAAE,aAAa;EAC3B,EAAE;EACF,MAAM,gBAAgB,MAAM,QAAQ,MAAM,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CAC9F;CAEA,MAAM,cAAyB,CAAC;CAChC,KAAK,MAAM,QAAQ,OACjB,YAAY,KAAK,GAAG,YAAY,MAAM,aAAa,MAAM,MAAM,GAAG,QAAQ,CAAC;CAG7E,IAAI,YACF,QAAQ,IAAI,KAAK,UAAU,aAAa,MAAM,CAAC,CAAC;MAEhD,eAAe,WAAW;CAG5B,MAAM,YAAY,YAAY,MAAM,MAAM,EAAE,UAAU,OAAO;CAC7D,IAAI,aAAa,WAAW,WAAW,QAAQ,WAAW;CAC1D,IAAI,aAAa,UAAU,YAAY,MAAM,MAAM,EAAE,UAAU,MAAM,GAAG,QAAQ,WAAW;AAC7F"}
package/dist/index.mjs CHANGED
@@ -526,7 +526,9 @@ function indexHtml(opts) {
526
526
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
527
527
  <title>${opts.name}</title>
528
528
  <style>
529
- @layer cascivo.reset, cascivo.base, cascivo.tokens, cascivo.component, cascivo.theme, cascivo.override;
529
+ @layer vendor, cascivo.reset, cascivo.base, cascivo.tokens, cascivo.component, cascivo.theme, cascivo.blocks, cascivo.override;
530
+ /* Third-party CSS goes in the low-priority vendor layer so it can't beat cascivo:
531
+ @import url('some-lib/styles.css') layer(vendor); — see docs/THIRD-PARTY-CSS.md */
530
532
  @layer cascivo.reset {
531
533
  *,
532
534
  *::before,
@@ -687,6 +689,53 @@ npm run dev
687
689
  Add more components with \`npx cascivo add <component>\`.
688
690
  `;
689
691
  }
692
+ function agentsMd(opts) {
693
+ return `# Agent instructions — ${opts.name}
694
+
695
+ This is a [cascivo](https://cascivo.com) app. When generating or editing CSS, follow
696
+ the **layer contract** — cascivo styles live in cascade layers, and layer order beats
697
+ selector specificity.
698
+
699
+ ## CSS layer contract
700
+
701
+ 1. Every declaration goes inside an \`@layer\` block. Unlayered CSS beats all layers
702
+ regardless of specificity — never emit it.
703
+ 2. Never invent layer names. Write only: your app slot \`cascivo.example\` (declared in
704
+ the order statement in \`index.html\`) for page styles, and
705
+ \`@layer cascivo.override { … }\` for hotfixes / one-off overrides — it beats
706
+ everything cascivo ships.
707
+ 3. Never nest layers deeper than the shipped \`cascivo.blocks.<name>\` pattern. For
708
+ sub-elements, use native CSS nesting inside one layer block, not new sublayers.
709
+ 4. Third-party CSS: \`@import url('lib/styles.css') layer(vendor);\` with \`vendor\`
710
+ declared before the cascivo layers. Never import vendor CSS from JavaScript.
711
+ 5. Style with \`--cascivo-*\` tokens, not raw values.
712
+
713
+ This app's declared layer order (in \`index.html\`):
714
+
715
+ \`\`\`css
716
+ @layer vendor, cascivo.reset, cascivo.base, cascivo.tokens, cascivo.component,
717
+ cascivo.theme, cascivo.blocks, cascivo.override;
718
+ \`\`\`
719
+
720
+ ### Worked example — nesting, not new layers
721
+
722
+ \`\`\`css
723
+ @layer cascivo.override {
724
+ .projectCard {
725
+ /* Sub-elements nest inside the one block — no cascivo.card.status sublayer. */
726
+ .statusBadge {
727
+ color: var(--cascivo-color-text-subtle);
728
+ .pulseDot {
729
+ background: var(--cascivo-color-success);
730
+ }
731
+ }
732
+ }
733
+ }
734
+ \`\`\`
735
+
736
+ More: cascivo's machine-readable guide is at https://cascivo.com/llms.txt.
737
+ `;
738
+ }
690
739
  /** Build the full set of files for a new cascivo app. Pure — no filesystem I/O. */
691
740
  function buildScaffold(opts) {
692
741
  const sections = resolveSections(opts.sections);
@@ -719,6 +768,10 @@ function buildScaffold(opts) {
719
768
  path: "README.md",
720
769
  contents: readme(opts)
721
770
  },
771
+ {
772
+ path: "AGENTS.md",
773
+ contents: agentsMd(opts)
774
+ },
722
775
  {
723
776
  path: "src/main.tsx",
724
777
  contents: mainTsx()
@@ -2131,7 +2184,7 @@ async function run(args) {
2131
2184
  break;
2132
2185
  }
2133
2186
  case "audit": {
2134
- const { audit } = await import("./audit-InQqdY1s.mjs");
2187
+ const { audit } = await import("./audit-jseQagw5.mjs");
2135
2188
  await audit(rest, await loadConfig());
2136
2189
  break;
2137
2190
  }