@getchomp/mcp 0.2.44 → 0.2.46
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/dist/designSystemPlugin.d.ts +263 -1
- package/dist/designSystemPlugin.js +193 -0
- package/dist/index.d.ts +151 -1
- package/dist/index.js +758 -76
- package/dist/intelligence.d.ts +5 -2
- package/dist/intelligence.js +371 -51
- package/dist/plugins/design-system/index.js +9 -2
- package/dist/plugins/enrich-nodes/index.d.ts +2 -2
- package/package.json +3 -3
package/dist/intelligence.d.ts
CHANGED
|
@@ -132,8 +132,8 @@ export type SeamDiagnostic = IsolatedDeploymentUnitsDiagnostic | UnstitchedProto
|
|
|
132
132
|
*/
|
|
133
133
|
export declare function packageMatchesFilter(nodePkg: string, nodePath: string | undefined, rawFilter: string): boolean;
|
|
134
134
|
/**
|
|
135
|
-
* Filters nodes in `chomp_get_nodes` with support for
|
|
136
|
-
* fast-path resolution ([PAT-MCP-08]).
|
|
135
|
+
* Filters nodes in `chomp_get_nodes` with support for single or batched `search_term(s)`,
|
|
136
|
+
* `file_path(s)`, and `packageName` fast-path resolution ([PAT-MCP-08]).
|
|
137
137
|
*/
|
|
138
138
|
export declare function filterNodesForMcp(graph: RepresentationGraph, filters: {
|
|
139
139
|
type?: string;
|
|
@@ -141,7 +141,9 @@ export declare function filterNodesForMcp(graph: RepresentationGraph, filters: {
|
|
|
141
141
|
parentBoundaryId?: string;
|
|
142
142
|
name?: string;
|
|
143
143
|
filePath?: string;
|
|
144
|
+
filePaths?: string[];
|
|
144
145
|
searchTerm?: string;
|
|
146
|
+
searchTerms?: string[];
|
|
145
147
|
packageName?: string;
|
|
146
148
|
overlaysByEntityId?: Map<string, Array<{
|
|
147
149
|
layer: string;
|
|
@@ -314,6 +316,7 @@ export declare function auditGraphHealth(graph: RepresentationGraph, options?: {
|
|
|
314
316
|
export declare function findGraphRedundancies(graph: RepresentationGraph, options?: {
|
|
315
317
|
packageName?: string;
|
|
316
318
|
limit?: number;
|
|
319
|
+
repoPath?: string;
|
|
317
320
|
}): {
|
|
318
321
|
summary: {
|
|
319
322
|
passThroughMiddlemenCount: number;
|
package/dist/intelligence.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { existsSync, readFileSync } from "node:fs";
|
|
12
12
|
import { resolve } from "node:path";
|
|
13
|
+
import ts from "typescript";
|
|
13
14
|
import { clusterSignalInstances, computeActionableUnresolvedCallsByNode, computeStructuralHealthMetrics, findDarkFiles, mergeContractPortValves, orphanShapeKey, } from "@getchomp/core";
|
|
14
15
|
const CONTAINER_ENTITY_TYPES = new Set(["DEPLOYMENT_UNIT"]);
|
|
15
16
|
const PACKAGE_CONNECTOR_ENTITY_TYPES = new Set([
|
|
@@ -1356,14 +1357,24 @@ function detectShadowedDbReceptors(graph, index, options) {
|
|
|
1356
1357
|
return diagnostics;
|
|
1357
1358
|
}
|
|
1358
1359
|
/**
|
|
1359
|
-
* Filters nodes in `chomp_get_nodes` with support for
|
|
1360
|
-
* fast-path resolution ([PAT-MCP-08]).
|
|
1360
|
+
* Filters nodes in `chomp_get_nodes` with support for single or batched `search_term(s)`,
|
|
1361
|
+
* `file_path(s)`, and `packageName` fast-path resolution ([PAT-MCP-08]).
|
|
1361
1362
|
*/
|
|
1362
1363
|
export function filterNodesForMcp(graph, filters) {
|
|
1363
1364
|
const index = buildGraphIndex(graph);
|
|
1364
1365
|
const nameFilter = filters.name?.toLowerCase();
|
|
1365
|
-
const
|
|
1366
|
-
|
|
1366
|
+
const filePathFilters = Array.from(new Set([
|
|
1367
|
+
...(filters.filePath ? [filters.filePath] : []),
|
|
1368
|
+
...(filters.filePaths ?? []),
|
|
1369
|
+
]
|
|
1370
|
+
.map((p) => p.trim().toLowerCase())
|
|
1371
|
+
.filter(Boolean)));
|
|
1372
|
+
const searchTermFilters = Array.from(new Set([
|
|
1373
|
+
...(filters.searchTerm ? [filters.searchTerm] : []),
|
|
1374
|
+
...(filters.searchTerms ?? []),
|
|
1375
|
+
]
|
|
1376
|
+
.map((s) => s.trim().toLowerCase())
|
|
1377
|
+
.filter(Boolean)));
|
|
1367
1378
|
const packageFilter = filters.packageName?.trim();
|
|
1368
1379
|
let filteredNodes = graph.nodes;
|
|
1369
1380
|
if (filters.type) {
|
|
@@ -1385,39 +1396,43 @@ export function filterNodesForMcp(graph, filters) {
|
|
|
1385
1396
|
if (nameFilter) {
|
|
1386
1397
|
filteredNodes = filteredNodes.filter((n) => typeof n.name === "string" && n.name.toLowerCase().includes(nameFilter));
|
|
1387
1398
|
}
|
|
1388
|
-
if (
|
|
1399
|
+
if (filePathFilters.length > 0) {
|
|
1400
|
+
const allowPackageConnectors = filters.type === "OPEN_CONNECTOR" ||
|
|
1401
|
+
filters.entityType === "EXTERNAL_PACKAGE" ||
|
|
1402
|
+
filters.entityType === "NODE_BUILTIN";
|
|
1389
1403
|
filteredNodes = filteredNodes.filter((n) => {
|
|
1404
|
+
if (!allowPackageConnectors && PACKAGE_CONNECTOR_ENTITY_TYPES.has(n.entityType)) {
|
|
1405
|
+
return false;
|
|
1406
|
+
}
|
|
1390
1407
|
const ev = n.evidence;
|
|
1391
1408
|
if (!ev)
|
|
1392
1409
|
return false;
|
|
1410
|
+
const matchesAnyPath = (fp) => typeof fp === "string" &&
|
|
1411
|
+
filePathFilters.some((q) => fp.toLowerCase().includes(q));
|
|
1393
1412
|
if (Array.isArray(ev)) {
|
|
1394
|
-
return ev.some((r) =>
|
|
1395
|
-
r.filePath.toLowerCase().includes(filePathFilter));
|
|
1413
|
+
return ev.some((r) => matchesAnyPath(r?.filePath));
|
|
1396
1414
|
}
|
|
1397
|
-
return (
|
|
1398
|
-
ev.filePath.toLowerCase().includes(filePathFilter));
|
|
1415
|
+
return matchesAnyPath(ev.filePath);
|
|
1399
1416
|
});
|
|
1400
1417
|
}
|
|
1401
|
-
if (
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
if (n.
|
|
1408
|
-
return
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
return
|
|
1418
|
+
if (searchTermFilters.length > 0) {
|
|
1419
|
+
const allowPackageConnectorFileMatch = filters.type === "OPEN_CONNECTOR" ||
|
|
1420
|
+
filters.entityType === "EXTERNAL_PACKAGE" ||
|
|
1421
|
+
filters.entityType === "NODE_BUILTIN";
|
|
1422
|
+
const scoreNodeForTerm = (n, term) => {
|
|
1423
|
+
const cleanLbl = cleanNodeLabel(n.name).toLowerCase();
|
|
1424
|
+
if (cleanLbl === term || n.id.toLowerCase() === term)
|
|
1425
|
+
return 4;
|
|
1426
|
+
if (cleanLbl.includes(term) || n.name.toLowerCase().includes(term))
|
|
1427
|
+
return 3;
|
|
1428
|
+
if (n.id.toLowerCase().includes(term) || n.entityType.toLowerCase().includes(term)) {
|
|
1429
|
+
return 2;
|
|
1413
1430
|
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
meta.summary.toLowerCase().includes(searchTermFilter)) {
|
|
1420
|
-
return true;
|
|
1431
|
+
const meta = parseNodeMeta(n);
|
|
1432
|
+
if ((typeof meta.humanLabel === "string" && meta.humanLabel.toLowerCase().includes(term)) ||
|
|
1433
|
+
(typeof meta.domain === "string" && meta.domain.toLowerCase().includes(term)) ||
|
|
1434
|
+
(typeof meta.summary === "string" && meta.summary.toLowerCase().includes(term))) {
|
|
1435
|
+
return 2;
|
|
1421
1436
|
}
|
|
1422
1437
|
const nodeOverlays = filters.overlaysByEntityId?.get(n.id);
|
|
1423
1438
|
if (nodeOverlays) {
|
|
@@ -1425,28 +1440,50 @@ export function filterNodesForMcp(graph, filters) {
|
|
|
1425
1440
|
const p = ov.payload;
|
|
1426
1441
|
if (!p || typeof p !== "object")
|
|
1427
1442
|
continue;
|
|
1428
|
-
if (typeof p.humanLabel === "string" &&
|
|
1429
|
-
p.
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
if (typeof p.domain === "string" &&
|
|
1433
|
-
p.domain.toLowerCase().includes(searchTermFilter)) {
|
|
1434
|
-
return true;
|
|
1435
|
-
}
|
|
1436
|
-
if (typeof p.summary === "string" &&
|
|
1437
|
-
p.summary.toLowerCase().includes(searchTermFilter)) {
|
|
1438
|
-
return true;
|
|
1443
|
+
if ((typeof p.humanLabel === "string" && p.humanLabel.toLowerCase().includes(term)) ||
|
|
1444
|
+
(typeof p.domain === "string" && p.domain.toLowerCase().includes(term)) ||
|
|
1445
|
+
(typeof p.summary === "string" && p.summary.toLowerCase().includes(term))) {
|
|
1446
|
+
return 2;
|
|
1439
1447
|
}
|
|
1440
1448
|
}
|
|
1441
1449
|
}
|
|
1450
|
+
if (!allowPackageConnectorFileMatch && PACKAGE_CONNECTOR_ENTITY_TYPES.has(n.entityType)) {
|
|
1451
|
+
return 0;
|
|
1452
|
+
}
|
|
1442
1453
|
const ev = n.evidence;
|
|
1443
1454
|
if (Array.isArray(ev)) {
|
|
1444
|
-
return ev.some((r) => typeof r?.filePath === "string" &&
|
|
1445
|
-
|
|
1455
|
+
return ev.some((r) => typeof r?.filePath === "string" && r.filePath.toLowerCase().includes(term))
|
|
1456
|
+
? 1
|
|
1457
|
+
: 0;
|
|
1446
1458
|
}
|
|
1447
|
-
return
|
|
1448
|
-
|
|
1449
|
-
|
|
1459
|
+
return typeof ev?.filePath === "string" && ev.filePath.toLowerCase().includes(term)
|
|
1460
|
+
? 1
|
|
1461
|
+
: 0;
|
|
1462
|
+
};
|
|
1463
|
+
if (searchTermFilters.length === 1) {
|
|
1464
|
+
const single = searchTermFilters[0];
|
|
1465
|
+
filteredNodes = filteredNodes.filter((n) => scoreNodeForTerm(n, single) > 0);
|
|
1466
|
+
}
|
|
1467
|
+
else {
|
|
1468
|
+
const scored = [];
|
|
1469
|
+
filteredNodes.forEach((n, idx) => {
|
|
1470
|
+
let matchedTerms = 0;
|
|
1471
|
+
let bestScore = 0;
|
|
1472
|
+
for (const term of searchTermFilters) {
|
|
1473
|
+
const s = scoreNodeForTerm(n, term);
|
|
1474
|
+
if (s > 0) {
|
|
1475
|
+
matchedTerms++;
|
|
1476
|
+
if (s > bestScore)
|
|
1477
|
+
bestScore = s;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
if (matchedTerms > 0) {
|
|
1481
|
+
scored.push({ node: n, score: matchedTerms * 10 + bestScore, idx });
|
|
1482
|
+
}
|
|
1483
|
+
});
|
|
1484
|
+
scored.sort((a, b) => b.score - a.score || a.idx - b.idx);
|
|
1485
|
+
filteredNodes = scored.map((s) => s.node);
|
|
1486
|
+
}
|
|
1450
1487
|
}
|
|
1451
1488
|
return filteredNodes;
|
|
1452
1489
|
}
|
|
@@ -2062,6 +2099,166 @@ export function auditGraphHealth(graph, options) {
|
|
|
2062
2099
|
recommendedHighlightNodeIds,
|
|
2063
2100
|
};
|
|
2064
2101
|
}
|
|
2102
|
+
function isTestSourcePath(filePath) {
|
|
2103
|
+
if (!filePath)
|
|
2104
|
+
return false;
|
|
2105
|
+
const norm = filePath.replace(/\\/g, "/");
|
|
2106
|
+
return (/\.(test|spec)\.[cm]?[jt]sx?$/i.test(norm) ||
|
|
2107
|
+
/(^|\/)(__tests__|__mocks__)\//i.test(norm));
|
|
2108
|
+
}
|
|
2109
|
+
function unwrapPassThroughExpression(expr) {
|
|
2110
|
+
let curr = expr;
|
|
2111
|
+
while (true) {
|
|
2112
|
+
if (ts.isParenthesizedExpression(curr)) {
|
|
2113
|
+
curr = curr.expression;
|
|
2114
|
+
}
|
|
2115
|
+
else if (ts.isAwaitExpression(curr)) {
|
|
2116
|
+
curr = curr.expression;
|
|
2117
|
+
}
|
|
2118
|
+
else if (ts.isAsExpression(curr) || ts.isSatisfiesExpression(curr)) {
|
|
2119
|
+
curr = curr.expression;
|
|
2120
|
+
}
|
|
2121
|
+
else if (ts.isTypeAssertionExpression(curr)) {
|
|
2122
|
+
curr = curr.expression;
|
|
2123
|
+
}
|
|
2124
|
+
else if (ts.isNonNullExpression(curr)) {
|
|
2125
|
+
curr = curr.expression;
|
|
2126
|
+
}
|
|
2127
|
+
else {
|
|
2128
|
+
return curr;
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
function areCallArgsPureForwardedIdentifiers(callExpr, allowedParamNames) {
|
|
2133
|
+
for (const arg of callExpr.arguments) {
|
|
2134
|
+
if (ts.isIdentifier(arg)) {
|
|
2135
|
+
if (arg.text === "undefined")
|
|
2136
|
+
return false;
|
|
2137
|
+
if (allowedParamNames && !allowedParamNames.has(arg.text))
|
|
2138
|
+
return false;
|
|
2139
|
+
continue;
|
|
2140
|
+
}
|
|
2141
|
+
if (ts.isSpreadElement(arg) && ts.isIdentifier(arg.expression)) {
|
|
2142
|
+
if (allowedParamNames && !allowedParamNames.has(arg.expression.text))
|
|
2143
|
+
return false;
|
|
2144
|
+
continue;
|
|
2145
|
+
}
|
|
2146
|
+
return false;
|
|
2147
|
+
}
|
|
2148
|
+
return true;
|
|
2149
|
+
}
|
|
2150
|
+
function isCallSnippetSpecialized(snippet, allowedParamNames, declaredParamCount) {
|
|
2151
|
+
const trimmed = snippet.trim();
|
|
2152
|
+
if (!trimmed || !trimmed.includes("("))
|
|
2153
|
+
return false;
|
|
2154
|
+
try {
|
|
2155
|
+
const sf = ts.createSourceFile("call_snippet.tsx", trimmed, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
2156
|
+
let foundCall = null;
|
|
2157
|
+
const visit = (n) => {
|
|
2158
|
+
if (foundCall)
|
|
2159
|
+
return;
|
|
2160
|
+
if (ts.isCallExpression(n)) {
|
|
2161
|
+
foundCall = n;
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
ts.forEachChild(n, visit);
|
|
2165
|
+
};
|
|
2166
|
+
ts.forEachChild(sf, visit);
|
|
2167
|
+
if (!foundCall)
|
|
2168
|
+
return false;
|
|
2169
|
+
const call = foundCall;
|
|
2170
|
+
// Truncation-safe check restricted strictly to the CallExpression's own argument slice
|
|
2171
|
+
const argSlice = trimmed.slice(call.arguments.pos, call.arguments.end);
|
|
2172
|
+
if (/[{[\]'"`?:+\-*/%=!&|<>]/.test(argSlice) ||
|
|
2173
|
+
/(?:^|[,(\s])\d/.test(argSlice)) {
|
|
2174
|
+
return true;
|
|
2175
|
+
}
|
|
2176
|
+
if (typeof declaredParamCount === "number" &&
|
|
2177
|
+
call.arguments.length > declaredParamCount) {
|
|
2178
|
+
return true;
|
|
2179
|
+
}
|
|
2180
|
+
return !areCallArgsPureForwardedIdentifiers(call, allowedParamNames);
|
|
2181
|
+
}
|
|
2182
|
+
catch {
|
|
2183
|
+
return false;
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
function isNonTrivialBodyInSourceFile(sf, targetLine1Based, contractLabel) {
|
|
2187
|
+
let matchedFn = null;
|
|
2188
|
+
const cleanName = contractLabel.split(".").pop() || contractLabel;
|
|
2189
|
+
const lineOf = (n) => sf.getLineAndCharacterOfPosition(n.getStart(sf)).line + 1;
|
|
2190
|
+
const visit = (n) => {
|
|
2191
|
+
if (matchedFn)
|
|
2192
|
+
return;
|
|
2193
|
+
if (ts.isFunctionDeclaration(n) || ts.isMethodDeclaration(n)) {
|
|
2194
|
+
const fnName = n.name && ts.isIdentifier(n.name) ? n.name.text : "";
|
|
2195
|
+
const l = lineOf(n);
|
|
2196
|
+
if ((targetLine1Based && Math.abs(l - targetLine1Based) <= 2) ||
|
|
2197
|
+
(fnName && fnName === cleanName)) {
|
|
2198
|
+
matchedFn = n;
|
|
2199
|
+
return;
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
else if (ts.isVariableDeclaration(n) && n.initializer) {
|
|
2203
|
+
const init = unwrapPassThroughExpression(n.initializer);
|
|
2204
|
+
if (ts.isArrowFunction(init) || ts.isFunctionExpression(init)) {
|
|
2205
|
+
const varName = ts.isIdentifier(n.name) ? n.name.text : "";
|
|
2206
|
+
const stmtLine = n.parent?.parent ? lineOf(n.parent.parent) : lineOf(n);
|
|
2207
|
+
if ((targetLine1Based &&
|
|
2208
|
+
(Math.abs(stmtLine - targetLine1Based) <= 2 ||
|
|
2209
|
+
Math.abs(lineOf(n) - targetLine1Based) <= 2)) ||
|
|
2210
|
+
(varName && varName === cleanName)) {
|
|
2211
|
+
matchedFn = init;
|
|
2212
|
+
return;
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
ts.forEachChild(n, visit);
|
|
2217
|
+
};
|
|
2218
|
+
ts.forEachChild(sf, visit);
|
|
2219
|
+
if (!matchedFn)
|
|
2220
|
+
return false;
|
|
2221
|
+
const fn = matchedFn;
|
|
2222
|
+
if (!fn.body)
|
|
2223
|
+
return false;
|
|
2224
|
+
let simpleParamNames = new Set();
|
|
2225
|
+
for (const p of fn.parameters) {
|
|
2226
|
+
if (p.initializer) {
|
|
2227
|
+
// Default parameter logic injects default values — not a pure 1-to-1 relay
|
|
2228
|
+
return true;
|
|
2229
|
+
}
|
|
2230
|
+
if (ts.isIdentifier(p.name)) {
|
|
2231
|
+
simpleParamNames?.add(p.name.text);
|
|
2232
|
+
}
|
|
2233
|
+
else {
|
|
2234
|
+
simpleParamNames = null;
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
let returnedExpr = null;
|
|
2238
|
+
if (ts.isBlock(fn.body)) {
|
|
2239
|
+
if (fn.body.statements.length !== 1)
|
|
2240
|
+
return true;
|
|
2241
|
+
const onlyStmt = fn.body.statements[0];
|
|
2242
|
+
if (ts.isReturnStatement(onlyStmt)) {
|
|
2243
|
+
if (!onlyStmt.expression)
|
|
2244
|
+
return true;
|
|
2245
|
+
returnedExpr = unwrapPassThroughExpression(onlyStmt.expression);
|
|
2246
|
+
}
|
|
2247
|
+
else if (ts.isExpressionStatement(onlyStmt)) {
|
|
2248
|
+
returnedExpr = unwrapPassThroughExpression(onlyStmt.expression);
|
|
2249
|
+
}
|
|
2250
|
+
else {
|
|
2251
|
+
return true;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
else {
|
|
2255
|
+
returnedExpr = unwrapPassThroughExpression(fn.body);
|
|
2256
|
+
}
|
|
2257
|
+
if (!returnedExpr || !ts.isCallExpression(returnedExpr)) {
|
|
2258
|
+
return true;
|
|
2259
|
+
}
|
|
2260
|
+
return !areCallArgsPureForwardedIdentifiers(returnedExpr, simpleParamNames);
|
|
2261
|
+
}
|
|
2065
2262
|
/**
|
|
2066
2263
|
* `chomp_find_redundancies` implementation ([PAT-MCP-08], [PAT-MCP-09]).
|
|
2067
2264
|
*
|
|
@@ -2072,6 +2269,34 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2072
2269
|
const index = buildGraphIndex(graph);
|
|
2073
2270
|
const maxItems = Math.max(1, Math.min(options?.limit ?? 25, 100));
|
|
2074
2271
|
const pkgFilter = options?.packageName?.trim();
|
|
2272
|
+
const repoRoot = options?.repoPath ? resolve(options.repoPath) : undefined;
|
|
2273
|
+
const sourceFileCache = new Map();
|
|
2274
|
+
const loadCachedSourceFile = (relPath) => {
|
|
2275
|
+
if (!repoRoot || !relPath)
|
|
2276
|
+
return null;
|
|
2277
|
+
const abs = resolve(repoRoot, relPath);
|
|
2278
|
+
if (sourceFileCache.has(abs))
|
|
2279
|
+
return sourceFileCache.get(abs) ?? null;
|
|
2280
|
+
if (!existsSync(abs)) {
|
|
2281
|
+
sourceFileCache.set(abs, null);
|
|
2282
|
+
return null;
|
|
2283
|
+
}
|
|
2284
|
+
try {
|
|
2285
|
+
const text = readFileSync(abs, "utf8");
|
|
2286
|
+
const kind = /\.tsx$/i.test(abs)
|
|
2287
|
+
? ts.ScriptKind.TSX
|
|
2288
|
+
: /\.jsx$/i.test(abs)
|
|
2289
|
+
? ts.ScriptKind.JSX
|
|
2290
|
+
: ts.ScriptKind.TS;
|
|
2291
|
+
const sf = ts.createSourceFile(abs, text, ts.ScriptTarget.Latest, true, kind);
|
|
2292
|
+
sourceFileCache.set(abs, sf);
|
|
2293
|
+
return sf;
|
|
2294
|
+
}
|
|
2295
|
+
catch {
|
|
2296
|
+
sourceFileCache.set(abs, null);
|
|
2297
|
+
return null;
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2075
2300
|
const matchesPkg = (nodeId) => {
|
|
2076
2301
|
if (!pkgFilter)
|
|
2077
2302
|
return true;
|
|
@@ -2080,7 +2305,7 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2080
2305
|
const ev = node ? getPrimaryEvidence(node) : {};
|
|
2081
2306
|
return packageMatchesFilter(pkg, ev.filePath, pkgFilter);
|
|
2082
2307
|
};
|
|
2083
|
-
// 1. Pass-Through Middlemen (1-to-1 relay contracts with no side-effects)
|
|
2308
|
+
// 1. Pass-Through Middlemen (true 1-to-1 identity relay contracts with no specialization, branching, or side-effects)
|
|
2084
2309
|
const passThroughMiddlemen = [];
|
|
2085
2310
|
for (const node of index.nodeById.values()) {
|
|
2086
2311
|
if (node.type !== "CONTRACT")
|
|
@@ -2091,10 +2316,13 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2091
2316
|
continue;
|
|
2092
2317
|
if (NON_EXECUTABLE_CONTRACT_ENTITY_TYPES.has(node.entityType))
|
|
2093
2318
|
continue;
|
|
2094
|
-
if (node.entityType === "EXPORTED_MODULE")
|
|
2319
|
+
if (node.entityType === "EXPORTED_MODULE" || node.entityType === "REACT_COMPONENT")
|
|
2095
2320
|
continue;
|
|
2096
2321
|
if (!matchesPkg(node.id))
|
|
2097
2322
|
continue;
|
|
2323
|
+
const nodeEv = getPrimaryEvidence(node);
|
|
2324
|
+
if (isTestSourcePath(nodeEv.filePath))
|
|
2325
|
+
continue;
|
|
2098
2326
|
const callers = index.flowInSourcesByTarget.get(node.id) ?? [];
|
|
2099
2327
|
const targets = index.flowOutTargetsBySource.get(node.id) ?? [];
|
|
2100
2328
|
const unresolved = index.unresolvedCallsByNodeId.get(node.id) ?? [];
|
|
@@ -2115,6 +2343,48 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2115
2343
|
const isRenderRelay = rawOutEdges.some((e) => e.targetId === targetNode.id && e.entityType === "RENDERS");
|
|
2116
2344
|
if (hasOpenConnectorCall || isRenderRelay)
|
|
2117
2345
|
continue;
|
|
2346
|
+
// Exclude functions that call the target at multiple call-sites (e.g. formatRange(fmt(a), fmt(b)))
|
|
2347
|
+
const targetCallEdges = rawOutEdges.filter((e) => e.targetId === targetNode.id);
|
|
2348
|
+
if (targetCallEdges.length > 1)
|
|
2349
|
+
continue;
|
|
2350
|
+
const singleTargetEdge = targetCallEdges[0];
|
|
2351
|
+
if (singleTargetEdge &&
|
|
2352
|
+
Array.isArray(singleTargetEdge.evidence) &&
|
|
2353
|
+
new Set(singleTargetEdge.evidence
|
|
2354
|
+
.filter((r) => !r?.evidenceRole || r.evidenceRole === "syntax-call")
|
|
2355
|
+
.map((r) => (typeof r?.lineNumber === "number" ? r.lineNumber : null))
|
|
2356
|
+
.filter((n) => n !== null)).size > 1) {
|
|
2357
|
+
continue;
|
|
2358
|
+
}
|
|
2359
|
+
// Exclude argument-specializing / default-injecting / transforming calls
|
|
2360
|
+
const nodeMeta = parseNodeMeta(node);
|
|
2361
|
+
const pvInputs = Array.isArray(nodeMeta.portValves?.inputs)
|
|
2362
|
+
? nodeMeta.portValves.inputs
|
|
2363
|
+
: null;
|
|
2364
|
+
let allowedParams = null;
|
|
2365
|
+
let declaredParamCount = null;
|
|
2366
|
+
if (pvInputs) {
|
|
2367
|
+
const hasRest = pvInputs.some((inp) => typeof inp?.name === "string" && inp.name.startsWith("..."));
|
|
2368
|
+
if (!hasRest) {
|
|
2369
|
+
declaredParamCount = pvInputs.length;
|
|
2370
|
+
}
|
|
2371
|
+
const names = pvInputs
|
|
2372
|
+
.map((inp) => String(inp?.name ?? "").replace(/^\.\.\./, "").trim())
|
|
2373
|
+
.filter(Boolean);
|
|
2374
|
+
if (names.length === pvInputs.length && names.every((nm) => /^[A-Za-z_$][\w$]*$/.test(nm))) {
|
|
2375
|
+
allowedParams = new Set(names);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
const callEv = singleTargetEdge ? getPrimaryEvidence(singleTargetEdge) : {};
|
|
2379
|
+
if (callEv.snippet &&
|
|
2380
|
+
isCallSnippetSpecialized(callEv.snippet, allowedParams, declaredParamCount)) {
|
|
2381
|
+
continue;
|
|
2382
|
+
}
|
|
2383
|
+
const sf = loadCachedSourceFile(nodeEv.filePath);
|
|
2384
|
+
if (sf &&
|
|
2385
|
+
isNonTrivialBodyInSourceFile(sf, nodeEv.lineNumber, cleanNodeLabel(node.name))) {
|
|
2386
|
+
continue;
|
|
2387
|
+
}
|
|
2118
2388
|
const nodeRef = toNodeSummaryRef(node, index.resolveNodePkg);
|
|
2119
2389
|
const targetRef = toNodeSummaryRef(targetNode, index.resolveNodePkg);
|
|
2120
2390
|
const callerRefs = callers
|
|
@@ -2140,6 +2410,8 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2140
2410
|
continue;
|
|
2141
2411
|
if (node.entityType === INIT_BLOCK_ENTITY_TYPE)
|
|
2142
2412
|
continue;
|
|
2413
|
+
if (isTestSourcePath(getPrimaryEvidence(node).filePath))
|
|
2414
|
+
continue;
|
|
2143
2415
|
const targets = index.flowOutTargetsBySource.get(node.id) ?? [];
|
|
2144
2416
|
if (targets.length < 2)
|
|
2145
2417
|
continue;
|
|
@@ -2198,6 +2470,8 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2198
2470
|
continue;
|
|
2199
2471
|
if (NON_EXECUTABLE_CONTRACT_ENTITY_TYPES.has(node.entityType))
|
|
2200
2472
|
continue;
|
|
2473
|
+
if (isTestSourcePath(getPrimaryEvidence(node).filePath))
|
|
2474
|
+
continue;
|
|
2201
2475
|
if (node.entityType === "PUBLIC_METHOD" ||
|
|
2202
2476
|
node.entityType === "NEXTJS_PAGE" ||
|
|
2203
2477
|
node.entityType === "NEXTJS_LAYOUT" ||
|
|
@@ -2371,22 +2645,62 @@ export function checkGraphBoundaries(graph, options) {
|
|
|
2371
2645
|
lineNumber: ev.lineNumber,
|
|
2372
2646
|
});
|
|
2373
2647
|
}
|
|
2374
|
-
// 2. Assign topological architectural tiers to packages
|
|
2648
|
+
// 2. Assign topological architectural tiers to packages (combining call topology with structural package roles)
|
|
2649
|
+
const serverRoleEntityTypes = new Set([
|
|
2650
|
+
"HTTP_ENDPOINT",
|
|
2651
|
+
"API_ENDPOINT",
|
|
2652
|
+
"MIDDLEWARE",
|
|
2653
|
+
"NEXTJS_MIDDLEWARE",
|
|
2654
|
+
]);
|
|
2655
|
+
const hasServerRoleByPkg = new Map();
|
|
2656
|
+
for (const node of index.nodeById.values()) {
|
|
2657
|
+
if (isHiddenNode(node))
|
|
2658
|
+
continue;
|
|
2659
|
+
if (!serverRoleEntityTypes.has(node.entityType))
|
|
2660
|
+
continue;
|
|
2661
|
+
const ownerPkg = index.resolveNodePkg(node.id);
|
|
2662
|
+
if (ownerPkg) {
|
|
2663
|
+
hasServerRoleByPkg.set(ownerPkg, true);
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2375
2666
|
const packageLayers = [];
|
|
2376
2667
|
const tierRankByPkg = new Map();
|
|
2377
2668
|
for (const [pkg, duNode] of index.deploymentUnitsByPkg.entries()) {
|
|
2378
2669
|
const outs = [...(outPkgsByPkg.get(pkg) ?? [])].sort();
|
|
2379
2670
|
const ins = [...(inPkgsByPkg.get(pkg) ?? [])].sort();
|
|
2380
|
-
const
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2671
|
+
const pkgPathNorm = (index.pathPrefixByPkg.get(pkg) ?? "").replace(/\\/g, "/");
|
|
2672
|
+
const pkgShort = pkg.toLowerCase().replace(/^@[^/]+\//, "");
|
|
2673
|
+
const isAppsDirPkg = /^apps\//i.test(pkgPathNorm);
|
|
2674
|
+
const hasServerRole = Boolean(hasServerRoleByPkg.get(pkg));
|
|
2675
|
+
const isSharedUiPkg = !isAppsDirPkg &&
|
|
2676
|
+
!hasServerRole &&
|
|
2677
|
+
(pkgShort === "ui" ||
|
|
2678
|
+
pkgShort.endsWith("-ui") ||
|
|
2679
|
+
pkgShort.endsWith("_ui") ||
|
|
2680
|
+
pkgShort === "design-system" ||
|
|
2681
|
+
pkgShort.endsWith("-design-system"));
|
|
2682
|
+
const isAdapterPkg = pkgShort === "db" ||
|
|
2683
|
+
pkgShort.endsWith("-db") ||
|
|
2684
|
+
pkgShort.endsWith("_db") ||
|
|
2685
|
+
pkgShort.includes("adapter");
|
|
2384
2686
|
let architecturalTier;
|
|
2385
2687
|
let tierRank;
|
|
2386
2688
|
if (outs.length === 0 && ins.length === 0) {
|
|
2387
2689
|
architecturalTier = "ISOLATED_PACKAGE";
|
|
2388
2690
|
tierRank = 0;
|
|
2389
2691
|
}
|
|
2692
|
+
else if (isAppsDirPkg) {
|
|
2693
|
+
// Deployable apps under `apps/*` always sit at the top entry tier (tierRank 0) so
|
|
2694
|
+
// shared `packages/*` libraries cannot import upward from application shells.
|
|
2695
|
+
architecturalTier = "ENTRY_APPLICATION";
|
|
2696
|
+
tierRank = 0;
|
|
2697
|
+
}
|
|
2698
|
+
else if (hasServerRole) {
|
|
2699
|
+
// Backend packages owning HTTP/API endpoints or middleware are application/service
|
|
2700
|
+
// boundaries (tierRank 0..1), never FOUNDATION_CORE even when outs.length === 0.
|
|
2701
|
+
architecturalTier = ins.length === 0 ? "ENTRY_APPLICATION" : "SERVICE_ORCHESTRATOR";
|
|
2702
|
+
tierRank = ins.length === 0 ? 0 : 1;
|
|
2703
|
+
}
|
|
2390
2704
|
else if (outs.length === 0 && isAdapterPkg && ins.length > 0) {
|
|
2391
2705
|
architecturalTier = "INFRASTRUCTURE_ADAPTER";
|
|
2392
2706
|
tierRank = 2;
|
|
@@ -2395,6 +2709,12 @@ export function checkGraphBoundaries(graph, options) {
|
|
|
2395
2709
|
architecturalTier = "FOUNDATION_CORE";
|
|
2396
2710
|
tierRank = 3;
|
|
2397
2711
|
}
|
|
2712
|
+
else if (isSharedUiPkg) {
|
|
2713
|
+
// Shared UI / design-system component libraries sit below application/API orchestrators
|
|
2714
|
+
// (tierRank 2), allowing imports from foundation/utils (3) while flagging upward imports into API/apps (0..1).
|
|
2715
|
+
architecturalTier = "INFRASTRUCTURE_ADAPTER";
|
|
2716
|
+
tierRank = 2;
|
|
2717
|
+
}
|
|
2398
2718
|
else if (ins.length === 0) {
|
|
2399
2719
|
architecturalTier = "ENTRY_APPLICATION";
|
|
2400
2720
|
tierRank = 0;
|
|
@@ -15,7 +15,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
15
15
|
import { basename, resolve } from "node:path";
|
|
16
16
|
import { CORE_EXTRACTOR_VERSION, analyzeTarget } from "@getchomp/core";
|
|
17
17
|
import { z } from "zod";
|
|
18
|
-
import { auditDesignSystem, createDesignSystemPlugin, diffDesignSystem, } from "../../designSystemPlugin.js";
|
|
18
|
+
import { auditDesignSystem, createDesignSystemPlugin, diffDesignSystem, formatCompactDesignSystemAudit, } from "../../designSystemPlugin.js";
|
|
19
19
|
import { defineChompPlugin } from "../../pluginRunner.js";
|
|
20
20
|
function resolveLiveGraphIfDirty(repoPath, dbPath) {
|
|
21
21
|
let needsLive = !existsSync(dbPath);
|
|
@@ -143,6 +143,10 @@ export const designSystemPluginModule = defineChompPlugin({
|
|
|
143
143
|
.optional()
|
|
144
144
|
.describe("When true, updates .chomp/current_view.json with L1_DESIGN_SYSTEM Spotlight highlights. Leave false (default) during coding tasks; pass true only when answering user questions or visual walkthrough requests."),
|
|
145
145
|
createView: z.boolean().optional().describe("Alias for create_view (camelCase)"),
|
|
146
|
+
verbose: z
|
|
147
|
+
.boolean()
|
|
148
|
+
.optional()
|
|
149
|
+
.describe("When true, returns the full raw tokenRegistry, routeComposition, atomicHierarchy, and per-component AST profiles instead of the compact orientation summary (default: false)."),
|
|
146
150
|
},
|
|
147
151
|
handler: async (args, ctx) => {
|
|
148
152
|
const persistOverlays = args.persist_overlays ?? args.persistOverlays ?? existsSync(ctx.dbPath);
|
|
@@ -193,7 +197,10 @@ export const designSystemPluginModule = defineChompPlugin({
|
|
|
193
197
|
},
|
|
194
198
|
});
|
|
195
199
|
}
|
|
196
|
-
return report
|
|
200
|
+
return formatCompactDesignSystemAudit(report, {
|
|
201
|
+
verbose: Boolean(args.verbose),
|
|
202
|
+
hasSearchTerm: Boolean(args.search_term ?? args.searchTerm),
|
|
203
|
+
});
|
|
197
204
|
},
|
|
198
205
|
},
|
|
199
206
|
{
|
|
@@ -59,18 +59,18 @@ export declare const enrichNodesPluginModule: {
|
|
|
59
59
|
badgeMode: z.ZodOptional<z.ZodEnum<["fold_into_callers", "badge_on_node"]>>;
|
|
60
60
|
}, "strip", z.ZodTypeAny, {
|
|
61
61
|
nodeId: string;
|
|
62
|
+
summary?: string | undefined;
|
|
62
63
|
humanLabel?: string | undefined;
|
|
63
64
|
domain?: string | undefined;
|
|
64
|
-
summary?: string | undefined;
|
|
65
65
|
rationale?: string | undefined;
|
|
66
66
|
action?: "middleware_badge" | "component_badge" | "micro_node" | "station_node" | undefined;
|
|
67
67
|
badgeLabel?: string | undefined;
|
|
68
68
|
badgeMode?: "fold_into_callers" | "badge_on_node" | undefined;
|
|
69
69
|
}, {
|
|
70
70
|
nodeId: string;
|
|
71
|
+
summary?: string | undefined;
|
|
71
72
|
humanLabel?: string | undefined;
|
|
72
73
|
domain?: string | undefined;
|
|
73
|
-
summary?: string | undefined;
|
|
74
74
|
rationale?: string | undefined;
|
|
75
75
|
action?: "middleware_badge" | "component_badge" | "micro_node" | "station_node" | undefined;
|
|
76
76
|
badgeLabel?: string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getchomp/mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.46",
|
|
4
4
|
"description": "Chomp MCP server — codebase map, blast-radius, health, and design-system tools for AI coding agents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://getchomp.dev",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
29
29
|
"typescript": "^5.3.3",
|
|
30
30
|
"zod": "^3.23.8",
|
|
31
|
-
"@getchomp/
|
|
32
|
-
"@getchomp/
|
|
31
|
+
"@getchomp/db": "0.2.46",
|
|
32
|
+
"@getchomp/core": "0.2.46"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"tsx": "^4.19.0"
|