@fragments-sdk/cli 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/LICENSE +77 -14
  2. package/dist/bin.js +247 -247
  3. package/dist/bin.js.map +1 -1
  4. package/dist/{chunk-CVXKXVOY.js → chunk-3T6QL7IY.js} +47 -29
  5. package/dist/chunk-3T6QL7IY.js.map +1 -0
  6. package/dist/{chunk-7OPWMLOE.js → chunk-7KUSBMI4.js} +114 -112
  7. package/dist/chunk-7KUSBMI4.js.map +1 -0
  8. package/dist/{chunk-XHUDJNN3.js → chunk-DH4ETVSM.js} +18 -18
  9. package/dist/chunk-DH4ETVSM.js.map +1 -0
  10. package/dist/{chunk-RVRTRESS.js → chunk-DQHWLAUV.js} +29 -29
  11. package/dist/chunk-DQHWLAUV.js.map +1 -0
  12. package/dist/{chunk-6JBGU74P.js → chunk-GHYYFAQN.js} +23 -23
  13. package/dist/chunk-GHYYFAQN.js.map +1 -0
  14. package/dist/{chunk-NWQ4CJOQ.js → chunk-GKX2HPZ6.js} +40 -40
  15. package/dist/chunk-GKX2HPZ6.js.map +1 -0
  16. package/dist/{chunk-TJ34N7C7.js → chunk-OOGTG5FM.js} +34 -33
  17. package/dist/chunk-OOGTG5FM.js.map +1 -0
  18. package/dist/{core-W2HYIQW6.js → core-UQXZTBFZ.js} +24 -26
  19. package/dist/{generate-LMTISDIJ.js → generate-GP6ZLAQB.js} +5 -5
  20. package/dist/generate-GP6ZLAQB.js.map +1 -0
  21. package/dist/index.d.ts +23 -27
  22. package/dist/index.js +10 -10
  23. package/dist/{init-7CHRKQ7P.js → init-W72WBSU2.js} +5 -5
  24. package/dist/{init-7CHRKQ7P.js.map → init-W72WBSU2.js.map} +1 -1
  25. package/dist/mcp-bin.js +73 -73
  26. package/dist/mcp-bin.js.map +1 -1
  27. package/dist/scan-V54HWRDY.js +12 -0
  28. package/dist/{service-T2L7VLTE.js → service-PVGTYUKX.js} +6 -6
  29. package/dist/{static-viewer-GBR7YNF3.js → static-viewer-KILKIVN7.js} +4 -4
  30. package/dist/{test-OJRXNDO2.js → test-3YRYQRGV.js} +19 -19
  31. package/dist/test-3YRYQRGV.js.map +1 -0
  32. package/dist/{tokens-3BWDESVM.js → tokens-IXSQHPQK.js} +5 -5
  33. package/dist/{viewer-SUFOISZM.js → viewer-K42REJU2.js} +199 -199
  34. package/dist/viewer-K42REJU2.js.map +1 -0
  35. package/package.json +13 -2
  36. package/src/ai.ts +5 -5
  37. package/src/analyze.ts +11 -11
  38. package/src/bin.ts +1 -1
  39. package/src/build.ts +37 -35
  40. package/src/commands/a11y.ts +6 -6
  41. package/src/commands/add.ts +11 -11
  42. package/src/commands/audit.ts +4 -4
  43. package/src/commands/baseline.ts +3 -3
  44. package/src/commands/build.ts +8 -8
  45. package/src/commands/compare.ts +20 -20
  46. package/src/commands/context.ts +16 -16
  47. package/src/commands/enhance.ts +36 -36
  48. package/src/commands/generate.ts +1 -1
  49. package/src/commands/graph.ts +5 -5
  50. package/src/commands/init.ts +1 -1
  51. package/src/commands/link/figma.ts +82 -82
  52. package/src/commands/link/index.ts +3 -3
  53. package/src/commands/link/storybook.ts +9 -9
  54. package/src/commands/list.ts +2 -2
  55. package/src/commands/reset.ts +15 -15
  56. package/src/commands/scan.ts +27 -27
  57. package/src/commands/storygen.ts +24 -24
  58. package/src/commands/validate.ts +2 -2
  59. package/src/commands/verify.ts +8 -8
  60. package/src/core/auto-props.ts +4 -4
  61. package/src/core/composition.test.ts +36 -36
  62. package/src/core/composition.ts +19 -19
  63. package/src/core/config.ts +6 -6
  64. package/src/core/{defineSegment.ts → defineFragment.ts} +16 -22
  65. package/src/core/discovery.ts +6 -6
  66. package/src/core/figma.ts +2 -2
  67. package/src/core/graph-extractor.test.ts +77 -77
  68. package/src/core/graph-extractor.ts +32 -32
  69. package/src/core/importAnalyzer.ts +1 -1
  70. package/src/core/index.ts +22 -23
  71. package/src/core/loader.ts +21 -24
  72. package/src/core/node.ts +5 -5
  73. package/src/core/parser.ts +71 -31
  74. package/src/core/previewLoader.ts +1 -1
  75. package/src/core/schema.ts +16 -16
  76. package/src/core/storyAdapter.test.ts +87 -87
  77. package/src/core/storyAdapter.ts +16 -16
  78. package/src/core/token-parser.ts +9 -1
  79. package/src/core/types.ts +21 -26
  80. package/src/diff.ts +22 -22
  81. package/src/index.ts +2 -2
  82. package/src/mcp/server.ts +80 -80
  83. package/src/migrate/__tests__/utils/utils.test.ts +3 -3
  84. package/src/migrate/bin.ts +4 -4
  85. package/src/migrate/converter.ts +16 -16
  86. package/src/migrate/index.ts +3 -3
  87. package/src/migrate/migrate.ts +3 -3
  88. package/src/migrate/parser.ts +8 -8
  89. package/src/migrate/report.ts +2 -2
  90. package/src/migrate/types.ts +4 -4
  91. package/src/screenshot.ts +22 -22
  92. package/src/service/__tests__/props-extractor.test.ts +15 -15
  93. package/src/service/analytics.ts +39 -39
  94. package/src/service/enhance/codebase-scanner.ts +1 -1
  95. package/src/service/enhance/index.ts +1 -1
  96. package/src/service/enhance/props-extractor.ts +2 -2
  97. package/src/service/enhance/types.ts +2 -2
  98. package/src/service/index.ts +2 -2
  99. package/src/service/metrics-store.ts +1 -1
  100. package/src/service/patch-generator.ts +1 -1
  101. package/src/setup.ts +52 -52
  102. package/src/shared/dev-server-client.ts +7 -7
  103. package/src/shared/fragment-loader.ts +59 -0
  104. package/src/shared/index.ts +1 -1
  105. package/src/shared/types.ts +4 -4
  106. package/src/static-viewer.ts +35 -35
  107. package/src/test/discovery.ts +6 -6
  108. package/src/test/index.ts +5 -5
  109. package/src/test/reporters/console.ts +1 -1
  110. package/src/test/reporters/junit.ts +1 -1
  111. package/src/test/runner.ts +7 -7
  112. package/src/test/types.ts +3 -3
  113. package/src/test/watch.ts +9 -9
  114. package/src/validators.ts +26 -26
  115. package/src/viewer/__tests__/render-utils.test.ts +28 -28
  116. package/src/viewer/__tests__/viewer-integration.test.ts +4 -4
  117. package/src/viewer/cli/health.ts +26 -26
  118. package/src/viewer/components/App.tsx +79 -79
  119. package/src/viewer/components/BottomPanel.tsx +17 -17
  120. package/src/viewer/components/CodePanel.tsx +3 -3
  121. package/src/viewer/components/CommandPalette.tsx +11 -11
  122. package/src/viewer/components/ComponentGraph.tsx +28 -28
  123. package/src/viewer/components/ComponentHeader.tsx +2 -2
  124. package/src/viewer/components/ContractPanel.tsx +6 -6
  125. package/src/viewer/components/FigmaEmbed.tsx +9 -9
  126. package/src/viewer/components/HealthDashboard.tsx +17 -17
  127. package/src/viewer/components/InteractionsPanel.tsx +2 -2
  128. package/src/viewer/components/IsolatedPreviewFrame.tsx +6 -6
  129. package/src/viewer/components/IsolatedRender.tsx +10 -10
  130. package/src/viewer/components/LeftSidebar.tsx +28 -28
  131. package/src/viewer/components/MultiViewportPreview.tsx +14 -14
  132. package/src/viewer/components/PreviewArea.tsx +11 -11
  133. package/src/viewer/components/PreviewFrameHost.tsx +51 -51
  134. package/src/viewer/components/RightSidebar.tsx +9 -9
  135. package/src/viewer/components/Sidebar.tsx +17 -17
  136. package/src/viewer/components/StoryRenderer.tsx +2 -2
  137. package/src/viewer/components/TokenStylePanel.tsx +1 -1
  138. package/src/viewer/components/UsageSection.tsx +2 -2
  139. package/src/viewer/components/VariantMatrix.tsx +11 -11
  140. package/src/viewer/components/VariantRenderer.tsx +3 -3
  141. package/src/viewer/components/VariantTabs.tsx +2 -2
  142. package/src/viewer/components/_future/CreatePage.tsx +6 -6
  143. package/src/viewer/composition-renderer.ts +11 -11
  144. package/src/viewer/entry.tsx +40 -40
  145. package/src/viewer/hooks/useFigmaIntegration.ts +1 -1
  146. package/src/viewer/hooks/usePreviewBridge.ts +5 -5
  147. package/src/viewer/hooks/useUrlState.ts +6 -6
  148. package/src/viewer/index.ts +2 -2
  149. package/src/viewer/intelligence/healthReport.ts +17 -17
  150. package/src/viewer/intelligence/styleDrift.ts +1 -1
  151. package/src/viewer/intelligence/usageScanner.ts +1 -1
  152. package/src/viewer/render-template.html +1 -1
  153. package/src/viewer/render-utils.ts +21 -21
  154. package/src/viewer/server.ts +18 -18
  155. package/src/viewer/utils/detectRelationships.ts +22 -22
  156. package/src/viewer/vite-plugin.ts +213 -213
  157. package/dist/chunk-6JBGU74P.js.map +0 -1
  158. package/dist/chunk-7OPWMLOE.js.map +0 -1
  159. package/dist/chunk-CVXKXVOY.js.map +0 -1
  160. package/dist/chunk-NWQ4CJOQ.js.map +0 -1
  161. package/dist/chunk-RVRTRESS.js.map +0 -1
  162. package/dist/chunk-TJ34N7C7.js.map +0 -1
  163. package/dist/chunk-XHUDJNN3.js.map +0 -1
  164. package/dist/generate-LMTISDIJ.js.map +0 -1
  165. package/dist/scan-WY23TJCP.js +0 -12
  166. package/dist/test-OJRXNDO2.js.map +0 -1
  167. package/dist/viewer-SUFOISZM.js.map +0 -1
  168. package/src/shared/segment-loader.ts +0 -59
  169. /package/dist/{core-W2HYIQW6.js.map → core-UQXZTBFZ.js.map} +0 -0
  170. /package/dist/{scan-WY23TJCP.js.map → scan-V54HWRDY.js.map} +0 -0
  171. /package/dist/{service-T2L7VLTE.js.map → service-PVGTYUKX.js.map} +0 -0
  172. /package/dist/{static-viewer-GBR7YNF3.js.map → static-viewer-KILKIVN7.js.map} +0 -0
  173. /package/dist/{tokens-3BWDESVM.js.map → tokens-IXSQHPQK.js.map} +0 -0
