@getchomp/mcp 0.0.0-stage → 0.2.42

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 (56) hide show
  1. package/README.md +15 -2
  2. package/dist/conventionsReference.d.ts +84 -0
  3. package/dist/conventionsReference.js +313 -0
  4. package/dist/designSystem/astScanner.d.ts +153 -0
  5. package/dist/designSystem/astScanner.js +2014 -0
  6. package/dist/designSystem/baseline.d.ts +65 -0
  7. package/dist/designSystem/baseline.js +136 -0
  8. package/dist/designSystem/color.d.ts +35 -0
  9. package/dist/designSystem/color.js +265 -0
  10. package/dist/designSystem/config.d.ts +183 -0
  11. package/dist/designSystem/config.js +469 -0
  12. package/dist/designSystem/contrast.d.ts +55 -0
  13. package/dist/designSystem/contrast.js +377 -0
  14. package/dist/designSystem/cssParser.d.ts +63 -0
  15. package/dist/designSystem/cssParser.js +469 -0
  16. package/dist/designSystem/merges.d.ts +57 -0
  17. package/dist/designSystem/merges.js +94 -0
  18. package/dist/designSystem/preprocessors.d.ts +46 -0
  19. package/dist/designSystem/preprocessors.js +1108 -0
  20. package/dist/designSystem/presentation.d.ts +45 -0
  21. package/dist/designSystem/presentation.js +796 -0
  22. package/dist/designSystem/styleVectors.d.ts +27 -0
  23. package/dist/designSystem/styleVectors.js +484 -0
  24. package/dist/designSystem/tokens.d.ts +39 -0
  25. package/dist/designSystem/tokens.js +409 -0
  26. package/dist/designSystem/topology.d.ts +64 -0
  27. package/dist/designSystem/topology.js +254 -0
  28. package/dist/designSystem/types.d.ts +857 -0
  29. package/dist/designSystem/types.js +113 -0
  30. package/dist/designSystem/typography.d.ts +25 -0
  31. package/dist/designSystem/typography.js +244 -0
  32. package/dist/designSystem/uiShapes.d.ts +74 -0
  33. package/dist/designSystem/uiShapes.js +285 -0
  34. package/dist/designSystem/valueClusters.d.ts +76 -0
  35. package/dist/designSystem/valueClusters.js +281 -0
  36. package/dist/designSystemPlugin.d.ts +321 -0
  37. package/dist/designSystemPlugin.js +4730 -0
  38. package/dist/enrichNodesPlugin.d.ts +160 -0
  39. package/dist/enrichNodesPlugin.js +957 -0
  40. package/dist/index.d.ts +65 -0
  41. package/dist/index.js +1298 -0
  42. package/dist/intelligence.d.ts +502 -0
  43. package/dist/intelligence.js +3058 -0
  44. package/dist/pluginRunner.d.ts +364 -0
  45. package/dist/pluginRunner.js +1096 -0
  46. package/dist/plugins/design-system/index.d.ts +14 -0
  47. package/dist/plugins/design-system/index.js +241 -0
  48. package/dist/plugins/enrich-nodes/index.d.ts +388 -0
  49. package/dist/plugins/enrich-nodes/index.js +697 -0
  50. package/dist/plugins/index.d.ts +15 -0
  51. package/dist/plugins/index.js +20 -0
  52. package/dist/plugins/local-shims/index.d.ts +121 -0
  53. package/dist/plugins/local-shims/index.js +237 -0
  54. package/dist/shimsPlugin.d.ts +134 -0
  55. package/dist/shimsPlugin.js +1392 -0
  56. package/package.json +38 -3
