@softerist/heuristic-mcp 3.2.3 → 3.2.5
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 +387 -376
- package/config.jsonc +800 -800
- package/features/ann-config.js +102 -110
- package/features/clear-cache.js +81 -84
- package/features/find-similar-code.js +265 -286
- package/features/hybrid-search.js +487 -536
- package/features/index-codebase.js +3146 -3271
- package/features/lifecycle.js +1011 -1063
- package/features/package-version.js +277 -291
- package/features/register.js +351 -370
- package/features/resources.js +115 -130
- package/features/set-workspace.js +214 -240
- package/index.js +788 -781
- package/lib/cache-ops.js +22 -22
- package/lib/cache-utils.js +465 -519
- package/lib/cache.js +1749 -1849
- package/lib/call-graph.js +396 -396
- package/lib/cli.js +232 -226
- package/lib/config.js +1483 -1495
- package/lib/constants.js +511 -493
- package/lib/embed-query-process.js +206 -212
- package/lib/embedding-process.js +434 -451
- package/lib/embedding-worker.js +862 -934
- package/lib/ignore-patterns.js +276 -316
- package/lib/json-worker.js +14 -14
- package/lib/json-writer.js +302 -310
- package/lib/logging.js +133 -127
- package/lib/memory-logger.js +13 -13
- package/lib/onnx-backend.js +188 -193
- package/lib/path-utils.js +18 -23
- package/lib/project-detector.js +82 -84
- package/lib/server-lifecycle.js +164 -147
- package/lib/settings-editor.js +738 -739
- package/lib/slice-normalize.js +25 -31
- package/lib/tokenizer.js +168 -203
- package/lib/utils.js +364 -409
- package/lib/vector-store-binary.js +973 -991
- package/lib/vector-store-sqlite.js +377 -414
- package/lib/workspace-env.js +32 -34
- package/mcp_config.json +9 -9
- package/package.json +86 -86
- package/scripts/clear-cache.js +20 -20
- package/scripts/download-model.js +43 -43
- package/scripts/mcp-launcher.js +49 -49
- package/scripts/postinstall.js +12 -12
- package/search-configs.js +36 -36
package/features/resources.js
CHANGED
|
@@ -1,130 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
contents: [
|
|
119
|
-
{
|
|
120
|
-
uri,
|
|
121
|
-
mimeType: getMimeType(path.extname(filePath)),
|
|
122
|
-
text: content,
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
};
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.error(`[Resources] Error reading resource ${uri}: ${error.message}`);
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fdir } from 'fdir';
|
|
4
|
+
import { getMimeType } from '../lib/constants.js';
|
|
5
|
+
|
|
6
|
+
function pathToUri(filePath) {
|
|
7
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
8
|
+
|
|
9
|
+
if (/^[a-zA-Z]:/.test(normalized)) {
|
|
10
|
+
return `file:///${normalized}`;
|
|
11
|
+
}
|
|
12
|
+
return `file://${normalized}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function uriToPath(uri) {
|
|
16
|
+
if (!uri.startsWith('file://')) {
|
|
17
|
+
throw new Error(`Invalid file URI: ${uri}`);
|
|
18
|
+
}
|
|
19
|
+
let filePath = uri.slice(7);
|
|
20
|
+
|
|
21
|
+
if (/^\/[a-zA-Z]:/.test(filePath)) {
|
|
22
|
+
filePath = filePath.slice(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
filePath = decodeURIComponent(filePath);
|
|
26
|
+
|
|
27
|
+
if (process.platform === 'win32') {
|
|
28
|
+
filePath = filePath.replace(/\//g, '\\');
|
|
29
|
+
}
|
|
30
|
+
return filePath;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isWithinWorkspace(filePath, workspaceDir) {
|
|
34
|
+
const resolvedPath = path.resolve(filePath);
|
|
35
|
+
const resolvedWorkspace = path.resolve(workspaceDir);
|
|
36
|
+
const relativePath = path.relative(resolvedWorkspace, resolvedPath);
|
|
37
|
+
return !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function handleListResources(config) {
|
|
41
|
+
const workspaceDir = config.searchDirectory;
|
|
42
|
+
const maxResults = 500;
|
|
43
|
+
|
|
44
|
+
const allowedExtensions = new Set(
|
|
45
|
+
(config.fileExtensions || []).map((ext) => `.${ext.toLowerCase()}`)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const excludedDirs = new Set();
|
|
49
|
+
for (const pattern of config.excludePatterns || []) {
|
|
50
|
+
const match = pattern.match(/(?:\*\*\/)?([^/*]+)(?:\/\*\*)?$/);
|
|
51
|
+
if (match && match[1] && !match[1].includes('*')) {
|
|
52
|
+
excludedDirs.add(match[1]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const crawler = new fdir()
|
|
58
|
+
.withBasePath()
|
|
59
|
+
.withMaxDepth(10)
|
|
60
|
+
.exclude((dirName) => {
|
|
61
|
+
return excludedDirs.has(dirName);
|
|
62
|
+
})
|
|
63
|
+
.filter((filePath) => {
|
|
64
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
65
|
+
return allowedExtensions.has(ext);
|
|
66
|
+
})
|
|
67
|
+
.crawl(workspaceDir);
|
|
68
|
+
|
|
69
|
+
const files = await crawler.withPromise();
|
|
70
|
+
const limitedFiles = files.slice(0, maxResults);
|
|
71
|
+
|
|
72
|
+
const resources = limitedFiles.map((filePath) => {
|
|
73
|
+
const relativePath = path.relative(workspaceDir, filePath);
|
|
74
|
+
return {
|
|
75
|
+
uri: pathToUri(filePath),
|
|
76
|
+
name: relativePath.replace(/\\/g, '/'),
|
|
77
|
+
mimeType: getMimeType(path.extname(filePath)),
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return { resources };
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(`[Resources] Error listing resources: ${error.message}`);
|
|
84
|
+
return { resources: [] };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function handleReadResource(uri, config) {
|
|
89
|
+
const workspaceDir = config.searchDirectory;
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const filePath = uriToPath(uri);
|
|
93
|
+
|
|
94
|
+
if (!isWithinWorkspace(filePath, workspaceDir)) {
|
|
95
|
+
throw new Error(`Access denied: ${uri} is outside workspace`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
await fs.access(filePath);
|
|
99
|
+
|
|
100
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
contents: [
|
|
104
|
+
{
|
|
105
|
+
uri,
|
|
106
|
+
mimeType: getMimeType(path.extname(filePath)),
|
|
107
|
+
text: content,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error(`[Resources] Error reading resource ${uri}: ${error.message}`);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|