package/src/build.ts CHANGED
@@ -2,20 +2,20 @@ import { readFile, writeFile, mkdir } from "node:fs/promises";
2
2
  import { resolve, join } from "node:path";
3
3
  import { existsSync } from "node:fs";
4
4
  import type {
5
- SegmentsConfig,
6
- CompiledSegmentsFile,
7
- CompiledSegment,
5
+ FragmentsConfig,
6
+ CompiledFragmentsFile,
7
+ CompiledFragment,
8
8
  CompiledBlock,
9
9
  CompiledTokenData,
10
10
  } from "./core/index.js";
11
11
  import { BRAND, compileBlock, parseTokenFile } from "./core/index.js";
12
12
  import type { BlockDefinition } from "./core/index.js";
13
13
  import {
14
- discoverSegmentFiles,
14
+ discoverFragmentFiles,
15
15
  discoverBlockFiles,
16
16
  discoverTokenFiles,
17
- parseSegmentFile,
18
- loadSegmentFile,
17
+ parseFragmentFile,
18
+ loadFragmentFile,
19
19
  generateRegistry,
20
20
  generateContextMd,
21
21
  } from "./core/node.js";
@@ -27,7 +27,7 @@ import {
27
27
  import { buildComponentGraph } from "./core/graph-extractor.js";
28
28
  import { serializeGraph } from "@fragments-sdk/context/graph";
29
29
 
30
- type CompiledProp = CompiledSegment["props"][string];
30
+ type CompiledProp = CompiledFragment["props"][string];
31
31
 
32
32
  function normalizeParsedProps(
33
33
  parsedProps: Record<string, Partial<CompiledProp>>
@@ -74,7 +74,7 @@ function mergeDocumentedAndAutoProps(
74
74
  export interface BuildResult {
75
75
  success: boolean;
76
76
  outputPath: string;
77
- segmentCount: number;
77
+ fragmentCount: number;
78
78
  errors: Array<{ file: string; error: string }>;
79
79
  warnings: Array<{ file: string; warning: string }>;
80
80
  }
@@ -85,14 +85,14 @@ export interface BuildResult {
85
85
  * Uses AST parsing to extract metadata WITHOUT executing fragment files.
86
86
  * This means the build works without any project dependencies installed.
87
87
  */
88
- export async function buildSegments(
89
- config: SegmentsConfig,
88
+ export async function buildFragments(
89
+ config: FragmentsConfig,
90
90
  configDir: string
91
91
  ): Promise<BuildResult> {
92
- const files = await discoverSegmentFiles(config, configDir);
92
+ const files = await discoverFragmentFiles(config, configDir);
93
93
  const errors: Array<{ file: string; error: string }> = [];
94
94
  const warnings: Array<{ file: string; warning: string }> = [];
95
- const segments: CompiledSegmentsFile["segments"] = {};
95
+ const fragments: CompiledFragmentsFile["fragments"] = {};
96
96
 
97
97
  for (const file of files) {
98
98
  try {
@@ -100,7 +100,7 @@ export async function buildSegments(
100
100
  const content = await readFile(file.absolutePath, "utf-8");
101
101
 
102
102
  // Parse using AST (no execution)
103
- const parsed = parseSegmentFile(content, file.relativePath);
103
+ const parsed = parseFragmentFile(content, file.relativePath);
104
104
 
105
105
  // Collect warnings
106
106
  for (const warning of parsed.warnings) {
@@ -171,7 +171,7 @@ export async function buildSegments(
171
171
  }
172
172
 
173
173
  // Build compiled fragment from parsed metadata
174
- const compiled: CompiledSegment = {
174
+ const compiled: CompiledFragment = {
175
175
  filePath: file.relativePath,
176
176
  meta: {
177
177
  name: parsed.meta.name,
@@ -208,9 +208,11 @@ export async function buildSegments(
208
208
  })),
209
209
  // Include AI metadata if present
210
210
  ...(parsed.ai && { ai: parsed.ai }),
211
+ // Include contract metadata if present
212
+ ...(parsed.contract && { contract: parsed.contract }),
211
213
  };
212
214
 
213
- segments[parsed.meta.name] = compiled;
215
+ fragments[parsed.meta.name] = compiled;
214
216
  } catch (error) {
215
217
  errors.push({
216
218
  file: file.relativePath,
@@ -225,9 +227,9 @@ export async function buildSegments(
225
227
  const blockFiles = await discoverBlockFiles(configDir, config.exclude);
226
228
  for (const file of blockFiles) {
227
229
  try {
228
- // loadSegmentFile uses esbuild to bundle+evaluate, returns default export
230
+ // loadFragmentFile uses esbuild to bundle+evaluate, returns default export
229
231
  // CJS/ESM interop may double-wrap the default export
230
- let raw = await loadSegmentFile(file.absolutePath) as unknown as Record<string, unknown> | null;
232
+ let raw = await loadFragmentFile(file.absolutePath) as unknown as Record<string, unknown> | null;
231
233
  // Unwrap double-default from CJS interop
232
234
  if (raw && 'default' in raw && typeof raw.default === 'object') {
233
235
  raw = raw.default as Record<string, unknown>;
@@ -255,7 +257,7 @@ export async function buildSegments(
255
257
  const tokenFiles = await discoverTokenFiles(configDir, tokenPatterns, config.exclude);
256
258
  if (tokenFiles.length > 0) {
257
259
  // Merge tokens from all discovered files
258
- const mergedCategories: Record<string, Array<{ name: string; description?: string }>> = {};
260
+ const mergedCategories: Record<string, Array<{ name: string; value?: string; description?: string }>> = {};
259
261
  let prefix = '--';
260
262
  let total = 0;
261
263
 
@@ -271,7 +273,7 @@ export async function buildSegments(
271
273
  for (const t of catTokens) {
272
274
  // Deduplicate by name
273
275
  if (!mergedCategories[cat].some((e) => e.name === t.name)) {
274
- mergedCategories[cat].push({ name: t.name, description: t.description });
276
+ mergedCategories[cat].push({ name: t.name, ...(t.value && { value: t.value }), description: t.description });
275
277
  }
276
278
  }
277
279
  }
@@ -302,25 +304,25 @@ export async function buildSegments(
302
304
  const componentDir = resolve(configDir, "src", "components");
303
305
  let graphData: ReturnType<typeof serializeGraph> | undefined;
304
306
  try {
305
- const graphResult = await buildComponentGraph(segments, blocks, componentDir);
307
+ const graphResult = await buildComponentGraph(fragments, blocks, componentDir);
306
308
 
307
- // Auto-enrich segments with detected metadata
308
- for (const [name, segment] of Object.entries(segments)) {
309
+ // Auto-enrich fragments with detected metadata
310
+ for (const [name, fragment] of Object.entries(fragments)) {
309
311
  const detected = graphResult.autoDetected.get(name);
310
312
  if (!detected) continue;
311
313
 
312
- if (!segment.ai) segment.ai = {};
313
- if (!segment.ai.subComponents && detected.subComponents) {
314
- segment.ai.subComponents = detected.subComponents;
314
+ if (!fragment.ai) fragment.ai = {};
315
+ if (!fragment.ai.subComponents && detected.subComponents) {
316
+ fragment.ai.subComponents = detected.subComponents;
315
317
  }
316
- if (!segment.ai.compositionPattern && detected.compositionPattern) {
317
- segment.ai.compositionPattern = detected.compositionPattern;
318
+ if (!fragment.ai.compositionPattern && detected.compositionPattern) {
319
+ fragment.ai.compositionPattern = detected.compositionPattern;
318
320
  }
319
- if (!segment.ai.commonPatterns && detected.commonPatterns) {
320
- segment.ai.commonPatterns = detected.commonPatterns;
321
+ if (!fragment.ai.commonPatterns && detected.commonPatterns) {
322
+ fragment.ai.commonPatterns = detected.commonPatterns;
321
323
  }
322
- if (!segment.ai.requiredChildren && detected.requiredChildren) {
323
- segment.ai.requiredChildren = detected.requiredChildren;
324
+ if (!fragment.ai.requiredChildren && detected.requiredChildren) {
325
+ fragment.ai.requiredChildren = detected.requiredChildren;
324
326
  }
325
327
  }
326
328
 
@@ -337,11 +339,11 @@ export async function buildSegments(
337
339
  });
338
340
  }
339
341
 
340
- const output: CompiledSegmentsFile = {
342
+ const output: CompiledFragmentsFile = {
341
343
  version: "1.0.0",
342
344
  generatedAt: new Date().toISOString(),
343
345
  ...(packageName && { packageName }),
344
- segments,
346
+ fragments,
345
347
  ...(Object.keys(blocks).length > 0 && { blocks }),
346
348
  ...(tokens && { tokens }),
347
349
  ...(graphData && { graph: graphData }),
@@ -353,7 +355,7 @@ export async function buildSegments(
353
355
  return {
354
356
  success: errors.length === 0,
355
357
  outputPath,
356
- segmentCount: Object.keys(segments).length,
358
+ fragmentCount: Object.keys(fragments).length,
357
359
  errors,
358
360
  warnings,
359
361
  };
@@ -381,7 +383,7 @@ export interface FragmentsBuildResult {
381
383
  * - .fragments/context.md - AI-ready consolidated context file
382
384
  */
383
385
  export async function buildFragmentsDir(
384
- config: SegmentsConfig,
386
+ config: FragmentsConfig,
385
387
  configDir: string
386
388
  ): Promise<FragmentsBuildResult> {
387
389
  const fragmentsDir = join(configDir, BRAND.dataDir);
@@ -229,10 +229,10 @@ export async function a11y(options: A11yOptions = {}): Promise<A11ySummary> {
229
229
  );
230
230
  }
231
231
 
232
- // Fetch all segments
233
- const segments = await client.getSegments();
232
+ // Fetch all fragments
233
+ const fragments = await client.getFragments();
234
234
 
235
- if (segments.length === 0) {
235
+ if (fragments.length === 0) {
236
236
  if (isJsonOutput) {
237
237
  console.log(JSON.stringify({ error: 'No fragments found', components: [] }));
238
238
  } else {
@@ -254,11 +254,11 @@ export async function a11y(options: A11yOptions = {}): Promise<A11ySummary> {
254
254
 
255
255
  // Filter to specific component if requested
256
256
  const componentsToCheck = component
257
- ? segments.filter(s => s.name.toLowerCase() === component.toLowerCase())
258
- : segments;
257
+ ? fragments.filter(s => s.name.toLowerCase() === component.toLowerCase())
258
+ : fragments;
259
259
 
260
260
  if (component && componentsToCheck.length === 0) {
261
- const error = `Component '${component}' not found. Available: ${segments.map(s => s.name).join(', ')}`;
261
+ const error = `Component '${component}' not found. Available: ${fragments.map(s => s.name).join(', ')}`;
262
262
  if (isJsonOutput) {
263
263
  console.log(JSON.stringify({ error }));
264
264
  } else {
@@ -27,7 +27,7 @@ export interface AddOptions {
27
27
  export interface AddResult {
28
28
  success: boolean;
29
29
  componentPath?: string;
30
- segmentPath: string;
30
+ fragmentPath: string;
31
31
  indexPath?: string;
32
32
  }
33
33
 
@@ -110,7 +110,7 @@ export async function add(
110
110
  // Determine output paths
111
111
  const componentDir = resolve(process.cwd(), dir, componentName);
112
112
  const componentFile = join(componentDir, `${componentName}.tsx`);
113
- const segmentFile = join(componentDir, `${componentName}${BRAND.fileExtension}`);
113
+ const fragmentFile = join(componentDir, `${componentName}${BRAND.fileExtension}`);
114
114
  const indexFile = join(componentDir, 'index.ts');
115
115
 
116
116
  // Check if directory already exists
@@ -133,10 +133,10 @@ export async function add(
133
133
  console.log(`${pc.green('✓')} Created ${relative(process.cwd(), componentFile)}`);
134
134
  }
135
135
 
136
- // Generate segment file
137
- const segmentCode = generateSegmentStub(componentName, category, template);
138
- await writeFile(segmentFile, segmentCode);
139
- console.log(`${pc.green('✓')} Created ${relative(process.cwd(), segmentFile)}`);
136
+ // Generate fragment file
137
+ const fragmentCode = generateFragmentStub(componentName, category, template);
138
+ await writeFile(fragmentFile, fragmentCode);
139
+ console.log(`${pc.green('✓')} Created ${relative(process.cwd(), fragmentFile)}`);
140
140
 
141
141
  // Generate index.ts
142
142
  const indexCode = `export { ${componentName} } from './${componentName}.js';\n`;
@@ -159,7 +159,7 @@ export async function add(
159
159
  return {
160
160
  success: true,
161
161
  componentPath: generateComponent ? componentFile : undefined,
162
- segmentPath: segmentFile,
162
+ fragmentPath: fragmentFile,
163
163
  indexPath: indexFile,
164
164
  };
165
165
  }
@@ -195,9 +195,9 @@ export function ${name}({ children, className }: ${name}Props) {
195
195
  }
196
196
 
197
197
  /**
198
- * Generate a segment stub based on template type.
198
+ * Generate a fragment stub based on template type.
199
199
  */
200
- function generateSegmentStub(name: string, category: string, template: string): string {
200
+ function generateFragmentStub(name: string, category: string, template: string): string {
201
201
  // Template-specific usage hints
202
202
  const usageHints: Record<string, { when: string[]; whenNot: string[] }> = {
203
203
  action: {
@@ -231,10 +231,10 @@ function generateSegmentStub(name: string, category: string, template: string):
231
231
  const scenarioTags = scenarioTagHints[template] || scenarioTagHints.display;
232
232
 
233
233
  return `import React from 'react';
234
- import { defineSegment } from '@fragments/core';
234
+ import { defineFragment } from '@fragments/core';
235
235
  import { ${name} } from './index.js';
236
236
 
237
- export default defineSegment({
237
+ export default defineFragment({
238
238
  component: ${name},
239
239
 
240
240
  meta: {
@@ -69,9 +69,9 @@ export async function audit(options: AuditOptions = {}): Promise<AuditSummary> {
69
69
  }
70
70
 
71
71
  // Fetch all fragments
72
- const segments = await client.getSegments();
72
+ const fragments = await client.getFragments();
73
73
 
74
- if (segments.length === 0) {
74
+ if (fragments.length === 0) {
75
75
  if (json) {
76
76
  console.log(JSON.stringify({ error: 'No fragments found', components: [] }));
77
77
  } else {
@@ -91,11 +91,11 @@ export async function audit(options: AuditOptions = {}): Promise<AuditSummary> {
91
91
  }
92
92
 
93
93
  if (!json) {
94
- console.log(pc.dim(`Auditing ${segments.length} component(s)...\n`));
94
+ console.log(pc.dim(`Auditing ${fragments.length} component(s)...\n`));
95
95
  }
96
96
 
97
97
  // Audit each fragment
98
- for (const seg of segments) {
98
+ for (const seg of fragments) {
99
99
  try {
100
100
  // Get real compliance from the server
101
101
  const complianceResult = await client.getCompliance({
@@ -98,16 +98,16 @@ async function updateBaseline(
98
98
  }
99
99
 
100
100
  const contextData = JSON.parse(await contextResp.text());
101
- const segments = contextData.components || [];
101
+ const fragments = contextData.components || [];
102
102
 
103
- if (segments.length === 0) {
103
+ if (fragments.length === 0) {
104
104
  console.log(pc.yellow('No components found.\n'));
105
105
  return { success: true, action: 'update', count: 0 };
106
106
  }
107
107
 
108
108
  component = await select({
109
109
  message: 'Select component to update:',
110
- choices: segments.map((s: { name: string }) => ({
110
+ choices: fragments.map((s: { name: string }) => ({
111
111
  name: s.name,
112
112
  value: s.name,
113
113
  })),
@@ -5,7 +5,7 @@
5
5
  import pc from 'picocolors';
6
6
  import { BRAND } from '../core/index.js';
7
7
  import { loadConfig } from '../core/node.js';
8
- import { buildSegments, buildFragmentsDir } from '../build.js';
8
+ import { buildFragments, buildFragmentsDir } from '../build.js';
9
9
  import { scan } from './scan.js';
10
10
 
11
11
  /**
@@ -35,7 +35,7 @@ export interface BuildOptions {
35
35
  */
36
36
  export interface BuildResult {
37
37
  success: boolean;
38
- segmentCount?: number;
38
+ fragmentCount?: number;
39
39
  outputPath?: string;
40
40
  componentCount?: number;
41
41
  registryPath?: string;
@@ -65,7 +65,7 @@ export async function build(options: BuildOptions = {}): Promise<BuildResult> {
65
65
 
66
66
  return {
67
67
  success: scanResult.success,
68
- segmentCount: scanResult.componentCount,
68
+ fragmentCount: scanResult.componentCount,
69
69
  outputPath: scanResult.outputPath,
70
70
  errors: scanResult.errors.map((e) => ({ file: e.component, error: e.error })),
71
71
  };
@@ -80,7 +80,7 @@ export async function build(options: BuildOptions = {}): Promise<BuildResult> {
80
80
  console.log(pc.cyan(`\n${BRAND.name} Build\n`));
81
81
 
82
82
  const errors: Array<{ file: string; error: string }> = [];
83
- let segmentCount: number | undefined;
83
+ let fragmentCount: number | undefined;
84
84
  let outputPath: string | undefined;
85
85
  let componentCount: number | undefined;
86
86
  let registryPath: string | undefined;
@@ -90,7 +90,7 @@ export async function build(options: BuildOptions = {}): Promise<BuildResult> {
90
90
  if (!options.registryOnly) {
91
91
  console.log(pc.dim('Compiling fragments...\n'));
92
92
 
93
- const result = await buildSegments(config, configDir);
93
+ const result = await buildFragments(config, configDir);
94
94
 
95
95
  if (result.errors.length > 0) {
96
96
  console.log(pc.yellow('Build completed with errors:\n'));
@@ -109,10 +109,10 @@ export async function build(options: BuildOptions = {}): Promise<BuildResult> {
109
109
  console.log();
110
110
  }
111
111
 
112
- segmentCount = result.segmentCount;
112
+ fragmentCount = result.fragmentCount;
113
113
  outputPath = result.outputPath;
114
114
 
115
- console.log(pc.green(`✓ Built ${result.segmentCount} fragment(s)`));
115
+ console.log(pc.green(`✓ Built ${result.fragmentCount} fragment(s)`));
116
116
  console.log(pc.dim(` Output: ${result.outputPath}\n`));
117
117
  }
118
118
 
@@ -150,7 +150,7 @@ export async function build(options: BuildOptions = {}): Promise<BuildResult> {
150
150
 
151
151
  return {
152
152
  success: errors.length === 0,
153
- segmentCount,
153
+ fragmentCount,
154
154
  outputPath,
155
155
  componentCount,
156
156
  registryPath,
@@ -15,7 +15,7 @@ export interface CompareOptions {
15
15
  config?: string;
16
16
  /** Compare specific variant */
17
17
  variant?: string;
18
- /** Figma frame URL (uses segment figma link if not provided) */
18
+ /** Figma frame URL (uses fragment figma link if not provided) */
19
19
  figma?: string;
20
20
  /** Diff threshold percentage */
21
21
  threshold?: number;
@@ -112,7 +112,7 @@ export async function compare(
112
112
  let failed = 0;
113
113
 
114
114
  for (const comp of componentsToCompare) {
115
- const response = await fetch(`${baseUrl}/segments/compare`, {
115
+ const response = await fetch(`${baseUrl}/fragments/compare`, {
116
116
  method: 'POST',
117
117
  headers: { 'Content-Type': 'application/json' },
118
118
  body: JSON.stringify({
@@ -177,24 +177,24 @@ async function compareAll(
177
177
  ): Promise<CompareCommandResult> {
178
178
  console.log(pc.dim('Comparing all components with Figma links...\n'));
179
179
 
180
- // Fetch the context to get all segments
181
- const contextResp = await fetch(`${baseUrl}/segments/context?format=json`);
180
+ // Fetch the context to get all fragments
181
+ const contextResp = await fetch(`${baseUrl}/fragments/context?format=json`);
182
182
  if (!contextResp.ok) {
183
- throw new Error('Failed to fetch segments. Make sure dev server is running.');
183
+ throw new Error('Failed to fetch fragments. Make sure dev server is running.');
184
184
  }
185
185
 
186
186
  const contextText = await contextResp.text();
187
- let segments: Array<{ name: string; figma?: string }> = [];
187
+ let fragments: Array<{ name: string; figma?: string }> = [];
188
188
  try {
189
189
  const contextData = JSON.parse(contextText);
190
- segments = contextData.components || [];
190
+ fragments = contextData.components || [];
191
191
  } catch {
192
- segments = [];
192
+ fragments = [];
193
193
  }
194
194
 
195
- if (segments.length === 0) {
195
+ if (fragments.length === 0) {
196
196
  console.log(pc.yellow('No components found with Figma links.'));
197
- console.log(pc.dim('Add figma field to your segment definitions:'));
197
+ console.log(pc.dim('Add figma field to your fragment definitions:'));
198
198
  console.log(pc.dim(' meta: { figma: "https://figma.com/file/..." }'));
199
199
  return { success: true, passed: 0, failed: 0, skipped: 0 };
200
200
  }
@@ -203,7 +203,7 @@ async function compareAll(
203
203
  let failed = 0;
204
204
  let skipped = 0;
205
205
 
206
- for (const seg of segments) {
206
+ for (const seg of fragments) {
207
207
  // Skip components without figma links
208
208
  if (!seg.figma) {
209
209
  skipped++;
@@ -212,7 +212,7 @@ async function compareAll(
212
212
  }
213
213
 
214
214
  try {
215
- const response = await fetch(`${baseUrl}/segments/compare`, {
215
+ const response = await fetch(`${baseUrl}/fragments/compare`, {
216
216
  method: 'POST',
217
217
  headers: { 'Content-Type': 'application/json' },
218
218
  body: JSON.stringify({
@@ -267,23 +267,23 @@ async function compareAll(
267
267
  async function selectComponents(baseUrl: string): Promise<string[]> {
268
268
  console.log(pc.dim('Fetching components with Figma links...\n'));
269
269
 
270
- const contextResp = await fetch(`${baseUrl}/segments/context?format=json`);
270
+ const contextResp = await fetch(`${baseUrl}/fragments/context?format=json`);
271
271
  if (!contextResp.ok) {
272
- throw new Error('Failed to fetch segments. Make sure dev server is running.');
272
+ throw new Error('Failed to fetch fragments. Make sure dev server is running.');
273
273
  }
274
274
 
275
275
  const contextText = await contextResp.text();
276
- let segments: Array<{ name: string; figma?: string }> = [];
276
+ let fragments: Array<{ name: string; figma?: string }> = [];
277
277
  try {
278
278
  const contextData = JSON.parse(contextText);
279
- segments = (contextData.components || []).filter((s: { figma?: string }) => s.figma);
279
+ fragments = (contextData.components || []).filter((s: { figma?: string }) => s.figma);
280
280
  } catch {
281
- segments = [];
281
+ fragments = [];
282
282
  }
283
283
 
284
- if (segments.length === 0) {
284
+ if (fragments.length === 0) {
285
285
  console.log(pc.yellow('No components found with Figma links.'));
286
- console.log(pc.dim('Add figma field to your segment definitions:'));
286
+ console.log(pc.dim('Add figma field to your fragment definitions:'));
287
287
  console.log(pc.dim(' meta: { figma: "https://figma.com/file/..." }'));
288
288
  return [];
289
289
  }
@@ -291,7 +291,7 @@ async function selectComponents(baseUrl: string): Promise<string[]> {
291
291
  const { checkbox } = await import('@inquirer/prompts');
292
292
 
293
293
  try {
294
- const choices = segments.map((seg) => ({
294
+ const choices = fragments.map((seg) => ({
295
295
  name: seg.name,
296
296
  value: seg.name,
297
297
  checked: true,
@@ -6,9 +6,9 @@ import { readFile } from 'node:fs/promises';
6
6
  import { resolve } from 'node:path';
7
7
  import pc from 'picocolors';
8
8
  import { generateContext } from '../core/index.js';
9
- import type { CompiledSegment, CompiledSegmentsFile } from '../core/index.js';
9
+ import type { CompiledFragment, CompiledFragmentsFile } from '../core/index.js';
10
10
  import { loadConfig } from '../core/node.js';
11
- import { buildSegments } from '../build.js';
11
+ import { buildFragments } from '../build.js';
12
12
 
13
13
  /**
14
14
  * Options for context command
@@ -16,7 +16,7 @@ import { buildSegments } from '../build.js';
16
16
  export interface ContextOptions {
17
17
  /** Path to config file */
18
18
  config?: string;
19
- /** Path to segments.json (builds if not provided) */
19
+ /** Path to fragments.json (builds if not provided) */
20
20
  input?: string;
21
21
  /** Output format (markdown/json) */
22
22
  format?: 'markdown' | 'json';
@@ -51,36 +51,36 @@ export async function context(options: ContextOptions = {}): Promise<ContextResu
51
51
  tokensOnly = false,
52
52
  } = options;
53
53
 
54
- let segments: CompiledSegment[];
54
+ let fragments: CompiledFragment[];
55
55
 
56
56
  if (options.input) {
57
- // Read from existing segments.json
57
+ // Read from existing fragments.json
58
58
  const inputPath = resolve(process.cwd(), options.input);
59
59
  const content = await readFile(inputPath, 'utf-8');
60
- const data: CompiledSegmentsFile = JSON.parse(content);
61
- segments = Object.values(data.segments);
60
+ const data: CompiledFragmentsFile = JSON.parse(content);
61
+ fragments = Object.values(data.fragments);
62
62
  } else {
63
- // Build segments on the fly
63
+ // Build fragments on the fly
64
64
  const { config, configDir } = await loadConfig(options.config);
65
- const result = await buildSegments(config, configDir);
65
+ const result = await buildFragments(config, configDir);
66
66
 
67
- if (result.errors.length > 0 && result.segmentCount === 0) {
68
- console.error(pc.red('Error: No segments found. Run `segments build` first or fix errors.'));
67
+ if (result.errors.length > 0 && result.fragmentCount === 0) {
68
+ console.error(pc.red('Error: No fragments found. Run `fragments build` first or fix errors.'));
69
69
  return { success: false, tokenEstimate: 0 };
70
70
  }
71
71
 
72
72
  // Read the generated file
73
73
  const content = await readFile(result.outputPath, 'utf-8');
74
- const data: CompiledSegmentsFile = JSON.parse(content);
75
- segments = Object.values(data.segments);
74
+ const data: CompiledFragmentsFile = JSON.parse(content);
75
+ fragments = Object.values(data.fragments);
76
76
  }
77
77
 
78
- if (segments.length === 0) {
79
- console.error(pc.red('No segments found.'));
78
+ if (fragments.length === 0) {
79
+ console.error(pc.red('No fragments found.'));
80
80
  return { success: false, tokenEstimate: 0 };
81
81
  }
82
82
 
83
- const { content, tokenEstimate } = generateContext(segments, {
83
+ const { content, tokenEstimate } = generateContext(fragments, {
84
84
  format,
85
85
  compact,
86
86
  include: {