@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.
- package/README.md +15 -2
- package/dist/conventionsReference.d.ts +84 -0
- package/dist/conventionsReference.js +313 -0
- package/dist/designSystem/astScanner.d.ts +153 -0
- package/dist/designSystem/astScanner.js +2014 -0
- package/dist/designSystem/baseline.d.ts +65 -0
- package/dist/designSystem/baseline.js +136 -0
- package/dist/designSystem/color.d.ts +35 -0
- package/dist/designSystem/color.js +265 -0
- package/dist/designSystem/config.d.ts +183 -0
- package/dist/designSystem/config.js +469 -0
- package/dist/designSystem/contrast.d.ts +55 -0
- package/dist/designSystem/contrast.js +377 -0
- package/dist/designSystem/cssParser.d.ts +63 -0
- package/dist/designSystem/cssParser.js +469 -0
- package/dist/designSystem/merges.d.ts +57 -0
- package/dist/designSystem/merges.js +94 -0
- package/dist/designSystem/preprocessors.d.ts +46 -0
- package/dist/designSystem/preprocessors.js +1108 -0
- package/dist/designSystem/presentation.d.ts +45 -0
- package/dist/designSystem/presentation.js +796 -0
- package/dist/designSystem/styleVectors.d.ts +27 -0
- package/dist/designSystem/styleVectors.js +484 -0
- package/dist/designSystem/tokens.d.ts +39 -0
- package/dist/designSystem/tokens.js +409 -0
- package/dist/designSystem/topology.d.ts +64 -0
- package/dist/designSystem/topology.js +254 -0
- package/dist/designSystem/types.d.ts +857 -0
- package/dist/designSystem/types.js +113 -0
- package/dist/designSystem/typography.d.ts +25 -0
- package/dist/designSystem/typography.js +244 -0
- package/dist/designSystem/uiShapes.d.ts +74 -0
- package/dist/designSystem/uiShapes.js +285 -0
- package/dist/designSystem/valueClusters.d.ts +76 -0
- package/dist/designSystem/valueClusters.js +281 -0
- package/dist/designSystemPlugin.d.ts +321 -0
- package/dist/designSystemPlugin.js +4730 -0
- package/dist/enrichNodesPlugin.d.ts +160 -0
- package/dist/enrichNodesPlugin.js +957 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +1298 -0
- package/dist/intelligence.d.ts +502 -0
- package/dist/intelligence.js +3058 -0
- package/dist/pluginRunner.d.ts +364 -0
- package/dist/pluginRunner.js +1096 -0
- package/dist/plugins/design-system/index.d.ts +14 -0
- package/dist/plugins/design-system/index.js +241 -0
- package/dist/plugins/enrich-nodes/index.d.ts +388 -0
- package/dist/plugins/enrich-nodes/index.js +697 -0
- package/dist/plugins/index.d.ts +15 -0
- package/dist/plugins/index.js +20 -0
- package/dist/plugins/local-shims/index.d.ts +121 -0
- package/dist/plugins/local-shims/index.js +237 -0
- package/dist/shimsPlugin.d.ts +134 -0
- package/dist/shimsPlugin.js +1392 -0
- package/package.json +38 -3
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/designSystem/topology.ts
|
|
3
|
+
*
|
|
4
|
+
* UI role classification, AST/render-topology Atomic Design tier assignment,
|
|
5
|
+
* dynamic class prefix matching, and cycle-safe weakest-link subtree health rollup.
|
|
6
|
+
*/
|
|
7
|
+
import { DEFAULT_ATOM_CATALOG, } from "./config.js";
|
|
8
|
+
import { UI_ROLE_CONVENTIONS, } from "./types.js";
|
|
9
|
+
import { doesComponentNameMatchAtom } from "./uiShapes.js";
|
|
10
|
+
export function getPrimaryNodeEvidence(node) {
|
|
11
|
+
if (!node.evidence)
|
|
12
|
+
return {};
|
|
13
|
+
if (Array.isArray(node.evidence)) {
|
|
14
|
+
const first = node.evidence.find((e) => Boolean(e?.filePath)) ?? node.evidence[0];
|
|
15
|
+
return { filePath: first?.filePath, lineNumber: first?.lineNumber };
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
filePath: node.evidence.filePath,
|
|
19
|
+
lineNumber: node.evidence.lineNumber,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function cleanNodeDisplayLabel(name) {
|
|
23
|
+
return name.replace(/^[A-Za-z0-9._\s/-]+:\s*/, "").trim();
|
|
24
|
+
}
|
|
25
|
+
export function matchUiRoleConvention(node, filePath, options = {}) {
|
|
26
|
+
const entityType = node.entityType || "";
|
|
27
|
+
const allowStructuralPathMatch = options.allowPathMatchForStructuralRoles !== false;
|
|
28
|
+
const patternId = typeof node.patternId === "string" && node.patternId
|
|
29
|
+
? node.patternId
|
|
30
|
+
: typeof node.metadata?.patternId === "string"
|
|
31
|
+
? node.metadata.patternId
|
|
32
|
+
: "";
|
|
33
|
+
const cleanLabel = node.name ? cleanNodeDisplayLabel(node.name) : "";
|
|
34
|
+
const isCustomHookName = /^use[A-Z0-9]/.test(cleanLabel);
|
|
35
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
36
|
+
for (const row of UI_ROLE_CONVENTIONS) {
|
|
37
|
+
if (row.entityTypes?.includes(entityType)) {
|
|
38
|
+
return row;
|
|
39
|
+
}
|
|
40
|
+
if (patternId &&
|
|
41
|
+
row.patternIdPrefixes?.some((prefix) => patternId.startsWith(prefix))) {
|
|
42
|
+
return row;
|
|
43
|
+
}
|
|
44
|
+
if (isCustomHookName &&
|
|
45
|
+
(row.role === "ATOM" || row.role === "MOLECULE" || row.role === "ORGANISM")) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if ((allowStructuralPathMatch || (row.role !== "ROUTE" && row.role !== "TEMPLATE")) &&
|
|
49
|
+
row.filePathPatterns?.some((re) => re.test(normalizedPath))) {
|
|
50
|
+
return row;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const INTERACTIVE_ATOM_TARGET_BY_TAG = {
|
|
56
|
+
button: "Button",
|
|
57
|
+
input: "Input",
|
|
58
|
+
select: "Select",
|
|
59
|
+
textarea: "Textarea",
|
|
60
|
+
};
|
|
61
|
+
export function classifyAtomicTier(params) {
|
|
62
|
+
const { jsxDomElementCount, jsxCustomComponentCount, stateHookCount, rendersOutDegree, domTags, } = params;
|
|
63
|
+
const cleanLabel = cleanNodeDisplayLabel(params.node.name);
|
|
64
|
+
// Detect chrome-wrapped interactive controls (e.g. labeled trigger slot or stepper wrapping raw `<button>`/`<input>`)
|
|
65
|
+
let hasChromeAroundInteractiveControl = false;
|
|
66
|
+
if (domTags && domTags.size > 0) {
|
|
67
|
+
for (const [tag, targetAtom] of Object.entries(INTERACTIVE_ATOM_TARGET_BY_TAG)) {
|
|
68
|
+
if (domTags.has(tag) &&
|
|
69
|
+
!doesComponentNameMatchAtom(cleanLabel, targetAtom) &&
|
|
70
|
+
!doesComponentNameMatchAtom(cleanLabel, "Switch") &&
|
|
71
|
+
!doesComponentNameMatchAtom(cleanLabel, "Checkbox") &&
|
|
72
|
+
jsxDomElementCount >= 2) {
|
|
73
|
+
hasChromeAroundInteractiveControl = true;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const matchedConv = matchUiRoleConvention(params.node, params.filePath, {
|
|
79
|
+
allowPathMatchForStructuralRoles: params.isPrimaryInFile !== false,
|
|
80
|
+
});
|
|
81
|
+
if (matchedConv) {
|
|
82
|
+
// Reclassify multi-element / chrome-wrapped components in `atoms/` directories to MOLECULE / ORGANISM
|
|
83
|
+
// unless explicitly marked by framework AST entityType (`UI_ATOM`, `UI_PRIMITIVE`).
|
|
84
|
+
const isExplicitAstAtomType = matchedConv.entityTypes?.includes(params.node.entityType || "");
|
|
85
|
+
if (matchedConv.role === "ATOM" && !isExplicitAstAtomType) {
|
|
86
|
+
if (rendersOutDegree >= 3 ||
|
|
87
|
+
jsxCustomComponentCount >= 3 ||
|
|
88
|
+
jsxDomElementCount >= 22 ||
|
|
89
|
+
stateHookCount >= 3) {
|
|
90
|
+
return {
|
|
91
|
+
atomicTier: "ORGANISM",
|
|
92
|
+
classificationSource: "renders-topology",
|
|
93
|
+
convention: matchedConv,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (rendersOutDegree > 0 ||
|
|
97
|
+
jsxCustomComponentCount > 0 ||
|
|
98
|
+
jsxDomElementCount >= 6 ||
|
|
99
|
+
hasChromeAroundInteractiveControl) {
|
|
100
|
+
return {
|
|
101
|
+
atomicTier: "MOLECULE",
|
|
102
|
+
classificationSource: "ast-footprint",
|
|
103
|
+
convention: matchedConv,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
atomicTier: matchedConv.role,
|
|
109
|
+
classificationSource: "convention-table",
|
|
110
|
+
convention: matchedConv,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (jsxDomElementCount === 0 && jsxCustomComponentCount === 0) {
|
|
114
|
+
return {
|
|
115
|
+
atomicTier: "UTILITY",
|
|
116
|
+
classificationSource: "ast-footprint",
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (rendersOutDegree >= 3 ||
|
|
120
|
+
jsxCustomComponentCount >= 3 ||
|
|
121
|
+
jsxDomElementCount >= 22 ||
|
|
122
|
+
stateHookCount >= 3) {
|
|
123
|
+
return {
|
|
124
|
+
atomicTier: "ORGANISM",
|
|
125
|
+
classificationSource: rendersOutDegree >= 3 ? "renders-topology" : "ast-footprint",
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (rendersOutDegree === 0 &&
|
|
129
|
+
jsxCustomComponentCount === 0 &&
|
|
130
|
+
jsxDomElementCount > 0 &&
|
|
131
|
+
jsxDomElementCount <= 6 &&
|
|
132
|
+
stateHookCount <= 1 &&
|
|
133
|
+
!hasChromeAroundInteractiveControl) {
|
|
134
|
+
return {
|
|
135
|
+
atomicTier: "ATOM",
|
|
136
|
+
classificationSource: "renders-topology",
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
atomicTier: "MOLECULE",
|
|
141
|
+
classificationSource: rendersOutDegree > 0 ? "renders-topology" : "ast-footprint",
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export function inferSuggestedComponentName(rootTag, canonicalSignature, elementCount) {
|
|
145
|
+
const pascal = (raw) => raw
|
|
146
|
+
.split(/[^A-Za-z0-9]+/)
|
|
147
|
+
.filter(Boolean)
|
|
148
|
+
.map((w) => w[0].toUpperCase() + w.slice(1))
|
|
149
|
+
.join("");
|
|
150
|
+
const tier = elementCount >= 10 ? "ORGANISM" : "MOLECULE";
|
|
151
|
+
const customNames = [];
|
|
152
|
+
for (const m of canonicalSignature.matchAll(/(?:^|[(,>])([A-Z][A-Za-z0-9]*(?:\.[A-Za-z0-9]+)?)/g)) {
|
|
153
|
+
const n = m[1].replace(/\./g, "");
|
|
154
|
+
if (!customNames.includes(n))
|
|
155
|
+
customNames.push(n);
|
|
156
|
+
}
|
|
157
|
+
if (customNames.length >= 2) {
|
|
158
|
+
return { name: customNames.slice(0, 3).join(""), tier, confidence: "medium" };
|
|
159
|
+
}
|
|
160
|
+
const classMatch = rootTag.match(/\.([a-zA-Z0-9_-]+)/);
|
|
161
|
+
if (classMatch?.[1]) {
|
|
162
|
+
const clean = pascal(classMatch[1].split("__")[0].split("--")[0]);
|
|
163
|
+
if (clean)
|
|
164
|
+
return { name: clean, tier, confidence: "medium" };
|
|
165
|
+
}
|
|
166
|
+
if (/^[A-Z]/.test(rootTag)) {
|
|
167
|
+
return { name: `${pascal(rootTag.split("[")[0])}Block`, tier, confidence: "medium" };
|
|
168
|
+
}
|
|
169
|
+
const roleMatch = rootTag.match(/\[role=([a-z]+)\]/);
|
|
170
|
+
if (roleMatch) {
|
|
171
|
+
return { name: `${pascal(roleMatch[1])}Block`, tier, confidence: "low" };
|
|
172
|
+
}
|
|
173
|
+
return { name: `Extracted${pascal(rootTag.split("[")[0])}Block`, tier, confidence: "low" };
|
|
174
|
+
}
|
|
175
|
+
export function matchesDynamicPrefix(cls, dynamicPrefixes) {
|
|
176
|
+
for (const prefixPattern of dynamicPrefixes) {
|
|
177
|
+
const cleanPrefix = prefixPattern.replace(/\*$/, "");
|
|
178
|
+
if (cleanPrefix && cls.startsWith(cleanPrefix)) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
/** Resolves the effective atom catalog from config (`defaults` + declared definitions, `extend`, or `replace`). */
|
|
185
|
+
export function resolveAtomCatalog(config) {
|
|
186
|
+
const declared = config.atoms.definitions;
|
|
187
|
+
if (config.atoms.catalog === "replace")
|
|
188
|
+
return [...declared];
|
|
189
|
+
const declaredNames = new Set(declared.map((d) => d.name.toLowerCase()));
|
|
190
|
+
return [
|
|
191
|
+
...declared,
|
|
192
|
+
...DEFAULT_ATOM_CATALOG.filter((d) => !declaredNames.has(d.name.toLowerCase())),
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
export const UNSUPPORTED_UI_EXTENSIONS = [".sass", ".styl"];
|
|
196
|
+
/**
|
|
197
|
+
* Cycle-safe weakest-link subtree health rollup over reachable `RENDERS` descendants.
|
|
198
|
+
* Does not double-count descendant issues into `directIssueCount` (used for package totals).
|
|
199
|
+
*/
|
|
200
|
+
export function computeSubtreeHealth(nodes, rendersOutById) {
|
|
201
|
+
const out = new Map();
|
|
202
|
+
for (const [rootId, root] of nodes.entries()) {
|
|
203
|
+
const visited = new Set([rootId]);
|
|
204
|
+
const queue = [];
|
|
205
|
+
for (const childId of rendersOutById.get(rootId) ?? []) {
|
|
206
|
+
if (!visited.has(childId) && nodes.has(childId)) {
|
|
207
|
+
visited.add(childId);
|
|
208
|
+
queue.push(childId);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
let head = 0;
|
|
212
|
+
let subtreeScore = root.directScore;
|
|
213
|
+
let subtreeIssueCount = 0;
|
|
214
|
+
const descendantOffenders = [];
|
|
215
|
+
while (head < queue.length) {
|
|
216
|
+
const currId = queue[head++];
|
|
217
|
+
const desc = nodes.get(currId);
|
|
218
|
+
if (!desc)
|
|
219
|
+
continue;
|
|
220
|
+
if (desc.directScore < subtreeScore)
|
|
221
|
+
subtreeScore = desc.directScore;
|
|
222
|
+
subtreeIssueCount += desc.directIssueCount;
|
|
223
|
+
if (desc.directIssueCount > 0 || desc.directScore < 100) {
|
|
224
|
+
descendantOffenders.push({
|
|
225
|
+
entityId: desc.entityId,
|
|
226
|
+
label: desc.label,
|
|
227
|
+
directScore: desc.directScore,
|
|
228
|
+
directIssueCount: desc.directIssueCount,
|
|
229
|
+
filePath: desc.filePath,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
for (const nextId of rendersOutById.get(currId) ?? []) {
|
|
233
|
+
if (!visited.has(nextId) && nodes.has(nextId)) {
|
|
234
|
+
visited.add(nextId);
|
|
235
|
+
queue.push(nextId);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
descendantOffenders.sort((a, b) => a.directScore - b.directScore ||
|
|
240
|
+
b.directIssueCount - a.directIssueCount ||
|
|
241
|
+
a.label.localeCompare(b.label));
|
|
242
|
+
const subtreeStatus = subtreeScore >= 85 ? "healthy" : subtreeScore >= 60 ? "warn" : "critical";
|
|
243
|
+
out.set(rootId, {
|
|
244
|
+
directScore: root.directScore,
|
|
245
|
+
directStatus: root.directStatus,
|
|
246
|
+
directIssueCount: root.directIssueCount,
|
|
247
|
+
subtreeScore,
|
|
248
|
+
subtreeStatus,
|
|
249
|
+
subtreeIssueCount,
|
|
250
|
+
descendantOffenders,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
return out;
|
|
254
|
+
}
|