@getchomp/mcp 0.2.43 → 0.2.45
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 +122 -1
- package/dist/index.js +596 -71
- package/dist/intelligence.js +10 -0
- package/dist/plugins/design-system/index.js +9 -2
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -482,12 +482,16 @@ export async function computeGraphDeltaWithShims(repoPath, dbPath, repoId, stora
|
|
|
482
482
|
overlayLayers,
|
|
483
483
|
});
|
|
484
484
|
const delta = compareGraphs(baseProjected, currentProjected);
|
|
485
|
+
const architecturalGate = computeArchitecturalDiffGate(baseProjected, currentProjected, {
|
|
486
|
+
repoPath,
|
|
487
|
+
});
|
|
485
488
|
return {
|
|
486
489
|
...delta,
|
|
487
490
|
headCommitSha,
|
|
488
491
|
baseExtractorVersion: baseRaw.extractorVersion,
|
|
489
492
|
targetExtractorVersion: currentRaw.extractorVersion,
|
|
490
493
|
baseStatus: "FRESH",
|
|
494
|
+
architecturalGate,
|
|
491
495
|
};
|
|
492
496
|
}
|
|
493
497
|
function resolveMcpGitCommitSha(repoPath, ref) {
|
|
@@ -644,6 +648,9 @@ export async function computeGitRefDeltaWithShims(repoPath, options) {
|
|
|
644
648
|
readRepoFileOverride: (rel) => readGitBlobAtCommit(repoPath, targetSha, rel),
|
|
645
649
|
});
|
|
646
650
|
const delta = compareGraphs(baseProjected, targetProjected);
|
|
651
|
+
const architecturalGate = computeArchitecturalDiffGate(baseProjected, targetProjected, {
|
|
652
|
+
repoPath,
|
|
653
|
+
});
|
|
647
654
|
return {
|
|
648
655
|
...delta,
|
|
649
656
|
baseCommitSha: baseSha,
|
|
@@ -655,6 +662,7 @@ export async function computeGitRefDeltaWithShims(repoPath, options) {
|
|
|
655
662
|
baseRef,
|
|
656
663
|
targetRef,
|
|
657
664
|
isWorkingTreeSnapshot: false,
|
|
665
|
+
architecturalGate,
|
|
658
666
|
};
|
|
659
667
|
}
|
|
660
668
|
const snapshotAt = new Date().toISOString();
|
|
@@ -664,6 +672,9 @@ export async function computeGitRefDeltaWithShims(repoPath, options) {
|
|
|
664
672
|
overlayLayers,
|
|
665
673
|
});
|
|
666
674
|
const delta = compareGraphs(baseProjected, currentProjected);
|
|
675
|
+
const architecturalGate = computeArchitecturalDiffGate(baseProjected, currentProjected, {
|
|
676
|
+
repoPath,
|
|
677
|
+
});
|
|
667
678
|
return {
|
|
668
679
|
...delta,
|
|
669
680
|
baseCommitSha: baseSha,
|
|
@@ -675,6 +686,147 @@ export async function computeGitRefDeltaWithShims(repoPath, options) {
|
|
|
675
686
|
targetRef: "WORKING_TREE",
|
|
676
687
|
isWorkingTreeSnapshot: true,
|
|
677
688
|
snapshotAt,
|
|
689
|
+
architecturalGate,
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
export function computeArchitecturalDiffGate(baseGraph, targetGraph, options) {
|
|
693
|
+
const baseRed = findGraphRedundancies(baseGraph, {
|
|
694
|
+
packageName: options?.packageName,
|
|
695
|
+
limit: 100,
|
|
696
|
+
});
|
|
697
|
+
const targetRed = findGraphRedundancies(targetGraph, {
|
|
698
|
+
packageName: options?.packageName,
|
|
699
|
+
limit: 100,
|
|
700
|
+
});
|
|
701
|
+
const baseMiddlemenIds = new Set(baseRed.passThroughMiddlemen.map((m) => m.middleman.id));
|
|
702
|
+
const newPassThroughWrappers = targetRed.passThroughMiddlemen.filter((m) => !baseMiddlemenIds.has(m.middleman.id));
|
|
703
|
+
const baseSeqCallersBySig = new Map();
|
|
704
|
+
for (const seq of baseRed.duplicateStorySequences) {
|
|
705
|
+
const sig = seq.sharedTargets.map((t) => t.id).sort().join("::");
|
|
706
|
+
baseSeqCallersBySig.set(sig, new Set(seq.parallelCallers.map((c) => c.id)));
|
|
707
|
+
}
|
|
708
|
+
const newDuplicateFlows = targetRed.duplicateStorySequences.filter((seq) => {
|
|
709
|
+
const sig = seq.sharedTargets.map((t) => t.id).sort().join("::");
|
|
710
|
+
const baseCallers = baseSeqCallersBySig.get(sig);
|
|
711
|
+
if (!baseCallers)
|
|
712
|
+
return true;
|
|
713
|
+
return seq.parallelCallers.some((c) => !baseCallers.has(c.id));
|
|
714
|
+
});
|
|
715
|
+
const baseDupCountByName = new Map();
|
|
716
|
+
for (const dup of baseRed.duplicateSymbols) {
|
|
717
|
+
baseDupCountByName.set(dup.symbolName, dup.instanceCount);
|
|
718
|
+
}
|
|
719
|
+
const newDuplicateSymbols = targetRed.duplicateSymbols.filter((dup) => dup.instanceCount > (baseDupCountByName.get(dup.symbolName) ?? 0));
|
|
720
|
+
const baseBnd = checkGraphBoundaries(baseGraph, {
|
|
721
|
+
packageName: options?.packageName,
|
|
722
|
+
repoPath: options?.repoPath,
|
|
723
|
+
});
|
|
724
|
+
const targetBnd = checkGraphBoundaries(targetGraph, {
|
|
725
|
+
packageName: options?.packageName,
|
|
726
|
+
repoPath: options?.repoPath,
|
|
727
|
+
});
|
|
728
|
+
const violationKey = (v) => `${v.ruleId}::${v.sourcePackage}::${v.targetPackage}`;
|
|
729
|
+
const baseViolationKeys = new Set(baseBnd.boundaryViolations.map(violationKey));
|
|
730
|
+
const newBoundaryViolations = targetBnd.boundaryViolations.filter((v) => !baseViolationKeys.has(violationKey(v)));
|
|
731
|
+
const pkgCycleKey = (c) => Array.isArray(c?.packages)
|
|
732
|
+
? [...c.packages].sort().join("::")
|
|
733
|
+
: JSON.stringify(c);
|
|
734
|
+
const basePkgCycles = new Set(baseBnd.circularDependencies.packageCycles.map(pkgCycleKey));
|
|
735
|
+
const newPkgCycles = targetBnd.circularDependencies.packageCycles.filter((c) => !basePkgCycles.has(pkgCycleKey(c)));
|
|
736
|
+
const contractCycleKey = (c) => Array.isArray(c?.nodes)
|
|
737
|
+
? c.nodes.map((n) => n.id ?? n).sort().join("::")
|
|
738
|
+
: JSON.stringify(c);
|
|
739
|
+
const baseContractCycles = new Set(baseBnd.circularDependencies.contractCycles.map(contractCycleKey));
|
|
740
|
+
const newContractCycles = targetBnd.circularDependencies.contractCycles.filter((c) => !baseContractCycles.has(contractCycleKey(c)));
|
|
741
|
+
const cap = options?.limit ?? 25;
|
|
742
|
+
const totalNew = newPassThroughWrappers.length +
|
|
743
|
+
newDuplicateFlows.length +
|
|
744
|
+
newDuplicateSymbols.length +
|
|
745
|
+
newBoundaryViolations.length +
|
|
746
|
+
newPkgCycles.length +
|
|
747
|
+
newContractCycles.length;
|
|
748
|
+
return {
|
|
749
|
+
gateStatus: totalNew === 0 ? "PASS" : "WARN",
|
|
750
|
+
summary: {
|
|
751
|
+
newPassThroughWrapperCount: newPassThroughWrappers.length,
|
|
752
|
+
newDuplicateFlowCount: newDuplicateFlows.length,
|
|
753
|
+
newDuplicateSymbolCount: newDuplicateSymbols.length,
|
|
754
|
+
newBoundaryViolationCount: newBoundaryViolations.length,
|
|
755
|
+
newCycleCount: newPkgCycles.length + newContractCycles.length,
|
|
756
|
+
},
|
|
757
|
+
newPassThroughWrappers: newPassThroughWrappers.slice(0, cap),
|
|
758
|
+
newDuplicateFlows: newDuplicateFlows.slice(0, cap),
|
|
759
|
+
newDuplicateSymbols: newDuplicateSymbols.slice(0, cap),
|
|
760
|
+
newBoundaryViolations: newBoundaryViolations.slice(0, cap),
|
|
761
|
+
newCycles: {
|
|
762
|
+
packageCycles: newPkgCycles.slice(0, cap),
|
|
763
|
+
contractCycles: newContractCycles.slice(0, cap),
|
|
764
|
+
},
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
export async function resolveLiveAndBaseGraphsForMcp(repoPath, dbPath, repoId, options) {
|
|
768
|
+
const gitState = inspectMcpRepoGitBranches(repoPath);
|
|
769
|
+
const overlayLayers = readRepoOverlayLayerToggles(repoPath);
|
|
770
|
+
if (gitState.workingTreeDirty) {
|
|
771
|
+
const { headCommitSha } = readGitHeadState(repoPath);
|
|
772
|
+
const excludeWorkspaces = loadRepoExcludeWorkspaces(repoPath);
|
|
773
|
+
const liveRaw = extractLiveUserGraph(repoPath, headCommitSha, excludeWorkspaces);
|
|
774
|
+
const targetGraph = applyActivePluginProjections(liveRaw, {
|
|
775
|
+
repoPath,
|
|
776
|
+
overlayLayers,
|
|
777
|
+
});
|
|
778
|
+
let baseGraph = null;
|
|
779
|
+
if (options?.needBaseGraph) {
|
|
780
|
+
if (existsSync(dbPath)) {
|
|
781
|
+
const persistedRaw = await loadActiveGraphCached(dbPath, repoId);
|
|
782
|
+
if (persistedRaw) {
|
|
783
|
+
baseGraph = hasGitCommit(repoPath, persistedRaw.commitSha)
|
|
784
|
+
? applyActivePluginProjections(persistedRaw, {
|
|
785
|
+
repoPath,
|
|
786
|
+
overlayLayers,
|
|
787
|
+
readRepoFileOverride: (rel) => readGitBlobAtCommit(repoPath, persistedRaw.commitSha.trim(), rel),
|
|
788
|
+
})
|
|
789
|
+
: persistedRaw;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
if (!baseGraph && headCommitSha) {
|
|
793
|
+
const baseRaw = extractMcpArchivedGraph(repoPath, headCommitSha, excludeWorkspaces, dbPath);
|
|
794
|
+
baseGraph = applyActivePluginProjections(baseRaw, {
|
|
795
|
+
repoPath,
|
|
796
|
+
overlayLayers,
|
|
797
|
+
readRepoFileOverride: (rel) => readGitBlobAtCommit(repoPath, headCommitSha, rel),
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
return { targetGraph, baseGraph, evaluatedSource: "WORKING_TREE" };
|
|
802
|
+
}
|
|
803
|
+
if (!existsSync(dbPath)) {
|
|
804
|
+
throw new Error(`Chomp database not found at ${dbPath}. Please run 'chomp analyze .' first.`);
|
|
805
|
+
}
|
|
806
|
+
const targetGraph = await loadActiveGraphWithShims(repoPath, dbPath, repoId);
|
|
807
|
+
if (!targetGraph) {
|
|
808
|
+
throw new Error(`Graph data for repository '${repoId}' not found in the database. Please run 'chomp analyze .' first.`);
|
|
809
|
+
}
|
|
810
|
+
let baseGraph = null;
|
|
811
|
+
if (options?.needBaseGraph &&
|
|
812
|
+
gitState.currentBranch !== "HEAD" &&
|
|
813
|
+
gitState.currentBranch !== gitState.defaultBaseBranch &&
|
|
814
|
+
gitState.hasDefaultBase) {
|
|
815
|
+
const baseSha = resolveMcpGitCommitSha(repoPath, gitState.defaultBaseBranch);
|
|
816
|
+
if (baseSha) {
|
|
817
|
+
const excludeWorkspaces = loadRepoExcludeWorkspaces(repoPath);
|
|
818
|
+
const baseRaw = extractMcpArchivedGraph(repoPath, baseSha, excludeWorkspaces, dbPath);
|
|
819
|
+
baseGraph = applyActivePluginProjections(baseRaw, {
|
|
820
|
+
repoPath,
|
|
821
|
+
overlayLayers,
|
|
822
|
+
readRepoFileOverride: (rel) => readGitBlobAtCommit(repoPath, baseSha, rel),
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return {
|
|
827
|
+
targetGraph,
|
|
828
|
+
baseGraph: baseGraph ?? (options?.needBaseGraph ? targetGraph : null),
|
|
829
|
+
evaluatedSource: "COMMITTED_HEAD",
|
|
678
830
|
};
|
|
679
831
|
}
|
|
680
832
|
/**
|
|
@@ -696,6 +848,324 @@ export function withMcpToolErrorBoundary(handler) {
|
|
|
696
848
|
}
|
|
697
849
|
};
|
|
698
850
|
}
|
|
851
|
+
export function formatCompactMcpDiff(delta, options) {
|
|
852
|
+
const includeLexical = Boolean(options?.includeLexicalShift);
|
|
853
|
+
const includeUnchanged = Boolean(options?.includeUnchanged);
|
|
854
|
+
const verbose = Boolean(options?.verbose);
|
|
855
|
+
const maxEdges = options?.maxEdges ?? 80;
|
|
856
|
+
const countStatuses = (record) => {
|
|
857
|
+
const counts = { ADDED: 0, MODIFIED: 0, REMOVED: 0, LEXICAL_SHIFT: 0, UNCHANGED: 0 };
|
|
858
|
+
for (const entry of Object.values(record)) {
|
|
859
|
+
if (entry.status in counts) {
|
|
860
|
+
counts[entry.status]++;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
return counts;
|
|
864
|
+
};
|
|
865
|
+
const baseEnvelope = {
|
|
866
|
+
baseStatus: delta.baseStatus ?? "FRESH",
|
|
867
|
+
...(delta.baseRef ? { baseRef: delta.baseRef } : {}),
|
|
868
|
+
baseCommitSha: delta.baseCommitSha,
|
|
869
|
+
...(delta.targetRef ? { targetRef: delta.targetRef } : {}),
|
|
870
|
+
targetCommitSha: delta.targetCommitSha,
|
|
871
|
+
headCommitSha: delta.headCommitSha,
|
|
872
|
+
...(delta.isWorkingTreeSnapshot !== undefined
|
|
873
|
+
? { isWorkingTreeSnapshot: delta.isWorkingTreeSnapshot }
|
|
874
|
+
: {}),
|
|
875
|
+
...(delta.snapshotAt ? { snapshotAt: delta.snapshotAt } : {}),
|
|
876
|
+
baseExtractorVersion: delta.baseExtractorVersion,
|
|
877
|
+
targetExtractorVersion: delta.targetExtractorVersion,
|
|
878
|
+
...(delta.architecturalGate ? { architecturalGate: delta.architecturalGate } : {}),
|
|
879
|
+
summary: {
|
|
880
|
+
nodes: countStatuses(delta.nodes),
|
|
881
|
+
edges: countStatuses(delta.edges),
|
|
882
|
+
},
|
|
883
|
+
};
|
|
884
|
+
if (verbose) {
|
|
885
|
+
const filterEntries = (record) => {
|
|
886
|
+
const out = {};
|
|
887
|
+
for (const [id, entry] of Object.entries(record)) {
|
|
888
|
+
if (entry.status === "UNCHANGED" && !includeUnchanged)
|
|
889
|
+
continue;
|
|
890
|
+
if (entry.status === "LEXICAL_SHIFT" && !includeLexical)
|
|
891
|
+
continue;
|
|
892
|
+
out[id] = entry;
|
|
893
|
+
}
|
|
894
|
+
return out;
|
|
895
|
+
};
|
|
896
|
+
return {
|
|
897
|
+
...baseEnvelope,
|
|
898
|
+
nodes: filterEntries(delta.nodes),
|
|
899
|
+
edges: filterEntries(delta.edges),
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
const nodeById = new Map();
|
|
903
|
+
for (const [id, entry] of Object.entries(delta.nodes)) {
|
|
904
|
+
const n = entry.target ?? entry.base;
|
|
905
|
+
if (n)
|
|
906
|
+
nodeById.set(id, n);
|
|
907
|
+
}
|
|
908
|
+
const primaryLoc = (ev) => {
|
|
909
|
+
const item = Array.isArray(ev) ? ev[0] : ev;
|
|
910
|
+
if (!item?.filePath)
|
|
911
|
+
return undefined;
|
|
912
|
+
return typeof item.lineNumber === "number"
|
|
913
|
+
? `${item.filePath}:${item.lineNumber}`
|
|
914
|
+
: String(item.filePath);
|
|
915
|
+
};
|
|
916
|
+
const formatSig = (n) => {
|
|
917
|
+
if (!n?.metadata)
|
|
918
|
+
return undefined;
|
|
919
|
+
const ins = Array.isArray(n.metadata.inputTypes) ? n.metadata.inputTypes.join(", ") : "";
|
|
920
|
+
const out = typeof n.metadata.outputType === "string" ? n.metadata.outputType : "";
|
|
921
|
+
if (!ins && !out)
|
|
922
|
+
return undefined;
|
|
923
|
+
return `(${ins}) => ${out || "void"}`;
|
|
924
|
+
};
|
|
925
|
+
const omittedNoise = {
|
|
926
|
+
modifiedDeploymentUnits: 0,
|
|
927
|
+
modifiedExternalPackageImports: 0,
|
|
928
|
+
modifiedSameEndpointEdges: 0,
|
|
929
|
+
externalPackageCallEdges: 0,
|
|
930
|
+
builtinOrDynamicEdges: 0,
|
|
931
|
+
truncatedEdges: 0,
|
|
932
|
+
};
|
|
933
|
+
const compactNodes = {};
|
|
934
|
+
for (const [id, entry] of Object.entries(delta.nodes)) {
|
|
935
|
+
if (entry.status === "UNCHANGED" && !includeUnchanged)
|
|
936
|
+
continue;
|
|
937
|
+
if (entry.status === "LEXICAL_SHIFT" && !includeLexical)
|
|
938
|
+
continue;
|
|
939
|
+
const primary = entry.target ?? entry.base;
|
|
940
|
+
if (!primary)
|
|
941
|
+
continue;
|
|
942
|
+
if (entry.status === "MODIFIED") {
|
|
943
|
+
if (primary.entityType === "DEPLOYMENT_UNIT" &&
|
|
944
|
+
entry.base?.name === entry.target?.name &&
|
|
945
|
+
entry.base?.parentBoundaryId === entry.target?.parentBoundaryId) {
|
|
946
|
+
omittedNoise.modifiedDeploymentUnits++;
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
if (primary.entityType === "EXTERNAL_PACKAGE" &&
|
|
950
|
+
entry.base?.name === entry.target?.name) {
|
|
951
|
+
omittedNoise.modifiedExternalPackageImports++;
|
|
952
|
+
continue;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
const loc = primaryLoc(primary.evidence);
|
|
956
|
+
const baseSig = entry.status === "MODIFIED" ? formatSig(entry.base) : undefined;
|
|
957
|
+
const targetSig = entry.status === "MODIFIED" ? formatSig(entry.target) : undefined;
|
|
958
|
+
const sigChanged = entry.status === "MODIFIED" && baseSig !== targetSig && Boolean(baseSig || targetSig);
|
|
959
|
+
compactNodes[id] = {
|
|
960
|
+
status: entry.status,
|
|
961
|
+
name: primary.name,
|
|
962
|
+
type: primary.type,
|
|
963
|
+
entityType: primary.entityType,
|
|
964
|
+
...(loc ? { file: loc } : {}),
|
|
965
|
+
...(sigChanged
|
|
966
|
+
? { signatureChange: { from: baseSig ?? "unspecified", to: targetSig ?? "unspecified" } }
|
|
967
|
+
: {}),
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
const candidateEdges = [];
|
|
971
|
+
for (const [id, entry] of Object.entries(delta.edges)) {
|
|
972
|
+
if (entry.status === "UNCHANGED" && !includeUnchanged)
|
|
973
|
+
continue;
|
|
974
|
+
if (entry.status === "LEXICAL_SHIFT" && !includeLexical)
|
|
975
|
+
continue;
|
|
976
|
+
const primary = entry.target ?? entry.base;
|
|
977
|
+
if (!primary)
|
|
978
|
+
continue;
|
|
979
|
+
if (entry.status === "MODIFIED" &&
|
|
980
|
+
entry.base?.sourceId === entry.target?.sourceId &&
|
|
981
|
+
entry.base?.targetId === entry.target?.targetId &&
|
|
982
|
+
entry.base?.entityType === entry.target?.entityType) {
|
|
983
|
+
omittedNoise.modifiedSameEndpointEdges++;
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
const tgtNode = primary.targetId ? nodeById.get(primary.targetId) : undefined;
|
|
987
|
+
if (tgtNode?.entityType === "EXTERNAL_PACKAGE") {
|
|
988
|
+
omittedNoise.externalPackageCallEdges++;
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
const resClass = primary.metadata?.resolutionClass;
|
|
992
|
+
if (!primary.targetId &&
|
|
993
|
+
(resClass === "BUILTIN_OR_PLATFORM" || resClass === "DYNAMIC_BOUNDARY")) {
|
|
994
|
+
omittedNoise.builtinOrDynamicEdges++;
|
|
995
|
+
continue;
|
|
996
|
+
}
|
|
997
|
+
const srcNode = nodeById.get(primary.sourceId);
|
|
998
|
+
const loc = primaryLoc(primary.evidence);
|
|
999
|
+
const priority = !primary.targetId ? 0 : entry.status === "ADDED" || entry.status === "REMOVED" ? 1 : 2;
|
|
1000
|
+
candidateEdges.push([
|
|
1001
|
+
id,
|
|
1002
|
+
{
|
|
1003
|
+
status: entry.status,
|
|
1004
|
+
entityType: primary.entityType,
|
|
1005
|
+
name: primary.name,
|
|
1006
|
+
sourceId: primary.sourceId,
|
|
1007
|
+
source: srcNode?.name ?? primary.sourceId,
|
|
1008
|
+
...(primary.targetId
|
|
1009
|
+
? {
|
|
1010
|
+
targetId: primary.targetId,
|
|
1011
|
+
target: tgtNode?.name ?? primary.targetId,
|
|
1012
|
+
}
|
|
1013
|
+
: { unresolved: true }),
|
|
1014
|
+
...(loc ? { file: loc } : {}),
|
|
1015
|
+
},
|
|
1016
|
+
priority,
|
|
1017
|
+
]);
|
|
1018
|
+
}
|
|
1019
|
+
candidateEdges.sort((a, b) => a[2] - b[2]);
|
|
1020
|
+
const keptEdges = candidateEdges.slice(0, maxEdges);
|
|
1021
|
+
if (candidateEdges.length > maxEdges) {
|
|
1022
|
+
omittedNoise.truncatedEdges = candidateEdges.length - maxEdges;
|
|
1023
|
+
}
|
|
1024
|
+
const compactEdges = {};
|
|
1025
|
+
for (const [id, payload] of keptEdges) {
|
|
1026
|
+
compactEdges[id] = payload;
|
|
1027
|
+
}
|
|
1028
|
+
return {
|
|
1029
|
+
...baseEnvelope,
|
|
1030
|
+
summary: {
|
|
1031
|
+
...baseEnvelope.summary,
|
|
1032
|
+
omittedNoise,
|
|
1033
|
+
},
|
|
1034
|
+
nodes: compactNodes,
|
|
1035
|
+
edges: compactEdges,
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
export function formatCompactMcpNodes(nodes, options) {
|
|
1039
|
+
if (options?.verbose)
|
|
1040
|
+
return nodes;
|
|
1041
|
+
let candidateNodes = nodes;
|
|
1042
|
+
if (typeof options?.limit === "number" &&
|
|
1043
|
+
options.limit > 0 &&
|
|
1044
|
+
nodes.length > options.limit) {
|
|
1045
|
+
const nodePriority = (n) => {
|
|
1046
|
+
if (n.type === "CONTRACT" && n.entityType !== "EXPORTED_TYPE")
|
|
1047
|
+
return 0;
|
|
1048
|
+
if (n.type === "BOUNDARY")
|
|
1049
|
+
return 1;
|
|
1050
|
+
if (n.entityType === "EXPORTED_TYPE")
|
|
1051
|
+
return 2;
|
|
1052
|
+
return 3;
|
|
1053
|
+
};
|
|
1054
|
+
candidateNodes = nodes
|
|
1055
|
+
.map((n, idx) => ({ n, idx, pri: nodePriority(n) }))
|
|
1056
|
+
.sort((a, b) => a.pri - b.pri || a.idx - b.idx)
|
|
1057
|
+
.slice(0, options.limit)
|
|
1058
|
+
.map((item) => item.n);
|
|
1059
|
+
}
|
|
1060
|
+
const compactEvidence = (ev) => {
|
|
1061
|
+
if (!ev)
|
|
1062
|
+
return {};
|
|
1063
|
+
if (Array.isArray(ev)) {
|
|
1064
|
+
const cleaned = ev.slice(0, 3).map((r) => ({
|
|
1065
|
+
filePath: r.filePath,
|
|
1066
|
+
...(typeof r.lineNumber === "number" ? { lineNumber: r.lineNumber } : {}),
|
|
1067
|
+
}));
|
|
1068
|
+
return {
|
|
1069
|
+
evidence: cleaned,
|
|
1070
|
+
...(ev.length > 3 ? { evidenceCount: ev.length } : {}),
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
return {
|
|
1074
|
+
evidence: {
|
|
1075
|
+
filePath: ev.filePath,
|
|
1076
|
+
...(typeof ev.lineNumber === "number" ? { lineNumber: ev.lineNumber } : {}),
|
|
1077
|
+
},
|
|
1078
|
+
};
|
|
1079
|
+
};
|
|
1080
|
+
const compactMetadata = (rawMeta) => {
|
|
1081
|
+
if (!rawMeta || typeof rawMeta !== "object")
|
|
1082
|
+
return undefined;
|
|
1083
|
+
const { analyzedFiles, bodyHash: _bodyHash, portValves, unresolvedOutgoing, ...rest } = rawMeta;
|
|
1084
|
+
const out = { ...rest };
|
|
1085
|
+
if (Array.isArray(analyzedFiles)) {
|
|
1086
|
+
out.analyzedFileCount = analyzedFiles.length;
|
|
1087
|
+
}
|
|
1088
|
+
if (Array.isArray(unresolvedOutgoing) && unresolvedOutgoing.length > 0) {
|
|
1089
|
+
out.unresolvedCount = unresolvedOutgoing.length;
|
|
1090
|
+
}
|
|
1091
|
+
if (portValves && typeof portValves === "object") {
|
|
1092
|
+
const inputs = Array.isArray(portValves.inputs)
|
|
1093
|
+
? portValves.inputs.map((inp) => `${inp.name ?? "arg"}${inp.optional ? "?" : ""}: ${inp.type ?? "unknown"}`)
|
|
1094
|
+
: undefined;
|
|
1095
|
+
const rawOut = portValves.output?.type ?? portValves.outputType ?? rawMeta.outputType;
|
|
1096
|
+
const output = rawOut && portValves.output?.async ? `Promise<${rawOut}>` : rawOut;
|
|
1097
|
+
if ((inputs && inputs.length > 0) || output) {
|
|
1098
|
+
out.signature = {
|
|
1099
|
+
...(inputs && inputs.length > 0 ? { inputs } : {}),
|
|
1100
|
+
...(output ? { output } : {}),
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
1105
|
+
};
|
|
1106
|
+
return candidateNodes.map((n) => {
|
|
1107
|
+
const evPart = compactEvidence(n.evidence);
|
|
1108
|
+
const metaPart = compactMetadata(n.metadata);
|
|
1109
|
+
return {
|
|
1110
|
+
id: n.id,
|
|
1111
|
+
name: n.name,
|
|
1112
|
+
type: n.type,
|
|
1113
|
+
entityType: n.entityType,
|
|
1114
|
+
...(n.parentBoundaryId ? { parentBoundaryId: n.parentBoundaryId } : {}),
|
|
1115
|
+
...evPart,
|
|
1116
|
+
...(metaPart ? { metadata: metaPart } : {}),
|
|
1117
|
+
...(n.overlays !== undefined ? { overlays: n.overlays } : {}),
|
|
1118
|
+
};
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
export function formatCompactMcpEdges(edges, options) {
|
|
1122
|
+
if (options?.verbose)
|
|
1123
|
+
return edges;
|
|
1124
|
+
const includeBuiltins = Boolean(options?.includeBuiltins);
|
|
1125
|
+
return edges
|
|
1126
|
+
.filter((e) => {
|
|
1127
|
+
if (includeBuiltins || e.targetId)
|
|
1128
|
+
return true;
|
|
1129
|
+
return e.metadata?.resolutionClass !== "BUILTIN_OR_PLATFORM";
|
|
1130
|
+
})
|
|
1131
|
+
.map((e) => {
|
|
1132
|
+
const ev = e.evidence;
|
|
1133
|
+
const compactEv = Array.isArray(ev)
|
|
1134
|
+
? ev.slice(0, 3).map((r) => ({
|
|
1135
|
+
filePath: r.filePath,
|
|
1136
|
+
...(typeof r.lineNumber === "number" ? { lineNumber: r.lineNumber } : {}),
|
|
1137
|
+
}))
|
|
1138
|
+
: ev
|
|
1139
|
+
? {
|
|
1140
|
+
filePath: ev.filePath,
|
|
1141
|
+
...(typeof ev.lineNumber === "number"
|
|
1142
|
+
? { lineNumber: ev.lineNumber }
|
|
1143
|
+
: {}),
|
|
1144
|
+
}
|
|
1145
|
+
: undefined;
|
|
1146
|
+
const meta = e.metadata;
|
|
1147
|
+
const compactMeta = meta && typeof meta === "object"
|
|
1148
|
+
? Object.fromEntries(Object.entries({
|
|
1149
|
+
resolutionClass: meta.resolutionClass,
|
|
1150
|
+
targetSymbol: meta.targetSymbol,
|
|
1151
|
+
viaHelper: meta.viaHelper,
|
|
1152
|
+
}).filter(([, v]) => v !== undefined))
|
|
1153
|
+
: undefined;
|
|
1154
|
+
return {
|
|
1155
|
+
id: e.id,
|
|
1156
|
+
name: e.name,
|
|
1157
|
+
entityType: e.entityType,
|
|
1158
|
+
...(e.confidence ? { confidence: e.confidence } : {}),
|
|
1159
|
+
sourceId: e.sourceId,
|
|
1160
|
+
...(e.targetId ? { targetId: e.targetId } : { unresolved: true }),
|
|
1161
|
+
...(compactEv ? { evidence: compactEv } : {}),
|
|
1162
|
+
...(Array.isArray(ev) && ev.length > 3 ? { evidenceCount: ev.length } : {}),
|
|
1163
|
+
...(compactMeta && Object.keys(compactMeta).length > 0
|
|
1164
|
+
? { metadata: compactMeta }
|
|
1165
|
+
: {}),
|
|
1166
|
+
};
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
699
1169
|
export async function runMcpServer(targetPath = process.cwd()) {
|
|
700
1170
|
const initialRepo = resolveActiveMcpRepo(targetPath);
|
|
701
1171
|
const repoLocalPluginsDir = resolve(initialRepo.repoPath, ".chomp", "plugins");
|
|
@@ -730,7 +1200,15 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
730
1200
|
enrichmentStatus: z
|
|
731
1201
|
.enum(["enriched", "unenriched", "stale"])
|
|
732
1202
|
.optional()
|
|
733
|
-
.describe("Alias for enrichment_status (camelCase)")
|
|
1203
|
+
.describe("Alias for enrichment_status (camelCase)"),
|
|
1204
|
+
limit: z
|
|
1205
|
+
.number()
|
|
1206
|
+
.optional()
|
|
1207
|
+
.describe("Maximum nodes to return (default: 50 when verbose is false)"),
|
|
1208
|
+
verbose: z
|
|
1209
|
+
.boolean()
|
|
1210
|
+
.optional()
|
|
1211
|
+
.describe("When true, returns full raw AST snippets, analyzedFiles, and expanded portValves field trees (default: false)")
|
|
734
1212
|
}, withMcpToolErrorBoundary(async (args) => {
|
|
735
1213
|
const { repoPath, repoId, dbPath } = resolveActiveMcpRepo(targetPath);
|
|
736
1214
|
if (!existsSync(dbPath)) {
|
|
@@ -794,8 +1272,12 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
794
1272
|
includeOverlays,
|
|
795
1273
|
layers: requestedLayers,
|
|
796
1274
|
});
|
|
1275
|
+
const responseNodes = formatCompactMcpNodes(filteredNodes, {
|
|
1276
|
+
verbose: args.verbose,
|
|
1277
|
+
limit: args.limit ?? 50,
|
|
1278
|
+
});
|
|
797
1279
|
return {
|
|
798
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
1280
|
+
content: [{ type: "text", text: JSON.stringify(responseNodes, null, 2) }]
|
|
799
1281
|
};
|
|
800
1282
|
}));
|
|
801
1283
|
server.tool("chomp_get_edges", "Use this tool to trace execution paths. If you need to know what a function calls, or what calls a function, pass the node ID here instead of using global text search. Edges originate from contracts, classes, public methods, or INIT_BLOCKs (top-level code run on module load) — never from files or DEPLOYMENT_UNITs — and calls into imported packages target `Package: X` OPEN_CONNECTORs.", {
|
|
@@ -807,7 +1289,10 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
807
1289
|
resolved_only: z.boolean().optional().describe("When true, returns only edges with a resolved targetId, suppressing unresolved LOW-confidence platform method calls"),
|
|
808
1290
|
resolvedOnly: z.boolean().optional().describe("Alias for resolved_only (camelCase)"),
|
|
809
1291
|
min_confidence: z.enum(["LOW", "MEDIUM", "HIGH"]).optional().describe("Optional minimum confidence threshold (LOW, MEDIUM, or HIGH). DETERMINISTIC edges always count as HIGH."),
|
|
810
|
-
minConfidence: z.enum(["LOW", "MEDIUM", "HIGH"]).optional().describe("Alias for min_confidence (camelCase)")
|
|
1292
|
+
minConfidence: z.enum(["LOW", "MEDIUM", "HIGH"]).optional().describe("Alias for min_confidence (camelCase)"),
|
|
1293
|
+
include_builtins: z.boolean().optional().describe("When true, includes unresolved BUILTIN_OR_PLATFORM calls (e.g. Array.map, String.trim; default: false)"),
|
|
1294
|
+
includeBuiltins: z.boolean().optional().describe("Alias for include_builtins (camelCase)"),
|
|
1295
|
+
verbose: z.boolean().optional().describe("When true, returns full raw AST edge snippets and metadata (default: false)")
|
|
811
1296
|
}, withMcpToolErrorBoundary(async (args) => {
|
|
812
1297
|
const { repoPath, repoId, dbPath } = resolveActiveMcpRepo(targetPath);
|
|
813
1298
|
if (!existsSync(dbPath)) {
|
|
@@ -851,8 +1336,12 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
851
1336
|
return edgeRank >= minRank;
|
|
852
1337
|
});
|
|
853
1338
|
}
|
|
1339
|
+
const responseEdges = formatCompactMcpEdges(filteredEdges, {
|
|
1340
|
+
verbose: args.verbose,
|
|
1341
|
+
includeBuiltins: args.include_builtins ?? args.includeBuiltins,
|
|
1342
|
+
});
|
|
854
1343
|
return {
|
|
855
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
1344
|
+
content: [{ type: "text", text: JSON.stringify(responseEdges, null, 2) }]
|
|
856
1345
|
};
|
|
857
1346
|
}));
|
|
858
1347
|
server.tool("chomp_get_diff", "Compares two git branches/commits (baseRef -> targetRef) or a point-in-time working-tree snapshot against the saved base graph in the Chomp SQLite database. Returns a structural delta summary and the ADDED, REMOVED, and MODIFIED entities (excluding UNCHANGED and LEXICAL_SHIFT noise by default).", {
|
|
@@ -863,7 +1352,8 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
863
1352
|
include_lexical_shift: z.boolean().optional().describe("When true, includes LEXICAL_SHIFT entries (line-number-only shifts) in nodes/edges"),
|
|
864
1353
|
includeLexicalShift: z.boolean().optional().describe("Alias for include_lexical_shift (camelCase)"),
|
|
865
1354
|
include_unchanged: z.boolean().optional().describe("When true, includes UNCHANGED entries in nodes/edges"),
|
|
866
|
-
includeUnchanged: z.boolean().optional().describe("Alias for include_unchanged (camelCase)")
|
|
1355
|
+
includeUnchanged: z.boolean().optional().describe("Alias for include_unchanged (camelCase)"),
|
|
1356
|
+
verbose: z.boolean().optional().describe("When true, returns full raw base/target AST node and edge records instead of compact summaries (default: false)")
|
|
867
1357
|
}, withMcpToolErrorBoundary(async (args) => {
|
|
868
1358
|
const { repoPath, repoId, dbPath } = resolveActiveMcpRepo(targetPath);
|
|
869
1359
|
const requestedBase = args.baseRef ?? args.base_ref;
|
|
@@ -909,48 +1399,11 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
909
1399
|
],
|
|
910
1400
|
};
|
|
911
1401
|
}
|
|
912
|
-
const
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
if (entry.status in counts) {
|
|
918
|
-
counts[entry.status]++;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
return counts;
|
|
922
|
-
};
|
|
923
|
-
const filterEntries = (record) => {
|
|
924
|
-
const out = {};
|
|
925
|
-
for (const [id, entry] of Object.entries(record)) {
|
|
926
|
-
if (entry.status === "UNCHANGED" && !includeUnchanged)
|
|
927
|
-
continue;
|
|
928
|
-
if (entry.status === "LEXICAL_SHIFT" && !includeLexical)
|
|
929
|
-
continue;
|
|
930
|
-
out[id] = entry;
|
|
931
|
-
}
|
|
932
|
-
return out;
|
|
933
|
-
};
|
|
934
|
-
const compactDelta = {
|
|
935
|
-
baseStatus: delta.baseStatus ?? "FRESH",
|
|
936
|
-
...(delta.baseRef ? { baseRef: delta.baseRef } : {}),
|
|
937
|
-
baseCommitSha: delta.baseCommitSha,
|
|
938
|
-
...(delta.targetRef ? { targetRef: delta.targetRef } : {}),
|
|
939
|
-
targetCommitSha: delta.targetCommitSha,
|
|
940
|
-
headCommitSha: delta.headCommitSha,
|
|
941
|
-
...(delta.isWorkingTreeSnapshot !== undefined
|
|
942
|
-
? { isWorkingTreeSnapshot: delta.isWorkingTreeSnapshot }
|
|
943
|
-
: {}),
|
|
944
|
-
...(delta.snapshotAt ? { snapshotAt: delta.snapshotAt } : {}),
|
|
945
|
-
baseExtractorVersion: delta.baseExtractorVersion,
|
|
946
|
-
targetExtractorVersion: delta.targetExtractorVersion,
|
|
947
|
-
summary: {
|
|
948
|
-
nodes: countStatuses(delta.nodes),
|
|
949
|
-
edges: countStatuses(delta.edges),
|
|
950
|
-
},
|
|
951
|
-
nodes: filterEntries(delta.nodes),
|
|
952
|
-
edges: filterEntries(delta.edges),
|
|
953
|
-
};
|
|
1402
|
+
const compactDelta = formatCompactMcpDiff(delta, {
|
|
1403
|
+
includeLexicalShift: Boolean(args?.include_lexical_shift ?? args?.includeLexicalShift),
|
|
1404
|
+
includeUnchanged: Boolean(args?.include_unchanged ?? args?.includeUnchanged),
|
|
1405
|
+
verbose: Boolean(args?.verbose),
|
|
1406
|
+
});
|
|
954
1407
|
return {
|
|
955
1408
|
content: [{ type: "text", text: JSON.stringify(compactDelta, null, 2) }]
|
|
956
1409
|
};
|
|
@@ -1094,45 +1547,117 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1094
1547
|
content: [{ type: "text", text: JSON.stringify(report, null, 2) }]
|
|
1095
1548
|
};
|
|
1096
1549
|
}));
|
|
1097
|
-
server.tool("chomp_find_redundancies", "ARCHITECTURAL REDUNDANCY & PATTERN ALIGNMENT DETECTOR: Scans the structural graph for (1) 1-to-1 pass-through wrapper functions that add indirection without branching or side effects, (2) parallel/duplicate call flows where multiple nodes invoke the exact same downstream target set, (3) duplicate symbol names across files/packages, and (4) outlier routes/endpoints that deviate from their package's dominant canonical wiring pattern.", {
|
|
1550
|
+
server.tool("chomp_find_redundancies", "ARCHITECTURAL REDUNDANCY & PATTERN ALIGNMENT DETECTOR: Scans the structural graph (automatically evaluating the live dirty working tree when uncommitted edits exist) for (1) 1-to-1 pass-through wrapper functions that add indirection without branching or side effects, (2) parallel/duplicate call flows where multiple nodes invoke the exact same downstream target set, (3) duplicate symbol names across files/packages, and (4) outlier routes/endpoints that deviate from their package's dominant canonical wiring pattern. Pass `only_new: true` (`diff_only: true`) during post-edit verification to report only newly introduced redundancies.", {
|
|
1098
1551
|
packageName: z.string().optional().describe("Optional filter by package / DEPLOYMENT_UNIT name (e.g., 'core', 'cli', 'mcp', 'web', 'db')"),
|
|
1099
1552
|
package_name: z.string().optional().describe("Alias for packageName (snake_case)"),
|
|
1100
|
-
limit: z.number().optional().describe("Maximum entries per redundancy category (default: 25)")
|
|
1553
|
+
limit: z.number().optional().describe("Maximum entries per redundancy category (default: 25)"),
|
|
1554
|
+
only_new: z.boolean().optional().describe("When true, compares against the saved baseline graph and returns only newly introduced redundancies (default: false)"),
|
|
1555
|
+
onlyNew: z.boolean().optional().describe("Alias for only_new (camelCase)"),
|
|
1556
|
+
diff_only: z.boolean().optional().describe("Alias for only_new"),
|
|
1557
|
+
diffOnly: z.boolean().optional().describe("Alias for only_new (camelCase)")
|
|
1101
1558
|
}, withMcpToolErrorBoundary(async (args) => {
|
|
1102
1559
|
const { repoPath, repoId, dbPath } = resolveActiveMcpRepo(targetPath);
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1560
|
+
const onlyNew = Boolean(args.only_new ?? args.onlyNew ?? args.diff_only ?? args.diffOnly);
|
|
1561
|
+
const pkgFilter = args.packageName ?? args.package_name;
|
|
1562
|
+
const { targetGraph, baseGraph, evaluatedSource } = await resolveLiveAndBaseGraphsForMcp(repoPath, dbPath, repoId, {
|
|
1563
|
+
needBaseGraph: onlyNew,
|
|
1564
|
+
});
|
|
1565
|
+
if (onlyNew && baseGraph) {
|
|
1566
|
+
const gate = computeArchitecturalDiffGate(baseGraph, targetGraph, {
|
|
1567
|
+
repoPath,
|
|
1568
|
+
packageName: pkgFilter,
|
|
1569
|
+
limit: args.limit,
|
|
1570
|
+
});
|
|
1571
|
+
const deltaReport = {
|
|
1572
|
+
evaluatedSource,
|
|
1573
|
+
diffOnly: true,
|
|
1574
|
+
gateStatus: gate.summary.newPassThroughWrapperCount +
|
|
1575
|
+
gate.summary.newDuplicateFlowCount +
|
|
1576
|
+
gate.summary.newDuplicateSymbolCount ===
|
|
1577
|
+
0
|
|
1578
|
+
? "PASS"
|
|
1579
|
+
: "WARN",
|
|
1580
|
+
summary: {
|
|
1581
|
+
passThroughMiddlemenCount: gate.summary.newPassThroughWrapperCount,
|
|
1582
|
+
duplicateStorySequenceGroups: gate.summary.newDuplicateFlowCount,
|
|
1583
|
+
duplicateSymbolCount: gate.summary.newDuplicateSymbolCount,
|
|
1584
|
+
patternAlignmentOpportunityCount: 0,
|
|
1585
|
+
},
|
|
1586
|
+
passThroughMiddlemen: gate.newPassThroughWrappers,
|
|
1587
|
+
duplicateStorySequences: gate.newDuplicateFlows,
|
|
1588
|
+
duplicateSymbols: gate.newDuplicateSymbols,
|
|
1589
|
+
patternAlignmentOpportunities: [],
|
|
1590
|
+
};
|
|
1591
|
+
return {
|
|
1592
|
+
content: [{ type: "text", text: JSON.stringify(deltaReport, null, 2) }],
|
|
1593
|
+
};
|
|
1109
1594
|
}
|
|
1110
|
-
const report = findGraphRedundancies(
|
|
1111
|
-
packageName:
|
|
1595
|
+
const report = findGraphRedundancies(targetGraph, {
|
|
1596
|
+
packageName: pkgFilter,
|
|
1112
1597
|
limit: args.limit,
|
|
1113
1598
|
});
|
|
1114
1599
|
return {
|
|
1115
|
-
content: [
|
|
1600
|
+
content: [
|
|
1601
|
+
{
|
|
1602
|
+
type: "text",
|
|
1603
|
+
text: JSON.stringify({ evaluatedSource, ...report }, null, 2),
|
|
1604
|
+
},
|
|
1605
|
+
],
|
|
1116
1606
|
};
|
|
1117
1607
|
}));
|
|
1118
|
-
server.tool("chomp_check_boundaries", "BOUNDARY & TOPOLOGICAL LAYER CHECKER: Analyzes cross-package dependency topology, assigns each DEPLOYMENT_UNIT to an architectural tier (ENTRY_APPLICATION, SERVICE_ORCHESTRATOR, INFRASTRUCTURE_ADAPTER, FOUNDATION_CORE, ISOLATED_PACKAGE), detects package-level and node-level circular dependencies and self-loops, flags boundary isolation or upward layer violations, and surfaces cross-package seam & missing-link diagnostics (`ISOLATED_DEPLOYMENT_UNITS`, `UNSTITCHED_PROTOCOL_SEAM`, `INIT_BLOCK_CONNECTOR_LEAK`).", {
|
|
1608
|
+
server.tool("chomp_check_boundaries", "BOUNDARY & TOPOLOGICAL LAYER CHECKER: Analyzes cross-package dependency topology (automatically evaluating the live dirty working tree when uncommitted edits exist), assigns each DEPLOYMENT_UNIT to an architectural tier (ENTRY_APPLICATION, SERVICE_ORCHESTRATOR, INFRASTRUCTURE_ADAPTER, FOUNDATION_CORE, ISOLATED_PACKAGE), detects package-level and node-level circular dependencies and self-loops, flags boundary isolation or upward layer violations, and surfaces cross-package seam & missing-link diagnostics (`ISOLATED_DEPLOYMENT_UNITS`, `UNSTITCHED_PROTOCOL_SEAM`, `INIT_BLOCK_CONNECTOR_LEAK`). Pass `only_new: true` (`diff_only: true`) during post-edit verification to report only newly introduced boundary violations or cycles.", {
|
|
1119
1609
|
packageName: z.string().optional().describe("Optional filter by package / DEPLOYMENT_UNIT name (e.g., 'core', 'cli', 'mcp', 'web', 'db')"),
|
|
1120
|
-
package_name: z.string().optional().describe("Alias for packageName (snake_case)")
|
|
1610
|
+
package_name: z.string().optional().describe("Alias for packageName (snake_case)"),
|
|
1611
|
+
only_new: z.boolean().optional().describe("When true, compares against the saved baseline graph and returns only newly introduced boundary violations and cycles (default: false)"),
|
|
1612
|
+
onlyNew: z.boolean().optional().describe("Alias for only_new (camelCase)"),
|
|
1613
|
+
diff_only: z.boolean().optional().describe("Alias for only_new"),
|
|
1614
|
+
diffOnly: z.boolean().optional().describe("Alias for only_new (camelCase)")
|
|
1121
1615
|
}, withMcpToolErrorBoundary(async (args) => {
|
|
1122
1616
|
const { repoPath, repoId, dbPath } = resolveActiveMcpRepo(targetPath);
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1617
|
+
const onlyNew = Boolean(args.only_new ?? args.onlyNew ?? args.diff_only ?? args.diffOnly);
|
|
1618
|
+
const pkgFilter = args.packageName ?? args.package_name;
|
|
1619
|
+
const { targetGraph, baseGraph, evaluatedSource } = await resolveLiveAndBaseGraphsForMcp(repoPath, dbPath, repoId, {
|
|
1620
|
+
needBaseGraph: onlyNew,
|
|
1621
|
+
});
|
|
1622
|
+
if (onlyNew && baseGraph) {
|
|
1623
|
+
const gate = computeArchitecturalDiffGate(baseGraph, targetGraph, {
|
|
1624
|
+
repoPath,
|
|
1625
|
+
packageName: pkgFilter,
|
|
1626
|
+
});
|
|
1627
|
+
const hardCount = gate.newBoundaryViolations.filter((v) => v.severity === "VIOLATION").length;
|
|
1628
|
+
const advCount = gate.newBoundaryViolations.filter((v) => v.severity === "ADVISORY").length;
|
|
1629
|
+
const deltaReport = {
|
|
1630
|
+
evaluatedSource,
|
|
1631
|
+
diffOnly: true,
|
|
1632
|
+
status: hardCount > 0 || gate.newCycles.packageCycles.length > 0
|
|
1633
|
+
? "VIOLATION"
|
|
1634
|
+
: advCount > 0 || gate.newCycles.contractCycles.length > 0
|
|
1635
|
+
? "ADVISORY"
|
|
1636
|
+
: "CLEAN",
|
|
1637
|
+
summary: {
|
|
1638
|
+
packageCycleCount: gate.newCycles.packageCycles.length,
|
|
1639
|
+
contractCycleCount: gate.newCycles.contractCycles.length,
|
|
1640
|
+
boundaryViolationCount: hardCount,
|
|
1641
|
+
boundaryAdvisoryCount: advCount,
|
|
1642
|
+
},
|
|
1643
|
+
circularDependencies: gate.newCycles,
|
|
1644
|
+
boundaryViolations: gate.newBoundaryViolations,
|
|
1645
|
+
};
|
|
1646
|
+
return {
|
|
1647
|
+
content: [{ type: "text", text: JSON.stringify(deltaReport, null, 2) }],
|
|
1648
|
+
};
|
|
1129
1649
|
}
|
|
1130
|
-
const report = checkGraphBoundaries(
|
|
1131
|
-
packageName:
|
|
1650
|
+
const report = checkGraphBoundaries(targetGraph, {
|
|
1651
|
+
packageName: pkgFilter,
|
|
1132
1652
|
repoPath,
|
|
1133
1653
|
});
|
|
1134
1654
|
return {
|
|
1135
|
-
content: [
|
|
1655
|
+
content: [
|
|
1656
|
+
{
|
|
1657
|
+
type: "text",
|
|
1658
|
+
text: JSON.stringify({ evaluatedSource, ...report }, null, 2),
|
|
1659
|
+
},
|
|
1660
|
+
],
|
|
1136
1661
|
};
|
|
1137
1662
|
}));
|
|
1138
1663
|
server.tool("chomp_get_blast_radius", "MANDATORY PRE-EDIT IMPACT ANALYSIS: Call this tool BEFORE modifying or refactoring a function, class, route, or package boundary to compute its upstream dependent callers, downstream dependencies, external OPEN_CONNECTOR side effects, affected entry points, affected packages, and input/output type schemas. Leave `create_view: false` (default) during coding/refactoring tasks; pass `create_view: true` only when answering user questions about impact or blast radius.", {
|
|
@@ -1276,7 +1801,7 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1276
1801
|
include_schema: z
|
|
1277
1802
|
.boolean()
|
|
1278
1803
|
.optional()
|
|
1279
|
-
.describe("When true
|
|
1804
|
+
.describe("When true, includes the full NodeMatcher / EdgeMatcher / EmitTemplate schema reference and config templates (default: false; pass true only when authoring chomp.config.json#conventions)."),
|
|
1280
1805
|
includeSchema: z.boolean().optional().describe("Alias for include_schema (camelCase)"),
|
|
1281
1806
|
}, withMcpToolErrorBoundary(async (args) => {
|
|
1282
1807
|
const { repoPath } = resolveActiveMcpRepo(targetPath);
|
|
@@ -1287,7 +1812,7 @@ export async function runMcpServer(targetPath = process.cwd()) {
|
|
|
1287
1812
|
signalKind: args.signal_kind ?? args.signalKind,
|
|
1288
1813
|
shapeKey: args.shape_key ?? args.shapeKey,
|
|
1289
1814
|
searchTerm: args.search_term ?? args.searchTerm,
|
|
1290
|
-
includeSchema: args.include_schema ?? args.includeSchema ??
|
|
1815
|
+
includeSchema: args.include_schema ?? args.includeSchema ?? false,
|
|
1291
1816
|
});
|
|
1292
1817
|
return {
|
|
1293
1818
|
content: [{ type: "text", text: JSON.stringify(report, null, 2) }],
|