cascivo 0.6.2 → 0.7.2
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/{audit-Cn6HJkuo.mjs → audit-C4ul-2Ix.mjs} +35 -9
- package/dist/audit-C4ul-2Ix.mjs.map +1 -0
- package/dist/{config-C6GdrbvF.mjs → config-D7ddWN_9.mjs} +27 -4
- package/dist/{config-C6GdrbvF.mjs.map → config-D7ddWN_9.mjs.map} +1 -1
- package/dist/{drift-qTzJ75Ds.mjs → drift-B02BbFN_.mjs} +22 -15
- package/dist/drift-B02BbFN_.mjs.map +1 -0
- package/dist/generated/audit-contract.json +500 -8
- package/dist/index.mjs +404 -55
- package/dist/index.mjs.map +1 -1
- package/dist/lock-CW8UuEPJ.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/audit-Cn6HJkuo.mjs.map +0 -1
- package/dist/drift-qTzJ75Ds.mjs.map +0 -1
|
@@ -18,6 +18,7 @@ function buildContract(input) {
|
|
|
18
18
|
else tokensByValue.set(key, [token.name]);
|
|
19
19
|
}
|
|
20
20
|
const contentNames = /* @__PURE__ */ new Set();
|
|
21
|
+
const primitiveNames = new Set(input.contentPrimitives ?? []);
|
|
21
22
|
for (const c of input.context.components) if (c.intent?.content) contentNames.add(c.name);
|
|
22
23
|
const byName = /* @__PURE__ */ new Map();
|
|
23
24
|
for (const entry of input.registry.components) {
|
|
@@ -52,12 +53,14 @@ function buildContract(input) {
|
|
|
52
53
|
hasRequiredProps: requiredProps.length > 0,
|
|
53
54
|
requiresChildren: all.some((p) => p.name === "children" && p.required),
|
|
54
55
|
hasContent: contentNames.has(name),
|
|
56
|
+
isContentPrimitive: primitiveNames.has(name),
|
|
55
57
|
entryCount: metas.length
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
return {
|
|
59
61
|
tokensByValue,
|
|
60
|
-
components
|
|
62
|
+
components,
|
|
63
|
+
domAttributes: new Set(input.domAttributes ?? [])
|
|
61
64
|
};
|
|
62
65
|
}
|
|
63
66
|
//#endregion
|
|
@@ -288,8 +291,9 @@ const HTML_PASSTHROUGH = new Set([
|
|
|
288
291
|
"disabled",
|
|
289
292
|
"open"
|
|
290
293
|
]);
|
|
291
|
-
function isPassthrough(prop) {
|
|
294
|
+
function isPassthrough(prop, contract) {
|
|
292
295
|
if (PASSTHROUGH.has(prop)) return true;
|
|
296
|
+
if (contract?.domAttributes.has(prop) === true) return true;
|
|
293
297
|
if (HTML_PASSTHROUGH.has(prop)) return true;
|
|
294
298
|
if (prop.startsWith("data-")) return true;
|
|
295
299
|
if (prop.startsWith("aria-")) return true;
|
|
@@ -448,7 +452,7 @@ function findJsxPropViolations(source, filename, contract) {
|
|
|
448
452
|
continue;
|
|
449
453
|
}
|
|
450
454
|
for (const name of extractAttrNames(tag.attrs)) {
|
|
451
|
-
if (isPassthrough(name)) continue;
|
|
455
|
+
if (isPassthrough(name, contract)) continue;
|
|
452
456
|
if (known.has(name)) continue;
|
|
453
457
|
findings.push({
|
|
454
458
|
file: filename,
|
|
@@ -477,12 +481,17 @@ function looksLikeProse(text) {
|
|
|
477
481
|
* chrome text (intent.content), warn when a literal multi-word English child
|
|
478
482
|
* appears, suggesting the labels prop / i18n. Never errors. Only inspects the
|
|
479
483
|
* immediate text directly after the opening tag (no nested element traversal).
|
|
484
|
+
*
|
|
485
|
+
* Typography primitives (`intent.content.contentPrimitive`) are excluded: their children
|
|
486
|
+
* are page copy, not component chrome.
|
|
480
487
|
*/
|
|
481
488
|
function findRawStringViolations(source, filename, contract) {
|
|
482
489
|
const findings = [];
|
|
483
490
|
const tracked = importedCascadeComponents(source);
|
|
484
491
|
for (const [comp, contractName] of tracked) {
|
|
485
|
-
|
|
492
|
+
const info = contract.components.get(contractName);
|
|
493
|
+
if (!info?.hasContent) continue;
|
|
494
|
+
if (info.isContentPrimitive) continue;
|
|
486
495
|
for (const tag of findOpeningTags(source, comp)) {
|
|
487
496
|
const openEnd = source.indexOf(">", tag.index);
|
|
488
497
|
if (openEnd === -1) continue;
|
|
@@ -826,7 +835,9 @@ function fromBundled(bundled) {
|
|
|
826
835
|
context: { components: bundled.content.map((name) => ({
|
|
827
836
|
name,
|
|
828
837
|
intent: { content: true }
|
|
829
|
-
})) }
|
|
838
|
+
})) },
|
|
839
|
+
...bundled.domAttributes ? { domAttributes: bundled.domAttributes } : {},
|
|
840
|
+
...bundled.contentPrimitives ? { contentPrimitives: bundled.contentPrimitives } : {}
|
|
830
841
|
});
|
|
831
842
|
}
|
|
832
843
|
/** Where the network fallback caches a downloaded contract. */
|
|
@@ -869,10 +880,25 @@ async function loadContract(options) {
|
|
|
869
880
|
throw new Error("cascivo contract unavailable. Pass --contract <path> to a downloaded audit-contract.json, or run inside the cascivo monorepo. (The CLI normally ships one; this build appears to be missing it.)");
|
|
870
881
|
}
|
|
871
882
|
report("monorepo artifacts");
|
|
883
|
+
const catalog = JSON.parse(readFileSync(catalogPath, "utf8"));
|
|
884
|
+
const registry = JSON.parse(readFileSync(registryPath, "utf8"));
|
|
885
|
+
const context = JSON.parse(readFileSync(contextPath, "utf8"));
|
|
886
|
+
let domAttributes;
|
|
887
|
+
let contentPrimitives;
|
|
888
|
+
try {
|
|
889
|
+
const generated = JSON.parse(readFileSync(join(docsPublic, "audit-contract.json"), "utf8"));
|
|
890
|
+
domAttributes = generated.domAttributes;
|
|
891
|
+
contentPrimitives = generated.contentPrimitives;
|
|
892
|
+
} catch {
|
|
893
|
+
domAttributes = void 0;
|
|
894
|
+
contentPrimitives = void 0;
|
|
895
|
+
}
|
|
872
896
|
return buildContract({
|
|
873
|
-
catalog
|
|
874
|
-
registry
|
|
875
|
-
context
|
|
897
|
+
catalog,
|
|
898
|
+
registry,
|
|
899
|
+
context,
|
|
900
|
+
...domAttributes ? { domAttributes } : {},
|
|
901
|
+
...contentPrimitives ? { contentPrimitives } : {}
|
|
876
902
|
});
|
|
877
903
|
}
|
|
878
904
|
//#endregion
|
|
@@ -1054,4 +1080,4 @@ async function audit(args, _config) {
|
|
|
1054
1080
|
//#endregion
|
|
1055
1081
|
export { audit };
|
|
1056
1082
|
|
|
1057
|
-
//# sourceMappingURL=audit-
|
|
1083
|
+
//# sourceMappingURL=audit-C4ul-2Ix.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-C4ul-2Ix.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/audit-ai/suppress.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 /**\n * Props that have required: true, EXCLUDING `children`. A component's children arrive as\n * JSX element content, not as an attribute, and the audit's prop scan only ever sees the\n * opening tag — so a required `children` reported every correct usage as missing. It is\n * checked separately, via the self-closing flag.\n */\n requiredProps: string[]\n /** True when the component's manifest marks `children` required. */\n requiresChildren: boolean\n /** True if the component declares user-facing chrome text (intent.content) */\n hasContent: boolean\n /**\n * True for a typography primitive whose children are authored page prose rather than\n * chrome the component owns. The `raw-string` rule skips these — otherwise every\n * sentence on every page warns and the real findings are buried.\n */\n isContentPrimitive: boolean\n /**\n * Number of distinct registry entries that share this display name. More than one means\n * the name is ambiguous (`AppShell` is both the npm component and the copy-paste\n * `layout/app-shell`, with different prop surfaces) and the props below are the UNION —\n * see `buildContract`.\n */\n entryCount: number\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 * DOM attribute names cascivo components inherit from a React `*HTMLAttributes` base and\n * spread onto their element — resolved from the types at contract-generation time, not\n * hand-listed. Empty when reading an older contract that predates the field.\n */\n domAttributes: Set<string>\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 /** Inherited DOM attributes, from the shipped contract. Absent in older contracts. */\n domAttributes?: string[]\n /** Typography-primitive names, from the shipped contract. Absent in older contracts. */\n contentPrimitives?: string[]\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 const primitiveNames = new Set<string>(input.contentPrimitives ?? [])\n for (const c of input.context.components) {\n if (c.intent?.content) contentNames.add(c.name)\n }\n\n // Several registry entries share a display name — `AppShell` is both the npm component\n // (props: header/nav/children/…) and the copy-paste `layout/app-shell` (props:\n // header/sideNav/aside/persistKey/…), and `Calendar` is both the component and the chart.\n // Keying a Map by name meant the last one won, so every adopter of `@cascivo/react`'s\n // AppShell was audited against a component they don't have: `nav` came back as an\n // \"unknown prop\" and `sideNav` was the only recognised slot.\n //\n // A JSX name alone cannot tell the entries apart, so the contract merges them: props are\n // the UNION (no false `unknown-prop`), and `required` only survives when EVERY entry with\n // that name requires it (no false `missing-prop`).\n const byName = new Map<string, RegistryComponentMeta[]>()\n for (const entry of input.registry.components) {\n const meta = entry.meta\n if (!meta?.name) continue\n const list = byName.get(meta.name)\n if (list) list.push(meta)\n else byName.set(meta.name, [meta])\n }\n\n const components = new Map<string, ComponentInfo>()\n for (const [name, metas] of byName) {\n const props = new Map<string, PropInfo>()\n for (const meta of metas) {\n for (const p of meta.props ?? []) {\n const existing = props.get(p.name)\n // Required only if required in every entry that declares the prop.\n const required = (existing?.required ?? true) && p.required === true\n props.set(p.name, { name: p.name, type: p.type ?? 'unknown', required })\n }\n }\n // A prop absent from one of the entries can't be required overall.\n if (metas.length > 1) {\n for (const [propName, info] of props) {\n const inEvery = metas.every((m) => (m.props ?? []).some((p) => p.name === propName))\n if (!inEvery) props.set(propName, { ...info, required: false })\n }\n }\n const all = [...props.values()]\n // `children` is element content, not an attribute — tracked separately.\n const requiredProps = all.filter((p) => p.required && p.name !== 'children').map((p) => p.name)\n components.set(name, {\n props: all,\n requiredProps,\n hasRequiredProps: requiredProps.length > 0,\n requiresChildren: all.some((p) => p.name === 'children' && p.required),\n hasContent: contentNames.has(name),\n isContentPrimitive: primitiveNames.has(name),\n entryCount: metas.length,\n })\n }\n\n return { tokensByValue, components, domAttributes: new Set(input.domAttributes ?? []) }\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' | 'warn' | '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 * Character ranges covered by a JSX `style={{ … }}` object.\n *\n * The inline-style scan used to run over every `prop: 'value'` pair in a `.tsx` file, so a\n * plain data object was audited as if it were CSS: a `DataTable` column's\n * `width: '3rem'` was reported as a hardcoded value that should be `--cascivo-space-12`.\n * A spacing token is not the right unit for a table column, and the object was never a\n * style in the first place — the rule was matching the literal, not the context.\n */\nfunction styleObjectRanges(source: string): Array<[number, number]> {\n const ranges: Array<[number, number]> = []\n const re = /style\\s*=\\s*\\{/g\n for (const m of source.matchAll(re)) {\n let depth = 0\n let quote = ''\n for (let i = m.index! + m[0].length - 1; i < source.length; i++) {\n const ch = source[i]\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 === '{') depth++\n else if (ch === '}') {\n depth--\n if (depth === 0) {\n ranges.push([m.index!, i])\n break\n }\n }\n }\n }\n return ranges\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 const styleRanges = styleObjectRanges(source)\n // Absolute offset of the start of each line, so a match can be tested against the ranges.\n const lineStarts: number[] = []\n let offset = 0\n for (const line of lines) {\n lineStarts.push(offset)\n offset += line.length + 1\n }\n const inStyleObject = (absolute: number): boolean =>\n styleRanges.some(([start, end]) => absolute >= start && absolute <= end)\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 // Only inside an actual `style={{ … }}`; a data object that happens to have a\n // `width` key is not CSS.\n if (!inStyleObject((lineStarts[i] ?? 0) + (m.index ?? 0))) 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 // Inline TSX `style={{…}}` overrides are a sanctioned fast-prototyping escape\n // hatch — surface a gentle `warn` (not a loop-blocking `error`) so an agent can\n // finish. `.css`-file literals stay `error`: there the fix is mechanical (`--fix`).\n const inlineCls = cls.level === 'error' ? { ...cls, level: 'warn' as const } : cls\n findings.push({\n file: filename,\n line: i + 1,\n property: prop,\n value: rawValue,\n rule: 'hardcoded-value',\n ...inlineCls,\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). */\nexport const PASSTHROUGH = new Set(['className', 'style', 'id', 'ref', 'key', 'children'])\n\n/**\n * Standard HTML/React DOM attributes. Every cascade component extends an\n * `HTMLAttributes` interface and spreads `{...props}` onto its element (verified\n * in button.tsx, card.tsx, …), so these are valid at runtime even though the\n * hand-written `*.meta.ts` prop lists (the audit contract) don't enumerate them.\n * Without this set, a legitimate `type`/`name`/`title`/`tabIndex` on a Button is\n * a non-suppressible `unknown-prop` error — the audit-loop deadlock.\n */\nexport const HTML_PASSTHROUGH = new Set([\n 'type',\n 'name',\n 'value',\n 'defaultValue',\n 'checked',\n 'defaultChecked',\n 'placeholder',\n 'title',\n 'role',\n 'tabIndex',\n 'form',\n 'href',\n 'target',\n 'rel',\n 'download',\n 'src',\n 'alt',\n 'width',\n 'height',\n 'loading',\n 'autoComplete',\n 'autoFocus',\n 'required',\n 'readOnly',\n 'min',\n 'max',\n 'step',\n 'rows',\n 'cols',\n 'wrap',\n 'maxLength',\n 'minLength',\n 'pattern',\n 'multiple',\n 'accept',\n 'size',\n 'dir',\n 'lang',\n 'hidden',\n 'draggable',\n 'spellCheck',\n 'contentEditable',\n 'inputMode',\n 'enterKeyHint',\n 'htmlFor',\n 'slot',\n 'disabled',\n 'open',\n])\n\nfunction isPassthrough(prop: string, contract?: Contract): boolean {\n if (PASSTHROUGH.has(prop)) return true\n // Resolved from the component types at contract-generation time. `HTML_PASSTHROUGH` below\n // is the pre-contract fallback for an older shipped contract that lacks the field.\n if (contract?.domAttributes.has(prop) === true) return true\n if (HTML_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/**\n * Local JSX names bound to a cascade component, mapped to the contract name they refer to.\n *\n * Two rules, both learned from false positives on correct code:\n *\n * 1. **Track the LOCAL binding, not the imported name.** `import { Link as CascadeLink }`\n * used to register `Link`, so the scan then matched the *router's* `<Link to=…>` and\n * reported `to` as an unknown prop. For a router-based app that collateral is close to\n * guaranteed.\n * 2. **Never audit a name this file also imports from somewhere else.** A bare-name clash\n * (`Link` from `@tanstack/react-router`) must not be audited against cascivo's contract\n * even when nothing is aliased.\n */\nexport function importedCascadeComponents(source: string): Map<string, string> {\n const names = new Map<string, string>()\n const foreign = new Set<string>()\n\n const importRe = /import\\s*(?:type\\s*)?\\{([^}]*)\\}\\s*from\\s*['\"]([^'\"]+)['\"]/g\n for (const m of source.matchAll(importRe)) {\n const [, group, specifier] = m\n if (group === undefined || specifier === undefined) continue\n const isCascade = specifier === '@cascivo/react'\n for (const raw of group.split(',')) {\n const parts = raw.trim().split(/\\s+as\\s+/)\n const imported = parts[0]?.trim().replace(/^type\\s+/, '')\n const local = (parts[1] ?? parts[0])?.trim()\n if (!imported || !local) continue\n if (isCascade) names.set(local, imported)\n else foreign.add(local)\n }\n }\n // A default import (`import Link from 'next/link'`) also shadows the name.\n for (const m of source.matchAll(\n /import\\s+(\\w+)\\s*(?:,\\s*\\{[^}]*\\})?\\s*from\\s*['\"]([^'\"]+)['\"]/g,\n )) {\n if (m[2] !== '@cascivo/react' && m[1]) foreign.add(m[1])\n }\n\n for (const local of foreign) names.delete(local)\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 /** `<Foo />` — the one shape that genuinely cannot have children. */\n selfClosing: 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 selfClosing = /\\/\\s*$/.test(attrs)\n const cleanAttrs = attrs.replace(/\\/\\s*$/, '')\n tags.push({\n attrs: cleanAttrs,\n index: start,\n hasSpread: /\\{\\s*\\.\\.\\./.test(cleanAttrs),\n selfClosing,\n })\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, contractName] of tracked) {\n const info = contract.components.get(contractName)\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, contract)) 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:\n `<${comp}> has unknown prop \"${name}\". ` +\n 'style/className pass through on every component (see the override ladder in ' +\n 'docs/AI-RULES.md); for an intentional one-off add `/* cascivo-audit: allow unknown-prop */`.',\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 *\n * Typography primitives (`intent.content.contentPrimitive`) are excluded: their children\n * are page copy, not component chrome.\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, contractName] of tracked) {\n const info = contract.components.get(contractName)\n if (!info?.hasContent) continue\n // A typography primitive's children ARE the page's authored prose, so \"use the labels\n // prop / i18n\" is advice with no target — `Text` has no labels prop. Warning here fires\n // once per sentence in a real app, which trains adopters to ignore the rule and buries\n // the chrome-label findings it exists to surface.\n if (info.isContentPrimitive) 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, contractName] of tracked) {\n const info = contract.components.get(contractName)\n if (!info) 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 // `children` is element content, not an attribute. The scan only ever sees the\n // opening tag, so treating it like a prop reported EVERY correct usage as missing —\n // `<AppShell>{children}</AppShell>` and `<Field label=\"…\"><Input/></Field>` both.\n // A self-closing tag is the one shape that genuinely has no children.\n if (info.requiresChildren && tag.selfClosing && !present.has('children')) {\n findings.push({\n file: filename,\n line,\n component: comp,\n prop: 'children',\n level: 'error',\n rule: 'missing-prop',\n message: `<${comp} /> is self-closing but requires children`,\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 (`@import url(\"<pkg>/styles.css\") layer(vendor);`) or add @cascivo/vite-plugin ' +\n '(`cascivoLayers({ imports: { \"<pkg>/styles.css\": \"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","/**\n * Inline suppression directives for `cascivo audit --ai`.\n *\n * A comment `cascivo-audit: allow <rule-id>[, <rule-id>…]` (or `allow all`) on the\n * same line as, or the line immediately preceding, a finding downgrades that\n * finding: it is marked `suppressed` so it no longer counts toward the error/warn\n * exit gate, while still being printed so it stays visible. This is the guaranteed\n * loop-breaker for an AI agent — the one escape hatch that no rule can override.\n */\n\n/** Rule ids a directive may name (the user-facing error/warn rules). */\nexport const AUDIT_RULES = new Set<string>([\n 'unknown-prop',\n 'hardcoded-value',\n 'missing-prop',\n 'raw-string',\n 'unlayered-css',\n 'vendor-css-import',\n])\n\nexport interface DirectiveFinding {\n file: string\n line: number\n level: 'warn'\n rule: 'audit-directive'\n message: string\n}\n\ninterface Directive {\n line: number\n rules: 'all' | Set<string>\n}\n\nconst DIRECTIVE_RE = /cascivo-audit:\\s*allow\\s+([^\\n]+)/i\n\n/**\n * Scan a source file for suppression directives. Returns the parsed directives\n * plus `warn`-level findings for any unknown rule id (so typos surface rather\n * than silently failing to suppress).\n */\nexport function parseDirectives(\n source: string,\n file: string,\n): { directives: Directive[]; findings: DirectiveFinding[] } {\n const directives: Directive[] = []\n const findings: DirectiveFinding[] = []\n const lines = source.split('\\n')\n for (let i = 0; i < lines.length; i++) {\n const m = lines[i]?.match(DIRECTIVE_RE)\n if (!m || m[1] === undefined) continue\n // Strip trailing comment terminators (`*/`, `-->`) and whitespace.\n const raw = m[1]\n .replace(/\\*\\/.*$/, '')\n .replace(/-->.*$/, '')\n .trim()\n const ids = raw.split(/[\\s,]+/).filter(Boolean)\n const line = i + 1\n if (ids.includes('all')) {\n directives.push({ line, rules: 'all' })\n continue\n }\n const valid = new Set<string>()\n const unknown: string[] = []\n for (const id of ids) {\n if (AUDIT_RULES.has(id)) valid.add(id)\n else unknown.push(id)\n }\n if (valid.size > 0) directives.push({ line, rules: valid })\n if (unknown.length > 0) {\n findings.push({\n file,\n line,\n level: 'warn',\n rule: 'audit-directive',\n message:\n `unknown audit rule id${unknown.length > 1 ? 's' : ''} in directive: ${unknown.join(', ')}. ` +\n `valid ids: ${[...AUDIT_RULES].join(', ')}.`,\n })\n }\n }\n return { directives, findings }\n}\n\n/**\n * Mark findings covered by a directive as `suppressed`. A directive on line L\n * applies to findings on line L (inline comment) or line L+1 (comment above the\n * code). Level is left unchanged; callers exclude `suppressed` findings from the\n * exit gate.\n */\nexport function applySuppressions<T extends { line: number; rule: string }>(\n findings: T[],\n directives: Directive[],\n): Array<T & { suppressed?: boolean }> {\n if (directives.length === 0) return findings\n return findings.map((f) => {\n const covered = directives.some(\n (d) =>\n (d.line === f.line || d.line === f.line - 1) && (d.rules === 'all' || d.rules.has(f.rule)),\n )\n return covered ? { ...f, suppressed: true } : f\n })\n}\n","import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { tmpdir } from 'node:os'\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\nconst CONTRACT_URL = 'https://cascivo.com/audit-contract.json'\n\n/**\n * Download the contract, caching it by version so a second run is offline-fast. Returns\n * null on any failure — the audit must never hard-depend on the network.\n */\nasync function fetchContract(report: (source: string) => void): Promise<Contract | null> {\n try {\n const response = await fetch(CONTRACT_URL, { signal: AbortSignal.timeout(5000) })\n if (!response.ok) return null\n const bundled = (await response.json()) as BundledContract\n try {\n const target = cachePath(bundled.version)\n mkdirSync(dirname(target), { recursive: true })\n writeFileSync(target, JSON.stringify(bundled))\n } catch {\n // A read-only cache dir is not a reason to fail the audit.\n }\n report(`network: ${CONTRACT_URL}`)\n return fromBundled(bundled)\n } catch {\n return null\n }\n}\n\n/** The reduced contract shipped inside this package (scripts/registry/audit-contract.ts). */\ninterface BundledContract {\n version: string\n tokens: { name: string; resolvedDefault: string | null }[]\n components: { name: string; props: { name: string; type: string; required: boolean }[] }[]\n /** Absent in contracts cut before the hand-listed passthrough set was replaced. */\n domAttributes?: string[]\n content: string[]\n /** Absent in contracts cut before typography primitives were distinguished. */\n contentPrimitives?: string[]\n}\n\n/** Adapt the bundled shape to `buildContract`'s three-artifact input. */\nfunction fromBundled(bundled: BundledContract): Contract {\n return buildContract({\n catalog: { tokens: bundled.tokens },\n registry: { components: bundled.components.map((c) => ({ meta: c })) },\n context: { components: bundled.content.map((name) => ({ name, intent: { content: true } })) },\n ...(bundled.domAttributes ? { domAttributes: bundled.domAttributes } : {}),\n ...(bundled.contentPrimitives ? { contentPrimitives: bundled.contentPrimitives } : {}),\n })\n}\n\n/** Where the network fallback caches a downloaded contract. */\nfunction cachePath(version: string): string {\n const base = process.env['XDG_CACHE_HOME'] ?? join(process.env['HOME'] ?? tmpdir(), '.cache')\n return join(base, 'cascivo', `audit-contract-${version}.json`)\n}\n\n/**\n * Load the cascade contract. Resolution order, first hit wins:\n *\n * 1. an explicit path (`--contract <file>` / `options.contractPath`)\n * 2. the dev-monorepo artifacts (`apps/site/public/…` + `registry.json`)\n * 3. the contract bundled in this package ← what makes `audit` work in a real project\n * 4. `https://cascivo.com/audit-contract.json`, cached under `~/.cache/cascivo/`\n *\n * (3) is why this exists: the walk-up in (2) only ever finds anything inside this monorepo,\n * so `cascivo audit --ai` died with \"token catalog not found\" in every consumer project —\n * a documented, working feature that nobody outside this repo could run. (4) is best-effort\n * and never required: `audit` works offline.\n */\nexport async function loadContract(options?: {\n catalogPath?: string\n contextPath?: string\n registryPath?: string\n /** Explicit contract file — either the bundled shape or a docs-public directory. */\n contractPath?: string\n /** Report which tier answered (used by `--verbose`). */\n onResolve?: (source: string) => void\n}): Promise<Contract> {\n const report = options?.onResolve ?? (() => {})\n\n // 1. Explicit path.\n if (options?.contractPath) {\n if (!existsSync(options.contractPath)) {\n throw new Error(`contract file not found: ${options.contractPath}`)\n }\n report(`explicit: ${options.contractPath}`)\n return fromBundled(JSON.parse(readFileSync(options.contractPath, 'utf8')) as BundledContract)\n }\n\n // 2. Dev monorepo — unchanged, so in-repo behavior and its tests are untouched.\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 const haveMonorepo =\n catalogPath &&\n existsSync(catalogPath) &&\n registryPath &&\n existsSync(registryPath) &&\n contextPath &&\n existsSync(contextPath)\n\n if (!haveMonorepo) {\n // 3. Bundled contract.\n const bundled = join(HERE, 'generated', 'audit-contract.json')\n const bundledDist = join(HERE, '..', 'generated', 'audit-contract.json')\n for (const candidate of [bundled, bundledDist]) {\n if (existsSync(candidate)) {\n report(`bundled: ${candidate}`)\n return fromBundled(JSON.parse(readFileSync(candidate, 'utf8')) as BundledContract)\n }\n }\n\n // 4. Network, with a local cache. Best-effort: a failure falls through to the error below.\n const fetched = await fetchContract(report)\n if (fetched) return fetched\n\n throw new Error(\n 'cascivo contract unavailable. Pass --contract <path> to a downloaded ' +\n 'audit-contract.json, or run inside the cascivo monorepo. ' +\n '(The CLI normally ships one; this build appears to be missing it.)',\n )\n }\n report('monorepo artifacts')\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 // The DOM-attribute set is derived by the contract generator (it needs the type checker),\n // so even the monorepo path reads it from the generated artifact rather than recomputing.\n let domAttributes: string[] | undefined\n let contentPrimitives: string[] | undefined\n try {\n const generated = JSON.parse(\n readFileSync(join(docsPublic!, 'audit-contract.json'), 'utf8'),\n ) as { domAttributes?: string[]; contentPrimitives?: string[] }\n domAttributes = generated.domAttributes\n contentPrimitives = generated.contentPrimitives\n } catch {\n domAttributes = undefined\n contentPrimitives = undefined\n }\n\n return buildContract({\n catalog,\n registry,\n context,\n ...(domAttributes ? { domAttributes } : {}),\n ...(contentPrimitives ? { contentPrimitives } : {}),\n })\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 { DirectiveFinding } from '../audit-ai/suppress.js'\nimport { applySuppressions, parseDirectives } from '../audit-ai/suppress.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 | DirectiveFinding\n\n/** A finding after suppression directives have been applied. */\nexport type AuditedFinding = Finding & { suppressed?: boolean }\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 case 'audit-directive':\n return f.message\n }\n}\n\nfunction levelLabel(level: Finding['level']): string {\n return level === 'warn' ? 'warn' : level\n}\n\nfunction renderFindings(findings: AuditedFinding[]): 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: f.suppressed ? 'suppressed' : 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 active = findings.filter((f) => !f.suppressed)\n const errors = active.filter((f) => f.level === 'error').length\n const warnings = active.filter((f) => f.level === 'warn').length\n const infos = active.filter((f) => f.level === 'info').length\n const suppressed = findings.filter((f) => f.suppressed).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 if (suppressed) parts.push(`${suppressed} suppressed`)\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 console.log(' --ai [paths…] audit files against the cascivo contract')\n console.log(' --fix rewrite hardcoded values to tokens where unambiguous')\n console.log(' --json machine-readable findings')\n console.log(' --level <level> minimum level to report (error|warning|info)')\n console.log(' --contract <path> use this audit-contract.json instead of the bundled one')\n console.log(' --verbose report which contract source was used')\n return\n }\n\n const jsonOutput = args.includes('--json')\n const fixMode = args.includes('--fix')\n const verbose = args.includes('--verbose')\n const levelIdx = args.indexOf('--level')\n const minLevel = levelIdx >= 0 ? (args[levelIdx + 1] ?? 'error') : 'error'\n const contractIdx = args.indexOf('--contract')\n const contractPath = contractIdx >= 0 ? args[contractIdx + 1] : undefined\n\n const paths = args.filter((a, i) => {\n if (a.startsWith('--')) return false\n if (levelIdx >= 0 && i === levelIdx + 1) return false\n if (contractIdx >= 0 && i === contractIdx + 1) return false\n return true\n })\n\n let contract: Contract\n try {\n contract = await loadContract({\n ...(contractPath ? { contractPath } : {}),\n ...(verbose ? { onResolve: (source: string) => console.error(`contract ← ${source}`) } : {}),\n })\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: AuditedFinding[] = []\n for (const file of files) {\n const source = readFileSync(file, 'utf8')\n const { directives, findings: directiveFindings } = parseDirectives(source, file)\n allFindings.push(...applySuppressions(findingsFor(file, source, contract), directives))\n allFindings.push(...directiveFindings)\n }\n\n if (jsonOutput) {\n console.log(JSON.stringify(allFindings, null, 2))\n } else {\n renderFindings(allFindings)\n }\n\n // Suppressed findings never fail the run — that is the escape hatch's whole point.\n const active = allFindings.filter((f) => !f.suppressed)\n const hasErrors = active.some((f) => f.level === 'error')\n if (minLevel === 'error' && hasErrors) process.exitCode = 1\n if (minLevel === 'warn' && active.some((f) => f.level !== 'info')) process.exitCode = 1\n}\n"],"mappings":";;;;;;AAiGA,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,MAAM,iBAAiB,IAAI,IAAY,MAAM,qBAAqB,CAAC,CAAC;CACpE,KAAK,MAAM,KAAK,MAAM,QAAQ,YAC5B,IAAI,EAAE,QAAQ,SAAS,aAAa,IAAI,EAAE,IAAI;CAahD,MAAM,yBAAS,IAAI,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AM,QAAQ,QAAQ,GAAG,UAAU,CAAC;EACtF,YAAY,KAAK,GAAG,iBAAiB;CACvC;CAEA,IAAI,YACF,QAAQ,IAAI,KAAK,UAAU,aAAa,MAAM,CAAC,CAAC;MAEhD,eAAe,WAAW;CAI5B,MAAM,SAAS,YAAY,QAAQ,MAAM,CAAC,EAAE,UAAU;CACtD,MAAM,YAAY,OAAO,MAAM,MAAM,EAAE,UAAU,OAAO;CACxD,IAAI,aAAa,WAAW,WAAW,QAAQ,WAAW;CAC1D,IAAI,aAAa,UAAU,OAAO,MAAM,MAAM,EAAE,UAAU,MAAM,GAAG,QAAQ,WAAW;AACxF"}
|
|
@@ -25,6 +25,7 @@ var config_exports = /* @__PURE__ */ __exportAll({
|
|
|
25
25
|
installHint: () => installHint,
|
|
26
26
|
isPackageManager: () => isPackageManager,
|
|
27
27
|
loadConfig: () => loadConfig,
|
|
28
|
+
pinSpecifier: () => pinSpecifier,
|
|
28
29
|
resolveConfig: () => resolveConfig
|
|
29
30
|
});
|
|
30
31
|
/**
|
|
@@ -152,12 +153,34 @@ function detectPackageManager(cwd = process.cwd(), opts = {}) {
|
|
|
152
153
|
}
|
|
153
154
|
return "npm";
|
|
154
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Pin every `@cascivo/*` package to an explicit version specifier.
|
|
158
|
+
*
|
|
159
|
+
* A bare name lets the package manager reuse whatever it already has resolvable. In a pnpm
|
|
160
|
+
* workspace a sibling package's lockfile entry won and `@cascivo/i18n` resolved to **0.2.14**
|
|
161
|
+
* while latest was **0.16.0** — then cascivo warned the adopter about the version it had
|
|
162
|
+
* just installed itself. `add name@latest` (or the registry's known floor) makes the intent
|
|
163
|
+
* explicit instead of leaving it to resolution order.
|
|
164
|
+
*
|
|
165
|
+
* Non-cascivo packages (`@preact/signals-react`) keep their bare name: their version is the
|
|
166
|
+
* app's business, and cascivo has no floor to assert.
|
|
167
|
+
*/
|
|
168
|
+
function pinSpecifier(pkg, floors = {}) {
|
|
169
|
+
if (!pkg.startsWith("@cascivo/") && pkg !== "cascivo") return pkg;
|
|
170
|
+
if (pkg.includes("@", 1)) return pkg;
|
|
171
|
+
const floor = floors[pkg];
|
|
172
|
+
if (floor?.startsWith(">=")) return `${pkg}@${floor.slice(2)} - x`;
|
|
173
|
+
return `${pkg}@latest`;
|
|
174
|
+
}
|
|
155
175
|
/** The install subcommand each package manager uses to add dependencies. */
|
|
156
176
|
function installCommand(pm, packages, opts = {}) {
|
|
177
|
+
const verb = pm === "npm" ? "install" : "add";
|
|
178
|
+
const devFlag = opts.dev ? [pm === "npm" ? "--save-dev" : "-D"] : [];
|
|
179
|
+
const specs = packages.map((p) => opts.pin && (p.startsWith("@cascivo/") || p === "cascivo") ? `${p}@${opts.pin}` : pinSpecifier(p, opts.floors ?? {}));
|
|
157
180
|
return [pm, [
|
|
158
|
-
|
|
159
|
-
...
|
|
160
|
-
...
|
|
181
|
+
verb,
|
|
182
|
+
...devFlag,
|
|
183
|
+
...specs
|
|
161
184
|
]];
|
|
162
185
|
}
|
|
163
186
|
/** Human-readable install command a user can copy-paste, e.g. `pnpm add -D cascivo`. */
|
|
@@ -168,4 +191,4 @@ function installHint(pm, packages, opts = {}) {
|
|
|
168
191
|
//#endregion
|
|
169
192
|
export { detectPackageManager as a, isPackageManager as c, config_exports as i, loadConfig as l, DEFAULT_CONFIG as n, installCommand as o, THEMES as r, installHint as s, CASCIVO_HOST as t, __exportAll as u };
|
|
170
193
|
|
|
171
|
-
//# sourceMappingURL=config-
|
|
194
|
+
//# sourceMappingURL=config-D7ddWN_9.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-C6GdrbvF.mjs","names":[],"sources":["../src/utils/config.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { pathToFileURL } from 'node:url'\n\n/**\n * Canonical (and only) host for hosted cascivo artifacts (registry.json, per-item\n * r/<name>.json, marketplace.json, /llms/*, /context/*). The legacy docs.cascivo.com\n * subdomain is retired and 301s here. Keep in sync with CASCIVO_HOST in packages/mcp.\n */\nexport const CASCIVO_HOST = 'https://cascivo.com'\n\n/** All first-party themes shipped by @cascivo/themes (selectable via data-theme). */\nexport const THEMES = [\n 'light',\n 'dark',\n 'warm',\n 'flat',\n 'minimal',\n 'midnight',\n 'pastel',\n 'brutalist',\n 'corporate',\n 'terminal',\n 'cyberpunk',\n 'arcade',\n] as const\n\nexport type ThemeName = (typeof THEMES)[number]\n\nexport type RegistryNamespaceConfig =\n | string\n | { url: string; headers?: Record<string, string>; params?: Record<string, string> }\n\nexport interface CascadeConfig {\n /** URL of the registry.json index. */\n registry: string\n /** Directory (relative to project root) where components are written. */\n outputDir: string\n /** Default theme imported by `cascade init`. */\n theme: ThemeName\n /** Namespace → registry URL template (with {name} placeholder) or auth config. */\n registries?: Record<string, RegistryNamespaceConfig>\n /** Whether to copy test files (*.contract.test.tsx) when adding components. */\n tests?: boolean\n}\n\nexport const DEFAULT_CONFIG: CascadeConfig = {\n // Canonical hosted registry index (served from the landing site, documented in\n // llms.txt). Prefer this over a branch's GitHub raw URL, which 404s for\n // unauthenticated/private-repo requests and breaks `cascivo list`/`add`.\n registry: `${CASCIVO_HOST}/registry.json`,\n outputDir: 'src/components/ui',\n theme: 'light',\n}\n\nconst CONFIG_FILES = ['cascivo.config.ts', 'cascivo.config.js', 'cascivo.config.mjs']\n\n/** Apply defaults over a (possibly partial) user config object. */\nexport function resolveConfig(partial: Partial<CascadeConfig> | null | undefined): CascadeConfig {\n return { ...DEFAULT_CONFIG, ...partial }\n}\n\n/** Let env vars override config — used by the MCP server to pass `outputDir`. */\nexport function applyEnvOverrides(\n config: CascadeConfig,\n env: NodeJS.ProcessEnv = process.env,\n): CascadeConfig {\n return {\n ...config,\n ...(env.CASCIVO_REGISTRY ? { registry: env.CASCIVO_REGISTRY } : {}),\n ...(env.CASCIVO_OUTPUT_DIR ? { outputDir: env.CASCIVO_OUTPUT_DIR } : {}),\n }\n}\n\n/**\n * Locate and load `cascivo.config.{ts,js,mjs}` from `cwd`. Falls back to the\n * default config when no file is found or the file cannot be loaded. Env vars\n * (`CASCIVO_REGISTRY`, `CASCIVO_OUTPUT_DIR`) take precedence.\n */\nexport async function loadConfig(cwd: string = process.cwd()): Promise<CascadeConfig> {\n for (const file of CONFIG_FILES) {\n const path = join(cwd, file)\n if (!existsSync(path)) continue\n try {\n const mod = (await import(pathToFileURL(path).href)) as {\n default?: Partial<CascadeConfig>\n }\n return applyEnvOverrides(resolveConfig(mod.default ?? (mod as Partial<CascadeConfig>)))\n } catch {\n // Unloadable config (e.g. unsupported TS syntax) — fall back to defaults.\n return applyEnvOverrides(resolveConfig(null))\n }\n }\n return applyEnvOverrides(resolveConfig(null))\n}\n\nexport type PackageManager = 'pnpm' | 'yarn' | 'npm' | 'bun'\n\n/** Narrow an arbitrary string to a known PackageManager. */\nexport function isPackageManager(value: string | undefined): value is PackageManager {\n return value === 'pnpm' || value === 'yarn' || value === 'npm' || value === 'bun'\n}\n\n/**\n * Lock files in probe order. `bun.lock` (bun ≥ 1.2 text lockfile) sits beside the\n * legacy binary `bun.lockb`; `package-lock.json` is npm's marker so a walk that\n * reaches an npm workspace root still resolves to npm rather than the default.\n */\nconst PM_LOCKFILES: readonly [string, PackageManager][] = [\n ['pnpm-lock.yaml', 'pnpm'],\n ['yarn.lock', 'yarn'],\n ['bun.lockb', 'bun'],\n ['bun.lock', 'bun'],\n ['package-lock.json', 'npm'],\n]\n\n/** The package manager that invoked this process, from `npm_config_user_agent`. */\nfunction pmFromUserAgent(ua: string | undefined): PackageManager | undefined {\n if (!ua) return undefined\n const name = ua.split('/')[0]\n return isPackageManager(name) ? name : undefined\n}\n\n/** The `packageManager` corepack field of a package.json, if it names a known PM. */\nfunction pmFromPackageJson(dir: string): PackageManager | undefined {\n try {\n const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as {\n packageManager?: string\n }\n const name = pkg.packageManager?.split('@')[0]\n return isPackageManager(name) ? name : undefined\n } catch {\n return undefined\n }\n}\n\n/**\n * Detect the package manager in use. Precedence, highest first:\n * 1. explicit override (the `--package-manager`/`--pm` flag)\n * 2. `CASCIVO_PACKAGE_MANAGER` env var\n * 3. `npm_config_user_agent` (the PM that spawned the CLI, e.g. `pnpm dlx`)\n * 4. an upward walk from `cwd` for a lock file or `packageManager` field —\n * this is what makes detection work inside a workspace, where the lock\n * file lives at the repo root, not in the app subdirectory the user runs\n * the CLI from. The walk stops after a directory containing `.git`.\n * 5. default `npm`.\n */\nexport function detectPackageManager(\n cwd: string = process.cwd(),\n opts: { override?: string; env?: NodeJS.ProcessEnv } = {},\n): PackageManager {\n const env = opts.env ?? process.env\n\n if (isPackageManager(opts.override)) return opts.override\n\n const envPm = env.CASCIVO_PACKAGE_MANAGER\n if (isPackageManager(envPm)) return envPm\n\n const uaPm = pmFromUserAgent(env.npm_config_user_agent)\n if (uaPm) return uaPm\n\n let current = cwd\n for (;;) {\n for (const [file, pm] of PM_LOCKFILES) {\n if (existsSync(join(current, file))) return pm\n }\n const fromField = pmFromPackageJson(current)\n if (fromField) return fromField\n // A `.git` directory marks the repo root — do not walk past it.\n if (existsSync(join(current, '.git'))) break\n const parent = dirname(current)\n if (parent === current) break\n current = parent\n }\n\n return 'npm'\n}\n\n/** The install subcommand each package manager uses to add dependencies. */\nexport function installCommand(\n pm: PackageManager,\n packages: string[],\n opts: { dev?: boolean } = {},\n): [string, string[]] {\n const verb = pm === 'npm' ? 'install' : 'add'\n const devFlag = opts.dev ? [pm === 'npm' ? '--save-dev' : '-D'] : []\n return [pm, [verb, ...devFlag, ...packages]]\n}\n\n/** Human-readable install command a user can copy-paste, e.g. `pnpm add -D cascivo`. */\nexport function installHint(\n pm: PackageManager,\n packages: string[],\n opts: { dev?: boolean } = {},\n): string {\n const [cmd, args] = installCommand(pm, packages, opts)\n return `${cmd} ${args.join(' ')}`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,M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GAAG,IAAI,GAAG,KAAK,KAAK,GAAG;AAChC"}
|
|
1
|
+
{"version":3,"file":"config-D7ddWN_9.mjs","names":[],"sources":["../src/utils/config.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { pathToFileURL } from 'node:url'\n\n/**\n * Canonical (and only) host for hosted cascivo artifacts (registry.json, per-item\n * r/<name>.json, marketplace.json, /llms/*, /context/*). The legacy docs.cascivo.com\n * subdomain is retired and 301s here. Keep in sync with CASCIVO_HOST in packages/mcp.\n */\nexport const CASCIVO_HOST = 'https://cascivo.com'\n\n/** All first-party themes shipped by @cascivo/themes (selectable via data-theme). */\nexport const THEMES = [\n 'light',\n 'dark',\n 'warm',\n 'flat',\n 'minimal',\n 'midnight',\n 'pastel',\n 'brutalist',\n 'corporate',\n 'terminal',\n 'cyberpunk',\n 'arcade',\n] as const\n\nexport type ThemeName = (typeof THEMES)[number]\n\nexport type RegistryNamespaceConfig =\n | string\n | { url: string; headers?: Record<string, string>; params?: Record<string, string> }\n\nexport interface CascadeConfig {\n /** URL of the registry.json index. */\n registry: string\n /** Directory (relative to project root) where components are written. */\n outputDir: string\n /** Default theme imported by `cascade init`. */\n theme: ThemeName\n /** Namespace → registry URL template (with {name} placeholder) or auth config. */\n registries?: Record<string, RegistryNamespaceConfig>\n /** Whether to copy test files (*.contract.test.tsx) when adding components. */\n tests?: boolean\n}\n\nexport const DEFAULT_CONFIG: CascadeConfig = {\n // Canonical hosted registry index (served from the landing site, documented in\n // llms.txt). Prefer this over a branch's GitHub raw URL, which 404s for\n // unauthenticated/private-repo requests and breaks `cascivo list`/`add`.\n registry: `${CASCIVO_HOST}/registry.json`,\n outputDir: 'src/components/ui',\n theme: 'light',\n}\n\nconst CONFIG_FILES = ['cascivo.config.ts', 'cascivo.config.js', 'cascivo.config.mjs']\n\n/** Apply defaults over a (possibly partial) user config object. */\nexport function resolveConfig(partial: Partial<CascadeConfig> | null | undefined): CascadeConfig {\n return { ...DEFAULT_CONFIG, ...partial }\n}\n\n/** Let env vars override config — used by the MCP server to pass `outputDir`. */\nexport function applyEnvOverrides(\n config: CascadeConfig,\n env: NodeJS.ProcessEnv = process.env,\n): CascadeConfig {\n return {\n ...config,\n ...(env.CASCIVO_REGISTRY ? { registry: env.CASCIVO_REGISTRY } : {}),\n ...(env.CASCIVO_OUTPUT_DIR ? { outputDir: env.CASCIVO_OUTPUT_DIR } : {}),\n }\n}\n\n/**\n * Locate and load `cascivo.config.{ts,js,mjs}` from `cwd`. Falls back to the\n * default config when no file is found or the file cannot be loaded. Env vars\n * (`CASCIVO_REGISTRY`, `CASCIVO_OUTPUT_DIR`) take precedence.\n */\nexport async function loadConfig(cwd: string = process.cwd()): Promise<CascadeConfig> {\n for (const file of CONFIG_FILES) {\n const path = join(cwd, file)\n if (!existsSync(path)) continue\n try {\n const mod = (await import(pathToFileURL(path).href)) as {\n default?: Partial<CascadeConfig>\n }\n return applyEnvOverrides(resolveConfig(mod.default ?? (mod as Partial<CascadeConfig>)))\n } catch {\n // Unloadable config (e.g. unsupported TS syntax) — fall back to defaults.\n return applyEnvOverrides(resolveConfig(null))\n }\n }\n return applyEnvOverrides(resolveConfig(null))\n}\n\nexport type PackageManager = 'pnpm' | 'yarn' | 'npm' | 'bun'\n\n/** Narrow an arbitrary string to a known PackageManager. */\nexport function isPackageManager(value: string | undefined): value is PackageManager {\n return value === 'pnpm' || value === 'yarn' || value === 'npm' || value === 'bun'\n}\n\n/**\n * Lock files in probe order. `bun.lock` (bun ≥ 1.2 text lockfile) sits beside the\n * legacy binary `bun.lockb`; `package-lock.json` is npm's marker so a walk that\n * reaches an npm workspace root still resolves to npm rather than the default.\n */\nconst PM_LOCKFILES: readonly [string, PackageManager][] = [\n ['pnpm-lock.yaml', 'pnpm'],\n ['yarn.lock', 'yarn'],\n ['bun.lockb', 'bun'],\n ['bun.lock', 'bun'],\n ['package-lock.json', 'npm'],\n]\n\n/** The package manager that invoked this process, from `npm_config_user_agent`. */\nfunction pmFromUserAgent(ua: string | undefined): PackageManager | undefined {\n if (!ua) return undefined\n const name = ua.split('/')[0]\n return isPackageManager(name) ? name : undefined\n}\n\n/** The `packageManager` corepack field of a package.json, if it names a known PM. */\nfunction pmFromPackageJson(dir: string): PackageManager | undefined {\n try {\n const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) as {\n packageManager?: string\n }\n const name = pkg.packageManager?.split('@')[0]\n return isPackageManager(name) ? name : undefined\n } catch {\n return undefined\n }\n}\n\n/**\n * Detect the package manager in use. Precedence, highest first:\n * 1. explicit override (the `--package-manager`/`--pm` flag)\n * 2. `CASCIVO_PACKAGE_MANAGER` env var\n * 3. `npm_config_user_agent` (the PM that spawned the CLI, e.g. `pnpm dlx`)\n * 4. an upward walk from `cwd` for a lock file or `packageManager` field —\n * this is what makes detection work inside a workspace, where the lock\n * file lives at the repo root, not in the app subdirectory the user runs\n * the CLI from. The walk stops after a directory containing `.git`.\n * 5. default `npm`.\n */\nexport function detectPackageManager(\n cwd: string = process.cwd(),\n opts: { override?: string; env?: NodeJS.ProcessEnv } = {},\n): PackageManager {\n const env = opts.env ?? process.env\n\n if (isPackageManager(opts.override)) return opts.override\n\n const envPm = env.CASCIVO_PACKAGE_MANAGER\n if (isPackageManager(envPm)) return envPm\n\n const uaPm = pmFromUserAgent(env.npm_config_user_agent)\n if (uaPm) return uaPm\n\n let current = cwd\n for (;;) {\n for (const [file, pm] of PM_LOCKFILES) {\n if (existsSync(join(current, file))) return pm\n }\n const fromField = pmFromPackageJson(current)\n if (fromField) return fromField\n // A `.git` directory marks the repo root — do not walk past it.\n if (existsSync(join(current, '.git'))) break\n const parent = dirname(current)\n if (parent === current) break\n current = parent\n }\n\n return 'npm'\n}\n\n/**\n * Pin every `@cascivo/*` package to an explicit version specifier.\n *\n * A bare name lets the package manager reuse whatever it already has resolvable. In a pnpm\n * workspace a sibling package's lockfile entry won and `@cascivo/i18n` resolved to **0.2.14**\n * while latest was **0.16.0** — then cascivo warned the adopter about the version it had\n * just installed itself. `add name@latest` (or the registry's known floor) makes the intent\n * explicit instead of leaving it to resolution order.\n *\n * Non-cascivo packages (`@preact/signals-react`) keep their bare name: their version is the\n * app's business, and cascivo has no floor to assert.\n */\nexport function pinSpecifier(pkg: string, floors: Record<string, string> = {}): string {\n if (!pkg.startsWith('@cascivo/') && pkg !== 'cascivo') return pkg\n if (pkg.includes('@', 1)) return pkg // already carries an explicit version\n const floor = floors[pkg]\n // `>=x.y.z` is not an installable specifier on its own; widen it to a range the package\n // manager understands, so a known floor is honoured rather than silently ignored.\n if (floor?.startsWith('>=')) return `${pkg}@${floor.slice(2)} - x`\n return `${pkg}@latest`\n}\n\n/** The install subcommand each package manager uses to add dependencies. */\nexport function installCommand(\n pm: PackageManager,\n packages: string[],\n opts: { dev?: boolean; floors?: Record<string, string>; pin?: string } = {},\n): [string, string[]] {\n const verb = pm === 'npm' ? 'install' : 'add'\n const devFlag = opts.dev ? [pm === 'npm' ? '--save-dev' : '-D'] : []\n const specs = packages.map((p) =>\n opts.pin && (p.startsWith('@cascivo/') || p === 'cascivo')\n ? `${p}@${opts.pin}`\n : pinSpecifier(p, opts.floors ?? {}),\n )\n return [pm, [verb, ...devFlag, ...specs]]\n}\n\n/** Human-readable install command a user can copy-paste, e.g. `pnpm add -D cascivo`. */\nexport function installHint(\n pm: PackageManager,\n packages: string[],\n opts: { dev?: boolean } = {},\n): string {\n const [cmd, args] = installCommand(pm, packages, opts)\n return `${cmd} ${args.join(' ')}`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,eAAe;;AAG5B,MAAa,SAAS;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAqBA,MAAa,iBAAgC;CAI3C,UAAU,GAAG,aAAa;CAC1B,WAAW;CACX,OAAO;AACT;AAEA,MAAM,eAAe;CAAC;CAAqB;CAAqB;AAAoB;;AAGpF,SAAgB,cAAc,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AM,aAC5C,GAAG,EAAE,GAAG,KAAK,QACb,aAAa,GAAG,KAAK,UAAU,CAAC,CAAC,CACvC;CACA,OAAO,CAAC,IAAI;EAAC;EAAM,GAAG;EAAS,GAAG;CAAK,CAAC;AAC1C;;AAGA,SAAgB,YACd,IACA,UACA,OAA0B,CAAC,GACnB;CACR,MAAM,CAAC,KAAK,QAAQ,eAAe,IAAI,UAAU,IAAI;CACrD,OAAO,GAAG,IAAI,GAAG,KAAK,KAAK,GAAG;AAChC"}
|
|
@@ -2,25 +2,28 @@ import { t as readFileSafe } from "./fs-m7ZvuBBm.mjs";
|
|
|
2
2
|
import { c as findComponent, n as readLock, o as fetchRegistry, r as sha256 } from "./lock-CW8UuEPJ.mjs";
|
|
3
3
|
import { t as checkPeerVersions } from "./peer-versions-Cep8Brn3.mjs";
|
|
4
4
|
//#region src/commands/drift.ts
|
|
5
|
-
/**
|
|
6
|
-
* `cascivo doctor --drift` — compares installed components against the
|
|
7
|
-
* registry. Two drift classes:
|
|
8
|
-
*
|
|
9
|
-
* 1. Local-edit drift: an installed file's content no longer matches what
|
|
10
|
-
* was copied at install time (hand edits, or deleted after install).
|
|
11
|
-
* 2. Peer-version drift: the currently-registered component source needs a
|
|
12
|
-
* newer `@cascivo/*` peer package (per `peerVersions`) than what's
|
|
13
|
-
* actually installed in node_modules — the dashboard-feedback failure
|
|
14
|
-
* mode (DataTable referencing an i18n builtin key an older published
|
|
15
|
-
* @cascivo/i18n build doesn't have).
|
|
16
|
-
*/
|
|
17
5
|
async function runDoctorDrift(config, cwd = process.cwd()) {
|
|
18
6
|
const lock = await readLock(cwd);
|
|
19
7
|
if (!lock || Object.keys(lock.items).length === 0) {
|
|
20
8
|
console.log("No installed components found in cascivo.lock.");
|
|
21
|
-
return
|
|
9
|
+
return {
|
|
10
|
+
ran: false,
|
|
11
|
+
reason: "no components installed (cascivo.lock is empty or missing)",
|
|
12
|
+
issues: 0
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
let registry;
|
|
16
|
+
try {
|
|
17
|
+
registry = await fetchRegistry(config.registry);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
const reason = `could not reach the registry (${error instanceof Error ? error.message : String(error)})`;
|
|
20
|
+
console.log(`Drift check skipped: ${reason}`);
|
|
21
|
+
return {
|
|
22
|
+
ran: false,
|
|
23
|
+
reason,
|
|
24
|
+
issues: 0
|
|
25
|
+
};
|
|
22
26
|
}
|
|
23
|
-
const registry = await fetchRegistry(config.registry);
|
|
24
27
|
let driftCount = 0;
|
|
25
28
|
for (const [name, entry] of Object.entries(lock.items)) {
|
|
26
29
|
const current = findComponent(registry, name);
|
|
@@ -50,8 +53,12 @@ async function runDoctorDrift(config, cwd = process.cwd()) {
|
|
|
50
53
|
console.log(`\n${driftCount} drift issue(s) found.`);
|
|
51
54
|
process.exitCode = 1;
|
|
52
55
|
} else console.log("No drift detected — installed components match the registry.");
|
|
56
|
+
return {
|
|
57
|
+
ran: true,
|
|
58
|
+
issues: driftCount
|
|
59
|
+
};
|
|
53
60
|
}
|
|
54
61
|
//#endregion
|
|
55
62
|
export { runDoctorDrift };
|
|
56
63
|
|
|
57
|
-
//# sourceMappingURL=drift-
|
|
64
|
+
//# sourceMappingURL=drift-B02BbFN_.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift-B02BbFN_.mjs","names":[],"sources":["../src/commands/drift.ts"],"sourcesContent":["import type { CascadeConfig } from '../utils/config.js'\nimport { readFileSafe } from '../utils/fs.js'\nimport { readLock, sha256 } from '../utils/lock.js'\nimport { checkPeerVersions } from '../utils/peer-versions.js'\nimport { fetchRegistry, findComponent } from '../utils/registry.js'\n\n/**\n * `cascivo doctor --drift` — compares installed components against the\n * registry. Two drift classes:\n *\n * 1. Local-edit drift: an installed file's content no longer matches what\n * was copied at install time (hand edits, or deleted after install).\n * 2. Peer-version drift: the currently-registered component source needs a\n * newer `@cascivo/*` peer package (per `peerVersions`) than what's\n * actually installed in node_modules — the dashboard-feedback failure\n * mode (DataTable referencing an i18n builtin key an older published\n * @cascivo/i18n build doesn't have).\n */\n/**\n * What a drift run actually managed to do.\n *\n * `runDoctorDrift` used to return void, so the default `cascivo doctor` could not run it and\n * still say something honest. That is how \"No violations found.\" got printed by a run that\n * had never looked: the two were disjoint branches, and `--drift` reported five real issues\n * on the same project.\n */\nexport interface DriftOutcome {\n /** False when the check could not run at all (no lockfile, offline, unreachable registry). */\n ran: boolean\n /** Why it could not run — printed instead of an unqualified \"clean\". */\n reason?: string\n issues: number\n}\n\nexport async function runDoctorDrift(\n config: CascadeConfig,\n cwd: string = process.cwd(),\n): Promise<DriftOutcome> {\n const lock = await readLock(cwd)\n if (!lock || Object.keys(lock.items).length === 0) {\n console.log('No installed components found in cascivo.lock.')\n return {\n ran: false,\n reason: 'no components installed (cascivo.lock is empty or missing)',\n issues: 0,\n }\n }\n\n let registry: Awaited<ReturnType<typeof fetchRegistry>>\n try {\n registry = await fetchRegistry(config.registry)\n } catch (error) {\n const reason = `could not reach the registry (${error instanceof Error ? error.message : String(error)})`\n console.log(`Drift check skipped: ${reason}`)\n return { ran: false, reason, issues: 0 }\n }\n let driftCount = 0\n\n for (const [name, entry] of Object.entries(lock.items)) {\n const current = findComponent(registry, name)\n if (!current) continue\n\n for (const [path, lockedHash] of Object.entries(entry.files)) {\n const content = await readFileSafe(path)\n if (content === null) {\n console.log(`${name}: ${path} is missing (installed, then deleted)`)\n driftCount++\n continue\n }\n if (sha256(content) !== lockedHash) {\n console.log(`${name}: ${path} has local edits (differs from the version installed)`)\n driftCount++\n }\n }\n\n if (current.peerVersions) {\n const violations = await checkPeerVersions(cwd, current.peerVersions)\n for (const v of violations) {\n const installedDesc = v.installed ? `${v.installed} is installed` : 'it is not installed'\n console.log(`${name}: needs ${v.pkg} ${v.required}, but ${installedDesc}.`)\n driftCount++\n }\n }\n }\n\n if (driftCount > 0) {\n console.log(`\\n${driftCount} drift issue(s) found.`)\n process.exitCode = 1\n } else {\n console.log('No drift detected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