@millstone/synapse-context-mcp 0.3.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/README.md +217 -0
- package/dist/bundled/code-structure.js +12427 -0
- package/dist/bundled/file-search.js +40278 -0
- package/dist/bundled/semantic-search.js +40245 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-bash.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-c.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-c_sharp.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-cpp.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-css.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-dart.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-elisp.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-elixir.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-elm.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-embedded_template.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-go.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-html.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-java.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-javascript.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-json.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-kotlin.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-lua.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-objc.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-ocaml.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-php.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-python.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-ql.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-rescript.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-ruby.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-rust.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-scala.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-solidity.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-swift.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-systemrdl.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-tlaplus.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-toml.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-tsx.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-typescript.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-vue.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-yaml.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter-zig.wasm +0 -0
- package/dist/bundled/tree-sitter-wasms/tree-sitter.wasm +0 -0
- package/dist/bundled/tree-sitter.wasm +0 -0
- package/dist/continue/ContinueIDE.d.ts +70 -0
- package/dist/continue/ContinueIDE.d.ts.map +1 -0
- package/dist/continue/ContinueIDE.js +251 -0
- package/dist/continue/ContinueIDE.js.map +1 -0
- package/dist/embeddings/embeddings-provider.d.ts +53 -0
- package/dist/embeddings/embeddings-provider.d.ts.map +1 -0
- package/dist/embeddings/embeddings-provider.js +138 -0
- package/dist/embeddings/embeddings-provider.js.map +1 -0
- package/dist/embeddings/index.d.ts +10 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/index.js +10 -0
- package/dist/embeddings/index.js.map +1 -0
- package/dist/embeddings/vector-index.d.ts +43 -0
- package/dist/embeddings/vector-index.d.ts.map +1 -0
- package/dist/embeddings/vector-index.js +174 -0
- package/dist/embeddings/vector-index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/selection/SelectionManager.d.ts +90 -0
- package/dist/selection/SelectionManager.d.ts.map +1 -0
- package/dist/selection/SelectionManager.js +167 -0
- package/dist/selection/SelectionManager.js.map +1 -0
- package/dist/server.d.ts +28 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +480 -0
- package/dist/server.js.map +1 -0
- package/dist/shims/continue-worker-paths.d.ts +47 -0
- package/dist/shims/continue-worker-paths.d.ts.map +1 -0
- package/dist/shims/continue-worker-paths.js +94 -0
- package/dist/shims/continue-worker-paths.js.map +1 -0
- package/dist/shims/workerpool-shim.d.ts +43 -0
- package/dist/shims/workerpool-shim.d.ts.map +1 -0
- package/dist/shims/workerpool-shim.js +37 -0
- package/dist/shims/workerpool-shim.js.map +1 -0
- package/dist/tools/code-structure.d.ts +36 -0
- package/dist/tools/code-structure.d.ts.map +1 -0
- package/dist/tools/code-structure.js +131 -0
- package/dist/tools/code-structure.js.map +1 -0
- package/dist/tools/file-search.d.ts +35 -0
- package/dist/tools/file-search.d.ts.map +1 -0
- package/dist/tools/file-search.js +286 -0
- package/dist/tools/file-search.js.map +1 -0
- package/dist/tools/file-tree.d.ts +18 -0
- package/dist/tools/file-tree.d.ts.map +1 -0
- package/dist/tools/file-tree.js +45 -0
- package/dist/tools/file-tree.js.map +1 -0
- package/dist/tools/manage-selection.d.ts +28 -0
- package/dist/tools/manage-selection.d.ts.map +1 -0
- package/dist/tools/manage-selection.js +98 -0
- package/dist/tools/manage-selection.js.map +1 -0
- package/dist/tools/read-file.d.ts +19 -0
- package/dist/tools/read-file.d.ts.map +1 -0
- package/dist/tools/read-file.js +35 -0
- package/dist/tools/read-file.js.map +1 -0
- package/dist/tools/semantic-search.d.ts +50 -0
- package/dist/tools/semantic-search.d.ts.map +1 -0
- package/dist/tools/semantic-search.js +243 -0
- package/dist/tools/semantic-search.js.map +1 -0
- package/dist/tools/workspace-context.d.ts +20 -0
- package/dist/tools/workspace-context.d.ts.map +1 -0
- package/dist/tools/workspace-context.js +36 -0
- package/dist/tools/workspace-context.js.map +1 -0
- package/dist/tree-sitter/code-snippet-queries/bash.scm +7 -0
- package/dist/tree-sitter/code-snippet-queries/c.scm +34 -0
- package/dist/tree-sitter/code-snippet-queries/c_sharp.scm +42 -0
- package/dist/tree-sitter/code-snippet-queries/cpp.scm +34 -0
- package/dist/tree-sitter/code-snippet-queries/dart.scm +33 -0
- package/dist/tree-sitter/code-snippet-queries/elisp.scm +21 -0
- package/dist/tree-sitter/code-snippet-queries/elixir.scm +32 -0
- package/dist/tree-sitter/code-snippet-queries/elm.scm +17 -0
- package/dist/tree-sitter/code-snippet-queries/go.scm +28 -0
- package/dist/tree-sitter/code-snippet-queries/java.scm +34 -0
- package/dist/tree-sitter/code-snippet-queries/javascript.scm +22 -0
- package/dist/tree-sitter/code-snippet-queries/kotlin.scm +32 -0
- package/dist/tree-sitter/code-snippet-queries/lua.scm +34 -0
- package/dist/tree-sitter/code-snippet-queries/ocaml.scm +27 -0
- package/dist/tree-sitter/code-snippet-queries/php.scm +43 -0
- package/dist/tree-sitter/code-snippet-queries/python.scm +17 -0
- package/dist/tree-sitter/code-snippet-queries/rescript.scm +23 -0
- package/dist/tree-sitter/code-snippet-queries/ruby.scm +33 -0
- package/dist/tree-sitter/code-snippet-queries/rust.scm +42 -0
- package/dist/tree-sitter/code-snippet-queries/scala.scm +32 -0
- package/dist/tree-sitter/code-snippet-queries/solidity.scm +33 -0
- package/dist/tree-sitter/code-snippet-queries/swift.scm +40 -0
- package/dist/tree-sitter/code-snippet-queries/tsx.scm +54 -0
- package/dist/tree-sitter/code-snippet-queries/typescript.scm +28 -0
- package/dist/tree-sitter/code-snippet-queries/zig.scm +16 -0
- package/dist/utils/file-walker.d.ts +19 -0
- package/dist/utils/file-walker.d.ts.map +1 -0
- package/dist/utils/file-walker.js +82 -0
- package/dist/utils/file-walker.js.map +1 -0
- package/dist/utils/token-counter.d.ts +16 -0
- package/dist/utils/token-counter.d.ts.map +1 -0
- package/dist/utils/token-counter.js +30 -0
- package/dist/utils/token-counter.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FileWalker } from '../utils/file-walker.js';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Get workspace file tree
|
|
5
|
+
*/
|
|
6
|
+
export async function getFileTreeTool(args, workspaceDir) {
|
|
7
|
+
// Return workspace roots
|
|
8
|
+
if (args.type === 'roots') {
|
|
9
|
+
return {
|
|
10
|
+
type: 'roots',
|
|
11
|
+
roots: [workspaceDir],
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
// Get files
|
|
15
|
+
try {
|
|
16
|
+
const walker = new FileWalker(workspaceDir);
|
|
17
|
+
const startPath = args.path || workspaceDir;
|
|
18
|
+
const files = await walker.walk(startPath);
|
|
19
|
+
// Filter by depth if specified
|
|
20
|
+
let filteredFiles = files;
|
|
21
|
+
if (args.max_depth !== undefined) {
|
|
22
|
+
filteredFiles = files.filter(file => {
|
|
23
|
+
const relativePath = path.relative(workspaceDir, file);
|
|
24
|
+
const depth = relativePath.split(path.sep).length;
|
|
25
|
+
return depth <= args.max_depth;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
type: args.type,
|
|
30
|
+
mode: args.mode,
|
|
31
|
+
files: filteredFiles,
|
|
32
|
+
count: filteredFiles.length,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error('File tree error:', error);
|
|
37
|
+
return {
|
|
38
|
+
type: args.type,
|
|
39
|
+
mode: args.mode,
|
|
40
|
+
files: [],
|
|
41
|
+
count: 0,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+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,aAAa,CAAC,MAAM;SAC5B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACzC,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,CAAC;SACT,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SelectionManager, SelectionMode, Slice } from '../selection/SelectionManager.js';
|
|
2
|
+
export interface ManageSelectionArgs {
|
|
3
|
+
op: 'get' | 'add' | 'remove' | 'set' | 'clear' | 'preview' | 'promote' | 'demote';
|
|
4
|
+
paths?: string[];
|
|
5
|
+
mode?: SelectionMode;
|
|
6
|
+
slices?: Array<{
|
|
7
|
+
path: string;
|
|
8
|
+
ranges: Slice[];
|
|
9
|
+
}>;
|
|
10
|
+
view?: 'summary' | 'files' | 'content';
|
|
11
|
+
}
|
|
12
|
+
export interface ManageSelectionResult {
|
|
13
|
+
operation: string;
|
|
14
|
+
files?: Array<{
|
|
15
|
+
path: string;
|
|
16
|
+
mode: SelectionMode;
|
|
17
|
+
slices?: Slice[];
|
|
18
|
+
}>;
|
|
19
|
+
totalFiles?: number;
|
|
20
|
+
totalTokens?: number;
|
|
21
|
+
content?: string;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Manage file selection (add/remove/get/clear)
|
|
26
|
+
*/
|
|
27
|
+
export declare function manageSelectionTool(args: ManageSelectionArgs, manager: SelectionManager): Promise<ManageSelectionResult>;
|
|
28
|
+
//# sourceMappingURL=manage-selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manage-selection.d.ts","sourceRoot":"","sources":["../../src/tools/manage-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAE/F,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IAClF,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,MAAM,CAAC,EAAE,KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,KAAK,EAAE,CAAC;KACjB,CAAC,CAAC;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;CACxC;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,aAAa,CAAC;QACpB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;KAClB,CAAC,CAAC;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,mBAAmB,EACzB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,qBAAqB,CAAC,CA8GhC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manage file selection (add/remove/get/clear)
|
|
3
|
+
*/
|
|
4
|
+
export async function manageSelectionTool(args, manager) {
|
|
5
|
+
// Validate operation
|
|
6
|
+
const validOps = ['get', 'add', 'remove', 'set', 'clear', 'preview', 'promote', 'demote'];
|
|
7
|
+
if (!validOps.includes(args.op)) {
|
|
8
|
+
return {
|
|
9
|
+
operation: args.op,
|
|
10
|
+
error: `Invalid operation '${args.op}'. Valid operations: ${validOps.join(', ')}`,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
// Validate that at least one of paths or slices is provided for operations that need them
|
|
14
|
+
if (['add', 'remove', 'set', 'promote', 'demote'].includes(args.op)) {
|
|
15
|
+
if (!args.paths && !args.slices) {
|
|
16
|
+
return {
|
|
17
|
+
operation: args.op,
|
|
18
|
+
error: `Operation '${args.op}' requires either 'paths' or 'slices' parameter`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
switch (args.op) {
|
|
23
|
+
case 'add':
|
|
24
|
+
// Handle adding full files
|
|
25
|
+
for (const path of args.paths || []) {
|
|
26
|
+
await manager.add(path, args.mode || 'full');
|
|
27
|
+
}
|
|
28
|
+
// Handle adding slices
|
|
29
|
+
if (args.slices) {
|
|
30
|
+
for (const slice of args.slices) {
|
|
31
|
+
await manager.addSlices(slice.path, slice.ranges);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
break;
|
|
35
|
+
case 'remove':
|
|
36
|
+
if (args.paths) {
|
|
37
|
+
manager.removeMultiple(args.paths);
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
case 'set':
|
|
41
|
+
const filesToSet = args.paths?.map(path => ({
|
|
42
|
+
path,
|
|
43
|
+
mode: args.mode || 'full',
|
|
44
|
+
})) || [];
|
|
45
|
+
if (args.slices) {
|
|
46
|
+
for (const slice of args.slices) {
|
|
47
|
+
filesToSet.push({
|
|
48
|
+
path: slice.path,
|
|
49
|
+
mode: 'slices',
|
|
50
|
+
slices: slice.ranges,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
await manager.set(filesToSet);
|
|
55
|
+
break;
|
|
56
|
+
case 'clear':
|
|
57
|
+
manager.clear();
|
|
58
|
+
break;
|
|
59
|
+
case 'preview':
|
|
60
|
+
const preview = await manager.preview();
|
|
61
|
+
return {
|
|
62
|
+
operation: 'preview',
|
|
63
|
+
content: preview.content,
|
|
64
|
+
totalTokens: preview.tokens,
|
|
65
|
+
};
|
|
66
|
+
case 'promote':
|
|
67
|
+
for (const path of args.paths || []) {
|
|
68
|
+
await manager.promote(path);
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
case 'demote':
|
|
72
|
+
for (const path of args.paths || []) {
|
|
73
|
+
await manager.demote(path);
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
case 'get':
|
|
77
|
+
default:
|
|
78
|
+
const summary = await manager.getSummary();
|
|
79
|
+
const result = {
|
|
80
|
+
operation: 'get',
|
|
81
|
+
files: summary.files,
|
|
82
|
+
totalFiles: summary.totalFiles,
|
|
83
|
+
totalTokens: summary.totalTokens,
|
|
84
|
+
};
|
|
85
|
+
if (args.view === 'content') {
|
|
86
|
+
result.content = await manager.getContent();
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
const summary = await manager.getSummary();
|
|
91
|
+
return {
|
|
92
|
+
operation: args.op,
|
|
93
|
+
files: summary.files,
|
|
94
|
+
totalFiles: summary.totalFiles,
|
|
95
|
+
totalTokens: summary.totalTokens,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=manage-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manage-selection.js","sourceRoot":"","sources":["../../src/tools/manage-selection.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAyB,EACzB,OAAyB;IAEzB,qBAAqB;IACrB,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC1F,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QAChC,OAAO;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AAE,OAAO,CAAC,KAAK;gBACpB,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,WAAW,EAAE,OAAO,CAAC,WAAW;aACjC,CAAC;YAEF,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC5B,MAAM,CAAC,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;YAC9C,CAAC;YAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;IAC3C,OAAO;QACL,SAAS,EAAE,IAAI,CAAC,EAAE;QAClB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ReadFileArgs {
|
|
2
|
+
path: string;
|
|
3
|
+
start_line?: number;
|
|
4
|
+
end_line?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ReadFileResult {
|
|
7
|
+
path: string;
|
|
8
|
+
content: string;
|
|
9
|
+
lines?: {
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
};
|
|
13
|
+
size: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Read file contents
|
|
17
|
+
*/
|
|
18
|
+
export declare function readFileTool(args: ReadFileArgs): Promise<ReadFileResult>;
|
|
19
|
+
//# sourceMappingURL=read-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.d.ts","sourceRoot":"","sources":["../../src/tools/read-file.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,cAAc,CAAC,CA6BzB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
/**
|
|
3
|
+
* Read file contents
|
|
4
|
+
*/
|
|
5
|
+
export async function readFileTool(args) {
|
|
6
|
+
try {
|
|
7
|
+
const fullContent = await fs.readFile(args.path, 'utf-8');
|
|
8
|
+
// Read specific line range if specified
|
|
9
|
+
if (args.start_line !== undefined && args.end_line !== undefined) {
|
|
10
|
+
const lines = fullContent.split('\n');
|
|
11
|
+
const selectedLines = lines.slice(args.start_line, args.end_line + 1);
|
|
12
|
+
const content = selectedLines.join('\n');
|
|
13
|
+
return {
|
|
14
|
+
path: args.path,
|
|
15
|
+
content,
|
|
16
|
+
lines: {
|
|
17
|
+
start: args.start_line,
|
|
18
|
+
end: args.end_line,
|
|
19
|
+
},
|
|
20
|
+
size: content.length,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return {
|
|
25
|
+
path: args.path,
|
|
26
|
+
content: fullContent,
|
|
27
|
+
size: fullContent.length,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new Error(`Failed to read file ${args.path}: ${error}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=read-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.js","sourceRoot":"","sources":["../../src/tools/read-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAkBlC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAkB;IAElB,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE1D,wCAAwC;QACxC,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACjE,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACtC,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;YACtE,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEzC,OAAO;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO;gBACP,KAAK,EAAE;oBACL,KAAK,EAAE,IAAI,CAAC,UAAU;oBACtB,GAAG,EAAE,IAAI,CAAC,QAAQ;iBACnB;gBACD,IAAI,EAAE,OAAO,CAAC,MAAM;aACrB,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO,EAAE,WAAW;gBACpB,IAAI,EAAE,WAAW,CAAC,MAAM;aACzB,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic Search Tool for Context-MCP
|
|
3
|
+
*
|
|
4
|
+
* Provides hybrid search combining:
|
|
5
|
+
* - FTS5 full-text search with BM25 ranking (lexical matching)
|
|
6
|
+
* - LanceDB vector search with embeddings (semantic similarity)
|
|
7
|
+
*
|
|
8
|
+
* Results are merged using Reciprocal Rank Fusion (RRF) to combine
|
|
9
|
+
* both ranking signals effectively.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT: This tool requires LanceDB. If LanceDB is unavailable
|
|
12
|
+
* (unsupported platform), the tool will fail rather than fall back.
|
|
13
|
+
*/
|
|
14
|
+
import type { ContinueIDE } from '../continue/ContinueIDE.js';
|
|
15
|
+
export interface SemanticSearchArgs {
|
|
16
|
+
query: string;
|
|
17
|
+
mode?: 'hybrid' | 'semantic' | 'lexical';
|
|
18
|
+
filter?: {
|
|
19
|
+
extensions?: string[];
|
|
20
|
+
exclude?: string[];
|
|
21
|
+
};
|
|
22
|
+
max_results?: number;
|
|
23
|
+
include_content?: boolean;
|
|
24
|
+
semantic_weight?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface SemanticSearchResult {
|
|
27
|
+
query: string;
|
|
28
|
+
mode: string;
|
|
29
|
+
results: Array<{
|
|
30
|
+
path: string;
|
|
31
|
+
line_range: [number, number];
|
|
32
|
+
content?: string;
|
|
33
|
+
score: number;
|
|
34
|
+
source: 'semantic' | 'lexical' | 'hybrid';
|
|
35
|
+
}>;
|
|
36
|
+
count: number;
|
|
37
|
+
performance?: {
|
|
38
|
+
searchTime: number;
|
|
39
|
+
semanticTime?: number;
|
|
40
|
+
lexicalTime?: number;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Main semantic search tool.
|
|
45
|
+
*
|
|
46
|
+
* @throws Error if vector search is unavailable (LanceDB not supported)
|
|
47
|
+
*/
|
|
48
|
+
export declare function semanticSearchTool(args: SemanticSearchArgs, workspaceDirs: string | string[], ide: ContinueIDE): Promise<SemanticSearchResult>;
|
|
49
|
+
export default semanticSearchTool;
|
|
50
|
+
//# sourceMappingURL=semantic-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-search.d.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
|
|
2
|
+
* Semantic Search Tool for Context-MCP
|
|
3
|
+
*
|
|
4
|
+
* Provides hybrid search combining:
|
|
5
|
+
* - FTS5 full-text search with BM25 ranking (lexical matching)
|
|
6
|
+
* - LanceDB vector search with embeddings (semantic similarity)
|
|
7
|
+
*
|
|
8
|
+
* Results are merged using Reciprocal Rank Fusion (RRF) to combine
|
|
9
|
+
* both ranking signals effectively.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT: This tool requires LanceDB. If LanceDB is unavailable
|
|
12
|
+
* (unsupported platform), the tool will fail rather than fall back.
|
|
13
|
+
*/
|
|
14
|
+
import { FullTextSearchCodebaseIndex } from '@continuedev/core/dist/indexing/FullTextSearchCodebaseIndex.js';
|
|
15
|
+
import { getComputeDeleteAddRemove } from '@continuedev/core/dist/indexing/refreshIndex.js';
|
|
16
|
+
import { ChunkCodebaseIndex } from '@continuedev/core/dist/indexing/chunk/ChunkCodebaseIndex.js';
|
|
17
|
+
import { promises as fs } from 'node:fs';
|
|
18
|
+
import { FileWalker } from '../utils/file-walker.js';
|
|
19
|
+
import { vectorSearch, isVectorSearchAvailable } from '../embeddings/vector-index.js';
|
|
20
|
+
// Track which directories have FTS index built
|
|
21
|
+
const ftsIndexedDirs = new Set();
|
|
22
|
+
/**
|
|
23
|
+
* Sanitize query for FTS5 phrase search.
|
|
24
|
+
*/
|
|
25
|
+
function sanitizeFTS5Query(text) {
|
|
26
|
+
const escaped = text.replace(/"/g, '""');
|
|
27
|
+
return `"${escaped}"`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build FTS5 index for a directory (same logic as file-search.ts).
|
|
31
|
+
*/
|
|
32
|
+
async function ensureFTSIndex(workspaceDir, ide) {
|
|
33
|
+
if (ftsIndexedDirs.has(workspaceDir)) {
|
|
34
|
+
return {
|
|
35
|
+
branch: 'main',
|
|
36
|
+
directory: workspaceDir,
|
|
37
|
+
artifactId: 'chunks',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
console.error(`[semantic-search] Building FTS index for: ${workspaceDir}`);
|
|
41
|
+
const tag = {
|
|
42
|
+
branch: 'main',
|
|
43
|
+
directory: workspaceDir,
|
|
44
|
+
artifactId: 'chunks',
|
|
45
|
+
};
|
|
46
|
+
const walker = new FileWalker(workspaceDir);
|
|
47
|
+
const allFiles = await walker.walk();
|
|
48
|
+
const fileStats = {};
|
|
49
|
+
for (const file of allFiles) {
|
|
50
|
+
try {
|
|
51
|
+
const stats = await fs.stat(file);
|
|
52
|
+
fileStats[file] = {
|
|
53
|
+
size: stats.size,
|
|
54
|
+
lastModified: stats.mtimeMs,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Skip files we can't stat
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const [results, , markComplete] = await getComputeDeleteAddRemove(tag, fileStats, async (path) => await fs.readFile(path, 'utf-8'), undefined);
|
|
62
|
+
// Build chunks index
|
|
63
|
+
const mockServerClient = {
|
|
64
|
+
connected: false,
|
|
65
|
+
url: undefined,
|
|
66
|
+
getUserToken: () => undefined,
|
|
67
|
+
getConfig: async () => ({ configJson: '{}' }),
|
|
68
|
+
getFromIndexCache: async () => ({ files: {} }),
|
|
69
|
+
};
|
|
70
|
+
const chunkIndex = new ChunkCodebaseIndex(ide.readFile.bind(ide), mockServerClient, 512);
|
|
71
|
+
for await (const progress of chunkIndex.update(tag, results, markComplete, undefined)) {
|
|
72
|
+
// Progress logging
|
|
73
|
+
}
|
|
74
|
+
// Build FTS index
|
|
75
|
+
const ftsIndex = new FullTextSearchCodebaseIndex();
|
|
76
|
+
for await (const progress of ftsIndex.update(tag, results, markComplete, undefined)) {
|
|
77
|
+
// Progress logging
|
|
78
|
+
}
|
|
79
|
+
ftsIndexedDirs.add(workspaceDir);
|
|
80
|
+
console.error(`[semantic-search] ✅ FTS index built for ${workspaceDir}`);
|
|
81
|
+
return tag;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Perform FTS5 lexical search.
|
|
85
|
+
*/
|
|
86
|
+
async function lexicalSearch(query, workspaceDirs, ide, maxResults) {
|
|
87
|
+
const tags = [];
|
|
88
|
+
for (const dir of workspaceDirs) {
|
|
89
|
+
const tag = await ensureFTSIndex(dir, ide);
|
|
90
|
+
tags.push(tag);
|
|
91
|
+
}
|
|
92
|
+
const ftsIndex = new FullTextSearchCodebaseIndex();
|
|
93
|
+
return await ftsIndex.retrieve({
|
|
94
|
+
n: maxResults,
|
|
95
|
+
text: sanitizeFTS5Query(query),
|
|
96
|
+
tags,
|
|
97
|
+
bm25Threshold: -2.5,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Reciprocal Rank Fusion (RRF) for combining ranked lists.
|
|
102
|
+
* RRF(d) = Σ 1/(k + rank(d)) for each ranking
|
|
103
|
+
* k=60 is standard constant to prevent high ranks from dominating.
|
|
104
|
+
*/
|
|
105
|
+
function reciprocalRankFusion(semanticResults, lexicalResults, semanticWeight = 0.5, k = 60) {
|
|
106
|
+
const scores = new Map();
|
|
107
|
+
const lexicalWeight = 1 - semanticWeight;
|
|
108
|
+
// Score semantic results
|
|
109
|
+
semanticResults.forEach((chunk, rank) => {
|
|
110
|
+
const key = `${chunk.filepath}:${chunk.startLine}-${chunk.endLine}`;
|
|
111
|
+
const rrfScore = semanticWeight / (k + rank + 1);
|
|
112
|
+
if (scores.has(key)) {
|
|
113
|
+
const existing = scores.get(key);
|
|
114
|
+
existing.score += rrfScore;
|
|
115
|
+
existing.sources.add('semantic');
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
scores.set(key, {
|
|
119
|
+
chunk,
|
|
120
|
+
score: rrfScore,
|
|
121
|
+
sources: new Set(['semantic']),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
// Score lexical results
|
|
126
|
+
lexicalResults.forEach((chunk, rank) => {
|
|
127
|
+
const key = `${chunk.filepath}:${chunk.startLine}-${chunk.endLine}`;
|
|
128
|
+
const rrfScore = lexicalWeight / (k + rank + 1);
|
|
129
|
+
if (scores.has(key)) {
|
|
130
|
+
const existing = scores.get(key);
|
|
131
|
+
existing.score += rrfScore;
|
|
132
|
+
existing.sources.add('lexical');
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
scores.set(key, {
|
|
136
|
+
chunk,
|
|
137
|
+
score: rrfScore,
|
|
138
|
+
sources: new Set(['lexical']),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return scores;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Main semantic search tool.
|
|
146
|
+
*
|
|
147
|
+
* @throws Error if vector search is unavailable (LanceDB not supported)
|
|
148
|
+
*/
|
|
149
|
+
export async function semanticSearchTool(args, workspaceDirs, ide) {
|
|
150
|
+
const dirs = Array.isArray(workspaceDirs) ? workspaceDirs : [workspaceDirs];
|
|
151
|
+
const mode = args.mode || 'hybrid';
|
|
152
|
+
const maxResults = args.max_results || 30;
|
|
153
|
+
const includeContent = args.include_content ?? false;
|
|
154
|
+
const semanticWeight = args.semantic_weight ?? 0.5;
|
|
155
|
+
const startTime = Date.now();
|
|
156
|
+
let semanticTime;
|
|
157
|
+
let lexicalTime;
|
|
158
|
+
// Check vector search availability - FAIL if unavailable
|
|
159
|
+
if (mode === 'hybrid' || mode === 'semantic') {
|
|
160
|
+
const available = await isVectorSearchAvailable();
|
|
161
|
+
if (!available) {
|
|
162
|
+
throw new Error('Semantic search requires LanceDB which is not available on this platform. ' +
|
|
163
|
+
'Use file_search tool for lexical search instead.');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
let semanticResults = [];
|
|
167
|
+
let lexicalResults = [];
|
|
168
|
+
// Perform semantic search
|
|
169
|
+
if (mode === 'hybrid' || mode === 'semantic') {
|
|
170
|
+
const semStart = Date.now();
|
|
171
|
+
semanticResults = await vectorSearch(args.query, dirs, ide, {
|
|
172
|
+
maxResults: maxResults * 2, // Get more to allow for deduplication
|
|
173
|
+
});
|
|
174
|
+
semanticTime = Date.now() - semStart;
|
|
175
|
+
}
|
|
176
|
+
// Perform lexical search
|
|
177
|
+
if (mode === 'hybrid' || mode === 'lexical') {
|
|
178
|
+
const lexStart = Date.now();
|
|
179
|
+
lexicalResults = await lexicalSearch(args.query, dirs, ide, maxResults * 2);
|
|
180
|
+
lexicalTime = Date.now() - lexStart;
|
|
181
|
+
}
|
|
182
|
+
// Merge results
|
|
183
|
+
let finalResults = [];
|
|
184
|
+
if (mode === 'hybrid') {
|
|
185
|
+
// Use RRF to combine rankings
|
|
186
|
+
const fusedScores = reciprocalRankFusion(semanticResults, lexicalResults, semanticWeight);
|
|
187
|
+
// Sort by fused score and take top results
|
|
188
|
+
const sorted = Array.from(fusedScores.values())
|
|
189
|
+
.sort((a, b) => b.score - a.score)
|
|
190
|
+
.slice(0, maxResults);
|
|
191
|
+
finalResults = sorted.map(({ chunk, score, sources }) => ({
|
|
192
|
+
path: chunk.filepath,
|
|
193
|
+
line_range: [chunk.startLine, chunk.endLine],
|
|
194
|
+
content: includeContent ? chunk.content : undefined,
|
|
195
|
+
score,
|
|
196
|
+
source: sources.size > 1 ? 'hybrid' : (sources.has('semantic') ? 'semantic' : 'lexical'),
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
else if (mode === 'semantic') {
|
|
200
|
+
finalResults = semanticResults.slice(0, maxResults).map((chunk, idx) => ({
|
|
201
|
+
path: chunk.filepath,
|
|
202
|
+
line_range: [chunk.startLine, chunk.endLine],
|
|
203
|
+
content: includeContent ? chunk.content : undefined,
|
|
204
|
+
score: 1 / (idx + 1), // Normalized rank score
|
|
205
|
+
source: 'semantic',
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
finalResults = lexicalResults.slice(0, maxResults).map((chunk, idx) => ({
|
|
210
|
+
path: chunk.filepath,
|
|
211
|
+
line_range: [chunk.startLine, chunk.endLine],
|
|
212
|
+
content: includeContent ? chunk.content : undefined,
|
|
213
|
+
score: 1 / (idx + 1),
|
|
214
|
+
source: 'lexical',
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
// Apply filters
|
|
218
|
+
if (args.filter?.extensions?.length) {
|
|
219
|
+
finalResults = finalResults.filter((r) => {
|
|
220
|
+
const ext = r.path.split('.').pop();
|
|
221
|
+
return ext && args.filter.extensions.includes(ext);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (args.filter?.exclude?.length) {
|
|
225
|
+
finalResults = finalResults.filter((r) => {
|
|
226
|
+
return !args.filter.exclude.some((ex) => r.path.includes(ex));
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const searchTime = Date.now() - startTime;
|
|
230
|
+
return {
|
|
231
|
+
query: args.query,
|
|
232
|
+
mode,
|
|
233
|
+
results: finalResults,
|
|
234
|
+
count: finalResults.length,
|
|
235
|
+
performance: {
|
|
236
|
+
searchTime,
|
|
237
|
+
semanticTime,
|
|
238
|
+
lexicalTime,
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
export default semanticSearchTool;
|
|
243
|
+
//# sourceMappingURL=semantic-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic-search.js","sourceRoot":"","sources":["../../src/tools/semantic-search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,2BAA2B,EAAE,MAAM,gEAAgE,CAAC;AAC7G,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,kBAAkB,EAAE,MAAM,6DAA6D,CAAC;AACjG,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAoB,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAiCxG,+CAA+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,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IAE1C,OAAO;QACL,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,IAAI;QACJ,OAAO,EAAE,YAAY;QACrB,KAAK,EAAE,YAAY,CAAC,MAAM;QAC1B,WAAW,EAAE;YACX,UAAU;YACV,YAAY;YACZ,WAAW;SACZ;KACF,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SelectionManager } from '../selection/SelectionManager.js';
|
|
2
|
+
export interface WorkspaceContextArgs {
|
|
3
|
+
include?: Array<'selection' | 'code' | 'files' | 'tree' | 'tokens'>;
|
|
4
|
+
}
|
|
5
|
+
export interface WorkspaceContextResult {
|
|
6
|
+
selection?: {
|
|
7
|
+
files: any[];
|
|
8
|
+
totalFiles: number;
|
|
9
|
+
totalTokens: number;
|
|
10
|
+
};
|
|
11
|
+
code_structures?: any;
|
|
12
|
+
file_contents?: string;
|
|
13
|
+
tree?: any;
|
|
14
|
+
tokens?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get comprehensive workspace context snapshot
|
|
18
|
+
*/
|
|
19
|
+
export declare function workspaceContextTool(args: WorkspaceContextArgs, manager: SelectionManager, workspaceDir: string): Promise<WorkspaceContextResult>;
|
|
20
|
+
//# sourceMappingURL=workspace-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-context.d.ts","sourceRoot":"","sources":["../../src/tools/workspace-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC;CACrE;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE;QACV,KAAK,EAAE,GAAG,EAAE,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,eAAe,CAAC,EAAE,GAAG,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,oBAAoB,EAC1B,OAAO,EAAE,gBAAgB,EACzB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,sBAAsB,CAAC,CAsCjC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getFileTreeTool } from './file-tree.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get comprehensive workspace context snapshot
|
|
4
|
+
*/
|
|
5
|
+
export async function workspaceContextTool(args, manager, workspaceDir) {
|
|
6
|
+
const include = args.include || ['selection', 'tokens'];
|
|
7
|
+
const result = {};
|
|
8
|
+
try {
|
|
9
|
+
if (include.includes('selection')) {
|
|
10
|
+
result.selection = await manager.getSummary();
|
|
11
|
+
}
|
|
12
|
+
if (include.includes('code')) {
|
|
13
|
+
result.code_structures = {
|
|
14
|
+
note: 'Code structure extraction will be added in V2',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (include.includes('files')) {
|
|
18
|
+
result.file_contents = await manager.getContent();
|
|
19
|
+
}
|
|
20
|
+
if (include.includes('tree')) {
|
|
21
|
+
result.tree = await getFileTreeTool({
|
|
22
|
+
type: 'files',
|
|
23
|
+
mode: 'full',
|
|
24
|
+
}, workspaceDir);
|
|
25
|
+
}
|
|
26
|
+
if (include.includes('tokens')) {
|
|
27
|
+
const preview = await manager.preview();
|
|
28
|
+
result.tokens = preview.tokens;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error('Workspace context error:', error);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=workspace-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-context.js","sourceRoot":"","sources":["../../src/tools/workspace-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAkBjD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAA0B,EAC1B,OAAyB,EACzB,YAAoB;IAEpB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACxD,MAAM,MAAM,GAA2B,EAAE,CAAC;IAE1C,IAAI,CAAC;QACH,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAClC,MAAM,CAAC,SAAS,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;QAChD,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7B,MAAM,CAAC,eAAe,GAAG;gBACvB,IAAI,EAAE,+CAA+C;aACtD,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9B,MAAM,CAAC,aAAa,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;QACpD,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,GAAG,MAAM,eAAe,CACjC;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,MAAM;aACb,EACD,YAAY,CACb,CAAC;QACJ,CAAC;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