@side-quest/kit 0.0.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 +36 -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,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic search command - Natural language code search
|
|
3
|
+
*
|
|
4
|
+
* Uses kit semantic search to find code by meaning rather than exact text.
|
|
5
|
+
* Gracefully falls back to grep if ML dependencies unavailable.
|
|
6
|
+
*/
|
|
7
|
+
import { color, OutputFormat } from '../formatters/output';
|
|
8
|
+
import { executeKitSemantic } from '../kit-wrapper';
|
|
9
|
+
/**
|
|
10
|
+
* Execute semantic search command
|
|
11
|
+
*
|
|
12
|
+
* Performs natural language search over codebase using vector embeddings.
|
|
13
|
+
* Shows warning with install instructions if semantic unavailable.
|
|
14
|
+
*
|
|
15
|
+
* @param query - Natural language search query
|
|
16
|
+
* @param options - Search options (path, topK, chunkBy, buildIndex)
|
|
17
|
+
* @param format - Output format (markdown or JSON)
|
|
18
|
+
*/
|
|
19
|
+
export async function executeSearch(query, options, format) {
|
|
20
|
+
try {
|
|
21
|
+
// Execute semantic search
|
|
22
|
+
const result = executeKitSemantic({ query, ...options });
|
|
23
|
+
// Handle errors
|
|
24
|
+
if ('error' in result) {
|
|
25
|
+
if (format === OutputFormat.JSON) {
|
|
26
|
+
console.error(JSON.stringify({
|
|
27
|
+
error: result.error,
|
|
28
|
+
query,
|
|
29
|
+
isError: true,
|
|
30
|
+
}, null, 2));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
console.error(color('red', '\n❌ Error:'), result.error, '\n');
|
|
34
|
+
// Show install hint if semantic unavailable
|
|
35
|
+
if ('hint' in result && result.hint) {
|
|
36
|
+
console.error(color('yellow', '💡 Tip:'), result.hint, '\n');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
// Show fallback warning if grep was used
|
|
42
|
+
if (result.fallback && format === OutputFormat.MARKDOWN) {
|
|
43
|
+
console.log(color('yellow', '\n⚠️ Semantic search unavailable - using grep fallback\n'));
|
|
44
|
+
if (result.installHint) {
|
|
45
|
+
console.log(color('dim', result.installHint), '\n');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Output results
|
|
49
|
+
if (format === OutputFormat.JSON) {
|
|
50
|
+
console.log(JSON.stringify(result, null, 2));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.log(formatMarkdown(result));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (format === OutputFormat.JSON) {
|
|
58
|
+
console.error(JSON.stringify({
|
|
59
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
60
|
+
query,
|
|
61
|
+
isError: true,
|
|
62
|
+
}, null, 2));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
console.error(color('red', '\n❌ Error:'), error instanceof Error ? error.message : error, '\n');
|
|
66
|
+
}
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Format semantic results as markdown
|
|
72
|
+
*/
|
|
73
|
+
function formatMarkdown(result) {
|
|
74
|
+
const { query, count, matches, fallback } = result;
|
|
75
|
+
if (count === 0) {
|
|
76
|
+
return color('yellow', `\n⚠️ No matches found for query: "${query}"\n`);
|
|
77
|
+
}
|
|
78
|
+
let output = color('cyan', `\n🔍 Found ${count} semantic match(es) for: `);
|
|
79
|
+
output += color('blue', `"${query}"`);
|
|
80
|
+
if (fallback) {
|
|
81
|
+
output += color('dim', ' (grep fallback)');
|
|
82
|
+
}
|
|
83
|
+
output += '\n\n';
|
|
84
|
+
// Group by file
|
|
85
|
+
const byFile = new Map();
|
|
86
|
+
for (const match of matches) {
|
|
87
|
+
if (!byFile.has(match.file)) {
|
|
88
|
+
byFile.set(match.file, []);
|
|
89
|
+
}
|
|
90
|
+
byFile.get(match.file)?.push(match);
|
|
91
|
+
}
|
|
92
|
+
// Output each file's matches
|
|
93
|
+
for (const [file, fileMatches] of byFile.entries()) {
|
|
94
|
+
output += color('dim', `${file}:\n`);
|
|
95
|
+
for (const match of fileMatches) {
|
|
96
|
+
const lineInfo = match.startLine
|
|
97
|
+
? `L${match.startLine}${match.endLine ? `-${match.endLine}` : ''}`
|
|
98
|
+
: '';
|
|
99
|
+
const scoreStr = `(${(match.score * 100).toFixed(1)}%)`;
|
|
100
|
+
output += ` ${color('dim', lineInfo)} ${color('green', scoreStr)}\n`;
|
|
101
|
+
// Show chunk preview (first 2 lines max)
|
|
102
|
+
const lines = match.chunk.split('\n').slice(0, 2);
|
|
103
|
+
for (const line of lines) {
|
|
104
|
+
output += ` ${color('dim', line.trim())}\n`;
|
|
105
|
+
}
|
|
106
|
+
output += '\n';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return output;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../../src/lib/commands/search.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,KAAa,EACb,OAAuC,EACvC,MAAoB;IAEpB,IAAI,CAAC;QACJ,0BAA0B;QAC1B,MAAM,MAAM,GAAG,kBAAkB,CAAC,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;QAExD,gBAAgB;QAChB,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;YACvB,IAAI,MAAM,KAAK,YAAY,CAAC,IAAI,EAAE,CAAC;gBAClC,OAAO,CAAC,KAAK,CACZ,IAAI,CAAC,SAAS,CACb;oBACC,KAAK,EAAE,MAAM,CAAC,KAAK;oBACnB,KAAK;oBACL,OAAO,EAAE,IAAI;iBACb,EACD,IAAI,EACJ,CAAC,CACD,CACD,CAAA;YACF,CAAC;iBAAM,CAAC;gBACP,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;gBAE7D,4CAA4C;gBAC5C,IAAI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AAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,KAAK,EAAE,GAAG,IAAI,KAAK,CAAC,CAAA;QACpC,KAAK,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;YACjC,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS;gBAC/B,CAAC,CAAC,IAAI,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;gBAClE,CAAC,CAAC,EAAE,CAAA;YACL,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA;YAEvD,MAAM,IAAI,KAAK,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAA;YAErE,yCAAyC;YACzC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YACjD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBAC1B,MAAM,IAAI,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,CAAA;YAC/C,CAAC;YACD,MAAM,IAAI,IAAI,CAAA;QACf,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kit Plugin Error Taxonomy
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive error handling with clear recovery instructions.
|
|
5
|
+
*/
|
|
6
|
+
import { isTimeoutOutput, PluginError } from '@side-quest/core/instrumentation';
|
|
7
|
+
/**
|
|
8
|
+
* Kit error types with associated recovery strategies.
|
|
9
|
+
*/
|
|
10
|
+
export declare enum KitErrorType {
|
|
11
|
+
/** Kit CLI not found in PATH */
|
|
12
|
+
KitNotInstalled = "KitNotInstalled",
|
|
13
|
+
/** Invalid repository path */
|
|
14
|
+
InvalidPath = "InvalidPath",
|
|
15
|
+
/** Invalid input (regex, glob, etc.) */
|
|
16
|
+
InvalidInput = "InvalidInput",
|
|
17
|
+
/** Semantic search not available (missing ML deps) */
|
|
18
|
+
SemanticNotAvailable = "SemanticNotAvailable",
|
|
19
|
+
/** Semantic search index not yet built for repository */
|
|
20
|
+
SemanticIndexNotBuilt = "SemanticIndexNotBuilt",
|
|
21
|
+
/** Too many results returned */
|
|
22
|
+
TooManyResults = "TooManyResults",
|
|
23
|
+
/** Kit command failed */
|
|
24
|
+
KitCommandFailed = "KitCommandFailed",
|
|
25
|
+
/** Failed to parse Kit output */
|
|
26
|
+
OutputParseError = "OutputParseError",
|
|
27
|
+
/** Operation timed out */
|
|
28
|
+
Timeout = "Timeout"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* User-facing error messages with recovery hints.
|
|
32
|
+
*/
|
|
33
|
+
export declare const ERROR_MESSAGES: Record<KitErrorType, {
|
|
34
|
+
message: string;
|
|
35
|
+
hint: string;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Custom error class for Kit operations.
|
|
39
|
+
*
|
|
40
|
+
* Extends PluginError to provide Kit-specific error handling with:
|
|
41
|
+
* - Typed error classification (KitErrorType enum)
|
|
42
|
+
* - User-friendly messages with recovery hints
|
|
43
|
+
* - Structured JSON serialization for MCP responses
|
|
44
|
+
*/
|
|
45
|
+
export declare class KitError extends PluginError<KitErrorType> {
|
|
46
|
+
constructor(type: KitErrorType, details?: string, stderr?: string);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Install hint shown when semantic search is unavailable.
|
|
50
|
+
*/
|
|
51
|
+
export declare const SEMANTIC_INSTALL_HINT: string;
|
|
52
|
+
/**
|
|
53
|
+
* Check if an error indicates semantic search is unavailable.
|
|
54
|
+
* @param stderr - Standard error output from Kit
|
|
55
|
+
*/
|
|
56
|
+
export declare function isSemanticUnavailableError(stderr: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Check if an error indicates a timeout occurred.
|
|
59
|
+
*
|
|
60
|
+
* Re-exports the core utility for backward compatibility.
|
|
61
|
+
*
|
|
62
|
+
* @param stderr - Standard error output
|
|
63
|
+
*/
|
|
64
|
+
export declare const isTimeoutError: typeof isTimeoutOutput;
|
|
65
|
+
/**
|
|
66
|
+
* Detect error type from Kit stderr output.
|
|
67
|
+
*
|
|
68
|
+
* Uses the generic core pattern matcher with Kit-specific patterns.
|
|
69
|
+
*
|
|
70
|
+
* @param stderr - Standard error output from Kit
|
|
71
|
+
* @param _exitCode - Exit code from Kit process (currently unused)
|
|
72
|
+
*/
|
|
73
|
+
export declare function detectErrorType(stderr: string, _exitCode: number): KitErrorType;
|
|
74
|
+
/**
|
|
75
|
+
* Create a KitError from process output.
|
|
76
|
+
* @param stderr - Standard error output
|
|
77
|
+
* @param exitCode - Process exit code
|
|
78
|
+
*/
|
|
79
|
+
export declare function createErrorFromOutput(stderr: string, exitCode: number): KitError;
|
|
80
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAGN,eAAe,EACf,WAAW,EACX,MAAM,kCAAkC,CAAA;AAMzC;;GAEG;AACH,oBAAY,YAAY;IACvB,gCAAgC;IAChC,eAAe,oBAAoB;IACnC,8BAA8B;IAC9B,WAAW,gBAAgB;IAC3B,wCAAwC;IACxC,YAAY,iBAAiB;IAC7B,sDAAsD;IACtD,oBAAoB,yBAAyB;IAC7C,yDAAyD;IACzD,qBAAqB,0BAA0B;IAC/C,gCAAgC;IAChC,cAAc,mBAAmB;IACjC,yBAAyB;IACzB,gBAAgB,qBAAqB;IACrC,iCAAiC;IACjC,gBAAgB,qBAAqB;IACrC,0BAA0B;IAC1B,OAAO,YAAY;CACnB;AAMD;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAClC,YAAY,EACZ;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAuCjC,CAAA;AAMD;;;;;;;GAOG;AACH,qBAAa,QAAS,SAAQ,WAAW,CAAC,YAAY,CAAC;gBAC1C,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAIjE;AAMD;;GAEG;AACH,eAAO,MAAM,qBAAqB,QAQ1B,CAAA;AAER;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAUlE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,wBAAkB,CAAA;AAwC7C;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GACf,YAAY,CAMd;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACd,QAAQ,CAGV"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kit Plugin Error Taxonomy
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive error handling with clear recovery instructions.
|
|
5
|
+
*/
|
|
6
|
+
import { detectErrorFromOutput as coreDetectErrorFromOutput, isTimeoutOutput, PluginError, } from '@side-quest/core/instrumentation';
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Error Types
|
|
9
|
+
// ============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* Kit error types with associated recovery strategies.
|
|
12
|
+
*/
|
|
13
|
+
export var KitErrorType;
|
|
14
|
+
(function (KitErrorType) {
|
|
15
|
+
/** Kit CLI not found in PATH */
|
|
16
|
+
KitErrorType["KitNotInstalled"] = "KitNotInstalled";
|
|
17
|
+
/** Invalid repository path */
|
|
18
|
+
KitErrorType["InvalidPath"] = "InvalidPath";
|
|
19
|
+
/** Invalid input (regex, glob, etc.) */
|
|
20
|
+
KitErrorType["InvalidInput"] = "InvalidInput";
|
|
21
|
+
/** Semantic search not available (missing ML deps) */
|
|
22
|
+
KitErrorType["SemanticNotAvailable"] = "SemanticNotAvailable";
|
|
23
|
+
/** Semantic search index not yet built for repository */
|
|
24
|
+
KitErrorType["SemanticIndexNotBuilt"] = "SemanticIndexNotBuilt";
|
|
25
|
+
/** Too many results returned */
|
|
26
|
+
KitErrorType["TooManyResults"] = "TooManyResults";
|
|
27
|
+
/** Kit command failed */
|
|
28
|
+
KitErrorType["KitCommandFailed"] = "KitCommandFailed";
|
|
29
|
+
/** Failed to parse Kit output */
|
|
30
|
+
KitErrorType["OutputParseError"] = "OutputParseError";
|
|
31
|
+
/** Operation timed out */
|
|
32
|
+
KitErrorType["Timeout"] = "Timeout";
|
|
33
|
+
})(KitErrorType || (KitErrorType = {}));
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// Error Messages & Recovery Hints
|
|
36
|
+
// ============================================================================
|
|
37
|
+
/**
|
|
38
|
+
* User-facing error messages with recovery hints.
|
|
39
|
+
*/
|
|
40
|
+
export const ERROR_MESSAGES = {
|
|
41
|
+
[KitErrorType.KitNotInstalled]: {
|
|
42
|
+
message: 'Kit CLI is not installed or not found in PATH.',
|
|
43
|
+
hint: 'Install Kit with: uv tool install cased-kit',
|
|
44
|
+
},
|
|
45
|
+
[KitErrorType.InvalidPath]: {
|
|
46
|
+
message: 'The specified path does not exist or is not accessible.',
|
|
47
|
+
hint: 'Check the path exists and you have read permissions.',
|
|
48
|
+
},
|
|
49
|
+
[KitErrorType.InvalidInput]: {
|
|
50
|
+
message: 'Invalid input provided.',
|
|
51
|
+
hint: 'Check your search pattern or options for syntax errors.',
|
|
52
|
+
},
|
|
53
|
+
[KitErrorType.SemanticNotAvailable]: {
|
|
54
|
+
message: 'Semantic search is not available.',
|
|
55
|
+
hint: `Install ML dependencies: pip install 'cased-kit[ml]' or uv tool install 'cased-kit[ml]'`,
|
|
56
|
+
},
|
|
57
|
+
[KitErrorType.SemanticIndexNotBuilt]: {
|
|
58
|
+
message: 'Vector index has not been built for this repository yet.',
|
|
59
|
+
hint: 'Build it by running the CLI command provided in the error details. After building (one-time), semantic search will be fast and cached.',
|
|
60
|
+
},
|
|
61
|
+
[KitErrorType.TooManyResults]: {
|
|
62
|
+
message: 'Query returned too many results.',
|
|
63
|
+
hint: 'Try a more specific query or use --max-results to limit output.',
|
|
64
|
+
},
|
|
65
|
+
[KitErrorType.KitCommandFailed]: {
|
|
66
|
+
message: 'Kit command failed to execute.',
|
|
67
|
+
hint: 'Check the error details below for more information.',
|
|
68
|
+
},
|
|
69
|
+
[KitErrorType.OutputParseError]: {
|
|
70
|
+
message: 'Failed to parse Kit output.',
|
|
71
|
+
hint: 'This may be a bug. Check logs for details.',
|
|
72
|
+
},
|
|
73
|
+
[KitErrorType.Timeout]: {
|
|
74
|
+
message: 'Operation timed out (this may take longer on large repositories).',
|
|
75
|
+
hint: 'Try again—the vector index will be cached. If it times out again, clear .kit/vector_db and rebuild with build_index: true.',
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
// ============================================================================
|
|
79
|
+
// Error Class
|
|
80
|
+
// ============================================================================
|
|
81
|
+
/**
|
|
82
|
+
* Custom error class for Kit operations.
|
|
83
|
+
*
|
|
84
|
+
* Extends PluginError to provide Kit-specific error handling with:
|
|
85
|
+
* - Typed error classification (KitErrorType enum)
|
|
86
|
+
* - User-friendly messages with recovery hints
|
|
87
|
+
* - Structured JSON serialization for MCP responses
|
|
88
|
+
*/
|
|
89
|
+
export class KitError extends PluginError {
|
|
90
|
+
constructor(type, details, stderr) {
|
|
91
|
+
const errorInfo = ERROR_MESSAGES[type];
|
|
92
|
+
super('KitError', type, errorInfo.message, errorInfo.hint, details, stderr);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// ============================================================================
|
|
96
|
+
// Semantic Search Fallback
|
|
97
|
+
// ============================================================================
|
|
98
|
+
/**
|
|
99
|
+
* Install hint shown when semantic search is unavailable.
|
|
100
|
+
*/
|
|
101
|
+
export const SEMANTIC_INSTALL_HINT = `
|
|
102
|
+
Semantic search is not available. Using text search instead.
|
|
103
|
+
|
|
104
|
+
To enable semantic search, install the ML dependencies:
|
|
105
|
+
pip install 'cased-kit[ml]'
|
|
106
|
+
|
|
107
|
+
Or if using uv:
|
|
108
|
+
uv tool install 'cased-kit[ml]'
|
|
109
|
+
`.trim();
|
|
110
|
+
/**
|
|
111
|
+
* Check if an error indicates semantic search is unavailable.
|
|
112
|
+
* @param stderr - Standard error output from Kit
|
|
113
|
+
*/
|
|
114
|
+
export function isSemanticUnavailableError(stderr) {
|
|
115
|
+
const patterns = [
|
|
116
|
+
'sentence-transformers',
|
|
117
|
+
'chromadb',
|
|
118
|
+
'semantic search',
|
|
119
|
+
'vector index',
|
|
120
|
+
'embedding',
|
|
121
|
+
];
|
|
122
|
+
const lowerStderr = stderr.toLowerCase();
|
|
123
|
+
return patterns.some((p) => lowerStderr.includes(p));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Check if an error indicates a timeout occurred.
|
|
127
|
+
*
|
|
128
|
+
* Re-exports the core utility for backward compatibility.
|
|
129
|
+
*
|
|
130
|
+
* @param stderr - Standard error output
|
|
131
|
+
*/
|
|
132
|
+
export const isTimeoutError = isTimeoutOutput;
|
|
133
|
+
// ============================================================================
|
|
134
|
+
// Error Detection Helpers
|
|
135
|
+
// ============================================================================
|
|
136
|
+
/**
|
|
137
|
+
* Kit-specific error patterns for subprocess output detection.
|
|
138
|
+
*
|
|
139
|
+
* These patterns are tested in order by detectErrorType().
|
|
140
|
+
*/
|
|
141
|
+
const KIT_ERROR_PATTERNS = [
|
|
142
|
+
// Semantic search unavailable (must be first - most specific)
|
|
143
|
+
{
|
|
144
|
+
type: KitErrorType.SemanticNotAvailable,
|
|
145
|
+
patterns: [
|
|
146
|
+
'sentence-transformers',
|
|
147
|
+
'chromadb',
|
|
148
|
+
'semantic search',
|
|
149
|
+
'vector index',
|
|
150
|
+
'embedding',
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
// Path errors
|
|
154
|
+
{
|
|
155
|
+
type: KitErrorType.InvalidPath,
|
|
156
|
+
patterns: ['no such file', 'not found', 'does not exist'],
|
|
157
|
+
},
|
|
158
|
+
// Timeout errors
|
|
159
|
+
{
|
|
160
|
+
type: KitErrorType.Timeout,
|
|
161
|
+
patterns: ['timeout', 'timed out', 'etimedout'],
|
|
162
|
+
},
|
|
163
|
+
// Too many results
|
|
164
|
+
{
|
|
165
|
+
type: KitErrorType.TooManyResults,
|
|
166
|
+
patterns: ['too many', 'limit'],
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
/**
|
|
170
|
+
* Detect error type from Kit stderr output.
|
|
171
|
+
*
|
|
172
|
+
* Uses the generic core pattern matcher with Kit-specific patterns.
|
|
173
|
+
*
|
|
174
|
+
* @param stderr - Standard error output from Kit
|
|
175
|
+
* @param _exitCode - Exit code from Kit process (currently unused)
|
|
176
|
+
*/
|
|
177
|
+
export function detectErrorType(stderr, _exitCode) {
|
|
178
|
+
return coreDetectErrorFromOutput(stderr, KIT_ERROR_PATTERNS, KitErrorType.KitCommandFailed);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Create a KitError from process output.
|
|
182
|
+
* @param stderr - Standard error output
|
|
183
|
+
* @param exitCode - Process exit code
|
|
184
|
+
*/
|
|
185
|
+
export function createErrorFromOutput(stderr, exitCode) {
|
|
186
|
+
const errorType = detectErrorType(stderr, exitCode);
|
|
187
|
+
return new KitError(errorType, undefined, stderr.trim());
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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ACZ,iBAAiB,GACjB,MAAM,6BAA6B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../../src/lib/formatters/output.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACN,KAAK,EACL,MAAM,EACN,YAAY,EACZ,iBAAiB,GACjB,MAAM,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kit Plugin Formatters
|
|
3
|
+
*
|
|
4
|
+
* Response formatters for MCP tool output in markdown and JSON formats.
|
|
5
|
+
*/
|
|
6
|
+
import type { ErrorResult, KitResult, SemanticResult, UsagesResult } from './types.js';
|
|
7
|
+
import { ResponseFormat } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Format semantic search results for display.
|
|
10
|
+
* @param result - Semantic result or error
|
|
11
|
+
* @param format - Output format (markdown or json)
|
|
12
|
+
* @returns Formatted string
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatSemanticResults(result: KitResult<SemanticResult>, format?: ResponseFormat): string;
|
|
15
|
+
/**
|
|
16
|
+
* Format an error result.
|
|
17
|
+
* @param error - Error result
|
|
18
|
+
* @param format - Output format
|
|
19
|
+
* @returns Formatted string
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatError(error: ErrorResult, format?: ResponseFormat): string;
|
|
22
|
+
/**
|
|
23
|
+
* Format symbol usages results for display.
|
|
24
|
+
* @param result - Usages result or error
|
|
25
|
+
* @param format - Output format (markdown or json)
|
|
26
|
+
* @returns Formatted string
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatUsagesResults(result: KitResult<UsagesResult>, format?: ResponseFormat): string;
|
|
29
|
+
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/lib/formatters.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACX,WAAW,EACX,SAAS,EACT,cAAc,EACd,YAAY,EACZ,MAAM,YAAY,CAAA;AACnB,OAAO,EAAW,cAAc,EAAE,MAAM,YAAY,CAAA;AAMpD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,EACjC,MAAM,GAAE,cAAwC,GAC9C,MAAM,CAmDR;AAMD;;;;;GAKG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,WAAW,EAClB,MAAM,GAAE,cAAwC,GAC9C,MAAM,CAgBR;AAMD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,SAAS,CAAC,YAAY,CAAC,EAC/B,MAAM,GAAE,cAAwC,GAC9C,MAAM,CA4CR"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kit Plugin Formatters
|
|
3
|
+
*
|
|
4
|
+
* Response formatters for MCP tool output in markdown and JSON formats.
|
|
5
|
+
*/
|
|
6
|
+
import { truncate } from '@side-quest/core/utils';
|
|
7
|
+
import { isError, ResponseFormat } from './types.js';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Semantic Formatters
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Format semantic search results for display.
|
|
13
|
+
* @param result - Semantic result or error
|
|
14
|
+
* @param format - Output format (markdown or json)
|
|
15
|
+
* @returns Formatted string
|
|
16
|
+
*/
|
|
17
|
+
export function formatSemanticResults(result, format = ResponseFormat.MARKDOWN) {
|
|
18
|
+
if (isError(result)) {
|
|
19
|
+
return formatError(result, format);
|
|
20
|
+
}
|
|
21
|
+
if (format === ResponseFormat.JSON) {
|
|
22
|
+
return JSON.stringify(result, null, 2);
|
|
23
|
+
}
|
|
24
|
+
// Markdown format
|
|
25
|
+
const lines = [];
|
|
26
|
+
lines.push(`## Semantic Search Results`);
|
|
27
|
+
lines.push('');
|
|
28
|
+
// Show fallback notice if applicable
|
|
29
|
+
if (result.fallback && result.installHint) {
|
|
30
|
+
lines.push(`> **Note:** ${result.installHint.split('\n')[0]}`);
|
|
31
|
+
lines.push('>');
|
|
32
|
+
lines.push('> Using text search fallback. Results may be less relevant than semantic search.');
|
|
33
|
+
lines.push('');
|
|
34
|
+
}
|
|
35
|
+
lines.push(`Found **${result.count}** matches for query: _"${result.query}"_`);
|
|
36
|
+
lines.push('');
|
|
37
|
+
if (result.matches.length === 0) {
|
|
38
|
+
lines.push('_No matches found._');
|
|
39
|
+
return lines.join('\n');
|
|
40
|
+
}
|
|
41
|
+
result.matches.forEach((match, i) => {
|
|
42
|
+
const score = (match.score * 100).toFixed(1);
|
|
43
|
+
const lineInfo = match.startLine && match.endLine
|
|
44
|
+
? `:${match.startLine}-${match.endLine}`
|
|
45
|
+
: match.startLine
|
|
46
|
+
? `:${match.startLine}`
|
|
47
|
+
: '';
|
|
48
|
+
lines.push(`### ${i + 1}. ${match.file}${lineInfo} (${score}% relevance)`);
|
|
49
|
+
lines.push('');
|
|
50
|
+
lines.push('```');
|
|
51
|
+
lines.push(truncate(match.chunk, 500));
|
|
52
|
+
lines.push('```');
|
|
53
|
+
lines.push('');
|
|
54
|
+
});
|
|
55
|
+
return lines.join('\n');
|
|
56
|
+
}
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Error Formatters
|
|
59
|
+
// ============================================================================
|
|
60
|
+
/**
|
|
61
|
+
* Format an error result.
|
|
62
|
+
* @param error - Error result
|
|
63
|
+
* @param format - Output format
|
|
64
|
+
* @returns Formatted string
|
|
65
|
+
*/
|
|
66
|
+
export function formatError(error, format = ResponseFormat.MARKDOWN) {
|
|
67
|
+
if (format === ResponseFormat.JSON) {
|
|
68
|
+
return JSON.stringify(error, null, 2);
|
|
69
|
+
}
|
|
70
|
+
const lines = [];
|
|
71
|
+
lines.push(`## Error`);
|
|
72
|
+
lines.push('');
|
|
73
|
+
lines.push(`**${error.error}**`);
|
|
74
|
+
if (error.hint) {
|
|
75
|
+
lines.push('');
|
|
76
|
+
lines.push(`**Hint:** ${error.hint}`);
|
|
77
|
+
}
|
|
78
|
+
return lines.join('\n');
|
|
79
|
+
}
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// Usages Formatters
|
|
82
|
+
// ============================================================================
|
|
83
|
+
/**
|
|
84
|
+
* Format symbol usages results for display.
|
|
85
|
+
* @param result - Usages result or error
|
|
86
|
+
* @param format - Output format (markdown or json)
|
|
87
|
+
* @returns Formatted string
|
|
88
|
+
*/
|
|
89
|
+
export function formatUsagesResults(result, format = ResponseFormat.MARKDOWN) {
|
|
90
|
+
if (isError(result)) {
|
|
91
|
+
return formatError(result, format);
|
|
92
|
+
}
|
|
93
|
+
if (format === ResponseFormat.JSON) {
|
|
94
|
+
return JSON.stringify(result, null, 2);
|
|
95
|
+
}
|
|
96
|
+
// Markdown format
|
|
97
|
+
const lines = [];
|
|
98
|
+
lines.push(`## Symbol Definitions`);
|
|
99
|
+
lines.push('');
|
|
100
|
+
lines.push(`Found **${result.count}** definition(s) for \`${result.symbolName}\``);
|
|
101
|
+
lines.push('');
|
|
102
|
+
if (result.usages.length === 0) {
|
|
103
|
+
lines.push('_No definitions found._');
|
|
104
|
+
return lines.join('\n');
|
|
105
|
+
}
|
|
106
|
+
for (const usage of result.usages) {
|
|
107
|
+
const icon = getSymbolTypeIcon(usage.type);
|
|
108
|
+
const lineInfo = usage.line ? `:${usage.line}` : '';
|
|
109
|
+
lines.push(`### ${icon} ${usage.name}`);
|
|
110
|
+
lines.push('');
|
|
111
|
+
lines.push(`- **Type:** ${usage.type}`);
|
|
112
|
+
lines.push(`- **File:** \`${usage.file}${lineInfo}\``);
|
|
113
|
+
if (usage.context) {
|
|
114
|
+
lines.push('');
|
|
115
|
+
lines.push('```');
|
|
116
|
+
lines.push(usage.context);
|
|
117
|
+
lines.push('```');
|
|
118
|
+
}
|
|
119
|
+
lines.push('');
|
|
120
|
+
}
|
|
121
|
+
return lines.join('\n');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get an icon for a symbol type (usages variant).
|
|
125
|
+
*/
|
|
126
|
+
function getSymbolTypeIcon(type) {
|
|
127
|
+
const icons = {
|
|
128
|
+
function: '📦',
|
|
129
|
+
class: '📚',
|
|
130
|
+
method: '🔧',
|
|
131
|
+
property: '🏷️',
|
|
132
|
+
variable: '📌',
|
|
133
|
+
constant: '🔒',
|
|
134
|
+
type: '📝',
|
|
135
|
+
interface: '📋',
|
|
136
|
+
enum: '📊',
|
|
137
|
+
module: '📁',
|
|
138
|
+
};
|
|
139
|
+
return icons[type.toLowerCase()] ?? '•';
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=formatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../src/lib/formatters.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAOjD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEpD,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACpC,MAAiC,EACjC,SAAyB,cAAc,CAAC,QAAQ;IAEhD,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACrB,OAAO,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACnC,CAAC;IAED,IAAI,MAAM,KAAK,cAAc,CAAC,IAAI,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACvC,CAAC;IAED,kBAAkB;IAClB,MAAM,KAAK,GAAa,EAAE,CAAA;IAE1B,KAAK,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;IACxC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAEd,qCAAqC;IACrC,IAAI,MAAM,CAAC,QAAQ,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