@getchomp/mcp 0.2.45 → 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/index.d.ts +29 -0
- package/dist/index.js +184 -27
- package/dist/intelligence.d.ts +5 -2
- package/dist/intelligence.js +368 -58
- package/dist/plugins/enrich-nodes/index.d.ts +2 -2
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -46,7 +46,9 @@ export declare function loadActiveGraphWithShims(repoPath: string, dbPath: strin
|
|
|
46
46
|
* Checks staleness (`[PAT-DB-03]`, Principle of Incomplete Truth) before reporting a delta.
|
|
47
47
|
*/
|
|
48
48
|
export declare function computeGraphDeltaWithShims(repoPath: string, dbPath: string, repoId: string, storageFactory?: (dbPath: string) => ChompStorage): Promise<GraphDelta & {
|
|
49
|
+
gateStatus?: "PASS" | "WARN";
|
|
49
50
|
architecturalGate?: ArchitecturalDiffGate;
|
|
51
|
+
designSystemGate?: CompactDesignSystemDiffGate;
|
|
50
52
|
}>;
|
|
51
53
|
export declare function computeGitRefDeltaWithShims(repoPath: string, options?: {
|
|
52
54
|
baseRef?: string;
|
|
@@ -57,8 +59,22 @@ export declare function computeGitRefDeltaWithShims(repoPath: string, options?:
|
|
|
57
59
|
targetRef: string;
|
|
58
60
|
isWorkingTreeSnapshot: boolean;
|
|
59
61
|
snapshotAt?: string;
|
|
62
|
+
gateStatus?: "PASS" | "WARN";
|
|
60
63
|
architecturalGate?: ArchitecturalDiffGate;
|
|
64
|
+
designSystemGate?: CompactDesignSystemDiffGate;
|
|
61
65
|
}>;
|
|
66
|
+
export interface CompactDesignSystemDiffGate {
|
|
67
|
+
gateStatus: "PASS" | "WARN";
|
|
68
|
+
summary: {
|
|
69
|
+
newRawPrimitiveCount: number;
|
|
70
|
+
newHardcodedLiteralCount: number;
|
|
71
|
+
newArbitraryTailwindCount: number;
|
|
72
|
+
newUndefinedTokenCount: number;
|
|
73
|
+
newInvariantViolationCount: number;
|
|
74
|
+
newContrastFailureCount: number;
|
|
75
|
+
};
|
|
76
|
+
newIssues?: Record<string, Array<any>>;
|
|
77
|
+
}
|
|
62
78
|
export interface ArchitecturalDiffGate {
|
|
63
79
|
gateStatus: "PASS" | "WARN";
|
|
64
80
|
summary: {
|
|
@@ -66,12 +82,14 @@ export interface ArchitecturalDiffGate {
|
|
|
66
82
|
newDuplicateFlowCount: number;
|
|
67
83
|
newDuplicateSymbolCount: number;
|
|
68
84
|
newBoundaryViolationCount: number;
|
|
85
|
+
newBoundaryAdvisoryCount?: number;
|
|
69
86
|
newCycleCount: number;
|
|
70
87
|
};
|
|
71
88
|
newPassThroughWrappers: Array<any>;
|
|
72
89
|
newDuplicateFlows: Array<any>;
|
|
73
90
|
newDuplicateSymbols: Array<any>;
|
|
74
91
|
newBoundaryViolations: Array<any>;
|
|
92
|
+
newBoundaryAdvisories?: Array<any>;
|
|
75
93
|
newCycles: {
|
|
76
94
|
packageCycles: Array<any>;
|
|
77
95
|
contractCycles: Array<any>;
|
|
@@ -81,6 +99,7 @@ export declare function computeArchitecturalDiffGate(baseGraph: RepresentationGr
|
|
|
81
99
|
repoPath?: string;
|
|
82
100
|
packageName?: string;
|
|
83
101
|
limit?: number;
|
|
102
|
+
isTargetOnDisk?: boolean;
|
|
84
103
|
}): ArchitecturalDiffGate;
|
|
85
104
|
export declare function resolveLiveAndBaseGraphsForMcp(repoPath: string, dbPath: string, repoId: string, options?: {
|
|
86
105
|
needBaseGraph?: boolean;
|
|
@@ -100,11 +119,14 @@ export declare function formatCompactMcpDiff(delta: GraphDelta & {
|
|
|
100
119
|
targetRef?: string;
|
|
101
120
|
isWorkingTreeSnapshot?: boolean;
|
|
102
121
|
snapshotAt?: string;
|
|
122
|
+
gateStatus?: "PASS" | "WARN";
|
|
103
123
|
architecturalGate?: ArchitecturalDiffGate;
|
|
124
|
+
designSystemGate?: CompactDesignSystemDiffGate;
|
|
104
125
|
}, options?: {
|
|
105
126
|
includeLexicalShift?: boolean;
|
|
106
127
|
includeUnchanged?: boolean;
|
|
107
128
|
verbose?: boolean;
|
|
129
|
+
maxNodes?: number;
|
|
108
130
|
maxEdges?: number;
|
|
109
131
|
}): {
|
|
110
132
|
nodes: Record<string, import("@getchomp/core").DiffNode>;
|
|
@@ -125,6 +147,7 @@ export declare function formatCompactMcpDiff(delta: GraphDelta & {
|
|
|
125
147
|
UNCHANGED: number;
|
|
126
148
|
};
|
|
127
149
|
};
|
|
150
|
+
designSystemGate?: CompactDesignSystemDiffGate | undefined;
|
|
128
151
|
architecturalGate?: ArchitecturalDiffGate | undefined;
|
|
129
152
|
baseExtractorVersion: string | undefined;
|
|
130
153
|
targetExtractorVersion: string | undefined;
|
|
@@ -136,6 +159,7 @@ export declare function formatCompactMcpDiff(delta: GraphDelta & {
|
|
|
136
159
|
baseCommitSha: string | undefined;
|
|
137
160
|
baseRef?: string | undefined;
|
|
138
161
|
baseStatus: "FRESH" | "STALE";
|
|
162
|
+
gateStatus?: "PASS" | "WARN" | undefined;
|
|
139
163
|
} | {
|
|
140
164
|
summary: {
|
|
141
165
|
omittedNoise: {
|
|
@@ -144,6 +168,9 @@ export declare function formatCompactMcpDiff(delta: GraphDelta & {
|
|
|
144
168
|
modifiedSameEndpointEdges: number;
|
|
145
169
|
externalPackageCallEdges: number;
|
|
146
170
|
builtinOrDynamicEdges: number;
|
|
171
|
+
testFileNodes: number;
|
|
172
|
+
testFileEdges: number;
|
|
173
|
+
truncatedNodes: number;
|
|
147
174
|
truncatedEdges: number;
|
|
148
175
|
};
|
|
149
176
|
nodes: {
|
|
@@ -163,6 +190,7 @@ export declare function formatCompactMcpDiff(delta: GraphDelta & {
|
|
|
163
190
|
};
|
|
164
191
|
nodes: Record<string, any>;
|
|
165
192
|
edges: Record<string, any>;
|
|
193
|
+
designSystemGate?: CompactDesignSystemDiffGate | undefined;
|
|
166
194
|
architecturalGate?: ArchitecturalDiffGate | undefined;
|
|
167
195
|
baseExtractorVersion: string | undefined;
|
|
168
196
|
targetExtractorVersion: string | undefined;
|
|
@@ -174,6 +202,7 @@ export declare function formatCompactMcpDiff(delta: GraphDelta & {
|
|
|
174
202
|
baseCommitSha: string | undefined;
|
|
175
203
|
baseRef?: string | undefined;
|
|
176
204
|
baseStatus: "FRESH" | "STALE";
|
|
205
|
+
gateStatus?: "PASS" | "WARN" | undefined;
|
|
177
206
|
};
|
|
178
207
|
export declare function formatCompactMcpNodes(nodes: Array<Record<string, any>>, options?: {
|
|
179
208
|
verbose?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,9 @@ import { applyActivePluginProjections, discoverPluginsInDir, listChompPlugins, l
|
|
|
13
13
|
import "./plugins/index.js";
|
|
14
14
|
import { SEMANTIC_OVERLAY_LAYER, classifySemanticOverlayMap, isEnrichmentTargetNode, } from "./enrichNodesPlugin.js";
|
|
15
15
|
import { getConventionsReference } from "./conventionsReference.js";
|
|
16
|
+
import { diffDesignSystem } from "./designSystemPlugin.js";
|
|
17
|
+
import { resolveBaselinePath } from "./designSystem/baseline.js";
|
|
18
|
+
import { resolveDesignSystemConfig } from "./designSystem/config.js";
|
|
16
19
|
export { auditGraphHealth, buildActiveViewUrl, checkGraphBoundaries, computeBlastRadius, filterNodesForMcp, findGraphRedundancies, formatEnrichNodesSummary, hydrateNodeOverlays, packageMatchesFilter, resolveViewNodeIds, resolveViewTargetAltitude, } from "./intelligence.js";
|
|
17
20
|
export { PLUGINS_STATE_DIR_REL, PLUGIN_LAST_RUN_FILENAME, applyActivePluginProjections, buildOverlayEvidence, collectPluginRepoFiles, collectPluginStateFiles, computeFileOverlayHash, defineChompPlugin, discoverPluginsInDir, getChompPlugin, getPluginEnvStatus, getPluginLastRunPath, getPluginMcpToolSummaries, getPluginSettingsPath, getPluginStateDir, getPluginStateDirRel, getRegisteredPluginDefaultLayers, isPluginLayerEnabled, isRegisteredStructuralPluginOverlay, listChompPlugins, loadPluginSettings, readPluginLastRun, readRepoOverlayLayerToggles, registerChompPlugin, resolveActiveUiBaseUrl, resolvePluginSecret, resolveRepoGitBranch, resolveRepoName, runAllChompPlugins, runChompPlugin, savePluginSettings, unregisterChompPlugin, writePluginActiveView, writePluginLastRun, } from "./pluginRunner.js";
|
|
18
21
|
export { BUILTIN_PLUGINS_DIR, discoverBuiltInPlugins } from "./plugins/index.js";
|
|
@@ -484,14 +487,22 @@ export async function computeGraphDeltaWithShims(repoPath, dbPath, repoId, stora
|
|
|
484
487
|
const delta = compareGraphs(baseProjected, currentProjected);
|
|
485
488
|
const architecturalGate = computeArchitecturalDiffGate(baseProjected, currentProjected, {
|
|
486
489
|
repoPath,
|
|
490
|
+
isTargetOnDisk: true,
|
|
487
491
|
});
|
|
492
|
+
const designSystemGate = await maybeComputeCompactDesignSystemGate(repoPath, repoId, currentProjected);
|
|
493
|
+
const gateStatus = architecturalGate.gateStatus === "PASS" &&
|
|
494
|
+
(!designSystemGate || designSystemGate.gateStatus === "PASS")
|
|
495
|
+
? "PASS"
|
|
496
|
+
: "WARN";
|
|
488
497
|
return {
|
|
489
498
|
...delta,
|
|
490
499
|
headCommitSha,
|
|
491
500
|
baseExtractorVersion: baseRaw.extractorVersion,
|
|
492
501
|
targetExtractorVersion: currentRaw.extractorVersion,
|
|
493
502
|
baseStatus: "FRESH",
|
|
503
|
+
gateStatus,
|
|
494
504
|
architecturalGate,
|
|
505
|
+
...(designSystemGate ? { designSystemGate } : {}),
|
|
495
506
|
};
|
|
496
507
|
}
|
|
497
508
|
function resolveMcpGitCommitSha(repoPath, ref) {
|
|
@@ -650,6 +661,7 @@ export async function computeGitRefDeltaWithShims(repoPath, options) {
|
|
|
650
661
|
const delta = compareGraphs(baseProjected, targetProjected);
|
|
651
662
|
const architecturalGate = computeArchitecturalDiffGate(baseProjected, targetProjected, {
|
|
652
663
|
repoPath,
|
|
664
|
+
isTargetOnDisk: false,
|
|
653
665
|
});
|
|
654
666
|
return {
|
|
655
667
|
...delta,
|
|
@@ -662,6 +674,7 @@ export async function computeGitRefDeltaWithShims(repoPath, options) {
|
|
|
662
674
|
baseRef,
|
|
663
675
|
targetRef,
|
|
664
676
|
isWorkingTreeSnapshot: false,
|
|
677
|
+
gateStatus: architecturalGate.gateStatus,
|
|
665
678
|
architecturalGate,
|
|
666
679
|
};
|
|
667
680
|
}
|
|
@@ -674,7 +687,14 @@ export async function computeGitRefDeltaWithShims(repoPath, options) {
|
|
|
674
687
|
const delta = compareGraphs(baseProjected, currentProjected);
|
|
675
688
|
const architecturalGate = computeArchitecturalDiffGate(baseProjected, currentProjected, {
|
|
676
689
|
repoPath,
|
|
690
|
+
isTargetOnDisk: true,
|
|
677
691
|
});
|
|
692
|
+
const repoIdForDs = resolveRepoName(repoPath).toLowerCase().replace(/[^a-z0-9_-]/g, "_");
|
|
693
|
+
const designSystemGate = await maybeComputeCompactDesignSystemGate(repoPath, repoIdForDs, currentProjected);
|
|
694
|
+
const gateStatus = architecturalGate.gateStatus === "PASS" &&
|
|
695
|
+
(!designSystemGate || designSystemGate.gateStatus === "PASS")
|
|
696
|
+
? "PASS"
|
|
697
|
+
: "WARN";
|
|
678
698
|
return {
|
|
679
699
|
...delta,
|
|
680
700
|
baseCommitSha: baseSha,
|
|
@@ -686,9 +706,50 @@ export async function computeGitRefDeltaWithShims(repoPath, options) {
|
|
|
686
706
|
targetRef: "WORKING_TREE",
|
|
687
707
|
isWorkingTreeSnapshot: true,
|
|
688
708
|
snapshotAt,
|
|
709
|
+
gateStatus,
|
|
689
710
|
architecturalGate,
|
|
711
|
+
...(designSystemGate ? { designSystemGate } : {}),
|
|
690
712
|
};
|
|
691
713
|
}
|
|
714
|
+
async function maybeComputeCompactDesignSystemGate(repoPath, repoId, liveGraph) {
|
|
715
|
+
try {
|
|
716
|
+
const resolvedCfg = resolveDesignSystemConfig(repoPath);
|
|
717
|
+
const baselinePath = resolveBaselinePath(repoPath, resolvedCfg.config.baseline.path);
|
|
718
|
+
if (!existsSync(baselinePath))
|
|
719
|
+
return undefined;
|
|
720
|
+
const ds = await diffDesignSystem({
|
|
721
|
+
repoPath,
|
|
722
|
+
repoId,
|
|
723
|
+
graph: liveGraph,
|
|
724
|
+
});
|
|
725
|
+
if (!ds.hasBaseline || ds.gateStatus === "NO_BASELINE")
|
|
726
|
+
return undefined;
|
|
727
|
+
const gateStatus = ds.gateStatus === "PASS" ? "PASS" : "WARN";
|
|
728
|
+
const nonEmptyIssues = {};
|
|
729
|
+
if (gateStatus === "WARN" && ds.newIssues) {
|
|
730
|
+
for (const [k, arr] of Object.entries(ds.newIssues)) {
|
|
731
|
+
if (Array.isArray(arr) && arr.length > 0) {
|
|
732
|
+
nonEmptyIssues[k] = arr.slice(0, 5);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return {
|
|
737
|
+
gateStatus,
|
|
738
|
+
summary: {
|
|
739
|
+
newRawPrimitiveCount: ds.summary.newRawPrimitiveCount ?? 0,
|
|
740
|
+
newHardcodedLiteralCount: ds.summary.newHardcodedLiteralCount ?? 0,
|
|
741
|
+
newArbitraryTailwindCount: ds.summary.newArbitraryTailwindCount ?? 0,
|
|
742
|
+
newUndefinedTokenCount: ds.summary.newUndefinedTokenCount ?? 0,
|
|
743
|
+
newInvariantViolationCount: ds.summary.newInvariantViolationCount ?? 0,
|
|
744
|
+
newContrastFailureCount: ds.summary.newContrastFailureCount ?? 0,
|
|
745
|
+
},
|
|
746
|
+
...(Object.keys(nonEmptyIssues).length > 0 ? { newIssues: nonEmptyIssues } : {}),
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
catch {
|
|
750
|
+
return undefined;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
692
753
|
export function computeArchitecturalDiffGate(baseGraph, targetGraph, options) {
|
|
693
754
|
const baseRed = findGraphRedundancies(baseGraph, {
|
|
694
755
|
packageName: options?.packageName,
|
|
@@ -697,9 +758,23 @@ export function computeArchitecturalDiffGate(baseGraph, targetGraph, options) {
|
|
|
697
758
|
const targetRed = findGraphRedundancies(targetGraph, {
|
|
698
759
|
packageName: options?.packageName,
|
|
699
760
|
limit: 100,
|
|
761
|
+
...(options?.isTargetOnDisk !== false && options?.repoPath
|
|
762
|
+
? { repoPath: options.repoPath }
|
|
763
|
+
: {}),
|
|
700
764
|
});
|
|
765
|
+
const baseNodeIds = new Set(baseGraph.nodes.map((n) => n.id));
|
|
701
766
|
const baseMiddlemenIds = new Set(baseRed.passThroughMiddlemen.map((m) => m.middleman.id));
|
|
702
|
-
const newPassThroughWrappers = targetRed.passThroughMiddlemen.filter((m) =>
|
|
767
|
+
const newPassThroughWrappers = targetRed.passThroughMiddlemen.filter((m) => {
|
|
768
|
+
if (baseMiddlemenIds.has(m.middleman.id))
|
|
769
|
+
return false;
|
|
770
|
+
// Do not penalize backward-compatible cross-package facade adapters (e.g. refactoring an
|
|
771
|
+
// existing @app/ui helper to delegate to a newly extracted @app/utils foundation package).
|
|
772
|
+
if (m.crossesPackageBoundary && baseNodeIds.has(m.middleman.id))
|
|
773
|
+
return false;
|
|
774
|
+
if (m.crossesPackageBoundary)
|
|
775
|
+
return false;
|
|
776
|
+
return true;
|
|
777
|
+
});
|
|
703
778
|
const baseSeqCallersBySig = new Map();
|
|
704
779
|
for (const seq of baseRed.duplicateStorySequences) {
|
|
705
780
|
const sig = seq.sharedTargets.map((t) => t.id).sort().join("::");
|
|
@@ -727,7 +802,9 @@ export function computeArchitecturalDiffGate(baseGraph, targetGraph, options) {
|
|
|
727
802
|
});
|
|
728
803
|
const violationKey = (v) => `${v.ruleId}::${v.sourcePackage}::${v.targetPackage}`;
|
|
729
804
|
const baseViolationKeys = new Set(baseBnd.boundaryViolations.map(violationKey));
|
|
730
|
-
const
|
|
805
|
+
const allNewBoundaryFindings = targetBnd.boundaryViolations.filter((v) => !baseViolationKeys.has(violationKey(v)));
|
|
806
|
+
const newBoundaryViolations = allNewBoundaryFindings.filter((v) => !v.severity || v.severity === "VIOLATION");
|
|
807
|
+
const newBoundaryAdvisories = allNewBoundaryFindings.filter((v) => v.severity === "ADVISORY");
|
|
731
808
|
const pkgCycleKey = (c) => Array.isArray(c?.packages)
|
|
732
809
|
? [...c.packages].sort().join("::")
|
|
733
810
|
: JSON.stringify(c);
|
|
@@ -752,12 +829,18 @@ export function computeArchitecturalDiffGate(baseGraph, targetGraph, options) {
|
|
|
752
829
|
newDuplicateFlowCount: newDuplicateFlows.length,
|
|
753
830
|
newDuplicateSymbolCount: newDuplicateSymbols.length,
|
|
754
831
|
newBoundaryViolationCount: newBoundaryViolations.length,
|
|
832
|
+
...(newBoundaryAdvisories.length > 0
|
|
833
|
+
? { newBoundaryAdvisoryCount: newBoundaryAdvisories.length }
|
|
834
|
+
: {}),
|
|
755
835
|
newCycleCount: newPkgCycles.length + newContractCycles.length,
|
|
756
836
|
},
|
|
757
837
|
newPassThroughWrappers: newPassThroughWrappers.slice(0, cap),
|
|
758
838
|
newDuplicateFlows: newDuplicateFlows.slice(0, cap),
|
|
759
839
|
newDuplicateSymbols: newDuplicateSymbols.slice(0, cap),
|
|
760
840
|
newBoundaryViolations: newBoundaryViolations.slice(0, cap),
|
|
841
|
+
...(newBoundaryAdvisories.length > 0
|
|
842
|
+
? { newBoundaryAdvisories: newBoundaryAdvisories.slice(0, cap) }
|
|
843
|
+
: {}),
|
|
761
844
|
newCycles: {
|
|
762
845
|
packageCycles: newPkgCycles.slice(0, cap),
|
|
763
846
|
contractCycles: newContractCycles.slice(0, cap),
|
|
@@ -779,7 +862,10 @@ export async function resolveLiveAndBaseGraphsForMcp(repoPath, dbPath, repoId, o
|
|
|
779
862
|
if (options?.needBaseGraph) {
|
|
780
863
|
if (existsSync(dbPath)) {
|
|
781
864
|
const persistedRaw = await loadActiveGraphCached(dbPath, repoId);
|
|
782
|
-
|
|
865
|
+
const persistedSnap = persistedRaw
|
|
866
|
+
? readBaseSnapshotIfMatching(dbPath, persistedRaw)
|
|
867
|
+
: null;
|
|
868
|
+
if (persistedRaw && !persistedSnap?.workingTreeDirty) {
|
|
783
869
|
baseGraph = hasGitCommit(repoPath, persistedRaw.commitSha)
|
|
784
870
|
? applyActivePluginProjections(persistedRaw, {
|
|
785
871
|
repoPath,
|
|
@@ -852,7 +938,15 @@ export function formatCompactMcpDiff(delta, options) {
|
|
|
852
938
|
const includeLexical = Boolean(options?.includeLexicalShift);
|
|
853
939
|
const includeUnchanged = Boolean(options?.includeUnchanged);
|
|
854
940
|
const verbose = Boolean(options?.verbose);
|
|
855
|
-
const
|
|
941
|
+
const maxNodes = options?.maxNodes ?? 60;
|
|
942
|
+
const maxEdges = options?.maxEdges ?? 60;
|
|
943
|
+
const isTestDiffPath = (loc) => {
|
|
944
|
+
if (!loc)
|
|
945
|
+
return false;
|
|
946
|
+
const clean = loc.split(":")[0].replace(/\\/g, "/");
|
|
947
|
+
return (/\.(test|spec)\.[cm]?[jt]sx?$/i.test(clean) ||
|
|
948
|
+
/(^|\/)(__tests__|__mocks__)\//i.test(clean));
|
|
949
|
+
};
|
|
856
950
|
const countStatuses = (record) => {
|
|
857
951
|
const counts = { ADDED: 0, MODIFIED: 0, REMOVED: 0, LEXICAL_SHIFT: 0, UNCHANGED: 0 };
|
|
858
952
|
for (const entry of Object.values(record)) {
|
|
@@ -862,7 +956,15 @@ export function formatCompactMcpDiff(delta, options) {
|
|
|
862
956
|
}
|
|
863
957
|
return counts;
|
|
864
958
|
};
|
|
959
|
+
const resolvedGateStatus = delta.gateStatus ??
|
|
960
|
+
(delta.architecturalGate
|
|
961
|
+
? delta.architecturalGate.gateStatus === "PASS" &&
|
|
962
|
+
(!delta.designSystemGate || delta.designSystemGate.gateStatus === "PASS")
|
|
963
|
+
? "PASS"
|
|
964
|
+
: "WARN"
|
|
965
|
+
: undefined);
|
|
865
966
|
const baseEnvelope = {
|
|
967
|
+
...(resolvedGateStatus ? { gateStatus: resolvedGateStatus } : {}),
|
|
866
968
|
baseStatus: delta.baseStatus ?? "FRESH",
|
|
867
969
|
...(delta.baseRef ? { baseRef: delta.baseRef } : {}),
|
|
868
970
|
baseCommitSha: delta.baseCommitSha,
|
|
@@ -876,6 +978,7 @@ export function formatCompactMcpDiff(delta, options) {
|
|
|
876
978
|
baseExtractorVersion: delta.baseExtractorVersion,
|
|
877
979
|
targetExtractorVersion: delta.targetExtractorVersion,
|
|
878
980
|
...(delta.architecturalGate ? { architecturalGate: delta.architecturalGate } : {}),
|
|
981
|
+
...(delta.designSystemGate ? { designSystemGate: delta.designSystemGate } : {}),
|
|
879
982
|
summary: {
|
|
880
983
|
nodes: countStatuses(delta.nodes),
|
|
881
984
|
edges: countStatuses(delta.edges),
|
|
@@ -928,9 +1031,12 @@ export function formatCompactMcpDiff(delta, options) {
|
|
|
928
1031
|
modifiedSameEndpointEdges: 0,
|
|
929
1032
|
externalPackageCallEdges: 0,
|
|
930
1033
|
builtinOrDynamicEdges: 0,
|
|
1034
|
+
testFileNodes: 0,
|
|
1035
|
+
testFileEdges: 0,
|
|
1036
|
+
truncatedNodes: 0,
|
|
931
1037
|
truncatedEdges: 0,
|
|
932
1038
|
};
|
|
933
|
-
const
|
|
1039
|
+
const candidateNodes = [];
|
|
934
1040
|
for (const [id, entry] of Object.entries(delta.nodes)) {
|
|
935
1041
|
if (entry.status === "UNCHANGED" && !includeUnchanged)
|
|
936
1042
|
continue;
|
|
@@ -953,19 +1059,43 @@ export function formatCompactMcpDiff(delta, options) {
|
|
|
953
1059
|
}
|
|
954
1060
|
}
|
|
955
1061
|
const loc = primaryLoc(primary.evidence);
|
|
1062
|
+
if (isTestDiffPath(loc)) {
|
|
1063
|
+
omittedNoise.testFileNodes++;
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
956
1066
|
const baseSig = entry.status === "MODIFIED" ? formatSig(entry.base) : undefined;
|
|
957
1067
|
const targetSig = entry.status === "MODIFIED" ? formatSig(entry.target) : undefined;
|
|
958
1068
|
const sigChanged = entry.status === "MODIFIED" && baseSig !== targetSig && Boolean(baseSig || targetSig);
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
1069
|
+
const nodePriority = primary.type === "CONTRACT" && primary.entityType !== "EXPORTED_TYPE"
|
|
1070
|
+
? 0
|
|
1071
|
+
: primary.type === "BOUNDARY"
|
|
1072
|
+
? 1
|
|
1073
|
+
: primary.entityType === "EXPORTED_TYPE"
|
|
1074
|
+
? 2
|
|
1075
|
+
: 3;
|
|
1076
|
+
candidateNodes.push([
|
|
1077
|
+
id,
|
|
1078
|
+
{
|
|
1079
|
+
status: entry.status,
|
|
1080
|
+
name: primary.name,
|
|
1081
|
+
type: primary.type,
|
|
1082
|
+
entityType: primary.entityType,
|
|
1083
|
+
...(loc ? { file: loc } : {}),
|
|
1084
|
+
...(sigChanged
|
|
1085
|
+
? { signatureChange: { from: baseSig ?? "unspecified", to: targetSig ?? "unspecified" } }
|
|
1086
|
+
: {}),
|
|
1087
|
+
},
|
|
1088
|
+
nodePriority,
|
|
1089
|
+
]);
|
|
1090
|
+
}
|
|
1091
|
+
candidateNodes.sort((a, b) => a[2] - b[2]);
|
|
1092
|
+
const keptNodes = candidateNodes.slice(0, maxNodes);
|
|
1093
|
+
if (candidateNodes.length > maxNodes) {
|
|
1094
|
+
omittedNoise.truncatedNodes = candidateNodes.length - maxNodes;
|
|
1095
|
+
}
|
|
1096
|
+
const compactNodes = {};
|
|
1097
|
+
for (const [id, payload] of keptNodes) {
|
|
1098
|
+
compactNodes[id] = payload;
|
|
969
1099
|
}
|
|
970
1100
|
const candidateEdges = [];
|
|
971
1101
|
for (const [id, entry] of Object.entries(delta.edges)) {
|
|
@@ -984,7 +1114,7 @@ export function formatCompactMcpDiff(delta, options) {
|
|
|
984
1114
|
continue;
|
|
985
1115
|
}
|
|
986
1116
|
const tgtNode = primary.targetId ? nodeById.get(primary.targetId) : undefined;
|
|
987
|
-
if (tgtNode?.entityType === "EXTERNAL_PACKAGE") {
|
|
1117
|
+
if (tgtNode?.entityType === "EXTERNAL_PACKAGE" || tgtNode?.entityType === "NODE_BUILTIN") {
|
|
988
1118
|
omittedNoise.externalPackageCallEdges++;
|
|
989
1119
|
continue;
|
|
990
1120
|
}
|
|
@@ -994,8 +1124,12 @@ export function formatCompactMcpDiff(delta, options) {
|
|
|
994
1124
|
omittedNoise.builtinOrDynamicEdges++;
|
|
995
1125
|
continue;
|
|
996
1126
|
}
|
|
997
|
-
const srcNode = nodeById.get(primary.sourceId);
|
|
998
1127
|
const loc = primaryLoc(primary.evidence);
|
|
1128
|
+
if (isTestDiffPath(loc)) {
|
|
1129
|
+
omittedNoise.testFileEdges++;
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
const srcNode = nodeById.get(primary.sourceId);
|
|
999
1133
|
const priority = !primary.targetId ? 0 : entry.status === "ADDED" || entry.status === "REMOVED" ? 1 : 2;
|
|
1000
1134
|
candidateEdges.push([
|
|
1001
1135
|
id,
|
|
@@ -1176,9 +1310,11 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1176
1310
|
name: "chomp-mcp-server",
|
|
1177
1311
|
version: "0.1.0",
|
|
1178
1312
|
});
|
|
1179
|
-
server.tool("chomp_get_nodes", "MANDATORY FIRST STEP (MAP-FIRST NAVIGATION): Retrieves structural nodes from the persisted Chomp graph.
|
|
1313
|
+
server.tool("chomp_get_nodes", "MANDATORY FIRST STEP (MAP-FIRST NAVIGATION): Retrieves structural nodes from the persisted Chomp graph. Batch multiple queries into a SINGLE call using `search_terms: [...]` (or `file_paths: [...]` / `packageName`) BEFORE reading any files to resolve the exact node IDs of target Services, Routes, Components, and Functions in one round-trip. Only follow up with `chomp_create_view` when the user is asking an architectural question, querying how a flow works, or explicitly requesting a visual highlight/walkthrough (do NOT invoke `chomp_create_view` on routine coding or implementation prompts). Files and directories are not graph nodes: each node's source file and line live in its evidence records, and BOUNDARY nodes are only DEPLOYMENT_UNIT, CLASS, NAMESPACE or INIT_BLOCK.", {
|
|
1180
1314
|
search_term: z.string().optional().describe("Fast-path case-insensitive search term matching node name, id, humanLabel, domain, summary, or evidence filePath (use this to quickly resolve target node IDs)"),
|
|
1181
1315
|
searchTerm: z.string().optional().describe("Alias for search_term (camelCase)"),
|
|
1316
|
+
search_terms: z.array(z.string()).optional().describe("Batched list of case-insensitive search terms matched with OR semantics in a single call, ranked by match count and symbol exactness (preferred over multiple single-term calls)"),
|
|
1317
|
+
searchTerms: z.array(z.string()).optional().describe("Alias for search_terms (camelCase)"),
|
|
1182
1318
|
packageName: z.string().optional().describe("Optional filter by owning package / DEPLOYMENT_UNIT name (e.g., 'mcp', '@getchomp/mcp', 'core', 'web', 'cli', 'db')"),
|
|
1183
1319
|
package_name: z.string().optional().describe("Alias for packageName (snake_case)"),
|
|
1184
1320
|
type: z.string().optional().describe("Optional filter by node type (e.g., BOUNDARY, CONTRACT, OPEN_CONNECTOR)"),
|
|
@@ -1189,6 +1325,8 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1189
1325
|
name: z.string().optional().describe("Optional case-insensitive substring filter on node name (e.g., 'visitContract', 'SQLiteStorage', '/api/layout')"),
|
|
1190
1326
|
file_path: z.string().optional().describe("Optional case-insensitive substring filter on the node's evidence filePath (e.g., 'contractVisitor.ts', 'packages/core')"),
|
|
1191
1327
|
filePath: z.string().optional().describe("Alias for file_path (camelCase)"),
|
|
1328
|
+
file_paths: z.array(z.string()).optional().describe("Batched list of case-insensitive evidence filePath substrings matched in a single call"),
|
|
1329
|
+
filePaths: z.array(z.string()).optional().describe("Alias for file_paths (camelCase)"),
|
|
1192
1330
|
include_overlays: z.boolean().optional().describe("When true, attaches entity_overlays records onto each returned node. Defaults to false unless layers/layer is specified, keeping structural queries compact."),
|
|
1193
1331
|
includeOverlays: z.boolean().optional().describe("Alias for include_overlays (camelCase)"),
|
|
1194
1332
|
layers: z.array(z.string()).optional().describe("Optional list of overlay layers to hydrate on returned nodes (e.g. ['L1_SEMANTIC', 'L1_DESIGN_SYSTEM']). Implicitly enables overlay hydration for those layers."),
|
|
@@ -1204,7 +1342,7 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1204
1342
|
limit: z
|
|
1205
1343
|
.number()
|
|
1206
1344
|
.optional()
|
|
1207
|
-
.describe("Maximum nodes to return (default: 50
|
|
1345
|
+
.describe("Maximum nodes to return (default: 50, or up to 80 for batched search_terms)"),
|
|
1208
1346
|
verbose: z
|
|
1209
1347
|
.boolean()
|
|
1210
1348
|
.optional()
|
|
@@ -1222,15 +1360,18 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1222
1360
|
.filter(Boolean);
|
|
1223
1361
|
const includeOverlays = args.include_overlays ?? args.includeOverlays ?? (requestedLayers.length > 0);
|
|
1224
1362
|
const searchTerm = args.search_term ?? args.searchTerm;
|
|
1363
|
+
const searchTerms = args.search_terms ?? args.searchTerms;
|
|
1364
|
+
const filePaths = args.file_paths ?? args.filePaths;
|
|
1365
|
+
const hasAnySearch = Boolean(searchTerm) || Boolean(searchTerms && searchTerms.length > 0);
|
|
1225
1366
|
const enrichmentStatus = args.enrichment_status ?? args.enrichmentStatus;
|
|
1226
1367
|
const needsSemanticFilter = Boolean(enrichmentStatus);
|
|
1227
|
-
const overlayLayerFilter = requestedLayers.length > 0 && !
|
|
1368
|
+
const overlayLayerFilter = requestedLayers.length > 0 && !hasAnySearch && !needsSemanticFilter
|
|
1228
1369
|
? requestedLayers
|
|
1229
|
-
: needsSemanticFilter && !includeOverlays && !
|
|
1370
|
+
: needsSemanticFilter && !includeOverlays && !hasAnySearch
|
|
1230
1371
|
? [SEMANTIC_OVERLAY_LAYER]
|
|
1231
1372
|
: undefined;
|
|
1232
1373
|
const graph = await loadActiveGraphWithShims(repoPath, dbPath, repoId);
|
|
1233
|
-
const overlays = includeOverlays ||
|
|
1374
|
+
const overlays = includeOverlays || hasAnySearch || needsSemanticFilter
|
|
1234
1375
|
? await withStorage(dbPath, (storage) => storage.getEntityOverlays(repoId, overlayLayerFilter ? { layers: overlayLayerFilter } : undefined))
|
|
1235
1376
|
: [];
|
|
1236
1377
|
if (!graph) {
|
|
@@ -1251,7 +1392,9 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1251
1392
|
parentBoundaryId: args.parent_boundary_id ?? args.parentBoundaryId,
|
|
1252
1393
|
name: args.name,
|
|
1253
1394
|
filePath: args.file_path ?? args.filePath,
|
|
1395
|
+
filePaths,
|
|
1254
1396
|
searchTerm,
|
|
1397
|
+
searchTerms,
|
|
1255
1398
|
packageName: args.packageName ?? args.package_name,
|
|
1256
1399
|
overlaysByEntityId,
|
|
1257
1400
|
});
|
|
@@ -1272,9 +1415,11 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1272
1415
|
includeOverlays,
|
|
1273
1416
|
layers: requestedLayers,
|
|
1274
1417
|
});
|
|
1418
|
+
const batchFactor = Math.max(searchTerms?.length ?? 1, filePaths?.length ?? 1);
|
|
1419
|
+
const defaultLimit = batchFactor > 1 ? Math.min(80, Math.max(50, batchFactor * 15)) : 50;
|
|
1275
1420
|
const responseNodes = formatCompactMcpNodes(filteredNodes, {
|
|
1276
1421
|
verbose: args.verbose,
|
|
1277
|
-
limit: args.limit ??
|
|
1422
|
+
limit: args.limit ?? defaultLimit,
|
|
1278
1423
|
});
|
|
1279
1424
|
return {
|
|
1280
1425
|
content: [{ type: "text", text: JSON.stringify(responseNodes, null, 2) }]
|
|
@@ -1344,7 +1489,7 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1344
1489
|
content: [{ type: "text", text: JSON.stringify(responseEdges, null, 2) }]
|
|
1345
1490
|
};
|
|
1346
1491
|
}));
|
|
1347
|
-
server.tool("chomp_get_diff", "Compares two git branches/commits (baseRef -> targetRef) or
|
|
1492
|
+
server.tool("chomp_get_diff", "UNIFIED POST-EDIT VERIFICATION GATE & STRUCTURAL DIFF: Compares two git branches/commits (baseRef -> targetRef) or the live dirty working tree against the saved base graph in .chomp/graph.db. Returns a top-level `gateStatus` ('PASS' | 'WARN'), inline `architecturalGate` (newly introduced pass-through middlemen, duplicate flows/symbols, upward boundary violations, and cycles), inline `designSystemGate` (when a design-system baseline exists), and compact ADDED/REMOVED/MODIFIED production entities. Call this ONCE after editing; if `gateStatus` is 'PASS', stop immediately without calling separate boundary/redundancy/design-system diff tools.", {
|
|
1348
1493
|
baseRef: z.string().optional().describe("Optional base git branch or commit SHA (e.g. 'main')"),
|
|
1349
1494
|
base_ref: z.string().optional().describe("Alias for baseRef (snake_case)"),
|
|
1350
1495
|
targetRef: z.string().optional().describe("Optional target git branch, commit SHA, or 'WORKING_TREE' (defaults to 'WORKING_TREE' when uncommitted edits exist, or current branch vs main when clean)"),
|
|
@@ -1375,6 +1520,13 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1375
1520
|
}
|
|
1376
1521
|
else {
|
|
1377
1522
|
delta = await computeGraphDeltaWithShims(repoPath, dbPath, repoId);
|
|
1523
|
+
if (delta.baseStatus === "STALE" && resolveMcpGitCommitSha(repoPath, "HEAD")) {
|
|
1524
|
+
delta = await computeGitRefDeltaWithShims(repoPath, {
|
|
1525
|
+
baseRef: "HEAD",
|
|
1526
|
+
targetRef: "WORKING_TREE",
|
|
1527
|
+
dbPath,
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1378
1530
|
}
|
|
1379
1531
|
if (delta.baseStatus === "STALE") {
|
|
1380
1532
|
return {
|
|
@@ -1595,6 +1747,7 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1595
1747
|
const report = findGraphRedundancies(targetGraph, {
|
|
1596
1748
|
packageName: pkgFilter,
|
|
1597
1749
|
limit: args.limit,
|
|
1750
|
+
repoPath,
|
|
1598
1751
|
});
|
|
1599
1752
|
return {
|
|
1600
1753
|
content: [
|
|
@@ -1623,9 +1776,10 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1623
1776
|
const gate = computeArchitecturalDiffGate(baseGraph, targetGraph, {
|
|
1624
1777
|
repoPath,
|
|
1625
1778
|
packageName: pkgFilter,
|
|
1779
|
+
isTargetOnDisk: true,
|
|
1626
1780
|
});
|
|
1627
|
-
const hardCount = gate.newBoundaryViolations.
|
|
1628
|
-
const advCount = gate.
|
|
1781
|
+
const hardCount = gate.newBoundaryViolations.length;
|
|
1782
|
+
const advCount = gate.newBoundaryAdvisories?.length ?? 0;
|
|
1629
1783
|
const deltaReport = {
|
|
1630
1784
|
evaluatedSource,
|
|
1631
1785
|
diffOnly: true,
|
|
@@ -1641,7 +1795,10 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1641
1795
|
boundaryAdvisoryCount: advCount,
|
|
1642
1796
|
},
|
|
1643
1797
|
circularDependencies: gate.newCycles,
|
|
1644
|
-
boundaryViolations:
|
|
1798
|
+
boundaryViolations: [
|
|
1799
|
+
...gate.newBoundaryViolations,
|
|
1800
|
+
...(gate.newBoundaryAdvisories ?? []),
|
|
1801
|
+
],
|
|
1645
1802
|
};
|
|
1646
1803
|
return {
|
|
1647
1804
|
content: [{ type: "text", text: JSON.stringify(deltaReport, null, 2) }],
|
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,46 +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 (
|
|
1389
|
-
const
|
|
1390
|
-
filters.entityType === "EXTERNAL_PACKAGE"
|
|
1399
|
+
if (filePathFilters.length > 0) {
|
|
1400
|
+
const allowPackageConnectors = filters.type === "OPEN_CONNECTOR" ||
|
|
1401
|
+
filters.entityType === "EXTERNAL_PACKAGE" ||
|
|
1402
|
+
filters.entityType === "NODE_BUILTIN";
|
|
1391
1403
|
filteredNodes = filteredNodes.filter((n) => {
|
|
1392
|
-
if (!
|
|
1404
|
+
if (!allowPackageConnectors && PACKAGE_CONNECTOR_ENTITY_TYPES.has(n.entityType)) {
|
|
1393
1405
|
return false;
|
|
1394
1406
|
}
|
|
1395
1407
|
const ev = n.evidence;
|
|
1396
1408
|
if (!ev)
|
|
1397
1409
|
return false;
|
|
1410
|
+
const matchesAnyPath = (fp) => typeof fp === "string" &&
|
|
1411
|
+
filePathFilters.some((q) => fp.toLowerCase().includes(q));
|
|
1398
1412
|
if (Array.isArray(ev)) {
|
|
1399
|
-
return ev.some((r) =>
|
|
1400
|
-
r.filePath.toLowerCase().includes(filePathFilter));
|
|
1413
|
+
return ev.some((r) => matchesAnyPath(r?.filePath));
|
|
1401
1414
|
}
|
|
1402
|
-
return (
|
|
1403
|
-
ev.filePath.toLowerCase().includes(filePathFilter));
|
|
1415
|
+
return matchesAnyPath(ev.filePath);
|
|
1404
1416
|
});
|
|
1405
1417
|
}
|
|
1406
|
-
if (
|
|
1407
|
-
const
|
|
1408
|
-
filters.entityType === "EXTERNAL_PACKAGE"
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
if (n.
|
|
1413
|
-
return
|
|
1414
|
-
if (n.
|
|
1415
|
-
return
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
meta.humanLabel.toLowerCase().includes(searchTermFilter)) {
|
|
1419
|
-
return true;
|
|
1420
|
-
}
|
|
1421
|
-
if (typeof meta.domain === "string" &&
|
|
1422
|
-
meta.domain.toLowerCase().includes(searchTermFilter)) {
|
|
1423
|
-
return true;
|
|
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;
|
|
1424
1430
|
}
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
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;
|
|
1428
1436
|
}
|
|
1429
1437
|
const nodeOverlays = filters.overlaysByEntityId?.get(n.id);
|
|
1430
1438
|
if (nodeOverlays) {
|
|
@@ -1432,31 +1440,50 @@ export function filterNodesForMcp(graph, filters) {
|
|
|
1432
1440
|
const p = ov.payload;
|
|
1433
1441
|
if (!p || typeof p !== "object")
|
|
1434
1442
|
continue;
|
|
1435
|
-
if (typeof p.humanLabel === "string" &&
|
|
1436
|
-
p.
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
if (typeof p.domain === "string" &&
|
|
1440
|
-
p.domain.toLowerCase().includes(searchTermFilter)) {
|
|
1441
|
-
return true;
|
|
1442
|
-
}
|
|
1443
|
-
if (typeof p.summary === "string" &&
|
|
1444
|
-
p.summary.toLowerCase().includes(searchTermFilter)) {
|
|
1445
|
-
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;
|
|
1446
1447
|
}
|
|
1447
1448
|
}
|
|
1448
1449
|
}
|
|
1449
|
-
if (!
|
|
1450
|
-
return
|
|
1450
|
+
if (!allowPackageConnectorFileMatch && PACKAGE_CONNECTOR_ENTITY_TYPES.has(n.entityType)) {
|
|
1451
|
+
return 0;
|
|
1451
1452
|
}
|
|
1452
1453
|
const ev = n.evidence;
|
|
1453
1454
|
if (Array.isArray(ev)) {
|
|
1454
|
-
return ev.some((r) => typeof r?.filePath === "string" &&
|
|
1455
|
-
|
|
1455
|
+
return ev.some((r) => typeof r?.filePath === "string" && r.filePath.toLowerCase().includes(term))
|
|
1456
|
+
? 1
|
|
1457
|
+
: 0;
|
|
1456
1458
|
}
|
|
1457
|
-
return
|
|
1458
|
-
|
|
1459
|
-
|
|
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
|
+
}
|
|
1460
1487
|
}
|
|
1461
1488
|
return filteredNodes;
|
|
1462
1489
|
}
|
|
@@ -2072,6 +2099,166 @@ export function auditGraphHealth(graph, options) {
|
|
|
2072
2099
|
recommendedHighlightNodeIds,
|
|
2073
2100
|
};
|
|
2074
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
|
+
}
|
|
2075
2262
|
/**
|
|
2076
2263
|
* `chomp_find_redundancies` implementation ([PAT-MCP-08], [PAT-MCP-09]).
|
|
2077
2264
|
*
|
|
@@ -2082,6 +2269,34 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2082
2269
|
const index = buildGraphIndex(graph);
|
|
2083
2270
|
const maxItems = Math.max(1, Math.min(options?.limit ?? 25, 100));
|
|
2084
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
|
+
};
|
|
2085
2300
|
const matchesPkg = (nodeId) => {
|
|
2086
2301
|
if (!pkgFilter)
|
|
2087
2302
|
return true;
|
|
@@ -2090,7 +2305,7 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2090
2305
|
const ev = node ? getPrimaryEvidence(node) : {};
|
|
2091
2306
|
return packageMatchesFilter(pkg, ev.filePath, pkgFilter);
|
|
2092
2307
|
};
|
|
2093
|
-
// 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)
|
|
2094
2309
|
const passThroughMiddlemen = [];
|
|
2095
2310
|
for (const node of index.nodeById.values()) {
|
|
2096
2311
|
if (node.type !== "CONTRACT")
|
|
@@ -2101,10 +2316,13 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2101
2316
|
continue;
|
|
2102
2317
|
if (NON_EXECUTABLE_CONTRACT_ENTITY_TYPES.has(node.entityType))
|
|
2103
2318
|
continue;
|
|
2104
|
-
if (node.entityType === "EXPORTED_MODULE")
|
|
2319
|
+
if (node.entityType === "EXPORTED_MODULE" || node.entityType === "REACT_COMPONENT")
|
|
2105
2320
|
continue;
|
|
2106
2321
|
if (!matchesPkg(node.id))
|
|
2107
2322
|
continue;
|
|
2323
|
+
const nodeEv = getPrimaryEvidence(node);
|
|
2324
|
+
if (isTestSourcePath(nodeEv.filePath))
|
|
2325
|
+
continue;
|
|
2108
2326
|
const callers = index.flowInSourcesByTarget.get(node.id) ?? [];
|
|
2109
2327
|
const targets = index.flowOutTargetsBySource.get(node.id) ?? [];
|
|
2110
2328
|
const unresolved = index.unresolvedCallsByNodeId.get(node.id) ?? [];
|
|
@@ -2125,6 +2343,48 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2125
2343
|
const isRenderRelay = rawOutEdges.some((e) => e.targetId === targetNode.id && e.entityType === "RENDERS");
|
|
2126
2344
|
if (hasOpenConnectorCall || isRenderRelay)
|
|
2127
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
|
+
}
|
|
2128
2388
|
const nodeRef = toNodeSummaryRef(node, index.resolveNodePkg);
|
|
2129
2389
|
const targetRef = toNodeSummaryRef(targetNode, index.resolveNodePkg);
|
|
2130
2390
|
const callerRefs = callers
|
|
@@ -2150,6 +2410,8 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2150
2410
|
continue;
|
|
2151
2411
|
if (node.entityType === INIT_BLOCK_ENTITY_TYPE)
|
|
2152
2412
|
continue;
|
|
2413
|
+
if (isTestSourcePath(getPrimaryEvidence(node).filePath))
|
|
2414
|
+
continue;
|
|
2153
2415
|
const targets = index.flowOutTargetsBySource.get(node.id) ?? [];
|
|
2154
2416
|
if (targets.length < 2)
|
|
2155
2417
|
continue;
|
|
@@ -2208,6 +2470,8 @@ export function findGraphRedundancies(graph, options) {
|
|
|
2208
2470
|
continue;
|
|
2209
2471
|
if (NON_EXECUTABLE_CONTRACT_ENTITY_TYPES.has(node.entityType))
|
|
2210
2472
|
continue;
|
|
2473
|
+
if (isTestSourcePath(getPrimaryEvidence(node).filePath))
|
|
2474
|
+
continue;
|
|
2211
2475
|
if (node.entityType === "PUBLIC_METHOD" ||
|
|
2212
2476
|
node.entityType === "NEXTJS_PAGE" ||
|
|
2213
2477
|
node.entityType === "NEXTJS_LAYOUT" ||
|
|
@@ -2381,22 +2645,62 @@ export function checkGraphBoundaries(graph, options) {
|
|
|
2381
2645
|
lineNumber: ev.lineNumber,
|
|
2382
2646
|
});
|
|
2383
2647
|
}
|
|
2384
|
-
// 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
|
+
}
|
|
2385
2666
|
const packageLayers = [];
|
|
2386
2667
|
const tierRankByPkg = new Map();
|
|
2387
2668
|
for (const [pkg, duNode] of index.deploymentUnitsByPkg.entries()) {
|
|
2388
2669
|
const outs = [...(outPkgsByPkg.get(pkg) ?? [])].sort();
|
|
2389
2670
|
const ins = [...(inPkgsByPkg.get(pkg) ?? [])].sort();
|
|
2390
|
-
const
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
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");
|
|
2394
2686
|
let architecturalTier;
|
|
2395
2687
|
let tierRank;
|
|
2396
2688
|
if (outs.length === 0 && ins.length === 0) {
|
|
2397
2689
|
architecturalTier = "ISOLATED_PACKAGE";
|
|
2398
2690
|
tierRank = 0;
|
|
2399
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
|
+
}
|
|
2400
2704
|
else if (outs.length === 0 && isAdapterPkg && ins.length > 0) {
|
|
2401
2705
|
architecturalTier = "INFRASTRUCTURE_ADAPTER";
|
|
2402
2706
|
tierRank = 2;
|
|
@@ -2405,6 +2709,12 @@ export function checkGraphBoundaries(graph, options) {
|
|
|
2405
2709
|
architecturalTier = "FOUNDATION_CORE";
|
|
2406
2710
|
tierRank = 3;
|
|
2407
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
|
+
}
|
|
2408
2718
|
else if (ins.length === 0) {
|
|
2409
2719
|
architecturalTier = "ENTRY_APPLICATION";
|
|
2410
2720
|
tierRank = 0;
|
|
@@ -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"
|