mcp-code-context 3.5.2 → 3.6.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 +57 -3
- package/HIRE_ME.md +234 -0
- package/INSTRUCTIONS.md +274 -0
- package/README.md +486 -304
- package/SECURITY.md +14 -14
- package/SPONSORS.md +104 -0
- package/dist/src/core/cacheManager.d.ts +44 -0
- package/dist/src/core/cacheManager.js +255 -0
- package/dist/src/core/cacheManager.js.map +1 -0
- package/dist/src/core/engine.d.ts +1 -1
- package/dist/src/core/engine.js +1 -1
- package/dist/src/core/validator.d.ts +1 -1
- package/dist/src/core/validator.js +21 -9
- package/dist/src/core/validator.js.map +1 -1
- package/dist/src/index.d.ts +6 -1
- package/dist/src/index.js +197 -20
- package/dist/src/index.js.map +1 -1
- package/dist/src/operations/compress.d.ts +3 -1
- package/dist/src/operations/compress.js +47 -48
- package/dist/src/operations/compress.js.map +1 -1
- package/dist/src/operations/confirmationStore.d.ts +1 -1
- package/dist/src/operations/confirmationStore.js +1 -1
- package/dist/src/operations/read.d.ts +5 -1
- package/dist/src/operations/read.js +129 -60
- package/dist/src/operations/read.js.map +1 -1
- package/dist/src/operations/write.d.ts +2 -2
- package/dist/src/operations/write.js +83 -59
- package/dist/src/operations/write.js.map +1 -1
- package/dist/src/parsers/base.d.ts +1 -1
- package/dist/src/parsers/base.js +1 -1
- package/dist/src/parsers/dartTreeSitter.d.ts +1 -1
- package/dist/src/parsers/dartTreeSitter.js +1 -1
- package/dist/src/parsers/php.d.ts +1 -1
- package/dist/src/parsers/php.js +1 -1
- package/dist/src/parsers/python.d.ts +1 -1
- package/dist/src/parsers/python.js +1 -1
- package/dist/src/parsers/registry.d.ts +1 -1
- package/dist/src/parsers/registry.js +1 -1
- package/dist/src/parsers/typescript.d.ts +1 -1
- package/dist/src/parsers/typescript.js +1 -1
- package/dist/src/utils/auditLogger.d.ts +1 -1
- package/dist/src/utils/auditLogger.js +3 -2
- package/dist/src/utils/auditLogger.js.map +1 -1
- package/dist/src/utils/backupManager.d.ts +30 -9
- package/dist/src/utils/backupManager.js +75 -33
- package/dist/src/utils/backupManager.js.map +1 -1
- package/dist/src/utils/constants.d.ts +13 -2
- package/dist/src/utils/constants.js +21 -2
- package/dist/src/utils/constants.js.map +1 -1
- package/dist/src/utils/diff.d.ts +37 -7
- package/dist/src/utils/diff.js +91 -101
- package/dist/src/utils/diff.js.map +1 -1
- package/dist/src/utils/fileLock.d.ts +25 -50
- package/dist/src/utils/fileLock.js +66 -100
- package/dist/src/utils/fileLock.js.map +1 -1
- package/dist/src/utils/fileWalker.d.ts +28 -0
- package/dist/src/utils/fileWalker.js +57 -0
- package/dist/src/utils/fileWalker.js.map +1 -0
- package/dist/src/utils/fileWatcher.d.ts +23 -0
- package/dist/src/utils/fileWatcher.js +80 -0
- package/dist/src/utils/fileWatcher.js.map +1 -0
- package/dist/src/utils/fuzzySearch.d.ts +22 -0
- package/dist/src/utils/fuzzySearch.js +36 -0
- package/dist/src/utils/fuzzySearch.js.map +1 -0
- package/dist/src/utils/logger.d.ts +19 -0
- package/dist/src/utils/logger.js +50 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/rateLimiter.d.ts +1 -1
- package/dist/src/utils/rateLimiter.js +1 -1
- package/dist/src/utils/safeRegex.d.ts +1 -1
- package/dist/src/utils/safeRegex.js +1 -1
- package/dist/src/utils/searchTools.d.ts +14 -0
- package/dist/src/utils/searchTools.js +94 -0
- package/dist/src/utils/searchTools.js.map +1 -0
- package/dist/src/utils/streaming.d.ts +1 -1
- package/dist/src/utils/streaming.js +1 -1
- package/dist/src/utils/telemetry.d.ts +1 -1
- package/dist/src/utils/telemetry.js +1 -1
- package/llms.txt +5 -5
- package/package.json +44 -11
- package/vitest.config.ts +37 -0
- package/CHANGELOG_v3.2.0.md +0 -196
- package/CHANGELOG_v3.3.0.md +0 -266
package/SECURITY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Security Policy - mcp-code-context v3.
|
|
1
|
+
# Security Policy - mcp-code-context v3.6.0
|
|
2
2
|
|
|
3
|
-
## 🔒 Security Improvements in v3.
|
|
3
|
+
## 🔒 Security Improvements in v3.6.0
|
|
4
4
|
|
|
5
5
|
This release addresses **all critical security vulnerabilities** from comprehensive adversarial audit, implements full middleware pipeline, and hardens all 13 tool handlers.
|
|
6
6
|
|
|
@@ -10,11 +10,11 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
10
10
|
|
|
11
11
|
### 1. Path Traversal (HIGH)
|
|
12
12
|
**CVSS Score**: 8.1 (High)
|
|
13
|
-
**Status**: ✅ FIXED in v3.2.0, **hardened in v3.
|
|
13
|
+
**Status**: ✅ FIXED in v3.2.0, **hardened in v3.6.0**
|
|
14
14
|
|
|
15
15
|
**Description**: Path traversal check occurred BEFORE path normalization, allowing bypass with absolute paths.
|
|
16
16
|
|
|
17
|
-
**Fix**: Check boundary AFTER `path.resolve()` normalization. In v3.
|
|
17
|
+
**Fix**: Check boundary AFTER `path.resolve()` normalization. In v3.6.0, **all 13 handlers** now require `projectRoot` and validate via `SecurityValidator`.
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -40,7 +40,7 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
40
40
|
|
|
41
41
|
### 4. ReDoS in searchPattern and readLines (MEDIUM)
|
|
42
42
|
**CVSS Score**: 5.3 (Medium)
|
|
43
|
-
**Status**: ✅ FIXED in v3.
|
|
43
|
+
**Status**: ✅ FIXED in v3.6.0
|
|
44
44
|
|
|
45
45
|
**Description**: User-provided regex patterns could cause catastrophic backtracking.
|
|
46
46
|
|
|
@@ -58,7 +58,7 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
58
58
|
|
|
59
59
|
### 6. extractSymbol API Mismatch (CRITICAL)
|
|
60
60
|
**CVSS Score**: 9.0 (Critical)
|
|
61
|
-
**Status**: ✅ FIXED in v3.
|
|
61
|
+
**Status**: ✅ FIXED in v3.6.0
|
|
62
62
|
|
|
63
63
|
**Description**: `read.ts` passed `content` as `symbolName` and real `symbolName` as `className`. Symbol extraction was 100% broken.
|
|
64
64
|
|
|
@@ -68,7 +68,7 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
68
68
|
|
|
69
69
|
### 7. Handlers Without Path Validation (HIGH)
|
|
70
70
|
**CVSS Score**: 8.5 (High)
|
|
71
|
-
**Status**: ✅ FIXED in v3.
|
|
71
|
+
**Status**: ✅ FIXED in v3.6.0
|
|
72
72
|
|
|
73
73
|
**Description**: `readLines`, `searchPattern`, `analyzeImpact`, `getSemanticRepoMap` had no path boundary check.
|
|
74
74
|
|
|
@@ -78,7 +78,7 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
78
78
|
|
|
79
79
|
### 8. renameSymbol Arbitrary Write (HIGH)
|
|
80
80
|
**CVSS Score**: 8.0 (High)
|
|
81
|
-
**Status**: ✅ FIXED in v3.
|
|
81
|
+
**Status**: ✅ FIXED in v3.6.0
|
|
82
82
|
|
|
83
83
|
**Description**: `renameSymbol` wrote dependent files without SecurityValidator check, using non-atomic writes.
|
|
84
84
|
|
|
@@ -88,7 +88,7 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
88
88
|
|
|
89
89
|
### 9. LCS Diff OOM (MEDIUM)
|
|
90
90
|
**CVSS Score**: 5.0 (Medium)
|
|
91
|
-
**Status**: ✅ FIXED in v3.
|
|
91
|
+
**Status**: ✅ FIXED in v3.6.0
|
|
92
92
|
|
|
93
93
|
**Description**: LCS diff algorithm is O(n²) memory — 10K-line files cause OOM.
|
|
94
94
|
|
|
@@ -101,16 +101,16 @@ This release addresses **all critical security vulnerabilities** from comprehens
|
|
|
101
101
|
### Defense in Depth
|
|
102
102
|
|
|
103
103
|
1. **Input Validation**
|
|
104
|
-
- Path boundary enforcement on ALL handlers (v3.
|
|
104
|
+
- Path boundary enforcement on ALL handlers (v3.6.0)
|
|
105
105
|
- File size limits (10MB per file, 50MB total)
|
|
106
106
|
- Regex sanitization + timeout (1s limit)
|
|
107
107
|
|
|
108
|
-
2. **Two-Phase Write Workflow** (v3.
|
|
108
|
+
2. **Two-Phase Write Workflow** (v3.6.0)
|
|
109
109
|
- Phase 1: Dry-run returns diff + confirmation token
|
|
110
110
|
- Phase 2: Apply with token (5-minute expiry)
|
|
111
111
|
- Max 50 pending operations
|
|
112
112
|
|
|
113
|
-
3. **Middleware Pipeline** (v3.
|
|
113
|
+
3. **Middleware Pipeline** (v3.6.0)
|
|
114
114
|
- Rate limiting (token bucket per operation)
|
|
115
115
|
- File locking (prevents concurrent writes)
|
|
116
116
|
- Audit logging (persistent `.mcp-audit-logs/`)
|
|
@@ -160,7 +160,7 @@ node dist-tests/tests/test-security.js
|
|
|
160
160
|
- [x] Syntax validation
|
|
161
161
|
- [x] Bounded memory in compress
|
|
162
162
|
|
|
163
|
-
### v3.
|
|
163
|
+
### v3.6.0 ✅
|
|
164
164
|
- [x] Regex timeout enforcement (safeRegexTest)
|
|
165
165
|
- [x] Rate limiting (token bucket)
|
|
166
166
|
- [x] File locking (concurrent write prevention)
|
|
@@ -174,4 +174,4 @@ node dist-tests/tests/test-security.js
|
|
|
174
174
|
---
|
|
175
175
|
|
|
176
176
|
**Last Updated**: 2026-04-24
|
|
177
|
-
**Version**: 3.
|
|
177
|
+
**Version**: 3.6.0
|
package/SPONSORS.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Sponsors & Supporters
|
|
2
|
+
|
|
3
|
+
Thank you to everyone who supports mcp-code-context! 🙏
|
|
4
|
+
|
|
5
|
+
Your contributions help keep this project:
|
|
6
|
+
- ✅ Free and open source
|
|
7
|
+
- ✅ Actively maintained
|
|
8
|
+
- ✅ Continuously improved
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 💎 Diamond Sponsors ($100+/month)
|
|
13
|
+
|
|
14
|
+
*(No sponsors yet - be the first!)*
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 🥇 Gold Sponsors ($50-99/month)
|
|
19
|
+
|
|
20
|
+
*(No sponsors yet)*
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 🥈 Silver Sponsors ($25-49/month)
|
|
25
|
+
|
|
26
|
+
*(No sponsors yet)*
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 🥉 Bronze Supporters ($5-24/month)
|
|
31
|
+
|
|
32
|
+
*(No sponsors yet)*
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## ☕ One-Time Contributors
|
|
37
|
+
|
|
38
|
+
*(No contributors yet - be the first!)*
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 🌟 How to Become a Sponsor
|
|
43
|
+
|
|
44
|
+
See the [Support This Project](#support-this-project) section in the [README](README.md#support-this-project).
|
|
45
|
+
|
|
46
|
+
### Available Options:
|
|
47
|
+
|
|
48
|
+
**Monthly Memberships** (Ko-fi):
|
|
49
|
+
- **$5/month** - Supporter: Name in SPONSORS.md + Early access to release notes
|
|
50
|
+
- **$25/month** - Contributor: Priority support + Early access to features + Vote on roadmap
|
|
51
|
+
- **$100/month** - Sponsor: Feature requests + Monthly consultation + Logo in README
|
|
52
|
+
|
|
53
|
+
**One-Time Donations**:
|
|
54
|
+
- **Ko-fi**: https://ko-fi.com/achatainga
|
|
55
|
+
- **PayPal**: https://paypal.me/achatainga
|
|
56
|
+
- **Binance (USDT)**: See README for addresses
|
|
57
|
+
|
|
58
|
+
- **TRC20**: `0xa68d53f7853ce0175eb96aaad4a30c068ca96444`
|
|
59
|
+
- **ERC20**: `0xa68d53f7853ce0175eb96aaad4a30c068ca96444`
|
|
60
|
+
- **Binance Pay ID**: `367669339`
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 📊 Transparency Report
|
|
65
|
+
|
|
66
|
+
### April 2025
|
|
67
|
+
- **Monthly Donations**: $0
|
|
68
|
+
- **One-Time Donations**: $0
|
|
69
|
+
- **Total Supporters**: 0
|
|
70
|
+
- **Expenses**: ~$20 (npm registry, testing credits, domain)
|
|
71
|
+
- **Time Invested**: ~40 hours
|
|
72
|
+
- **Net**: -$20
|
|
73
|
+
|
|
74
|
+
*(Updated monthly)*
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 💼 Hire Me
|
|
79
|
+
|
|
80
|
+
Need custom MCP tools or AI integrations?
|
|
81
|
+
|
|
82
|
+
- **Rate**: $50-75/hour
|
|
83
|
+
- **Email**: a.chataing.a@gmail.com
|
|
84
|
+
- **Details**: [HIRE_ME.md](HIRE_ME.md)
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## ❤️ Non-Financial Support
|
|
89
|
+
|
|
90
|
+
Can't donate? No problem! You can still help:
|
|
91
|
+
|
|
92
|
+
- ⭐ Star the repo on GitHub
|
|
93
|
+
- 🐛 Report bugs or suggest features
|
|
94
|
+
- 📝 Improve documentation
|
|
95
|
+
- 🗣️ Share with others who might benefit
|
|
96
|
+
- 💬 Help other users in discussions
|
|
97
|
+
|
|
98
|
+
Every contribution matters, financial or not.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
**Thank you for supporting open source! 🚀**
|
|
103
|
+
|
|
104
|
+
*Built with ❤️ from Caracas, Venezuela 🇻🇪*
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Manager - v3.6.0
|
|
3
|
+
* WASM SQLite cache with debounced persistence
|
|
4
|
+
*/
|
|
5
|
+
export interface CachedFile {
|
|
6
|
+
filePath: string;
|
|
7
|
+
hash: string;
|
|
8
|
+
symbols: any[];
|
|
9
|
+
lastModified: number;
|
|
10
|
+
cachedAt: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class CacheManager {
|
|
13
|
+
private db;
|
|
14
|
+
private dbPath;
|
|
15
|
+
private cacheDir;
|
|
16
|
+
private isDirty;
|
|
17
|
+
private persistTimer;
|
|
18
|
+
private initPromise;
|
|
19
|
+
private watcher;
|
|
20
|
+
private projectRoot;
|
|
21
|
+
constructor(projectRoot: string);
|
|
22
|
+
private init;
|
|
23
|
+
private initSchema;
|
|
24
|
+
get(filePath: string, currentHash: string): Promise<CachedFile | null>;
|
|
25
|
+
set(file: CachedFile): Promise<void>;
|
|
26
|
+
invalidate(filePath: string): Promise<void>;
|
|
27
|
+
clear(): Promise<void>;
|
|
28
|
+
getStats(): Promise<{
|
|
29
|
+
totalEntries: number;
|
|
30
|
+
totalSize: number;
|
|
31
|
+
oldestEntry: number | null;
|
|
32
|
+
newestEntry: number | null;
|
|
33
|
+
}>;
|
|
34
|
+
private schedulePersist;
|
|
35
|
+
private persist;
|
|
36
|
+
private persistSync;
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
startWatcher(debounceMs?: number): void;
|
|
39
|
+
stopWatcher(): void;
|
|
40
|
+
getWatcherStatus(): {
|
|
41
|
+
isWatching: boolean;
|
|
42
|
+
watchedFiles: number;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Manager - v3.6.0
|
|
3
|
+
* WASM SQLite cache with debounced persistence
|
|
4
|
+
*/
|
|
5
|
+
import initSqlJs from 'sql.js';
|
|
6
|
+
import * as fs from 'node:fs/promises';
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import * as crypto from 'node:crypto';
|
|
10
|
+
import { tmpdir } from 'os';
|
|
11
|
+
import { logger } from '../utils/logger.js';
|
|
12
|
+
import { FileWatcher } from '../utils/fileWatcher.js';
|
|
13
|
+
export class CacheManager {
|
|
14
|
+
db = null;
|
|
15
|
+
dbPath;
|
|
16
|
+
cacheDir;
|
|
17
|
+
isDirty = false;
|
|
18
|
+
persistTimer = null;
|
|
19
|
+
initPromise;
|
|
20
|
+
watcher = null;
|
|
21
|
+
projectRoot;
|
|
22
|
+
constructor(projectRoot) {
|
|
23
|
+
this.projectRoot = projectRoot;
|
|
24
|
+
const projectHash = crypto.createHash('md5')
|
|
25
|
+
.update(projectRoot)
|
|
26
|
+
.digest('hex')
|
|
27
|
+
.substring(0, 8);
|
|
28
|
+
this.cacheDir = path.join(tmpdir(), 'mcp-cache', projectHash);
|
|
29
|
+
this.dbPath = path.join(this.cacheDir, 'cache.db');
|
|
30
|
+
// Initialize on construction
|
|
31
|
+
this.initPromise = this.init();
|
|
32
|
+
// Persist on process exit
|
|
33
|
+
process.on('SIGINT', () => this.persistSync());
|
|
34
|
+
process.on('SIGTERM', () => this.persistSync());
|
|
35
|
+
process.on('exit', () => this.persistSync());
|
|
36
|
+
}
|
|
37
|
+
async init() {
|
|
38
|
+
try {
|
|
39
|
+
// Ensure cache directory exists (OS cleanup recovery)
|
|
40
|
+
if (!existsSync(this.cacheDir)) {
|
|
41
|
+
logger.warn({ cacheDir: this.cacheDir }, 'Cache directory deleted by OS, recreating');
|
|
42
|
+
mkdirSync(this.cacheDir, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
const SQL = await initSqlJs();
|
|
45
|
+
// Load existing database or create new
|
|
46
|
+
if (existsSync(this.dbPath)) {
|
|
47
|
+
const buffer = readFileSync(this.dbPath);
|
|
48
|
+
this.db = new SQL.Database(buffer);
|
|
49
|
+
logger.debug({ dbPath: this.dbPath }, 'Loaded existing cache database');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.db = new SQL.Database();
|
|
53
|
+
this.initSchema();
|
|
54
|
+
logger.info({ dbPath: this.dbPath }, 'Created new cache database');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger.error({ error }, 'Failed to initialize cache');
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
initSchema() {
|
|
63
|
+
if (!this.db)
|
|
64
|
+
return;
|
|
65
|
+
this.db.run(`
|
|
66
|
+
CREATE TABLE IF NOT EXISTS file_cache (
|
|
67
|
+
file_path TEXT PRIMARY KEY,
|
|
68
|
+
hash TEXT NOT NULL,
|
|
69
|
+
symbols TEXT NOT NULL,
|
|
70
|
+
last_modified INTEGER NOT NULL,
|
|
71
|
+
cached_at INTEGER NOT NULL
|
|
72
|
+
)
|
|
73
|
+
`);
|
|
74
|
+
this.db.run(`
|
|
75
|
+
CREATE INDEX IF NOT EXISTS idx_cached_at ON file_cache(cached_at)
|
|
76
|
+
`);
|
|
77
|
+
}
|
|
78
|
+
async get(filePath, currentHash) {
|
|
79
|
+
await this.initPromise;
|
|
80
|
+
if (!this.db)
|
|
81
|
+
return null;
|
|
82
|
+
try {
|
|
83
|
+
const stmt = this.db.prepare('SELECT * FROM file_cache WHERE file_path = ? AND hash = ?');
|
|
84
|
+
stmt.bind([filePath, currentHash]);
|
|
85
|
+
if (stmt.step()) {
|
|
86
|
+
const row = stmt.getAsObject();
|
|
87
|
+
stmt.free();
|
|
88
|
+
return {
|
|
89
|
+
filePath: row.file_path,
|
|
90
|
+
hash: row.hash,
|
|
91
|
+
symbols: JSON.parse(row.symbols),
|
|
92
|
+
lastModified: row.last_modified,
|
|
93
|
+
cachedAt: row.cached_at,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
stmt.free();
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
logger.error({ error, filePath }, 'Cache get failed');
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async set(file) {
|
|
105
|
+
await this.initPromise;
|
|
106
|
+
if (!this.db)
|
|
107
|
+
return;
|
|
108
|
+
try {
|
|
109
|
+
this.db.run(`INSERT OR REPLACE INTO file_cache
|
|
110
|
+
(file_path, hash, symbols, last_modified, cached_at)
|
|
111
|
+
VALUES (?, ?, ?, ?, ?)`, [
|
|
112
|
+
file.filePath,
|
|
113
|
+
file.hash,
|
|
114
|
+
JSON.stringify(file.symbols),
|
|
115
|
+
file.lastModified,
|
|
116
|
+
file.cachedAt,
|
|
117
|
+
]);
|
|
118
|
+
this.isDirty = true;
|
|
119
|
+
this.schedulePersist();
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
logger.error({ error, filePath: file.filePath }, 'Cache set failed');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async invalidate(filePath) {
|
|
126
|
+
await this.initPromise;
|
|
127
|
+
if (!this.db)
|
|
128
|
+
return;
|
|
129
|
+
try {
|
|
130
|
+
this.db.run('DELETE FROM file_cache WHERE file_path = ?', [filePath]);
|
|
131
|
+
this.isDirty = true;
|
|
132
|
+
this.schedulePersist();
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
logger.error({ error, filePath }, 'Cache invalidate failed');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async clear() {
|
|
139
|
+
await this.initPromise;
|
|
140
|
+
if (!this.db)
|
|
141
|
+
return;
|
|
142
|
+
try {
|
|
143
|
+
this.db.run('DELETE FROM file_cache');
|
|
144
|
+
this.isDirty = true;
|
|
145
|
+
await this.persist();
|
|
146
|
+
logger.info('Cache cleared');
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
logger.error({ error }, 'Cache clear failed');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async getStats() {
|
|
153
|
+
await this.initPromise;
|
|
154
|
+
if (!this.db) {
|
|
155
|
+
return { totalEntries: 0, totalSize: 0, oldestEntry: null, newestEntry: null };
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const stmt = this.db.prepare(`
|
|
159
|
+
SELECT
|
|
160
|
+
COUNT(*) as count,
|
|
161
|
+
MIN(cached_at) as oldest,
|
|
162
|
+
MAX(cached_at) as newest
|
|
163
|
+
FROM file_cache
|
|
164
|
+
`);
|
|
165
|
+
stmt.step();
|
|
166
|
+
const row = stmt.getAsObject();
|
|
167
|
+
stmt.free();
|
|
168
|
+
const totalSize = existsSync(this.dbPath)
|
|
169
|
+
? (await fs.stat(this.dbPath)).size
|
|
170
|
+
: 0;
|
|
171
|
+
return {
|
|
172
|
+
totalEntries: row.count,
|
|
173
|
+
totalSize,
|
|
174
|
+
oldestEntry: row.oldest,
|
|
175
|
+
newestEntry: row.newest,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
logger.error({ error }, 'Failed to get cache stats');
|
|
180
|
+
return { totalEntries: 0, totalSize: 0, oldestEntry: null, newestEntry: null };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
schedulePersist() {
|
|
184
|
+
if (this.persistTimer)
|
|
185
|
+
clearTimeout(this.persistTimer);
|
|
186
|
+
this.persistTimer = setTimeout(() => this.persist(), 5000);
|
|
187
|
+
}
|
|
188
|
+
async persist() {
|
|
189
|
+
if (!this.isDirty || !this.db)
|
|
190
|
+
return;
|
|
191
|
+
try {
|
|
192
|
+
const data = this.db.export();
|
|
193
|
+
const buffer = Buffer.from(data);
|
|
194
|
+
await fs.writeFile(this.dbPath, buffer);
|
|
195
|
+
this.isDirty = false;
|
|
196
|
+
logger.debug({ dbPath: this.dbPath, size: buffer.length }, 'Cache persisted');
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
logger.error({ error }, 'Failed to persist cache');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
persistSync() {
|
|
203
|
+
if (!this.isDirty || !this.db)
|
|
204
|
+
return;
|
|
205
|
+
try {
|
|
206
|
+
const data = this.db.export();
|
|
207
|
+
const buffer = Buffer.from(data);
|
|
208
|
+
writeFileSync(this.dbPath, buffer);
|
|
209
|
+
this.isDirty = false;
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
console.error('Failed to persist cache on exit:', error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async close() {
|
|
216
|
+
if (this.watcher) {
|
|
217
|
+
this.watcher.stop();
|
|
218
|
+
this.watcher = null;
|
|
219
|
+
}
|
|
220
|
+
if (this.persistTimer) {
|
|
221
|
+
clearTimeout(this.persistTimer);
|
|
222
|
+
this.persistTimer = null;
|
|
223
|
+
}
|
|
224
|
+
await this.persist();
|
|
225
|
+
if (this.db) {
|
|
226
|
+
this.db.close();
|
|
227
|
+
this.db = null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
startWatcher(debounceMs = 500) {
|
|
231
|
+
if (this.watcher) {
|
|
232
|
+
logger.warn({ projectRoot: this.projectRoot }, 'Watcher already started');
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
this.watcher = new FileWatcher({
|
|
236
|
+
debounceMs,
|
|
237
|
+
ignored: [],
|
|
238
|
+
onFileChange: async (filePath) => {
|
|
239
|
+
await this.invalidate(filePath);
|
|
240
|
+
logger.debug({ filePath }, 'Cache invalidated by file watcher');
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
this.watcher.start(this.projectRoot);
|
|
244
|
+
}
|
|
245
|
+
stopWatcher() {
|
|
246
|
+
if (this.watcher) {
|
|
247
|
+
this.watcher.stop();
|
|
248
|
+
this.watcher = null;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
getWatcherStatus() {
|
|
252
|
+
return this.watcher ? this.watcher.getStatus() : { isWatching: false, watchedFiles: 0 };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=cacheManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cacheManager.js","sourceRoot":"","sources":["../../../src/core/cacheManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,SAAuB,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aA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,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;IAC1F,CAAC;CACF"}
|
package/dist/src/core/engine.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Security Validator - v3.
|
|
2
|
+
* Security Validator - v3.6.0
|
|
3
3
|
* CRITICAL FIX: Path traversal check AFTER normalization
|
|
4
4
|
*/
|
|
5
5
|
import * as path from "node:path";
|
|
@@ -12,18 +12,22 @@ export class SecurityValidator {
|
|
|
12
12
|
async validateFilePath(filePath) {
|
|
13
13
|
// Resolve FIRST, then check
|
|
14
14
|
const resolved = path.resolve(filePath);
|
|
15
|
-
// CRITICAL: Check boundary AFTER normalization
|
|
16
|
-
if (!resolved.startsWith(this.projectRoot)) {
|
|
17
|
-
return {
|
|
15
|
+
// CRITICAL: Check boundary AFTER normalization (with path separator)
|
|
16
|
+
if (resolved !== this.projectRoot && !resolved.startsWith(this.projectRoot + path.sep)) {
|
|
17
|
+
return {
|
|
18
|
+
valid: false,
|
|
19
|
+
error: `Security: Path "${filePath}" is outside project boundary "${this.projectRoot}"`
|
|
20
|
+
};
|
|
18
21
|
}
|
|
19
|
-
// NOTE: Path traversal already caught by startsWith check above.
|
|
20
|
-
// Removed dead code that duplicated the boundary check (unreachable condition).
|
|
21
22
|
// Existence check
|
|
22
23
|
try {
|
|
23
24
|
await fs.access(resolved);
|
|
24
25
|
}
|
|
25
26
|
catch {
|
|
26
|
-
return {
|
|
27
|
+
return {
|
|
28
|
+
valid: false,
|
|
29
|
+
error: `File not found: "${filePath}" (resolved to "${resolved}")`
|
|
30
|
+
};
|
|
27
31
|
}
|
|
28
32
|
return { valid: true, resolvedPath: resolved };
|
|
29
33
|
}
|
|
@@ -31,12 +35,20 @@ export class SecurityValidator {
|
|
|
31
35
|
try {
|
|
32
36
|
const stat = await fs.stat(filePath);
|
|
33
37
|
if (stat.size > maxSize) {
|
|
34
|
-
|
|
38
|
+
const sizeMB = (stat.size / 1024 / 1024).toFixed(2);
|
|
39
|
+
const maxMB = (maxSize / 1024 / 1024).toFixed(2);
|
|
40
|
+
return {
|
|
41
|
+
valid: false,
|
|
42
|
+
error: `File too large: ${sizeMB}MB exceeds maximum ${maxMB}MB`
|
|
43
|
+
};
|
|
35
44
|
}
|
|
36
45
|
return { valid: true };
|
|
37
46
|
}
|
|
38
47
|
catch (error) {
|
|
39
|
-
return {
|
|
48
|
+
return {
|
|
49
|
+
valid: false,
|
|
50
|
+
error: `Failed to check file size for "${filePath}": ${error instanceof Error ? error.message : String(error)}`
|
|
51
|
+
};
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../src/core/validator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAQvC,MAAM,OAAO,iBAAiB;IACpB,WAAW,CAAS;IAE5B,YAAY,WAAmB;QAC7B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,QAAgB;QACrC,4BAA4B;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAExC
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../src/core/validator.ts"],"names":[],"mappings":"AAAA;;;GAGG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IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACpD,MAAM,KAAK,GAAG,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACjD,OAAO;oBACL,KAAK,EAAE,KAAK;oBACZ,KAAK,EAAE,mBAAmB,MAAM,sBAAsB,KAAK,IAAI;iBAChE,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,kCAAkC,QAAQ,MAAM,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;aAChH,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* mcp-code-context v3.
|
|
3
|
+
* mcp-code-context v3.6.0 - Tree-sitter WASM Edition
|
|
4
4
|
*
|
|
5
5
|
* Production-ready with:
|
|
6
6
|
* - Tree-sitter WASM for 100% AST accuracy (TypeScript, Python, PHP, Dart)
|
|
@@ -8,5 +8,10 @@
|
|
|
8
8
|
* - Two-phase write workflow (dry-run + confirmation token)
|
|
9
9
|
* - Middleware pipeline: rate limiting, file locking, audit logging, telemetry
|
|
10
10
|
* - Mandatory security boundaries on ALL handlers
|
|
11
|
+
* - Persistent WASM SQLite cache with <100ms hits
|
|
12
|
+
* - Structured logging with pino (JSON to stderr, MCP-safe)
|
|
13
|
+
* - File watcher with chokidar for auto cache invalidation
|
|
14
|
+
* - Fuzzy search with fuse.js + pagination
|
|
15
|
+
* - Token optimization: compact diffs, auto-optimize output
|
|
11
16
|
*/
|
|
12
17
|
export {};
|