@side-quest/kit 0.1.0 → 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/CHANGELOG.md +20 -0
- package/README.md +54 -352
- package/dist/cli.d.ts +14 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +156 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -2509
- package/dist/index.js.map +1 -0
- package/dist/lib/ast/index.d.ts +11 -0
- package/dist/lib/ast/index.d.ts.map +1 -0
- package/dist/lib/ast/index.js +15 -0
- package/dist/lib/ast/index.js.map +1 -0
- package/dist/lib/ast/languages.d.ts +55 -0
- package/dist/lib/ast/languages.d.ts.map +1 -0
- package/dist/lib/ast/languages.js +146 -0
- package/dist/lib/ast/languages.js.map +1 -0
- package/dist/lib/ast/pattern.d.ts +84 -0
- package/dist/lib/ast/pattern.d.ts.map +1 -0
- package/dist/lib/ast/pattern.js +268 -0
- package/dist/lib/ast/pattern.js.map +1 -0
- package/dist/lib/ast/searcher.d.ts +89 -0
- package/dist/lib/ast/searcher.d.ts.map +1 -0
- package/dist/lib/ast/searcher.js +316 -0
- package/dist/lib/ast/searcher.js.map +1 -0
- package/dist/lib/ast/types.d.ts +93 -0
- package/dist/lib/ast/types.d.ts.map +1 -0
- package/dist/lib/ast/types.js +23 -0
- package/dist/lib/ast/types.js.map +1 -0
- package/dist/lib/commands/callers.d.ts +20 -0
- package/dist/lib/commands/callers.d.ts.map +1 -0
- package/dist/lib/commands/callers.js +162 -0
- package/dist/lib/commands/callers.js.map +1 -0
- package/dist/lib/commands/find.d.ts +15 -0
- package/dist/lib/commands/find.d.ts.map +1 -0
- package/dist/lib/commands/find.js +113 -0
- package/dist/lib/commands/find.js.map +1 -0
- package/dist/lib/commands/overview.d.ts +6 -0
- package/dist/lib/commands/overview.d.ts.map +1 -0
- package/dist/lib/commands/overview.js +52 -0
- package/dist/lib/commands/overview.js.map +1 -0
- package/dist/lib/commands/prime.d.ts +16 -0
- package/dist/lib/commands/prime.d.ts.map +1 -0
- package/dist/lib/commands/prime.js +168 -0
- package/dist/lib/commands/prime.js.map +1 -0
- package/dist/lib/commands/search.d.ts +20 -0
- package/dist/lib/commands/search.d.ts.map +1 -0
- package/dist/lib/commands/search.js +111 -0
- package/dist/lib/commands/search.js.map +1 -0
- package/dist/lib/errors.d.ts +80 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +189 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/formatters/output.d.ts +5 -0
- package/dist/lib/formatters/output.d.ts.map +1 -0
- package/dist/lib/formatters/output.js +5 -0
- package/dist/lib/formatters/output.js.map +1 -0
- package/dist/lib/formatters.d.ts +29 -0
- package/dist/lib/formatters.d.ts.map +1 -0
- package/dist/lib/formatters.js +141 -0
- package/dist/lib/formatters.js.map +1 -0
- package/dist/lib/index-tools.d.ts +108 -0
- package/dist/lib/index-tools.d.ts.map +1 -0
- package/dist/lib/index-tools.js +311 -0
- package/dist/lib/index-tools.js.map +1 -0
- package/dist/lib/index.d.ts +21 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +42 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/kit-wrapper.d.ts +70 -0
- package/dist/lib/kit-wrapper.d.ts.map +1 -0
- package/dist/lib/kit-wrapper.js +462 -0
- package/dist/lib/kit-wrapper.js.map +1 -0
- package/dist/lib/logger.d.ts +28 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +39 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/types.d.ts +179 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +48 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils/args.d.ts +40 -0
- package/dist/lib/utils/args.d.ts.map +1 -0
- package/dist/lib/utils/args.js +58 -0
- package/dist/lib/utils/args.js.map +1 -0
- package/dist/lib/utils/git.d.ts +23 -0
- package/dist/lib/utils/git.d.ts.map +1 -0
- package/dist/lib/utils/git.js +50 -0
- package/dist/lib/utils/git.js.map +1 -0
- package/dist/lib/utils/index-parser.d.ts +155 -0
- package/dist/lib/utils/index-parser.d.ts.map +1 -0
- package/dist/lib/utils/index-parser.js +252 -0
- package/dist/lib/utils/index-parser.js.map +1 -0
- package/dist/lib/validators.d.ts +138 -0
- package/dist/lib/validators.d.ts.map +1 -0
- package/dist/lib/validators.js +302 -0
- package/dist/lib/validators.js.map +1 -0
- package/dist/mcp/index.d.ts +19 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +769 -0
- package/dist/mcp/index.js.map +1 -0
- package/package.json +5 -2
- package/src/cli.ts +170 -0
- package/src/lib/ast/index.ts +32 -0
- package/src/lib/ast/languages.ts +172 -0
- package/src/lib/ast/pattern.ts +299 -0
- package/src/lib/ast/searcher.ts +381 -0
- package/src/lib/ast/types.ts +99 -0
- package/src/lib/commands/callers.ts +226 -0
- package/src/lib/commands/find.ts +159 -0
- package/src/lib/commands/overview.ts +73 -0
- package/src/lib/commands/prime.ts +271 -0
- package/src/lib/commands/search.ts +146 -0
- package/src/lib/errors.ts +221 -0
- package/src/lib/formatters/output.ts +9 -0
- package/src/lib/formatters.ts +189 -0
- package/src/lib/index-tools.ts +471 -0
- package/src/lib/index.ts +122 -0
- package/src/lib/kit-wrapper.ts +675 -0
- package/src/lib/logger.ts +57 -0
- package/src/lib/types.ts +228 -0
- package/src/lib/utils/args.ts +72 -0
- package/src/lib/utils/git.ts +65 -0
- package/src/lib/utils/index-parser.ts +350 -0
- package/src/lib/validators.ts +437 -0
- package/src/mcp/index.ts +144 -79
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PROJECT_INDEX.json based tools for token-efficient codebase queries
|
|
3
|
+
*
|
|
4
|
+
* These tools read from a pre-built index instead of scanning files,
|
|
5
|
+
* providing significant token savings for LLM workflows.
|
|
6
|
+
*/
|
|
7
|
+
export interface IndexFindResult {
|
|
8
|
+
query: string;
|
|
9
|
+
matchType: 'exact' | 'fuzzy';
|
|
10
|
+
count: number;
|
|
11
|
+
results: Array<{
|
|
12
|
+
file: string;
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
line: number;
|
|
16
|
+
code: string;
|
|
17
|
+
score?: number;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export interface IndexStatsResult {
|
|
21
|
+
files: number;
|
|
22
|
+
totalSymbols: number;
|
|
23
|
+
distribution: Record<string, number>;
|
|
24
|
+
hotspots: Array<{
|
|
25
|
+
directory: string;
|
|
26
|
+
symbolCount: number;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
export interface IndexOverviewResult {
|
|
30
|
+
file: string;
|
|
31
|
+
symbolCount: number;
|
|
32
|
+
symbols: Array<{
|
|
33
|
+
name: string;
|
|
34
|
+
type: string;
|
|
35
|
+
line: number;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export interface IndexError {
|
|
39
|
+
error: string;
|
|
40
|
+
isError: true;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Find symbol definitions from PROJECT_INDEX.json
|
|
44
|
+
*
|
|
45
|
+
* @param symbolName - Symbol name to search for
|
|
46
|
+
* @param indexPath - Optional path to index file or directory
|
|
47
|
+
* @returns Symbol search results
|
|
48
|
+
*/
|
|
49
|
+
export declare function executeIndexFind(symbolName: string, indexPath?: string): Promise<IndexFindResult | IndexError>;
|
|
50
|
+
/**
|
|
51
|
+
* Get codebase statistics from PROJECT_INDEX.json
|
|
52
|
+
*
|
|
53
|
+
* @param indexPath - Optional path to index file or directory
|
|
54
|
+
* @param topN - Number of top hotspots to return
|
|
55
|
+
* @returns Codebase statistics
|
|
56
|
+
*/
|
|
57
|
+
export declare function executeIndexStats(indexPath?: string, topN?: number): Promise<IndexStatsResult | IndexError>;
|
|
58
|
+
/**
|
|
59
|
+
* Get all symbols in a file from PROJECT_INDEX.json
|
|
60
|
+
*
|
|
61
|
+
* @param filePath - File path to get symbols for
|
|
62
|
+
* @param indexPath - Optional path to index file or directory
|
|
63
|
+
* @returns File symbols
|
|
64
|
+
*/
|
|
65
|
+
export declare function executeIndexOverview(filePath: string, indexPath?: string): Promise<IndexOverviewResult | IndexError>;
|
|
66
|
+
export interface IndexPrimeResult {
|
|
67
|
+
success: true;
|
|
68
|
+
location: string;
|
|
69
|
+
files: number;
|
|
70
|
+
symbols: number;
|
|
71
|
+
size: string;
|
|
72
|
+
durationSec: number;
|
|
73
|
+
}
|
|
74
|
+
export interface IndexPrimeExistsResult {
|
|
75
|
+
status: 'exists';
|
|
76
|
+
location: string;
|
|
77
|
+
ageHours: number;
|
|
78
|
+
files: number;
|
|
79
|
+
symbols: number;
|
|
80
|
+
size: string;
|
|
81
|
+
message: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Generate or refresh PROJECT_INDEX.json
|
|
85
|
+
*
|
|
86
|
+
* @param force - Force regenerate even if index is fresh
|
|
87
|
+
* @param customPath - Optional custom path to index
|
|
88
|
+
* @returns Prime result
|
|
89
|
+
*/
|
|
90
|
+
export declare function executeIndexPrime(force?: boolean, customPath?: string): Promise<IndexPrimeResult | IndexPrimeExistsResult | IndexError>;
|
|
91
|
+
import type { ResponseFormat } from './types.js';
|
|
92
|
+
/**
|
|
93
|
+
* Format index find results
|
|
94
|
+
*/
|
|
95
|
+
export declare function formatIndexFindResults(result: IndexFindResult | IndexError, format: ResponseFormat): string;
|
|
96
|
+
/**
|
|
97
|
+
* Format index stats results
|
|
98
|
+
*/
|
|
99
|
+
export declare function formatIndexStatsResults(result: IndexStatsResult | IndexError, format: ResponseFormat): string;
|
|
100
|
+
/**
|
|
101
|
+
* Format index overview results
|
|
102
|
+
*/
|
|
103
|
+
export declare function formatIndexOverviewResults(result: IndexOverviewResult | IndexError, format: ResponseFormat): string;
|
|
104
|
+
/**
|
|
105
|
+
* Format index prime results
|
|
106
|
+
*/
|
|
107
|
+
export declare function formatIndexPrimeResults(result: IndexPrimeResult | IndexPrimeExistsResult | IndexError, format: ResponseFormat): string;
|
|
108
|
+
//# sourceMappingURL=index-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-tools.d.ts","sourceRoot":"","sources":["../../src/lib/index-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,MAAM,WAAW,eAAe;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,OAAO,GAAG,OAAO,CAAA;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,CAAA;KACd,CAAC,CAAA;CACF;AAED,MAAM,WAAW,gBAAgB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,QAAQ,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC3D;AAED,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;KACZ,CAAC,CAAA;CACF;AAED,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,IAAI,CAAA;CACb;A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uBAAuB,CACtC,MAAM,EAAE,gBAAgB,GAAG,UAAU,EACrC,MAAM,EAAE,cAAc,GACpB,MAAM,CA4BR;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,mBAAmB,GAAG,UAAU,EACxC,MAAM,EAAE,cAAc,GACpB,MAAM,CAoCR;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,gBAAgB,GAAG,sBAAsB,GAAG,UAAU,EAC9D,MAAM,EAAE,cAAc,GACpB,MAAM,CAiCR"}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PROJECT_INDEX.json based tools for token-efficient codebase queries
|
|
3
|
+
*
|
|
4
|
+
* These tools read from a pre-built index instead of scanning files,
|
|
5
|
+
* providing significant token savings for LLM workflows.
|
|
6
|
+
*/
|
|
7
|
+
import { findSymbol, findSymbolFuzzy, getComplexityHotspots, getFileSymbols, getSymbolTypeDistribution, loadProjectIndex, } from './utils/index-parser';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Find Tool - Symbol lookup from index
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Find symbol definitions from PROJECT_INDEX.json
|
|
13
|
+
*
|
|
14
|
+
* @param symbolName - Symbol name to search for
|
|
15
|
+
* @param indexPath - Optional path to index file or directory
|
|
16
|
+
* @returns Symbol search results
|
|
17
|
+
*/
|
|
18
|
+
export async function executeIndexFind(symbolName, indexPath) {
|
|
19
|
+
try {
|
|
20
|
+
const index = await loadProjectIndex(indexPath);
|
|
21
|
+
// Try exact match first
|
|
22
|
+
let results = findSymbol(index, symbolName);
|
|
23
|
+
let matchType = 'exact';
|
|
24
|
+
// Fall back to fuzzy search if no exact match
|
|
25
|
+
if (results.length === 0) {
|
|
26
|
+
const fuzzyResults = findSymbolFuzzy(index, symbolName);
|
|
27
|
+
matchType = 'fuzzy';
|
|
28
|
+
results = fuzzyResults.map(({ file, symbol }) => ({ file, symbol }));
|
|
29
|
+
return {
|
|
30
|
+
query: symbolName,
|
|
31
|
+
matchType,
|
|
32
|
+
count: fuzzyResults.length,
|
|
33
|
+
results: fuzzyResults.map(({ file, symbol, score }) => ({
|
|
34
|
+
file,
|
|
35
|
+
name: symbol.name,
|
|
36
|
+
type: symbol.type,
|
|
37
|
+
line: symbol.start_line,
|
|
38
|
+
code: symbol.code,
|
|
39
|
+
score,
|
|
40
|
+
})),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
query: symbolName,
|
|
45
|
+
matchType,
|
|
46
|
+
count: results.length,
|
|
47
|
+
results: results.map(({ file, symbol }) => ({
|
|
48
|
+
file,
|
|
49
|
+
name: symbol.name,
|
|
50
|
+
type: symbol.type,
|
|
51
|
+
line: symbol.start_line,
|
|
52
|
+
code: symbol.code,
|
|
53
|
+
})),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
return {
|
|
58
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
59
|
+
isError: true,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// ============================================================================
|
|
64
|
+
// Stats Tool - Codebase metrics from index
|
|
65
|
+
// ============================================================================
|
|
66
|
+
/**
|
|
67
|
+
* Get codebase statistics from PROJECT_INDEX.json
|
|
68
|
+
*
|
|
69
|
+
* @param indexPath - Optional path to index file or directory
|
|
70
|
+
* @param topN - Number of top hotspots to return
|
|
71
|
+
* @returns Codebase statistics
|
|
72
|
+
*/
|
|
73
|
+
export async function executeIndexStats(indexPath, topN = 5) {
|
|
74
|
+
try {
|
|
75
|
+
const index = await loadProjectIndex(indexPath);
|
|
76
|
+
const distribution = getSymbolTypeDistribution(index);
|
|
77
|
+
const hotspots = getComplexityHotspots(index, topN);
|
|
78
|
+
const totalSymbols = Object.values(distribution).reduce((sum, count) => sum + count, 0);
|
|
79
|
+
return {
|
|
80
|
+
files: Object.keys(index.symbols).length,
|
|
81
|
+
totalSymbols,
|
|
82
|
+
distribution,
|
|
83
|
+
hotspots,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return {
|
|
88
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
89
|
+
isError: true,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// ============================================================================
|
|
94
|
+
// Overview Tool - File symbols from index
|
|
95
|
+
// ============================================================================
|
|
96
|
+
/**
|
|
97
|
+
* Get all symbols in a file from PROJECT_INDEX.json
|
|
98
|
+
*
|
|
99
|
+
* @param filePath - File path to get symbols for
|
|
100
|
+
* @param indexPath - Optional path to index file or directory
|
|
101
|
+
* @returns File symbols
|
|
102
|
+
*/
|
|
103
|
+
export async function executeIndexOverview(filePath, indexPath) {
|
|
104
|
+
try {
|
|
105
|
+
const index = await loadProjectIndex(indexPath);
|
|
106
|
+
const symbols = getFileSymbols(index, filePath);
|
|
107
|
+
return {
|
|
108
|
+
file: filePath,
|
|
109
|
+
symbolCount: symbols.length,
|
|
110
|
+
symbols: symbols.map((s) => ({
|
|
111
|
+
name: s.name,
|
|
112
|
+
type: s.type,
|
|
113
|
+
line: s.start_line,
|
|
114
|
+
})),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
return {
|
|
119
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
120
|
+
isError: true,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// ============================================================================
|
|
125
|
+
// Prime Tool - Generate/refresh index
|
|
126
|
+
// ============================================================================
|
|
127
|
+
import { join } from 'node:path';
|
|
128
|
+
import { getFileAgeHours, getFileSizeMB } from '@side-quest/core/fs';
|
|
129
|
+
import { ensureCommandAvailable, spawnWithTimeout, } from '@side-quest/core/spawn';
|
|
130
|
+
import { getTargetDir, INDEX_FILE, MAX_AGE_HOURS } from './utils/git.js';
|
|
131
|
+
/**
|
|
132
|
+
* Generate or refresh PROJECT_INDEX.json
|
|
133
|
+
*
|
|
134
|
+
* @param force - Force regenerate even if index is fresh
|
|
135
|
+
* @param customPath - Optional custom path to index
|
|
136
|
+
* @returns Prime result
|
|
137
|
+
*/
|
|
138
|
+
export async function executeIndexPrime(force = false, customPath) {
|
|
139
|
+
try {
|
|
140
|
+
const targetDir = await getTargetDir(customPath);
|
|
141
|
+
const kitCmd = ensureCommandAvailable('kit');
|
|
142
|
+
const indexPath = join(targetDir, INDEX_FILE);
|
|
143
|
+
// Check if index exists and is fresh
|
|
144
|
+
const ageHours = getFileAgeHours(indexPath);
|
|
145
|
+
if (ageHours !== null && ageHours <= MAX_AGE_HOURS && !force) {
|
|
146
|
+
const index = await loadProjectIndex(indexPath);
|
|
147
|
+
const symbolCount = Object.values(index.symbols).reduce((sum, symbols) => sum + symbols.length, 0);
|
|
148
|
+
const sizeMB = getFileSizeMB(indexPath);
|
|
149
|
+
return {
|
|
150
|
+
status: 'exists',
|
|
151
|
+
location: targetDir,
|
|
152
|
+
ageHours: Number.parseFloat(ageHours.toFixed(1)),
|
|
153
|
+
files: Object.keys(index.symbols).length,
|
|
154
|
+
symbols: symbolCount,
|
|
155
|
+
size: `${sizeMB} MB`,
|
|
156
|
+
message: 'Index is less than 24 hours old. Use force=true to regenerate.',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
// Generate new index
|
|
160
|
+
const startTime = Date.now();
|
|
161
|
+
const result = await spawnWithTimeout([kitCmd, 'index', targetDir, '-o', indexPath], 60_000);
|
|
162
|
+
if (result.timedOut) {
|
|
163
|
+
return {
|
|
164
|
+
error: 'kit index timed out',
|
|
165
|
+
isError: true,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
if (result.exitCode !== 0) {
|
|
169
|
+
return {
|
|
170
|
+
error: `kit index failed: ${result.stderr}`,
|
|
171
|
+
isError: true,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const durationSec = (Date.now() - startTime) / 1000;
|
|
175
|
+
// Parse generated index
|
|
176
|
+
const index = await loadProjectIndex(indexPath);
|
|
177
|
+
const symbolCount = Object.values(index.symbols).reduce((sum, symbols) => sum + symbols.length, 0);
|
|
178
|
+
const sizeMB = getFileSizeMB(indexPath);
|
|
179
|
+
return {
|
|
180
|
+
success: true,
|
|
181
|
+
location: targetDir,
|
|
182
|
+
files: Object.keys(index.symbols).length,
|
|
183
|
+
symbols: symbolCount,
|
|
184
|
+
size: `${sizeMB} MB`,
|
|
185
|
+
durationSec: Number.parseFloat(durationSec.toFixed(1)),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
return {
|
|
190
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
191
|
+
isError: true,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Format index find results
|
|
197
|
+
*/
|
|
198
|
+
export function formatIndexFindResults(result, format) {
|
|
199
|
+
if ('isError' in result) {
|
|
200
|
+
return format === 'json'
|
|
201
|
+
? JSON.stringify(result, null, 2)
|
|
202
|
+
: `**Error:** ${result.error}`;
|
|
203
|
+
}
|
|
204
|
+
if (format === 'json') {
|
|
205
|
+
return JSON.stringify(result, null, 2);
|
|
206
|
+
}
|
|
207
|
+
if (result.count === 0) {
|
|
208
|
+
return `No symbols found matching: ${result.query}`;
|
|
209
|
+
}
|
|
210
|
+
let output = `Found ${result.count} ${result.matchType} match(es) for "${result.query}":\n\n`;
|
|
211
|
+
for (const r of result.results) {
|
|
212
|
+
output += `- **${r.name}** (${r.type}) in \`${r.file}:${r.line}\``;
|
|
213
|
+
if (r.score !== undefined) {
|
|
214
|
+
output += ` [score: ${r.score}]`;
|
|
215
|
+
}
|
|
216
|
+
output += '\n';
|
|
217
|
+
}
|
|
218
|
+
return output;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Format index stats results
|
|
222
|
+
*/
|
|
223
|
+
export function formatIndexStatsResults(result, format) {
|
|
224
|
+
if ('isError' in result) {
|
|
225
|
+
return format === 'json'
|
|
226
|
+
? JSON.stringify(result, null, 2)
|
|
227
|
+
: `**Error:** ${result.error}`;
|
|
228
|
+
}
|
|
229
|
+
if (format === 'json') {
|
|
230
|
+
return JSON.stringify(result, null, 2);
|
|
231
|
+
}
|
|
232
|
+
let output = `## Codebase Statistics\n\n`;
|
|
233
|
+
output += `- **Files:** ${result.files}\n`;
|
|
234
|
+
output += `- **Total Symbols:** ${result.totalSymbols}\n\n`;
|
|
235
|
+
output += `### Symbol Distribution\n`;
|
|
236
|
+
for (const [type, count] of Object.entries(result.distribution)) {
|
|
237
|
+
if (count > 0) {
|
|
238
|
+
output += `- ${type}: ${count}\n`;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
output += `\n### Complexity Hotspots\n`;
|
|
242
|
+
for (const { directory, symbolCount } of result.hotspots) {
|
|
243
|
+
output += `- \`${directory}\`: ${symbolCount} symbols\n`;
|
|
244
|
+
}
|
|
245
|
+
return output;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Format index overview results
|
|
249
|
+
*/
|
|
250
|
+
export function formatIndexOverviewResults(result, format) {
|
|
251
|
+
if ('isError' in result) {
|
|
252
|
+
return format === 'json'
|
|
253
|
+
? JSON.stringify(result, null, 2)
|
|
254
|
+
: `**Error:** ${result.error}`;
|
|
255
|
+
}
|
|
256
|
+
if (format === 'json') {
|
|
257
|
+
return JSON.stringify(result, null, 2);
|
|
258
|
+
}
|
|
259
|
+
if (result.symbolCount === 0) {
|
|
260
|
+
return `No symbols found in: ${result.file}`;
|
|
261
|
+
}
|
|
262
|
+
let output = `## ${result.file}\n\n`;
|
|
263
|
+
output += `**${result.symbolCount} symbol(s)**\n\n`;
|
|
264
|
+
// Group by type
|
|
265
|
+
const byType = {};
|
|
266
|
+
for (const sym of result.symbols) {
|
|
267
|
+
if (!byType[sym.type]) {
|
|
268
|
+
byType[sym.type] = [];
|
|
269
|
+
}
|
|
270
|
+
byType[sym.type].push(sym);
|
|
271
|
+
}
|
|
272
|
+
for (const [type, symbols] of Object.entries(byType)) {
|
|
273
|
+
output += `### ${type}s\n`;
|
|
274
|
+
for (const sym of symbols) {
|
|
275
|
+
output += `- \`${sym.name}\` (line ${sym.line})\n`;
|
|
276
|
+
}
|
|
277
|
+
output += '\n';
|
|
278
|
+
}
|
|
279
|
+
return output;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Format index prime results
|
|
283
|
+
*/
|
|
284
|
+
export function formatIndexPrimeResults(result, format) {
|
|
285
|
+
if ('isError' in result) {
|
|
286
|
+
return format === 'json'
|
|
287
|
+
? JSON.stringify(result, null, 2)
|
|
288
|
+
: `**Error:** ${result.error}`;
|
|
289
|
+
}
|
|
290
|
+
if (format === 'json') {
|
|
291
|
+
return JSON.stringify(result, null, 2);
|
|
292
|
+
}
|
|
293
|
+
if ('status' in result && result.status === 'exists') {
|
|
294
|
+
return (`## Index Already Exists\n\n` +
|
|
295
|
+
`- **Location:** ${result.location}\n` +
|
|
296
|
+
`- **Age:** ${result.ageHours} hours\n` +
|
|
297
|
+
`- **Files:** ${result.files}\n` +
|
|
298
|
+
`- **Symbols:** ${result.symbols}\n` +
|
|
299
|
+
`- **Size:** ${result.size}\n\n` +
|
|
300
|
+
`> ${result.message}`);
|
|
301
|
+
}
|
|
302
|
+
// TypeScript narrowing: at this point result is IndexPrimeResult
|
|
303
|
+
const primeResult = result;
|
|
304
|
+
return (`## Index Generated Successfully\n\n` +
|
|
305
|
+
`- **Location:** ${primeResult.location}\n` +
|
|
306
|
+
`- **Files:** ${primeResult.files}\n` +
|
|
307
|
+
`- **Symbols:** ${primeResult.symbols}\n` +
|
|
308
|
+
`- **Size:** ${primeResult.size}\n` +
|
|
309
|
+
`- **Duration:** ${primeResult.durationSec}s`);
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=index-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YACjC,CAAC,CAAC,cAAc,MAAM,CAAC,KAAK,EAAE,CAAA;IAChC,CAAC;IAED,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACvC,CAAC;IAED,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACtD,OAAO,CACN,6BAA6B;YAC7B,mBAAmB,MAAM,CAAC,QAAQ,IAAI;YACtC,cAAc,MAAM,CAAC,QAAQ,UAAU;YACvC,gBAAgB,MAAM,CAAC,KAAK,IAAI;YAChC,kBAAkB,MAAM,CAAC,OAAO,IAAI;YACpC,eAAe,MAAM,CAAC,IAAI,MAAM;YAChC,KAAK,MAAM,CAAC,OAAO,EAAE,CACrB,CAAA;IACF,CAAC;IAED,iEAAiE;IACjE,MAAM,WAAW,GAAG,MAA0B,CAAA;IAC9C,OAAO,CACN,qCAAqC;QACrC,mBAAmB,WAAW,CAAC,QAAQ,IAAI;QAC3C,gBAAgB,WAAW,CAAC,KAAK,IAAI;QACrC,kBAAkB,WAAW,CAAC,OAAO,IAAI;QACzC,eAAe,WAAW,CAAC,IAAI,IAAI;QACnC,mBAAmB,WAAW,CAAC,WAAW,GAAG,CAC7C,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kit Plugin
|
|
3
|
+
*
|
|
4
|
+
* MCP server integrating Kit CLI for semantic search,
|
|
5
|
+
* symbol usages, and AST search. Provides intelligent code search
|
|
6
|
+
* capabilities for the Obsidian vault and other codebases.
|
|
7
|
+
*/
|
|
8
|
+
export type { SupportedLanguage } from './ast/languages.js';
|
|
9
|
+
export type { ASTMatch, ASTMatchContext, ASTSearchOptions, ASTSearchResult, PatternCriteria, } from './ast/types.js';
|
|
10
|
+
export { SearchMode } from './ast/types.js';
|
|
11
|
+
export type { ErrorResult, GrepMatch, GrepOptions, GrepResult, KitResult, SemanticMatch, SemanticOptions, SemanticResult, SymbolUsage, UsagesOptions, UsagesResult, } from './types.js';
|
|
12
|
+
export { isError, ResponseFormat } from './types.js';
|
|
13
|
+
export { detectErrorType, KitError, KitErrorType } from './errors.js';
|
|
14
|
+
export { executeAstSearch, executeKitGrep, executeKitSemantic, executeKitUsages, getKitVersion, isKitInstalled, } from './kit-wrapper.js';
|
|
15
|
+
export { executeIndexFind, executeIndexOverview, executeIndexPrime, formatIndexFindResults, formatIndexOverviewResults, formatIndexPrimeResults, type IndexError, type IndexFindResult, type IndexOverviewResult, type IndexPrimeExistsResult, type IndexPrimeResult, type IndexStatsResult, } from './index-tools.js';
|
|
16
|
+
export { ASTPattern, ASTSearcher, detectLanguage, getParser, getSupportedGlob, initParser, isSupported, LANGUAGES, SUPPORTED_LANGUAGES, } from './ast/index.js';
|
|
17
|
+
export { validateAstSearchInputs, validatePath, validateSemanticInputs, validateUsagesInputs, } from './validators.js';
|
|
18
|
+
export { formatError, formatSemanticResults, formatUsagesResults, } from './formatters.js';
|
|
19
|
+
export { createCorrelationId, initLogger, logger } from './logger.js';
|
|
20
|
+
export { findGitRoot, findGitRootSync, getTargetDir } from './utils/git.js';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,YAAY,EACX,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,eAAe,GACf,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,YAAY,EACX,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,aAAa,EACb,eAAe,EACf,cAAc,EACd,WAAW,EACX,aAAa,EACb,YAAY,GACZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMpD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAMrE,OAAO,EACN,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,cAAc,GACd,MAAM,kBAAkB,CAAA;AAMzB,OAAO,EACN,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACrB,MAAM,kBAAkB,CAAA;AAMzB,OAAO,EACN,UAAU,EACV,WAAW,EACX,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,SAAS,EACT,mBAAmB,GACnB,MAAM,gBAAgB,CAAA;AAMvB,OAAO,EACN,uBAAuB,EACvB,YAAY,EACZ,sBAAsB,EACtB,oBAAoB,GACpB,MAAM,iBAAiB,CAAA;AAMxB,OAAO,EACN,WAAW,EACX,qBAAqB,EACrB,mBAAmB,GACnB,MAAM,iBAAiB,CAAA;AAMxB,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAMrE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kit Plugin
|
|
3
|
+
*
|
|
4
|
+
* MCP server integrating Kit CLI for semantic search,
|
|
5
|
+
* symbol usages, and AST search. Provides intelligent code search
|
|
6
|
+
* capabilities for the Obsidian vault and other codebases.
|
|
7
|
+
*/
|
|
8
|
+
export { SearchMode } from './ast/types.js';
|
|
9
|
+
export { isError, ResponseFormat } from './types.js';
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Errors
|
|
12
|
+
// ============================================================================
|
|
13
|
+
export { detectErrorType, KitError, KitErrorType } from './errors.js';
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Functions - Kit Wrapper
|
|
16
|
+
// ============================================================================
|
|
17
|
+
export { executeAstSearch, executeKitGrep, executeKitSemantic, executeKitUsages, getKitVersion, isKitInstalled, } from './kit-wrapper.js';
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Functions - Index Tools
|
|
20
|
+
// ============================================================================
|
|
21
|
+
export { executeIndexFind, executeIndexOverview, executeIndexPrime, formatIndexFindResults, formatIndexOverviewResults, formatIndexPrimeResults, } from './index-tools.js';
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// Functions - AST Search
|
|
24
|
+
// ============================================================================
|
|
25
|
+
export { ASTPattern, ASTSearcher, detectLanguage, getParser, getSupportedGlob, initParser, isSupported, LANGUAGES, SUPPORTED_LANGUAGES, } from './ast/index.js';
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// Validators
|
|
28
|
+
// ============================================================================
|
|
29
|
+
export { validateAstSearchInputs, validatePath, validateSemanticInputs, validateUsagesInputs, } from './validators.js';
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// Formatters
|
|
32
|
+
// ============================================================================
|
|
33
|
+
export { formatError, formatSemanticResults, formatUsagesResults, } from './formatters.js';
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// Logger
|
|
36
|
+
// ============================================================================
|
|
37
|
+
export { createCorrelationId, initLogger, logger } from './logger.js';
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// Utils
|
|
40
|
+
// ============================================================================
|
|
41
|
+
export { findGitRoot, findGitRootSync, getTargetDir } from './utils/git.js';
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
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AAA;AAErE,+EAA+E;AAC/E,QAAQ;AACR,+EAA+E;AAE/E,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kit CLI Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for executing Kit CLI commands with proper error handling.
|
|
5
|
+
* Uses Bun.spawnSync via shared helpers for synchronous execution to fit MCP tool patterns.
|
|
6
|
+
*/
|
|
7
|
+
import { type ASTSearchOptions, type ASTSearchResult } from './ast/index.js';
|
|
8
|
+
import type { GrepOptions, GrepResult, KitResult, SemanticOptions, SemanticResult, UsagesOptions, UsagesResult } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Check if Kit CLI is installed and available in PATH.
|
|
11
|
+
* @returns True if kit command is available
|
|
12
|
+
*/
|
|
13
|
+
export declare function isKitInstalled(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Get Kit CLI version.
|
|
16
|
+
* @returns Version string or null if not installed
|
|
17
|
+
*/
|
|
18
|
+
export declare function getKitVersion(): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Execute kit grep command.
|
|
21
|
+
* @param options - Grep options
|
|
22
|
+
* @returns Grep result or error
|
|
23
|
+
*/
|
|
24
|
+
export declare function executeKitGrep(options: GrepOptions): KitResult<GrepResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Execute kit semantic search command.
|
|
27
|
+
* @param options - Semantic search options
|
|
28
|
+
* @returns Semantic result or error (with fallback to grep)
|
|
29
|
+
*/
|
|
30
|
+
export declare function executeKitSemantic(options: SemanticOptions): KitResult<SemanticResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Execute kit usages command to find symbol definitions.
|
|
33
|
+
* @param options - Usages options
|
|
34
|
+
* @returns Usages result or error
|
|
35
|
+
*/
|
|
36
|
+
export declare function executeKitUsages(options: UsagesOptions): KitResult<UsagesResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Execute AST-based code search using tree-sitter.
|
|
39
|
+
*
|
|
40
|
+
* Unlike other Kit commands, this uses an internal tree-sitter
|
|
41
|
+
* implementation rather than shelling out to the Kit CLI.
|
|
42
|
+
*
|
|
43
|
+
* @param options - AST search options
|
|
44
|
+
* @returns AST search result or error
|
|
45
|
+
*/
|
|
46
|
+
export declare function executeAstSearch(options: ASTSearchOptions): Promise<KitResult<ASTSearchResult>>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the persist directory for a repo's semantic search vector index.
|
|
49
|
+
* Creates the directory if it doesn't exist.
|
|
50
|
+
*
|
|
51
|
+
* Per-repo caching strategy: Each repository gets its own .kit/vector_db/
|
|
52
|
+
* directory for isolated, portable vector indexes. This ensures:
|
|
53
|
+
* - Cache is scoped to the repo being searched
|
|
54
|
+
* - No cross-contamination between different repos
|
|
55
|
+
* - Cache travels with the repo context in Claude Code sessions
|
|
56
|
+
* - Easy cleanup (delete .kit/ when done with project)
|
|
57
|
+
*
|
|
58
|
+
* Structure: <repo-path>/.kit/vector_db/
|
|
59
|
+
*
|
|
60
|
+
* @param repoPath - Absolute path to the repository
|
|
61
|
+
* @returns Path to the persist directory for this repo's vector index
|
|
62
|
+
*/
|
|
63
|
+
export declare function getSemanticCacheDir(repoPath: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Check if semantic search vector index has been built for a repository.
|
|
66
|
+
* @param repoPath - Path to the repository
|
|
67
|
+
* @returns True if vector index exists and has been built
|
|
68
|
+
*/
|
|
69
|
+
export declare function isSemanticIndexBuilt(repoPath: string): boolean;
|
|
70
|
+
//# sourceMappingURL=kit-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kit-wrapper.d.ts","sourceRoot":"","sources":["../../src/lib/kit-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,OAAO,EAGN,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,MAAM,gBAAgB,CAAA;AAgBvB,OAAO,KAAK,EAEX,WAAW,EACX,UAAU,EACV,SAAS,EAET,eAAe,EACf,cAAc,EAEd,aAAa,EACb,YAAY,EACZ,MAAM,YAAY,CAAA;AAYnB;;;GAGG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAOxC;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,IAAI,CAe7C;AA6CD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC,UAAU,CAAC,CAmG1E;AAmBD;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,eAAe,GACtB,SAAS,CAAC,cAAc,CAAC,CAqJ3B;AAmED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,aAAa,GACpB,SAAS,CAAC,YAAY,CAAC,CAsFzB;AAMD;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACrC,OAAO,EAAE,gBAAgB,GACvB,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CA2CrC;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAG9D"}
|