@compilr-dev/agents-coding-ts 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -5
- package/dist/index.js +14 -4
- package/dist/parser/index.d.ts +2 -2
- package/dist/parser/index.js +1 -1
- package/dist/parser/typescript-parser.d.ts +2 -2
- package/dist/parser/typescript-parser.js +77 -54
- package/dist/skills/code-health.js +18 -5
- package/dist/skills/code-structure.js +15 -5
- package/dist/skills/dependency-audit.js +16 -5
- package/dist/skills/index.d.ts +7 -7
- package/dist/skills/index.js +11 -11
- package/dist/skills/refactor-impact.js +16 -5
- package/dist/skills/type-analysis.js +16 -5
- package/dist/tools/find-dead-code.d.ts +2 -2
- package/dist/tools/find-dead-code.js +82 -58
- package/dist/tools/find-duplicates.d.ts +2 -2
- package/dist/tools/find-duplicates.js +41 -38
- package/dist/tools/find-implementations.d.ts +2 -2
- package/dist/tools/find-implementations.js +44 -36
- package/dist/tools/find-patterns.d.ts +2 -2
- package/dist/tools/find-patterns.js +154 -148
- package/dist/tools/find-references.d.ts +2 -2
- package/dist/tools/find-references.js +76 -72
- package/dist/tools/find-symbol.d.ts +2 -2
- package/dist/tools/find-symbol.js +106 -96
- package/dist/tools/get-call-graph.d.ts +2 -2
- package/dist/tools/get-call-graph.js +52 -47
- package/dist/tools/get-complexity.d.ts +2 -2
- package/dist/tools/get-complexity.js +94 -46
- package/dist/tools/get-dependency-graph.d.ts +2 -2
- package/dist/tools/get-dependency-graph.js +66 -52
- package/dist/tools/get-documentation.d.ts +2 -2
- package/dist/tools/get-documentation.js +154 -122
- package/dist/tools/get-exports.d.ts +2 -2
- package/dist/tools/get-exports.js +73 -61
- package/dist/tools/get-file-structure.d.ts +2 -2
- package/dist/tools/get-file-structure.js +16 -16
- package/dist/tools/get-imports.d.ts +2 -2
- package/dist/tools/get-imports.js +46 -46
- package/dist/tools/get-signature.d.ts +2 -2
- package/dist/tools/get-signature.js +168 -124
- package/dist/tools/get-type-hierarchy.d.ts +2 -2
- package/dist/tools/get-type-hierarchy.js +53 -44
- package/dist/tools/index.d.ts +18 -16
- package/dist/tools/index.js +17 -15
- package/dist/tools/read-symbol.d.ts +62 -0
- package/dist/tools/read-symbol.js +464 -0
- package/dist/tools/types.d.ts +27 -27
- package/package.json +3 -3
|
@@ -4,48 +4,53 @@
|
|
|
4
4
|
* Find classes that implement an interface or extend an abstract class.
|
|
5
5
|
* Useful for understanding interface usage and finding concrete implementations.
|
|
6
6
|
*/
|
|
7
|
-
import * as fs from
|
|
8
|
-
import * as path from
|
|
9
|
-
import * as ts from
|
|
10
|
-
import { defineTool, createSuccessResult, createErrorResult } from
|
|
11
|
-
import { detectLanguage, isLanguageSupported } from
|
|
7
|
+
import * as fs from "node:fs/promises";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import * as ts from "typescript";
|
|
10
|
+
import { defineTool, createSuccessResult, createErrorResult, } from "@compilr-dev/agents";
|
|
11
|
+
import { detectLanguage, isLanguageSupported, } from "../parser/typescript-parser.js";
|
|
12
12
|
// Tool description
|
|
13
13
|
const TOOL_DESCRIPTION = `Find classes that implement an interface or extend an abstract class.
|
|
14
14
|
Returns information about each implementation including which methods are implemented.
|
|
15
15
|
Useful for understanding how interfaces are used across the codebase.`;
|
|
16
16
|
// Tool input schema
|
|
17
17
|
const TOOL_INPUT_SCHEMA = {
|
|
18
|
-
type:
|
|
18
|
+
type: "object",
|
|
19
19
|
properties: {
|
|
20
20
|
name: {
|
|
21
|
-
type:
|
|
22
|
-
description:
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "Interface or abstract class name to find implementations of",
|
|
23
23
|
},
|
|
24
24
|
scope: {
|
|
25
|
-
type:
|
|
26
|
-
description:
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "Directory or file to search in (defaults to current directory)",
|
|
27
27
|
},
|
|
28
28
|
includeAbstract: {
|
|
29
|
-
type:
|
|
30
|
-
description:
|
|
29
|
+
type: "boolean",
|
|
30
|
+
description: "Include abstract classes that partially implement (default: false)",
|
|
31
31
|
default: false,
|
|
32
32
|
},
|
|
33
33
|
maxFiles: {
|
|
34
|
-
type:
|
|
35
|
-
description:
|
|
34
|
+
type: "number",
|
|
35
|
+
description: "Maximum files to search (default: 100)",
|
|
36
36
|
default: 100,
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
|
-
required: [
|
|
39
|
+
required: ["name"],
|
|
40
40
|
};
|
|
41
41
|
// Default file patterns
|
|
42
|
-
const DEFAULT_INCLUDE = [
|
|
43
|
-
const DEFAULT_EXCLUDE = [
|
|
42
|
+
const DEFAULT_INCLUDE = ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"];
|
|
43
|
+
const DEFAULT_EXCLUDE = [
|
|
44
|
+
"**/node_modules/**",
|
|
45
|
+
"**/dist/**",
|
|
46
|
+
"**/build/**",
|
|
47
|
+
"**/.git/**",
|
|
48
|
+
];
|
|
44
49
|
/**
|
|
45
50
|
* findImplementations tool - Find implementations of interfaces/abstract classes
|
|
46
51
|
*/
|
|
47
52
|
export const findImplementationsTool = defineTool({
|
|
48
|
-
name:
|
|
53
|
+
name: "find_implementations",
|
|
49
54
|
description: TOOL_DESCRIPTION,
|
|
50
55
|
inputSchema: TOOL_INPUT_SCHEMA,
|
|
51
56
|
execute: executeFindImplementations,
|
|
@@ -54,11 +59,11 @@ export const findImplementationsTool = defineTool({
|
|
|
54
59
|
* Execute the findImplementations tool
|
|
55
60
|
*/
|
|
56
61
|
async function executeFindImplementations(input) {
|
|
57
|
-
const { name, scope =
|
|
62
|
+
const { name, scope = ".", includeAbstract = false, maxFiles = 100 } = input;
|
|
58
63
|
const startTime = Date.now();
|
|
59
64
|
// Validate input
|
|
60
65
|
if (!name || name.trim().length === 0) {
|
|
61
|
-
return createErrorResult(
|
|
66
|
+
return createErrorResult("Interface or class name is required");
|
|
62
67
|
}
|
|
63
68
|
try {
|
|
64
69
|
// Resolve scope path
|
|
@@ -119,7 +124,7 @@ async function executeFindImplementations(input) {
|
|
|
119
124
|
*/
|
|
120
125
|
async function findTargetDefinition(filePath, targetName) {
|
|
121
126
|
try {
|
|
122
|
-
const content = await fs.readFile(filePath,
|
|
127
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
123
128
|
const detection = detectLanguage(filePath);
|
|
124
129
|
if (!detection.language) {
|
|
125
130
|
return null;
|
|
@@ -127,7 +132,7 @@ async function findTargetDefinition(filePath, targetName) {
|
|
|
127
132
|
if (!isLanguageSupported(detection.language)) {
|
|
128
133
|
return null;
|
|
129
134
|
}
|
|
130
|
-
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, filePath.endsWith(
|
|
135
|
+
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, filePath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
131
136
|
let result = null;
|
|
132
137
|
const visit = (node) => {
|
|
133
138
|
// Check for interface declaration
|
|
@@ -207,7 +212,7 @@ function extractClassMethods(node, abstractOnly) {
|
|
|
207
212
|
*/
|
|
208
213
|
async function findImplementationsInFile(filePath, targetName, targetMethods, isInterface, isAbstractClass, includeAbstract) {
|
|
209
214
|
try {
|
|
210
|
-
const content = await fs.readFile(filePath,
|
|
215
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
211
216
|
const detection = detectLanguage(filePath);
|
|
212
217
|
if (!detection.language) {
|
|
213
218
|
return [];
|
|
@@ -215,7 +220,7 @@ async function findImplementationsInFile(filePath, targetName, targetMethods, is
|
|
|
215
220
|
if (!isLanguageSupported(detection.language)) {
|
|
216
221
|
return [];
|
|
217
222
|
}
|
|
218
|
-
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, filePath.endsWith(
|
|
223
|
+
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, filePath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
219
224
|
const implementations = [];
|
|
220
225
|
const visit = (node) => {
|
|
221
226
|
// Check for class declaration
|
|
@@ -248,7 +253,7 @@ async function findImplementationsInFile(filePath, targetName, targetMethods, is
|
|
|
248
253
|
path: filePath,
|
|
249
254
|
line: line + 1,
|
|
250
255
|
column: character + 1,
|
|
251
|
-
kind:
|
|
256
|
+
kind: "object",
|
|
252
257
|
exported: isExported,
|
|
253
258
|
implementedMethods: targetMethods,
|
|
254
259
|
missingMethods: [],
|
|
@@ -277,7 +282,8 @@ function checkClassImplementation(node, sourceFile, filePath, targetName, target
|
|
|
277
282
|
if (className === targetName)
|
|
278
283
|
return null;
|
|
279
284
|
// Check if it's abstract
|
|
280
|
-
const classIsAbstract = node.modifiers?.some((m) => m.kind === ts.SyntaxKind.AbstractKeyword) ??
|
|
285
|
+
const classIsAbstract = node.modifiers?.some((m) => m.kind === ts.SyntaxKind.AbstractKeyword) ??
|
|
286
|
+
false;
|
|
281
287
|
// Skip abstract classes if not including them
|
|
282
288
|
if (classIsAbstract && !includeAbstract)
|
|
283
289
|
return null;
|
|
@@ -329,13 +335,14 @@ function checkClassImplementation(node, sourceFile, filePath, targetName, target
|
|
|
329
335
|
// Calculate missing methods
|
|
330
336
|
const missingMethods = targetMethods.filter((m) => !implementedMethods.includes(m));
|
|
331
337
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
332
|
-
const isExported = node.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ??
|
|
338
|
+
const isExported = node.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ??
|
|
339
|
+
false;
|
|
333
340
|
return {
|
|
334
341
|
name: className,
|
|
335
342
|
path: filePath,
|
|
336
343
|
line: line + 1,
|
|
337
344
|
column: character + 1,
|
|
338
|
-
kind:
|
|
345
|
+
kind: "class",
|
|
339
346
|
isAbstract: classIsAbstract,
|
|
340
347
|
exported: isExported,
|
|
341
348
|
implementedMethods,
|
|
@@ -358,13 +365,14 @@ function checkTypeImplementation(node, sourceFile, filePath, targetName) {
|
|
|
358
365
|
if (!extendsTarget)
|
|
359
366
|
return null;
|
|
360
367
|
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
361
|
-
const isExported = node.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ??
|
|
368
|
+
const isExported = node.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ??
|
|
369
|
+
false;
|
|
362
370
|
return {
|
|
363
371
|
name: node.name.text,
|
|
364
372
|
path: filePath,
|
|
365
373
|
line: line + 1,
|
|
366
374
|
column: character + 1,
|
|
367
|
-
kind:
|
|
375
|
+
kind: "type",
|
|
368
376
|
exported: isExported,
|
|
369
377
|
};
|
|
370
378
|
}
|
|
@@ -384,9 +392,9 @@ async function collectFiles(dirPath, include, exclude, maxDepth, maxFiles, curre
|
|
|
384
392
|
const relativePath = fullPath;
|
|
385
393
|
// Check exclusions
|
|
386
394
|
const isExcluded = exclude.some((pattern) => {
|
|
387
|
-
if (pattern.includes(
|
|
388
|
-
const simplePattern = pattern.replace(/\*\*/g,
|
|
389
|
-
return relativePath.includes(simplePattern.replace(/\*/g,
|
|
395
|
+
if (pattern.includes("**")) {
|
|
396
|
+
const simplePattern = pattern.replace(/\*\*/g, "");
|
|
397
|
+
return relativePath.includes(simplePattern.replace(/\*/g, ""));
|
|
390
398
|
}
|
|
391
399
|
return entry.name === pattern || relativePath.includes(pattern);
|
|
392
400
|
});
|
|
@@ -399,8 +407,8 @@ async function collectFiles(dirPath, include, exclude, maxDepth, maxFiles, curre
|
|
|
399
407
|
else if (entry.isFile()) {
|
|
400
408
|
// Check if file matches include patterns
|
|
401
409
|
const isIncluded = include.some((pattern) => {
|
|
402
|
-
if (pattern.includes(
|
|
403
|
-
const ext = pattern.replace(
|
|
410
|
+
if (pattern.includes("*")) {
|
|
411
|
+
const ext = pattern.replace("**/", "").replace("*", "");
|
|
404
412
|
return entry.name.endsWith(ext);
|
|
405
413
|
}
|
|
406
414
|
return entry.name === pattern;
|
|
@@ -421,7 +429,7 @@ async function collectFiles(dirPath, include, exclude, maxDepth, maxFiles, curre
|
|
|
421
429
|
*/
|
|
422
430
|
export function createFindImplementationsTool(options) {
|
|
423
431
|
return defineTool({
|
|
424
|
-
name: options?.name ??
|
|
432
|
+
name: options?.name ?? "find_implementations",
|
|
425
433
|
description: options?.description ?? TOOL_DESCRIPTION,
|
|
426
434
|
inputSchema: TOOL_INPUT_SCHEMA,
|
|
427
435
|
execute: async (input) => {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Find code patterns, anti-patterns, and code smells in the codebase.
|
|
5
5
|
* Uses regex and AST-based pattern matching.
|
|
6
6
|
*/
|
|
7
|
-
import type { Tool } from
|
|
8
|
-
import type { FindPatternsInput, CodePattern } from
|
|
7
|
+
import type { Tool } from "@compilr-dev/agents";
|
|
8
|
+
import type { FindPatternsInput, CodePattern } from "./types.js";
|
|
9
9
|
/**
|
|
10
10
|
* findPatterns tool
|
|
11
11
|
*/
|