@thoughtflow/codebase 0.2.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/dist/contexts/context-decomposer.d.ts +13 -0
- package/dist/contexts/context-decomposer.d.ts.map +1 -0
- package/dist/contexts/context-decomposer.js +97 -0
- package/dist/contexts/context-decomposer.js.map +1 -0
- package/dist/contexts/context-document-manager.d.ts +21 -0
- package/dist/contexts/context-document-manager.d.ts.map +1 -0
- package/dist/contexts/context-document-manager.js +69 -0
- package/dist/contexts/context-document-manager.js.map +1 -0
- package/dist/contexts/context-router.d.ts +13 -0
- package/dist/contexts/context-router.d.ts.map +1 -0
- package/dist/contexts/context-router.js +94 -0
- package/dist/contexts/context-router.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/libs/codebase/deep-analyzer.d.ts +58 -0
- package/dist/libs/codebase/deep-analyzer.d.ts.map +1 -0
- package/dist/libs/codebase/deep-analyzer.js +239 -0
- package/dist/libs/codebase/deep-analyzer.js.map +1 -0
- package/dist/libs/codebase/graph/dependency-extractor.d.ts +20 -0
- package/dist/libs/codebase/graph/dependency-extractor.d.ts.map +1 -0
- package/dist/libs/codebase/graph/dependency-extractor.js +174 -0
- package/dist/libs/codebase/graph/dependency-extractor.js.map +1 -0
- package/dist/libs/codebase/graph/graph-analysis.d.ts +42 -0
- package/dist/libs/codebase/graph/graph-analysis.d.ts.map +1 -0
- package/dist/libs/codebase/graph/graph-analysis.js +222 -0
- package/dist/libs/codebase/graph/graph-analysis.js.map +1 -0
- package/dist/libs/codebase/graph/graph-visualizer.d.ts +12 -0
- package/dist/libs/codebase/graph/graph-visualizer.d.ts.map +1 -0
- package/dist/libs/codebase/graph/graph-visualizer.js +99 -0
- package/dist/libs/codebase/graph/graph-visualizer.js.map +1 -0
- package/dist/libs/codebase/indexer/batch-processor.d.ts +18 -0
- package/dist/libs/codebase/indexer/batch-processor.d.ts.map +1 -0
- package/dist/libs/codebase/indexer/batch-processor.js +39 -0
- package/dist/libs/codebase/indexer/batch-processor.js.map +1 -0
- package/dist/libs/codebase/indexer/chunker-markdown.d.ts +19 -0
- package/dist/libs/codebase/indexer/chunker-markdown.d.ts.map +1 -0
- package/dist/libs/codebase/indexer/chunker-markdown.js +138 -0
- package/dist/libs/codebase/indexer/chunker-markdown.js.map +1 -0
- package/dist/libs/codebase/indexer/chunker.d.ts +21 -0
- package/dist/libs/codebase/indexer/chunker.d.ts.map +1 -0
- package/dist/libs/codebase/indexer/chunker.js +133 -0
- package/dist/libs/codebase/indexer/chunker.js.map +1 -0
- package/dist/libs/codebase/indexer/explorer.d.ts +29 -0
- package/dist/libs/codebase/indexer/explorer.d.ts.map +1 -0
- package/dist/libs/codebase/indexer/explorer.js +278 -0
- package/dist/libs/codebase/indexer/explorer.js.map +1 -0
- package/dist/libs/codebase/indexer/indexer.d.ts +35 -0
- package/dist/libs/codebase/indexer/indexer.d.ts.map +1 -0
- package/dist/libs/codebase/indexer/indexer.js +172 -0
- package/dist/libs/codebase/indexer/indexer.js.map +1 -0
- package/dist/libs/codebase/knowledge/cross-referencer.d.ts +32 -0
- package/dist/libs/codebase/knowledge/cross-referencer.d.ts.map +1 -0
- package/dist/libs/codebase/knowledge/cross-referencer.js +132 -0
- package/dist/libs/codebase/knowledge/cross-referencer.js.map +1 -0
- package/dist/libs/codebase/knowledge/markdown-extractor.d.ts +34 -0
- package/dist/libs/codebase/knowledge/markdown-extractor.d.ts.map +1 -0
- package/dist/libs/codebase/knowledge/markdown-extractor.js +273 -0
- package/dist/libs/codebase/knowledge/markdown-extractor.js.map +1 -0
- package/dist/libs/codebase/knowledge/summarizer.d.ts +25 -0
- package/dist/libs/codebase/knowledge/summarizer.d.ts.map +1 -0
- package/dist/libs/codebase/knowledge/summarizer.js +61 -0
- package/dist/libs/codebase/knowledge/summarizer.js.map +1 -0
- package/dist/libs/codebase/search/bm25.d.ts +23 -0
- package/dist/libs/codebase/search/bm25.d.ts.map +1 -0
- package/dist/libs/codebase/search/bm25.js +93 -0
- package/dist/libs/codebase/search/bm25.js.map +1 -0
- package/dist/libs/codebase/search/hybrid-search.d.ts +22 -0
- package/dist/libs/codebase/search/hybrid-search.d.ts.map +1 -0
- package/dist/libs/codebase/search/hybrid-search.js +80 -0
- package/dist/libs/codebase/search/hybrid-search.js.map +1 -0
- package/dist/libs/codebase-index.class.d.ts +66 -0
- package/dist/libs/codebase-index.class.d.ts.map +1 -0
- package/dist/libs/codebase-index.class.js +595 -0
- package/dist/libs/codebase-index.class.js.map +1 -0
- package/dist/tools/codebase/codebase-analyze.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-analyze.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-analyze.tool.js +20 -0
- package/dist/tools/codebase/codebase-analyze.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-crossref.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-crossref.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-crossref.tool.js +20 -0
- package/dist/tools/codebase/codebase-crossref.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-flow.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-flow.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-flow.tool.js +20 -0
- package/dist/tools/codebase/codebase-flow.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-graph-circular.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-graph-circular.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-graph-circular.tool.js +17 -0
- package/dist/tools/codebase/codebase-graph-circular.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-graph-query.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-graph-query.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-graph-query.tool.js +21 -0
- package/dist/tools/codebase/codebase-graph-query.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-graph-stats.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-graph-stats.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-graph-stats.tool.js +17 -0
- package/dist/tools/codebase/codebase-graph-stats.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-graph-visualize.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-graph-visualize.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-graph-visualize.tool.js +21 -0
- package/dist/tools/codebase/codebase-graph-visualize.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-impact.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-impact.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-impact.tool.js +21 -0
- package/dist/tools/codebase/codebase-impact.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-index.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-index.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-index.tool.js +21 -0
- package/dist/tools/codebase/codebase-index.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-knowledge.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-knowledge.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-knowledge.tool.js +22 -0
- package/dist/tools/codebase/codebase-knowledge.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-search.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-search.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-search.tool.js +24 -0
- package/dist/tools/codebase/codebase-search.tool.js.map +1 -0
- package/dist/tools/codebase/codebase-status.tool.d.ts +8 -0
- package/dist/tools/codebase/codebase-status.tool.d.ts.map +1 -0
- package/dist/tools/codebase/codebase-status.tool.js +19 -0
- package/dist/tools/codebase/codebase-status.tool.js.map +1 -0
- package/dist/tools/neural/comparative-analysis.tool.d.ts +37 -0
- package/dist/tools/neural/comparative-analysis.tool.d.ts.map +1 -0
- package/dist/tools/neural/comparative-analysis.tool.js +241 -0
- package/dist/tools/neural/comparative-analysis.tool.js.map +1 -0
- package/dist/tools/neural/index.d.ts +12 -0
- package/dist/tools/neural/index.d.ts.map +1 -0
- package/dist/tools/neural/index.js +28 -0
- package/dist/tools/neural/index.js.map +1 -0
- package/dist/tools/neural/neural-deadcode.tool.d.ts +10 -0
- package/dist/tools/neural/neural-deadcode.tool.d.ts.map +1 -0
- package/dist/tools/neural/neural-deadcode.tool.js +133 -0
- package/dist/tools/neural/neural-deadcode.tool.js.map +1 -0
- package/dist/tools/neural/neural-debug.tool.d.ts +11 -0
- package/dist/tools/neural/neural-debug.tool.d.ts.map +1 -0
- package/dist/tools/neural/neural-debug.tool.js +205 -0
- package/dist/tools/neural/neural-debug.tool.js.map +1 -0
- package/dist/tools/neural/neural-explain.tool.d.ts +9 -0
- package/dist/tools/neural/neural-explain.tool.d.ts.map +1 -0
- package/dist/tools/neural/neural-explain.tool.js +100 -0
- package/dist/tools/neural/neural-explain.tool.js.map +1 -0
- package/dist/tools/neural/neural-optimize.tool.d.ts +9 -0
- package/dist/tools/neural/neural-optimize.tool.d.ts.map +1 -0
- package/dist/tools/neural/neural-optimize.tool.js +117 -0
- package/dist/tools/neural/neural-optimize.tool.js.map +1 -0
- package/dist/tools/neural/neural-pattern.tool.d.ts +10 -0
- package/dist/tools/neural/neural-pattern.tool.d.ts.map +1 -0
- package/dist/tools/neural/neural-pattern.tool.js +169 -0
- package/dist/tools/neural/neural-pattern.tool.js.map +1 -0
- package/dist/tools/neural/neural-review.tool.d.ts +11 -0
- package/dist/tools/neural/neural-review.tool.d.ts.map +1 -0
- package/dist/tools/neural/neural-review.tool.js +152 -0
- package/dist/tools/neural/neural-review.tool.js.map +1 -0
- package/dist/tools/neural/neural-security.tool.d.ts +16 -0
- package/dist/tools/neural/neural-security.tool.d.ts.map +1 -0
- package/dist/tools/neural/neural-security.tool.js +256 -0
- package/dist/tools/neural/neural-security.tool.js.map +1 -0
- package/dist/tools/neural/neural-similar.tool.d.ts +9 -0
- package/dist/tools/neural/neural-similar.tool.d.ts.map +1 -0
- package/dist/tools/neural/neural-similar.tool.js +139 -0
- package/dist/tools/neural/neural-similar.tool.js.map +1 -0
- package/dist/tools/neural/neural-smells.tool.d.ts +9 -0
- package/dist/tools/neural/neural-smells.tool.d.ts.map +1 -0
- package/dist/tools/neural/neural-smells.tool.js +123 -0
- package/dist/tools/neural/neural-smells.tool.js.map +1 -0
- package/dist/tools/neural/neural-suggest.tool.d.ts +9 -0
- package/dist/tools/neural/neural-suggest.tool.d.ts.map +1 -0
- package/dist/tools/neural/neural-suggest.tool.js +64 -0
- package/dist/tools/neural/neural-suggest.tool.js.map +1 -0
- package/dist/tools/quality/index.d.ts +8 -0
- package/dist/tools/quality/index.d.ts.map +1 -0
- package/dist/tools/quality/index.js +24 -0
- package/dist/tools/quality/index.js.map +1 -0
- package/dist/tools/quality/quality-complexity.tool.d.ts +11 -0
- package/dist/tools/quality/quality-complexity.tool.d.ts.map +1 -0
- package/dist/tools/quality/quality-complexity.tool.js +152 -0
- package/dist/tools/quality/quality-complexity.tool.js.map +1 -0
- package/dist/tools/quality/quality-coupling.tool.d.ts +9 -0
- package/dist/tools/quality/quality-coupling.tool.d.ts.map +1 -0
- package/dist/tools/quality/quality-coupling.tool.js +51 -0
- package/dist/tools/quality/quality-coupling.tool.js.map +1 -0
- package/dist/tools/quality/quality-coverage.tool.d.ts +9 -0
- package/dist/tools/quality/quality-coverage.tool.d.ts.map +1 -0
- package/dist/tools/quality/quality-coverage.tool.js +104 -0
- package/dist/tools/quality/quality-coverage.tool.js.map +1 -0
- package/dist/tools/quality/quality-deps.tool.d.ts +11 -0
- package/dist/tools/quality/quality-deps.tool.d.ts.map +1 -0
- package/dist/tools/quality/quality-deps.tool.js +119 -0
- package/dist/tools/quality/quality-deps.tool.js.map +1 -0
- package/dist/tools/quality/quality-duplication.tool.d.ts +9 -0
- package/dist/tools/quality/quality-duplication.tool.d.ts.map +1 -0
- package/dist/tools/quality/quality-duplication.tool.js +100 -0
- package/dist/tools/quality/quality-duplication.tool.js.map +1 -0
- package/dist/tools/quality/quality-size.tool.d.ts +9 -0
- package/dist/tools/quality/quality-size.tool.d.ts.map +1 -0
- package/dist/tools/quality/quality-size.tool.js +94 -0
- package/dist/tools/quality/quality-size.tool.js.map +1 -0
- package/dist/tools/quality/quality-types.tool.d.ts +9 -0
- package/dist/tools/quality/quality-types.tool.d.ts.map +1 -0
- package/dist/tools/quality/quality-types.tool.js +95 -0
- package/dist/tools/quality/quality-types.tool.js.map +1 -0
- package/dist/tools/workspace/analyze-project.tool.d.ts +36 -0
- package/dist/tools/workspace/analyze-project.tool.d.ts.map +1 -0
- package/dist/tools/workspace/analyze-project.tool.js +454 -0
- package/dist/tools/workspace/analyze-project.tool.js.map +1 -0
- package/dist/tools/workspace/codebase-research.tool.d.ts +10 -0
- package/dist/tools/workspace/codebase-research.tool.d.ts.map +1 -0
- package/dist/tools/workspace/codebase-research.tool.js +89 -0
- package/dist/tools/workspace/codebase-research.tool.js.map +1 -0
- package/dist/tools/workspace/project-scanner.tool.d.ts +55 -0
- package/dist/tools/workspace/project-scanner.tool.d.ts.map +1 -0
- package/dist/tools/workspace/project-scanner.tool.js +978 -0
- package/dist/tools/workspace/project-scanner.tool.js.map +1 -0
- package/dist/tools/workspace/search-code.tool.d.ts +14 -0
- package/dist/tools/workspace/search-code.tool.d.ts.map +1 -0
- package/dist/tools/workspace/search-code.tool.js +286 -0
- package/dist/tools/workspace/search-code.tool.js.map +1 -0
- package/package.json +17 -0
- package/src/contexts/context-decomposer.ts +113 -0
- package/src/contexts/context-document-manager.ts +70 -0
- package/src/contexts/context-router.ts +121 -0
- package/src/index.ts +65 -0
- package/src/libs/codebase/deep-analyzer.ts +287 -0
- package/src/libs/codebase/graph/dependency-extractor.ts +165 -0
- package/src/libs/codebase/graph/graph-analysis.ts +231 -0
- package/src/libs/codebase/graph/graph-visualizer.ts +124 -0
- package/src/libs/codebase/indexer/batch-processor.ts +47 -0
- package/src/libs/codebase/indexer/chunker-markdown.ts +175 -0
- package/src/libs/codebase/indexer/chunker.ts +126 -0
- package/src/libs/codebase/indexer/explorer.ts +269 -0
- package/src/libs/codebase/indexer/indexer.ts +174 -0
- package/src/libs/codebase/knowledge/cross-referencer.ts +182 -0
- package/src/libs/codebase/knowledge/markdown-extractor.ts +270 -0
- package/src/libs/codebase/knowledge/summarizer.ts +85 -0
- package/src/libs/codebase/search/bm25.ts +109 -0
- package/src/libs/codebase/search/hybrid-search.ts +109 -0
- package/src/libs/codebase-index.class.ts +715 -0
- package/src/tools/codebase/codebase-analyze.tool.ts +18 -0
- package/src/tools/codebase/codebase-crossref.tool.ts +18 -0
- package/src/tools/codebase/codebase-flow.tool.ts +18 -0
- package/src/tools/codebase/codebase-graph-circular.tool.ts +15 -0
- package/src/tools/codebase/codebase-graph-query.tool.ts +19 -0
- package/src/tools/codebase/codebase-graph-stats.tool.ts +15 -0
- package/src/tools/codebase/codebase-graph-visualize.tool.ts +19 -0
- package/src/tools/codebase/codebase-impact.tool.ts +19 -0
- package/src/tools/codebase/codebase-index.tool.ts +19 -0
- package/src/tools/codebase/codebase-knowledge.tool.ts +20 -0
- package/src/tools/codebase/codebase-search.tool.ts +22 -0
- package/src/tools/codebase/codebase-status.tool.ts +17 -0
- package/src/tools/neural/comparative-analysis.tool.ts +309 -0
- package/src/tools/neural/index.ts +11 -0
- package/src/tools/neural/neural-deadcode.tool.ts +105 -0
- package/src/tools/neural/neural-debug.tool.ts +199 -0
- package/src/tools/neural/neural-explain.tool.ts +67 -0
- package/src/tools/neural/neural-optimize.tool.ts +93 -0
- package/src/tools/neural/neural-pattern.tool.ts +141 -0
- package/src/tools/neural/neural-review.tool.ts +145 -0
- package/src/tools/neural/neural-security.tool.ts +226 -0
- package/src/tools/neural/neural-similar.tool.ts +113 -0
- package/src/tools/neural/neural-smells.tool.ts +98 -0
- package/src/tools/neural/neural-suggest.tool.ts +65 -0
- package/src/tools/quality/index.ts +7 -0
- package/src/tools/quality/quality-complexity.tool.ts +132 -0
- package/src/tools/quality/quality-coupling.tool.ts +57 -0
- package/src/tools/quality/quality-coverage.tool.ts +78 -0
- package/src/tools/quality/quality-deps.tool.ts +89 -0
- package/src/tools/quality/quality-duplication.tool.ts +71 -0
- package/src/tools/quality/quality-size.tool.ts +66 -0
- package/src/tools/quality/quality-types.tool.ts +66 -0
- package/src/tools/workspace/analyze-project.tool.ts +429 -0
- package/src/tools/workspace/codebase-research.tool.ts +100 -0
- package/src/tools/workspace/project-scanner.tool.ts +1058 -0
- package/src/tools/workspace/search-code.tool.ts +344 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export type CodebaseSearchMode = "hybrid" | "content" | "path" | "symbol";
|
|
2
|
+
export type CodebaseSymbolKind = "class" | "function" | "method" | "interface" | "type" | "enum" | "const" | "variable";
|
|
3
|
+
export interface CodebaseSearchFilters {
|
|
4
|
+
pathPrefix?: string;
|
|
5
|
+
extensions?: string[];
|
|
6
|
+
includeGlobs?: string[];
|
|
7
|
+
excludeGlobs?: string[];
|
|
8
|
+
includeHidden?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface CodebaseSearchOptions extends CodebaseSearchFilters {
|
|
11
|
+
query?: string;
|
|
12
|
+
mode: CodebaseSearchMode;
|
|
13
|
+
limit: number;
|
|
14
|
+
offset: number;
|
|
15
|
+
regex?: boolean;
|
|
16
|
+
caseSensitive?: boolean;
|
|
17
|
+
symbolKinds?: CodebaseSymbolKind[];
|
|
18
|
+
maxSnippetChars?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface CodebaseSearchHit {
|
|
21
|
+
path: string;
|
|
22
|
+
line?: number;
|
|
23
|
+
column?: number;
|
|
24
|
+
snippet?: string;
|
|
25
|
+
symbol?: string;
|
|
26
|
+
kind?: CodebaseSymbolKind;
|
|
27
|
+
source: "path" | "content" | "symbol";
|
|
28
|
+
score: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CodebaseIndexStats {
|
|
31
|
+
rootDir: string;
|
|
32
|
+
fileCount: number;
|
|
33
|
+
symbolCount: number;
|
|
34
|
+
hasFts: boolean;
|
|
35
|
+
indexedAt: string | null;
|
|
36
|
+
}
|
|
37
|
+
export declare class CodebaseIndex {
|
|
38
|
+
private readonly rootDir;
|
|
39
|
+
private static readonly shared;
|
|
40
|
+
static forRoot(rootDir: string): Promise<CodebaseIndex>;
|
|
41
|
+
private readonly db;
|
|
42
|
+
private hasFts;
|
|
43
|
+
private indexedAtMs;
|
|
44
|
+
private indexed;
|
|
45
|
+
private constructor();
|
|
46
|
+
isIndexed(): boolean;
|
|
47
|
+
rebuild(maxFileBytes?: number): CodebaseIndexStats;
|
|
48
|
+
getStats(): CodebaseIndexStats;
|
|
49
|
+
search(options: CodebaseSearchOptions): CodebaseSearchHit[];
|
|
50
|
+
private searchPaths;
|
|
51
|
+
private searchContent;
|
|
52
|
+
private searchSymbols;
|
|
53
|
+
private queryDocuments;
|
|
54
|
+
private applyDocumentFilters;
|
|
55
|
+
private makeMatcher;
|
|
56
|
+
private makeLineFinder;
|
|
57
|
+
private pathScore;
|
|
58
|
+
private applyGlobFilters;
|
|
59
|
+
private createSchema;
|
|
60
|
+
private clearIndex;
|
|
61
|
+
private collectFiles;
|
|
62
|
+
private isLikelyText;
|
|
63
|
+
private normalizeRel;
|
|
64
|
+
private extractSymbols;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=codebase-index.class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codebase-index.class.d.ts","sourceRoot":"","sources":["../../src/libs/codebase-index.class.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;AAC1E,MAAM,MAAM,kBAAkB,GAC1B,OAAO,GACP,UAAU,GACV,QAAQ,GACR,WAAW,GACX,MAAM,GACN,MAAM,GACN,OAAO,GACP,UAAU,CAAC;AAEf,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,kBAAkB,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACnC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;IACtC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAsGD,qBAAa,aAAa;IAkBJ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAjB5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAoC;WAErD,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAU7D,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAM;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO;IAQP,SAAS,IAAI,OAAO;IAIpB,OAAO,CAAC,YAAY,SAAc,GAAG,kBAAkB;IA8DvD,QAAQ,IAAI,kBAAkB;IAc9B,MAAM,CAAC,OAAO,EAAE,qBAAqB,GAAG,iBAAiB,EAAE;IAkC3D,OAAO,CAAC,WAAW;IAqBnB,OAAO,CAAC,aAAa;IA6BrB,OAAO,CAAC,aAAa;IAiDrB,OAAO,CAAC,cAAc;IA0CtB,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,cAAc;IAsCtB,OAAO,CAAC,SAAS;IAUjB,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,YAAY;IAuCpB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,YAAY;IA6BpB,OAAO,CAAC,YAAY;IAsBpB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,cAAc;CAiCvB"}
|
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.CodebaseIndex = void 0;
|
|
37
|
+
const fs = __importStar(require("node:fs"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const DEFAULT_SKIP_DIRS = new Set([
|
|
40
|
+
"node_modules",
|
|
41
|
+
".git",
|
|
42
|
+
"dist",
|
|
43
|
+
"build",
|
|
44
|
+
"coverage",
|
|
45
|
+
"out",
|
|
46
|
+
".next",
|
|
47
|
+
".turbo",
|
|
48
|
+
".cache",
|
|
49
|
+
"vendor",
|
|
50
|
+
]);
|
|
51
|
+
const DEFAULT_BINARY_EXTS = new Set([
|
|
52
|
+
".png", ".jpg", ".jpeg", ".gif", ".webp", ".ico", ".pdf", ".zip", ".gz", ".tar", ".tgz",
|
|
53
|
+
".bz2", ".7z", ".rar", ".mp4", ".mov", ".avi", ".mp3", ".wav", ".woff", ".woff2", ".ttf",
|
|
54
|
+
".eot", ".class", ".jar", ".exe", ".dll", ".so", ".dylib", ".bin", ".wasm", ".map",
|
|
55
|
+
]);
|
|
56
|
+
const SYMBOL_PATTERNS = [
|
|
57
|
+
// TS/JS
|
|
58
|
+
{ kind: "class", regex: /\bclass\s+([A-Za-z_$][\w$]*)/g, languages: ["ts", "js"] },
|
|
59
|
+
{ kind: "interface", regex: /\binterface\s+([A-Za-z_$][\w$]*)/g, languages: ["ts"] },
|
|
60
|
+
{ kind: "type", regex: /\btype\s+([A-Za-z_$][\w$]*)\s*=/g, languages: ["ts"] },
|
|
61
|
+
{ kind: "enum", regex: /\benum\s+([A-Za-z_$][\w$]*)/g, languages: ["ts", "js"] },
|
|
62
|
+
{ kind: "function", regex: /\bfunction\s+([A-Za-z_$][\w$]*)\s*\(/g, languages: ["ts", "js"] },
|
|
63
|
+
{ kind: "const", regex: /\bconst\s+([A-Za-z_$][\w$]*)\s*=/g, languages: ["ts", "js"] },
|
|
64
|
+
{ kind: "variable", regex: /\b(?:let|var)\s+([A-Za-z_$][\w$]*)\s*=/g, languages: ["ts", "js"] },
|
|
65
|
+
{ kind: "method", regex: /^\s*(?:public|private|protected|async|static|readonly\s+)*([A-Za-z_$][\w$]*)\s*\([^\n)]*\)\s*\{/g, languages: ["ts", "js"] },
|
|
66
|
+
// Python
|
|
67
|
+
{ kind: "class", regex: /^\s*class\s+([A-Za-z_][\w]*)\s*(?:\(|:)/g, languages: ["python"] },
|
|
68
|
+
{ kind: "function", regex: /^\s*def\s+([A-Za-z_][\w]*)\s*\(/g, languages: ["python"] },
|
|
69
|
+
// PHP
|
|
70
|
+
{ kind: "class", regex: /\bclass\s+([A-Za-z_][\w]*)/g, languages: ["php"] },
|
|
71
|
+
{ kind: "interface", regex: /\binterface\s+([A-Za-z_][\w]*)/g, languages: ["php"] },
|
|
72
|
+
{ kind: "enum", regex: /\benum\s+([A-Za-z_][\w]*)/g, languages: ["php"] },
|
|
73
|
+
{ kind: "function", regex: /\bfunction\s+([A-Za-z_][\w]*)\s*\(/g, languages: ["php"] },
|
|
74
|
+
// Go
|
|
75
|
+
{ kind: "type", regex: /^\s*type\s+([A-Za-z_][\w]*)\s+(?:struct|interface|\w+)/g, languages: ["go"] },
|
|
76
|
+
{ kind: "function", regex: /^\s*func\s+(?:\([^)]+\)\s*)?([A-Za-z_][\w]*)\s*\(/g, languages: ["go"] },
|
|
77
|
+
// Java
|
|
78
|
+
{ kind: "class", regex: /\bclass\s+([A-Za-z_][\w]*)/g, languages: ["java"] },
|
|
79
|
+
{ kind: "interface", regex: /\binterface\s+([A-Za-z_][\w]*)/g, languages: ["java"] },
|
|
80
|
+
{ kind: "enum", regex: /\benum\s+([A-Za-z_][\w]*)/g, languages: ["java"] },
|
|
81
|
+
{ kind: "method", regex: /^\s*(?:public|private|protected|static|final|synchronized|native|abstract)\s+[A-Za-z_<>,\[\]\s]+\s+([A-Za-z_][\w]*)\s*\(/g, languages: ["java"] },
|
|
82
|
+
// C#
|
|
83
|
+
{ kind: "class", regex: /\bclass\s+([A-Za-z_][\w]*)/g, languages: ["csharp"] },
|
|
84
|
+
{ kind: "interface", regex: /\binterface\s+([A-Za-z_][\w]*)/g, languages: ["csharp"] },
|
|
85
|
+
{ kind: "enum", regex: /\benum\s+([A-Za-z_][\w]*)/g, languages: ["csharp"] },
|
|
86
|
+
{ kind: "method", regex: /^\s*(?:public|private|protected|internal|static|virtual|override|async)\s+[A-Za-z_<>,\[\]\?\s]+\s+([A-Za-z_][\w]*)\s*\(/g, languages: ["csharp"] },
|
|
87
|
+
// Rust
|
|
88
|
+
{ kind: "type", regex: /^\s*(?:pub\s+)?(?:struct|trait|type)\s+([A-Za-z_][\w]*)/g, languages: ["rust"] },
|
|
89
|
+
{ kind: "enum", regex: /^\s*(?:pub\s+)?enum\s+([A-Za-z_][\w]*)/g, languages: ["rust"] },
|
|
90
|
+
{ kind: "function", regex: /^\s*(?:pub\s+)?fn\s+([A-Za-z_][\w]*)\s*\(/g, languages: ["rust"] },
|
|
91
|
+
// Ruby
|
|
92
|
+
{ kind: "class", regex: /^\s*class\s+([A-Za-z_][\w:]*)/g, languages: ["ruby"] },
|
|
93
|
+
{ kind: "function", regex: /^\s*def\s+([A-Za-z_][\w!?=]*)/g, languages: ["ruby"] },
|
|
94
|
+
];
|
|
95
|
+
class CodebaseIndex {
|
|
96
|
+
rootDir;
|
|
97
|
+
static shared = new Map();
|
|
98
|
+
static async forRoot(rootDir) {
|
|
99
|
+
const { default: Database } = await Promise.resolve().then(() => __importStar(require("better-sqlite3")));
|
|
100
|
+
const key = path.resolve(rootDir);
|
|
101
|
+
const existing = this.shared.get(key);
|
|
102
|
+
if (existing)
|
|
103
|
+
return existing;
|
|
104
|
+
const created = new CodebaseIndex(key, Database);
|
|
105
|
+
this.shared.set(key, created);
|
|
106
|
+
return created;
|
|
107
|
+
}
|
|
108
|
+
db;
|
|
109
|
+
hasFts = false;
|
|
110
|
+
indexedAtMs = null;
|
|
111
|
+
indexed = false;
|
|
112
|
+
constructor(rootDir, Database) {
|
|
113
|
+
this.rootDir = rootDir;
|
|
114
|
+
this.db = new Database(":memory:");
|
|
115
|
+
this.db.pragma("journal_mode = OFF");
|
|
116
|
+
this.db.pragma("synchronous = OFF");
|
|
117
|
+
this.db.pragma("temp_store = MEMORY");
|
|
118
|
+
this.createSchema();
|
|
119
|
+
}
|
|
120
|
+
isIndexed() {
|
|
121
|
+
return this.indexed;
|
|
122
|
+
}
|
|
123
|
+
rebuild(maxFileBytes = 1024 * 1024) {
|
|
124
|
+
this.clearIndex();
|
|
125
|
+
const files = this.collectFiles(this.rootDir);
|
|
126
|
+
const insertFile = this.db.prepare("INSERT INTO files (rel_path, ext, mtime_ms, size_bytes, content) VALUES (?, ?, ?, ?, ?)");
|
|
127
|
+
const insertFts = this.hasFts
|
|
128
|
+
? this.db.prepare("INSERT INTO files_fts (rowid, rel_path, content) VALUES (?, ?, ?)")
|
|
129
|
+
: null;
|
|
130
|
+
const insertSymbol = this.db.prepare("INSERT INTO symbols (file_id, name, kind, line, column, signature) VALUES (?, ?, ?, ?, ?, ?)");
|
|
131
|
+
const tx = this.db.transaction((absolutePaths) => {
|
|
132
|
+
for (const absPath of absolutePaths) {
|
|
133
|
+
let stat;
|
|
134
|
+
try {
|
|
135
|
+
stat = fs.statSync(absPath);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (!stat.isFile())
|
|
141
|
+
continue;
|
|
142
|
+
if (stat.size > maxFileBytes)
|
|
143
|
+
continue;
|
|
144
|
+
if (!this.isLikelyText(absPath))
|
|
145
|
+
continue;
|
|
146
|
+
let content;
|
|
147
|
+
try {
|
|
148
|
+
content = fs.readFileSync(absPath, "utf8");
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const relPath = this.normalizeRel(absPath);
|
|
154
|
+
const ext = path.extname(absPath).toLowerCase();
|
|
155
|
+
const inserted = insertFile.run(relPath, ext, Math.floor(stat.mtimeMs), stat.size, content);
|
|
156
|
+
const fileId = Number(inserted.lastInsertRowid);
|
|
157
|
+
if (insertFts) {
|
|
158
|
+
insertFts.run(fileId, relPath, content);
|
|
159
|
+
}
|
|
160
|
+
for (const symbol of this.extractSymbols(content, ext)) {
|
|
161
|
+
insertSymbol.run(fileId, symbol.name, symbol.kind, symbol.line, symbol.column, symbol.signature);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
tx(files);
|
|
166
|
+
this.indexedAtMs = Date.now();
|
|
167
|
+
this.indexed = true;
|
|
168
|
+
return this.getStats();
|
|
169
|
+
}
|
|
170
|
+
getStats() {
|
|
171
|
+
const fileRow = this.db.prepare("SELECT COUNT(*) AS c FROM files").get();
|
|
172
|
+
const symbolRow = this.db.prepare("SELECT COUNT(*) AS c FROM symbols").get();
|
|
173
|
+
const fileCount = Number(fileRow?.c ?? 0);
|
|
174
|
+
const symbolCount = Number(symbolRow?.c ?? 0);
|
|
175
|
+
return {
|
|
176
|
+
rootDir: this.rootDir,
|
|
177
|
+
fileCount,
|
|
178
|
+
symbolCount,
|
|
179
|
+
hasFts: this.hasFts,
|
|
180
|
+
indexedAt: this.indexedAtMs ? new Date(this.indexedAtMs).toISOString() : null,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
search(options) {
|
|
184
|
+
const mode = options.mode;
|
|
185
|
+
const allHits = [];
|
|
186
|
+
if (mode === "path" || mode === "hybrid") {
|
|
187
|
+
allHits.push(...this.searchPaths(options));
|
|
188
|
+
}
|
|
189
|
+
if (mode === "content" || mode === "hybrid") {
|
|
190
|
+
allHits.push(...this.searchContent(options));
|
|
191
|
+
}
|
|
192
|
+
if (mode === "symbol" || mode === "hybrid") {
|
|
193
|
+
allHits.push(...this.searchSymbols(options));
|
|
194
|
+
}
|
|
195
|
+
const dedup = new Map();
|
|
196
|
+
for (const hit of allHits) {
|
|
197
|
+
const key = `${hit.source}|${hit.path}|${hit.line ?? 0}|${hit.column ?? 0}|${hit.symbol ?? ""}`;
|
|
198
|
+
const existing = dedup.get(key);
|
|
199
|
+
if (!existing || hit.score > existing.score)
|
|
200
|
+
dedup.set(key, hit);
|
|
201
|
+
}
|
|
202
|
+
const sorted = Array.from(dedup.values()).sort((a, b) => {
|
|
203
|
+
if (b.score !== a.score)
|
|
204
|
+
return b.score - a.score;
|
|
205
|
+
if (a.path !== b.path)
|
|
206
|
+
return a.path.localeCompare(b.path);
|
|
207
|
+
return (a.line ?? 0) - (b.line ?? 0);
|
|
208
|
+
});
|
|
209
|
+
const offset = Math.max(0, options.offset);
|
|
210
|
+
const limit = Math.max(1, options.limit);
|
|
211
|
+
return sorted.slice(offset, offset + limit);
|
|
212
|
+
}
|
|
213
|
+
searchPaths(options) {
|
|
214
|
+
const docs = this.queryDocuments(options);
|
|
215
|
+
const query = (options.query ?? "").trim();
|
|
216
|
+
if (!query && !options.pathPrefix && !options.includeGlobs?.length)
|
|
217
|
+
return [];
|
|
218
|
+
const matcher = this.makeMatcher(query, options.regex === true, options.caseSensitive === true);
|
|
219
|
+
const hits = [];
|
|
220
|
+
for (const doc of docs) {
|
|
221
|
+
if (!query || matcher(doc.path)) {
|
|
222
|
+
hits.push({
|
|
223
|
+
path: doc.path,
|
|
224
|
+
source: "path",
|
|
225
|
+
score: this.pathScore(doc.path, query),
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return hits;
|
|
230
|
+
}
|
|
231
|
+
searchContent(options) {
|
|
232
|
+
const query = (options.query ?? "").trim();
|
|
233
|
+
if (!query)
|
|
234
|
+
return [];
|
|
235
|
+
const docs = this.queryDocuments(options, { forContent: true, query, regex: options.regex === true });
|
|
236
|
+
const matchLine = this.makeLineFinder(query, options.regex === true, options.caseSensitive === true, options.maxSnippetChars ?? 220);
|
|
237
|
+
const hits = [];
|
|
238
|
+
for (const doc of docs) {
|
|
239
|
+
const lineHit = matchLine(doc.content);
|
|
240
|
+
if (!lineHit)
|
|
241
|
+
continue;
|
|
242
|
+
hits.push({
|
|
243
|
+
path: doc.path,
|
|
244
|
+
line: lineHit.line,
|
|
245
|
+
column: lineHit.column,
|
|
246
|
+
snippet: lineHit.snippet,
|
|
247
|
+
source: "content",
|
|
248
|
+
score: lineHit.exact ? 95 : 78,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return hits;
|
|
252
|
+
}
|
|
253
|
+
searchSymbols(options) {
|
|
254
|
+
const query = (options.query ?? "").trim();
|
|
255
|
+
if (!query)
|
|
256
|
+
return [];
|
|
257
|
+
const conds = [];
|
|
258
|
+
const params = [];
|
|
259
|
+
if (options.pathPrefix) {
|
|
260
|
+
conds.push("f.rel_path LIKE ? ESCAPE '\\\\'");
|
|
261
|
+
params.push(`${escapeLike(this.normalizeRel(options.pathPrefix))}%`);
|
|
262
|
+
}
|
|
263
|
+
if (options.extensions && options.extensions.length > 0) {
|
|
264
|
+
conds.push(`f.ext IN (${options.extensions.map(() => "?").join(",")})`);
|
|
265
|
+
params.push(...options.extensions.map((ext) => normalizeExt(ext)));
|
|
266
|
+
}
|
|
267
|
+
if (options.symbolKinds && options.symbolKinds.length > 0) {
|
|
268
|
+
conds.push(`s.kind IN (${options.symbolKinds.map(() => "?").join(",")})`);
|
|
269
|
+
params.push(...options.symbolKinds);
|
|
270
|
+
}
|
|
271
|
+
let sql = "SELECT f.rel_path AS path, s.name AS name, s.kind AS kind, s.line AS line, s.column AS column, s.signature AS signature " +
|
|
272
|
+
"FROM symbols s JOIN files f ON f.id = s.file_id";
|
|
273
|
+
if (conds.length > 0)
|
|
274
|
+
sql += ` WHERE ${conds.join(" AND ")}`;
|
|
275
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
276
|
+
const matchName = this.makeMatcher(query, options.regex === true, options.caseSensitive === true);
|
|
277
|
+
const hits = [];
|
|
278
|
+
for (const row of rows) {
|
|
279
|
+
if (!this.applyGlobFilters(row.path, options))
|
|
280
|
+
continue;
|
|
281
|
+
if (!matchName(row.name))
|
|
282
|
+
continue;
|
|
283
|
+
hits.push({
|
|
284
|
+
path: row.path,
|
|
285
|
+
line: row.line,
|
|
286
|
+
column: row.column,
|
|
287
|
+
snippet: row.signature ?? undefined,
|
|
288
|
+
symbol: row.name,
|
|
289
|
+
kind: row.kind,
|
|
290
|
+
source: "symbol",
|
|
291
|
+
score: row.name === query ? 100 : 86,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return hits;
|
|
295
|
+
}
|
|
296
|
+
queryDocuments(filters, contentQuery) {
|
|
297
|
+
if (contentQuery && this.hasFts && !contentQuery.regex) {
|
|
298
|
+
const ftsQuery = toFtsQuery(contentQuery.query);
|
|
299
|
+
if (ftsQuery) {
|
|
300
|
+
try {
|
|
301
|
+
const rows = this.db
|
|
302
|
+
.prepare("SELECT f.id AS id, f.rel_path AS path, f.ext AS ext, f.content AS content " +
|
|
303
|
+
"FROM files_fts ft JOIN files f ON f.id = ft.rowid " +
|
|
304
|
+
"WHERE files_fts MATCH ? LIMIT 500")
|
|
305
|
+
.all(ftsQuery);
|
|
306
|
+
return rows.filter((row) => this.applyDocumentFilters(row.path, row.ext, filters));
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
// Fallback below.
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const conds = [];
|
|
314
|
+
const params = [];
|
|
315
|
+
if (filters.pathPrefix) {
|
|
316
|
+
conds.push("rel_path LIKE ? ESCAPE '\\\\'");
|
|
317
|
+
params.push(`${escapeLike(this.normalizeRel(filters.pathPrefix))}%`);
|
|
318
|
+
}
|
|
319
|
+
if (filters.extensions && filters.extensions.length > 0) {
|
|
320
|
+
conds.push(`ext IN (${filters.extensions.map(() => "?").join(",")})`);
|
|
321
|
+
params.push(...filters.extensions.map((ext) => normalizeExt(ext)));
|
|
322
|
+
}
|
|
323
|
+
let sql = "SELECT id, rel_path AS path, ext, content FROM files";
|
|
324
|
+
if (conds.length > 0)
|
|
325
|
+
sql += ` WHERE ${conds.join(" AND ")}`;
|
|
326
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
327
|
+
return rows.filter((row) => this.applyDocumentFilters(row.path, row.ext, filters));
|
|
328
|
+
}
|
|
329
|
+
applyDocumentFilters(filePath, ext, filters) {
|
|
330
|
+
if (filters.pathPrefix) {
|
|
331
|
+
const prefix = this.normalizeRel(filters.pathPrefix);
|
|
332
|
+
if (prefix && !filePath.startsWith(prefix))
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
if (filters.extensions && filters.extensions.length > 0) {
|
|
336
|
+
const normalized = new Set(filters.extensions.map((value) => normalizeExt(value)));
|
|
337
|
+
if (!normalized.has(ext))
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
return this.applyGlobFilters(filePath, filters);
|
|
341
|
+
}
|
|
342
|
+
makeMatcher(query, regex, caseSensitive) {
|
|
343
|
+
if (!query)
|
|
344
|
+
return () => true;
|
|
345
|
+
if (regex) {
|
|
346
|
+
const flags = caseSensitive ? "" : "i";
|
|
347
|
+
const re = new RegExp(query, flags);
|
|
348
|
+
return (value) => re.test(value);
|
|
349
|
+
}
|
|
350
|
+
const needle = caseSensitive ? query : query.toLowerCase();
|
|
351
|
+
return (value) => (caseSensitive ? value : value.toLowerCase()).includes(needle);
|
|
352
|
+
}
|
|
353
|
+
makeLineFinder(query, regex, caseSensitive, maxChars) {
|
|
354
|
+
if (regex) {
|
|
355
|
+
const flags = caseSensitive ? "" : "i";
|
|
356
|
+
const re = new RegExp(query, flags);
|
|
357
|
+
return (content) => {
|
|
358
|
+
const lines = content.split("\n");
|
|
359
|
+
for (let i = 0; i < lines.length; i++) {
|
|
360
|
+
const line = lines[i] ?? "";
|
|
361
|
+
re.lastIndex = 0;
|
|
362
|
+
const match = re.exec(line);
|
|
363
|
+
if (!match)
|
|
364
|
+
continue;
|
|
365
|
+
const snippet = trimSnippet(line, maxChars);
|
|
366
|
+
return { line: i + 1, column: (match.index ?? 0) + 1, snippet, exact: false };
|
|
367
|
+
}
|
|
368
|
+
return null;
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
const needle = caseSensitive ? query : query.toLowerCase();
|
|
372
|
+
return (content) => {
|
|
373
|
+
const lines = content.split("\n");
|
|
374
|
+
for (let i = 0; i < lines.length; i++) {
|
|
375
|
+
const line = lines[i] ?? "";
|
|
376
|
+
const hay = caseSensitive ? line : line.toLowerCase();
|
|
377
|
+
const idx = hay.indexOf(needle);
|
|
378
|
+
if (idx === -1)
|
|
379
|
+
continue;
|
|
380
|
+
const snippet = trimSnippet(line, maxChars);
|
|
381
|
+
return { line: i + 1, column: idx + 1, snippet, exact: line.includes(query) };
|
|
382
|
+
}
|
|
383
|
+
return null;
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
pathScore(filePath, query) {
|
|
387
|
+
if (!query)
|
|
388
|
+
return 55;
|
|
389
|
+
const lowerPath = filePath.toLowerCase();
|
|
390
|
+
const lowerQuery = query.toLowerCase();
|
|
391
|
+
if (lowerPath === lowerQuery)
|
|
392
|
+
return 98;
|
|
393
|
+
if (lowerPath.endsWith(`/${lowerQuery}`))
|
|
394
|
+
return 90;
|
|
395
|
+
if (lowerPath.includes(lowerQuery))
|
|
396
|
+
return 80;
|
|
397
|
+
return 60;
|
|
398
|
+
}
|
|
399
|
+
applyGlobFilters(filePath, filters) {
|
|
400
|
+
if (filters.includeHidden !== true) {
|
|
401
|
+
const segments = filePath.split("/");
|
|
402
|
+
if (segments.some((segment) => segment.startsWith(".")))
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
const includeGlobs = filters.includeGlobs ?? [];
|
|
406
|
+
if (includeGlobs.length > 0 && !includeGlobs.some((glob) => globMatch(glob, filePath))) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
const excludeGlobs = filters.excludeGlobs ?? [];
|
|
410
|
+
if (excludeGlobs.some((glob) => globMatch(glob, filePath))) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
createSchema() {
|
|
416
|
+
this.db.exec("CREATE TABLE IF NOT EXISTS files (" +
|
|
417
|
+
"id INTEGER PRIMARY KEY, " +
|
|
418
|
+
"rel_path TEXT NOT NULL UNIQUE, " +
|
|
419
|
+
"ext TEXT NOT NULL, " +
|
|
420
|
+
"mtime_ms INTEGER NOT NULL, " +
|
|
421
|
+
"size_bytes INTEGER NOT NULL, " +
|
|
422
|
+
"content TEXT NOT NULL" +
|
|
423
|
+
");");
|
|
424
|
+
this.db.exec("CREATE INDEX IF NOT EXISTS idx_files_ext ON files(ext);");
|
|
425
|
+
this.db.exec("CREATE INDEX IF NOT EXISTS idx_files_path ON files(rel_path);");
|
|
426
|
+
this.db.exec("CREATE TABLE IF NOT EXISTS symbols (" +
|
|
427
|
+
"id INTEGER PRIMARY KEY, " +
|
|
428
|
+
"file_id INTEGER NOT NULL, " +
|
|
429
|
+
"name TEXT NOT NULL, " +
|
|
430
|
+
"kind TEXT NOT NULL, " +
|
|
431
|
+
"line INTEGER NOT NULL, " +
|
|
432
|
+
"column INTEGER NOT NULL, " +
|
|
433
|
+
"signature TEXT, " +
|
|
434
|
+
"FOREIGN KEY(file_id) REFERENCES files(id) ON DELETE CASCADE" +
|
|
435
|
+
");");
|
|
436
|
+
this.db.exec("CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);");
|
|
437
|
+
this.db.exec("CREATE INDEX IF NOT EXISTS idx_symbols_kind ON symbols(kind);");
|
|
438
|
+
try {
|
|
439
|
+
this.db.exec("CREATE VIRTUAL TABLE IF NOT EXISTS files_fts USING fts5(rel_path, content, tokenize='unicode61');");
|
|
440
|
+
this.hasFts = true;
|
|
441
|
+
}
|
|
442
|
+
catch {
|
|
443
|
+
this.hasFts = false;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
clearIndex() {
|
|
447
|
+
this.db.exec("DELETE FROM symbols;");
|
|
448
|
+
this.db.exec("DELETE FROM files;");
|
|
449
|
+
if (this.hasFts)
|
|
450
|
+
this.db.exec("DELETE FROM files_fts;");
|
|
451
|
+
}
|
|
452
|
+
collectFiles(root) {
|
|
453
|
+
const out = [];
|
|
454
|
+
const walk = (dir) => {
|
|
455
|
+
let entries;
|
|
456
|
+
try {
|
|
457
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
458
|
+
}
|
|
459
|
+
catch {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
for (const entry of entries) {
|
|
463
|
+
const abs = path.join(dir, entry.name);
|
|
464
|
+
if (entry.isDirectory()) {
|
|
465
|
+
if (DEFAULT_SKIP_DIRS.has(entry.name))
|
|
466
|
+
continue;
|
|
467
|
+
walk(abs);
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
if (!entry.isFile())
|
|
471
|
+
continue;
|
|
472
|
+
out.push(abs);
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
walk(root);
|
|
476
|
+
return out;
|
|
477
|
+
}
|
|
478
|
+
isLikelyText(absPath) {
|
|
479
|
+
const ext = path.extname(absPath).toLowerCase();
|
|
480
|
+
if (DEFAULT_BINARY_EXTS.has(ext))
|
|
481
|
+
return false;
|
|
482
|
+
let fd = null;
|
|
483
|
+
try {
|
|
484
|
+
fd = fs.openSync(absPath, "r");
|
|
485
|
+
const sample = Buffer.allocUnsafe(1024);
|
|
486
|
+
const read = fs.readSync(fd, sample, 0, sample.length, 0);
|
|
487
|
+
for (let i = 0; i < read; i++) {
|
|
488
|
+
if (sample[i] === 0)
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
catch {
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
finally {
|
|
497
|
+
if (fd !== null) {
|
|
498
|
+
try {
|
|
499
|
+
fs.closeSync(fd);
|
|
500
|
+
}
|
|
501
|
+
catch { /* noop */ }
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
normalizeRel(p) {
|
|
506
|
+
const rel = path.isAbsolute(p) ? path.relative(this.rootDir, p) : p;
|
|
507
|
+
return rel.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
508
|
+
}
|
|
509
|
+
extractSymbols(content, ext) {
|
|
510
|
+
const language = languageFromExt(ext);
|
|
511
|
+
const rows = content.split("\n");
|
|
512
|
+
const out = [];
|
|
513
|
+
for (let i = 0; i < rows.length; i++) {
|
|
514
|
+
const line = rows[i] ?? "";
|
|
515
|
+
for (const pattern of SYMBOL_PATTERNS) {
|
|
516
|
+
if (!pattern.languages.includes(language))
|
|
517
|
+
continue;
|
|
518
|
+
pattern.regex.lastIndex = 0;
|
|
519
|
+
const match = pattern.regex.exec(line);
|
|
520
|
+
if (!match || !match[1])
|
|
521
|
+
continue;
|
|
522
|
+
const name = String(match[1]);
|
|
523
|
+
const column = (match.index ?? 0) + 1;
|
|
524
|
+
out.push({
|
|
525
|
+
name,
|
|
526
|
+
kind: pattern.kind,
|
|
527
|
+
line: i + 1,
|
|
528
|
+
column,
|
|
529
|
+
signature: line.trim().slice(0, 240),
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return out;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
exports.CodebaseIndex = CodebaseIndex;
|
|
537
|
+
function languageFromExt(ext) {
|
|
538
|
+
const normalized = ext.toLowerCase();
|
|
539
|
+
if (normalized === ".ts" || normalized === ".tsx" || normalized === ".mts" || normalized === ".cts")
|
|
540
|
+
return "ts";
|
|
541
|
+
if (normalized === ".js" || normalized === ".jsx" || normalized === ".mjs" || normalized === ".cjs")
|
|
542
|
+
return "js";
|
|
543
|
+
if (normalized === ".py")
|
|
544
|
+
return "python";
|
|
545
|
+
if (normalized === ".php" || normalized === ".phtml")
|
|
546
|
+
return "php";
|
|
547
|
+
if (normalized === ".go")
|
|
548
|
+
return "go";
|
|
549
|
+
if (normalized === ".java")
|
|
550
|
+
return "java";
|
|
551
|
+
if (normalized === ".cs")
|
|
552
|
+
return "csharp";
|
|
553
|
+
if (normalized === ".rs")
|
|
554
|
+
return "rust";
|
|
555
|
+
if (normalized === ".rb")
|
|
556
|
+
return "ruby";
|
|
557
|
+
return "other";
|
|
558
|
+
}
|
|
559
|
+
function normalizeExt(raw) {
|
|
560
|
+
if (!raw)
|
|
561
|
+
return raw;
|
|
562
|
+
return raw.startsWith(".") ? raw.toLowerCase() : `.${raw.toLowerCase()}`;
|
|
563
|
+
}
|
|
564
|
+
function escapeLike(value) {
|
|
565
|
+
return value.replace(/[\\%_]/g, "\\$&");
|
|
566
|
+
}
|
|
567
|
+
function trimSnippet(line, maxChars) {
|
|
568
|
+
const clean = line.trim();
|
|
569
|
+
if (clean.length <= maxChars)
|
|
570
|
+
return clean;
|
|
571
|
+
return `${clean.slice(0, Math.max(20, maxChars - 1))}...`;
|
|
572
|
+
}
|
|
573
|
+
function toFtsQuery(query) {
|
|
574
|
+
const tokens = query.toLowerCase().match(/[a-z0-9_]+/g);
|
|
575
|
+
if (!tokens || tokens.length === 0)
|
|
576
|
+
return null;
|
|
577
|
+
return tokens.map((token) => `${token}*`).join(" AND ");
|
|
578
|
+
}
|
|
579
|
+
function globMatch(glob, filePath) {
|
|
580
|
+
const normGlob = glob.replace(/\\/g, "/");
|
|
581
|
+
const normPath = filePath.replace(/\\/g, "/");
|
|
582
|
+
const escaped = normGlob
|
|
583
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
|
|
584
|
+
.replace(/\*\*/g, "@@DOUBLESTAR@@")
|
|
585
|
+
.replace(/\*/g, "[^/]*")
|
|
586
|
+
.replace(/@@DOUBLESTAR@@/g, ".*")
|
|
587
|
+
.replace(/\?/g, "[^/]");
|
|
588
|
+
try {
|
|
589
|
+
return new RegExp(`^${escaped}$`).test(normPath);
|
|
590
|
+
}
|
|
591
|
+
catch {
|
|
592
|
+
return normPath.includes(normGlob);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
//# sourceMappingURL=codebase-index.class.js.map
|