@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
@@ -71,9 +71,9 @@ export interface EnhanceOptions {
71
71
  }
72
72
 
73
73
  /**
74
- * Enhanced segment data
74
+ * Enhanced fragment data
75
75
  */
76
- export interface EnhancedSegment {
76
+ export interface EnhancedFragment {
77
77
  componentName: string;
78
78
  added: {
79
79
  when: string[];
@@ -90,7 +90,7 @@ export interface EnhancedSegment {
90
90
  */
91
91
  export interface EnhanceResult {
92
92
  success: boolean;
93
- enhanced: EnhancedSegment[];
93
+ enhanced: EnhancedFragment[];
94
94
  totalTokens: number;
95
95
  estimatedCost: number;
96
96
  /** Context output for IDE AI mode */
@@ -211,9 +211,9 @@ export async function enhance(options: EnhanceOptions = {}): Promise<EnhanceResu
211
211
  }
212
212
 
213
213
  // Search entire root dir, not just src/
214
- const segmentFiles = await findSegmentFiles(rootDir);
214
+ const fragmentFiles = await findFragmentFiles(rootDir);
215
215
 
216
- if (segmentFiles.length === 0) {
216
+ if (fragmentFiles.length === 0) {
217
217
  const msg = 'No fragment files found';
218
218
  if (format === 'json') {
219
219
  console.log(JSON.stringify({ success: false, error: msg }));
@@ -224,7 +224,7 @@ export async function enhance(options: EnhanceOptions = {}): Promise<EnhanceResu
224
224
  }
225
225
 
226
226
  if (isInteractive) {
227
- console.log(pc.green(` Found ${segmentFiles.length} fragment files`));
227
+ console.log(pc.green(` Found ${fragmentFiles.length} fragment files`));
228
228
  }
229
229
 
230
230
  // Filter components if specified
@@ -232,7 +232,7 @@ export async function enhance(options: EnhanceOptions = {}): Promise<EnhanceResu
232
232
  if (component && component !== 'all') {
233
233
  componentsToEnhance = [component];
234
234
  } else {
235
- componentsToEnhance = segmentFiles.map(f => extractComponentName(f));
235
+ componentsToEnhance = fragmentFiles.map(f => extractComponentName(f));
236
236
  }
237
237
 
238
238
  // Phase 4: Extract props from TypeScript source files
@@ -242,16 +242,16 @@ export async function enhance(options: EnhanceOptions = {}): Promise<EnhanceResu
242
242
 
243
243
  const propsExtractions = new Map<string, PropsExtractionResult>();
244
244
  for (const compName of componentsToEnhance) {
245
- const segmentFile = segmentFiles.find(f => extractComponentName(f) === compName);
246
- if (!segmentFile) continue;
245
+ const fragmentFile = fragmentFiles.find(f => extractComponentName(f) === compName);
246
+ if (!fragmentFile) continue;
247
247
 
248
- // Try to find the component source file relative to the segment file
249
- const segmentDir = segmentFile.replace(/\.segment\.(tsx?|jsx?)$/, '');
248
+ // Try to find the component source file relative to the fragment file
249
+ const fragmentDir = fragmentFile.replace(/\.fragment\.(tsx?|jsx?)$/, '');
250
250
  const possiblePaths = [
251
- `${segmentDir}.tsx`,
252
- `${segmentDir}.ts`,
253
- `${segmentDir}/index.tsx`,
254
- `${segmentDir}/index.ts`,
251
+ `${fragmentDir}.tsx`,
252
+ `${fragmentDir}.ts`,
253
+ `${fragmentDir}/index.tsx`,
254
+ `${fragmentDir}/index.ts`,
255
255
  join(rootDir, 'src', 'components', `${compName}.tsx`),
256
256
  join(rootDir, 'src', 'components', compName, `${compName}.tsx`),
257
257
  join(rootDir, 'src', 'components', compName, 'index.tsx'),
@@ -332,14 +332,14 @@ export async function enhance(options: EnhanceOptions = {}): Promise<EnhanceResu
332
332
  }
333
333
 
334
334
  // Build contexts for all components
335
- const contexts: Array<{ name: string; context: ComponentContext; segmentFile: string }> = [];
335
+ const contexts: Array<{ name: string; context: ComponentContext; fragmentFile: string }> = [];
336
336
  for (const compName of componentsToEnhance) {
337
337
  const analysis = usageAnalysis.components[compName];
338
338
  const stories = storyFiles.get(compName);
339
- const segmentFile = segmentFiles.find(f => extractComponentName(f) === compName);
339
+ const fragmentFile = fragmentFiles.find(f => extractComponentName(f) === compName);
340
340
  const propsExtraction = propsExtractions.get(compName);
341
341
 
342
- if (!segmentFile) continue;
342
+ if (!fragmentFile) continue;
343
343
 
344
344
  const context = generateComponentContext(
345
345
  compName,
@@ -348,7 +348,7 @@ export async function enhance(options: EnhanceOptions = {}): Promise<EnhanceResu
348
348
  stories,
349
349
  propsExtraction
350
350
  );
351
- contexts.push({ name: compName, context, segmentFile });
351
+ contexts.push({ name: compName, context, fragmentFile });
352
352
  }
353
353
 
354
354
  // Context-only mode: output prompts for IDE AI
@@ -361,13 +361,13 @@ export async function enhance(options: EnhanceOptions = {}): Promise<EnhanceResu
361
361
  console.log(pc.dim(`\nPhase 6: Generating AI enhancements for ${componentsToEnhance.length} component(s)...\n`));
362
362
  }
363
363
 
364
- const enhanced: EnhancedSegment[] = [];
364
+ const enhanced: EnhancedFragment[] = [];
365
365
  let totalTokens = 0;
366
366
 
367
367
  // Initialize AI client
368
368
  const aiClient = await createAIClient(provider, apiKey!);
369
369
 
370
- for (const { name: compName, context, segmentFile } of contexts) {
370
+ for (const { name: compName, context, fragmentFile } of contexts) {
371
371
  // Check if we have enough data
372
372
  if (!context.usageAnalysis || context.usageAnalysis.totalUsages < 2) {
373
373
  enhanced.push({
@@ -426,7 +426,7 @@ export async function enhance(options: EnhanceOptions = {}): Promise<EnhanceResu
426
426
  // Phase 7: Apply changes
427
427
  if (!dryRun) {
428
428
  if (isInteractive) {
429
- console.log(pc.dim('\nPhase 7: Updating segment files...'));
429
+ console.log(pc.dim('\nPhase 7: Updating fragment files...'));
430
430
  }
431
431
 
432
432
  for (const result of enhanced) {
@@ -434,17 +434,17 @@ export async function enhance(options: EnhanceOptions = {}): Promise<EnhanceResu
434
434
  continue;
435
435
  }
436
436
 
437
- const segmentFile = segmentFiles.find(f => extractComponentName(f) === result.componentName);
438
- if (!segmentFile) continue;
437
+ const fragmentFile = fragmentFiles.find(f => extractComponentName(f) === result.componentName);
438
+ if (!fragmentFile) continue;
439
439
 
440
440
  try {
441
- await updateSegmentFile(segmentFile, result.added);
441
+ await updateFragmentFile(fragmentFile, result.added);
442
442
  if (isInteractive) {
443
- console.log(pc.green(` Updated: ${relative(rootDir, segmentFile)}`));
443
+ console.log(pc.green(` Updated: ${relative(rootDir, fragmentFile)}`));
444
444
  }
445
445
  } catch {
446
446
  if (isInteractive) {
447
- console.log(pc.red(` Failed to update: ${relative(rootDir, segmentFile)}`));
447
+ console.log(pc.red(` Failed to update: ${relative(rootDir, fragmentFile)}`));
448
448
  }
449
449
  }
450
450
  }
@@ -488,7 +488,7 @@ export async function enhance(options: EnhanceOptions = {}): Promise<EnhanceResu
488
488
  * Handle context-only mode for IDE AI
489
489
  */
490
490
  function handleContextOnlyMode(
491
- contexts: Array<{ name: string; context: ComponentContext; segmentFile: string }>,
491
+ contexts: Array<{ name: string; context: ComponentContext; fragmentFile: string }>,
492
492
  format: string,
493
493
  isInteractive: boolean
494
494
  ): EnhanceResult {
@@ -544,7 +544,7 @@ For each component, provide your response in JSON format:
544
544
  console.log(pc.dim('─'.repeat(60)));
545
545
  console.log();
546
546
  console.log(pc.green('Tip: In Cursor, press Cmd+L to open chat and paste this prompt.'));
547
- console.log(pc.dim('After getting suggestions, manually update your segment files.'));
547
+ console.log(pc.dim('After getting suggestions, manually update your fragment files.'));
548
548
  console.log();
549
549
  }
550
550
 
@@ -783,11 +783,11 @@ function calculateCost(provider: AIProvider, tokens: number): number {
783
783
  }
784
784
 
785
785
  /**
786
- * Find all segment files in a directory
786
+ * Find all fragment files in a directory
787
787
  */
788
- async function findSegmentFiles(dir: string): Promise<string[]> {
788
+ async function findFragmentFiles(dir: string): Promise<string[]> {
789
789
  const fg = await import('fast-glob');
790
- return fg.default(['**/*.segment.tsx', '**/*.segment.ts'], {
790
+ return fg.default(['**/*.fragment.tsx', '**/*.fragment.ts'], {
791
791
  cwd: dir,
792
792
  absolute: true,
793
793
  ignore: ['**/node_modules/**', '**/dist/**'],
@@ -795,17 +795,17 @@ async function findSegmentFiles(dir: string): Promise<string[]> {
795
795
  }
796
796
 
797
797
  /**
798
- * Extract component name from segment file path
798
+ * Extract component name from fragment file path
799
799
  */
800
800
  function extractComponentName(filePath: string): string {
801
- const match = filePath.match(/([^/\\]+)\.segment\.(tsx?|jsx?)$/);
801
+ const match = filePath.match(/([^/\\]+)\.fragment\.(tsx?|jsx?)$/);
802
802
  return match ? match[1] : '';
803
803
  }
804
804
 
805
805
  /**
806
- * Update a segment file with new when/whenNot suggestions
806
+ * Update a fragment file with new when/whenNot suggestions
807
807
  */
808
- async function updateSegmentFile(
808
+ async function updateFragmentFile(
809
809
  filePath: string,
810
810
  suggestions: { when: string[]; whenNot: string[] }
811
811
  ): Promise<void> {
@@ -57,7 +57,7 @@ export async function generate(options: GenerateOptions = {}): Promise<GenerateR
57
57
  ignore: [
58
58
  "**/node_modules/**",
59
59
  "**/*.stories.*",
60
- "**/*.segment.*",
60
+ "**/*.fragment.*",
61
61
  "**/*.test.*",
62
62
  "**/*.spec.*",
63
63
  "**/*.d.ts",
@@ -8,7 +8,7 @@
8
8
  import pc from 'picocolors';
9
9
  import { readFile } from 'node:fs/promises';
10
10
  import { resolve } from 'node:path';
11
- import type { CompiledSegmentsFile } from '../core/index.js';
11
+ import type { CompiledFragmentsFile } from '../core/index.js';
12
12
  import { BRAND } from '../core/index.js';
13
13
  import { loadConfig } from '../core/node.js';
14
14
  import {
@@ -33,10 +33,10 @@ export async function graph(
33
33
  const { config, configDir } = await loadConfig(options.config);
34
34
  const outputPath = resolve(configDir, config.outFile ?? BRAND.outFile);
35
35
 
36
- let data: CompiledSegmentsFile;
36
+ let data: CompiledFragmentsFile;
37
37
  try {
38
38
  const content = await readFile(outputPath, 'utf-8');
39
- data = JSON.parse(content) as CompiledSegmentsFile;
39
+ data = JSON.parse(content) as CompiledFragmentsFile;
40
40
  } catch {
41
41
  console.error(
42
42
  pc.red(`Error: Could not load ${BRAND.outFile}. Run \`${BRAND.cliCommand} build\` first.`),
@@ -205,8 +205,8 @@ export async function graph(
205
205
  if (tree.subComponents.length > 0) {
206
206
  console.log(` ${pc.cyan('Sub-components:')}`);
207
207
  for (const sub of tree.subComponents) {
208
- const isRequired = tree.requiredChildren.includes(sub);
209
- console.log(` ${pc.yellow(sub)}${isRequired ? pc.red(' (required)') : ''}`);
208
+ const isChild = tree.children.includes(sub);
209
+ console.log(` ${pc.yellow(sub)}${isChild ? pc.dim(' (child)') : ''}`);
210
210
  }
211
211
  }
212
212
  if (tree.siblings.length > 0) {
@@ -428,7 +428,7 @@ export async function init(options: InitOptions = {}): Promise<InitResult> {
428
428
  // Note: Stories are loaded separately by the viewer, not via include patterns
429
429
  const includePaths: string[] = [
430
430
  `${componentPath}/**/*.fragment.tsx`,
431
- `${componentPath}/**/*.segment.tsx`, // Legacy support
431
+ `${componentPath}/**/*.fragment.tsx`, // Legacy support
432
432
  ];
433
433
 
434
434
  // Create config file