@cascivo/mcp 0.1.4 → 0.1.6

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/index.d.mts CHANGED
@@ -69,7 +69,7 @@ interface ComponentManifest {
69
69
  }
70
70
  interface RegistryComponent {
71
71
  name: string;
72
- type?: 'component' | 'layout' | 'block' | 'chart' | 'section';
72
+ type?: 'component' | 'layout' | 'block' | 'chart' | 'section' | 'flow';
73
73
  description: string;
74
74
  category: string;
75
75
  version: string;
package/dist/index.mjs CHANGED
@@ -792,7 +792,9 @@ function createServer(options = {}) {
792
792
  "component",
793
793
  "layout",
794
794
  "block",
795
- "chart"
795
+ "chart",
796
+ "flow",
797
+ "editor"
796
798
  ]).optional().describe("Filter by entry type")
797
799
  }
798
800
  }, ({ category, type }) => json(listComponents(registry, category, type)));
@@ -920,6 +922,60 @@ function createServer(options = {}) {
920
922
  grammar
921
923
  });
922
924
  });
925
+ server.registerTool("scaffold_flow", {
926
+ title: "Scaffold a flow diagram",
927
+ description: "Generate a starter declarative <Flow nodes edges /> (from @cascivo/flow) for a node/edge diagram — flowchart, DAG, or pipeline. Returns serializable nodes/edges plus ready-to-paste JSX. Edit the labels/edges to match the intent.",
928
+ inputSchema: {
929
+ description: z.string().describe("What the diagram represents"),
930
+ steps: z.array(z.string()).optional().describe("Ordered step labels; consecutive steps are connected. Omit for a 3-step starter."),
931
+ layout: z.enum([
932
+ "none",
933
+ "grid",
934
+ "layered"
935
+ ]).optional().describe("Optional auto-layout. Default \"layered\".")
936
+ }
937
+ }, ({ description, steps, layout }) => {
938
+ const labels = steps && steps.length > 0 ? steps : [
939
+ "Source",
940
+ "Process",
941
+ "Sink"
942
+ ];
943
+ const nodes = labels.map((label, i) => ({
944
+ id: `n${i + 1}`,
945
+ position: {
946
+ x: i * 240,
947
+ y: 0
948
+ },
949
+ data: { label }
950
+ }));
951
+ const edges = labels.slice(1).map((_, i) => ({
952
+ id: `e${i + 1}`,
953
+ source: `n${i + 1}`,
954
+ target: `n${i + 2}`,
955
+ animated: true
956
+ }));
957
+ const lay = layout ?? "layered";
958
+ return json({
959
+ nodes,
960
+ edges,
961
+ layout: lay,
962
+ code: `import { Flow } from '@cascivo/flow'
963
+ import '@cascivo/flow/styles.css'
964
+
965
+ // ${description}
966
+ export function Diagram() {
967
+ return (
968
+ <Flow
969
+ style={{ height: 360 }}
970
+ background
971
+ controls${lay === "none" ? "" : ` layout="${lay}"`}
972
+ nodes={${JSON.stringify(nodes)}}
973
+ edges={${JSON.stringify(edges)}}
974
+ />
975
+ )
976
+ }`
977
+ });
978
+ });
923
979
  server.registerTool("get_view_grammar", {
924
980
  title: "Get view grammar",
925
981
  description: "Get the bound-vocabulary grammar + system prompt for generating valid ViewConfig JSON, derived from the component manifests. Use this to constrain an LLM to cascivo's real components, props, and enum values (anti-hallucination). Optionally scope to a subset of components.",
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["HERE","c","v","HERE","HERE"],"sources":["../src/registry.ts","../src/theme.ts","../src/scaffold.ts","../src/validate.ts","../src/grammar.ts","../src/scaffold-view.ts","../src/prompt.ts","../src/tokens.ts","../src/variants.ts","../src/validate-component.ts","../src/context.ts","../src/select.ts","../src/server.ts","../src/index.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport interface PropManifest {\n name: string\n type: string\n required: boolean\n default?: string\n description?: string\n}\n\nexport interface ComponentManifest {\n name: string\n description: string\n category: string\n states: string[]\n variants: string[]\n sizes: string[]\n props: PropManifest[]\n tokens: string[]\n accessibility: { role: string; wcag: string; keyboard: string[] }\n examples: { title: string; code: string; description?: string }[]\n dependencies: string[]\n tags: string[]\n}\n\nexport interface RegistryComponent {\n name: string\n type?: 'component' | 'layout' | 'block' | 'chart' | 'section'\n description: string\n category: string\n version: string\n files: string[]\n dependencies: string[]\n tags: string[]\n meta: ComponentManifest\n}\n\nexport interface Registry {\n version: string\n generatedAt: string\n components: RegistryComponent[]\n}\n\nconst HERE = dirname(fileURLToPath(import.meta.url))\n\n/**\n * Resolve the registry.json location. Checks, in order: an explicit path, the\n * `CASCIVO_REGISTRY_PATH` env var, a copy bundled next to the built server\n * (published package), and the monorepo root (dev).\n */\nexport function resolveRegistryPath(explicit?: string): string {\n const candidates = [\n explicit,\n process.env.CASCIVO_REGISTRY_PATH,\n join(HERE, 'registry.json'),\n join(HERE, '..', '..', '..', 'registry.json'),\n join(HERE, '..', '..', 'registry.json'),\n ].filter((p): p is string => typeof p === 'string' && p.length > 0)\n\n return (\n candidates.find((p) => existsSync(p)) ?? candidates[candidates.length - 1] ?? 'registry.json'\n )\n}\n\nexport function loadRegistry(path?: string): Registry {\n const resolved = resolveRegistryPath(path)\n const raw = JSON.parse(readFileSync(resolved, 'utf8')) as Registry\n if (!Array.isArray(raw.components)) {\n throw new Error(`Invalid registry at ${resolved}: \"components\" must be an array`)\n }\n return raw\n}\n\n/** List component manifests, optionally filtered by category and/or type. */\nexport function listComponents(\n registry: Registry,\n category?: string,\n type?: string,\n): ComponentManifest[] {\n let entries = registry.components\n if (category) entries = entries.filter((c) => c.category === category)\n if (type) entries = entries.filter((c) => c.type === type)\n return entries.map((c) => c.meta)\n}\n\n/** Find one component manifest by name (matches registry name or meta name). */\nexport function getComponent(registry: Registry, name: string): ComponentManifest | undefined {\n const target = name.toLowerCase()\n return registry.components.find(\n (c) => c.name.toLowerCase() === target || c.meta.name.toLowerCase() === target,\n )?.meta\n}\n\n// ---------------------------------------------------------------------------\n// Multi-registry support\n// ---------------------------------------------------------------------------\n\nexport interface RegistryDirectoryEntry {\n namespace: string\n name: string\n description?: string\n registryUrl: string\n verified?: boolean\n homepage?: string\n}\n\nconst DIRECTORY_URL = 'https://cascivo.com/r/registries.json'\nconst FETCH_TIMEOUT_MS = 15_000\nconst MAX_BODY_BYTES = 1_048_576 // 1 MB\n\ntype FetchFn = (url: string, init?: RequestInit) => Promise<Response>\n\nasync function fetchWithGuards(url: string, fetchFn: FetchFn = fetch): Promise<string | null> {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS)\n try {\n const res = await fetchFn(url, { signal: controller.signal })\n if (!res.ok) return null\n const buf = await res.arrayBuffer()\n if (buf.byteLength > MAX_BODY_BYTES) return null\n return new TextDecoder().decode(buf)\n } catch {\n return null\n } finally {\n clearTimeout(timer)\n }\n}\n\n/** Fetch the central cascade registry directory. Returns empty array on failure. */\nexport async function fetchDirectory(fetchFn?: FetchFn): Promise<RegistryDirectoryEntry[]> {\n const raw = await fetchWithGuards(DIRECTORY_URL, fetchFn)\n if (!raw) return []\n try {\n const parsed = JSON.parse(raw) as unknown\n if (!Array.isArray(parsed)) return []\n return parsed as RegistryDirectoryEntry[]\n } catch {\n return []\n }\n}\n\n/** Fetch the component index from a namespace's registryUrl. Returns null on failure. */\nexport async function fetchRegistryIndex(\n registryUrl: string,\n fetchFn?: FetchFn,\n): Promise<Registry | null> {\n // Resolve the registry.json URL: replace trailing `{name}` template or append /registry.json\n const indexUrl = registryUrl.includes('{name}')\n ? registryUrl.replace('{name}', 'registry').replace(/\\/registry$/, '/registry.json')\n : registryUrl.replace(/\\/?$/, '/registry.json').replace(/\\/\\/registry\\.json$/, '/registry.json')\n const raw = await fetchWithGuards(indexUrl, fetchFn)\n if (!raw) return null\n try {\n const parsed = JSON.parse(raw) as Registry\n if (!Array.isArray(parsed.components)) return null\n return parsed\n } catch {\n return null\n }\n}\n\n/** Parse CASCADE_REGISTRIES env var — returns empty array on failure. */\nexport function getEnvRegistries(): RegistryDirectoryEntry[] {\n const raw = process.env['CASCADE_REGISTRIES']\n if (!raw) return []\n try {\n const parsed = JSON.parse(raw) as unknown\n if (!Array.isArray(parsed)) return []\n return parsed as RegistryDirectoryEntry[]\n } catch {\n return []\n }\n}\n\n/** Merge directory entries with env entries (env wins on namespace collision). */\nexport function mergeRegistries(\n directory: RegistryDirectoryEntry[],\n env: RegistryDirectoryEntry[],\n): RegistryDirectoryEntry[] {\n const map = new Map<string, RegistryDirectoryEntry>()\n for (const entry of directory) map.set(entry.namespace, entry)\n for (const entry of env) map.set(entry.namespace, entry)\n return Array.from(map.values())\n}\n\n/** Fuzzy search over name, tags, and description. */\nexport function searchComponents(registry: Registry, query: string): ComponentManifest[] {\n const q = query.toLowerCase().trim()\n if (q === '') return []\n return registry.components\n .filter(\n (c) =>\n c.name.toLowerCase().includes(q) ||\n c.description.toLowerCase().includes(q) ||\n c.tags.some((t) => t.toLowerCase().includes(q)),\n )\n .map((c) => c.meta)\n}\n","export interface ThemeColors {\n /** Main brand / interactive color (maps to the accent token family). */\n primary: string\n /** Base gray used to derive surfaces, borders, and text. */\n neutral: string\n /** Secondary highlight color (info / focus ring). */\n accent: string\n}\n\n/** Darken a color by mixing in black (modern CSS, no preprocessor). */\nfunction darken(color: string, amount: number): string {\n return `color-mix(in oklab, ${color}, black ${amount}%)`\n}\n\n/** Lighten a color by mixing in white. */\nfunction lighten(color: string, amount: number): string {\n return `color-mix(in oklab, ${color}, white ${amount}%)`\n}\n\n/**\n * Generate a custom cascivo theme as CSS. Maps the three input colors onto the\n * semantic token layer; component tokens inherit automatically.\n */\nexport function generateThemeCss(colors: ThemeColors, name = 'custom'): string {\n const { primary, neutral, accent } = colors\n return `/* cascivo — Generated theme: ${name} */\n\n@layer cascivo.theme {\n [data-theme='${name}'] {\n color-scheme: light;\n\n /* ── Surface (derived from neutral) ───────────────── */\n --cascivo-color-bg: ${lighten(neutral, 96)};\n --cascivo-color-bg-subtle: ${lighten(neutral, 92)};\n --cascivo-color-surface: ${lighten(neutral, 98)};\n --cascivo-color-surface-raised: ${lighten(neutral, 94)};\n --cascivo-color-surface-overlay: ${lighten(neutral, 98)};\n --cascivo-color-border: ${lighten(neutral, 80)};\n --cascivo-color-border-strong: ${lighten(neutral, 65)};\n\n /* ── Text (derived from neutral) ──────────────────── */\n --cascivo-color-text: ${darken(neutral, 80)};\n --cascivo-color-text-subtle: ${darken(neutral, 50)};\n --cascivo-color-text-muted: ${lighten(neutral, 30)};\n --cascivo-color-text-on-accent: #ffffff;\n --cascivo-color-text-on-destructive: #ffffff;\n\n /* ── Accent / primary interactive ─────────────────── */\n --cascivo-color-accent: ${primary};\n --cascivo-color-accent-hover: ${darken(primary, 12)};\n --cascivo-color-accent-active: ${darken(primary, 24)};\n --cascivo-color-accent-subtle: ${lighten(primary, 88)};\n --cascivo-color-accent-muted: ${lighten(primary, 76)};\n\n /* ── Secondary accent (info / focus) ──────────────── */\n --cascivo-color-info: ${accent};\n --cascivo-color-info-subtle: ${lighten(accent, 88)};\n --cascivo-color-focus-ring: ${accent};\n --cascivo-focus-ring: 0 0 0 3px ${lighten(accent, 20)};\n\n /* ── Status ───────────────────────────────────────── */\n --cascivo-color-destructive: #dc2626;\n --cascivo-color-destructive-hover: ${darken('#dc2626', 12)};\n --cascivo-color-destructive-subtle: ${lighten('#dc2626', 88)};\n --cascivo-color-success: #16a34a;\n --cascivo-color-success-subtle: ${lighten('#16a34a', 88)};\n --cascivo-color-warning: #f59e0b;\n --cascivo-color-warning-subtle: ${lighten('#f59e0b', 88)};\n }\n}\n`\n}\n","export interface ScaffoldOptions {\n description: string\n components?: string[]\n}\n\nconst DEFAULT_COMPONENTS = ['card', 'input', 'button']\n\nfunction pascalCase(name: string): string {\n return name\n .split(/[-_\\s]+/)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')\n}\n\n/** A reasonable default usage snippet per component for the scaffold. */\nfunction usage(component: string, Tag: string): string {\n switch (component) {\n case 'button':\n return ` <${Tag}>Get started</${Tag}>`\n case 'input':\n return ` <${Tag} label=\"Email\" placeholder=\"you@example.com\" />`\n case 'card':\n return ` <${Tag}>\\n <h2>Card title</h2>\\n <p>Card content goes here.</p>\\n </${Tag}>`\n case 'badge':\n return ` <${Tag}>New</${Tag}>`\n default:\n return ` <${Tag} />`\n }\n}\n\n/**\n * Generate a JSX page layout string from a natural-language description and an\n * optional list of cascade components to include.\n */\nexport function scaffoldPage(options: ScaffoldOptions): string {\n const components = options.components?.length ? options.components : DEFAULT_COMPONENTS\n const unique = [...new Set(components.map((c) => c.toLowerCase()))]\n\n const imports = unique\n .map((c) => `import { ${pascalCase(c)} } from './components/ui/${c}/${c}'`)\n .join('\\n')\n\n const body = unique.map((c) => usage(c, pascalCase(c))).join('\\n')\n\n return `${imports}\n\n/* ${options.description} */\nexport function Page() {\n return (\n <main\n data-theme=\"light\"\n style={{ maxWidth: '48rem', margin: '0 auto', padding: '2rem', display: 'grid', gap: '1rem' }}\n >\n${body}\n </main>\n )\n}\n`\n}\n","// Inlined from @cascivo/render — avoids a Node.js binary depending on React components at runtime.\n// Component name validation uses the registry (passed by caller) instead of the React component map.\n\nexport interface ValidationError {\n path: string\n message: string\n}\n\nexport interface ComponentNode {\n component: string\n props?: Record<string, unknown>\n bind?: Record<string, string>\n events?: Record<string, string>\n children?: ComponentNode[] | string\n}\n\nexport interface ViewConfig {\n $schema?: string\n version?: 1\n view: {\n layout?: string\n regions: Record<string, ComponentNode[]>\n }\n}\n\nconst DATA_REF_RE = /^\\$data\\./\nconst ACTION_REF_RE = /^\\$actions\\./\n\nfunction closestName(name: string, candidates: string[]): string | undefined {\n const target = name.toLowerCase()\n let best: string | undefined\n let bestDist = 3\n for (const candidate of candidates) {\n const dist = levenshtein(target, candidate.toLowerCase())\n if (dist < bestDist) {\n bestDist = dist\n best = candidate\n }\n }\n return best\n}\n\nfunction levenshtein(a: string, b: string): number {\n const m = a.length\n const n = b.length\n const dp: number[][] = Array.from({ length: m + 1 }, (_, i) =>\n Array.from({ length: n + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)),\n )\n for (let i = 1; i <= m; i++) {\n for (let j = 1; j <= n; j++) {\n dp[i]![j] =\n a[i - 1] === b[j - 1]\n ? dp[i - 1]![j - 1]!\n : 1 + Math.min(dp[i - 1]![j]!, dp[i]![j - 1]!, dp[i - 1]![j - 1]!)\n }\n }\n return dp[m]![n]!\n}\n\nfunction validateNode(\n node: unknown,\n path: string,\n errors: ValidationError[],\n componentNames: Set<string>,\n): void {\n if (typeof node !== 'object' || node === null) {\n errors.push({ path, message: 'Expected a component node object' })\n return\n }\n const n = node as Record<string, unknown>\n if (typeof n['component'] !== 'string') {\n errors.push({ path: `${path}.component`, message: 'component must be a string' })\n return\n }\n const componentName = n['component'] as string\n if (!componentNames.has(componentName)) {\n const suggestion = closestName(componentName, [...componentNames])\n const hint = suggestion ? ` Did you mean \"${suggestion}\"?` : ''\n errors.push({\n path: `${path}.component`,\n message: `Unknown component \"${componentName}\".${hint}`,\n })\n return\n }\n\n const nodeBind = (n['bind'] ?? {}) as Record<string, string>\n for (const [key, value] of Object.entries(nodeBind)) {\n if (typeof value !== 'string' || !DATA_REF_RE.test(value)) {\n errors.push({\n path: `${path}.bind.${key}`,\n message: `bind values must start with \"$data.\" — got \"${value}\"`,\n })\n }\n }\n\n const nodeEvents = (n['events'] ?? {}) as Record<string, string>\n for (const [key, value] of Object.entries(nodeEvents)) {\n if (typeof value !== 'string' || !ACTION_REF_RE.test(value)) {\n errors.push({\n path: `${path}.events.${key}`,\n message: `events values must start with \"$actions.\" — got \"${value}\"`,\n })\n }\n }\n\n if (Array.isArray(n['children'])) {\n for (let i = 0; i < n['children'].length; i++) {\n validateNode(\n n['children'][i] as ComponentNode,\n `${path}.children[${i}]`,\n errors,\n componentNames,\n )\n }\n }\n}\n\n/** Validate a ViewConfig object. Component names are checked against the provided set. */\nexport function validateView(\n config: unknown,\n componentNames: Set<string>,\n): { valid: boolean; errors: ValidationError[] } {\n const errors: ValidationError[] = []\n\n if (typeof config !== 'object' || config === null) {\n return { valid: false, errors: [{ path: '', message: 'Config must be an object' }] }\n }\n\n const c = config as Record<string, unknown>\n const view = c['view']\n\n if (typeof view !== 'object' || view === null) {\n return { valid: false, errors: [{ path: 'view', message: 'view must be an object' }] }\n }\n\n const v = view as Record<string, unknown>\n const regions = v['regions']\n\n if (typeof regions !== 'object' || regions === null) {\n errors.push({ path: 'view.regions', message: 'view.regions must be an object' })\n return { valid: false, errors }\n }\n\n for (const [regionName, nodes] of Object.entries(regions as Record<string, unknown>)) {\n if (!Array.isArray(nodes)) {\n errors.push({\n path: `view.regions.${regionName}`,\n message: `Region \"${regionName}\" must be an array of component nodes`,\n })\n continue\n }\n for (let i = 0; i < nodes.length; i++) {\n validateNode(\n nodes[i] as ComponentNode,\n `view.regions.${regionName}[${i}]`,\n errors,\n componentNames,\n )\n }\n }\n\n return { valid: errors.length === 0, errors }\n}\n","// Library-derived bound vocabulary (v40 T1).\n//\n// OpenUI's anti-hallucination mechanism is a system prompt generated from the\n// component library so a model can only emit registered components/props. This\n// module derives that bound vocabulary from the cascade manifests\n// (component.meta.ts → registry.json): per component → its props (name, type,\n// allowed enum values, required) plus variants/sizes. Because it is *derived*,\n// it can never drift from the components (grammar.test.ts asserts every name it\n// references exists in the registry).\n\nimport type { Registry } from './registry.js'\n\nexport interface GrammarProp {\n name: string\n required: boolean\n /** Raw TypeScript type string from the manifest. */\n type: string\n /** Allowed values, when `type` is a string-literal union (e.g. `'sm' | 'md'`). */\n enum?: string[]\n}\n\nexport interface GrammarComponent {\n name: string\n category: string\n props: GrammarProp[]\n variants: string[]\n sizes: string[]\n}\n\nexport interface ViewGrammar {\n components: GrammarComponent[]\n}\n\n/**\n * Parse a string-literal union type (`'a' | 'b' | \"c\"`) into its allowed\n * values. Returns `undefined` for any non-enum type (primitives, functions,\n * named types, object shapes) so the grammar only constrains what it can.\n */\nexport function parseEnum(type: string): string[] | undefined {\n const branches = type\n .split('|')\n .map((s) => s.trim())\n .filter((s) => s.length > 0)\n if (branches.length === 0) return undefined\n const values: string[] = []\n for (const branch of branches) {\n const quoted = branch.match(/^['\"](.+)['\"]$/)\n if (!quoted?.[1]) return undefined\n values.push(quoted[1])\n }\n return values\n}\n\n/**\n * Build the bound-vocabulary descriptor from the registry, optionally scoped to\n * a subset of component names (case-insensitive). Output is deterministic\n * (components and props sorted by name) for reproducible prompts and tests.\n */\n// Preference when two registry entries share a meta.name (e.g. a `component`\n// and a `layout` both named \"AppShell\"): the node-usable component wins.\nconst TYPE_RANK: Record<string, number> = {\n component: 0,\n block: 1,\n chart: 2,\n section: 3,\n layout: 4,\n}\n\nexport function buildGrammar(registry: Registry, subset?: string[]): ViewGrammar {\n const wanted = subset && subset.length > 0 ? new Set(subset.map((n) => n.toLowerCase())) : null\n\n // Dedupe by meta.name, keeping the highest-ranked (node-usable) entry.\n const canonical = new Map<string, (typeof registry.components)[number]>()\n for (const c of registry.components) {\n const key = c.meta.name.toLowerCase()\n const current = canonical.get(key)\n if (!current || (TYPE_RANK[c.type ?? ''] ?? 9) < (TYPE_RANK[current.type ?? ''] ?? 9)) {\n canonical.set(key, c)\n }\n }\n\n const components: GrammarComponent[] = [...canonical.values()]\n .filter(\n (c) => !wanted || wanted.has(c.meta.name.toLowerCase()) || wanted.has(c.name.toLowerCase()),\n )\n .map((c) => {\n const props: GrammarProp[] = (c.meta.props ?? [])\n .map((p) => {\n const values = parseEnum(p.type)\n return {\n name: p.name,\n required: p.required === true,\n type: p.type,\n ...(values ? { enum: values } : {}),\n }\n })\n .sort((a, b) => a.name.localeCompare(b.name))\n return {\n name: c.meta.name,\n category: c.category,\n props,\n variants: c.meta.variants ?? [],\n sizes: c.meta.sizes ?? [],\n }\n })\n .sort((a, b) => a.name.localeCompare(b.name))\n\n return { components }\n}\n\n/** Render one prop as `name`, `name*` (required), with enum choices or its type. */\nfunction formatProp(prop: GrammarProp): string {\n const mark = prop.required ? '*' : ''\n const value = prop.enum ? prop.enum.join('|') : prop.type\n return `${prop.name}${mark}: ${value}`\n}\n\n/**\n * Render the grammar as a compact, model-friendly table: one line per\n * component. Terser than verbose JSON; a `*` marks a required prop.\n *\n * Badge(size: sm|md, variant: default|secondary|success|warning|destructive|outline)\n */\nexport function formatGrammar(grammar: ViewGrammar): string {\n return grammar.components\n .map((c) => `${c.name}(${c.props.map(formatProp).join(', ')})`)\n .join('\\n')\n}\n","import type { ViewConfig } from './validate.js'\nimport { validateView } from './validate.js'\nimport type { Registry } from './registry.js'\nimport { buildGrammar, formatGrammar } from './grammar.js'\n\ninterface ScaffoldViewInput {\n description: string\n components?: string[]\n}\n\n/** Simple keyword matcher — returns region layout name based on description keywords. */\nfunction pickLayout(description: string): string {\n const d = description.toLowerCase()\n if (d.includes('dashboard') || d.includes('stats') || d.includes('kpi')) return 'dashboard'\n if (d.includes('settings') || d.includes('preferences') || d.includes('config')) return 'settings'\n if (d.includes('login') || d.includes('auth') || d.includes('sign')) return 'auth'\n return 'none'\n}\n\n/** Pick sensible components from the registry matching keywords in description. */\nfunction pickComponents(description: string, registry: Registry, explicit?: string[]): string[] {\n if (explicit && explicit.length > 0) return explicit.map((c) => c.toLowerCase())\n const d = description.toLowerCase()\n const candidates: string[] = []\n for (const entry of registry.components) {\n const name = entry.meta.name.toLowerCase()\n const tags = entry.tags.join(' ').toLowerCase()\n if (d.includes(name) || tags.split(' ').some((t) => d.includes(t))) {\n candidates.push(entry.meta.name)\n }\n }\n // Always add at least one component\n if (candidates.length === 0) candidates.push('Badge')\n return candidates.slice(0, 4)\n}\n\nfunction makeNode(\n componentName: string,\n registry: Registry,\n): { component: string; props?: Record<string, string | number | boolean> } {\n const entry = registry.components.find(\n (c) => c.meta.name.toLowerCase() === componentName.toLowerCase(),\n )\n if (!entry) return { component: componentName }\n const props: Record<string, string | number | boolean> = {}\n for (const prop of entry.meta.props ?? []) {\n if (prop.required && prop.default !== undefined) {\n props[prop.name] = prop.default\n } else if (\n prop.default !== undefined &&\n ['string', 'number', 'boolean'].includes(typeof prop.default)\n ) {\n // Skip defaults that are complex\n }\n }\n return Object.keys(props).length > 0\n ? { component: entry.meta.name, props }\n : { component: entry.meta.name }\n}\n\nexport function scaffoldView(\n input: ScaffoldViewInput,\n registry: Registry,\n): {\n config: ViewConfig\n errors: { path: string; message: string }[]\n /** Bound-vocabulary grammar (v40 T1) for the scaffolded components, so a caller gets both a starter scaffold and the allowed props/enums to refine it. */\n grammar: string\n} {\n const layout = pickLayout(input.description)\n const componentNames = pickComponents(input.description, registry, input.components)\n\n const config: ViewConfig = {\n $schema:\n 'https://raw.githubusercontent.com/cascivo/cascivo/main/packages/render/schema/view.v1.json',\n version: 1,\n view: {\n ...(layout !== 'none' ? { layout } : {}),\n regions: {\n main: componentNames.map((name) => makeNode(name, registry)),\n },\n },\n }\n\n const validNames = new Set(registry.components.map((c) => c.meta.name))\n const { errors } = validateView(config, validNames)\n const grammar = formatGrammar(buildGrammar(registry, componentNames))\n return { config, errors, grammar }\n}\n","// Generation prompt derived from the bound vocabulary (v40 T1).\n//\n// Composes the system prompt an LLM needs to emit valid `ViewConfig` JSON that\n// is restricted to cascivo's real components, props, and enum values — the\n// OpenUI \"system prompt from the component library\" anti-hallucination\n// mechanism, applied to the format cascivo already ships and dogfoods\n// (@cascivo/render). See docs/ROADMAP-V40.md.\n\nimport { buildGrammar, formatGrammar } from './grammar.js'\nimport type { Registry } from './registry.js'\n\nexport interface GenerationPromptOptions {\n /** Scope the vocabulary to a subset of component names. Defaults to all. */\n components?: string[]\n}\n\nconst SCHEMA_DOC = `A ViewConfig is a JSON object:\n\n{\n \"version\": 1,\n \"view\": {\n \"layout\": \"<optional layout name, e.g. dashboard | settings | auth>\",\n \"regions\": {\n \"<regionName>\": [ <ComponentNode>, ... ]\n }\n }\n}\n\nA ComponentNode is:\n\n{\n \"component\": \"<one of the registered component names below>\",\n \"props\": { \"<propName>\": <value> },\n \"bind\": { \"<propName>\": \"$data.<path>\" },\n \"events\": { \"<eventPropName>\": \"$actions.<name>\" },\n \"children\": <ComponentNode[] | string | { \"$t\": \"<i18n.key>\" }>\n}\n\nRules:\n- \"component\" MUST be one of the registered components listed below — never invent one.\n- Only use props listed for that component; enum props MUST use one of the listed values.\n- \"bind\" values are host-data references and MUST start with \"$data.\".\n- \"events\" values are host-action references and MUST start with \"$actions.\".\n- \"children\" is an array of nodes, a plain string, or an i18n ref { \"$t\": \"key\" }.\n- Output ONLY the JSON ViewConfig — no prose, no markdown fences.`\n\n/**\n * Build the bound-vocabulary system prompt for emitting `ViewConfig` JSON.\n * Parameterizable by an optional component subset (defaults to the full\n * registry).\n */\nexport function buildGenerationPrompt(\n registry: Registry,\n options: GenerationPromptOptions = {},\n): string {\n const grammar = buildGrammar(registry, options.components)\n const vocabulary = formatGrammar(grammar)\n\n const sections = [\n 'You generate UI as a cascivo ViewConfig — a JSON description rendered by @cascivo/render <CascadeView />.',\n SCHEMA_DOC,\n 'Registered components (allowed vocabulary — `name*` marks a required prop):',\n vocabulary,\n // EXTENSION POINT (v40 T3, optional): when the `cvl` compact DSL ships, append a\n // \"cvl syntax\" section here so an agent can be asked to emit cvl instead of JSON.\n ]\n\n return sections.join('\\n\\n')\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport interface TokenCatalogEntry {\n name: string\n value: string\n layer: 'primitive' | 'semantic' | 'component'\n group: string\n resolvedDefault: string | null\n resolvesPerTheme: boolean\n}\n\nexport interface TokenCatalog {\n generatedAt: string\n count: number\n tokens: TokenCatalogEntry[]\n}\n\ntype FetchFn = (url: string, init?: RequestInit) => Promise<Response>\n\nconst HERE = dirname(fileURLToPath(import.meta.url))\nconst CATALOG_BASE_URL = 'https://cascivo.com'\n\nexport async function loadTokenCatalog(fetchFn?: FetchFn): Promise<TokenCatalog> {\n const localPaths = [\n join(HERE, '..', '..', '..', 'apps', 'docs', 'public', 'tokens.catalog.json'),\n join(HERE, 'tokens.catalog.json'),\n ]\n for (const p of localPaths) {\n if (existsSync(p)) return JSON.parse(readFileSync(p, 'utf8')) as TokenCatalog\n }\n const url = `${CATALOG_BASE_URL}/tokens.catalog.json`\n const fn = fetchFn ?? fetch\n const res = await fn(url)\n if (!res.ok) throw new Error(`Failed to fetch token catalog: ${res.status}`)\n return res.json() as Promise<TokenCatalog>\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport interface VariantToken {\n name: string\n layer: 'primitive' | 'semantic' | 'component'\n group: string\n role?: string\n slot?: string\n byTheme: Record<string, string | null>\n}\n\nexport interface VariantMatrix {\n generatedAt: string\n themes: string[]\n families: Record<string, Record<string, string>>\n tokens: VariantToken[]\n}\n\ntype FetchFn = (url: string, init?: RequestInit) => Promise<Response>\n\nconst HERE = dirname(fileURLToPath(import.meta.url))\nconst BASE_URL = 'https://cascivo.com'\n\nexport async function loadVariantMatrix(fetchFn?: FetchFn): Promise<VariantMatrix> {\n const localPaths = [\n join(HERE, '..', '..', '..', 'apps', 'docs', 'public', 'tokens.variants.json'),\n join(HERE, 'tokens.variants.json'),\n ]\n for (const p of localPaths) {\n if (existsSync(p)) return JSON.parse(readFileSync(p, 'utf8')) as VariantMatrix\n }\n const url = `${BASE_URL}/tokens.variants.json`\n const fn = fetchFn ?? fetch\n const res = await fn(url)\n if (!res.ok) throw new Error(`Failed to fetch variant matrix: ${res.status}`)\n return res.json() as Promise<VariantMatrix>\n}\n","/**\n * Shadow-sandbox component validator.\n *\n * Runs cascivo's own structural invariants over a candidate component's source\n * (TSX + CSS) *before* it is written to disk, so an agent can loop until the\n * source passes instead of emitting code that the repo's gates would later\n * reject. This is a static structural evaluation — not a full browser render —\n * but it catches the mistakes LLMs actually make against this design system:\n * banned React hooks, off-scale breakpoint literals, missing static fallbacks\n * for progressive CSS, and hallucinated `--cascivo-*` tokens.\n *\n * The checks mirror the repo gates:\n * - use-signals-gate / authoring rules → banned hooks\n * - breakpoint:check → off-scale @media/@container widths\n * - fallback:check → @function/if() static-fallback contract\n * - token catalog (closed set) → no hallucinated tokens\n */\n\nexport type Severity = 'error' | 'warning'\n\nexport interface ComponentViolation {\n rule: string\n severity: Severity\n line: number\n detail: string\n}\n\nexport interface ValidateComponentInput {\n /** Component TSX source. */\n tsx?: string\n /** Component CSS (module or plain) source. */\n css?: string\n /** Component name, for messages only. */\n name?: string\n}\n\nexport interface ValidateComponentOptions {\n /**\n * The closed set of valid `--cascivo-*` token names. When provided, any\n * `var(--cascivo-…)` reference outside this set is flagged as hallucinated.\n */\n tokenNames?: ReadonlySet<string>\n}\n\nexport interface ValidateComponentResult {\n valid: boolean\n name?: string\n violations: ComponentViolation[]\n}\n\n// Hooks that cascivo components must never use — signals replace them.\nconst BANNED_HOOKS = ['useState', 'useEffect', 'useLayoutEffect', 'useContext', 'useReducer']\n\n// Canonical breakpoint width literals (the only ones allowed in @media/@container).\nconst CANONICAL_WIDTHS = new Set([\n '30rem',\n '40rem',\n '64rem',\n '80rem',\n '480px',\n '640px',\n '1024px',\n '1280px',\n])\n\nfunction 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/** Detect banned React hooks in TSX (usage or import). */\nfunction checkBannedHooks(tsx: string): ComponentViolation[] {\n const violations: ComponentViolation[] = []\n for (const hook of BANNED_HOOKS) {\n const re = new RegExp(`\\\\b${hook}\\\\b`, 'g')\n let m: RegExpExecArray | null\n while ((m = re.exec(tsx)) !== null) {\n violations.push({\n rule: 'banned-hook',\n severity: 'error',\n line: lineOf(tsx, m.index),\n detail:\n hook === 'useEffect'\n ? `${hook} is banned — use useSignalEffect for DOM side effects`\n : `${hook} is banned — use useSignal/useComputed from @cascivo/core`,\n })\n }\n }\n return violations\n}\n\n/** Detect off-scale width literals in @media / @container conditions. */\nfunction checkBreakpoints(css: string): ComponentViolation[] {\n const violations: ComponentViolation[] = []\n const widthCondRe =\n /(?:min-width|max-width|width|min-inline-size|max-inline-size|inline-size)\\s*:\\s*([\\d.]+(?:rem|px|em))/g\n const lines = css.split('\\n')\n for (let i = 0; i < lines.length; i++) {\n const trimmed = (lines[i] ?? '').trim()\n if (!trimmed.startsWith('@media') && !trimmed.startsWith('@container')) continue\n if (\n /prefers|forced|pointer|hover|aspect|color|resolution|orientation|print|screen/.test(trimmed)\n )\n continue\n let m: RegExpExecArray | null\n widthCondRe.lastIndex = 0\n while ((m = widthCondRe.exec(trimmed)) !== null) {\n const value = m[1] ?? ''\n if (!CANONICAL_WIDTHS.has(value)) {\n violations.push({\n rule: 'off-scale-breakpoint',\n severity: 'error',\n line: i + 1,\n detail: `Off-scale width \"${value}\" — use 30rem/40rem/64rem/80rem`,\n })\n }\n }\n }\n return violations\n}\n\nconst isFunctionCall = (value: string) => /--[\\w-]+\\(/.test(value)\nconst isIfExpression = (value: string) => /\\bif\\s*\\(/.test(value)\n\n/** Enforce the @function / if() static-fallback contract. */\nfunction checkFallbacks(css: string): ComponentViolation[] {\n const violations: ComponentViolation[] = []\n const lines = css.split('\\n')\n let inSupports = false\n let supportsDepth = 0\n let baseSupportsDepth = 0\n interface Block {\n properties: Map<string, boolean>\n }\n const stack: Block[] = []\n\n for (let i = 0; i < lines.length; i++) {\n const line = (lines[i] ?? '').trim()\n if (/^@supports\\b/.test(line)) {\n inSupports = true\n baseSupportsDepth = supportsDepth\n }\n const opens = (line.match(/\\{/g) ?? []).length\n const closes = (line.match(/\\}/g) ?? []).length\n for (let j = 0; j < opens; j++) {\n stack.push({ properties: new Map() })\n supportsDepth++\n }\n for (let j = 0; j < closes; j++) {\n if (stack.length > 0) stack.pop()\n supportsDepth--\n if (supportsDepth <= baseSupportsDepth) inSupports = false\n }\n const declMatch = line.match(/^([\\w-]+)\\s*:\\s*(.+?)\\s*;?\\s*$/)\n if (!declMatch) continue\n const property = declMatch[1]!\n const value = declMatch[2]!\n if (isFunctionCall(value) || isIfExpression(value)) {\n let hasFallback = inSupports\n if (!hasFallback) {\n for (const block of stack) {\n if (block.properties.get(property)) {\n hasFallback = true\n break\n }\n }\n }\n if (!hasFallback) {\n violations.push({\n rule: 'missing-css-fallback',\n severity: 'error',\n line: i + 1,\n detail: `\"${property}\" uses @function/if() with no preceding static fallback`,\n })\n }\n } else if (stack.length > 0) {\n stack[stack.length - 1]!.properties.set(property, true)\n }\n }\n return violations\n}\n\n/** Flag `var(--cascivo-…)` references that are not in the closed token set. */\nfunction checkTokens(css: string, tokenNames: ReadonlySet<string>): ComponentViolation[] {\n if (tokenNames.size === 0) return []\n const violations: ComponentViolation[] = []\n const re = /var\\(\\s*(--cascivo-[\\w-]+)/g\n let m: RegExpExecArray | null\n const seen = new Set<string>()\n while ((m = re.exec(css)) !== null) {\n const token = m[1]!\n if (tokenNames.has(token) || seen.has(token)) continue\n seen.add(token)\n violations.push({\n rule: 'unknown-token',\n severity: 'error',\n line: lineOf(css, m.index),\n detail: `\"${token}\" is not in the cascivo token catalog (hallucinated token)`,\n })\n }\n return violations\n}\n\n/** Run all structural invariants over a candidate component's source. */\nexport function validateComponentSource(\n input: ValidateComponentInput,\n options: ValidateComponentOptions = {},\n): ValidateComponentResult {\n const violations: ComponentViolation[] = []\n if (input.tsx) violations.push(...checkBannedHooks(input.tsx))\n if (input.css) {\n violations.push(...checkBreakpoints(input.css))\n violations.push(...checkFallbacks(input.css))\n if (options.tokenNames) violations.push(...checkTokens(input.css, options.tokenNames))\n }\n violations.sort((a, b) => a.line - b.line)\n return {\n valid: violations.every((v) => v.severity !== 'error'),\n ...(input.name ? { name: input.name } : {}),\n violations,\n }\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport interface ContextRelated {\n name: string\n relationship: string\n reason: string\n}\n\nexport interface ContextAntiPattern {\n bad: string\n good: string\n why: string\n}\n\nexport interface ContextFlexibility {\n area: string\n level: string\n note: string\n}\n\nexport interface ComponentIntent {\n whenToUse: string[]\n whenNotToUse: string[]\n antiPatterns: ContextAntiPattern[]\n related: ContextRelated[]\n a11yRationale?: string\n flexibility?: ContextFlexibility[]\n}\n\nexport interface ContextComponent {\n name: string\n category: string\n description: string\n intent: ComponentIntent\n contextUrl: string\n /** Copy-pasteable system-prompt snippet that pins an LLM to this component. */\n aiPrompt?: string\n}\n\nexport interface ContextBundle {\n generatedAt: string\n tagline: string\n authoringRules: string[]\n tokenCatalogUrl: string\n components: ContextComponent[]\n}\n\ntype FetchFn = (url: string, init?: RequestInit) => Promise<Response>\n\nconst HERE = dirname(fileURLToPath(import.meta.url))\nconst CONTEXT_BASE_URL = 'https://cascivo.com'\n\nexport async function loadContext(fetchFn?: FetchFn): Promise<ContextBundle> {\n const localPaths = [\n join(HERE, '..', '..', '..', 'apps', 'docs', 'public', 'context.json'),\n join(HERE, 'context.json'),\n ]\n for (const p of localPaths) {\n if (existsSync(p)) return JSON.parse(readFileSync(p, 'utf8')) as ContextBundle\n }\n const url = `${CONTEXT_BASE_URL}/context.json`\n const fn = fetchFn ?? fetch\n const res = await fn(url)\n if (!res.ok) throw new Error(`Failed to fetch context bundle: ${res.status}`)\n return res.json() as Promise<ContextBundle>\n}\n\nexport async function loadComponentMarkdown(\n name: string,\n fetchFn?: FetchFn,\n): Promise<string | null> {\n const slug = name.toLowerCase().replace(/\\s+/g, '-')\n const localPaths = [\n join(HERE, '..', '..', '..', 'apps', 'docs', 'public', 'context', `${slug}.md`),\n join(HERE, 'context', `${slug}.md`),\n ]\n for (const p of localPaths) {\n if (existsSync(p)) return readFileSync(p, 'utf8')\n }\n const url = `${CONTEXT_BASE_URL}/context/${slug}.md`\n const fn = fetchFn ?? fetch\n try {\n const res = await fn(url)\n if (!res.ok) return null\n return res.text()\n } catch {\n return null\n }\n}\n","import type { ContextComponent } from './context.js'\n\nexport interface SelectRelated {\n name: string\n relationship: string\n reason: string\n}\n\nexport interface SelectResult {\n name: string\n score: number\n why: string\n /** When NOT to use this pick — lets an agent disqualify a wrong match. */\n whenNotToUse: string[]\n /** Related components (alternatives, pairs-with) to consider instead/alongside. */\n related: SelectRelated[]\n}\n\n// Minimum length for a need word to be scored (filters out articles, prepositions, etc.)\nconst MIN_WORD_LEN = 3\n\nfunction words(text: string): string[] {\n return (text.toLowerCase().match(/\\b\\w+\\b/g) ?? []).filter((w) => w.length >= MIN_WORD_LEN)\n}\n\nfunction countMatches(needWords: string[], text: string): string[] {\n const lower = text.toLowerCase()\n return needWords.filter((w) => lower.includes(w))\n}\n\nexport function selectComponent(need: string, components: ContextComponent[]): SelectResult[] {\n const needWords = words(need)\n if (needWords.length === 0) return []\n\n const scored = components.map((c) => {\n const whenToUseText = c.intent.whenToUse.join(' ')\n const whenNotToUseText = c.intent.whenNotToUse.join(' ')\n\n const whenToUseMatches = countMatches(needWords, whenToUseText)\n const descMatches = countMatches(needWords, c.description)\n const penaltyMatches = countMatches(needWords, whenNotToUseText)\n\n const score = whenToUseMatches.length * 2 + descMatches.length - penaltyMatches.length * 3\n\n // Build why from the best-matching whenToUse sentence\n let why = ''\n if (whenToUseMatches.length > 0) {\n const bestSentence = c.intent.whenToUse\n .map((s) => ({ s, count: countMatches(needWords, s).length }))\n .filter((x) => x.count > 0)\n .sort((a, b) => b.count - a.count)[0]?.s\n why = bestSentence\n ? `Matched: ${whenToUseMatches.map((w) => `'${w}'`).join(', ')} in whenToUse — \"${bestSentence}\"`\n : `Matched: ${whenToUseMatches.map((w) => `'${w}'`).join(', ')} in description`\n } else if (descMatches.length > 0) {\n why = `Matched: ${descMatches.map((w) => `'${w}'`).join(', ')} in description`\n }\n\n return {\n name: c.name,\n score,\n why,\n whenNotToUse: c.intent.whenNotToUse ?? [],\n related: c.intent.related ?? [],\n }\n })\n\n // First pass: top 3 by score for related bonus\n const top3Names = new Set(\n [...scored]\n .sort((a, b) => b.score - a.score || a.name.localeCompare(b.name))\n .slice(0, 3)\n .map((r) => r.name),\n )\n\n // Apply related bonus: +1 if a top-3 component points at this component\n const relatedBonus = new Map<string, number>()\n for (const r of scored) {\n if (!top3Names.has(r.name)) continue\n for (const rel of r.related) {\n relatedBonus.set(rel.name, (relatedBonus.get(rel.name) ?? 0) + 1)\n }\n }\n\n const final = scored.map((r) => ({\n name: r.name,\n score: r.score + (relatedBonus.get(r.name) ?? 0),\n why: r.why,\n whenNotToUse: r.whenNotToUse,\n related: r.related,\n }))\n\n return final\n .filter((r) => r.score >= 0)\n .sort((a, b) => b.score - a.score || a.name.localeCompare(b.name))\n .slice(0, 5)\n}\n","import { spawnSync } from 'node:child_process'\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { z } from 'zod'\nimport {\n fetchDirectory,\n fetchRegistryIndex,\n getComponent,\n getEnvRegistries,\n listComponents,\n loadRegistry,\n mergeRegistries,\n searchComponents,\n type Registry,\n} from './registry.js'\nimport { generateThemeCss } from './theme.js'\nimport { scaffoldPage } from './scaffold.js'\nimport { validateView } from './validate.js'\nimport { scaffoldView } from './scaffold-view.js'\nimport { buildGrammar, formatGrammar } from './grammar.js'\nimport { buildGenerationPrompt } from './prompt.js'\nimport { loadTokenCatalog } from './tokens.js'\nimport { loadVariantMatrix } from './variants.js'\nimport { validateComponentSource } from './validate-component.js'\nimport { loadContext, loadComponentMarkdown } from './context.js'\nimport { selectComponent } from './select.js'\n\ntype FetchFn = (url: string, init?: RequestInit) => Promise<Response>\n\nexport interface ServerOptions {\n registryPath?: string\n version?: string\n /** Injectable fetch function — used for testing multi-registry features. */\n fetchFn?: FetchFn\n}\n\nconst json = (value: unknown) => ({\n content: [{ type: 'text' as const, text: JSON.stringify(value, null, 2) }],\n})\n\nconst text = (value: string) => ({ content: [{ type: 'text' as const, text: value }] })\n\nconst error = (message: string) => ({\n content: [{ type: 'text' as const, text: message }],\n isError: true,\n})\n\n/** Build a configured McpServer exposing the cascade component registry. */\nexport function createServer(options: ServerOptions = {}): McpServer {\n const registry: Registry = loadRegistry(options.registryPath)\n const fetchFn = options.fetchFn\n\n const server = new McpServer({\n name: '@cascivo/mcp',\n version: options.version ?? '0.0.0',\n })\n\n server.registerTool(\n 'list_registries',\n {\n title: 'List registries',\n description:\n 'List available component registries: the cascade directory plus any configured via CASCADE_REGISTRIES env.',\n inputSchema: {},\n },\n async () => {\n const directory = await fetchDirectory(fetchFn)\n const env = getEnvRegistries()\n const entries = mergeRegistries(directory, env)\n return json(\n entries.map(({ namespace, name, description, verified, homepage }) => ({\n namespace,\n name,\n description,\n verified: verified ?? false,\n homepage,\n })),\n )\n },\n )\n\n server.registerTool(\n 'list_components',\n {\n title: 'List components',\n description: 'List all cascade components, optionally filtered by category and/or type.',\n inputSchema: {\n category: z\n .enum(['inputs', 'display', 'overlay', 'navigation', 'feedback', 'chart'])\n .optional()\n .describe('Filter by component category'),\n type: z\n .enum(['component', 'layout', 'block', 'chart'])\n .optional()\n .describe('Filter by entry type'),\n },\n },\n ({ category, type }) => json(listComponents(registry, category, type)),\n )\n\n server.registerTool(\n 'get_component',\n {\n title: 'Get component',\n description:\n 'Get the full manifest (props, states, tokens, a11y, examples) for one component.',\n inputSchema: {\n name: z.string().describe('Component name, e.g. \"button\"'),\n registry: z\n .string()\n .optional()\n .describe('Namespace of an external registry, e.g. \"@myns\". Omit for the default.'),\n },\n },\n async ({ name, registry: ns }) => {\n if (ns) {\n const env = getEnvRegistries()\n const directory = await fetchDirectory(fetchFn)\n const entries = mergeRegistries(directory, env)\n const entry = entries.find((e) => e.namespace === ns)\n if (!entry) return error(`Registry \"${ns}\" not found.`)\n const remoteRegistry = await fetchRegistryIndex(entry.registryUrl, fetchFn)\n if (!remoteRegistry) return error(`Failed to fetch registry index for \"${ns}\".`)\n const meta = getComponent(remoteRegistry, name)\n return meta ? json(meta) : error(`Component \"${name}\" not found in registry \"${ns}\".`)\n }\n const meta = getComponent(registry, name)\n return meta ? json(meta) : error(`Component \"${name}\" not found.`)\n },\n )\n\n server.registerTool(\n 'search_components',\n {\n title: 'Search components',\n description: 'Fuzzy search components by name, tags, or description.',\n inputSchema: {\n query: z.string().describe('Search query'),\n registry: z\n .string()\n .optional()\n .describe('Namespace of an external registry, e.g. \"@myns\". Omit for the default.'),\n },\n },\n async ({ query, registry: ns }) => {\n if (ns) {\n const env = getEnvRegistries()\n const directory = await fetchDirectory(fetchFn)\n const entries = mergeRegistries(directory, env)\n const entry = entries.find((e) => e.namespace === ns)\n if (!entry) return error(`Registry \"${ns}\" not found.`)\n const remoteRegistry = await fetchRegistryIndex(entry.registryUrl, fetchFn)\n if (!remoteRegistry) return error(`Failed to fetch registry index for \"${ns}\".`)\n return json(searchComponents(remoteRegistry, query))\n }\n return json(searchComponents(registry, query))\n },\n )\n\n server.registerTool(\n 'add_to_project',\n {\n title: 'Add to project',\n description: 'Add a component to the current project by running the cascade CLI.',\n inputSchema: {\n name: z.string().describe('Component name to add'),\n outputDir: z.string().optional().describe('Directory to write the component into'),\n },\n },\n ({ name, outputDir }) => {\n const env = outputDir ? { ...process.env, CASCIVO_OUTPUT_DIR: outputDir } : process.env\n const result = spawnSync('npx', ['-y', 'cascivo', 'add', name], { encoding: 'utf8', env })\n if (result.status !== 0) {\n return error(result.stderr || result.error?.message || `Failed to add \"${name}\".`)\n }\n return text(result.stdout || `Added ${name}.`)\n },\n )\n\n server.registerTool(\n 'create_theme',\n {\n title: 'Create theme',\n description: 'Generate a cascade theme CSS file from three colors.',\n inputSchema: {\n primary: z.string().describe('Primary / interactive color (any CSS color)'),\n neutral: z.string().describe('Base neutral color for surfaces and text'),\n accent: z.string().describe('Secondary accent color (info / focus)'),\n name: z.string().optional().describe('Theme name (default: \"custom\")'),\n },\n },\n ({ primary, neutral, accent, name }) =>\n text(generateThemeCss({ primary, neutral, accent }, name)),\n )\n\n server.registerTool(\n 'scaffold_page',\n {\n title: 'Scaffold page (deprecated)',\n description:\n '[Deprecated — use scaffold_view instead] Generate a JSX page layout from a description.',\n inputSchema: {\n description: z.string().describe('What the page is for'),\n components: z.array(z.string()).optional().describe('Components to include'),\n },\n },\n ({ description, components }) => {\n const { config } = scaffoldView(\n { description, ...(components ? { components } : {}) },\n registry,\n )\n return text(\n `[Deprecated] Use scaffold_view for config-first output. JSX scaffold:\\n\\n${scaffoldPage(components ? { description, components } : { description })}\\n\\n--- scaffold_view output ---\\n${JSON.stringify(config, null, 2)}`,\n )\n },\n )\n\n server.registerTool(\n 'validate_view',\n {\n title: 'Validate view config',\n description:\n 'Validate a CascadeView JSON config against the registry. Returns errors with exact paths.',\n inputSchema: {\n config: z.record(z.string(), z.unknown()).describe('The ViewConfig object to validate'),\n },\n },\n ({ config }) => {\n const componentNames = new Set(registry.components.map((c) => c.meta.name))\n const result = validateView(config, componentNames)\n return json(result)\n },\n )\n\n server.registerTool(\n 'scaffold_view',\n {\n title: 'Scaffold view config',\n description:\n 'Generate a valid starter ViewConfig from a description. Always validates before returning.',\n inputSchema: {\n description: z.string().describe('What the page/view is for'),\n components: z.array(z.string()).optional().describe('Component names to include'),\n },\n },\n ({ description, components }) => {\n const { config, errors, grammar } = scaffoldView(\n { description, ...(components ? { components } : {}) },\n registry,\n )\n if (errors.length > 0) {\n return json({ valid: false, errors, config, grammar })\n }\n return json({ valid: true, config, grammar })\n },\n )\n\n server.registerTool(\n 'get_view_grammar',\n {\n title: 'Get view grammar',\n description:\n \"Get the bound-vocabulary grammar + system prompt for generating valid ViewConfig JSON, derived from the component manifests. Use this to constrain an LLM to cascivo's real components, props, and enum values (anti-hallucination). Optionally scope to a subset of components.\",\n inputSchema: {\n components: z\n .array(z.string())\n .optional()\n .describe('Scope the vocabulary to these component names. Omit for the full registry.'),\n },\n },\n ({ components }) => {\n const grammar = buildGrammar(registry, components)\n return json({\n grammar: formatGrammar(grammar),\n prompt: buildGenerationPrompt(registry, components ? { components } : {}),\n components: grammar.components,\n })\n },\n )\n\n server.registerTool(\n 'get_tokens',\n {\n title: 'Get tokens',\n description:\n 'Get the cascade token catalog (closed set). Agents must select from this catalog rather than hard-coding values.',\n inputSchema: {\n group: z\n .string()\n .optional()\n .describe('Filter by token group, e.g. \"color\", \"space\", \"radius\"'),\n layer: z\n .enum(['primitive', 'semantic', 'component'])\n .optional()\n .describe('Filter by layer'),\n },\n },\n async ({ group, layer }) => {\n try {\n const catalog = await loadTokenCatalog(fetchFn)\n let tokens = catalog.tokens\n if (group) tokens = tokens.filter((t) => t.group === group)\n if (layer) tokens = tokens.filter((t) => t.layer === layer)\n return json({ count: tokens.length, tokens })\n } catch (e) {\n return error(`Token catalog unavailable: ${e instanceof Error ? e.message : String(e)}`)\n }\n },\n )\n\n server.registerTool(\n 'get_variant_matrix',\n {\n title: 'Get variant matrix',\n description:\n 'Get the deterministic token variant matrix: a map from design intent (a colour role + state slot, e.g. accent + hover) to the exact token name, plus every semantic/component token resolved to a concrete value in each theme. Use this to answer \"what is the warm theme\\'s accent-hover value?\" or \"which token is the active state of primary?\" without guessing how layered theme CSS resolves.',\n inputSchema: {\n role: z\n .string()\n .optional()\n .describe('Filter to one colour role, e.g. \"accent\", \"primary\", \"destructive\"'),\n theme: z\n .string()\n .optional()\n .describe('Restrict the per-theme values to a single theme, e.g. \"warm\"'),\n },\n },\n async ({ role, theme }) => {\n try {\n const matrix = await loadVariantMatrix(fetchFn)\n if (theme && !matrix.themes.includes(theme)) {\n return error(`Unknown theme \"${theme}\". Available: ${matrix.themes.join(', ')}`)\n }\n const pickTheme = (byTheme: Record<string, string | null>) =>\n theme ? { [theme]: byTheme[theme] ?? null } : byTheme\n let tokens = matrix.tokens\n let families = matrix.families\n if (role) {\n tokens = tokens.filter((t) => t.role === role)\n families = matrix.families[role] ? { [role]: matrix.families[role] } : {}\n if (tokens.length === 0) {\n const available = Object.keys(matrix.families).join(', ')\n return error(`No colour role \"${role}\". Available roles: ${available}`)\n }\n }\n return json({\n themes: theme ? [theme] : matrix.themes,\n families,\n tokens: tokens.map((t) => ({ ...t, byTheme: pickTheme(t.byTheme) })),\n })\n } catch (e) {\n return error(`Variant matrix unavailable: ${e instanceof Error ? e.message : String(e)}`)\n }\n },\n )\n\n server.registerTool(\n 'validate_component',\n {\n title: 'Validate component (shadow sandbox)',\n description:\n \"Run cascivo's structural invariants over candidate component source (TSX and/or CSS) before writing it to disk. Catches banned React hooks, off-scale @media/@container breakpoints, missing static fallbacks for progressive CSS (@function/if()), and hallucinated --cascivo-* tokens. Use this to self-correct generated code in a loop until `valid` is true.\",\n inputSchema: {\n tsx: z.string().optional().describe('Component TSX source'),\n css: z.string().optional().describe('Component CSS (module or plain) source'),\n name: z.string().optional().describe('Component name (for messages only)'),\n },\n },\n async ({ tsx, css, name }) => {\n let tokenNames: Set<string> | undefined\n try {\n const catalog = await loadTokenCatalog(fetchFn)\n tokenNames = new Set(catalog.tokens.map((t) => t.name))\n } catch {\n // Token catalog is optional — skip the hallucination check if unavailable.\n }\n const result = validateComponentSource(\n { ...(tsx ? { tsx } : {}), ...(css ? { css } : {}), ...(name ? { name } : {}) },\n tokenNames ? { tokenNames } : {},\n )\n return json(result)\n },\n )\n\n server.registerTool(\n 'get_context',\n {\n title: 'Get context',\n description:\n 'Get intent, whenToUse/whenNotToUse, and authoring guidance for one component by name.',\n inputSchema: {\n name: z.string().describe('Component name, e.g. \"Toast\"'),\n },\n },\n async ({ name }) => {\n try {\n const ctx = await loadContext(fetchFn)\n const target = name.toLowerCase()\n const component = ctx.components.find((c) => c.name.toLowerCase() === target)\n if (!component) {\n const available = ctx.components.map((c) => c.name).join(', ')\n return error(`Component \"${name}\" not found. Available: ${available}`)\n }\n const md = await loadComponentMarkdown(component.name, fetchFn)\n return json({\n name: component.name,\n category: component.category,\n description: component.description,\n intent: component.intent,\n contextUrl: component.contextUrl,\n ...(component.aiPrompt ? { aiPrompt: component.aiPrompt } : {}),\n ...(md ? { markdown: md } : {}),\n })\n } catch (e) {\n return error(`Context bundle unavailable: ${e instanceof Error ? e.message : String(e)}`)\n }\n },\n )\n\n server.registerTool(\n 'select_component',\n {\n title: 'Select component',\n description:\n 'Heuristic ranking of cascade components by natural language need. Returns top matches with scores and reasons. Note: heuristic ranking, not a model call.',\n inputSchema: {\n need: z.string().describe('Natural language description of what the component should do'),\n },\n },\n async ({ need }) => {\n try {\n const ctx = await loadContext(fetchFn)\n const results = selectComponent(need, ctx.components)\n return json({\n note: 'Heuristic ranking — not a model call. Verify with get_context before using.',\n results,\n })\n } catch (e) {\n return error(`Context bundle unavailable: ${e instanceof Error ? e.message : String(e)}`)\n }\n },\n )\n\n return server\n}\n","import { argv } from 'node:process'\nimport { pathToFileURL } from 'node:url'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { createServer } from './server.js'\n\nexport const VERSION = '0.0.0'\n\nexport { createServer } from './server.js'\nexport type { ServerOptions } from './server.js'\nexport { generateThemeCss, type ThemeColors } from './theme.js'\nexport { scaffoldPage, type ScaffoldOptions } from './scaffold.js'\nexport {\n buildGrammar,\n formatGrammar,\n parseEnum,\n type GrammarComponent,\n type GrammarProp,\n type ViewGrammar,\n} from './grammar.js'\nexport { buildGenerationPrompt, type GenerationPromptOptions } from './prompt.js'\nexport {\n getComponent,\n listComponents,\n loadRegistry,\n searchComponents,\n type ComponentManifest,\n type Registry,\n type RegistryComponent,\n} from './registry.js'\n\n/** Start the MCP server over stdio. */\nexport async function main(): Promise<void> {\n const server = createServer({ version: VERSION })\n await server.connect(new StdioServerTransport())\n}\n\nconst isMain = argv[1] !== undefined && import.meta.url === pathToFileURL(argv[1]).href\n\nif (isMain) {\n main().catch((err: unknown) => {\n console.error(err instanceof Error ? err.message : String(err))\n process.exitCode = 1\n })\n}\n"],"mappings":";;;;;;;;;AA6CA,MAAMA,SAAO,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC;;;;;;AAOnD,SAAgB,oBAAoB,UAA2B;CAC7D,MAAM,aAAa;EACjB;EACA,QAAQ,IAAI;EACZ,KAAKA,QAAM,eAAe;EAC1B,KAAKA,QAAM,MAAM,MAAM,MAAM,eAAe;EAC5C,KAAKA,QAAM,MAAM,MAAM,eAAe;CACxC,CAAC,CAAC,QAAQ,MAAmB,OAAO,MAAM,YAAY,EAAE,SAAS,CAAC;CAElE,OACE,WAAW,MAAM,MAAM,WAAW,CAAC,CAAC,KAAK,WAAW,WAAW,SAAS,MAAM;AAElF;AAEA,SAAgB,aAAa,MAAyB;CACpD,MAAM,WAAW,oBAAoB,IAAI;CACzC,MAAM,MAAM,KAAK,MAAM,aAAa,UAAU,MAAM,CAAC;CACrD,IAAI,CAAC,MAAM,QAAQ,IAAI,UAAU,G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;IACV,MAAM,UAAU;IAChB,UAAU,UAAU;IACpB,aAAa,UAAU;IACvB,QAAQ,UAAU;IAClB,YAAY,UAAU;IACtB,GAAI,UAAU,WAAW,EAAE,UAAU,UAAU,SAAS,IAAI,CAAC;IAC7D,GAAI,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;GAC/B,CAAC;EACH,SAAS,GAAG;GACV,OAAO,MAAM,+BAA+B,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,GAAG;EAC1F;CACF,CACF;CAEA,OAAO,aACL,oBACA;EACE,OAAO;EACP,aACE;EACF,aAAa,EACX,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,8DAA8D,EAC1F;CACF,GACA,OAAO,EAAE,WAAW;EAClB,IAAI;GAGF,OAAO,KAAK;IACV,MAAM;IACN,SAHc,gBAAgB,OAAM,MADpB,YAAY,OAAO,EAAA,CACK,UAGlC;GACR,CAAC;EACH,SAAS,GAAG;GACV,OAAO,MAAM,+BAA+B,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,GAAG;EAC1F;CACF,CACF;CAEA,OAAO;AACT;;;ACtbA,MAAa,UAAU;;AA0BvB,eAAsB,OAAsB;CAE1C,MADe,aAAa,EAAE,SAAS,QAAQ,CACpC,CAAC,CAAC,QAAQ,IAAI,qBAAqB,CAAC;AACjD;AAIA,IAFe,KAAK,OAAO,KAAA,KAAa,OAAO,KAAK,QAAQ,cAAc,KAAK,EAAE,CAAC,CAAC,MAGjF,KAAK,CAAC,CAAC,OAAO,QAAiB;CAC7B,QAAQ,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;CAC9D,QAAQ,WAAW;AACrB,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":["HERE","c","v","HERE","HERE"],"sources":["../src/registry.ts","../src/theme.ts","../src/scaffold.ts","../src/validate.ts","../src/grammar.ts","../src/scaffold-view.ts","../src/prompt.ts","../src/tokens.ts","../src/variants.ts","../src/validate-component.ts","../src/context.ts","../src/select.ts","../src/server.ts","../src/index.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport interface PropManifest {\n name: string\n type: string\n required: boolean\n default?: string\n description?: string\n}\n\nexport interface ComponentManifest {\n name: string\n description: string\n category: string\n states: string[]\n variants: string[]\n sizes: string[]\n props: PropManifest[]\n tokens: string[]\n accessibility: { role: string; wcag: string; keyboard: string[] }\n examples: { title: string; code: string; description?: string }[]\n dependencies: string[]\n tags: string[]\n}\n\nexport interface RegistryComponent {\n name: string\n type?: 'component' | 'layout' | 'block' | 'chart' | 'section' | 'flow'\n description: string\n category: string\n version: string\n files: string[]\n dependencies: string[]\n tags: string[]\n meta: ComponentManifest\n}\n\nexport interface Registry {\n version: string\n generatedAt: string\n components: RegistryComponent[]\n}\n\nconst HERE = dirname(fileURLToPath(import.meta.url))\n\n/**\n * Resolve the registry.json location. Checks, in order: an explicit path, the\n * `CASCIVO_REGISTRY_PATH` env var, a copy bundled next to the built server\n * (published package), and the monorepo root (dev).\n */\nexport function resolveRegistryPath(explicit?: string): string {\n const candidates = [\n explicit,\n process.env.CASCIVO_REGISTRY_PATH,\n join(HERE, 'registry.json'),\n join(HERE, '..', '..', '..', 'registry.json'),\n join(HERE, '..', '..', 'registry.json'),\n ].filter((p): p is string => typeof p === 'string' && p.length > 0)\n\n return (\n candidates.find((p) => existsSync(p)) ?? candidates[candidates.length - 1] ?? 'registry.json'\n )\n}\n\nexport function loadRegistry(path?: string): Registry {\n const resolved = resolveRegistryPath(path)\n const raw = JSON.parse(readFileSync(resolved, 'utf8')) as Registry\n if (!Array.isArray(raw.components)) {\n throw new Error(`Invalid registry at ${resolved}: \"components\" must be an array`)\n }\n return raw\n}\n\n/** List component manifests, optionally filtered by category and/or type. */\nexport function listComponents(\n registry: Registry,\n category?: string,\n type?: string,\n): ComponentManifest[] {\n let entries = registry.components\n if (category) entries = entries.filter((c) => c.category === category)\n if (type) entries = entries.filter((c) => c.type === type)\n return entries.map((c) => c.meta)\n}\n\n/** Find one component manifest by name (matches registry name or meta name). */\nexport function getComponent(registry: Registry, name: string): ComponentManifest | undefined {\n const target = name.toLowerCase()\n return registry.components.find(\n (c) => c.name.toLowerCase() === target || c.meta.name.toLowerCase() === target,\n )?.meta\n}\n\n// ---------------------------------------------------------------------------\n// Multi-registry support\n// ---------------------------------------------------------------------------\n\nexport interface RegistryDirectoryEntry {\n namespace: string\n name: string\n description?: string\n registryUrl: string\n verified?: boolean\n homepage?: string\n}\n\nconst DIRECTORY_URL = 'https://cascivo.com/r/registries.json'\nconst FETCH_TIMEOUT_MS = 15_000\nconst MAX_BODY_BYTES = 1_048_576 // 1 MB\n\ntype FetchFn = (url: string, init?: RequestInit) => Promise<Response>\n\nasync function fetchWithGuards(url: string, fetchFn: FetchFn = fetch): Promise<string | null> {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS)\n try {\n const res = await fetchFn(url, { signal: controller.signal })\n if (!res.ok) return null\n const buf = await res.arrayBuffer()\n if (buf.byteLength > MAX_BODY_BYTES) return null\n return new TextDecoder().decode(buf)\n } catch {\n return null\n } finally {\n clearTimeout(timer)\n }\n}\n\n/** Fetch the central cascade registry directory. Returns empty array on failure. */\nexport async function fetchDirectory(fetchFn?: FetchFn): Promise<RegistryDirectoryEntry[]> {\n const raw = await fetchWithGuards(DIRECTORY_URL, fetchFn)\n if (!raw) return []\n try {\n const parsed = JSON.parse(raw) as unknown\n if (!Array.isArray(parsed)) return []\n return parsed as RegistryDirectoryEntry[]\n } catch {\n return []\n }\n}\n\n/** Fetch the component index from a namespace's registryUrl. Returns null on failure. */\nexport async function fetchRegistryIndex(\n registryUrl: string,\n fetchFn?: FetchFn,\n): Promise<Registry | null> {\n // Resolve the registry.json URL: replace trailing `{name}` template or append /registry.json\n const indexUrl = registryUrl.includes('{name}')\n ? registryUrl.replace('{name}', 'registry').replace(/\\/registry$/, '/registry.json')\n : registryUrl.replace(/\\/?$/, '/registry.json').replace(/\\/\\/registry\\.json$/, '/registry.json')\n const raw = await fetchWithGuards(indexUrl, fetchFn)\n if (!raw) return null\n try {\n const parsed = JSON.parse(raw) as Registry\n if (!Array.isArray(parsed.components)) return null\n return parsed\n } catch {\n return null\n }\n}\n\n/** Parse CASCADE_REGISTRIES env var — returns empty array on failure. */\nexport function getEnvRegistries(): RegistryDirectoryEntry[] {\n const raw = process.env['CASCADE_REGISTRIES']\n if (!raw) return []\n try {\n const parsed = JSON.parse(raw) as unknown\n if (!Array.isArray(parsed)) return []\n return parsed as RegistryDirectoryEntry[]\n } catch {\n return []\n }\n}\n\n/** Merge directory entries with env entries (env wins on namespace collision). */\nexport function mergeRegistries(\n directory: RegistryDirectoryEntry[],\n env: RegistryDirectoryEntry[],\n): RegistryDirectoryEntry[] {\n const map = new Map<string, RegistryDirectoryEntry>()\n for (const entry of directory) map.set(entry.namespace, entry)\n for (const entry of env) map.set(entry.namespace, entry)\n return Array.from(map.values())\n}\n\n/** Fuzzy search over name, tags, and description. */\nexport function searchComponents(registry: Registry, query: string): ComponentManifest[] {\n const q = query.toLowerCase().trim()\n if (q === '') return []\n return registry.components\n .filter(\n (c) =>\n c.name.toLowerCase().includes(q) ||\n c.description.toLowerCase().includes(q) ||\n c.tags.some((t) => t.toLowerCase().includes(q)),\n )\n .map((c) => c.meta)\n}\n","export interface ThemeColors {\n /** Main brand / interactive color (maps to the accent token family). */\n primary: string\n /** Base gray used to derive surfaces, borders, and text. */\n neutral: string\n /** Secondary highlight color (info / focus ring). */\n accent: string\n}\n\n/** Darken a color by mixing in black (modern CSS, no preprocessor). */\nfunction darken(color: string, amount: number): string {\n return `color-mix(in oklab, ${color}, black ${amount}%)`\n}\n\n/** Lighten a color by mixing in white. */\nfunction lighten(color: string, amount: number): string {\n return `color-mix(in oklab, ${color}, white ${amount}%)`\n}\n\n/**\n * Generate a custom cascivo theme as CSS. Maps the three input colors onto the\n * semantic token layer; component tokens inherit automatically.\n */\nexport function generateThemeCss(colors: ThemeColors, name = 'custom'): string {\n const { primary, neutral, accent } = colors\n return `/* cascivo — Generated theme: ${name} */\n\n@layer cascivo.theme {\n [data-theme='${name}'] {\n color-scheme: light;\n\n /* ── Surface (derived from neutral) ───────────────── */\n --cascivo-color-bg: ${lighten(neutral, 96)};\n --cascivo-color-bg-subtle: ${lighten(neutral, 92)};\n --cascivo-color-surface: ${lighten(neutral, 98)};\n --cascivo-color-surface-raised: ${lighten(neutral, 94)};\n --cascivo-color-surface-overlay: ${lighten(neutral, 98)};\n --cascivo-color-border: ${lighten(neutral, 80)};\n --cascivo-color-border-strong: ${lighten(neutral, 65)};\n\n /* ── Text (derived from neutral) ──────────────────── */\n --cascivo-color-text: ${darken(neutral, 80)};\n --cascivo-color-text-subtle: ${darken(neutral, 50)};\n --cascivo-color-text-muted: ${lighten(neutral, 30)};\n --cascivo-color-text-on-accent: #ffffff;\n --cascivo-color-text-on-destructive: #ffffff;\n\n /* ── Accent / primary interactive ─────────────────── */\n --cascivo-color-accent: ${primary};\n --cascivo-color-accent-hover: ${darken(primary, 12)};\n --cascivo-color-accent-active: ${darken(primary, 24)};\n --cascivo-color-accent-subtle: ${lighten(primary, 88)};\n --cascivo-color-accent-muted: ${lighten(primary, 76)};\n\n /* ── Secondary accent (info / focus) ──────────────── */\n --cascivo-color-info: ${accent};\n --cascivo-color-info-subtle: ${lighten(accent, 88)};\n --cascivo-color-focus-ring: ${accent};\n --cascivo-focus-ring: 0 0 0 3px ${lighten(accent, 20)};\n\n /* ── Status ───────────────────────────────────────── */\n --cascivo-color-destructive: #dc2626;\n --cascivo-color-destructive-hover: ${darken('#dc2626', 12)};\n --cascivo-color-destructive-subtle: ${lighten('#dc2626', 88)};\n --cascivo-color-success: #16a34a;\n --cascivo-color-success-subtle: ${lighten('#16a34a', 88)};\n --cascivo-color-warning: #f59e0b;\n --cascivo-color-warning-subtle: ${lighten('#f59e0b', 88)};\n }\n}\n`\n}\n","export interface ScaffoldOptions {\n description: string\n components?: string[]\n}\n\nconst DEFAULT_COMPONENTS = ['card', 'input', 'button']\n\nfunction pascalCase(name: string): string {\n return name\n .split(/[-_\\s]+/)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')\n}\n\n/** A reasonable default usage snippet per component for the scaffold. */\nfunction usage(component: string, Tag: string): string {\n switch (component) {\n case 'button':\n return ` <${Tag}>Get started</${Tag}>`\n case 'input':\n return ` <${Tag} label=\"Email\" placeholder=\"you@example.com\" />`\n case 'card':\n return ` <${Tag}>\\n <h2>Card title</h2>\\n <p>Card content goes here.</p>\\n </${Tag}>`\n case 'badge':\n return ` <${Tag}>New</${Tag}>`\n default:\n return ` <${Tag} />`\n }\n}\n\n/**\n * Generate a JSX page layout string from a natural-language description and an\n * optional list of cascade components to include.\n */\nexport function scaffoldPage(options: ScaffoldOptions): string {\n const components = options.components?.length ? options.components : DEFAULT_COMPONENTS\n const unique = [...new Set(components.map((c) => c.toLowerCase()))]\n\n const imports = unique\n .map((c) => `import { ${pascalCase(c)} } from './components/ui/${c}/${c}'`)\n .join('\\n')\n\n const body = unique.map((c) => usage(c, pascalCase(c))).join('\\n')\n\n return `${imports}\n\n/* ${options.description} */\nexport function Page() {\n return (\n <main\n data-theme=\"light\"\n style={{ maxWidth: '48rem', margin: '0 auto', padding: '2rem', display: 'grid', gap: '1rem' }}\n >\n${body}\n </main>\n )\n}\n`\n}\n","// Inlined from @cascivo/render — avoids a Node.js binary depending on React components at runtime.\n// Component name validation uses the registry (passed by caller) instead of the React component map.\n\nexport interface ValidationError {\n path: string\n message: string\n}\n\nexport interface ComponentNode {\n component: string\n props?: Record<string, unknown>\n bind?: Record<string, string>\n events?: Record<string, string>\n children?: ComponentNode[] | string\n}\n\nexport interface ViewConfig {\n $schema?: string\n version?: 1\n view: {\n layout?: string\n regions: Record<string, ComponentNode[]>\n }\n}\n\nconst DATA_REF_RE = /^\\$data\\./\nconst ACTION_REF_RE = /^\\$actions\\./\n\nfunction closestName(name: string, candidates: string[]): string | undefined {\n const target = name.toLowerCase()\n let best: string | undefined\n let bestDist = 3\n for (const candidate of candidates) {\n const dist = levenshtein(target, candidate.toLowerCase())\n if (dist < bestDist) {\n bestDist = dist\n best = candidate\n }\n }\n return best\n}\n\nfunction levenshtein(a: string, b: string): number {\n const m = a.length\n const n = b.length\n const dp: number[][] = Array.from({ length: m + 1 }, (_, i) =>\n Array.from({ length: n + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)),\n )\n for (let i = 1; i <= m; i++) {\n for (let j = 1; j <= n; j++) {\n dp[i]![j] =\n a[i - 1] === b[j - 1]\n ? dp[i - 1]![j - 1]!\n : 1 + Math.min(dp[i - 1]![j]!, dp[i]![j - 1]!, dp[i - 1]![j - 1]!)\n }\n }\n return dp[m]![n]!\n}\n\nfunction validateNode(\n node: unknown,\n path: string,\n errors: ValidationError[],\n componentNames: Set<string>,\n): void {\n if (typeof node !== 'object' || node === null) {\n errors.push({ path, message: 'Expected a component node object' })\n return\n }\n const n = node as Record<string, unknown>\n if (typeof n['component'] !== 'string') {\n errors.push({ path: `${path}.component`, message: 'component must be a string' })\n return\n }\n const componentName = n['component'] as string\n if (!componentNames.has(componentName)) {\n const suggestion = closestName(componentName, [...componentNames])\n const hint = suggestion ? ` Did you mean \"${suggestion}\"?` : ''\n errors.push({\n path: `${path}.component`,\n message: `Unknown component \"${componentName}\".${hint}`,\n })\n return\n }\n\n const nodeBind = (n['bind'] ?? {}) as Record<string, string>\n for (const [key, value] of Object.entries(nodeBind)) {\n if (typeof value !== 'string' || !DATA_REF_RE.test(value)) {\n errors.push({\n path: `${path}.bind.${key}`,\n message: `bind values must start with \"$data.\" — got \"${value}\"`,\n })\n }\n }\n\n const nodeEvents = (n['events'] ?? {}) as Record<string, string>\n for (const [key, value] of Object.entries(nodeEvents)) {\n if (typeof value !== 'string' || !ACTION_REF_RE.test(value)) {\n errors.push({\n path: `${path}.events.${key}`,\n message: `events values must start with \"$actions.\" — got \"${value}\"`,\n })\n }\n }\n\n if (Array.isArray(n['children'])) {\n for (let i = 0; i < n['children'].length; i++) {\n validateNode(\n n['children'][i] as ComponentNode,\n `${path}.children[${i}]`,\n errors,\n componentNames,\n )\n }\n }\n}\n\n/** Validate a ViewConfig object. Component names are checked against the provided set. */\nexport function validateView(\n config: unknown,\n componentNames: Set<string>,\n): { valid: boolean; errors: ValidationError[] } {\n const errors: ValidationError[] = []\n\n if (typeof config !== 'object' || config === null) {\n return { valid: false, errors: [{ path: '', message: 'Config must be an object' }] }\n }\n\n const c = config as Record<string, unknown>\n const view = c['view']\n\n if (typeof view !== 'object' || view === null) {\n return { valid: false, errors: [{ path: 'view', message: 'view must be an object' }] }\n }\n\n const v = view as Record<string, unknown>\n const regions = v['regions']\n\n if (typeof regions !== 'object' || regions === null) {\n errors.push({ path: 'view.regions', message: 'view.regions must be an object' })\n return { valid: false, errors }\n }\n\n for (const [regionName, nodes] of Object.entries(regions as Record<string, unknown>)) {\n if (!Array.isArray(nodes)) {\n errors.push({\n path: `view.regions.${regionName}`,\n message: `Region \"${regionName}\" must be an array of component nodes`,\n })\n continue\n }\n for (let i = 0; i < nodes.length; i++) {\n validateNode(\n nodes[i] as ComponentNode,\n `view.regions.${regionName}[${i}]`,\n errors,\n componentNames,\n )\n }\n }\n\n return { valid: errors.length === 0, errors }\n}\n","// Library-derived bound vocabulary (v40 T1).\n//\n// OpenUI's anti-hallucination mechanism is a system prompt generated from the\n// component library so a model can only emit registered components/props. This\n// module derives that bound vocabulary from the cascade manifests\n// (component.meta.ts → registry.json): per component → its props (name, type,\n// allowed enum values, required) plus variants/sizes. Because it is *derived*,\n// it can never drift from the components (grammar.test.ts asserts every name it\n// references exists in the registry).\n\nimport type { Registry } from './registry.js'\n\nexport interface GrammarProp {\n name: string\n required: boolean\n /** Raw TypeScript type string from the manifest. */\n type: string\n /** Allowed values, when `type` is a string-literal union (e.g. `'sm' | 'md'`). */\n enum?: string[]\n}\n\nexport interface GrammarComponent {\n name: string\n category: string\n props: GrammarProp[]\n variants: string[]\n sizes: string[]\n}\n\nexport interface ViewGrammar {\n components: GrammarComponent[]\n}\n\n/**\n * Parse a string-literal union type (`'a' | 'b' | \"c\"`) into its allowed\n * values. Returns `undefined` for any non-enum type (primitives, functions,\n * named types, object shapes) so the grammar only constrains what it can.\n */\nexport function parseEnum(type: string): string[] | undefined {\n const branches = type\n .split('|')\n .map((s) => s.trim())\n .filter((s) => s.length > 0)\n if (branches.length === 0) return undefined\n const values: string[] = []\n for (const branch of branches) {\n const quoted = branch.match(/^['\"](.+)['\"]$/)\n if (!quoted?.[1]) return undefined\n values.push(quoted[1])\n }\n return values\n}\n\n/**\n * Build the bound-vocabulary descriptor from the registry, optionally scoped to\n * a subset of component names (case-insensitive). Output is deterministic\n * (components and props sorted by name) for reproducible prompts and tests.\n */\n// Preference when two registry entries share a meta.name (e.g. a `component`\n// and a `layout` both named \"AppShell\"): the node-usable component wins.\nconst TYPE_RANK: Record<string, number> = {\n component: 0,\n block: 1,\n chart: 2,\n section: 3,\n layout: 4,\n}\n\nexport function buildGrammar(registry: Registry, subset?: string[]): ViewGrammar {\n const wanted = subset && subset.length > 0 ? new Set(subset.map((n) => n.toLowerCase())) : null\n\n // Dedupe by meta.name, keeping the highest-ranked (node-usable) entry.\n const canonical = new Map<string, (typeof registry.components)[number]>()\n for (const c of registry.components) {\n const key = c.meta.name.toLowerCase()\n const current = canonical.get(key)\n if (!current || (TYPE_RANK[c.type ?? ''] ?? 9) < (TYPE_RANK[current.type ?? ''] ?? 9)) {\n canonical.set(key, c)\n }\n }\n\n const components: GrammarComponent[] = [...canonical.values()]\n .filter(\n (c) => !wanted || wanted.has(c.meta.name.toLowerCase()) || wanted.has(c.name.toLowerCase()),\n )\n .map((c) => {\n const props: GrammarProp[] = (c.meta.props ?? [])\n .map((p) => {\n const values = parseEnum(p.type)\n return {\n name: p.name,\n required: p.required === true,\n type: p.type,\n ...(values ? { enum: values } : {}),\n }\n })\n .sort((a, b) => a.name.localeCompare(b.name))\n return {\n name: c.meta.name,\n category: c.category,\n props,\n variants: c.meta.variants ?? [],\n sizes: c.meta.sizes ?? [],\n }\n })\n .sort((a, b) => a.name.localeCompare(b.name))\n\n return { components }\n}\n\n/** Render one prop as `name`, `name*` (required), with enum choices or its type. */\nfunction formatProp(prop: GrammarProp): string {\n const mark = prop.required ? '*' : ''\n const value = prop.enum ? prop.enum.join('|') : prop.type\n return `${prop.name}${mark}: ${value}`\n}\n\n/**\n * Render the grammar as a compact, model-friendly table: one line per\n * component. Terser than verbose JSON; a `*` marks a required prop.\n *\n * Badge(size: sm|md, variant: default|secondary|success|warning|destructive|outline)\n */\nexport function formatGrammar(grammar: ViewGrammar): string {\n return grammar.components\n .map((c) => `${c.name}(${c.props.map(formatProp).join(', ')})`)\n .join('\\n')\n}\n","import type { ViewConfig } from './validate.js'\nimport { validateView } from './validate.js'\nimport type { Registry } from './registry.js'\nimport { buildGrammar, formatGrammar } from './grammar.js'\n\ninterface ScaffoldViewInput {\n description: string\n components?: string[]\n}\n\n/** Simple keyword matcher — returns region layout name based on description keywords. */\nfunction pickLayout(description: string): string {\n const d = description.toLowerCase()\n if (d.includes('dashboard') || d.includes('stats') || d.includes('kpi')) return 'dashboard'\n if (d.includes('settings') || d.includes('preferences') || d.includes('config')) return 'settings'\n if (d.includes('login') || d.includes('auth') || d.includes('sign')) return 'auth'\n return 'none'\n}\n\n/** Pick sensible components from the registry matching keywords in description. */\nfunction pickComponents(description: string, registry: Registry, explicit?: string[]): string[] {\n if (explicit && explicit.length > 0) return explicit.map((c) => c.toLowerCase())\n const d = description.toLowerCase()\n const candidates: string[] = []\n for (const entry of registry.components) {\n const name = entry.meta.name.toLowerCase()\n const tags = entry.tags.join(' ').toLowerCase()\n if (d.includes(name) || tags.split(' ').some((t) => d.includes(t))) {\n candidates.push(entry.meta.name)\n }\n }\n // Always add at least one component\n if (candidates.length === 0) candidates.push('Badge')\n return candidates.slice(0, 4)\n}\n\nfunction makeNode(\n componentName: string,\n registry: Registry,\n): { component: string; props?: Record<string, string | number | boolean> } {\n const entry = registry.components.find(\n (c) => c.meta.name.toLowerCase() === componentName.toLowerCase(),\n )\n if (!entry) return { component: componentName }\n const props: Record<string, string | number | boolean> = {}\n for (const prop of entry.meta.props ?? []) {\n if (prop.required && prop.default !== undefined) {\n props[prop.name] = prop.default\n } else if (\n prop.default !== undefined &&\n ['string', 'number', 'boolean'].includes(typeof prop.default)\n ) {\n // Skip defaults that are complex\n }\n }\n return Object.keys(props).length > 0\n ? { component: entry.meta.name, props }\n : { component: entry.meta.name }\n}\n\nexport function scaffoldView(\n input: ScaffoldViewInput,\n registry: Registry,\n): {\n config: ViewConfig\n errors: { path: string; message: string }[]\n /** Bound-vocabulary grammar (v40 T1) for the scaffolded components, so a caller gets both a starter scaffold and the allowed props/enums to refine it. */\n grammar: string\n} {\n const layout = pickLayout(input.description)\n const componentNames = pickComponents(input.description, registry, input.components)\n\n const config: ViewConfig = {\n $schema:\n 'https://raw.githubusercontent.com/cascivo/cascivo/main/packages/render/schema/view.v1.json',\n version: 1,\n view: {\n ...(layout !== 'none' ? { layout } : {}),\n regions: {\n main: componentNames.map((name) => makeNode(name, registry)),\n },\n },\n }\n\n const validNames = new Set(registry.components.map((c) => c.meta.name))\n const { errors } = validateView(config, validNames)\n const grammar = formatGrammar(buildGrammar(registry, componentNames))\n return { config, errors, grammar }\n}\n","// Generation prompt derived from the bound vocabulary (v40 T1).\n//\n// Composes the system prompt an LLM needs to emit valid `ViewConfig` JSON that\n// is restricted to cascivo's real components, props, and enum values — the\n// OpenUI \"system prompt from the component library\" anti-hallucination\n// mechanism, applied to the format cascivo already ships and dogfoods\n// (@cascivo/render). See docs/ROADMAP-V40.md.\n\nimport { buildGrammar, formatGrammar } from './grammar.js'\nimport type { Registry } from './registry.js'\n\nexport interface GenerationPromptOptions {\n /** Scope the vocabulary to a subset of component names. Defaults to all. */\n components?: string[]\n}\n\nconst SCHEMA_DOC = `A ViewConfig is a JSON object:\n\n{\n \"version\": 1,\n \"view\": {\n \"layout\": \"<optional layout name, e.g. dashboard | settings | auth>\",\n \"regions\": {\n \"<regionName>\": [ <ComponentNode>, ... ]\n }\n }\n}\n\nA ComponentNode is:\n\n{\n \"component\": \"<one of the registered component names below>\",\n \"props\": { \"<propName>\": <value> },\n \"bind\": { \"<propName>\": \"$data.<path>\" },\n \"events\": { \"<eventPropName>\": \"$actions.<name>\" },\n \"children\": <ComponentNode[] | string | { \"$t\": \"<i18n.key>\" }>\n}\n\nRules:\n- \"component\" MUST be one of the registered components listed below — never invent one.\n- Only use props listed for that component; enum props MUST use one of the listed values.\n- \"bind\" values are host-data references and MUST start with \"$data.\".\n- \"events\" values are host-action references and MUST start with \"$actions.\".\n- \"children\" is an array of nodes, a plain string, or an i18n ref { \"$t\": \"key\" }.\n- Output ONLY the JSON ViewConfig — no prose, no markdown fences.`\n\n/**\n * Build the bound-vocabulary system prompt for emitting `ViewConfig` JSON.\n * Parameterizable by an optional component subset (defaults to the full\n * registry).\n */\nexport function buildGenerationPrompt(\n registry: Registry,\n options: GenerationPromptOptions = {},\n): string {\n const grammar = buildGrammar(registry, options.components)\n const vocabulary = formatGrammar(grammar)\n\n const sections = [\n 'You generate UI as a cascivo ViewConfig — a JSON description rendered by @cascivo/render <CascadeView />.',\n SCHEMA_DOC,\n 'Registered components (allowed vocabulary — `name*` marks a required prop):',\n vocabulary,\n // EXTENSION POINT (v40 T3, optional): when the `cvl` compact DSL ships, append a\n // \"cvl syntax\" section here so an agent can be asked to emit cvl instead of JSON.\n ]\n\n return sections.join('\\n\\n')\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport interface TokenCatalogEntry {\n name: string\n value: string\n layer: 'primitive' | 'semantic' | 'component'\n group: string\n resolvedDefault: string | null\n resolvesPerTheme: boolean\n}\n\nexport interface TokenCatalog {\n generatedAt: string\n count: number\n tokens: TokenCatalogEntry[]\n}\n\ntype FetchFn = (url: string, init?: RequestInit) => Promise<Response>\n\nconst HERE = dirname(fileURLToPath(import.meta.url))\nconst CATALOG_BASE_URL = 'https://cascivo.com'\n\nexport async function loadTokenCatalog(fetchFn?: FetchFn): Promise<TokenCatalog> {\n const localPaths = [\n join(HERE, '..', '..', '..', 'apps', 'docs', 'public', 'tokens.catalog.json'),\n join(HERE, 'tokens.catalog.json'),\n ]\n for (const p of localPaths) {\n if (existsSync(p)) return JSON.parse(readFileSync(p, 'utf8')) as TokenCatalog\n }\n const url = `${CATALOG_BASE_URL}/tokens.catalog.json`\n const fn = fetchFn ?? fetch\n const res = await fn(url)\n if (!res.ok) throw new Error(`Failed to fetch token catalog: ${res.status}`)\n return res.json() as Promise<TokenCatalog>\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport interface VariantToken {\n name: string\n layer: 'primitive' | 'semantic' | 'component'\n group: string\n role?: string\n slot?: string\n byTheme: Record<string, string | null>\n}\n\nexport interface VariantMatrix {\n generatedAt: string\n themes: string[]\n families: Record<string, Record<string, string>>\n tokens: VariantToken[]\n}\n\ntype FetchFn = (url: string, init?: RequestInit) => Promise<Response>\n\nconst HERE = dirname(fileURLToPath(import.meta.url))\nconst BASE_URL = 'https://cascivo.com'\n\nexport async function loadVariantMatrix(fetchFn?: FetchFn): Promise<VariantMatrix> {\n const localPaths = [\n join(HERE, '..', '..', '..', 'apps', 'docs', 'public', 'tokens.variants.json'),\n join(HERE, 'tokens.variants.json'),\n ]\n for (const p of localPaths) {\n if (existsSync(p)) return JSON.parse(readFileSync(p, 'utf8')) as VariantMatrix\n }\n const url = `${BASE_URL}/tokens.variants.json`\n const fn = fetchFn ?? fetch\n const res = await fn(url)\n if (!res.ok) throw new Error(`Failed to fetch variant matrix: ${res.status}`)\n return res.json() as Promise<VariantMatrix>\n}\n","/**\n * Shadow-sandbox component validator.\n *\n * Runs cascivo's own structural invariants over a candidate component's source\n * (TSX + CSS) *before* it is written to disk, so an agent can loop until the\n * source passes instead of emitting code that the repo's gates would later\n * reject. This is a static structural evaluation — not a full browser render —\n * but it catches the mistakes LLMs actually make against this design system:\n * banned React hooks, off-scale breakpoint literals, missing static fallbacks\n * for progressive CSS, and hallucinated `--cascivo-*` tokens.\n *\n * The checks mirror the repo gates:\n * - use-signals-gate / authoring rules → banned hooks\n * - breakpoint:check → off-scale @media/@container widths\n * - fallback:check → @function/if() static-fallback contract\n * - token catalog (closed set) → no hallucinated tokens\n */\n\nexport type Severity = 'error' | 'warning'\n\nexport interface ComponentViolation {\n rule: string\n severity: Severity\n line: number\n detail: string\n}\n\nexport interface ValidateComponentInput {\n /** Component TSX source. */\n tsx?: string\n /** Component CSS (module or plain) source. */\n css?: string\n /** Component name, for messages only. */\n name?: string\n}\n\nexport interface ValidateComponentOptions {\n /**\n * The closed set of valid `--cascivo-*` token names. When provided, any\n * `var(--cascivo-…)` reference outside this set is flagged as hallucinated.\n */\n tokenNames?: ReadonlySet<string>\n}\n\nexport interface ValidateComponentResult {\n valid: boolean\n name?: string\n violations: ComponentViolation[]\n}\n\n// Hooks that cascivo components must never use — signals replace them.\nconst BANNED_HOOKS = ['useState', 'useEffect', 'useLayoutEffect', 'useContext', 'useReducer']\n\n// Canonical breakpoint width literals (the only ones allowed in @media/@container).\nconst CANONICAL_WIDTHS = new Set([\n '30rem',\n '40rem',\n '64rem',\n '80rem',\n '480px',\n '640px',\n '1024px',\n '1280px',\n])\n\nfunction 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/** Detect banned React hooks in TSX (usage or import). */\nfunction checkBannedHooks(tsx: string): ComponentViolation[] {\n const violations: ComponentViolation[] = []\n for (const hook of BANNED_HOOKS) {\n const re = new RegExp(`\\\\b${hook}\\\\b`, 'g')\n let m: RegExpExecArray | null\n while ((m = re.exec(tsx)) !== null) {\n violations.push({\n rule: 'banned-hook',\n severity: 'error',\n line: lineOf(tsx, m.index),\n detail:\n hook === 'useEffect'\n ? `${hook} is banned — use useSignalEffect for DOM side effects`\n : `${hook} is banned — use useSignal/useComputed from @cascivo/core`,\n })\n }\n }\n return violations\n}\n\n/** Detect off-scale width literals in @media / @container conditions. */\nfunction checkBreakpoints(css: string): ComponentViolation[] {\n const violations: ComponentViolation[] = []\n const widthCondRe =\n /(?:min-width|max-width|width|min-inline-size|max-inline-size|inline-size)\\s*:\\s*([\\d.]+(?:rem|px|em))/g\n const lines = css.split('\\n')\n for (let i = 0; i < lines.length; i++) {\n const trimmed = (lines[i] ?? '').trim()\n if (!trimmed.startsWith('@media') && !trimmed.startsWith('@container')) continue\n if (\n /prefers|forced|pointer|hover|aspect|color|resolution|orientation|print|screen/.test(trimmed)\n )\n continue\n let m: RegExpExecArray | null\n widthCondRe.lastIndex = 0\n while ((m = widthCondRe.exec(trimmed)) !== null) {\n const value = m[1] ?? ''\n if (!CANONICAL_WIDTHS.has(value)) {\n violations.push({\n rule: 'off-scale-breakpoint',\n severity: 'error',\n line: i + 1,\n detail: `Off-scale width \"${value}\" — use 30rem/40rem/64rem/80rem`,\n })\n }\n }\n }\n return violations\n}\n\nconst isFunctionCall = (value: string) => /--[\\w-]+\\(/.test(value)\nconst isIfExpression = (value: string) => /\\bif\\s*\\(/.test(value)\n\n/** Enforce the @function / if() static-fallback contract. */\nfunction checkFallbacks(css: string): ComponentViolation[] {\n const violations: ComponentViolation[] = []\n const lines = css.split('\\n')\n let inSupports = false\n let supportsDepth = 0\n let baseSupportsDepth = 0\n interface Block {\n properties: Map<string, boolean>\n }\n const stack: Block[] = []\n\n for (let i = 0; i < lines.length; i++) {\n const line = (lines[i] ?? '').trim()\n if (/^@supports\\b/.test(line)) {\n inSupports = true\n baseSupportsDepth = supportsDepth\n }\n const opens = (line.match(/\\{/g) ?? []).length\n const closes = (line.match(/\\}/g) ?? []).length\n for (let j = 0; j < opens; j++) {\n stack.push({ properties: new Map() })\n supportsDepth++\n }\n for (let j = 0; j < closes; j++) {\n if (stack.length > 0) stack.pop()\n supportsDepth--\n if (supportsDepth <= baseSupportsDepth) inSupports = false\n }\n const declMatch = line.match(/^([\\w-]+)\\s*:\\s*(.+?)\\s*;?\\s*$/)\n if (!declMatch) continue\n const property = declMatch[1]!\n const value = declMatch[2]!\n if (isFunctionCall(value) || isIfExpression(value)) {\n let hasFallback = inSupports\n if (!hasFallback) {\n for (const block of stack) {\n if (block.properties.get(property)) {\n hasFallback = true\n break\n }\n }\n }\n if (!hasFallback) {\n violations.push({\n rule: 'missing-css-fallback',\n severity: 'error',\n line: i + 1,\n detail: `\"${property}\" uses @function/if() with no preceding static fallback`,\n })\n }\n } else if (stack.length > 0) {\n stack[stack.length - 1]!.properties.set(property, true)\n }\n }\n return violations\n}\n\n/** Flag `var(--cascivo-…)` references that are not in the closed token set. */\nfunction checkTokens(css: string, tokenNames: ReadonlySet<string>): ComponentViolation[] {\n if (tokenNames.size === 0) return []\n const violations: ComponentViolation[] = []\n const re = /var\\(\\s*(--cascivo-[\\w-]+)/g\n let m: RegExpExecArray | null\n const seen = new Set<string>()\n while ((m = re.exec(css)) !== null) {\n const token = m[1]!\n if (tokenNames.has(token) || seen.has(token)) continue\n seen.add(token)\n violations.push({\n rule: 'unknown-token',\n severity: 'error',\n line: lineOf(css, m.index),\n detail: `\"${token}\" is not in the cascivo token catalog (hallucinated token)`,\n })\n }\n return violations\n}\n\n/** Run all structural invariants over a candidate component's source. */\nexport function validateComponentSource(\n input: ValidateComponentInput,\n options: ValidateComponentOptions = {},\n): ValidateComponentResult {\n const violations: ComponentViolation[] = []\n if (input.tsx) violations.push(...checkBannedHooks(input.tsx))\n if (input.css) {\n violations.push(...checkBreakpoints(input.css))\n violations.push(...checkFallbacks(input.css))\n if (options.tokenNames) violations.push(...checkTokens(input.css, options.tokenNames))\n }\n violations.sort((a, b) => a.line - b.line)\n return {\n valid: violations.every((v) => v.severity !== 'error'),\n ...(input.name ? { name: input.name } : {}),\n violations,\n }\n}\n","import { existsSync, readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport interface ContextRelated {\n name: string\n relationship: string\n reason: string\n}\n\nexport interface ContextAntiPattern {\n bad: string\n good: string\n why: string\n}\n\nexport interface ContextFlexibility {\n area: string\n level: string\n note: string\n}\n\nexport interface ComponentIntent {\n whenToUse: string[]\n whenNotToUse: string[]\n antiPatterns: ContextAntiPattern[]\n related: ContextRelated[]\n a11yRationale?: string\n flexibility?: ContextFlexibility[]\n}\n\nexport interface ContextComponent {\n name: string\n category: string\n description: string\n intent: ComponentIntent\n contextUrl: string\n /** Copy-pasteable system-prompt snippet that pins an LLM to this component. */\n aiPrompt?: string\n}\n\nexport interface ContextBundle {\n generatedAt: string\n tagline: string\n authoringRules: string[]\n tokenCatalogUrl: string\n components: ContextComponent[]\n}\n\ntype FetchFn = (url: string, init?: RequestInit) => Promise<Response>\n\nconst HERE = dirname(fileURLToPath(import.meta.url))\nconst CONTEXT_BASE_URL = 'https://cascivo.com'\n\nexport async function loadContext(fetchFn?: FetchFn): Promise<ContextBundle> {\n const localPaths = [\n join(HERE, '..', '..', '..', 'apps', 'docs', 'public', 'context.json'),\n join(HERE, 'context.json'),\n ]\n for (const p of localPaths) {\n if (existsSync(p)) return JSON.parse(readFileSync(p, 'utf8')) as ContextBundle\n }\n const url = `${CONTEXT_BASE_URL}/context.json`\n const fn = fetchFn ?? fetch\n const res = await fn(url)\n if (!res.ok) throw new Error(`Failed to fetch context bundle: ${res.status}`)\n return res.json() as Promise<ContextBundle>\n}\n\nexport async function loadComponentMarkdown(\n name: string,\n fetchFn?: FetchFn,\n): Promise<string | null> {\n const slug = name.toLowerCase().replace(/\\s+/g, '-')\n const localPaths = [\n join(HERE, '..', '..', '..', 'apps', 'docs', 'public', 'context', `${slug}.md`),\n join(HERE, 'context', `${slug}.md`),\n ]\n for (const p of localPaths) {\n if (existsSync(p)) return readFileSync(p, 'utf8')\n }\n const url = `${CONTEXT_BASE_URL}/context/${slug}.md`\n const fn = fetchFn ?? fetch\n try {\n const res = await fn(url)\n if (!res.ok) return null\n return res.text()\n } catch {\n return null\n }\n}\n","import type { ContextComponent } from './context.js'\n\nexport interface SelectRelated {\n name: string\n relationship: string\n reason: string\n}\n\nexport interface SelectResult {\n name: string\n score: number\n why: string\n /** When NOT to use this pick — lets an agent disqualify a wrong match. */\n whenNotToUse: string[]\n /** Related components (alternatives, pairs-with) to consider instead/alongside. */\n related: SelectRelated[]\n}\n\n// Minimum length for a need word to be scored (filters out articles, prepositions, etc.)\nconst MIN_WORD_LEN = 3\n\nfunction words(text: string): string[] {\n return (text.toLowerCase().match(/\\b\\w+\\b/g) ?? []).filter((w) => w.length >= MIN_WORD_LEN)\n}\n\nfunction countMatches(needWords: string[], text: string): string[] {\n const lower = text.toLowerCase()\n return needWords.filter((w) => lower.includes(w))\n}\n\nexport function selectComponent(need: string, components: ContextComponent[]): SelectResult[] {\n const needWords = words(need)\n if (needWords.length === 0) return []\n\n const scored = components.map((c) => {\n const whenToUseText = c.intent.whenToUse.join(' ')\n const whenNotToUseText = c.intent.whenNotToUse.join(' ')\n\n const whenToUseMatches = countMatches(needWords, whenToUseText)\n const descMatches = countMatches(needWords, c.description)\n const penaltyMatches = countMatches(needWords, whenNotToUseText)\n\n const score = whenToUseMatches.length * 2 + descMatches.length - penaltyMatches.length * 3\n\n // Build why from the best-matching whenToUse sentence\n let why = ''\n if (whenToUseMatches.length > 0) {\n const bestSentence = c.intent.whenToUse\n .map((s) => ({ s, count: countMatches(needWords, s).length }))\n .filter((x) => x.count > 0)\n .sort((a, b) => b.count - a.count)[0]?.s\n why = bestSentence\n ? `Matched: ${whenToUseMatches.map((w) => `'${w}'`).join(', ')} in whenToUse — \"${bestSentence}\"`\n : `Matched: ${whenToUseMatches.map((w) => `'${w}'`).join(', ')} in description`\n } else if (descMatches.length > 0) {\n why = `Matched: ${descMatches.map((w) => `'${w}'`).join(', ')} in description`\n }\n\n return {\n name: c.name,\n score,\n why,\n whenNotToUse: c.intent.whenNotToUse ?? [],\n related: c.intent.related ?? [],\n }\n })\n\n // First pass: top 3 by score for related bonus\n const top3Names = new Set(\n [...scored]\n .sort((a, b) => b.score - a.score || a.name.localeCompare(b.name))\n .slice(0, 3)\n .map((r) => r.name),\n )\n\n // Apply related bonus: +1 if a top-3 component points at this component\n const relatedBonus = new Map<string, number>()\n for (const r of scored) {\n if (!top3Names.has(r.name)) continue\n for (const rel of r.related) {\n relatedBonus.set(rel.name, (relatedBonus.get(rel.name) ?? 0) + 1)\n }\n }\n\n const final = scored.map((r) => ({\n name: r.name,\n score: r.score + (relatedBonus.get(r.name) ?? 0),\n why: r.why,\n whenNotToUse: r.whenNotToUse,\n related: r.related,\n }))\n\n return final\n .filter((r) => r.score >= 0)\n .sort((a, b) => b.score - a.score || a.name.localeCompare(b.name))\n .slice(0, 5)\n}\n","import { spawnSync } from 'node:child_process'\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { z } from 'zod'\nimport {\n fetchDirectory,\n fetchRegistryIndex,\n getComponent,\n getEnvRegistries,\n listComponents,\n loadRegistry,\n mergeRegistries,\n searchComponents,\n type Registry,\n} from './registry.js'\nimport { generateThemeCss } from './theme.js'\nimport { scaffoldPage } from './scaffold.js'\nimport { validateView } from './validate.js'\nimport { scaffoldView } from './scaffold-view.js'\nimport { buildGrammar, formatGrammar } from './grammar.js'\nimport { buildGenerationPrompt } from './prompt.js'\nimport { loadTokenCatalog } from './tokens.js'\nimport { loadVariantMatrix } from './variants.js'\nimport { validateComponentSource } from './validate-component.js'\nimport { loadContext, loadComponentMarkdown } from './context.js'\nimport { selectComponent } from './select.js'\n\ntype FetchFn = (url: string, init?: RequestInit) => Promise<Response>\n\nexport interface ServerOptions {\n registryPath?: string\n version?: string\n /** Injectable fetch function — used for testing multi-registry features. */\n fetchFn?: FetchFn\n}\n\nconst json = (value: unknown) => ({\n content: [{ type: 'text' as const, text: JSON.stringify(value, null, 2) }],\n})\n\nconst text = (value: string) => ({ content: [{ type: 'text' as const, text: value }] })\n\nconst error = (message: string) => ({\n content: [{ type: 'text' as const, text: message }],\n isError: true,\n})\n\n/** Build a configured McpServer exposing the cascade component registry. */\nexport function createServer(options: ServerOptions = {}): McpServer {\n const registry: Registry = loadRegistry(options.registryPath)\n const fetchFn = options.fetchFn\n\n const server = new McpServer({\n name: '@cascivo/mcp',\n version: options.version ?? '0.0.0',\n })\n\n server.registerTool(\n 'list_registries',\n {\n title: 'List registries',\n description:\n 'List available component registries: the cascade directory plus any configured via CASCADE_REGISTRIES env.',\n inputSchema: {},\n },\n async () => {\n const directory = await fetchDirectory(fetchFn)\n const env = getEnvRegistries()\n const entries = mergeRegistries(directory, env)\n return json(\n entries.map(({ namespace, name, description, verified, homepage }) => ({\n namespace,\n name,\n description,\n verified: verified ?? false,\n homepage,\n })),\n )\n },\n )\n\n server.registerTool(\n 'list_components',\n {\n title: 'List components',\n description: 'List all cascade components, optionally filtered by category and/or type.',\n inputSchema: {\n category: z\n .enum(['inputs', 'display', 'overlay', 'navigation', 'feedback', 'chart'])\n .optional()\n .describe('Filter by component category'),\n type: z\n .enum(['component', 'layout', 'block', 'chart', 'flow', 'editor'])\n .optional()\n .describe('Filter by entry type'),\n },\n },\n ({ category, type }) => json(listComponents(registry, category, type)),\n )\n\n server.registerTool(\n 'get_component',\n {\n title: 'Get component',\n description:\n 'Get the full manifest (props, states, tokens, a11y, examples) for one component.',\n inputSchema: {\n name: z.string().describe('Component name, e.g. \"button\"'),\n registry: z\n .string()\n .optional()\n .describe('Namespace of an external registry, e.g. \"@myns\". Omit for the default.'),\n },\n },\n async ({ name, registry: ns }) => {\n if (ns) {\n const env = getEnvRegistries()\n const directory = await fetchDirectory(fetchFn)\n const entries = mergeRegistries(directory, env)\n const entry = entries.find((e) => e.namespace === ns)\n if (!entry) return error(`Registry \"${ns}\" not found.`)\n const remoteRegistry = await fetchRegistryIndex(entry.registryUrl, fetchFn)\n if (!remoteRegistry) return error(`Failed to fetch registry index for \"${ns}\".`)\n const meta = getComponent(remoteRegistry, name)\n return meta ? json(meta) : error(`Component \"${name}\" not found in registry \"${ns}\".`)\n }\n const meta = getComponent(registry, name)\n return meta ? json(meta) : error(`Component \"${name}\" not found.`)\n },\n )\n\n server.registerTool(\n 'search_components',\n {\n title: 'Search components',\n description: 'Fuzzy search components by name, tags, or description.',\n inputSchema: {\n query: z.string().describe('Search query'),\n registry: z\n .string()\n .optional()\n .describe('Namespace of an external registry, e.g. \"@myns\". Omit for the default.'),\n },\n },\n async ({ query, registry: ns }) => {\n if (ns) {\n const env = getEnvRegistries()\n const directory = await fetchDirectory(fetchFn)\n const entries = mergeRegistries(directory, env)\n const entry = entries.find((e) => e.namespace === ns)\n if (!entry) return error(`Registry \"${ns}\" not found.`)\n const remoteRegistry = await fetchRegistryIndex(entry.registryUrl, fetchFn)\n if (!remoteRegistry) return error(`Failed to fetch registry index for \"${ns}\".`)\n return json(searchComponents(remoteRegistry, query))\n }\n return json(searchComponents(registry, query))\n },\n )\n\n server.registerTool(\n 'add_to_project',\n {\n title: 'Add to project',\n description: 'Add a component to the current project by running the cascade CLI.',\n inputSchema: {\n name: z.string().describe('Component name to add'),\n outputDir: z.string().optional().describe('Directory to write the component into'),\n },\n },\n ({ name, outputDir }) => {\n const env = outputDir ? { ...process.env, CASCIVO_OUTPUT_DIR: outputDir } : process.env\n const result = spawnSync('npx', ['-y', 'cascivo', 'add', name], { encoding: 'utf8', env })\n if (result.status !== 0) {\n return error(result.stderr || result.error?.message || `Failed to add \"${name}\".`)\n }\n return text(result.stdout || `Added ${name}.`)\n },\n )\n\n server.registerTool(\n 'create_theme',\n {\n title: 'Create theme',\n description: 'Generate a cascade theme CSS file from three colors.',\n inputSchema: {\n primary: z.string().describe('Primary / interactive color (any CSS color)'),\n neutral: z.string().describe('Base neutral color for surfaces and text'),\n accent: z.string().describe('Secondary accent color (info / focus)'),\n name: z.string().optional().describe('Theme name (default: \"custom\")'),\n },\n },\n ({ primary, neutral, accent, name }) =>\n text(generateThemeCss({ primary, neutral, accent }, name)),\n )\n\n server.registerTool(\n 'scaffold_page',\n {\n title: 'Scaffold page (deprecated)',\n description:\n '[Deprecated — use scaffold_view instead] Generate a JSX page layout from a description.',\n inputSchema: {\n description: z.string().describe('What the page is for'),\n components: z.array(z.string()).optional().describe('Components to include'),\n },\n },\n ({ description, components }) => {\n const { config } = scaffoldView(\n { description, ...(components ? { components } : {}) },\n registry,\n )\n return text(\n `[Deprecated] Use scaffold_view for config-first output. JSX scaffold:\\n\\n${scaffoldPage(components ? { description, components } : { description })}\\n\\n--- scaffold_view output ---\\n${JSON.stringify(config, null, 2)}`,\n )\n },\n )\n\n server.registerTool(\n 'validate_view',\n {\n title: 'Validate view config',\n description:\n 'Validate a CascadeView JSON config against the registry. Returns errors with exact paths.',\n inputSchema: {\n config: z.record(z.string(), z.unknown()).describe('The ViewConfig object to validate'),\n },\n },\n ({ config }) => {\n const componentNames = new Set(registry.components.map((c) => c.meta.name))\n const result = validateView(config, componentNames)\n return json(result)\n },\n )\n\n server.registerTool(\n 'scaffold_view',\n {\n title: 'Scaffold view config',\n description:\n 'Generate a valid starter ViewConfig from a description. Always validates before returning.',\n inputSchema: {\n description: z.string().describe('What the page/view is for'),\n components: z.array(z.string()).optional().describe('Component names to include'),\n },\n },\n ({ description, components }) => {\n const { config, errors, grammar } = scaffoldView(\n { description, ...(components ? { components } : {}) },\n registry,\n )\n if (errors.length > 0) {\n return json({ valid: false, errors, config, grammar })\n }\n return json({ valid: true, config, grammar })\n },\n )\n\n server.registerTool(\n 'scaffold_flow',\n {\n title: 'Scaffold a flow diagram',\n description:\n 'Generate a starter declarative <Flow nodes edges /> (from @cascivo/flow) for a node/edge diagram — flowchart, DAG, or pipeline. Returns serializable nodes/edges plus ready-to-paste JSX. Edit the labels/edges to match the intent.',\n inputSchema: {\n description: z.string().describe('What the diagram represents'),\n steps: z\n .array(z.string())\n .optional()\n .describe(\n 'Ordered step labels; consecutive steps are connected. Omit for a 3-step starter.',\n ),\n layout: z\n .enum(['none', 'grid', 'layered'])\n .optional()\n .describe('Optional auto-layout. Default \"layered\".'),\n },\n },\n ({ description, steps, layout }) => {\n const labels = steps && steps.length > 0 ? steps : ['Source', 'Process', 'Sink']\n const nodes = labels.map((label, i) => ({\n id: `n${i + 1}`,\n position: { x: i * 240, y: 0 },\n data: { label },\n }))\n const edges = labels.slice(1).map((_, i) => ({\n id: `e${i + 1}`,\n source: `n${i + 1}`,\n target: `n${i + 2}`,\n animated: true,\n }))\n const lay = layout ?? 'layered'\n const layoutProp = lay === 'none' ? '' : ` layout=\"${lay}\"`\n const code = `import { Flow } from '@cascivo/flow'\nimport '@cascivo/flow/styles.css'\n\n// ${description}\nexport function Diagram() {\n return (\n <Flow\n style={{ height: 360 }}\n background\n controls${layoutProp}\n nodes={${JSON.stringify(nodes)}}\n edges={${JSON.stringify(edges)}}\n />\n )\n}`\n return json({ nodes, edges, layout: lay, code })\n },\n )\n\n server.registerTool(\n 'get_view_grammar',\n {\n title: 'Get view grammar',\n description:\n \"Get the bound-vocabulary grammar + system prompt for generating valid ViewConfig JSON, derived from the component manifests. Use this to constrain an LLM to cascivo's real components, props, and enum values (anti-hallucination). Optionally scope to a subset of components.\",\n inputSchema: {\n components: z\n .array(z.string())\n .optional()\n .describe('Scope the vocabulary to these component names. Omit for the full registry.'),\n },\n },\n ({ components }) => {\n const grammar = buildGrammar(registry, components)\n return json({\n grammar: formatGrammar(grammar),\n prompt: buildGenerationPrompt(registry, components ? { components } : {}),\n components: grammar.components,\n })\n },\n )\n\n server.registerTool(\n 'get_tokens',\n {\n title: 'Get tokens',\n description:\n 'Get the cascade token catalog (closed set). Agents must select from this catalog rather than hard-coding values.',\n inputSchema: {\n group: z\n .string()\n .optional()\n .describe('Filter by token group, e.g. \"color\", \"space\", \"radius\"'),\n layer: z\n .enum(['primitive', 'semantic', 'component'])\n .optional()\n .describe('Filter by layer'),\n },\n },\n async ({ group, layer }) => {\n try {\n const catalog = await loadTokenCatalog(fetchFn)\n let tokens = catalog.tokens\n if (group) tokens = tokens.filter((t) => t.group === group)\n if (layer) tokens = tokens.filter((t) => t.layer === layer)\n return json({ count: tokens.length, tokens })\n } catch (e) {\n return error(`Token catalog unavailable: ${e instanceof Error ? e.message : String(e)}`)\n }\n },\n )\n\n server.registerTool(\n 'get_variant_matrix',\n {\n title: 'Get variant matrix',\n description:\n 'Get the deterministic token variant matrix: a map from design intent (a colour role + state slot, e.g. accent + hover) to the exact token name, plus every semantic/component token resolved to a concrete value in each theme. Use this to answer \"what is the warm theme\\'s accent-hover value?\" or \"which token is the active state of primary?\" without guessing how layered theme CSS resolves.',\n inputSchema: {\n role: z\n .string()\n .optional()\n .describe('Filter to one colour role, e.g. \"accent\", \"primary\", \"destructive\"'),\n theme: z\n .string()\n .optional()\n .describe('Restrict the per-theme values to a single theme, e.g. \"warm\"'),\n },\n },\n async ({ role, theme }) => {\n try {\n const matrix = await loadVariantMatrix(fetchFn)\n if (theme && !matrix.themes.includes(theme)) {\n return error(`Unknown theme \"${theme}\". Available: ${matrix.themes.join(', ')}`)\n }\n const pickTheme = (byTheme: Record<string, string | null>) =>\n theme ? { [theme]: byTheme[theme] ?? null } : byTheme\n let tokens = matrix.tokens\n let families = matrix.families\n if (role) {\n tokens = tokens.filter((t) => t.role === role)\n families = matrix.families[role] ? { [role]: matrix.families[role] } : {}\n if (tokens.length === 0) {\n const available = Object.keys(matrix.families).join(', ')\n return error(`No colour role \"${role}\". Available roles: ${available}`)\n }\n }\n return json({\n themes: theme ? [theme] : matrix.themes,\n families,\n tokens: tokens.map((t) => ({ ...t, byTheme: pickTheme(t.byTheme) })),\n })\n } catch (e) {\n return error(`Variant matrix unavailable: ${e instanceof Error ? e.message : String(e)}`)\n }\n },\n )\n\n server.registerTool(\n 'validate_component',\n {\n title: 'Validate component (shadow sandbox)',\n description:\n \"Run cascivo's structural invariants over candidate component source (TSX and/or CSS) before writing it to disk. Catches banned React hooks, off-scale @media/@container breakpoints, missing static fallbacks for progressive CSS (@function/if()), and hallucinated --cascivo-* tokens. Use this to self-correct generated code in a loop until `valid` is true.\",\n inputSchema: {\n tsx: z.string().optional().describe('Component TSX source'),\n css: z.string().optional().describe('Component CSS (module or plain) source'),\n name: z.string().optional().describe('Component name (for messages only)'),\n },\n },\n async ({ tsx, css, name }) => {\n let tokenNames: Set<string> | undefined\n try {\n const catalog = await loadTokenCatalog(fetchFn)\n tokenNames = new Set(catalog.tokens.map((t) => t.name))\n } catch {\n // Token catalog is optional — skip the hallucination check if unavailable.\n }\n const result = validateComponentSource(\n { ...(tsx ? { tsx } : {}), ...(css ? { css } : {}), ...(name ? { name } : {}) },\n tokenNames ? { tokenNames } : {},\n )\n return json(result)\n },\n )\n\n server.registerTool(\n 'get_context',\n {\n title: 'Get context',\n description:\n 'Get intent, whenToUse/whenNotToUse, and authoring guidance for one component by name.',\n inputSchema: {\n name: z.string().describe('Component name, e.g. \"Toast\"'),\n },\n },\n async ({ name }) => {\n try {\n const ctx = await loadContext(fetchFn)\n const target = name.toLowerCase()\n const component = ctx.components.find((c) => c.name.toLowerCase() === target)\n if (!component) {\n const available = ctx.components.map((c) => c.name).join(', ')\n return error(`Component \"${name}\" not found. Available: ${available}`)\n }\n const md = await loadComponentMarkdown(component.name, fetchFn)\n return json({\n name: component.name,\n category: component.category,\n description: component.description,\n intent: component.intent,\n contextUrl: component.contextUrl,\n ...(component.aiPrompt ? { aiPrompt: component.aiPrompt } : {}),\n ...(md ? { markdown: md } : {}),\n })\n } catch (e) {\n return error(`Context bundle unavailable: ${e instanceof Error ? e.message : String(e)}`)\n }\n },\n )\n\n server.registerTool(\n 'select_component',\n {\n title: 'Select component',\n description:\n 'Heuristic ranking of cascade components by natural language need. Returns top matches with scores and reasons. Note: heuristic ranking, not a model call.',\n inputSchema: {\n need: z.string().describe('Natural language description of what the component should do'),\n },\n },\n async ({ need }) => {\n try {\n const ctx = await loadContext(fetchFn)\n const results = selectComponent(need, ctx.components)\n return json({\n note: 'Heuristic ranking — not a model call. Verify with get_context before using.',\n results,\n })\n } catch (e) {\n return error(`Context bundle unavailable: ${e instanceof Error ? e.message : String(e)}`)\n }\n },\n )\n\n return server\n}\n","import { argv } from 'node:process'\nimport { pathToFileURL } from 'node:url'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { createServer } from './server.js'\n\nexport const VERSION = '0.0.0'\n\nexport { createServer } from './server.js'\nexport type { ServerOptions } from './server.js'\nexport { generateThemeCss, type ThemeColors } from './theme.js'\nexport { scaffoldPage, type ScaffoldOptions } from './scaffold.js'\nexport {\n buildGrammar,\n formatGrammar,\n parseEnum,\n type GrammarComponent,\n type GrammarProp,\n type ViewGrammar,\n} from './grammar.js'\nexport { buildGenerationPrompt, type GenerationPromptOptions } from './prompt.js'\nexport {\n getComponent,\n listComponents,\n loadRegistry,\n searchComponents,\n type ComponentManifest,\n type Registry,\n type RegistryComponent,\n} from './registry.js'\n\n/** Start the MCP server over stdio. */\nexport async function main(): Promise<void> {\n const server = createServer({ version: VERSION })\n await server.connect(new StdioServerTransport())\n}\n\nconst isMain = argv[1] !== undefined && import.meta.url === pathToFileURL(argv[1]).href\n\nif (isMain) {\n main().catch((err: unknown) => {\n console.error(err instanceof Error ? err.message : String(err))\n process.exitCode = 1\n })\n}\n"],"mappings":";;;;;;;;;AA6CA,MAAMA,SAAO,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC;;;;;;AAOnD,SAAgB,oBAAoB,UAA2B;CAC7D,MAAM,aAAa;EACjB;EACA,QAAQ,IAAI;EACZ,KAAKA,QAAM,eAAe;EAC1B,KAAKA,QAAM,MAAM,MAAM,MAAM,eAAe;EAC5C,KAAKA,QAAM,MAAM,MAAM,eAAe;CACxC,CAAC,CAAC,QAAQ,MAAmB,OAAO,MAAM,YAAY,EAAE,SAAS,CAAC;CAElE,OACE,WAAW,MAAM,MAAM,WAAW,CAAC,CAAC,KAAK,WAAW,WAAW,SAAS,MAAM;AAElF;AAEA,SAAgB,aAAa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