@softerist/heuristic-mcp 2.1.47 → 3.0.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/.agent/workflows/code-review.md +60 -0
- package/.prettierrc +7 -0
- package/ARCHITECTURE.md +105 -170
- package/CONTRIBUTING.md +32 -113
- package/GEMINI.md +73 -0
- package/LICENSE +21 -21
- package/README.md +161 -54
- package/config.json +876 -75
- package/debug-pids.js +27 -0
- package/eslint.config.js +36 -0
- package/features/ann-config.js +37 -26
- package/features/clear-cache.js +28 -19
- package/features/find-similar-code.js +142 -66
- package/features/hybrid-search.js +253 -93
- package/features/index-codebase.js +1455 -394
- package/features/lifecycle.js +813 -180
- package/features/register.js +58 -52
- package/index.js +450 -306
- package/lib/cache-ops.js +22 -0
- package/lib/cache-utils.js +68 -0
- package/lib/cache.js +1392 -587
- package/lib/call-graph.js +165 -50
- package/lib/cli.js +154 -0
- package/lib/config.js +462 -121
- package/lib/embedding-process.js +77 -0
- package/lib/embedding-worker.js +545 -30
- package/lib/ignore-patterns.js +61 -59
- package/lib/json-worker.js +14 -0
- package/lib/json-writer.js +344 -0
- package/lib/logging.js +88 -0
- package/lib/memory-logger.js +13 -0
- package/lib/project-detector.js +13 -17
- package/lib/server-lifecycle.js +38 -0
- package/lib/settings-editor.js +645 -0
- package/lib/tokenizer.js +207 -104
- package/lib/utils.js +273 -198
- package/lib/vector-store-binary.js +592 -0
- package/mcp_config.example.json +13 -0
- package/package.json +13 -2
- package/scripts/clear-cache.js +6 -17
- package/scripts/download-model.js +14 -9
- package/scripts/postinstall.js +5 -5
- package/search-configs.js +36 -0
- package/test/ann-config.test.js +179 -0
- package/test/ann-fallback.test.js +6 -6
- package/test/binary-store.test.js +69 -0
- package/test/cache-branches.test.js +120 -0
- package/test/cache-errors.test.js +264 -0
- package/test/cache-extra.test.js +300 -0
- package/test/cache-helpers.test.js +205 -0
- package/test/cache-hnsw-failure.test.js +40 -0
- package/test/cache-json-worker.test.js +190 -0
- package/test/cache-worker.test.js +102 -0
- package/test/cache.test.js +443 -0
- package/test/call-graph.test.js +103 -4
- package/test/clear-cache.test.js +69 -68
- package/test/code-review-workflow.test.js +50 -0
- package/test/config.test.js +418 -0
- package/test/coverage-gap.test.js +497 -0
- package/test/coverage-maximizer.test.js +236 -0
- package/test/debug-analysis.js +107 -0
- package/test/embedding-model.test.js +173 -103
- package/test/embedding-worker-extra.test.js +272 -0
- package/test/embedding-worker.test.js +158 -0
- package/test/features.test.js +139 -0
- package/test/final-boost.test.js +271 -0
- package/test/final-polish.test.js +183 -0
- package/test/final.test.js +95 -0
- package/test/find-similar-code.test.js +191 -0
- package/test/helpers.js +92 -11
- package/test/helpers.test.js +46 -0
- package/test/hybrid-search-basic.test.js +62 -0
- package/test/hybrid-search-branch.test.js +202 -0
- package/test/hybrid-search-callgraph.test.js +229 -0
- package/test/hybrid-search-extra.test.js +81 -0
- package/test/hybrid-search.test.js +484 -71
- package/test/index-cli.test.js +520 -0
- package/test/index-codebase-batch.test.js +119 -0
- package/test/index-codebase-branches.test.js +585 -0
- package/test/index-codebase-core.test.js +1032 -0
- package/test/index-codebase-edge-cases.test.js +254 -0
- package/test/index-codebase-errors.test.js +132 -0
- package/test/index-codebase-gap.test.js +239 -0
- package/test/index-codebase-lines.test.js +151 -0
- package/test/index-codebase-watcher.test.js +259 -0
- package/test/index-codebase-zone.test.js +259 -0
- package/test/index-codebase.test.js +371 -69
- package/test/index-memory.test.js +220 -0
- package/test/indexer-detailed.test.js +176 -0
- package/test/integration.test.js +148 -92
- package/test/json-worker.test.js +50 -0
- package/test/lifecycle.test.js +541 -0
- package/test/master.test.js +198 -0
- package/test/perfection.test.js +349 -0
- package/test/project-detector.test.js +65 -0
- package/test/register.test.js +262 -0
- package/test/tokenizer.test.js +55 -93
- package/test/ultra-maximizer.test.js +116 -0
- package/test/utils-branches.test.js +161 -0
- package/test/utils-extra.test.js +116 -0
- package/test/utils.test.js +131 -0
- package/test/verify_fixes.js +76 -0
- package/test/worker-errors.test.js +96 -0
- package/test/worker-init.test.js +102 -0
- package/test/worker_throttling.test.js +93 -0
- package/tools/scripts/benchmark-search.js +95 -0
- package/tools/scripts/cache-stats.js +71 -0
- package/tools/scripts/manual-search.js +34 -0
- package/vitest.config.js +19 -9
package/lib/cache-ops.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import { loadConfig } from './config.js';
|
|
3
|
+
import { clearStaleCaches } from './cache-utils.js';
|
|
4
|
+
|
|
5
|
+
export async function clearCache(workspaceDir) {
|
|
6
|
+
const effectiveWorkspace = workspaceDir || process.cwd();
|
|
7
|
+
const activeConfig = await loadConfig(effectiveWorkspace);
|
|
8
|
+
|
|
9
|
+
if (!activeConfig.enableCache) {
|
|
10
|
+
console.info('[Cache] Cache disabled (enableCache=false); nothing to clear.');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
await fs.rm(activeConfig.cacheDirectory, { recursive: true, force: true });
|
|
16
|
+
console.info(`[Cache] Cleared cache directory: ${activeConfig.cacheDirectory}`);
|
|
17
|
+
await clearStaleCaches();
|
|
18
|
+
} catch (err) {
|
|
19
|
+
console.error(`[Cache] Failed to clear cache: ${err.message}`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getGlobalCacheDir } from './config.js';
|
|
4
|
+
|
|
5
|
+
export async function clearStaleCaches({ maxAgeMs = 6 * 60 * 60 * 1000, logger = console } = {}) {
|
|
6
|
+
const globalCacheRoot = path.join(getGlobalCacheDir(), 'heuristic-mcp');
|
|
7
|
+
const cacheDirs = await fs.readdir(globalCacheRoot).catch(() => []);
|
|
8
|
+
if (cacheDirs.length === 0) return 0;
|
|
9
|
+
|
|
10
|
+
const now = Date.now();
|
|
11
|
+
let removed = 0;
|
|
12
|
+
|
|
13
|
+
for (const dir of cacheDirs) {
|
|
14
|
+
const cacheDir = path.join(globalCacheRoot, dir);
|
|
15
|
+
const metaFile = path.join(cacheDir, 'meta.json');
|
|
16
|
+
try {
|
|
17
|
+
await fs.access(metaFile);
|
|
18
|
+
continue; // valid cache with metadata
|
|
19
|
+
} catch (err) {
|
|
20
|
+
if (err.code !== 'ENOENT') continue;
|
|
21
|
+
try {
|
|
22
|
+
const stats = await fs.stat(cacheDir);
|
|
23
|
+
const ageMs = now - stats.mtimeMs;
|
|
24
|
+
if (ageMs < maxAgeMs) {
|
|
25
|
+
continue; // likely indexing in progress
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let progressAgeMs = null;
|
|
29
|
+
const progressFile = path.join(cacheDir, 'progress.json');
|
|
30
|
+
try {
|
|
31
|
+
const raw = await fs.readFile(progressFile, 'utf-8');
|
|
32
|
+
const data = JSON.parse(raw);
|
|
33
|
+
const updatedAt = Date.parse(data?.updatedAt);
|
|
34
|
+
if (Number.isFinite(updatedAt)) {
|
|
35
|
+
progressAgeMs = now - updatedAt;
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
// ignore progress read errors
|
|
39
|
+
}
|
|
40
|
+
if (progressAgeMs === null) {
|
|
41
|
+
try {
|
|
42
|
+
const progressStats = await fs.stat(progressFile);
|
|
43
|
+
progressAgeMs = now - progressStats.mtimeMs;
|
|
44
|
+
} catch {
|
|
45
|
+
// no progress file
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (progressAgeMs !== null && progressAgeMs < maxAgeMs) {
|
|
50
|
+
continue; // progress updated recently
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await fs.rm(cacheDir, { recursive: true, force: true });
|
|
54
|
+
removed++;
|
|
55
|
+
} catch {
|
|
56
|
+
// ignore failures per dir
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (removed > 0) {
|
|
62
|
+
logger.info(
|
|
63
|
+
`[Cache] Removed ${removed} stale cache director${removed === 1 ? 'y' : 'ies'}.`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return removed;
|
|
68
|
+
}
|