@@ -0,0 +1,321 @@
1
+ /**
2
+ * packages/mcp/src/designSystemPlugin.ts
3
+ *
4
+ * Design System & Frontend Agent Plugin (`L1_DESIGN_SYSTEM` / `source: 'design-system'`)
5
+ * Enforces [PAT-DB-03], [PAT-DB-05], [PAT-VIS-13], [PAT-VIS-21], [PAT-MCP-08], [PAT-MCP-09].
6
+ *
7
+ * Repo-agnostic, deterministic static analysis plugin for **frontend packages only** (detected
8
+ * from `package.json` dependencies, or listed in `chomp.config.json` → `designSystem.scope`).
9
+ *
10
+ * Nothing here assumes a particular repo's naming. The system is either *derived from the code*
11
+ * (`extract` mode) or *declared in `chomp.config.json`* (`adhere` mode) — see
12
+ * `designSystem/config.ts`. Capabilities:
13
+ * 1. Parses `.css` stylesheets (`:root`, theme selectors, `@theme`, `@property`, CSS nesting) to
14
+ * inventory tokens and derives their tiers from the token reference graph; detects undefined
15
+ * `var(--*)` leaks, duplicate/forked declarations, unused tokens, and WCAG 2.1 contrast across
16
+ * dark/light themes (hex, rgb, hsl, oklch…) — reporting un-evaluable pairs explicitly.
17
+ * 2. Scans React/TSX/TS components for styling convention mix, arbitrary Tailwind, raw palette
18
+ * use, hardcoded color/length literals (CSS, TS, JSX props, inline styles) and **clusters them
19
+ * into candidate tokens**; checks prop-literal invariants and atom composability.
20
+ * 3. Derives the atomic hierarchy, parallel-twin components (with a proposed merged prop API),
21
+ * structural/compositional JSX clones, and shared-atom adoption.
22
+ * 4. Provides the Closed-Loop Frontend Agent Gate (`auditDesignSystem` and `diffDesignSystem`)
23
+ * against a pinned baseline snapshot ("Query Before Write, Diff After Write").
24
+ */
25
+ import { type RepresentationGraph } from "@getchomp/core";
26
+ import { type EntityOverlayInput } from "@getchomp/db";
27
+ import { type ChompPlugin, type ChompPluginContext } from "./pluginRunner.js";
28
+ import { type DesignSystemBaselineSnapshot, type FindingRecord, type WorkingTreeCheck } from "./designSystem/baseline.js";
29
+ import { type DesignSystemConfig } from "./designSystem/config.js";
30
+ import { type AnalyzeDesignSystemOptions } from "./designSystem/topology.js";
31
+ import { type DerivedTokenProposal } from "./designSystem/valueClusters.js";
32
+ import type { AgentExtendabilitySection, AtomicConsolidationCandidate, AtomicHierarchySummary, BypassedAtomFinding, CallSiteOverrideFinding, ComponentDesignProfile, ComposabilityIssue, CompositeTypeTuple, ContextualStyleOverrideFinding, ContrastAuditItem, CoverageSection, DesignSystemAnalysisReport, DesignSystemSourceInfo, DuplicateTokenDiagnostic, InvariantViolation, NestedInteractiveFinding, ParallelTwinGroup, PropApiDriftGroup, RouteCompositionItem, SiblingAtomOverlapFinding, StructuralJsxCloneGroup, StylingConvention, ThemeSymmetryFinding, TokenRegistryEntry, TokenTier, TypographyRoleCluster, UnbackedSemanticTokenDiagnostic, UndefinedCssClassDiagnostic, UndefinedTokenDiagnostic, UnextractedUiShapeFinding } from "./designSystem/types.js";
33
+ export * from "./designSystem/types.js";
34
+ export { classifyTokenTier, parseCssStylesheet, type ParseCssOptions, type ParsedCssRule, type ParsedCssStylesheet, } from "./designSystem/cssParser.js";
35
+ export { computeRelativeLuminance, computeWcagContrastRatio, evaluateContrast, evaluateThemeContrastPairs, parseCssColorString, type ContrastEvaluation, type ContrastEvaluationOptions, type RgbaColor, type TailwindClassPairCandidate, } from "./designSystem/contrast.js";
36
+ export { scanTsxOrTsFile, type ScanOptions, type ScannedFileAstResult, } from "./designSystem/astScanner.js";
37
+ export { classifyAtomicTier, computeSubtreeHealth, matchUiRoleConvention, resolveAtomCatalog, type AnalyzeDesignSystemOptions, } from "./designSystem/topology.js";
38
+ export { buildTokenLookupMaps, computeStyleVectorDeltas, resolveComponentStyleVector, } from "./designSystem/styleVectors.js";
39
+ export { analyzeTypographyAndContextualOverrides } from "./designSystem/typography.js";
40
+ export { analyzeUiShapesAndSiblingOverlaps, isAuthorizedAtomOwner, resolveCanonicalAtomsByTarget, } from "./designSystem/uiShapes.js";
41
+ export { analyzeTokenLineageAndSymmetry, computeLiveReferencedTokens, deriveTokenTiers, isScaleStepTokenName, } from "./designSystem/tokens.js";
42
+ export declare function analyzeRepositoryDesignSystem(ctx: ChompPluginContext, analyzeOptions?: AnalyzeDesignSystemOptions): {
43
+ report: DesignSystemAnalysisReport;
44
+ overlays: EntityOverlayInput[];
45
+ };
46
+ /**
47
+ * Builds the `design-system` plugin. `configOverrides` is merged over `chomp.config.json` → `designSystem`
48
+ * and the built-in defaults (used by tests and programmatic callers; the registered plugin uses none).
49
+ */
50
+ export declare function createDesignSystemPlugin(configOverrides?: Partial<DesignSystemConfig>): ChompPlugin;
51
+ export declare const designSystemPlugin: ChompPlugin;
52
+ /**
53
+ * Flattens a report into identity-keyed findings (no line numbers) plus the set of failing
54
+ * contrast `pairId::theme` identities. This is the unit the pinned baseline snapshot stores.
55
+ */
56
+ export declare function collectDesignSystemFindings(report: DesignSystemAnalysisReport): {
57
+ records: FindingRecord[];
58
+ failingContrast: string[];
59
+ };
60
+ export interface AuditDesignSystemOptions {
61
+ repoPath: string;
62
+ repoId?: string;
63
+ repoName?: string;
64
+ dbPath?: string;
65
+ graph?: RepresentationGraph;
66
+ packageName?: string;
67
+ searchTerm?: string;
68
+ /** Refreshes the `entity_overlays` *display* layer. Never affects the diff baseline. */
69
+ persistOverlays?: boolean;
70
+ limit?: number;
71
+ /** Writes (or replaces) the pinned diff baseline snapshot from this audit. */
72
+ setBaseline?: boolean;
73
+ /** Override the baseline snapshot path (default: `designSystem.baseline.path`). */
74
+ baselinePath?: string;
75
+ /**
76
+ * When true (default), a *missing* baseline is only auto-pinned if the in-scope working tree is clean;
77
+ * otherwise pinning is refused (a baseline cut from uncommitted drift would hide that drift).
78
+ * Explicit `setBaseline` always pins and records `workingTreeDirty`.
79
+ */
80
+ requireCleanTree?: boolean;
81
+ /** When true (default), automatically pins a missing baseline if the working tree is clean. */
82
+ autoPinCleanBaseline?: boolean;
83
+ /** Injectable working-tree check (tests). Default: `git status` over the in-scope frontend directories. */
84
+ workingTreeCheck?: (repoPath: string, dirs: string[]) => WorkingTreeCheck;
85
+ configOverrides?: Partial<DesignSystemConfig>;
86
+ }
87
+ export interface DesignSystemBaselineStatus {
88
+ path: string;
89
+ exists: boolean;
90
+ /** True when this call created the baseline because none existed. */
91
+ bootstrapped: boolean;
92
+ /** True when this call wrote (created or replaced) the baseline. */
93
+ written: boolean;
94
+ /** True when no baseline exists and pinning was refused because the in-scope working tree has uncommitted changes. */
95
+ refused?: boolean;
96
+ /** Uncommitted in-scope paths that caused the refusal (or were present when a dirty tree was pinned explicitly). */
97
+ dirtyFiles?: string[];
98
+ createdAt?: string;
99
+ commitSha?: string;
100
+ note?: string;
101
+ }
102
+ export declare function auditDesignSystem(options: AuditDesignSystemOptions): Promise<{
103
+ plugin: {
104
+ name: string;
105
+ version: string;
106
+ layer: import("@getchomp/db").OverlayLayer;
107
+ runId: string;
108
+ overlaysPersisted: number;
109
+ durationMs: number;
110
+ };
111
+ system: DesignSystemSourceInfo;
112
+ coverage: CoverageSection;
113
+ baseline: DesignSystemBaselineStatus;
114
+ summary: {
115
+ cssFilesScanned: number;
116
+ componentFilesScanned: number;
117
+ componentsProfiled: number;
118
+ routeCount: number;
119
+ templateCount: number;
120
+ organismCount: number;
121
+ moleculeCount: number;
122
+ atomCount: number;
123
+ utilityCount: number;
124
+ structuralJsxCloneCount: number;
125
+ bypassedAtomCount: number;
126
+ siblingAtomOverlapCount: number;
127
+ nestedInteractiveCount: number;
128
+ unextractedShapeCount: number;
129
+ parallelTwinGroupCount: number;
130
+ callSiteOverrideCount: number;
131
+ propApiDriftGroupCount: number;
132
+ agentExtendabilityScore: number | null;
133
+ agentExtendabilityGrade: "A" | "B" | "C" | "D" | "F" | "N/A";
134
+ totalDefinedTokens: number;
135
+ primitiveTokenCount: number;
136
+ semanticTokenCount: number;
137
+ componentTokenCount: number;
138
+ themeBridgeTokenCount: number;
139
+ unbackedSemanticTokenCount: number;
140
+ themeSymmetryIssueCount: number;
141
+ undefinedTokenCount: number;
142
+ undefinedCssClassCount: number;
143
+ duplicateTokenCount: number;
144
+ forkedTokenCount: number;
145
+ unusedTokenCount: number;
146
+ contrastPairsAudited: number;
147
+ contrastCandidateCount: number;
148
+ contrastFailureCount: number;
149
+ contrastPairsUnresolved: number;
150
+ hardcodedLiteralCount: number;
151
+ derivedTokenProposalCount: number;
152
+ invariantViolationCount: number;
153
+ composabilityIssueCount: number;
154
+ frontendPackageCount: number;
155
+ unsupportedFileCount: number;
156
+ arbitraryTailwindCount: number;
157
+ magicSpacingCount: number;
158
+ primitiveScaleSkipCount: number;
159
+ inlineStyleLiteralCount: number;
160
+ canvasCssSlotCount: number;
161
+ canvasTsConstSlotCount: number;
162
+ canvasLiteralSlotCount: number;
163
+ rawDomPrimitiveCount: number;
164
+ atomicConsolidationGroupCount: number;
165
+ dynamicClassPrefixCount: number;
166
+ unusedCssSelectorCount: number;
167
+ typographyTupleCount: number;
168
+ typographyDriftRoleCount: number;
169
+ contextualOverrideCount: number;
170
+ conventionBreakdown: Record<StylingConvention, number>;
171
+ };
172
+ routeComposition: RouteCompositionItem[];
173
+ atomicHierarchy: AtomicHierarchySummary;
174
+ alignmentAudit: {
175
+ bypassedAtoms: BypassedAtomFinding[];
176
+ siblingAtomOverlaps: SiblingAtomOverlapFinding[];
177
+ nestedInteractive: NestedInteractiveFinding[];
178
+ unextractedShapes: UnextractedUiShapeFinding[];
179
+ parallelTwins: ParallelTwinGroup[];
180
+ callSiteOverrides: CallSiteOverrideFinding[];
181
+ propApiDrift: PropApiDriftGroup[];
182
+ invariantViolations: InvariantViolation[];
183
+ composabilityIssues: ComposabilityIssue[];
184
+ };
185
+ dryAudit: {
186
+ structuralJsxClones: StructuralJsxCloneGroup[];
187
+ atomicConsolidation: AtomicConsolidationCandidate[];
188
+ duplicateCssTokens: DuplicateTokenDiagnostic[];
189
+ };
190
+ derivedTokens: DerivedTokenProposal[];
191
+ agentExtendability: AgentExtendabilitySection;
192
+ tokenCatalog: {
193
+ primitive: string[];
194
+ semantic: string[];
195
+ component: string[];
196
+ themeBridge: string[];
197
+ };
198
+ tokenRegistry: TokenRegistryEntry[];
199
+ mergeDecisions: import("./designSystem/merges.js").DesignSystemMergeDecision[];
200
+ atomicConsolidation: AtomicConsolidationCandidate[];
201
+ diagnostics: {
202
+ undefinedTokens: UndefinedTokenDiagnostic[];
203
+ undefinedCssClasses: UndefinedCssClassDiagnostic[];
204
+ duplicateTokens: DuplicateTokenDiagnostic[];
205
+ unusedTokens: {
206
+ name: string;
207
+ tier: TokenTier;
208
+ filePath: string;
209
+ lineNumber: number;
210
+ }[];
211
+ unbackedSemanticTokens: UnbackedSemanticTokenDiagnostic[];
212
+ themeSymmetryIssues: ThemeSymmetryFinding[];
213
+ typographyTuples: CompositeTypeTuple[];
214
+ typographyRoleClusters: TypographyRoleCluster[];
215
+ contextualStyleOverrides: ContextualStyleOverrideFinding[];
216
+ contrastFailures: ContrastAuditItem[];
217
+ contrastAudits: ContrastAuditItem[];
218
+ dynamicClassPrefixes: string[];
219
+ unusedCssSelectors: {
220
+ selector: string;
221
+ filePath: string;
222
+ lineNumber: number;
223
+ }[];
224
+ hardcodedCssLiteralCount: number;
225
+ };
226
+ components: ComponentDesignProfile[];
227
+ recommendedHighlightNodeIds: string[];
228
+ agentGuidance: string[];
229
+ }>;
230
+ export interface DiffDesignSystemOptions {
231
+ repoPath: string;
232
+ repoId?: string;
233
+ repoName?: string;
234
+ dbPath?: string;
235
+ graph?: RepresentationGraph;
236
+ /** Override the baseline snapshot path (default: `designSystem.baseline.path`). */
237
+ baselinePath?: string;
238
+ configOverrides?: Partial<DesignSystemConfig>;
239
+ }
240
+ /** Short labels (scope stripped) of the frontend packages in a report's scope. */
241
+ export declare function frontendPackageLabels(report: DesignSystemAnalysisReport): string[];
242
+ export interface DesignSystemDiffResult {
243
+ /** `NO_BASELINE`: nothing pinned to compare against, which is *unknown*, never a pass. */
244
+ gateStatus: "PASS" | "WARN" | "NO_BASELINE";
245
+ hasBaseline: boolean;
246
+ baseline: {
247
+ path: string;
248
+ createdAt?: string;
249
+ commitSha?: string;
250
+ pluginVersion?: string;
251
+ };
252
+ /** Frontend packages that were in scope for this diff. */
253
+ frontendPackages: string[];
254
+ summary: {
255
+ newUndefinedTokenCount: number;
256
+ resolvedUndefinedTokenCount: number;
257
+ newArbitraryTailwindCount: number;
258
+ resolvedArbitraryTailwindCount: number;
259
+ newPrimitiveScaleSkipCount: number;
260
+ newHardcodedLiteralCount: number;
261
+ newInvariantViolationCount: number;
262
+ newRawPrimitiveCount: number;
263
+ newComposabilityIssueCount: number;
264
+ newCallSiteOverrideCount: number;
265
+ newContrastFailureCount: number;
266
+ resolvedContrastFailureCount: number;
267
+ regressedComponentCount: number;
268
+ improvedComponentCount: number;
269
+ };
270
+ newIssues: {
271
+ undefinedTokens: FindingRecord[];
272
+ arbitraryTailwind: FindingRecord[];
273
+ primitiveScaleSkips: FindingRecord[];
274
+ hardcodedLiterals: FindingRecord[];
275
+ invariantViolations: FindingRecord[];
276
+ rawPrimitives: FindingRecord[];
277
+ composabilityIssues: FindingRecord[];
278
+ callSiteOverrides: FindingRecord[];
279
+ contrastFailures: ContrastAuditItem[];
280
+ };
281
+ resolvedIssues: {
282
+ undefinedTokens: string[];
283
+ arbitraryTailwind: string[];
284
+ contrastFailures: string[];
285
+ };
286
+ componentDeltas: Array<{
287
+ entityId?: string;
288
+ label: string;
289
+ filePath: string;
290
+ status: "IMPROVED" | "REGRESSED";
291
+ added: number;
292
+ resolved: number;
293
+ addedFindings: string[];
294
+ }>;
295
+ /** Live (not diffed) totals so a `NO_BASELINE` result is still informative. */
296
+ liveTotals: Record<string, number>;
297
+ remediationGuidance: string[];
298
+ }
299
+ /**
300
+ * Pins the current working tree as the diff baseline. Explicit by design: no other call ever
301
+ * moves the baseline, so a re-audit can never silently move the goalposts of the gate.
302
+ */
303
+ export declare function snapshotDesignSystemBaseline(options: {
304
+ repoPath: string;
305
+ repoId?: string;
306
+ repoName?: string;
307
+ dbPath?: string;
308
+ graph?: RepresentationGraph;
309
+ baselinePath?: string;
310
+ commitSha?: string;
311
+ configOverrides?: Partial<DesignSystemConfig>;
312
+ }): Promise<{
313
+ path: string;
314
+ snapshot: DesignSystemBaselineSnapshot;
315
+ workingTree: WorkingTreeCheck;
316
+ }>;
317
+ /**
318
+ * Compares the live working-tree scan against the pinned baseline snapshot (`[PAT-MCP-02]`).
319
+ * Findings are keyed by identity (file, component, value) and compared by occurrence count.
320
+ */
321
+ export declare function diffDesignSystem(options: DiffDesignSystemOptions): Promise<DesignSystemDiffResult>;