@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
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* TypeScript/JavaScript analysis tools for AI coding agents.
|
|
5
5
|
* Provides AST-based code analysis, complexity metrics, and type hierarchy tools.
|
|
6
6
|
*/
|
|
7
|
-
export { parseTypeScript, detectLanguage, isLanguageSupported, } from
|
|
8
|
-
export { getFileStructureTool, createGetFileStructureTool, findSymbolTool, createFindSymbolTool, findReferencesTool, createFindReferencesTool, getImportsTool, createGetImportsTool, getExportsTool, createGetExportsTool, getCallGraphTool, createGetCallGraphTool, getDependencyGraphTool, createGetDependencyGraphTool, findImplementationsTool, createFindImplementationsTool, getTypeHierarchyTool, createGetTypeHierarchyTool, getComplexityTool, createGetComplexityTool, findDeadCodeTool, createFindDeadCodeTool, findDuplicatesTool, createFindDuplicatesTool, findPatternsTool, createFindPatternsTool, getSignatureTool, createGetSignatureTool, getDocumentationTool, createGetDocumentationTool, } from
|
|
9
|
-
export type { SupportedLanguage, ParameterInfo, GetFileStructureInput, FileStructure, ImportInfo, ExportInfo, ClassInfo, FunctionInfo, MethodInfo, PropertyInfo, VariableInfo, TypeDefinitionInfo, FileStats, SymbolKind, SymbolKindFilter, FindSymbolInput, FindSymbolResult, SymbolDefinition, SearchStats, ReferenceType, FindReferencesInput, FindReferencesResult, Reference, FileReferences, GetImportsInput, GetImportsResult, DetailedImport, ImportedSymbol, TransitiveImport, ImportStats, GetExportsInput, GetExportsResult, ExportedSymbol, ExportKind, ReExport, ExportStats, CallGraphDirection, CallType, GetCallGraphInput, GetCallGraphResult, FunctionNode, CallInfo, CallGraphNode, CallGraphStats, GetDependencyGraphInput, GetDependencyGraphResult, ModuleNode, DependencyEdge, CircularDependency, DependencyGraphStats, FindImplementationsInput, FindImplementationsResult, ImplementationInfo, HierarchyDirection, GetTypeHierarchyInput, GetTypeHierarchyResult, TypeHierarchyNode, GetComplexityInput, GetComplexityResult, FileComplexity, FunctionComplexity, ComplexityContributor, ComplexityContributorType, FindDeadCodeInput, FindDeadCodeResult, DeadCodeItem, FindDuplicatesInput, FindDuplicatesResult, DuplicateGroup, CodeLocation, FindPatternsInput, FindPatternsResult, PatternMatch, CodePattern, GetSignatureInput, GetSignatureResult, ParameterDetail, TypeDetail, GenericDetail, Documentation, MemberSignature, SignatureSymbolKind, GetDocumentationInput, GetDocumentationResult, FileDocumentation, DocumentedSymbol, DocumentationSymbolKind, ExtractorOptions, } from
|
|
10
|
-
export { codeStructureSkill, dependencyAuditSkill, refactorImpactSkill, typeAnalysisSkill, codeHealthSkill, tsSkills, defineSkill, type Skill, } from
|
|
7
|
+
export { parseTypeScript, detectLanguage, isLanguageSupported, } from "./parser/index.js";
|
|
8
|
+
export { getFileStructureTool, createGetFileStructureTool, findSymbolTool, createFindSymbolTool, findReferencesTool, createFindReferencesTool, getImportsTool, createGetImportsTool, getExportsTool, createGetExportsTool, getCallGraphTool, createGetCallGraphTool, getDependencyGraphTool, createGetDependencyGraphTool, findImplementationsTool, createFindImplementationsTool, getTypeHierarchyTool, createGetTypeHierarchyTool, getComplexityTool, createGetComplexityTool, findDeadCodeTool, createFindDeadCodeTool, findDuplicatesTool, createFindDuplicatesTool, findPatternsTool, createFindPatternsTool, getSignatureTool, createGetSignatureTool, getDocumentationTool, createGetDocumentationTool, readFunctionTool, readClassTool, readTypeTool, createReadFunctionTool, createReadClassTool, createReadTypeTool, } from "./tools/index.js";
|
|
9
|
+
export type { SupportedLanguage, ParameterInfo, GetFileStructureInput, FileStructure, ImportInfo, ExportInfo, ClassInfo, FunctionInfo, MethodInfo, PropertyInfo, VariableInfo, TypeDefinitionInfo, FileStats, SymbolKind, SymbolKindFilter, FindSymbolInput, FindSymbolResult, SymbolDefinition, SearchStats, ReferenceType, FindReferencesInput, FindReferencesResult, Reference, FileReferences, GetImportsInput, GetImportsResult, DetailedImport, ImportedSymbol, TransitiveImport, ImportStats, GetExportsInput, GetExportsResult, ExportedSymbol, ExportKind, ReExport, ExportStats, CallGraphDirection, CallType, GetCallGraphInput, GetCallGraphResult, FunctionNode, CallInfo, CallGraphNode, CallGraphStats, GetDependencyGraphInput, GetDependencyGraphResult, ModuleNode, DependencyEdge, CircularDependency, DependencyGraphStats, FindImplementationsInput, FindImplementationsResult, ImplementationInfo, HierarchyDirection, GetTypeHierarchyInput, GetTypeHierarchyResult, TypeHierarchyNode, GetComplexityInput, GetComplexityResult, FileComplexity, FunctionComplexity, ComplexityContributor, ComplexityContributorType, FindDeadCodeInput, FindDeadCodeResult, DeadCodeItem, FindDuplicatesInput, FindDuplicatesResult, DuplicateGroup, CodeLocation, FindPatternsInput, FindPatternsResult, PatternMatch, CodePattern, GetSignatureInput, GetSignatureResult, ParameterDetail, TypeDetail, GenericDetail, Documentation, MemberSignature, SignatureSymbolKind, GetDocumentationInput, GetDocumentationResult, FileDocumentation, DocumentedSymbol, DocumentationSymbolKind, ExtractorOptions, ReadFunctionInput, ReadClassInput, ReadTypeInput, ReadSymbolResult, } from "./tools/index.js";
|
|
10
|
+
export { codeStructureSkill, dependencyAuditSkill, refactorImpactSkill, typeAnalysisSkill, codeHealthSkill, tsSkills, defineSkill, type Skill, } from "./skills/index.js";
|
|
11
11
|
/**
|
|
12
12
|
* All TypeScript/JavaScript analysis tools for easy registration
|
|
13
13
|
*/
|
|
@@ -27,8 +27,11 @@ export declare const tsTools: {
|
|
|
27
27
|
readonly findPatterns: import("@compilr-dev/agents").Tool<import("./tools/types.js").FindPatternsInput>;
|
|
28
28
|
readonly getSignature: import("@compilr-dev/agents").Tool<import("./tools/types.js").GetSignatureInput>;
|
|
29
29
|
readonly getDocumentation: import("@compilr-dev/agents").Tool<import("./tools/types.js").GetDocumentationInput>;
|
|
30
|
+
readonly readFunction: import("@compilr-dev/agents").Tool<import("./tools/read-symbol.js").ReadFunctionInput>;
|
|
31
|
+
readonly readClass: import("@compilr-dev/agents").Tool<import("./tools/read-symbol.js").ReadClassInput>;
|
|
32
|
+
readonly readType: import("@compilr-dev/agents").Tool<import("./tools/read-symbol.js").ReadTypeInput>;
|
|
30
33
|
};
|
|
31
34
|
/**
|
|
32
35
|
* Array of all TypeScript/JavaScript analysis tools
|
|
33
36
|
*/
|
|
34
|
-
export declare const allTsTools: readonly [import("@compilr-dev/agents").Tool<import("./tools/types.js").GetFileStructureInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindSymbolInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindReferencesInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetImportsInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetExportsInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetCallGraphInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetDependencyGraphInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindImplementationsInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetTypeHierarchyInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetComplexityInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindDeadCodeInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindDuplicatesInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindPatternsInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetSignatureInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetDocumentationInput>];
|
|
37
|
+
export declare const allTsTools: readonly [import("@compilr-dev/agents").Tool<import("./tools/types.js").GetFileStructureInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindSymbolInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindReferencesInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetImportsInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetExportsInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetCallGraphInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetDependencyGraphInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindImplementationsInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetTypeHierarchyInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetComplexityInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindDeadCodeInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindDuplicatesInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").FindPatternsInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetSignatureInput>, import("@compilr-dev/agents").Tool<import("./tools/types.js").GetDocumentationInput>, import("@compilr-dev/agents").Tool<import("./tools/read-symbol.js").ReadFunctionInput>, import("@compilr-dev/agents").Tool<import("./tools/read-symbol.js").ReadClassInput>, import("@compilr-dev/agents").Tool<import("./tools/read-symbol.js").ReadTypeInput>];
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Provides AST-based code analysis, complexity metrics, and type hierarchy tools.
|
|
6
6
|
*/
|
|
7
7
|
// Parser exports
|
|
8
|
-
export { parseTypeScript, detectLanguage, isLanguageSupported, } from
|
|
8
|
+
export { parseTypeScript, detectLanguage, isLanguageSupported, } from "./parser/index.js";
|
|
9
9
|
// Tool exports
|
|
10
10
|
export {
|
|
11
11
|
// Tier 1 & 2 Tools
|
|
@@ -13,11 +13,13 @@ getFileStructureTool, createGetFileStructureTool, findSymbolTool, createFindSymb
|
|
|
13
13
|
// Tier 3 Tools
|
|
14
14
|
getComplexityTool, createGetComplexityTool, findDeadCodeTool, createFindDeadCodeTool, findDuplicatesTool, createFindDuplicatesTool, findPatternsTool, createFindPatternsTool,
|
|
15
15
|
// Tier 4 Utility Tools
|
|
16
|
-
getSignatureTool, createGetSignatureTool, getDocumentationTool, createGetDocumentationTool,
|
|
16
|
+
getSignatureTool, createGetSignatureTool, getDocumentationTool, createGetDocumentationTool,
|
|
17
|
+
// Smart File Reading Tools
|
|
18
|
+
readFunctionTool, readClassTool, readTypeTool, createReadFunctionTool, createReadClassTool, createReadTypeTool, } from "./tools/index.js";
|
|
17
19
|
// Skill exports
|
|
18
|
-
export { codeStructureSkill, dependencyAuditSkill, refactorImpactSkill, typeAnalysisSkill, codeHealthSkill, tsSkills, defineSkill, } from
|
|
20
|
+
export { codeStructureSkill, dependencyAuditSkill, refactorImpactSkill, typeAnalysisSkill, codeHealthSkill, tsSkills, defineSkill, } from "./skills/index.js";
|
|
19
21
|
// Tool imports for collections
|
|
20
|
-
import { getFileStructureTool, findSymbolTool, findReferencesTool, getImportsTool, getExportsTool, getCallGraphTool, getDependencyGraphTool, findImplementationsTool, getTypeHierarchyTool, getComplexityTool, findDeadCodeTool, findDuplicatesTool, findPatternsTool, getSignatureTool, getDocumentationTool, } from
|
|
22
|
+
import { getFileStructureTool, findSymbolTool, findReferencesTool, getImportsTool, getExportsTool, getCallGraphTool, getDependencyGraphTool, findImplementationsTool, getTypeHierarchyTool, getComplexityTool, findDeadCodeTool, findDuplicatesTool, findPatternsTool, getSignatureTool, getDocumentationTool, readFunctionTool, readClassTool, readTypeTool, } from "./tools/index.js";
|
|
21
23
|
/**
|
|
22
24
|
* All TypeScript/JavaScript analysis tools for easy registration
|
|
23
25
|
*/
|
|
@@ -40,6 +42,10 @@ export const tsTools = {
|
|
|
40
42
|
// Tier 4
|
|
41
43
|
getSignature: getSignatureTool,
|
|
42
44
|
getDocumentation: getDocumentationTool,
|
|
45
|
+
// Smart File Reading
|
|
46
|
+
readFunction: readFunctionTool,
|
|
47
|
+
readClass: readClassTool,
|
|
48
|
+
readType: readTypeTool,
|
|
43
49
|
};
|
|
44
50
|
/**
|
|
45
51
|
* Array of all TypeScript/JavaScript analysis tools
|
|
@@ -63,4 +69,8 @@ export const allTsTools = [
|
|
|
63
69
|
// Tier 4
|
|
64
70
|
getSignatureTool,
|
|
65
71
|
getDocumentationTool,
|
|
72
|
+
// Smart File Reading
|
|
73
|
+
readFunctionTool,
|
|
74
|
+
readClassTool,
|
|
75
|
+
readTypeTool,
|
|
66
76
|
];
|
package/dist/parser/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides AST parsing capabilities using the TypeScript Compiler API.
|
|
5
5
|
*/
|
|
6
|
-
export { parseTypeScript, detectLanguage, isLanguageSupported, } from
|
|
7
|
-
export type { SupportedLanguage } from
|
|
6
|
+
export { parseTypeScript, detectLanguage, isLanguageSupported, } from "./typescript-parser.js";
|
|
7
|
+
export type { SupportedLanguage } from "../tools/types.js";
|
package/dist/parser/index.js
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides AST parsing capabilities using the TypeScript Compiler API.
|
|
5
5
|
*/
|
|
6
|
-
export { parseTypeScript, detectLanguage, isLanguageSupported, } from
|
|
6
|
+
export { parseTypeScript, detectLanguage, isLanguageSupported, } from "./typescript-parser.js";
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* Uses TypeScript's built-in parser for accurate AST analysis.
|
|
5
5
|
* Works for both TypeScript and JavaScript files.
|
|
6
6
|
*/
|
|
7
|
-
import type { FileStructure, ExtractorOptions, SupportedLanguage } from
|
|
7
|
+
import type { FileStructure, ExtractorOptions, SupportedLanguage } from "../tools/types.js";
|
|
8
8
|
/**
|
|
9
9
|
* Parse a TypeScript/JavaScript file and extract its structure
|
|
10
10
|
*/
|
|
11
|
-
export declare function parseTypeScript(sourceCode: string, filePath: string, options?: ExtractorOptions): Omit<FileStructure,
|
|
11
|
+
export declare function parseTypeScript(sourceCode: string, filePath: string, options?: ExtractorOptions): Omit<FileStructure, "path" | "language" | "languageConfidence">;
|
|
12
12
|
/**
|
|
13
13
|
* Detect language from file path
|
|
14
14
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Uses TypeScript's built-in parser for accurate AST analysis.
|
|
5
5
|
* Works for both TypeScript and JavaScript files.
|
|
6
6
|
*/
|
|
7
|
-
import * as ts from
|
|
7
|
+
import * as ts from "typescript";
|
|
8
8
|
// Helper to check for a specific modifier kind
|
|
9
9
|
function hasModifierKind(modifiers, kind) {
|
|
10
10
|
return modifiers?.some((m) => m.kind === kind) ?? false;
|
|
@@ -27,7 +27,7 @@ export function parseTypeScript(sourceCode, filePath, options = {}) {
|
|
|
27
27
|
const types = extractTypes(sourceFile);
|
|
28
28
|
// Calculate stats
|
|
29
29
|
const stats = {
|
|
30
|
-
lineCount: sourceCode.split(
|
|
30
|
+
lineCount: sourceCode.split("\n").length,
|
|
31
31
|
importCount: imports.length,
|
|
32
32
|
exportCount: exports.length,
|
|
33
33
|
classCount: classes.length,
|
|
@@ -48,21 +48,21 @@ export function parseTypeScript(sourceCode, filePath, options = {}) {
|
|
|
48
48
|
* Get TypeScript script kind from file extension
|
|
49
49
|
*/
|
|
50
50
|
function getScriptKind(filePath) {
|
|
51
|
-
const ext = filePath.toLowerCase().split(
|
|
51
|
+
const ext = filePath.toLowerCase().split(".").pop();
|
|
52
52
|
switch (ext) {
|
|
53
|
-
case
|
|
53
|
+
case "ts":
|
|
54
54
|
return ts.ScriptKind.TS;
|
|
55
|
-
case
|
|
55
|
+
case "tsx":
|
|
56
56
|
return ts.ScriptKind.TSX;
|
|
57
|
-
case
|
|
57
|
+
case "js":
|
|
58
58
|
return ts.ScriptKind.JS;
|
|
59
|
-
case
|
|
59
|
+
case "jsx":
|
|
60
60
|
return ts.ScriptKind.JSX;
|
|
61
|
-
case
|
|
62
|
-
case
|
|
61
|
+
case "mts":
|
|
62
|
+
case "cts":
|
|
63
63
|
return ts.ScriptKind.TS;
|
|
64
|
-
case
|
|
65
|
-
case
|
|
64
|
+
case "mjs":
|
|
65
|
+
case "cjs":
|
|
66
66
|
return ts.ScriptKind.JS;
|
|
67
67
|
default:
|
|
68
68
|
return ts.ScriptKind.TS;
|
|
@@ -80,7 +80,9 @@ function extractImports(sourceFile) {
|
|
|
80
80
|
return;
|
|
81
81
|
const source = moduleSpecifier.text;
|
|
82
82
|
// Check for type-only import using modifiers
|
|
83
|
-
const modifiers = ts.canHaveModifiers(node)
|
|
83
|
+
const modifiers = ts.canHaveModifiers(node)
|
|
84
|
+
? ts.getModifiers(node)
|
|
85
|
+
: undefined;
|
|
84
86
|
const hasTypeKeyword = hasModifierKind(modifiers, ts.SyntaxKind.TypeKeyword);
|
|
85
87
|
const importInfo = {
|
|
86
88
|
source,
|
|
@@ -120,7 +122,7 @@ function extractExports(sourceFile) {
|
|
|
120
122
|
// export default ...
|
|
121
123
|
if (ts.isExportAssignment(node)) {
|
|
122
124
|
exports.push({
|
|
123
|
-
name:
|
|
125
|
+
name: "default",
|
|
124
126
|
isDefault: true,
|
|
125
127
|
isTypeOnly: false,
|
|
126
128
|
});
|
|
@@ -129,7 +131,9 @@ function extractExports(sourceFile) {
|
|
|
129
131
|
// export { ... }
|
|
130
132
|
if (ts.isExportDeclaration(node)) {
|
|
131
133
|
// Check for type-only export using modifiers
|
|
132
|
-
const exportMods = ts.canHaveModifiers(node)
|
|
134
|
+
const exportMods = ts.canHaveModifiers(node)
|
|
135
|
+
? ts.getModifiers(node)
|
|
136
|
+
: undefined;
|
|
133
137
|
const isTypeOnlyExport = hasModifierKind(exportMods, ts.SyntaxKind.TypeKeyword);
|
|
134
138
|
if (node.exportClause && ts.isNamedExports(node.exportClause)) {
|
|
135
139
|
for (const element of node.exportClause.elements) {
|
|
@@ -143,11 +147,13 @@ function extractExports(sourceFile) {
|
|
|
143
147
|
return;
|
|
144
148
|
}
|
|
145
149
|
// Check for export modifier on declarations
|
|
146
|
-
const modifiers = ts.canHaveModifiers(node)
|
|
150
|
+
const modifiers = ts.canHaveModifiers(node)
|
|
151
|
+
? ts.getModifiers(node)
|
|
152
|
+
: undefined;
|
|
147
153
|
const hasExport = hasModifierKind(modifiers, ts.SyntaxKind.ExportKeyword);
|
|
148
154
|
const hasDefault = hasModifierKind(modifiers, ts.SyntaxKind.DefaultKeyword);
|
|
149
155
|
if (hasExport) {
|
|
150
|
-
let name =
|
|
156
|
+
let name = "unknown";
|
|
151
157
|
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
152
158
|
name = node.name.text;
|
|
153
159
|
}
|
|
@@ -175,9 +181,9 @@ function extractExports(sourceFile) {
|
|
|
175
181
|
else if (ts.isEnumDeclaration(node)) {
|
|
176
182
|
name = node.name.text;
|
|
177
183
|
}
|
|
178
|
-
if (name !==
|
|
184
|
+
if (name !== "unknown" || hasDefault) {
|
|
179
185
|
exports.push({
|
|
180
|
-
name: hasDefault ?
|
|
186
|
+
name: hasDefault ? "default" : name,
|
|
181
187
|
isDefault: hasDefault,
|
|
182
188
|
isTypeOnly: ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node),
|
|
183
189
|
});
|
|
@@ -205,24 +211,28 @@ function extractClasses(sourceFile, includePrivate, maxDepth) {
|
|
|
205
211
|
* Extract information from a class declaration
|
|
206
212
|
*/
|
|
207
213
|
function extractClassInfo(node, includePrivate, _maxDepth) {
|
|
208
|
-
const name = node.name?.text ??
|
|
209
|
-
const modifiers = ts.canHaveModifiers(node)
|
|
214
|
+
const name = node.name?.text ?? "anonymous";
|
|
215
|
+
const modifiers = ts.canHaveModifiers(node)
|
|
216
|
+
? ts.getModifiers(node)
|
|
217
|
+
: undefined;
|
|
210
218
|
const isExported = hasModifierKind(modifiers, ts.SyntaxKind.ExportKeyword);
|
|
211
219
|
const isAbstract = hasModifierKind(modifiers, ts.SyntaxKind.AbstractKeyword);
|
|
212
220
|
const methods = [];
|
|
213
221
|
const properties = [];
|
|
214
222
|
for (const member of node.members) {
|
|
215
|
-
const memberModifiers = ts.canHaveModifiers(member)
|
|
223
|
+
const memberModifiers = ts.canHaveModifiers(member)
|
|
224
|
+
? ts.getModifiers(member)
|
|
225
|
+
: undefined;
|
|
216
226
|
const visibility = getVisibility(memberModifiers);
|
|
217
227
|
// Skip private members if not included
|
|
218
|
-
if (!includePrivate && visibility ===
|
|
228
|
+
if (!includePrivate && visibility === "private") {
|
|
219
229
|
continue;
|
|
220
230
|
}
|
|
221
231
|
if (ts.isConstructorDeclaration(member)) {
|
|
222
232
|
const isAsync = hasModifierKind(memberModifiers, ts.SyntaxKind.AsyncKeyword);
|
|
223
233
|
const isStatic = hasModifierKind(memberModifiers, ts.SyntaxKind.StaticKeyword);
|
|
224
234
|
methods.push({
|
|
225
|
-
name:
|
|
235
|
+
name: "constructor",
|
|
226
236
|
visibility,
|
|
227
237
|
async: isAsync,
|
|
228
238
|
static: isStatic,
|
|
@@ -231,7 +241,9 @@ function extractClassInfo(node, includePrivate, _maxDepth) {
|
|
|
231
241
|
});
|
|
232
242
|
}
|
|
233
243
|
else if (ts.isMethodDeclaration(member)) {
|
|
234
|
-
const methodName = ts.isIdentifier(member.name)
|
|
244
|
+
const methodName = ts.isIdentifier(member.name)
|
|
245
|
+
? member.name.text
|
|
246
|
+
: "computed";
|
|
235
247
|
const isAsync = hasModifierKind(memberModifiers, ts.SyntaxKind.AsyncKeyword);
|
|
236
248
|
const isStatic = hasModifierKind(memberModifiers, ts.SyntaxKind.StaticKeyword);
|
|
237
249
|
methods.push({
|
|
@@ -244,8 +256,7 @@ function extractClassInfo(node, includePrivate, _maxDepth) {
|
|
|
244
256
|
});
|
|
245
257
|
}
|
|
246
258
|
else if (ts.isPropertyDeclaration(member)) {
|
|
247
|
-
|
|
248
|
-
const propName = member.name && ts.isIdentifier(member.name) ? member.name.text : null;
|
|
259
|
+
const propName = ts.isIdentifier(member.name) ? member.name.text : null;
|
|
249
260
|
if (propName) {
|
|
250
261
|
const isStatic = hasModifierKind(memberModifiers, ts.SyntaxKind.StaticKeyword);
|
|
251
262
|
const isReadonly = hasModifierKind(memberModifiers, ts.SyntaxKind.ReadonlyKeyword);
|
|
@@ -272,21 +283,21 @@ function extractClassInfo(node, includePrivate, _maxDepth) {
|
|
|
272
283
|
*/
|
|
273
284
|
function getVisibility(modifiers) {
|
|
274
285
|
if (!modifiers)
|
|
275
|
-
return
|
|
286
|
+
return "public";
|
|
276
287
|
for (const mod of modifiers) {
|
|
277
288
|
if (mod.kind === ts.SyntaxKind.PrivateKeyword)
|
|
278
|
-
return
|
|
289
|
+
return "private";
|
|
279
290
|
if (mod.kind === ts.SyntaxKind.ProtectedKeyword)
|
|
280
|
-
return
|
|
291
|
+
return "protected";
|
|
281
292
|
}
|
|
282
|
-
return
|
|
293
|
+
return "public";
|
|
283
294
|
}
|
|
284
295
|
/**
|
|
285
296
|
* Extract parameter information
|
|
286
297
|
*/
|
|
287
298
|
function extractParameters(params) {
|
|
288
299
|
return params.map((param) => ({
|
|
289
|
-
name: ts.isIdentifier(param.name) ? param.name.text :
|
|
300
|
+
name: ts.isIdentifier(param.name) ? param.name.text : "param",
|
|
290
301
|
type: param.type ? param.type.getText() : undefined,
|
|
291
302
|
}));
|
|
292
303
|
}
|
|
@@ -298,7 +309,9 @@ function extractFunctions(sourceFile) {
|
|
|
298
309
|
ts.forEachChild(sourceFile, (node) => {
|
|
299
310
|
// Function declarations
|
|
300
311
|
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
301
|
-
const modifiers = ts.canHaveModifiers(node)
|
|
312
|
+
const modifiers = ts.canHaveModifiers(node)
|
|
313
|
+
? ts.getModifiers(node)
|
|
314
|
+
: undefined;
|
|
302
315
|
const isExported = hasModifierKind(modifiers, ts.SyntaxKind.ExportKeyword);
|
|
303
316
|
const isAsync = hasModifierKind(modifiers, ts.SyntaxKind.AsyncKeyword);
|
|
304
317
|
functions.push({
|
|
@@ -311,11 +324,14 @@ function extractFunctions(sourceFile) {
|
|
|
311
324
|
}
|
|
312
325
|
// Variable declarations that are arrow functions
|
|
313
326
|
if (ts.isVariableStatement(node)) {
|
|
314
|
-
const modifiers = ts.canHaveModifiers(node)
|
|
327
|
+
const modifiers = ts.canHaveModifiers(node)
|
|
328
|
+
? ts.getModifiers(node)
|
|
329
|
+
: undefined;
|
|
315
330
|
const isExported = hasModifierKind(modifiers, ts.SyntaxKind.ExportKeyword);
|
|
316
331
|
for (const decl of node.declarationList.declarations) {
|
|
317
332
|
if (ts.isIdentifier(decl.name) && decl.initializer) {
|
|
318
|
-
if (ts.isArrowFunction(decl.initializer) ||
|
|
333
|
+
if (ts.isArrowFunction(decl.initializer) ||
|
|
334
|
+
ts.isFunctionExpression(decl.initializer)) {
|
|
319
335
|
const funcModifiers = decl.initializer.modifiers;
|
|
320
336
|
const isAsync = funcModifiers
|
|
321
337
|
? funcModifiers.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword)
|
|
@@ -325,7 +341,9 @@ function extractFunctions(sourceFile) {
|
|
|
325
341
|
exported: isExported,
|
|
326
342
|
async: isAsync,
|
|
327
343
|
parameters: extractParameters(decl.initializer.parameters),
|
|
328
|
-
returnType: decl.initializer.type
|
|
344
|
+
returnType: decl.initializer.type
|
|
345
|
+
? decl.initializer.type.getText()
|
|
346
|
+
: undefined,
|
|
329
347
|
});
|
|
330
348
|
}
|
|
331
349
|
}
|
|
@@ -341,14 +359,17 @@ function extractVariables(sourceFile) {
|
|
|
341
359
|
const variables = [];
|
|
342
360
|
ts.forEachChild(sourceFile, (node) => {
|
|
343
361
|
if (ts.isVariableStatement(node)) {
|
|
344
|
-
const modifiers = ts.canHaveModifiers(node)
|
|
362
|
+
const modifiers = ts.canHaveModifiers(node)
|
|
363
|
+
? ts.getModifiers(node)
|
|
364
|
+
: undefined;
|
|
345
365
|
const isExported = hasModifierKind(modifiers, ts.SyntaxKind.ExportKeyword);
|
|
346
|
-
const kind = node.declarationList.flags & ts.NodeFlags.Const ?
|
|
366
|
+
const kind = node.declarationList.flags & ts.NodeFlags.Const ? "const" : "let";
|
|
347
367
|
for (const decl of node.declarationList.declarations) {
|
|
348
368
|
if (ts.isIdentifier(decl.name)) {
|
|
349
369
|
// Skip if this is a function (arrow function or function expression)
|
|
350
370
|
if (decl.initializer &&
|
|
351
|
-
(ts.isArrowFunction(decl.initializer) ||
|
|
371
|
+
(ts.isArrowFunction(decl.initializer) ||
|
|
372
|
+
ts.isFunctionExpression(decl.initializer))) {
|
|
352
373
|
continue;
|
|
353
374
|
}
|
|
354
375
|
variables.push({
|
|
@@ -369,26 +390,28 @@ function extractVariables(sourceFile) {
|
|
|
369
390
|
function extractTypes(sourceFile) {
|
|
370
391
|
const types = [];
|
|
371
392
|
ts.forEachChild(sourceFile, (node) => {
|
|
372
|
-
const modifiers = ts.canHaveModifiers(node)
|
|
393
|
+
const modifiers = ts.canHaveModifiers(node)
|
|
394
|
+
? ts.getModifiers(node)
|
|
395
|
+
: undefined;
|
|
373
396
|
const isExported = hasModifierKind(modifiers, ts.SyntaxKind.ExportKeyword);
|
|
374
397
|
if (ts.isInterfaceDeclaration(node)) {
|
|
375
398
|
types.push({
|
|
376
399
|
name: node.name.text,
|
|
377
|
-
kind:
|
|
400
|
+
kind: "interface",
|
|
378
401
|
exported: isExported,
|
|
379
402
|
});
|
|
380
403
|
}
|
|
381
404
|
else if (ts.isTypeAliasDeclaration(node)) {
|
|
382
405
|
types.push({
|
|
383
406
|
name: node.name.text,
|
|
384
|
-
kind:
|
|
407
|
+
kind: "type",
|
|
385
408
|
exported: isExported,
|
|
386
409
|
});
|
|
387
410
|
}
|
|
388
411
|
else if (ts.isEnumDeclaration(node)) {
|
|
389
412
|
types.push({
|
|
390
413
|
name: node.name.text,
|
|
391
|
-
kind:
|
|
414
|
+
kind: "enum",
|
|
392
415
|
exported: isExported,
|
|
393
416
|
});
|
|
394
417
|
}
|
|
@@ -399,18 +422,18 @@ function extractTypes(sourceFile) {
|
|
|
399
422
|
* Detect language from file path
|
|
400
423
|
*/
|
|
401
424
|
export function detectLanguage(filePath) {
|
|
402
|
-
const ext = filePath.toLowerCase().split(
|
|
425
|
+
const ext = filePath.toLowerCase().split(".").pop();
|
|
403
426
|
switch (ext) {
|
|
404
|
-
case
|
|
405
|
-
case
|
|
406
|
-
case
|
|
407
|
-
case
|
|
408
|
-
return { language:
|
|
409
|
-
case
|
|
410
|
-
case
|
|
411
|
-
case
|
|
412
|
-
case
|
|
413
|
-
return { language:
|
|
427
|
+
case "ts":
|
|
428
|
+
case "tsx":
|
|
429
|
+
case "mts":
|
|
430
|
+
case "cts":
|
|
431
|
+
return { language: "typescript", confidence: 1.0 };
|
|
432
|
+
case "js":
|
|
433
|
+
case "jsx":
|
|
434
|
+
case "mjs":
|
|
435
|
+
case "cjs":
|
|
436
|
+
return { language: "javascript", confidence: 1.0 };
|
|
414
437
|
default:
|
|
415
438
|
return { language: null, confidence: 0 };
|
|
416
439
|
}
|
|
@@ -419,5 +442,5 @@ export function detectLanguage(filePath) {
|
|
|
419
442
|
* Check if a language is supported by this parser
|
|
420
443
|
*/
|
|
421
444
|
export function isLanguageSupported(language) {
|
|
422
|
-
return language ===
|
|
445
|
+
return language === "typescript" || language === "javascript";
|
|
423
446
|
}
|
|
@@ -3,15 +3,28 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Analyze codebase health: complexity, dead code, duplicates, and anti-patterns.
|
|
5
5
|
*/
|
|
6
|
-
import { defineSkill } from
|
|
6
|
+
import { defineSkill } from "@compilr-dev/agents";
|
|
7
7
|
/**
|
|
8
8
|
* Code health skill - Analyze codebase health using Tier 3 tools
|
|
9
9
|
*/
|
|
10
10
|
export const codeHealthSkill = defineSkill({
|
|
11
|
-
name:
|
|
12
|
-
description:
|
|
11
|
+
name: "code-health",
|
|
12
|
+
description: "Analyze codebase health: complexity, dead code, duplicates, and anti-patterns",
|
|
13
13
|
prompt: `You are in CODE HEALTH ANALYSIS mode. Analyze the codebase for quality issues.
|
|
14
14
|
|
|
15
|
+
## When to Use
|
|
16
|
+
- Conducting a code quality audit
|
|
17
|
+
- Finding complexity hotspots before refactoring
|
|
18
|
+
- Identifying dead code that can be removed
|
|
19
|
+
- Detecting code duplication and anti-patterns
|
|
20
|
+
- Preparing for a code review or tech debt assessment
|
|
21
|
+
|
|
22
|
+
## When NOT to Use
|
|
23
|
+
- Need security-focused review → use security-review skill
|
|
24
|
+
- Want to understand code structure → use code-structure skill
|
|
25
|
+
- Planning specific refactoring → use refactor-impact skill first
|
|
26
|
+
- Checking npm package vulnerabilities → use dependency-management skill (from core)
|
|
27
|
+
|
|
15
28
|
## TOOLS TO USE
|
|
16
29
|
|
|
17
30
|
1. **get_complexity**: Analyze code complexity
|
|
@@ -162,6 +175,6 @@ find_patterns({
|
|
|
162
175
|
- Consider project context (prototype vs production)
|
|
163
176
|
- Dead code detection has false positives - verify before removing
|
|
164
177
|
- Duplication is sometimes intentional - use judgment`,
|
|
165
|
-
tags: [
|
|
166
|
-
version:
|
|
178
|
+
tags: ["analysis", "quality", "complexity", "health", "audit"],
|
|
179
|
+
version: "1.0.0",
|
|
167
180
|
});
|
|
@@ -3,15 +3,25 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Analyze and understand codebase structure using analysis tools.
|
|
5
5
|
*/
|
|
6
|
-
import { defineSkill } from
|
|
6
|
+
import { defineSkill } from "@compilr-dev/agents";
|
|
7
7
|
/**
|
|
8
8
|
* Code structure skill - Understand codebase structure using analysis tools
|
|
9
9
|
*/
|
|
10
10
|
export const codeStructureSkill = defineSkill({
|
|
11
|
-
name:
|
|
12
|
-
description:
|
|
11
|
+
name: "code-structure",
|
|
12
|
+
description: "Analyze and understand codebase structure quickly",
|
|
13
13
|
prompt: `You are in CODE STRUCTURE ANALYSIS mode. Analyze the specified path to understand its structure.
|
|
14
14
|
|
|
15
|
+
## When to Use
|
|
16
|
+
- Understanding a new file or module
|
|
17
|
+
- Exploring codebase architecture
|
|
18
|
+
- Finding entry points and exports
|
|
19
|
+
|
|
20
|
+
## When NOT to Use
|
|
21
|
+
- Need to find a specific symbol → use code-navigation skill
|
|
22
|
+
- Need to refactor → use refactor-impact skill first
|
|
23
|
+
- Need dependency analysis → use dependency-audit skill
|
|
24
|
+
|
|
15
25
|
## TOOLS TO USE
|
|
16
26
|
|
|
17
27
|
1. **get_file_structure**: Analyze a file's internal structure
|
|
@@ -92,6 +102,6 @@ Any patterns, conventions, or notable design decisions.
|
|
|
92
102
|
- Highlight patterns and conventions
|
|
93
103
|
- Note any red flags (circular deps, mixed concerns) but don't dwell
|
|
94
104
|
- Keep output concise - expand only when asked`,
|
|
95
|
-
tags: [
|
|
96
|
-
version:
|
|
105
|
+
tags: ["analysis", "structure", "understanding", "navigation"],
|
|
106
|
+
version: "1.0.0",
|
|
97
107
|
});
|
|
@@ -3,15 +3,26 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Audit module dependencies and identify potential issues.
|
|
5
5
|
*/
|
|
6
|
-
import { defineSkill } from
|
|
6
|
+
import { defineSkill } from "@compilr-dev/agents";
|
|
7
7
|
/**
|
|
8
8
|
* Dependency audit skill - Analyze module dependencies for issues
|
|
9
9
|
*/
|
|
10
10
|
export const dependencyAuditSkill = defineSkill({
|
|
11
|
-
name:
|
|
12
|
-
description:
|
|
11
|
+
name: "dependency-audit",
|
|
12
|
+
description: "Audit module dependencies and identify potential issues",
|
|
13
13
|
prompt: `You are in DEPENDENCY AUDIT mode. Analyze the project's module dependencies.
|
|
14
14
|
|
|
15
|
+
## When to Use
|
|
16
|
+
- Investigating circular dependency issues
|
|
17
|
+
- Auditing module coupling before refactoring
|
|
18
|
+
- Understanding dependency relationships in a codebase
|
|
19
|
+
- Identifying heavy or duplicate external packages
|
|
20
|
+
|
|
21
|
+
## When NOT to Use
|
|
22
|
+
- Just need to understand one file's structure → use code-structure skill
|
|
23
|
+
- Looking for a specific function or class → use code-navigation skill (find_symbol)
|
|
24
|
+
- Checking npm package vulnerabilities → use dependency-management skill (from core)
|
|
25
|
+
|
|
15
26
|
## TOOLS TO USE
|
|
16
27
|
|
|
17
28
|
1. **get_dependency_graph**: Build a complete module dependency graph
|
|
@@ -105,6 +116,6 @@ For suspicious files, use get_imports to see:
|
|
|
105
116
|
- Don't flag normal patterns as issues
|
|
106
117
|
- Provide actionable recommendations
|
|
107
118
|
- Be concise - expand only on request`,
|
|
108
|
-
tags: [
|
|
109
|
-
version:
|
|
119
|
+
tags: ["analysis", "dependencies", "audit", "architecture"],
|
|
120
|
+
version: "1.0.0",
|
|
110
121
|
});
|
package/dist/skills/index.d.ts
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Specialized skills for code analysis workflows using AST-based tools.
|
|
5
5
|
*/
|
|
6
|
-
import type { Skill } from
|
|
7
|
-
export { defineSkill, type Skill } from
|
|
8
|
-
export { codeStructureSkill } from
|
|
9
|
-
export { dependencyAuditSkill } from
|
|
10
|
-
export { refactorImpactSkill } from
|
|
11
|
-
export { typeAnalysisSkill } from
|
|
12
|
-
export { codeHealthSkill } from
|
|
6
|
+
import type { Skill } from "@compilr-dev/agents";
|
|
7
|
+
export { defineSkill, type Skill } from "@compilr-dev/agents";
|
|
8
|
+
export { codeStructureSkill } from "./code-structure.js";
|
|
9
|
+
export { dependencyAuditSkill } from "./dependency-audit.js";
|
|
10
|
+
export { refactorImpactSkill } from "./refactor-impact.js";
|
|
11
|
+
export { typeAnalysisSkill } from "./type-analysis.js";
|
|
12
|
+
export { codeHealthSkill } from "./code-health.js";
|
|
13
13
|
/**
|
|
14
14
|
* All TypeScript/JavaScript analysis skills
|
|
15
15
|
*/
|
package/dist/skills/index.js
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Specialized skills for code analysis workflows using AST-based tools.
|
|
5
5
|
*/
|
|
6
|
-
export { defineSkill } from
|
|
7
|
-
export { codeStructureSkill } from
|
|
8
|
-
export { dependencyAuditSkill } from
|
|
9
|
-
export { refactorImpactSkill } from
|
|
10
|
-
export { typeAnalysisSkill } from
|
|
11
|
-
export { codeHealthSkill } from
|
|
6
|
+
export { defineSkill } from "@compilr-dev/agents";
|
|
7
|
+
export { codeStructureSkill } from "./code-structure.js";
|
|
8
|
+
export { dependencyAuditSkill } from "./dependency-audit.js";
|
|
9
|
+
export { refactorImpactSkill } from "./refactor-impact.js";
|
|
10
|
+
export { typeAnalysisSkill } from "./type-analysis.js";
|
|
11
|
+
export { codeHealthSkill } from "./code-health.js";
|
|
12
12
|
// Import for collection
|
|
13
|
-
import { codeStructureSkill } from
|
|
14
|
-
import { dependencyAuditSkill } from
|
|
15
|
-
import { refactorImpactSkill } from
|
|
16
|
-
import { typeAnalysisSkill } from
|
|
17
|
-
import { codeHealthSkill } from
|
|
13
|
+
import { codeStructureSkill } from "./code-structure.js";
|
|
14
|
+
import { dependencyAuditSkill } from "./dependency-audit.js";
|
|
15
|
+
import { refactorImpactSkill } from "./refactor-impact.js";
|
|
16
|
+
import { typeAnalysisSkill } from "./type-analysis.js";
|
|
17
|
+
import { codeHealthSkill } from "./code-health.js";
|
|
18
18
|
/**
|
|
19
19
|
* All TypeScript/JavaScript analysis skills
|
|
20
20
|
*/
|