@compilr-dev/agents-coding-go 0.1.0
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/LICENSE +21 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/parser/go-parser.d.ts +104 -0
- package/dist/parser/go-parser.d.ts.map +1 -0
- package/dist/parser/go-parser.js +492 -0
- package/dist/parser/index.d.ts +6 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +5 -0
- package/dist/parser/node-types.d.ts +130 -0
- package/dist/parser/node-types.d.ts.map +1 -0
- package/dist/parser/node-types.js +4 -0
- package/dist/skills/go-best-practices.d.ts +7 -0
- package/dist/skills/go-best-practices.d.ts.map +1 -0
- package/dist/skills/go-best-practices.js +78 -0
- package/dist/skills/go-code-health.d.ts +7 -0
- package/dist/skills/go-code-health.d.ts.map +1 -0
- package/dist/skills/go-code-health.js +209 -0
- package/dist/skills/go-code-structure.d.ts +7 -0
- package/dist/skills/go-code-structure.d.ts.map +1 -0
- package/dist/skills/go-code-structure.js +155 -0
- package/dist/skills/go-dependency-audit.d.ts +7 -0
- package/dist/skills/go-dependency-audit.d.ts.map +1 -0
- package/dist/skills/go-dependency-audit.js +246 -0
- package/dist/skills/go-refactor-impact.d.ts +7 -0
- package/dist/skills/go-refactor-impact.d.ts.map +1 -0
- package/dist/skills/go-refactor-impact.js +232 -0
- package/dist/skills/index.d.ts +26 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +36 -0
- package/dist/tools/extract-docstrings.d.ts +51 -0
- package/dist/tools/extract-docstrings.d.ts.map +1 -0
- package/dist/tools/extract-docstrings.js +292 -0
- package/dist/tools/find-dead-code.d.ts +62 -0
- package/dist/tools/find-dead-code.d.ts.map +1 -0
- package/dist/tools/find-dead-code.js +422 -0
- package/dist/tools/find-duplicates.d.ts +65 -0
- package/dist/tools/find-duplicates.d.ts.map +1 -0
- package/dist/tools/find-duplicates.js +289 -0
- package/dist/tools/find-implementations.d.ts +71 -0
- package/dist/tools/find-implementations.d.ts.map +1 -0
- package/dist/tools/find-implementations.js +342 -0
- package/dist/tools/find-patterns.d.ts +71 -0
- package/dist/tools/find-patterns.d.ts.map +1 -0
- package/dist/tools/find-patterns.js +477 -0
- package/dist/tools/find-references.d.ts +66 -0
- package/dist/tools/find-references.d.ts.map +1 -0
- package/dist/tools/find-references.js +306 -0
- package/dist/tools/find-symbol.d.ts +86 -0
- package/dist/tools/find-symbol.d.ts.map +1 -0
- package/dist/tools/find-symbol.js +380 -0
- package/dist/tools/get-call-graph.d.ts +89 -0
- package/dist/tools/get-call-graph.d.ts.map +1 -0
- package/dist/tools/get-call-graph.js +431 -0
- package/dist/tools/get-class-hierarchy.d.ts +34 -0
- package/dist/tools/get-class-hierarchy.d.ts.map +1 -0
- package/dist/tools/get-class-hierarchy.js +250 -0
- package/dist/tools/get-complexity.d.ts +53 -0
- package/dist/tools/get-complexity.d.ts.map +1 -0
- package/dist/tools/get-complexity.js +357 -0
- package/dist/tools/get-dependency-graph.d.ts +85 -0
- package/dist/tools/get-dependency-graph.d.ts.map +1 -0
- package/dist/tools/get-dependency-graph.js +389 -0
- package/dist/tools/get-exports.d.ts +78 -0
- package/dist/tools/get-exports.d.ts.map +1 -0
- package/dist/tools/get-exports.js +437 -0
- package/dist/tools/get-file-structure.d.ts +28 -0
- package/dist/tools/get-file-structure.d.ts.map +1 -0
- package/dist/tools/get-file-structure.js +172 -0
- package/dist/tools/get-imports.d.ts +30 -0
- package/dist/tools/get-imports.d.ts.map +1 -0
- package/dist/tools/get-imports.js +420 -0
- package/dist/tools/get-signature.d.ts +100 -0
- package/dist/tools/get-signature.d.ts.map +1 -0
- package/dist/tools/get-signature.js +800 -0
- package/dist/tools/index.d.ts +55 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +75 -0
- package/dist/tools/types.d.ts +408 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +4 -0
- package/package.json +86 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* findSymbol Tool
|
|
3
|
+
*
|
|
4
|
+
* Find the definition location of a symbol across Go codebases.
|
|
5
|
+
* Uses Tree-sitter for AST analysis.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from "node:fs/promises";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import { defineTool, createSuccessResult, createErrorResult, } from "@compilr-dev/agents";
|
|
10
|
+
import { parseFile, parseClass, parseFunction, parseMethod, parseVariable, isExported, walkTree, getNodeText, } from "../parser/go-parser.js";
|
|
11
|
+
// Supported file extensions for searching
|
|
12
|
+
const SUPPORTED_EXTENSIONS = new Set([".go"]);
|
|
13
|
+
// Tool description
|
|
14
|
+
const TOOL_DESCRIPTION = `Find the definition location of a symbol by name across Go codebases.
|
|
15
|
+
Returns structured JSON with file path, line number, symbol kind, and other metadata.
|
|
16
|
+
Use this to locate where functions, structs, interfaces, variables, etc. are defined.`;
|
|
17
|
+
// Tool input schema
|
|
18
|
+
const TOOL_INPUT_SCHEMA = {
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {
|
|
21
|
+
symbol: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "Symbol name to find",
|
|
24
|
+
},
|
|
25
|
+
scope: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Scope the search to a specific file or directory",
|
|
28
|
+
},
|
|
29
|
+
kind: {
|
|
30
|
+
type: "string",
|
|
31
|
+
enum: [
|
|
32
|
+
"function",
|
|
33
|
+
"struct",
|
|
34
|
+
"interface",
|
|
35
|
+
"method",
|
|
36
|
+
"variable",
|
|
37
|
+
"constant",
|
|
38
|
+
"type",
|
|
39
|
+
"any",
|
|
40
|
+
],
|
|
41
|
+
description: "Filter by symbol kind (default: any)",
|
|
42
|
+
default: "any",
|
|
43
|
+
},
|
|
44
|
+
limit: {
|
|
45
|
+
type: "number",
|
|
46
|
+
description: "Maximum results to return (default: 10)",
|
|
47
|
+
default: 10,
|
|
48
|
+
},
|
|
49
|
+
includeVendor: {
|
|
50
|
+
type: "boolean",
|
|
51
|
+
description: "Include symbols from vendor directory (default: false)",
|
|
52
|
+
default: false,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
required: ["symbol"],
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* findSymbol tool - Find symbol definitions in Go
|
|
59
|
+
*/
|
|
60
|
+
export const findSymbolTool = defineTool({
|
|
61
|
+
name: "find_symbol_go",
|
|
62
|
+
description: TOOL_DESCRIPTION,
|
|
63
|
+
inputSchema: TOOL_INPUT_SCHEMA,
|
|
64
|
+
execute: executeFindSymbol,
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* Execute the findSymbol tool
|
|
68
|
+
*/
|
|
69
|
+
async function executeFindSymbol(input) {
|
|
70
|
+
const { symbol, scope, kind = "any", limit = 10, includeVendor = false, } = input;
|
|
71
|
+
// Validate input
|
|
72
|
+
if (!symbol || symbol.trim().length === 0) {
|
|
73
|
+
return createErrorResult("Symbol name is required");
|
|
74
|
+
}
|
|
75
|
+
const startTime = Date.now();
|
|
76
|
+
const definitions = [];
|
|
77
|
+
let filesSearched = 0;
|
|
78
|
+
try {
|
|
79
|
+
// Determine search path
|
|
80
|
+
const searchPath = scope || process.cwd();
|
|
81
|
+
// Check if path exists
|
|
82
|
+
try {
|
|
83
|
+
await fs.access(searchPath);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return createErrorResult(`Path not found: ${searchPath}`);
|
|
87
|
+
}
|
|
88
|
+
const stats = await fs.stat(searchPath);
|
|
89
|
+
if (stats.isFile()) {
|
|
90
|
+
// Search single file
|
|
91
|
+
if (isGoFile(searchPath)) {
|
|
92
|
+
filesSearched = 1;
|
|
93
|
+
const fileDefinitions = await searchFileForSymbol(searchPath, symbol, kind);
|
|
94
|
+
definitions.push(...fileDefinitions);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (stats.isDirectory()) {
|
|
98
|
+
// Search directory recursively
|
|
99
|
+
const files = await collectFiles(searchPath, includeVendor);
|
|
100
|
+
filesSearched = files.length;
|
|
101
|
+
for (const filePath of files) {
|
|
102
|
+
if (definitions.length >= limit)
|
|
103
|
+
break;
|
|
104
|
+
const fileDefinitions = await searchFileForSymbol(filePath, symbol, kind);
|
|
105
|
+
const remaining = limit - definitions.length;
|
|
106
|
+
definitions.push(...fileDefinitions.slice(0, remaining));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return createErrorResult(`Path is neither a file nor directory: ${searchPath}`);
|
|
111
|
+
}
|
|
112
|
+
const endTime = Date.now();
|
|
113
|
+
const result = {
|
|
114
|
+
query: symbol,
|
|
115
|
+
definitions: definitions.slice(0, limit),
|
|
116
|
+
stats: {
|
|
117
|
+
filesSearched,
|
|
118
|
+
timeMs: endTime - startTime,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
return createSuccessResult(result);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
125
|
+
return createErrorResult(`Failed to search for symbol: ${message}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Check if a file is a Go file
|
|
130
|
+
*/
|
|
131
|
+
function isGoFile(filePath) {
|
|
132
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
133
|
+
return SUPPORTED_EXTENSIONS.has(ext);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Collect all Go files in a directory recursively
|
|
137
|
+
*/
|
|
138
|
+
async function collectFiles(dir, includeVendor) {
|
|
139
|
+
const files = [];
|
|
140
|
+
async function walk(currentDir) {
|
|
141
|
+
const entries = await fs.readdir(currentDir, { withFileTypes: true });
|
|
142
|
+
for (const entry of entries) {
|
|
143
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
144
|
+
if (entry.isDirectory()) {
|
|
145
|
+
// Skip vendor unless explicitly included
|
|
146
|
+
if (!includeVendor && entry.name === "vendor") {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
// Skip common non-source directories
|
|
150
|
+
if (entry.name.startsWith(".") ||
|
|
151
|
+
entry.name === "testdata" ||
|
|
152
|
+
entry.name === "node_modules") {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
await walk(fullPath);
|
|
156
|
+
}
|
|
157
|
+
else if (entry.isFile()) {
|
|
158
|
+
if (isGoFile(fullPath)) {
|
|
159
|
+
files.push(fullPath);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
await walk(dir);
|
|
165
|
+
return files;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Search a single file for symbol definitions
|
|
169
|
+
*/
|
|
170
|
+
async function searchFileForSymbol(filePath, symbolName, kindFilter) {
|
|
171
|
+
const definitions = [];
|
|
172
|
+
try {
|
|
173
|
+
const parseResult = await parseFile(filePath);
|
|
174
|
+
const { tree, source } = parseResult;
|
|
175
|
+
const rootNode = tree.rootNode;
|
|
176
|
+
// Walk the AST looking for definitions
|
|
177
|
+
for (const node of walkTree(rootNode)) {
|
|
178
|
+
// Function declarations
|
|
179
|
+
if (node.type === "function_declaration") {
|
|
180
|
+
const funcInfo = parseFunction(node, source);
|
|
181
|
+
if (funcInfo.name === symbolName) {
|
|
182
|
+
if (kindFilter === "any" || kindFilter === "function") {
|
|
183
|
+
definitions.push({
|
|
184
|
+
name: funcInfo.name,
|
|
185
|
+
path: filePath,
|
|
186
|
+
line: funcInfo.line,
|
|
187
|
+
column: funcInfo.column + 1,
|
|
188
|
+
kind: "function",
|
|
189
|
+
isExported: isExported(funcInfo.name),
|
|
190
|
+
signature: buildFunctionSignature(funcInfo),
|
|
191
|
+
docSummary: funcInfo.docstring?.split("\n")[0],
|
|
192
|
+
confidence: 1.0,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Method declarations (function with receiver)
|
|
198
|
+
if (node.type === "method_declaration") {
|
|
199
|
+
const methodInfo = parseMethod(node, source);
|
|
200
|
+
if (methodInfo.name === symbolName) {
|
|
201
|
+
if (kindFilter === "any" || kindFilter === "method") {
|
|
202
|
+
definitions.push({
|
|
203
|
+
name: methodInfo.name,
|
|
204
|
+
path: filePath,
|
|
205
|
+
line: methodInfo.line,
|
|
206
|
+
column: methodInfo.column + 1,
|
|
207
|
+
kind: "method",
|
|
208
|
+
container: methodInfo.receiverType,
|
|
209
|
+
isExported: isExported(methodInfo.name),
|
|
210
|
+
signature: buildMethodSignature(methodInfo),
|
|
211
|
+
docSummary: methodInfo.docstring?.split("\n")[0],
|
|
212
|
+
confidence: 1.0,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// Type declarations (struct, interface, type alias)
|
|
218
|
+
if (node.type === "type_declaration") {
|
|
219
|
+
const typeInfo = parseClass(node, source);
|
|
220
|
+
if (typeInfo.name === symbolName) {
|
|
221
|
+
const typeKind = typeInfo.isInterface
|
|
222
|
+
? "interface"
|
|
223
|
+
: typeInfo.isStruct
|
|
224
|
+
? "struct"
|
|
225
|
+
: "type";
|
|
226
|
+
if (kindFilter === "any" || kindFilter === typeKind) {
|
|
227
|
+
definitions.push({
|
|
228
|
+
name: typeInfo.name,
|
|
229
|
+
path: filePath,
|
|
230
|
+
line: typeInfo.line,
|
|
231
|
+
column: typeInfo.column + 1,
|
|
232
|
+
kind: typeKind,
|
|
233
|
+
isExported: isExported(typeInfo.name),
|
|
234
|
+
signature: buildTypeSignature(typeInfo),
|
|
235
|
+
docSummary: typeInfo.docstring?.split("\n")[0],
|
|
236
|
+
confidence: 1.0,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// Variable and constant declarations
|
|
242
|
+
if (node.type === "var_declaration" ||
|
|
243
|
+
node.type === "const_declaration") {
|
|
244
|
+
const varInfos = parseVariable(node, source);
|
|
245
|
+
for (const varInfo of varInfos) {
|
|
246
|
+
if (varInfo.name === symbolName) {
|
|
247
|
+
const varKind = varInfo.isConstant
|
|
248
|
+
? "constant"
|
|
249
|
+
: "variable";
|
|
250
|
+
if (kindFilter === "any" ||
|
|
251
|
+
kindFilter === varKind ||
|
|
252
|
+
(kindFilter === "variable" && varKind === "constant")) {
|
|
253
|
+
definitions.push({
|
|
254
|
+
name: varInfo.name,
|
|
255
|
+
path: filePath,
|
|
256
|
+
line: varInfo.line,
|
|
257
|
+
column: (varInfo.column ?? 0) + 1,
|
|
258
|
+
kind: varKind,
|
|
259
|
+
isExported: isExported(varInfo.name),
|
|
260
|
+
signature: buildVariableSignature(varInfo),
|
|
261
|
+
confidence: 1.0,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// Short variable declarations (:=)
|
|
268
|
+
if (node.type === "short_var_declaration") {
|
|
269
|
+
const leftSide = node.childForFieldName("left");
|
|
270
|
+
if (leftSide) {
|
|
271
|
+
for (const child of leftSide.children) {
|
|
272
|
+
if (child.type === "identifier") {
|
|
273
|
+
const name = getNodeText(child, source);
|
|
274
|
+
if (name === symbolName) {
|
|
275
|
+
if (kindFilter === "any" || kindFilter === "variable") {
|
|
276
|
+
definitions.push({
|
|
277
|
+
name,
|
|
278
|
+
path: filePath,
|
|
279
|
+
line: child.startPosition.row + 1,
|
|
280
|
+
column: child.startPosition.column + 1,
|
|
281
|
+
kind: "variable",
|
|
282
|
+
isExported: isExported(name),
|
|
283
|
+
signature: name,
|
|
284
|
+
confidence: 1.0,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
// Silently skip files that can't be parsed
|
|
296
|
+
}
|
|
297
|
+
return definitions;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Build a function signature string
|
|
301
|
+
*/
|
|
302
|
+
function buildFunctionSignature(func) {
|
|
303
|
+
const params = func.parameters
|
|
304
|
+
.map((p) => {
|
|
305
|
+
if (p.type)
|
|
306
|
+
return `${p.name} ${p.type}`;
|
|
307
|
+
return p.name;
|
|
308
|
+
})
|
|
309
|
+
.join(", ");
|
|
310
|
+
const returnType = func.returnType ? ` ${func.returnType}` : "";
|
|
311
|
+
return `func ${func.name}(${params})${returnType}`;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Build a method signature string
|
|
315
|
+
*/
|
|
316
|
+
function buildMethodSignature(method) {
|
|
317
|
+
const receiver = method.receiverType
|
|
318
|
+
? method.isPointerReceiver
|
|
319
|
+
? `(*${method.receiverType})`
|
|
320
|
+
: `(${method.receiverType})`
|
|
321
|
+
: "";
|
|
322
|
+
const params = method.parameters
|
|
323
|
+
.map((p) => {
|
|
324
|
+
if (p.type)
|
|
325
|
+
return `${p.name} ${p.type}`;
|
|
326
|
+
return p.name;
|
|
327
|
+
})
|
|
328
|
+
.join(", ");
|
|
329
|
+
const returnType = method.returnType ? ` ${method.returnType}` : "";
|
|
330
|
+
return `func ${receiver} ${method.name}(${params})${returnType}`;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Build a type signature string
|
|
334
|
+
*/
|
|
335
|
+
function buildTypeSignature(typeInfo) {
|
|
336
|
+
if (typeInfo.isInterface) {
|
|
337
|
+
return `type ${typeInfo.name} interface`;
|
|
338
|
+
}
|
|
339
|
+
if (typeInfo.isStruct) {
|
|
340
|
+
const embeds = typeInfo.bases.length > 0
|
|
341
|
+
? ` (embeds: ${typeInfo.bases.join(", ")})`
|
|
342
|
+
: "";
|
|
343
|
+
return `type ${typeInfo.name} struct${embeds}`;
|
|
344
|
+
}
|
|
345
|
+
return `type ${typeInfo.name}`;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Build a variable signature string
|
|
349
|
+
*/
|
|
350
|
+
function buildVariableSignature(varInfo) {
|
|
351
|
+
const keyword = varInfo.isConstant ? "const" : "var";
|
|
352
|
+
let sig = `${keyword} ${varInfo.name}`;
|
|
353
|
+
if (varInfo.type)
|
|
354
|
+
sig += ` ${varInfo.type}`;
|
|
355
|
+
if (varInfo.value) {
|
|
356
|
+
const valuePreview = varInfo.value.length > 50
|
|
357
|
+
? varInfo.value.substring(0, 47) + "..."
|
|
358
|
+
: varInfo.value;
|
|
359
|
+
sig += ` = ${valuePreview}`;
|
|
360
|
+
}
|
|
361
|
+
return sig;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Factory function to create a customized findSymbol tool
|
|
365
|
+
*/
|
|
366
|
+
export function createFindSymbolTool(options) {
|
|
367
|
+
const { defaultLimit = 10, defaultIncludeVendor = false } = options ?? {};
|
|
368
|
+
return defineTool({
|
|
369
|
+
name: "find_symbol_go",
|
|
370
|
+
description: TOOL_DESCRIPTION,
|
|
371
|
+
inputSchema: TOOL_INPUT_SCHEMA,
|
|
372
|
+
execute: async (input) => {
|
|
373
|
+
return executeFindSymbol({
|
|
374
|
+
...input,
|
|
375
|
+
limit: input.limit ?? defaultLimit,
|
|
376
|
+
includeVendor: input.includeVendor ?? defaultIncludeVendor,
|
|
377
|
+
});
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* getCallGraph Tool
|
|
3
|
+
*
|
|
4
|
+
* Analyze function call relationships in Go code.
|
|
5
|
+
* Returns a call graph showing what functions call what.
|
|
6
|
+
*/
|
|
7
|
+
import type { Tool } from "@compilr-dev/agents";
|
|
8
|
+
/**
|
|
9
|
+
* Direction for call graph traversal
|
|
10
|
+
*/
|
|
11
|
+
export type CallGraphDirection = "callers" | "callees" | "both";
|
|
12
|
+
/**
|
|
13
|
+
* Call type
|
|
14
|
+
*/
|
|
15
|
+
export type CallType = "direct" | "method" | "constructor" | "decorator";
|
|
16
|
+
/**
|
|
17
|
+
* Function node in the call graph
|
|
18
|
+
*/
|
|
19
|
+
export interface FunctionNode {
|
|
20
|
+
name: string;
|
|
21
|
+
path: string;
|
|
22
|
+
line: number;
|
|
23
|
+
column?: number;
|
|
24
|
+
className?: string;
|
|
25
|
+
async?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Call info
|
|
29
|
+
*/
|
|
30
|
+
export interface CallInfo {
|
|
31
|
+
function: FunctionNode;
|
|
32
|
+
callLine: number;
|
|
33
|
+
callColumn?: number;
|
|
34
|
+
type: CallType;
|
|
35
|
+
count: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Call graph node
|
|
39
|
+
*/
|
|
40
|
+
export interface CallGraphNode {
|
|
41
|
+
function: FunctionNode;
|
|
42
|
+
calls: CallInfo[];
|
|
43
|
+
calledBy: CallInfo[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Call graph stats
|
|
47
|
+
*/
|
|
48
|
+
export interface CallGraphStats {
|
|
49
|
+
totalFunctions: number;
|
|
50
|
+
totalCalls: number;
|
|
51
|
+
maxDepthReached: number;
|
|
52
|
+
externalCalls?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Input for getCallGraph tool
|
|
56
|
+
*/
|
|
57
|
+
export interface GetCallGraphInput {
|
|
58
|
+
/** File to analyze */
|
|
59
|
+
path: string;
|
|
60
|
+
/** Specific function to analyze (optional) */
|
|
61
|
+
functionName?: string;
|
|
62
|
+
/** Direction: 'callers' | 'callees' | 'both' (default: 'both') */
|
|
63
|
+
direction?: CallGraphDirection;
|
|
64
|
+
/** Maximum depth to traverse (default: 2) */
|
|
65
|
+
maxDepth?: number;
|
|
66
|
+
/** Include external package calls (default: false) */
|
|
67
|
+
includeExternal?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Result of getCallGraph
|
|
71
|
+
*/
|
|
72
|
+
export interface GetCallGraphResult {
|
|
73
|
+
root?: FunctionNode;
|
|
74
|
+
graph: CallGraphNode[];
|
|
75
|
+
stats: CallGraphStats;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* getCallGraph tool
|
|
79
|
+
*/
|
|
80
|
+
export declare const getCallGraphTool: Tool<GetCallGraphInput>;
|
|
81
|
+
/**
|
|
82
|
+
* Factory function to create a customized getCallGraph tool
|
|
83
|
+
*/
|
|
84
|
+
export declare function createGetCallGraphTool(options?: {
|
|
85
|
+
defaultDirection?: CallGraphDirection;
|
|
86
|
+
defaultMaxDepth?: number;
|
|
87
|
+
defaultIncludeExternal?: boolean;
|
|
88
|
+
}): Tool<GetCallGraphInput>;
|
|
89
|
+
//# sourceMappingURL=get-call-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-call-graph.d.ts","sourceRoot":"","sources":["../../src/tools/get-call-graph.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,KAAK,EAAE,IAAI,EAAuB,MAAM,qBAAqB,CAAC;AAIrE;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,aAAa,GAAG,WAAW,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,KAAK,EAAE,cAAc,CAAC;CACvB;AA+CD;;GAEG;AACH,eAAO,MAAM,gBAAgB,yBAK3B,CAAC;AA6dH;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE;IAC/C,gBAAgB,CAAC,EAAE,kBAAkB,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,GAAG,IAAI,CAAC,iBAAiB,CAAC,CAoB1B"}
|