@fragments-sdk/context 0.4.2 → 0.4.4

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.
@@ -81,7 +81,68 @@ function generateMarkdownContext(fragments, include, compact, blocks) {
81
81
  lines.push("");
82
82
  }
83
83
  }
84
- if (include.props && Object.keys(fragment.props).length > 0) {
84
+ if (fragment.ai?.compositionPattern) {
85
+ const ai = fragment.ai;
86
+ const parts = [`**Composition:** ${ai.compositionPattern}`];
87
+ if (ai.subComponents && ai.subComponents.length > 0) {
88
+ parts.push(`Sub-components: ${ai.subComponents.map((s) => `${fragment.meta.name}.${s}`).join(", ")}`);
89
+ }
90
+ if (ai.requiredChildren && ai.requiredChildren.length > 0) {
91
+ parts.push(`Required: ${ai.requiredChildren.map((c) => `${fragment.meta.name}.${c}`).join(", ")}`);
92
+ }
93
+ lines.push(parts.join(" | "));
94
+ lines.push("");
95
+ if (ai.commonPatterns && ai.commonPatterns.length > 0) {
96
+ lines.push("**Patterns:**");
97
+ for (const pattern of ai.commonPatterns) {
98
+ lines.push(`- \`${pattern}\``);
99
+ }
100
+ lines.push("");
101
+ }
102
+ }
103
+ if (fragment.contract) {
104
+ const contract = fragment.contract;
105
+ if (contract.propsSummary && contract.propsSummary.length > 0) {
106
+ lines.push(`**Props:** ${contract.propsSummary.join(", ")}`);
107
+ lines.push("");
108
+ } else if (include.props && Object.keys(fragment.props).length > 0) {
109
+ lines.push("**Props:**");
110
+ for (const [name, prop] of Object.entries(fragment.props)) {
111
+ lines.push(`- \`${name}\`: ${formatPropType(prop)}${prop.required ? " (required)" : ""}`);
112
+ }
113
+ lines.push("");
114
+ }
115
+ if (contract.compoundChildren && Object.keys(contract.compoundChildren).length > 0) {
116
+ lines.push("**Sub-components:**");
117
+ for (const [childName, childMeta] of Object.entries(contract.compoundChildren)) {
118
+ const parts = [`\`${fragment.meta.name}.${childName}\``];
119
+ if (childMeta.required) parts.push("(required)");
120
+ if (childMeta.description) parts.push(`\u2014 ${childMeta.description}`);
121
+ lines.push(`- ${parts.join(" ")}`);
122
+ }
123
+ lines.push("");
124
+ }
125
+ if (contract.canonicalUsage && contract.canonicalUsage.length > 0) {
126
+ lines.push("**Usage examples:**");
127
+ for (const usage of contract.canonicalUsage) {
128
+ lines.push("```tsx");
129
+ lines.push(usage);
130
+ lines.push("```");
131
+ }
132
+ lines.push("");
133
+ }
134
+ if (contract.a11yRules && contract.a11yRules.length > 0) {
135
+ lines.push(`**A11y:** ${contract.a11yRules.join(", ")}`);
136
+ lines.push("");
137
+ }
138
+ if (contract.bans && contract.bans.length > 0) {
139
+ lines.push("**Banned patterns:**");
140
+ for (const ban of contract.bans) {
141
+ lines.push(`- \`${ban.pattern}\`: ${ban.message}`);
142
+ }
143
+ lines.push("");
144
+ }
145
+ } else if (include.props && Object.keys(fragment.props).length > 0) {
85
146
  lines.push("**Props:**");
86
147
  for (const [name, prop] of Object.entries(fragment.props)) {
87
148
  lines.push(`- \`${name}\`: ${formatPropType(prop)}${prop.required ? " (required)" : ""}`);
@@ -159,6 +220,35 @@ function generateJsonContext(fragments, include, compact, blocks) {
159
220
  if (whenFiltered.length > 0) component.whenToUse = whenFiltered;
160
221
  if (whenNotFiltered.length > 0) component.whenNotToUse = whenNotFiltered;
161
222
  }
223
+ if (fragment.ai?.compositionPattern) {
224
+ const ai = fragment.ai;
225
+ const comp = { pattern: ai.compositionPattern };
226
+ if (ai.subComponents && ai.subComponents.length > 0) {
227
+ comp.subComponents = ai.subComponents;
228
+ }
229
+ if (ai.requiredChildren && ai.requiredChildren.length > 0) {
230
+ comp.requiredChildren = ai.requiredChildren;
231
+ }
232
+ if (ai.commonPatterns && ai.commonPatterns.length > 0) {
233
+ comp.commonPatterns = ai.commonPatterns;
234
+ }
235
+ component.composition = comp;
236
+ }
237
+ if (fragment.contract?.propsSummary && fragment.contract.propsSummary.length > 0) {
238
+ component.propsSummary = fragment.contract.propsSummary;
239
+ }
240
+ if (fragment.contract?.compoundChildren && Object.keys(fragment.contract.compoundChildren).length > 0) {
241
+ component.compoundChildren = fragment.contract.compoundChildren;
242
+ }
243
+ if (fragment.contract?.canonicalUsage && fragment.contract.canonicalUsage.length > 0) {
244
+ component.canonicalUsage = fragment.contract.canonicalUsage;
245
+ }
246
+ if (fragment.contract?.a11yRules && fragment.contract.a11yRules.length > 0) {
247
+ component.a11yRules = fragment.contract.a11yRules;
248
+ }
249
+ if (fragment.contract?.bans && fragment.contract.bans.length > 0) {
250
+ component.bans = fragment.contract.bans;
251
+ }
162
252
  if (include.props && Object.keys(fragment.props).length > 0) {
163
253
  component.props = {};
164
254
  for (const [name, prop] of Object.entries(fragment.props)) {
@@ -35,6 +35,19 @@ var CLI_COMMAND_CATEGORIES = {
35
35
  };
36
36
  var CLI_COMMANDS = [
37
37
  // ── Setup ──
38
+ {
39
+ name: "setup",
40
+ description: "Configure @fragments-sdk/ui in a consumer project (styles, providers, Next.js config)",
41
+ category: "setup",
42
+ usage: "fragments setup [options]",
43
+ options: [
44
+ { flags: "--root <dir>", description: "Project root directory" },
45
+ { flags: "-y, --yes", description: "Skip interactive prompts" },
46
+ { flags: "--brand <color>", description: "Brand color hex (e.g., #6366f1)" },
47
+ { flags: "--scss", description: "Create SCSS seed file for build-time theming" },
48
+ { flags: "--mcp", description: "Configure MCP server for AI tooling" }
49
+ ]
50
+ },
38
51
  {
39
52
  name: "init",
40
53
  description: "Initialize fragments in a project (interactive by default)",
@@ -288,6 +288,21 @@ var MCP_TOOL_DEFINITIONS = [
288
288
  }
289
289
  },
290
290
  required: ["component"]
291
+ },
292
+ {
293
+ key: "generate_ui",
294
+ description: "Generate a complete UI from a natural language description. Returns a structured element tree that can be rendered with Fragments components. Optionally pass an existing element tree to refine it.",
295
+ params: {
296
+ prompt: {
297
+ type: "string",
298
+ description: 'Natural language description of the UI to generate (e.g., "a settings page with profile section and notification preferences")'
299
+ },
300
+ currentTree: {
301
+ type: "object",
302
+ description: "Optional existing element tree to refine. When provided, the AI will modify this tree based on the prompt instead of generating from scratch."
303
+ }
304
+ },
305
+ required: ["prompt"]
291
306
  }
292
307
  ];
293
308
  var CLI_TOOL_EXTENSIONS = [
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CLI_COMMANDS,
3
3
  CLI_COMMAND_CATEGORIES
4
- } from "../chunk-U7P5372N.js";
4
+ } from "../chunk-BZ6SGVA2.js";
5
5
  export {
6
6
  CLI_COMMANDS,
7
7
  CLI_COMMAND_CATEGORIES
@@ -1,5 +1,5 @@
1
1
  import { CompiledFragment, CompiledBlock } from '../types/index.js';
2
- import '../types-RAbbckR4.js';
2
+ import '../types-ExvGbLOm.js';
3
3
 
4
4
  /**
5
5
  * Context generation for AI agents.
@@ -2,7 +2,7 @@ import {
2
2
  PLACEHOLDER_PATTERNS,
3
3
  filterPlaceholders,
4
4
  generateContext
5
- } from "../chunk-2UQY4VNM.js";
5
+ } from "../chunk-AW6Q5736.js";
6
6
  export {
7
7
  PLACEHOLDER_PATTERNS,
8
8
  filterPlaceholders,
@@ -1,5 +1,5 @@
1
- import { C as ComponentGraph, G as GraphEdgeType, a as GraphEdge, I as ImpactResult, P as PathResult, N as NeighborResult, b as CompositionTree, c as GraphHealth, d as ComponentNode, S as SerializedComponentGraph } from '../types-RAbbckR4.js';
2
- export { E as EDGE_TYPE_WEIGHTS, f as GRAPH_EDGE_TYPES, e as SerializedEdge } from '../types-RAbbckR4.js';
1
+ import { C as ComponentGraph, G as GraphEdgeType, a as GraphEdge, I as ImpactResult, P as PathResult, N as NeighborResult, b as CompositionTree, c as GraphHealth, d as ComponentNode, S as SerializedComponentGraph } from '../types-ExvGbLOm.js';
2
+ export { E as EDGE_TYPE_WEIGHTS, f as GRAPH_EDGE_TYPES, e as SerializedEdge } from '../types-ExvGbLOm.js';
3
3
 
4
4
  /**
5
5
  * ComponentGraphEngine — query engine for the design-system relationship graph.
package/dist/index.d.ts CHANGED
@@ -8,4 +8,4 @@ export { AST_SUPPORTED_LANGUAGES, ChangedFiles, FileEntry, GrammarMapping, INDEX
8
8
  export { ChunkMapping, CitationDocumentBlock, CitationDocumentOptions, DocumentMapping, RawCitation, ResolvedCitation, buildCitationDocuments, resolveCitation, resolveCitations } from './citations/index.js';
9
9
  export { CLI_TOOL_EXTENSIONS, CliToolExtension, MCP_TOOL_DEFINITIONS, McpToolDefinition, McpToolParam, buildMcpTools, buildToolNames } from './mcp-tools/index.js';
10
10
  export { CLI_COMMANDS, CLI_COMMAND_CATEGORIES, CliCategoryInfo, CliCommandCategory, CliCommandDef, CliOptionDef } from './cli-commands/index.js';
11
- import './types-RAbbckR4.js';
11
+ import './types-ExvGbLOm.js';
package/dist/index.js CHANGED
@@ -3,11 +3,11 @@ import {
3
3
  MCP_TOOL_DEFINITIONS,
4
4
  buildMcpTools,
5
5
  buildToolNames
6
- } from "./chunk-FGBRIJOT.js";
6
+ } from "./chunk-RTJ3JOPA.js";
7
7
  import {
8
8
  CLI_COMMANDS,
9
9
  CLI_COMMAND_CATEGORIES
10
- } from "./chunk-U7P5372N.js";
10
+ } from "./chunk-BZ6SGVA2.js";
11
11
  import {
12
12
  chunkByAST,
13
13
  chunkByLines,
@@ -36,7 +36,7 @@ import {
36
36
  PLACEHOLDER_PATTERNS,
37
37
  filterPlaceholders,
38
38
  generateContext
39
- } from "./chunk-2UQY4VNM.js";
39
+ } from "./chunk-AW6Q5736.js";
40
40
  import {
41
41
  buildCitationDocuments,
42
42
  resolveCitation,
@@ -3,7 +3,7 @@ import {
3
3
  MCP_TOOL_DEFINITIONS,
4
4
  buildMcpTools,
5
5
  buildToolNames
6
- } from "../chunk-FGBRIJOT.js";
6
+ } from "../chunk-RTJ3JOPA.js";
7
7
  export {
8
8
  CLI_TOOL_EXTENSIONS,
9
9
  MCP_TOOL_DEFINITIONS,
@@ -1,4 +1,4 @@
1
- import { S as SerializedComponentGraph } from '../types-RAbbckR4.js';
1
+ import { S as SerializedComponentGraph } from '../types-ExvGbLOm.js';
2
2
 
3
3
  /**
4
4
  * Compiled fragment types — shared between CLI and MCP packages.
@@ -73,6 +73,14 @@ interface FragmentContract {
73
73
  scenarioTags?: string[];
74
74
  /** Per-component performance budget override in bytes (gzipped) */
75
75
  performanceBudget?: number;
76
+ /** Sub-component slot metadata for compound components */
77
+ compoundChildren?: Record<string, {
78
+ required?: boolean;
79
+ accepts?: string[];
80
+ description?: string;
81
+ }>;
82
+ /** Canonical JSX usage examples showing how to assemble the component */
83
+ canonicalUsage?: string[];
76
84
  }
77
85
  /**
78
86
  * Provenance tracking for generated fragments
@@ -87,7 +95,7 @@ interface FragmentGenerated {
87
95
  * AI-specific metadata
88
96
  */
89
97
  interface AIMetadata {
90
- compositionPattern?: "compound" | "simple" | "controlled";
98
+ compositionPattern?: "compound" | "simple" | "controlled" | "wrapper";
91
99
  subComponents?: string[];
92
100
  requiredChildren?: string[];
93
101
  commonPatterns?: string[];
@@ -12,7 +12,7 @@ interface ComponentNode {
12
12
  name: string;
13
13
  category: string;
14
14
  status: string;
15
- compositionPattern?: 'compound' | 'simple' | 'controlled';
15
+ compositionPattern?: 'compound' | 'simple' | 'controlled' | 'wrapper';
16
16
  subComponents?: string[];
17
17
  }
18
18
  interface GraphEdge {
@@ -84,7 +84,7 @@ interface CompositionTree {
84
84
  /** The root component */
85
85
  component: string;
86
86
  /** Composition pattern */
87
- compositionPattern?: 'compound' | 'simple' | 'controlled';
87
+ compositionPattern?: 'compound' | 'simple' | 'controlled' | 'wrapper';
88
88
  /** Direct sub-components */
89
89
  subComponents: string[];
90
90
  /** Components that declare this component as their parent */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fragments-sdk/context",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "license": "FSL-1.1-MIT",
5
5
  "description": "Code intelligence and RAG primitives for design system and codebase indexing",
6
6
  "author": "Conan McNicholl",