@fragments-sdk/cli 0.11.1 → 0.13.0

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 (89) hide show
  1. package/dist/ai-client-I6MDWNYA.js +21 -0
  2. package/dist/bin.js +419 -410
  3. package/dist/bin.js.map +1 -1
  4. package/dist/{chunk-HRFUSSZI.js → chunk-3SOAPJDX.js} +2 -2
  5. package/dist/{chunk-D5PYOXEI.js → chunk-4K7EAQ5L.js} +148 -13
  6. package/dist/{chunk-D5PYOXEI.js.map → chunk-4K7EAQ5L.js.map} +1 -1
  7. package/dist/chunk-DXX6HADE.js +443 -0
  8. package/dist/chunk-DXX6HADE.js.map +1 -0
  9. package/dist/chunk-EYXVAMEX.js +626 -0
  10. package/dist/chunk-EYXVAMEX.js.map +1 -0
  11. package/dist/{chunk-ZM4ZQZWZ.js → chunk-FO6EBJWP.js} +39 -37
  12. package/dist/chunk-FO6EBJWP.js.map +1 -0
  13. package/dist/{chunk-OQO55NKV.js → chunk-QM7SVOGF.js} +120 -12
  14. package/dist/chunk-QM7SVOGF.js.map +1 -0
  15. package/dist/{chunk-5G3VZH43.js → chunk-RF3C6LGA.js} +281 -351
  16. package/dist/chunk-RF3C6LGA.js.map +1 -0
  17. package/dist/{chunk-WXSR2II7.js → chunk-SM674YAS.js} +58 -6
  18. package/dist/chunk-SM674YAS.js.map +1 -0
  19. package/dist/chunk-SXTKFDCR.js +104 -0
  20. package/dist/chunk-SXTKFDCR.js.map +1 -0
  21. package/dist/{chunk-PW7QTQA6.js → chunk-UV5JQV3R.js} +2 -2
  22. package/dist/core/index.js +13 -1
  23. package/dist/{discovery-NEOY4MPN.js → discovery-VSGC76JN.js} +3 -3
  24. package/dist/{generate-FBHSXR3D.js → generate-QZXOXYFW.js} +4 -4
  25. package/dist/index.js +7 -6
  26. package/dist/index.js.map +1 -1
  27. package/dist/init-XK6PRUE5.js +636 -0
  28. package/dist/init-XK6PRUE5.js.map +1 -0
  29. package/dist/mcp-bin.js +2 -2
  30. package/dist/{scan-CJF2DOQW.js → scan-CHQHXWVD.js} +6 -6
  31. package/dist/scan-generate-U3RFVDTX.js +1115 -0
  32. package/dist/scan-generate-U3RFVDTX.js.map +1 -0
  33. package/dist/{service-TQYWY65E.js → service-MMEKG4MZ.js} +3 -3
  34. package/dist/{snapshot-SV2JOFZH.js → snapshot-53TUR3HW.js} +2 -2
  35. package/dist/{static-viewer-NUBFPKWH.js → static-viewer-KKCR4KXR.js} +3 -3
  36. package/dist/static-viewer-KKCR4KXR.js.map +1 -0
  37. package/dist/{test-Z5LVO724.js → test-5UCKXYSC.js} +4 -4
  38. package/dist/{tokens-CE46OTMD.js → tokens-L46MK5AW.js} +5 -5
  39. package/dist/{viewer-DLLJIMCK.js → viewer-M2EQQSGE.js} +14 -14
  40. package/dist/viewer-M2EQQSGE.js.map +1 -0
  41. package/package.json +11 -9
  42. package/src/ai-client.ts +156 -0
  43. package/src/bin.ts +99 -2
  44. package/src/build.ts +95 -33
  45. package/src/commands/__tests__/drift-sync.test.ts +252 -0
  46. package/src/commands/__tests__/scan-generate.test.ts +497 -45
  47. package/src/commands/enhance.ts +11 -35
  48. package/src/commands/govern.ts +122 -0
  49. package/src/commands/init.ts +288 -260
  50. package/src/commands/scan-generate.ts +740 -139
  51. package/src/commands/scan.ts +37 -32
  52. package/src/commands/setup.ts +143 -52
  53. package/src/commands/sync.ts +357 -0
  54. package/src/commands/validate.ts +43 -1
  55. package/src/core/component-extractor.test.ts +282 -0
  56. package/src/core/component-extractor.ts +1030 -0
  57. package/src/core/discovery.ts +93 -7
  58. package/src/service/enhance/props-extractor.ts +235 -13
  59. package/src/validators.ts +236 -0
  60. package/src/viewer/vite-plugin.ts +1 -1
  61. package/dist/chunk-5G3VZH43.js.map +0 -1
  62. package/dist/chunk-OQO55NKV.js.map +0 -1
  63. package/dist/chunk-WXSR2II7.js.map +0 -1
  64. package/dist/chunk-ZM4ZQZWZ.js.map +0 -1
  65. package/dist/init-UFGK5TCN.js +0 -867
  66. package/dist/init-UFGK5TCN.js.map +0 -1
  67. package/dist/scan-generate-SJAN5MVI.js +0 -691
  68. package/dist/scan-generate-SJAN5MVI.js.map +0 -1
  69. package/dist/viewer-DLLJIMCK.js.map +0 -1
  70. package/src/ai.ts +0 -266
  71. package/src/commands/init-framework.ts +0 -414
  72. package/src/mcp/bin.ts +0 -36
  73. package/src/migrate/bin.ts +0 -114
  74. package/src/theme/index.ts +0 -77
  75. package/src/viewer/bin.ts +0 -86
  76. package/src/viewer/cli/health.ts +0 -256
  77. package/src/viewer/cli/index.ts +0 -33
  78. package/src/viewer/cli/scan.ts +0 -124
  79. package/src/viewer/cli/utils.ts +0 -174
  80. /package/dist/{discovery-NEOY4MPN.js.map → ai-client-I6MDWNYA.js.map} +0 -0
  81. /package/dist/{chunk-HRFUSSZI.js.map → chunk-3SOAPJDX.js.map} +0 -0
  82. /package/dist/{chunk-PW7QTQA6.js.map → chunk-UV5JQV3R.js.map} +0 -0
  83. /package/dist/{scan-CJF2DOQW.js.map → discovery-VSGC76JN.js.map} +0 -0
  84. /package/dist/{generate-FBHSXR3D.js.map → generate-QZXOXYFW.js.map} +0 -0
  85. /package/dist/{service-TQYWY65E.js.map → scan-CHQHXWVD.js.map} +0 -0
  86. /package/dist/{static-viewer-NUBFPKWH.js.map → service-MMEKG4MZ.js.map} +0 -0
  87. /package/dist/{snapshot-SV2JOFZH.js.map → snapshot-53TUR3HW.js.map} +0 -0
  88. /package/dist/{test-Z5LVO724.js.map → test-5UCKXYSC.js.map} +0 -0
  89. /package/dist/{tokens-CE46OTMD.js.map → tokens-L46MK5AW.js.map} +0 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * fragments govern — AI UI governance checks
