@compilr-dev/agents-coding-python 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/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 +119 -0
- package/dist/parser/node-types.d.ts.map +1 -0
- package/dist/parser/node-types.js +4 -0
- package/dist/parser/python-parser.d.ts +85 -0
- package/dist/parser/python-parser.d.ts.map +1 -0
- package/dist/parser/python-parser.js +477 -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/skills/python-best-practices.d.ts +7 -0
- package/dist/skills/python-best-practices.d.ts.map +1 -0
- package/dist/skills/python-best-practices.js +78 -0
- package/dist/skills/python-code-health.d.ts +7 -0
- package/dist/skills/python-code-health.d.ts.map +1 -0
- package/dist/skills/python-code-health.js +209 -0
- package/dist/skills/python-code-structure.d.ts +7 -0
- package/dist/skills/python-code-structure.d.ts.map +1 -0
- package/dist/skills/python-code-structure.js +155 -0
- package/dist/skills/python-dependency-audit.d.ts +7 -0
- package/dist/skills/python-dependency-audit.d.ts.map +1 -0
- package/dist/skills/python-dependency-audit.js +246 -0
- package/dist/skills/python-refactor-impact.d.ts +7 -0
- package/dist/skills/python-refactor-impact.d.ts.map +1 -0
- package/dist/skills/python-refactor-impact.js +232 -0
- package/dist/tools/extract-docstrings.d.ts +70 -0
- package/dist/tools/extract-docstrings.d.ts.map +1 -0
- package/dist/tools/extract-docstrings.js +575 -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 +414 -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 +38 -0
- package/dist/tools/get-class-hierarchy.d.ts.map +1 -0
- package/dist/tools/get-class-hierarchy.js +289 -0
- package/dist/tools/get-complexity.d.ts +61 -0
- package/dist/tools/get-complexity.d.ts.map +1 -0
- package/dist/tools/get-complexity.js +384 -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 +387 -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 +186 -0
- package/dist/tools/get-imports.d.ts +34 -0
- package/dist/tools/get-imports.d.ts.map +1 -0
- package/dist/tools/get-imports.js +455 -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 +378 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +4 -0
- package/package.json +85 -0
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* getImports Tool
|
|
3
|
+
*
|
|
4
|
+
* Analyzes imports in Python files.
|
|
5
|
+
* Categorizes imports into stdlib, third-party, and local.
|
|
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, parseImport } from "../parser/python-parser.js";
|
|
11
|
+
// Python standard library modules (Python 3.10+)
|
|
12
|
+
const STDLIB_MODULES = new Set([
|
|
13
|
+
// Built-in modules
|
|
14
|
+
"abc",
|
|
15
|
+
"aifc",
|
|
16
|
+
"argparse",
|
|
17
|
+
"array",
|
|
18
|
+
"ast",
|
|
19
|
+
"asynchat",
|
|
20
|
+
"asyncio",
|
|
21
|
+
"asyncore",
|
|
22
|
+
"atexit",
|
|
23
|
+
"audioop",
|
|
24
|
+
"base64",
|
|
25
|
+
"bdb",
|
|
26
|
+
"binascii",
|
|
27
|
+
"binhex",
|
|
28
|
+
"bisect",
|
|
29
|
+
"builtins",
|
|
30
|
+
"bz2",
|
|
31
|
+
"calendar",
|
|
32
|
+
"cgi",
|
|
33
|
+
"cgitb",
|
|
34
|
+
"chunk",
|
|
35
|
+
"cmath",
|
|
36
|
+
"cmd",
|
|
37
|
+
"code",
|
|
38
|
+
"codecs",
|
|
39
|
+
"codeop",
|
|
40
|
+
"collections",
|
|
41
|
+
"colorsys",
|
|
42
|
+
"compileall",
|
|
43
|
+
"concurrent",
|
|
44
|
+
"configparser",
|
|
45
|
+
"contextlib",
|
|
46
|
+
"contextvars",
|
|
47
|
+
"copy",
|
|
48
|
+
"copyreg",
|
|
49
|
+
"cProfile",
|
|
50
|
+
"crypt",
|
|
51
|
+
"csv",
|
|
52
|
+
"ctypes",
|
|
53
|
+
"curses",
|
|
54
|
+
"dataclasses",
|
|
55
|
+
"datetime",
|
|
56
|
+
"dbm",
|
|
57
|
+
"decimal",
|
|
58
|
+
"difflib",
|
|
59
|
+
"dis",
|
|
60
|
+
"distutils",
|
|
61
|
+
"doctest",
|
|
62
|
+
"email",
|
|
63
|
+
"encodings",
|
|
64
|
+
"enum",
|
|
65
|
+
"errno",
|
|
66
|
+
"faulthandler",
|
|
67
|
+
"fcntl",
|
|
68
|
+
"filecmp",
|
|
69
|
+
"fileinput",
|
|
70
|
+
"fnmatch",
|
|
71
|
+
"fractions",
|
|
72
|
+
"ftplib",
|
|
73
|
+
"functools",
|
|
74
|
+
"gc",
|
|
75
|
+
"getopt",
|
|
76
|
+
"getpass",
|
|
77
|
+
"gettext",
|
|
78
|
+
"glob",
|
|
79
|
+
"graphlib",
|
|
80
|
+
"grp",
|
|
81
|
+
"gzip",
|
|
82
|
+
"hashlib",
|
|
83
|
+
"heapq",
|
|
84
|
+
"hmac",
|
|
85
|
+
"html",
|
|
86
|
+
"http",
|
|
87
|
+
"idlelib",
|
|
88
|
+
"imaplib",
|
|
89
|
+
"imghdr",
|
|
90
|
+
"imp",
|
|
91
|
+
"importlib",
|
|
92
|
+
"inspect",
|
|
93
|
+
"io",
|
|
94
|
+
"ipaddress",
|
|
95
|
+
"itertools",
|
|
96
|
+
"json",
|
|
97
|
+
"keyword",
|
|
98
|
+
"lib2to3",
|
|
99
|
+
"linecache",
|
|
100
|
+
"locale",
|
|
101
|
+
"logging",
|
|
102
|
+
"lzma",
|
|
103
|
+
"mailbox",
|
|
104
|
+
"mailcap",
|
|
105
|
+
"marshal",
|
|
106
|
+
"math",
|
|
107
|
+
"mimetypes",
|
|
108
|
+
"mmap",
|
|
109
|
+
"modulefinder",
|
|
110
|
+
"multiprocessing",
|
|
111
|
+
"netrc",
|
|
112
|
+
"nis",
|
|
113
|
+
"nntplib",
|
|
114
|
+
"numbers",
|
|
115
|
+
"operator",
|
|
116
|
+
"optparse",
|
|
117
|
+
"os",
|
|
118
|
+
"ossaudiodev",
|
|
119
|
+
"pathlib",
|
|
120
|
+
"pdb",
|
|
121
|
+
"pickle",
|
|
122
|
+
"pickletools",
|
|
123
|
+
"pipes",
|
|
124
|
+
"pkgutil",
|
|
125
|
+
"platform",
|
|
126
|
+
"plistlib",
|
|
127
|
+
"poplib",
|
|
128
|
+
"posix",
|
|
129
|
+
"posixpath",
|
|
130
|
+
"pprint",
|
|
131
|
+
"profile",
|
|
132
|
+
"pstats",
|
|
133
|
+
"pty",
|
|
134
|
+
"pwd",
|
|
135
|
+
"py_compile",
|
|
136
|
+
"pyclbr",
|
|
137
|
+
"pydoc",
|
|
138
|
+
"queue",
|
|
139
|
+
"quopri",
|
|
140
|
+
"random",
|
|
141
|
+
"re",
|
|
142
|
+
"readline",
|
|
143
|
+
"reprlib",
|
|
144
|
+
"resource",
|
|
145
|
+
"rlcompleter",
|
|
146
|
+
"runpy",
|
|
147
|
+
"sched",
|
|
148
|
+
"secrets",
|
|
149
|
+
"select",
|
|
150
|
+
"selectors",
|
|
151
|
+
"shelve",
|
|
152
|
+
"shlex",
|
|
153
|
+
"shutil",
|
|
154
|
+
"signal",
|
|
155
|
+
"site",
|
|
156
|
+
"smtpd",
|
|
157
|
+
"smtplib",
|
|
158
|
+
"sndhdr",
|
|
159
|
+
"socket",
|
|
160
|
+
"socketserver",
|
|
161
|
+
"spwd",
|
|
162
|
+
"sqlite3",
|
|
163
|
+
"ssl",
|
|
164
|
+
"stat",
|
|
165
|
+
"statistics",
|
|
166
|
+
"string",
|
|
167
|
+
"stringprep",
|
|
168
|
+
"struct",
|
|
169
|
+
"subprocess",
|
|
170
|
+
"sunau",
|
|
171
|
+
"symtable",
|
|
172
|
+
"sys",
|
|
173
|
+
"sysconfig",
|
|
174
|
+
"syslog",
|
|
175
|
+
"tabnanny",
|
|
176
|
+
"tarfile",
|
|
177
|
+
"telnetlib",
|
|
178
|
+
"tempfile",
|
|
179
|
+
"termios",
|
|
180
|
+
"test",
|
|
181
|
+
"textwrap",
|
|
182
|
+
"threading",
|
|
183
|
+
"time",
|
|
184
|
+
"timeit",
|
|
185
|
+
"tkinter",
|
|
186
|
+
"token",
|
|
187
|
+
"tokenize",
|
|
188
|
+
"trace",
|
|
189
|
+
"traceback",
|
|
190
|
+
"tracemalloc",
|
|
191
|
+
"tty",
|
|
192
|
+
"turtle",
|
|
193
|
+
"turtledemo",
|
|
194
|
+
"types",
|
|
195
|
+
"typing",
|
|
196
|
+
"unicodedata",
|
|
197
|
+
"unittest",
|
|
198
|
+
"urllib",
|
|
199
|
+
"uu",
|
|
200
|
+
"uuid",
|
|
201
|
+
"venv",
|
|
202
|
+
"warnings",
|
|
203
|
+
"wave",
|
|
204
|
+
"weakref",
|
|
205
|
+
"webbrowser",
|
|
206
|
+
"winreg",
|
|
207
|
+
"winsound",
|
|
208
|
+
"wsgiref",
|
|
209
|
+
"xdrlib",
|
|
210
|
+
"xml",
|
|
211
|
+
"xmlrpc",
|
|
212
|
+
"zipapp",
|
|
213
|
+
"zipfile",
|
|
214
|
+
"zipimport",
|
|
215
|
+
"zlib",
|
|
216
|
+
"zoneinfo",
|
|
217
|
+
]);
|
|
218
|
+
// Tool description
|
|
219
|
+
const TOOL_DESCRIPTION = `Analyze imports in a Python file or directory.
|
|
220
|
+
Returns categorized imports (stdlib, third-party, local) with details about each import.
|
|
221
|
+
Useful for understanding dependencies and finding import issues.`;
|
|
222
|
+
// Tool input schema
|
|
223
|
+
const TOOL_INPUT_SCHEMA = {
|
|
224
|
+
type: "object",
|
|
225
|
+
properties: {
|
|
226
|
+
path: {
|
|
227
|
+
type: "string",
|
|
228
|
+
description: "File or directory to analyze",
|
|
229
|
+
},
|
|
230
|
+
recursive: {
|
|
231
|
+
type: "boolean",
|
|
232
|
+
description: "Recursively analyze directory (default: false)",
|
|
233
|
+
default: false,
|
|
234
|
+
},
|
|
235
|
+
filterModule: {
|
|
236
|
+
type: "string",
|
|
237
|
+
description: "Filter to imports from a specific module",
|
|
238
|
+
},
|
|
239
|
+
maxFiles: {
|
|
240
|
+
type: "number",
|
|
241
|
+
description: "Maximum files to analyze (default: 50)",
|
|
242
|
+
default: 50,
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
required: ["path"],
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* getImports tool - Analyze Python imports
|
|
249
|
+
*/
|
|
250
|
+
export const getImportsTool = defineTool({
|
|
251
|
+
name: "get_imports_python",
|
|
252
|
+
description: TOOL_DESCRIPTION,
|
|
253
|
+
inputSchema: TOOL_INPUT_SCHEMA,
|
|
254
|
+
execute: executeGetImports,
|
|
255
|
+
});
|
|
256
|
+
/**
|
|
257
|
+
* Execute the getImports tool
|
|
258
|
+
*/
|
|
259
|
+
async function executeGetImports(input) {
|
|
260
|
+
const { path: targetPath, recursive = false, filterModule, maxFiles = 50, } = input;
|
|
261
|
+
const resolvedPath = path.resolve(targetPath);
|
|
262
|
+
// Check if path exists
|
|
263
|
+
try {
|
|
264
|
+
await fs.access(resolvedPath);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return createErrorResult(`Path not found: ${resolvedPath}`);
|
|
268
|
+
}
|
|
269
|
+
const stats = await fs.stat(resolvedPath);
|
|
270
|
+
try {
|
|
271
|
+
if (stats.isFile()) {
|
|
272
|
+
// Analyze single file
|
|
273
|
+
if (!resolvedPath.endsWith(".py") && !resolvedPath.endsWith(".pyi")) {
|
|
274
|
+
return createErrorResult(`Not a Python file: ${resolvedPath}`);
|
|
275
|
+
}
|
|
276
|
+
const result = await analyzeFileImports(resolvedPath, filterModule);
|
|
277
|
+
return createSuccessResult(result);
|
|
278
|
+
}
|
|
279
|
+
else if (stats.isDirectory()) {
|
|
280
|
+
// Analyze directory
|
|
281
|
+
const files = await collectPythonFiles(resolvedPath, recursive, maxFiles);
|
|
282
|
+
const allImports = [];
|
|
283
|
+
let stdlibCount = 0;
|
|
284
|
+
let thirdPartyCount = 0;
|
|
285
|
+
let localCount = 0;
|
|
286
|
+
for (const filePath of files) {
|
|
287
|
+
const fileResult = await analyzeFileImports(filePath, filterModule);
|
|
288
|
+
allImports.push(...fileResult.imports);
|
|
289
|
+
stdlibCount += fileResult.stats.stdlib;
|
|
290
|
+
thirdPartyCount += fileResult.stats.thirdParty;
|
|
291
|
+
localCount += fileResult.stats.local;
|
|
292
|
+
}
|
|
293
|
+
// Deduplicate imports
|
|
294
|
+
const uniqueImports = deduplicateImports(allImports);
|
|
295
|
+
const result = {
|
|
296
|
+
path: resolvedPath,
|
|
297
|
+
imports: uniqueImports,
|
|
298
|
+
stats: {
|
|
299
|
+
total: uniqueImports.length,
|
|
300
|
+
stdlib: stdlibCount,
|
|
301
|
+
thirdParty: thirdPartyCount,
|
|
302
|
+
local: localCount,
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
return createSuccessResult(result);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
return createErrorResult(`Path is neither a file nor directory: ${resolvedPath}`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
313
|
+
return createErrorResult(`Failed to analyze imports: ${message}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Analyze imports in a single file
|
|
318
|
+
*/
|
|
319
|
+
async function analyzeFileImports(filePath, filterModule) {
|
|
320
|
+
const parseResult = await parseFile(filePath);
|
|
321
|
+
const { tree, source } = parseResult;
|
|
322
|
+
const rootNode = tree.rootNode;
|
|
323
|
+
const imports = [];
|
|
324
|
+
let stdlibCount = 0;
|
|
325
|
+
let thirdPartyCount = 0;
|
|
326
|
+
let localCount = 0;
|
|
327
|
+
for (const child of rootNode.children) {
|
|
328
|
+
if (child.type === "import_statement" ||
|
|
329
|
+
child.type === "import_from_statement") {
|
|
330
|
+
const importInfo = parseImport(child, source);
|
|
331
|
+
const category = categorizeImport(importInfo.module, importInfo.isRelative);
|
|
332
|
+
// Apply filter if specified
|
|
333
|
+
if (filterModule && !importInfo.module.startsWith(filterModule)) {
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
const categorizedImport = {
|
|
337
|
+
...importInfo,
|
|
338
|
+
category,
|
|
339
|
+
};
|
|
340
|
+
imports.push(categorizedImport);
|
|
341
|
+
switch (category) {
|
|
342
|
+
case "stdlib":
|
|
343
|
+
stdlibCount++;
|
|
344
|
+
break;
|
|
345
|
+
case "third_party":
|
|
346
|
+
thirdPartyCount++;
|
|
347
|
+
break;
|
|
348
|
+
case "local":
|
|
349
|
+
localCount++;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
path: filePath,
|
|
356
|
+
imports,
|
|
357
|
+
stats: {
|
|
358
|
+
total: imports.length,
|
|
359
|
+
stdlib: stdlibCount,
|
|
360
|
+
thirdParty: thirdPartyCount,
|
|
361
|
+
local: localCount,
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Categorize an import as stdlib, third-party, or local
|
|
367
|
+
*/
|
|
368
|
+
function categorizeImport(module, isRelative) {
|
|
369
|
+
// Relative imports are always local
|
|
370
|
+
if (isRelative) {
|
|
371
|
+
return "local";
|
|
372
|
+
}
|
|
373
|
+
// Empty module (from . import) is local
|
|
374
|
+
if (!module) {
|
|
375
|
+
return "local";
|
|
376
|
+
}
|
|
377
|
+
// Get the top-level module name
|
|
378
|
+
const topLevelModule = module.split(".")[0];
|
|
379
|
+
// Check if it's a stdlib module
|
|
380
|
+
if (STDLIB_MODULES.has(topLevelModule)) {
|
|
381
|
+
return "stdlib";
|
|
382
|
+
}
|
|
383
|
+
// Everything else is third-party
|
|
384
|
+
// Note: In a real implementation, we could check against installed packages
|
|
385
|
+
// or look for local modules in the project directory
|
|
386
|
+
return "third_party";
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Collect Python files in a directory
|
|
390
|
+
*/
|
|
391
|
+
async function collectPythonFiles(dir, recursive, maxFiles) {
|
|
392
|
+
const files = [];
|
|
393
|
+
async function walk(currentDir) {
|
|
394
|
+
if (files.length >= maxFiles)
|
|
395
|
+
return;
|
|
396
|
+
const entries = await fs.readdir(currentDir, { withFileTypes: true });
|
|
397
|
+
for (const entry of entries) {
|
|
398
|
+
if (files.length >= maxFiles)
|
|
399
|
+
break;
|
|
400
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
401
|
+
if (entry.isDirectory() && recursive) {
|
|
402
|
+
// Skip common non-source directories
|
|
403
|
+
if (entry.name.startsWith(".") ||
|
|
404
|
+
entry.name === "__pycache__" ||
|
|
405
|
+
entry.name === "venv" ||
|
|
406
|
+
entry.name === ".venv" ||
|
|
407
|
+
entry.name === "env" ||
|
|
408
|
+
entry.name === "node_modules" ||
|
|
409
|
+
entry.name === "dist" ||
|
|
410
|
+
entry.name === "build") {
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
await walk(fullPath);
|
|
414
|
+
}
|
|
415
|
+
else if (entry.isFile()) {
|
|
416
|
+
if (fullPath.endsWith(".py") || fullPath.endsWith(".pyi")) {
|
|
417
|
+
files.push(fullPath);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
await walk(dir);
|
|
423
|
+
return files;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Deduplicate imports by module name
|
|
427
|
+
*/
|
|
428
|
+
function deduplicateImports(imports) {
|
|
429
|
+
const seen = new Map();
|
|
430
|
+
for (const imp of imports) {
|
|
431
|
+
const key = `${imp.module}:${imp.isFromImport}:${JSON.stringify(imp.names)}`;
|
|
432
|
+
if (!seen.has(key)) {
|
|
433
|
+
seen.set(key, imp);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return Array.from(seen.values());
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Factory function to create a customized getImports tool
|
|
440
|
+
*/
|
|
441
|
+
export function createGetImportsTool(options) {
|
|
442
|
+
const { defaultRecursive = false, defaultMaxFiles = 50 } = options ?? {};
|
|
443
|
+
return defineTool({
|
|
444
|
+
name: "get_imports_python",
|
|
445
|
+
description: TOOL_DESCRIPTION,
|
|
446
|
+
inputSchema: TOOL_INPUT_SCHEMA,
|
|
447
|
+
execute: async (input) => {
|
|
448
|
+
return executeGetImports({
|
|
449
|
+
...input,
|
|
450
|
+
recursive: input.recursive ?? defaultRecursive,
|
|
451
|
+
maxFiles: input.maxFiles ?? defaultMaxFiles,
|
|
452
|
+
});
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* getSignature Tool
|
|
3
|
+
*
|
|
4
|
+
* Get detailed signature information for a function, method, or class in Python code.
|
|
5
|
+
* Includes parameters, type hints, decorators, and docstrings.
|
|
6
|
+
*/
|
|
7
|
+
import type { Tool } from "@compilr-dev/agents";
|
|
8
|
+
/**
|
|
9
|
+
* Python symbol kinds
|
|
10
|
+
*/
|
|
11
|
+
export type PythonSymbolKind = "function" | "async_function" | "method" | "class" | "variable";
|
|
12
|
+
/**
|
|
13
|
+
* Parameter detail
|
|
14
|
+
*/
|
|
15
|
+
export interface ParameterDetail {
|
|
16
|
+
name: string;
|
|
17
|
+
type?: string;
|
|
18
|
+
optional: boolean;
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
isKwOnly?: boolean;
|
|
22
|
+
isPosOnly?: boolean;
|
|
23
|
+
isVarArgs?: boolean;
|
|
24
|
+
isKwArgs?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Return type detail
|
|
28
|
+
*/
|
|
29
|
+
export interface ReturnTypeDetail {
|
|
30
|
+
type: string;
|
|
31
|
+
isCoroutine?: boolean;
|
|
32
|
+
nullable?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Member signature (for class members)
|
|
36
|
+
*/
|
|
37
|
+
export interface MemberSignature {
|
|
38
|
+
name: string;
|
|
39
|
+
kind: "method" | "property" | "class_variable";
|
|
40
|
+
signature: string;
|
|
41
|
+
async?: boolean;
|
|
42
|
+
static?: boolean;
|
|
43
|
+
classmethod?: boolean;
|
|
44
|
+
decorators?: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Documentation extracted from docstrings
|
|
48
|
+
*/
|
|
49
|
+
export interface Documentation {
|
|
50
|
+
summary: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
params?: Record<string, string>;
|
|
53
|
+
returns?: string;
|
|
54
|
+
raises?: string[];
|
|
55
|
+
examples?: string[];
|
|
56
|
+
notes?: string;
|
|
57
|
+
deprecated?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Input for getSignature tool
|
|
61
|
+
*/
|
|
62
|
+
export interface GetSignatureInput {
|
|
63
|
+
/** File containing the symbol */
|
|
64
|
+
path: string;
|
|
65
|
+
/** Symbol name to get signature for */
|
|
66
|
+
name: string;
|
|
67
|
+
/** Line number for disambiguation (optional) */
|
|
68
|
+
line?: number;
|
|
69
|
+
/** Include full documentation (default: true) */
|
|
70
|
+
includeDoc?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Result of getSignature
|
|
74
|
+
*/
|
|
75
|
+
export interface GetSignatureResult {
|
|
76
|
+
name: string;
|
|
77
|
+
path: string;
|
|
78
|
+
kind: PythonSymbolKind;
|
|
79
|
+
line: number;
|
|
80
|
+
signature: string;
|
|
81
|
+
formattedSignature: string;
|
|
82
|
+
parameters?: ParameterDetail[];
|
|
83
|
+
returnType?: ReturnTypeDetail;
|
|
84
|
+
decorators?: string[];
|
|
85
|
+
documentation?: Documentation;
|
|
86
|
+
bases?: string[];
|
|
87
|
+
members?: MemberSignature[];
|
|
88
|
+
async?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* getSignature tool
|
|
92
|
+
*/
|
|
93
|
+
export declare const getSignatureTool: Tool<GetSignatureInput>;
|
|
94
|
+
/**
|
|
95
|
+
* Factory function to create a customized getSignature tool
|
|
96
|
+
*/
|
|
97
|
+
export declare function createGetSignatureTool(options?: {
|
|
98
|
+
defaultIncludeDoc?: boolean;
|
|
99
|
+
}): Tool<GetSignatureInput>;
|
|
100
|
+
//# sourceMappingURL=get-signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-signature.d.ts","sourceRoot":"","sources":["../../src/tools/get-signature.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,KAAK,EAAE,IAAI,EAAuB,MAAM,qBAAqB,CAAC;AAQrE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,UAAU,GACV,gBAAgB,GAChB,QAAQ,GACR,OAAO,GACP,UAAU,CAAC;AAEf;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,UAAU,GAAG,gBAAgB,CAAC;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,eAAe,EAAE,CAAC;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAgCD;;GAEG;AACH,eAAO,MAAM,gBAAgB,yBAK3B,CAAC;AAu3BH;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE;IAC/C,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,GAAG,IAAI,CAAC,iBAAiB,CAAC,CAY1B"}
|