@milo4jo/contextkit 0.3.0 → 0.5.1
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/README.md +43 -11
- package/dist/commands/cache.d.ts +3 -0
- package/dist/commands/cache.d.ts.map +1 -0
- package/dist/commands/cache.js +50 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/select.d.ts.map +1 -1
- package/dist/commands/select.js +17 -9
- package/dist/commands/select.js.map +1 -1
- package/dist/config/index.d.ts +11 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +11 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/validation.d.ts +33 -0
- package/dist/config/validation.d.ts.map +1 -0
- package/dist/config/validation.js +241 -0
- package/dist/config/validation.js.map +1 -0
- package/dist/db/index.d.ts +47 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +98 -0
- package/dist/db/index.js.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/indexer/chunker.d.ts +15 -2
- package/dist/indexer/chunker.d.ts.map +1 -1
- package/dist/indexer/chunker.js +222 -3
- package/dist/indexer/chunker.js.map +1 -1
- package/dist/parsers/index.d.ts +45 -0
- package/dist/parsers/index.d.ts.map +1 -0
- package/dist/parsers/index.js +71 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/typescript.d.ts +43 -0
- package/dist/parsers/typescript.d.ts.map +1 -0
- package/dist/parsers/typescript.js +306 -0
- package/dist/parsers/typescript.js.map +1 -0
- package/dist/retrieval/imports.d.ts +76 -0
- package/dist/retrieval/imports.d.ts.map +1 -0
- package/dist/retrieval/imports.js +258 -0
- package/dist/retrieval/imports.js.map +1 -0
- package/dist/selector/formatter.d.ts +15 -0
- package/dist/selector/formatter.d.ts.map +1 -1
- package/dist/selector/formatter.js +132 -0
- package/dist/selector/formatter.js.map +1 -1
- package/dist/selector/index.d.ts +15 -4
- package/dist/selector/index.d.ts.map +1 -1
- package/dist/selector/index.js +100 -12
- package/dist/selector/index.js.map +1 -1
- package/dist/selector/scoring.d.ts +20 -0
- package/dist/selector/scoring.d.ts.map +1 -1
- package/dist/selector/scoring.js +103 -10
- package/dist/selector/scoring.js.map +1 -1
- package/package.json +1 -1
- package/dist/commands/source.d.ts +0 -3
- package/dist/commands/source.d.ts.map +0 -1
- package/dist/commands/source.js +0 -153
- package/dist/commands/source.js.map +0 -1
- package/dist/utils/output.d.ts +0 -42
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/output.js +0 -62
- package/dist/utils/output.js.map +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for language-specific parsers.
|
|
5
|
+
* Determines which parser to use based on file extension.
|
|
6
|
+
*/
|
|
7
|
+
import { parseTypeScript, isTypeScriptOrJavaScript, } from './typescript.js';
|
|
8
|
+
/** Registered parsers mapped by extension */
|
|
9
|
+
const parsers = new Map();
|
|
10
|
+
// Register TypeScript/JavaScript parser for all supported extensions
|
|
11
|
+
const tsExtensions = ['ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs', 'mts', 'cts'];
|
|
12
|
+
for (const ext of tsExtensions) {
|
|
13
|
+
parsers.set(ext, parseTypeScript);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get the parser for a file based on its extension.
|
|
17
|
+
*
|
|
18
|
+
* @param filePath - Path to the file
|
|
19
|
+
* @returns Parser function or undefined if no parser is available
|
|
20
|
+
*/
|
|
21
|
+
export function getParser(filePath) {
|
|
22
|
+
const ext = filePath.toLowerCase().split('.').pop();
|
|
23
|
+
if (!ext)
|
|
24
|
+
return undefined;
|
|
25
|
+
return parsers.get(ext);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check if a file can be parsed by any registered parser.
|
|
29
|
+
*
|
|
30
|
+
* @param filePath - Path to the file
|
|
31
|
+
* @returns True if a parser is available for this file type
|
|
32
|
+
*/
|
|
33
|
+
export function canParse(filePath) {
|
|
34
|
+
return getParser(filePath) !== undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parse a file and extract code boundaries.
|
|
38
|
+
*
|
|
39
|
+
* @param content - File content
|
|
40
|
+
* @param filePath - Path to the file (used to determine parser)
|
|
41
|
+
* @returns Parse result with boundaries, or failure result if no parser available
|
|
42
|
+
*/
|
|
43
|
+
export function parseFile(content, filePath) {
|
|
44
|
+
const parser = getParser(filePath);
|
|
45
|
+
if (!parser) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
boundaries: [],
|
|
49
|
+
error: `No parser available for file type: ${filePath}`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return parser(content, filePath);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Register a custom parser for a file extension.
|
|
56
|
+
*
|
|
57
|
+
* @param extension - File extension (without dot)
|
|
58
|
+
* @param parser - Parser function
|
|
59
|
+
*/
|
|
60
|
+
export function registerParser(extension, parser) {
|
|
61
|
+
parsers.set(extension.toLowerCase(), parser);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get list of supported file extensions.
|
|
65
|
+
*/
|
|
66
|
+
export function getSupportedExtensions() {
|
|
67
|
+
return Array.from(parsers.keys());
|
|
68
|
+
}
|
|
69
|
+
// Re-export utility functions
|
|
70
|
+
export { isTypeScriptOrJavaScript };
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parsers/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EACf,wBAAwB,GAIzB,MAAM,iBAAiB,CAAC;AAOzB,6CAA6C;AAC7C,MAAM,OAAO,GAA0B,IAAI,GAAG,EAAE,CAAC;AAEjD,qEAAqE;AACrE,MAAM,YAAY,GAAG,CAAC,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C,CAAC;AAED,8BAA8B;AAC9B,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript/JavaScript AST Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses TS/JS files to identify code boundaries for intelligent chunking.
|
|
5
|
+
* Uses acorn for parsing JavaScript (ignores TypeScript-specific syntax).
|
|
6
|
+
*/
|
|
7
|
+
/** Type of code unit identified by the parser */
|
|
8
|
+
export type CodeUnitType = 'function' | 'class' | 'method' | 'constant' | 'block';
|
|
9
|
+
/** A code boundary identified by the parser */
|
|
10
|
+
export interface CodeBoundary {
|
|
11
|
+
/** Type of code unit */
|
|
12
|
+
type: CodeUnitType;
|
|
13
|
+
/** Name of the unit (function name, class name, etc.) */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Start line (1-indexed) */
|
|
16
|
+
startLine: number;
|
|
17
|
+
/** End line (1-indexed, inclusive) */
|
|
18
|
+
endLine: number;
|
|
19
|
+
/** Whether this is exported */
|
|
20
|
+
exported: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Result of parsing a file */
|
|
23
|
+
export interface ParseResult {
|
|
24
|
+
/** Whether parsing succeeded */
|
|
25
|
+
success: boolean;
|
|
26
|
+
/** Identified code boundaries */
|
|
27
|
+
boundaries: CodeBoundary[];
|
|
28
|
+
/** Error message if parsing failed */
|
|
29
|
+
error?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse TypeScript/JavaScript code and extract code boundaries.
|
|
33
|
+
*
|
|
34
|
+
* @param content - The file content to parse
|
|
35
|
+
* @param _filePath - Path to the file (for error messages, unused currently)
|
|
36
|
+
* @returns Parse result with boundaries or error
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseTypeScript(content: string, _filePath?: string): ParseResult;
|
|
39
|
+
/**
|
|
40
|
+
* Check if a file extension is supported by this parser.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isTypeScriptOrJavaScript(filePath: string): boolean;
|
|
43
|
+
//# sourceMappingURL=typescript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/parsers/typescript.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,iDAAiD;AACjD,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAElF,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,wBAAwB;IACxB,IAAI,EAAE,YAAY,CAAC;IACnB,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,+BAA+B;AAC/B,MAAM,WAAW,WAAW;IAC1B,gCAAgC;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,iCAAiC;IACjC,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA0HD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAsPhF;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGlE"}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript/JavaScript AST Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses TS/JS files to identify code boundaries for intelligent chunking.
|
|
5
|
+
* Uses acorn for parsing JavaScript (ignores TypeScript-specific syntax).
|
|
6
|
+
*/
|
|
7
|
+
import * as acorn from 'acorn';
|
|
8
|
+
/**
|
|
9
|
+
* Strip TypeScript-specific syntax to make the code parseable by acorn.
|
|
10
|
+
* This is a simple preprocessing step that handles common TS patterns.
|
|
11
|
+
*/
|
|
12
|
+
function stripTypeScript(code) {
|
|
13
|
+
// Remove type annotations: `: Type`, `: Type[]`, `: Type<Generic>`
|
|
14
|
+
// This regex handles common cases but isn't perfect for all TS syntax
|
|
15
|
+
let stripped = code;
|
|
16
|
+
// Remove type imports: import type { ... } from '...'
|
|
17
|
+
stripped = stripped.replace(/import\s+type\s+\{[^}]*\}\s+from\s+['"][^'"]*['"];?/g, '');
|
|
18
|
+
stripped = stripped.replace(/import\s+type\s+\w+\s+from\s+['"][^'"]*['"];?/g, '');
|
|
19
|
+
// Remove "type" keyword in imports: import { type Foo, Bar } from '...'
|
|
20
|
+
stripped = stripped.replace(/,\s*type\s+\w+/g, '');
|
|
21
|
+
stripped = stripped.replace(/\{\s*type\s+\w+\s*,/g, '{');
|
|
22
|
+
stripped = stripped.replace(/\{\s*type\s+\w+\s*\}/g, '{}');
|
|
23
|
+
// Remove interface declarations
|
|
24
|
+
stripped = stripped.replace(/interface\s+\w+(?:<[^>]*>)?\s*(?:extends[^{]*)?\{[^}]*\}/gs, '');
|
|
25
|
+
// Remove type aliases
|
|
26
|
+
stripped = stripped.replace(/type\s+\w+(?:<[^>]*>)?\s*=\s*[^;]+;/g, '');
|
|
27
|
+
// Remove type assertions: as Type, as const
|
|
28
|
+
stripped = stripped.replace(/\s+as\s+(?:const|\w+(?:<[^>]*>)?)/g, '');
|
|
29
|
+
// Remove generic type parameters from functions/classes: <T, U>
|
|
30
|
+
stripped = stripped.replace(/<[^<>()]*(?:<[^<>]*>[^<>()]*)*>\s*(?=\()/g, '');
|
|
31
|
+
// Remove type annotations from parameters: (x: Type) => (x)
|
|
32
|
+
// This is tricky - we need to be careful not to break the code
|
|
33
|
+
stripped = stripped.replace(/:\s*\w+(?:<[^>]*>)?(?:\[\])?(?:\s*\|\s*\w+(?:<[^>]*>)?(?:\[\])?)*(?=\s*[,)=])/g, '');
|
|
34
|
+
// Remove return type annotations: ): Type {
|
|
35
|
+
stripped = stripped.replace(/\):\s*\w+(?:<[^>]*>)?(?:\[\])?(?:\s*\|\s*\w+(?:<[^>]*>)?(?:\[\])?)*\s*(?=\{|=>)/g, ') ');
|
|
36
|
+
// Remove non-null assertions: foo!.bar -> foo.bar
|
|
37
|
+
stripped = stripped.replace(/!(?=\.|\[)/g, '');
|
|
38
|
+
// Remove declare keyword
|
|
39
|
+
stripped = stripped.replace(/declare\s+/g, '');
|
|
40
|
+
// Remove readonly keyword
|
|
41
|
+
stripped = stripped.replace(/readonly\s+/g, '');
|
|
42
|
+
// Remove abstract keyword
|
|
43
|
+
stripped = stripped.replace(/abstract\s+/g, '');
|
|
44
|
+
// Remove public/private/protected modifiers
|
|
45
|
+
stripped = stripped.replace(/(?:public|private|protected)\s+/g, '');
|
|
46
|
+
// Remove implements clause
|
|
47
|
+
stripped = stripped.replace(/implements\s+[\w,\s<>]+(?=\s*\{)/g, '');
|
|
48
|
+
return stripped;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Parse TypeScript/JavaScript code and extract code boundaries.
|
|
52
|
+
*
|
|
53
|
+
* @param content - The file content to parse
|
|
54
|
+
* @param _filePath - Path to the file (for error messages, unused currently)
|
|
55
|
+
* @returns Parse result with boundaries or error
|
|
56
|
+
*/
|
|
57
|
+
export function parseTypeScript(content, _filePath) {
|
|
58
|
+
const boundaries = [];
|
|
59
|
+
// Try to parse as JavaScript first, then try stripping TypeScript syntax
|
|
60
|
+
let ast;
|
|
61
|
+
try {
|
|
62
|
+
ast = acorn.parse(content, {
|
|
63
|
+
ecmaVersion: 'latest',
|
|
64
|
+
sourceType: 'module',
|
|
65
|
+
locations: true,
|
|
66
|
+
allowHashBang: true,
|
|
67
|
+
allowAwaitOutsideFunction: true,
|
|
68
|
+
allowImportExportEverywhere: true,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Try stripping TypeScript syntax and parse again
|
|
73
|
+
try {
|
|
74
|
+
const stripped = stripTypeScript(content);
|
|
75
|
+
ast = acorn.parse(stripped, {
|
|
76
|
+
ecmaVersion: 'latest',
|
|
77
|
+
sourceType: 'module',
|
|
78
|
+
locations: true,
|
|
79
|
+
allowHashBang: true,
|
|
80
|
+
allowAwaitOutsideFunction: true,
|
|
81
|
+
allowImportExportEverywhere: true,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
boundaries: [],
|
|
88
|
+
error: e instanceof Error ? e.message : 'Parse error',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Track what's been exported
|
|
93
|
+
const exportedNames = new Set();
|
|
94
|
+
// First pass: collect exports
|
|
95
|
+
for (const node of ast.body) {
|
|
96
|
+
if (node.type === 'ExportNamedDeclaration') {
|
|
97
|
+
const exportNode = node;
|
|
98
|
+
if (exportNode.declaration) {
|
|
99
|
+
const decl = exportNode.declaration;
|
|
100
|
+
if (decl.type === 'FunctionDeclaration') {
|
|
101
|
+
const fn = decl;
|
|
102
|
+
if (fn.id?.name)
|
|
103
|
+
exportedNames.add(fn.id.name);
|
|
104
|
+
}
|
|
105
|
+
else if (decl.type === 'ClassDeclaration') {
|
|
106
|
+
const cls = decl;
|
|
107
|
+
if (cls.id?.name)
|
|
108
|
+
exportedNames.add(cls.id.name);
|
|
109
|
+
}
|
|
110
|
+
else if (decl.type === 'VariableDeclaration') {
|
|
111
|
+
const varDecl = decl;
|
|
112
|
+
for (const declarator of varDecl.declarations) {
|
|
113
|
+
if (declarator.id.type === 'Identifier') {
|
|
114
|
+
exportedNames.add(declarator.id.name);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (node.type === 'ExportDefaultDeclaration') {
|
|
121
|
+
exportedNames.add('default');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Second pass: extract boundaries
|
|
125
|
+
for (const node of ast.body) {
|
|
126
|
+
if (!node.loc)
|
|
127
|
+
continue;
|
|
128
|
+
const startLine = node.loc.start.line;
|
|
129
|
+
const endLine = node.loc.end.line;
|
|
130
|
+
if (node.type === 'FunctionDeclaration') {
|
|
131
|
+
const fn = node;
|
|
132
|
+
const name = fn.id?.name || 'anonymous';
|
|
133
|
+
boundaries.push({
|
|
134
|
+
type: 'function',
|
|
135
|
+
name,
|
|
136
|
+
startLine,
|
|
137
|
+
endLine,
|
|
138
|
+
exported: exportedNames.has(name),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else if (node.type === 'ClassDeclaration') {
|
|
142
|
+
const cls = node;
|
|
143
|
+
const className = cls.id?.name || 'AnonymousClass';
|
|
144
|
+
// Add the class itself
|
|
145
|
+
boundaries.push({
|
|
146
|
+
type: 'class',
|
|
147
|
+
name: className,
|
|
148
|
+
startLine,
|
|
149
|
+
endLine,
|
|
150
|
+
exported: exportedNames.has(className),
|
|
151
|
+
});
|
|
152
|
+
// Also add methods as separate boundaries (for large classes)
|
|
153
|
+
if (cls.body?.body) {
|
|
154
|
+
for (const member of cls.body.body) {
|
|
155
|
+
if (member.type === 'MethodDefinition' && member.loc) {
|
|
156
|
+
const method = member;
|
|
157
|
+
let methodName = 'anonymous';
|
|
158
|
+
if (method.key.type === 'Identifier') {
|
|
159
|
+
methodName = method.key.name;
|
|
160
|
+
}
|
|
161
|
+
boundaries.push({
|
|
162
|
+
type: 'method',
|
|
163
|
+
name: `${className}.${methodName}`,
|
|
164
|
+
startLine: member.loc.start.line,
|
|
165
|
+
endLine: member.loc.end.line,
|
|
166
|
+
exported: false,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else if (node.type === 'VariableDeclaration') {
|
|
173
|
+
const varDecl = node;
|
|
174
|
+
// Only track const declarations (likely to be important exports/configs)
|
|
175
|
+
if (varDecl.kind === 'const') {
|
|
176
|
+
for (const declarator of varDecl.declarations) {
|
|
177
|
+
if (declarator.id.type === 'Identifier') {
|
|
178
|
+
const name = declarator.id.name;
|
|
179
|
+
// Check if it's an arrow function or function expression
|
|
180
|
+
const init = declarator.init;
|
|
181
|
+
const isFunction = init?.type === 'ArrowFunctionExpression' ||
|
|
182
|
+
init?.type === 'FunctionExpression';
|
|
183
|
+
boundaries.push({
|
|
184
|
+
type: isFunction ? 'function' : 'constant',
|
|
185
|
+
name,
|
|
186
|
+
startLine,
|
|
187
|
+
endLine,
|
|
188
|
+
exported: exportedNames.has(name),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else if (node.type === 'ExportNamedDeclaration') {
|
|
195
|
+
const exportNode = node;
|
|
196
|
+
if (exportNode.declaration) {
|
|
197
|
+
// The declaration inside the export has already been processed above
|
|
198
|
+
// due to our pre-pass. Mark the boundaries as exported.
|
|
199
|
+
const decl = exportNode.declaration;
|
|
200
|
+
if (decl.type === 'FunctionDeclaration') {
|
|
201
|
+
const fn = decl;
|
|
202
|
+
const name = fn.id?.name || 'anonymous';
|
|
203
|
+
boundaries.push({
|
|
204
|
+
type: 'function',
|
|
205
|
+
name,
|
|
206
|
+
startLine,
|
|
207
|
+
endLine,
|
|
208
|
+
exported: true,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
else if (decl.type === 'ClassDeclaration') {
|
|
212
|
+
const cls = decl;
|
|
213
|
+
const className = cls.id?.name || 'AnonymousClass';
|
|
214
|
+
boundaries.push({
|
|
215
|
+
type: 'class',
|
|
216
|
+
name: className,
|
|
217
|
+
startLine,
|
|
218
|
+
endLine,
|
|
219
|
+
exported: true,
|
|
220
|
+
});
|
|
221
|
+
// Add methods
|
|
222
|
+
if (cls.body?.body) {
|
|
223
|
+
for (const member of cls.body.body) {
|
|
224
|
+
if (member.type === 'MethodDefinition' && member.loc) {
|
|
225
|
+
const method = member;
|
|
226
|
+
let methodName = 'anonymous';
|
|
227
|
+
if (method.key.type === 'Identifier') {
|
|
228
|
+
methodName = method.key.name;
|
|
229
|
+
}
|
|
230
|
+
boundaries.push({
|
|
231
|
+
type: 'method',
|
|
232
|
+
name: `${className}.${methodName}`,
|
|
233
|
+
startLine: member.loc.start.line,
|
|
234
|
+
endLine: member.loc.end.line,
|
|
235
|
+
exported: false,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else if (decl.type === 'VariableDeclaration') {
|
|
242
|
+
const varDecl = decl;
|
|
243
|
+
if (varDecl.kind === 'const') {
|
|
244
|
+
for (const declarator of varDecl.declarations) {
|
|
245
|
+
if (declarator.id.type === 'Identifier') {
|
|
246
|
+
const name = declarator.id.name;
|
|
247
|
+
const init = declarator.init;
|
|
248
|
+
const isFunction = init?.type === 'ArrowFunctionExpression' ||
|
|
249
|
+
init?.type === 'FunctionExpression';
|
|
250
|
+
boundaries.push({
|
|
251
|
+
type: isFunction ? 'function' : 'constant',
|
|
252
|
+
name,
|
|
253
|
+
startLine,
|
|
254
|
+
endLine,
|
|
255
|
+
exported: true,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else if (node.type === 'ExportDefaultDeclaration') {
|
|
264
|
+
const exportDefault = node;
|
|
265
|
+
const decl = exportDefault.declaration;
|
|
266
|
+
let type = 'block';
|
|
267
|
+
let name = 'default';
|
|
268
|
+
if (decl.type === 'FunctionDeclaration' || decl.type === 'FunctionExpression') {
|
|
269
|
+
type = 'function';
|
|
270
|
+
if (decl.id?.name) {
|
|
271
|
+
name = decl.id.name;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
else if (decl.type === 'ClassDeclaration') {
|
|
275
|
+
type = 'class';
|
|
276
|
+
if (decl.id?.name) {
|
|
277
|
+
name = decl.id.name;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else if (decl.type === 'ArrowFunctionExpression') {
|
|
281
|
+
type = 'function';
|
|
282
|
+
}
|
|
283
|
+
boundaries.push({
|
|
284
|
+
type,
|
|
285
|
+
name,
|
|
286
|
+
startLine,
|
|
287
|
+
endLine,
|
|
288
|
+
exported: true,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// Sort boundaries by start line
|
|
293
|
+
boundaries.sort((a, b) => a.startLine - b.startLine);
|
|
294
|
+
return {
|
|
295
|
+
success: true,
|
|
296
|
+
boundaries,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Check if a file extension is supported by this parser.
|
|
301
|
+
*/
|
|
302
|
+
export function isTypeScriptOrJavaScript(filePath) {
|
|
303
|
+
const ext = filePath.toLowerCase().split('.').pop();
|
|
304
|
+
return ['ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs', 'mts', 'cts'].includes(ext || '');
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=typescript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../src/parsers/typescript.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA2F/B;;;GAGG;AACH,SAAS,eAAe,CAAC,IAAY;IACnC,mEAAmE;IACnE,sEAAsE;IACtE,IAAI,QAAQ,GAAG,IAAI,CAAC;IAEpB,sDAAsD;IACtD,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,sDAAsD,EAAE,EAAE,CAAC,CAAC;IACxF,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,gDAAgD,EAAE,EAAE,CAAC,CAAC;IAElF,wEAAwE;IACxE,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACnD,QAAQ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EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import Parser Module
|
|
3
|
+
*
|
|
4
|
+
* Parses TypeScript/JavaScript import statements to find related files.
|
|
5
|
+
* Uses regex patterns instead of AST parsing for simplicity and speed.
|
|
6
|
+
*/
|
|
7
|
+
/** Parsed import statement */
|
|
8
|
+
export interface ParsedImport {
|
|
9
|
+
/** Original import specifier (e.g., './utils', 'lodash') */
|
|
10
|
+
specifier: string;
|
|
11
|
+
/** Type of import */
|
|
12
|
+
type: 'relative' | 'absolute' | 'package';
|
|
13
|
+
/** Line number where import appears (1-indexed) */
|
|
14
|
+
line: number;
|
|
15
|
+
/** Named imports (e.g., ['foo', 'bar'] from `import { foo, bar } from ...`) */
|
|
16
|
+
namedImports?: string[];
|
|
17
|
+
/** Default import name */
|
|
18
|
+
defaultImport?: string;
|
|
19
|
+
/** Whether it's a type-only import */
|
|
20
|
+
isTypeOnly: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Result of import parsing */
|
|
23
|
+
export interface ImportParseResult {
|
|
24
|
+
/** All parsed imports */
|
|
25
|
+
imports: ParsedImport[];
|
|
26
|
+
/** Resolved relative paths to related files */
|
|
27
|
+
relatedFiles: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Supported import patterns:
|
|
31
|
+
* - import { foo, bar } from './module'
|
|
32
|
+
* - import * as name from './module'
|
|
33
|
+
* - import name from './module'
|
|
34
|
+
* - import './module'
|
|
35
|
+
* - import type { Foo } from './module'
|
|
36
|
+
* - export { foo } from './module'
|
|
37
|
+
* - export * from './module'
|
|
38
|
+
* - const x = require('./module')
|
|
39
|
+
* - const x = await import('./module')
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Parse imports from source code
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseImports(content: string): ParsedImport[];
|
|
45
|
+
/**
|
|
46
|
+
* Classify import type based on specifier
|
|
47
|
+
*/
|
|
48
|
+
export declare function classifyImportType(specifier: string): 'relative' | 'absolute' | 'package';
|
|
49
|
+
/**
|
|
50
|
+
* Resolve a relative import specifier to an actual file path
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveImport(specifier: string, fromFile: string, basePath: string): string | null;
|
|
53
|
+
/**
|
|
54
|
+
* Parse imports and resolve related files
|
|
55
|
+
*/
|
|
56
|
+
export declare function parseImportsWithResolution(content: string, filePath: string, basePath: string): ImportParseResult;
|
|
57
|
+
/**
|
|
58
|
+
* Extract all import specifiers from content (quick extraction without full parsing)
|
|
59
|
+
*/
|
|
60
|
+
export declare function extractImportSpecifiers(content: string): string[];
|
|
61
|
+
/**
|
|
62
|
+
* Check if a file is TypeScript/JavaScript
|
|
63
|
+
*/
|
|
64
|
+
export declare function isJsTsFile(filePath: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Build a simple dependency graph for files
|
|
67
|
+
*/
|
|
68
|
+
export declare function buildDependencyGraph(files: Array<{
|
|
69
|
+
path: string;
|
|
70
|
+
content: string;
|
|
71
|
+
}>, basePath: string): Map<string, string[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Find files that import a given file (reverse dependencies)
|
|
74
|
+
*/
|
|
75
|
+
export declare function findImporters(targetFile: string, dependencyGraph: Map<string, string[]>): string[];
|
|
76
|
+
//# sourceMappingURL=imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../src/retrieval/imports.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,8BAA8B;AAC9B,MAAM,WAAW,YAAY;IAC3B,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB;IACrB,IAAI,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;IAC1C,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,+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