3
+ *
4
+ * Subcommands:
5
+ * check — Validate a UISpec against governance policies
6
+ * init — Generate a govern.config.ts template
7
+ * report — Summarize audit log
8
+ */
9
+
10
+ import pc from 'picocolors';
11
+ import { BRAND } from '../core/index.js';
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // Options
15
+ // ---------------------------------------------------------------------------
16
+
17
+ export interface GovernCheckOptions {
18
+ /** Path to UISpec JSON file, or '-' for stdin */
19
+ input?: string;
20
+ /** Path to govern.config.ts */
21
+ config?: string;
22
+ /** Output format */
23
+ format?: 'json' | 'summary' | 'sarif';
24
+ /** Suppress non-error output */
25
+ quiet?: boolean;
26
+ }
27
+
28
+ export interface GovernInitOptions {
29
+ /** Output path (defaults to ./govern.config.ts) */
30
+ output?: string;
31
+ }
32
+
33
+ // ---------------------------------------------------------------------------
34
+ // check
35
+ // ---------------------------------------------------------------------------
36
+
37
+ export async function governCheck(options: GovernCheckOptions = {}): Promise<{ exitCode: number }> {
38
+ console.log(pc.cyan(`\n${BRAND.name} Governance Check\n`));
39
+
40
+ const { cliCheck, formatVerdict } = await import('@fragments-sdk/govern');
41
+
42
+ const result = await cliCheck(options);
43
+ const output = formatVerdict(result.verdict, options.format ?? 'summary');
44
+
45
+ if (!options.quiet) {
46
+ console.log(output);
47
+ console.log();
48
+ }
49
+
50
+ if (result.verdict.passed) {
51
+ console.log(pc.green(`✓ Governance check passed (score: ${result.verdict.score}/100)\n`));
52
+ } else {
53
+ console.log(pc.red(`✗ Governance check failed (score: ${result.verdict.score}/100)\n`));
54
+ }
55
+
56
+ return { exitCode: result.exitCode };
57
+ }
58
+
59
+ // ---------------------------------------------------------------------------
60
+ // init
61
+ // ---------------------------------------------------------------------------
62
+
63
+ export async function governInit(options: GovernInitOptions = {}): Promise<void> {
64
+ const { writeFile } = await import('node:fs/promises');
65
+ const { resolve } = await import('node:path');
66
+ const { generateConfigTemplate } = await import('@fragments-sdk/govern');
67
+
68
+ const outputPath = resolve(options.output ?? 'govern.config.ts');
69
+ const template = generateConfigTemplate();
70
+
71
+ await writeFile(outputPath, template, 'utf-8');
72
+ console.log(pc.green(`✓ Created ${outputPath}\n`));
73
+ }
74
+
75
+ // ---------------------------------------------------------------------------
76
+ // report
77
+ // ---------------------------------------------------------------------------
78
+
79
+ export async function governReport(): Promise<void> {
80
+ const { readFile } = await import('node:fs/promises');
81
+
82
+ console.log(pc.cyan(`\n${BRAND.name} Governance Report\n`));
83
+
84
+ let raw: string;
85
+ try {
86
+ raw = await readFile('.govern-audit.jsonl', 'utf-8');
87
+ } catch {
88
+ console.log(pc.yellow('No audit log found (.govern-audit.jsonl)\n'));
89
+ console.log(pc.dim('Run `fragments govern check` to generate audit data.\n'));
90
+ return;
91
+ }
92
+
93
+ const lines = raw.trim().split('\n').filter(Boolean);
94
+ if (lines.length === 0) {
95
+ console.log(pc.yellow('Audit log is empty.\n'));
96
+ return;
97
+ }
98
+
99
+ let totalScore = 0;
100
+ let passCount = 0;
101
+ let totalViolations = 0;
102
+
103
+ for (const line of lines) {
104
+ try {
105
+ const entry = JSON.parse(line);
106
+ totalScore += entry.score ?? 0;
107
+ if (entry.passed) passCount++;
108
+ totalViolations += entry.violationCount ?? 0;
109
+ } catch {
110
+ // Skip malformed lines
111
+ }
112
+ }
113
+
114
+ const avgScore = Math.round(totalScore / lines.length);
115
+ const passRate = Math.round((passCount / lines.length) * 100);
116
+
117
+ console.log(` Checks: ${lines.length}`);
118
+ console.log(` Pass rate: ${passRate}%`);
119
+ console.log(` Avg score: ${avgScore}/100`);
120
+ console.log(` Violations: ${totalViolations} total`);
121
+ console.log();
122
+ }