@softerist/heuristic-mcp 3.0.17 → 3.1.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/config.jsonc +23 -6
- package/features/ann-config.js +7 -14
- package/features/clear-cache.js +3 -3
- package/features/find-similar-code.js +17 -22
- package/features/hybrid-search.js +59 -67
- package/features/index-codebase.js +305 -268
- package/features/lifecycle.js +370 -176
- package/features/package-version.js +15 -26
- package/features/register.js +75 -57
- package/features/resources.js +21 -47
- package/features/set-workspace.js +31 -43
- package/index.js +818 -172
- package/lib/cache-utils.js +95 -99
- package/lib/cache.js +121 -166
- package/lib/cli.js +246 -238
- package/lib/config.js +232 -62
- package/lib/constants.js +22 -2
- package/lib/embed-query-process.js +13 -29
- package/lib/embedding-process.js +29 -19
- package/lib/embedding-worker.js +166 -149
- package/lib/ignore-patterns.js +39 -39
- package/lib/json-writer.js +7 -34
- package/lib/logging.js +11 -42
- package/lib/onnx-backend.js +4 -4
- package/lib/path-utils.js +4 -21
- package/lib/project-detector.js +3 -3
- package/lib/server-lifecycle.js +109 -15
- package/lib/settings-editor.js +25 -18
- package/lib/slice-normalize.js +6 -16
- package/lib/tokenizer.js +56 -109
- package/lib/utils.js +62 -81
- package/lib/vector-store-binary.js +7 -7
- package/lib/vector-store-sqlite.js +35 -67
- package/lib/workspace-cache-key.js +36 -0
- package/lib/workspace-env.js +55 -14
- package/package.json +86 -86
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runtime Workspace Switching Tool
|
|
3
|
-
*
|
|
4
|
-
* Changes the workspace path at runtime, reinitializing the cache
|
|
5
|
-
* and optionally triggering reindexing.
|
|
6
|
-
*/
|
|
7
1
|
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import fs from 'fs/promises';
|
|
10
|
-
import crypto from 'crypto';
|
|
11
|
-
import { acquireWorkspaceLock, releaseWorkspaceLock } from '../lib/server-lifecycle.js';
|
|
12
2
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs/promises';
|
|
5
|
+
import { acquireWorkspaceLock, releaseWorkspaceLock } from '../lib/server-lifecycle.js';
|
|
6
|
+
import { getWorkspaceCachePath } from '../lib/workspace-cache-key.js';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function getWorkspaceCacheDir(workspacePath, globalCacheDir) {
|
|
10
|
+
return getWorkspaceCachePath(workspacePath, globalCacheDir);
|
|
11
|
+
}
|
|
12
|
+
|
|
21
13
|
|
|
22
|
-
// MCP Tool definition
|
|
23
14
|
export function getToolDefinition() {
|
|
24
15
|
return {
|
|
25
16
|
name: 'f_set_workspace',
|
|
@@ -50,10 +41,7 @@ export function getToolDefinition() {
|
|
|
50
41
|
};
|
|
51
42
|
}
|
|
52
43
|
|
|
53
|
-
|
|
54
|
-
* Create the SetWorkspace feature class
|
|
55
|
-
* This needs access to shared state (config, cache, indexer) to actually perform the switch
|
|
56
|
-
*/
|
|
44
|
+
|
|
57
45
|
export class SetWorkspaceFeature {
|
|
58
46
|
constructor(config, cache, indexer, getGlobalCacheDir) {
|
|
59
47
|
this.config = config;
|
|
@@ -63,7 +51,7 @@ export class SetWorkspaceFeature {
|
|
|
63
51
|
}
|
|
64
52
|
|
|
65
53
|
async execute({ workspacePath, reindex = true }) {
|
|
66
|
-
|
|
54
|
+
|
|
67
55
|
if (!workspacePath || typeof workspacePath !== 'string') {
|
|
68
56
|
return {
|
|
69
57
|
success: false,
|
|
@@ -73,7 +61,7 @@ export class SetWorkspaceFeature {
|
|
|
73
61
|
|
|
74
62
|
const normalizedPath = path.resolve(workspacePath);
|
|
75
63
|
|
|
76
|
-
|
|
64
|
+
|
|
77
65
|
try {
|
|
78
66
|
const stat = await fs.stat(normalizedPath);
|
|
79
67
|
if (!stat.isDirectory()) {
|
|
@@ -92,14 +80,14 @@ export class SetWorkspaceFeature {
|
|
|
92
80
|
const previousWorkspace = this.config.searchDirectory;
|
|
93
81
|
const previousCache = this.config.cacheDirectory;
|
|
94
82
|
|
|
95
|
-
|
|
83
|
+
|
|
96
84
|
this.config.searchDirectory = normalizedPath;
|
|
97
85
|
|
|
98
|
-
|
|
86
|
+
|
|
99
87
|
const globalCacheDir = this.getGlobalCacheDir();
|
|
100
88
|
let newCacheDir = getWorkspaceCacheDir(normalizedPath, globalCacheDir);
|
|
101
89
|
|
|
102
|
-
|
|
90
|
+
|
|
103
91
|
const legacyPath = path.join(normalizedPath, '.smart-coding-cache');
|
|
104
92
|
try {
|
|
105
93
|
const legacyStats = await fs.stat(legacyPath);
|
|
@@ -107,15 +95,15 @@ export class SetWorkspaceFeature {
|
|
|
107
95
|
newCacheDir = legacyPath;
|
|
108
96
|
}
|
|
109
97
|
} catch {
|
|
110
|
-
|
|
98
|
+
|
|
111
99
|
}
|
|
112
100
|
this.config.cacheDirectory = newCacheDir;
|
|
113
101
|
|
|
114
|
-
|
|
102
|
+
|
|
115
103
|
try {
|
|
116
104
|
await fs.mkdir(newCacheDir, { recursive: true });
|
|
117
105
|
} catch (err) {
|
|
118
|
-
|
|
106
|
+
|
|
119
107
|
this.config.searchDirectory = previousWorkspace;
|
|
120
108
|
this.config.cacheDirectory = previousCache;
|
|
121
109
|
return {
|
|
@@ -124,13 +112,13 @@ export class SetWorkspaceFeature {
|
|
|
124
112
|
};
|
|
125
113
|
}
|
|
126
114
|
|
|
127
|
-
|
|
115
|
+
|
|
128
116
|
const lock = await acquireWorkspaceLock({
|
|
129
117
|
cacheDirectory: newCacheDir,
|
|
130
118
|
workspaceDir: normalizedPath,
|
|
131
119
|
});
|
|
132
120
|
if (!lock.acquired) {
|
|
133
|
-
|
|
121
|
+
|
|
134
122
|
this.config.searchDirectory = previousWorkspace;
|
|
135
123
|
this.config.cacheDirectory = previousCache;
|
|
136
124
|
return {
|
|
@@ -140,7 +128,7 @@ export class SetWorkspaceFeature {
|
|
|
140
128
|
}
|
|
141
129
|
let indexerUpdateError = null;
|
|
142
130
|
|
|
143
|
-
|
|
131
|
+
|
|
144
132
|
if (this.indexer) {
|
|
145
133
|
if (typeof this.indexer.terminateWorkers === 'function') {
|
|
146
134
|
try {
|
|
@@ -154,7 +142,7 @@ export class SetWorkspaceFeature {
|
|
|
154
142
|
await this.indexer.updateWorkspaceState({ restartWatcher: true });
|
|
155
143
|
} else {
|
|
156
144
|
this.indexer.workspaceRoot = normalizedPath;
|
|
157
|
-
this.indexer.workspaceRootReal = null;
|
|
145
|
+
this.indexer.workspaceRootReal = null;
|
|
158
146
|
if (this.config.watchFiles && typeof this.indexer.setupFileWatcher === 'function') {
|
|
159
147
|
await this.indexer.setupFileWatcher();
|
|
160
148
|
}
|
|
@@ -165,7 +153,7 @@ export class SetWorkspaceFeature {
|
|
|
165
153
|
}
|
|
166
154
|
|
|
167
155
|
if (indexerUpdateError) {
|
|
168
|
-
|
|
156
|
+
|
|
169
157
|
this.config.searchDirectory = previousWorkspace;
|
|
170
158
|
this.config.cacheDirectory = previousCache;
|
|
171
159
|
await releaseWorkspaceLock({ cacheDirectory: newCacheDir });
|
|
@@ -192,12 +180,12 @@ export class SetWorkspaceFeature {
|
|
|
192
180
|
};
|
|
193
181
|
}
|
|
194
182
|
|
|
195
|
-
|
|
183
|
+
|
|
196
184
|
if (previousCache) {
|
|
197
185
|
await releaseWorkspaceLock({ cacheDirectory: previousCache });
|
|
198
186
|
}
|
|
199
187
|
|
|
200
|
-
|
|
188
|
+
|
|
201
189
|
if (this.cache && typeof this.cache.load === 'function') {
|
|
202
190
|
try {
|
|
203
191
|
await this.cache.load();
|
|
@@ -206,11 +194,11 @@ export class SetWorkspaceFeature {
|
|
|
206
194
|
}
|
|
207
195
|
}
|
|
208
196
|
|
|
209
|
-
|
|
197
|
+
|
|
210
198
|
let reindexStatus = null;
|
|
211
199
|
if (reindex && this.indexer && typeof this.indexer.indexAll === 'function') {
|
|
212
200
|
try {
|
|
213
|
-
|
|
201
|
+
|
|
214
202
|
this.indexer.indexAll().catch((err) => {
|
|
215
203
|
console.warn(`[SetWorkspace] Reindex failed: ${err.message}`);
|
|
216
204
|
});
|
|
@@ -232,7 +220,7 @@ export class SetWorkspaceFeature {
|
|
|
232
220
|
}
|
|
233
221
|
}
|
|
234
222
|
|
|
235
|
-
|
|
223
|
+
|
|
236
224
|
export function createHandleToolCall(featureInstance) {
|
|
237
225
|
return async (request) => {
|
|
238
226
|
const args = request.params?.arguments || {};
|
|
@@ -240,7 +228,7 @@ export function createHandleToolCall(featureInstance) {
|
|
|
240
228
|
|
|
241
229
|
const result = await featureInstance.execute({
|
|
242
230
|
workspacePath,
|
|
243
|
-
reindex: reindex !== false,
|
|
231
|
+
reindex: reindex !== false,
|
|
244
232
|
});
|
|
245
233
|
|
|
246
234
|
if (result.success) {
|
|
@@ -261,5 +249,5 @@ export function createHandleToolCall(featureInstance) {
|
|
|
261
249
|
};
|
|
262
250
|
}
|
|
263
251
|
|
|
264
|
-
|
|
252
|
+
|
|
265
253
|
export { getWorkspaceCacheDir };
|