grepmax 0.7.12 → 0.7.13
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/commands/mcp.js
CHANGED
|
@@ -226,6 +226,10 @@ const TOOLS = [
|
|
|
226
226
|
type: "string",
|
|
227
227
|
description: "The function, method, or class name to trace (e.g. 'handleAuth')",
|
|
228
228
|
},
|
|
229
|
+
depth: {
|
|
230
|
+
type: "number",
|
|
231
|
+
description: "Traversal depth for callers (default 1, max 3). depth: 2 shows callers-of-callers.",
|
|
232
|
+
},
|
|
229
233
|
},
|
|
230
234
|
required: ["symbol"],
|
|
231
235
|
},
|
|
@@ -861,20 +865,29 @@ exports.mcp = new commander_1.Command("mcp")
|
|
|
861
865
|
try {
|
|
862
866
|
const db = getVectorDb();
|
|
863
867
|
const builder = new graph_builder_1.GraphBuilder(db);
|
|
864
|
-
const
|
|
868
|
+
const depth = Math.min(Math.max(Number(args.depth) || 1, 1), 3);
|
|
869
|
+
const graph = yield builder.buildGraphMultiHop(symbol, depth);
|
|
865
870
|
if (!graph.center) {
|
|
866
871
|
return ok(`Symbol '${symbol}' not found in the index.`);
|
|
867
872
|
}
|
|
868
873
|
const lines = [];
|
|
869
874
|
// Center
|
|
870
875
|
lines.push(`${graph.center.symbol} [${graph.center.role}] ${graph.center.file}:${graph.center.line + 1}`);
|
|
871
|
-
// Callers
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
+
// Callers (recursive tree)
|
|
877
|
+
function formatCallerTree(trees, indent) {
|
|
878
|
+
for (const t of trees) {
|
|
879
|
+
const rel = t.node.file.startsWith(projectRoot)
|
|
880
|
+
? t.node.file.slice(projectRoot.length + 1)
|
|
881
|
+
: t.node.file;
|
|
882
|
+
const pad = " ".repeat(indent);
|
|
883
|
+
lines.push(`${pad}<- ${t.node.symbol} ${rel}:${t.node.line + 1}`);
|
|
884
|
+
formatCallerTree(t.callers, indent + 1);
|
|
876
885
|
}
|
|
877
886
|
}
|
|
887
|
+
if (graph.callerTree.length > 0) {
|
|
888
|
+
lines.push("Callers:");
|
|
889
|
+
formatCallerTree(graph.callerTree, 1);
|
|
890
|
+
}
|
|
878
891
|
else {
|
|
879
892
|
lines.push("Callers: none");
|
|
880
893
|
}
|
|
@@ -105,6 +105,40 @@ class GraphBuilder {
|
|
|
105
105
|
return { center, callers, callees: calleeNodes };
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
+
buildGraphMultiHop(symbol, depth) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const graph = yield this.buildGraph(symbol);
|
|
111
|
+
if (depth <= 1 || !graph.center) {
|
|
112
|
+
return {
|
|
113
|
+
center: graph.center,
|
|
114
|
+
callerTree: graph.callers.map((c) => ({ node: c, callers: [] })),
|
|
115
|
+
callees: graph.callees,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const visited = new Set([symbol]);
|
|
119
|
+
const callerTree = yield this.expandCallers(graph.callers, depth - 1, visited);
|
|
120
|
+
return { center: graph.center, callerTree, callees: graph.callees };
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
expandCallers(callers, remainingDepth, visited) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const trees = [];
|
|
126
|
+
for (const caller of callers) {
|
|
127
|
+
if (visited.has(caller.symbol)) {
|
|
128
|
+
trees.push({ node: caller, callers: [] });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
visited.add(caller.symbol);
|
|
132
|
+
let subCallers = [];
|
|
133
|
+
if (remainingDepth > 0) {
|
|
134
|
+
const upstreamCallers = yield this.getCallers(caller.symbol);
|
|
135
|
+
subCallers = yield this.expandCallers(upstreamCallers, remainingDepth - 1, visited);
|
|
136
|
+
}
|
|
137
|
+
trees.push({ node: caller, callers: subCallers });
|
|
138
|
+
}
|
|
139
|
+
return trees;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
108
142
|
mapRowToNode(row, targetSymbol, type) {
|
|
109
143
|
// Helper to convert Arrow Vector to array if needed
|
|
110
144
|
const toArray = (val) => {
|
package/package.json
CHANGED
|
@@ -71,6 +71,7 @@ File or directory structure — signatures with bodies collapsed (~4x fewer toke
|
|
|
71
71
|
### trace_calls
|
|
72
72
|
Call graph — who calls a symbol and what it calls. Callers and callees include file:line locations. Unscoped — follows calls across all indexed directories.
|
|
73
73
|
- `symbol` (required): Function/method/class name
|
|
74
|
+
- `depth` (optional): Traversal depth for callers (default 1, max 3). depth: 2 shows callers-of-callers with indentation.
|
|
74
75
|
|
|
75
76
|
### list_symbols
|
|
76
77
|
List indexed symbols with definition locations, role, and export status.
|