mcp-code-context 3.5.3 → 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.
Files changed (79) hide show
  1. package/CHANGELOG.md +57 -3
  2. package/INSTRUCTIONS.md +274 -0
  3. package/README.md +59 -6
  4. package/SECURITY.md +14 -14
  5. package/dist/src/core/cacheManager.d.ts +44 -0
  6. package/dist/src/core/cacheManager.js +255 -0
  7. package/dist/src/core/cacheManager.js.map +1 -0
  8. package/dist/src/core/engine.d.ts +1 -1
  9. package/dist/src/core/engine.js +1 -1
  10. package/dist/src/core/validator.d.ts +1 -1
  11. package/dist/src/core/validator.js +19 -7
  12. package/dist/src/core/validator.js.map +1 -1
  13. package/dist/src/index.d.ts +6 -1
  14. package/dist/src/index.js +197 -20
  15. package/dist/src/index.js.map +1 -1
  16. package/dist/src/operations/compress.d.ts +3 -1
  17. package/dist/src/operations/compress.js +47 -48
  18. package/dist/src/operations/compress.js.map +1 -1
  19. package/dist/src/operations/confirmationStore.d.ts +1 -1
  20. package/dist/src/operations/confirmationStore.js +1 -1
  21. package/dist/src/operations/read.d.ts +5 -1
  22. package/dist/src/operations/read.js +125 -64
  23. package/dist/src/operations/read.js.map +1 -1
  24. package/dist/src/operations/write.d.ts +2 -2
  25. package/dist/src/operations/write.js +83 -59
  26. package/dist/src/operations/write.js.map +1 -1
  27. package/dist/src/parsers/base.d.ts +1 -1
  28. package/dist/src/parsers/base.js +1 -1
  29. package/dist/src/parsers/dartTreeSitter.d.ts +1 -1
  30. package/dist/src/parsers/dartTreeSitter.js +1 -1
  31. package/dist/src/parsers/php.d.ts +1 -1
  32. package/dist/src/parsers/php.js +1 -1
  33. package/dist/src/parsers/python.d.ts +1 -1
  34. package/dist/src/parsers/python.js +1 -1
  35. package/dist/src/parsers/registry.d.ts +1 -1
  36. package/dist/src/parsers/registry.js +1 -1
  37. package/dist/src/parsers/typescript.d.ts +1 -1
  38. package/dist/src/parsers/typescript.js +1 -1
  39. package/dist/src/utils/auditLogger.d.ts +1 -1
  40. package/dist/src/utils/auditLogger.js +3 -2
  41. package/dist/src/utils/auditLogger.js.map +1 -1
  42. package/dist/src/utils/backupManager.d.ts +30 -9
  43. package/dist/src/utils/backupManager.js +75 -33
  44. package/dist/src/utils/backupManager.js.map +1 -1
  45. package/dist/src/utils/constants.d.ts +13 -2
  46. package/dist/src/utils/constants.js +21 -2
  47. package/dist/src/utils/constants.js.map +1 -1
  48. package/dist/src/utils/diff.d.ts +37 -7
  49. package/dist/src/utils/diff.js +91 -101
  50. package/dist/src/utils/diff.js.map +1 -1
  51. package/dist/src/utils/fileLock.d.ts +25 -50
  52. package/dist/src/utils/fileLock.js +66 -100
  53. package/dist/src/utils/fileLock.js.map +1 -1
  54. package/dist/src/utils/fileWalker.d.ts +28 -0
  55. package/dist/src/utils/fileWalker.js +57 -0
  56. package/dist/src/utils/fileWalker.js.map +1 -0
  57. package/dist/src/utils/fileWatcher.d.ts +23 -0
  58. package/dist/src/utils/fileWatcher.js +80 -0
  59. package/dist/src/utils/fileWatcher.js.map +1 -0
  60. package/dist/src/utils/fuzzySearch.d.ts +22 -0
  61. package/dist/src/utils/fuzzySearch.js +36 -0
  62. package/dist/src/utils/fuzzySearch.js.map +1 -0
  63. package/dist/src/utils/logger.d.ts +19 -0
  64. package/dist/src/utils/logger.js +50 -0
  65. package/dist/src/utils/logger.js.map +1 -0
  66. package/dist/src/utils/rateLimiter.d.ts +1 -1
  67. package/dist/src/utils/rateLimiter.js +1 -1
  68. package/dist/src/utils/safeRegex.d.ts +1 -1
  69. package/dist/src/utils/safeRegex.js +1 -1
  70. package/dist/src/utils/searchTools.d.ts +14 -0
  71. package/dist/src/utils/searchTools.js +94 -0
  72. package/dist/src/utils/searchTools.js.map +1 -0
  73. package/dist/src/utils/streaming.d.ts +1 -1
  74. package/dist/src/utils/streaming.js +1 -1
  75. package/dist/src/utils/telemetry.d.ts +1 -1
  76. package/dist/src/utils/telemetry.js +1 -1
  77. package/llms.txt +5 -5
  78. package/package.json +28 -10
  79. package/vitest.config.ts +37 -0
@@ -0,0 +1,23 @@
1
+ /**
2
+ * File Watcher - v3.6.0
3
+ * Auto-invalidate cache on file changes with chokidar
4
+ */
5
+ export interface FileWatcherConfig {
6
+ debounceMs: number;
7
+ ignored: string[];
8
+ onFileChange: (filePath: string) => void | Promise<void>;
9
+ }
10
+ export declare class FileWatcher {
11
+ private watcher;
12
+ private config;
13
+ private debounceTimers;
14
+ private isWatching;
15
+ constructor(config: FileWatcherConfig);
16
+ start(rootDir: string): void;
17
+ stop(): void;
18
+ getStatus(): {
19
+ isWatching: boolean;
20
+ watchedFiles: number;
21
+ };
22
+ private handleChange;
23
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * File Watcher - v3.6.0
3
+ * Auto-invalidate cache on file changes with chokidar
4
+ */
5
+ import chokidar from 'chokidar';
6
+ import { logger } from './logger.js';
7
+ import { EXCLUDE_DIRS } from './constants.js';
8
+ export class FileWatcher {
9
+ watcher = null;
10
+ config;
11
+ debounceTimers = new Map();
12
+ isWatching = false;
13
+ constructor(config) {
14
+ this.config = config;
15
+ }
16
+ start(rootDir) {
17
+ if (this.isWatching) {
18
+ logger.warn({ rootDir }, 'File watcher already running');
19
+ return;
20
+ }
21
+ this.watcher = chokidar.watch(rootDir, {
22
+ ignored: [
23
+ /(^|[\/\\])\../, // Hidden files
24
+ ...EXCLUDE_DIRS.map(dir => `**/${dir}/**`),
25
+ ...this.config.ignored,
26
+ ],
27
+ persistent: true,
28
+ ignoreInitial: true,
29
+ awaitWriteFinish: {
30
+ stabilityThreshold: 500,
31
+ pollInterval: 100,
32
+ },
33
+ });
34
+ this.watcher
35
+ .on('change', (filePath) => this.handleChange(filePath))
36
+ .on('unlink', (filePath) => this.handleChange(filePath))
37
+ .on('error', (error) => logger.error({ error }, 'File watcher error'));
38
+ this.isWatching = true;
39
+ logger.info({ rootDir, debounceMs: this.config.debounceMs }, 'File watcher started');
40
+ }
41
+ stop() {
42
+ if (this.watcher) {
43
+ this.watcher.close();
44
+ this.watcher = null;
45
+ }
46
+ // Clear all pending debounce timers
47
+ for (const timer of this.debounceTimers.values()) {
48
+ clearTimeout(timer);
49
+ }
50
+ this.debounceTimers.clear();
51
+ this.isWatching = false;
52
+ logger.info('File watcher stopped');
53
+ }
54
+ getStatus() {
55
+ return {
56
+ isWatching: this.isWatching,
57
+ watchedFiles: this.watcher ? Object.keys(this.watcher.getWatched()).length : 0,
58
+ };
59
+ }
60
+ handleChange(filePath) {
61
+ // Clear existing timer for this file
62
+ const existingTimer = this.debounceTimers.get(filePath);
63
+ if (existingTimer) {
64
+ clearTimeout(existingTimer);
65
+ }
66
+ // Set new debounced timer
67
+ const timer = setTimeout(() => {
68
+ this.debounceTimers.delete(filePath);
69
+ try {
70
+ this.config.onFileChange(filePath);
71
+ logger.debug({ filePath }, 'File change processed');
72
+ }
73
+ catch (error) {
74
+ logger.error({ error, filePath }, 'Error processing file change');
75
+ }
76
+ }, this.config.debounceMs);
77
+ this.debounceTimers.set(filePath, timer);
78
+ }
79
+ }
80
+ //# sourceMappingURL=fileWatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileWatcher.js","sourceRoot":"","sources":["../../../src/utils/fileWatcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,QAAuB,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAQ9C,MAAM,OAAO,WAAW;IACd,OAAO,GAAqB,IAAI,CAAC;IACjC,MAAM,CAAoB;IAC1B,cAAc,GAAG,IAAI,GAAG,EAA0B,CAAC;IACnD,UAAU,GAAG,KAAK,CAAC;IAE3B,YAAY,MAAyB;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAe;QACnB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC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AAC,CAAC;IAC3C,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Fuzzy Search - v3.6.0
3
+ * Typo-tolerant search with fuse.js
4
+ */
5
+ export interface FuzzySearchOptions {
6
+ threshold?: number;
7
+ keys?: string[];
8
+ includeScore?: boolean;
9
+ }
10
+ export interface FuzzySearchResult<T> {
11
+ item: T;
12
+ score?: number;
13
+ matches?: readonly any[];
14
+ }
15
+ /**
16
+ * Perform fuzzy search on array of items
17
+ */
18
+ export declare function fuzzySearch<T>(items: T[], query: string, options?: FuzzySearchOptions): FuzzySearchResult<T>[];
19
+ /**
20
+ * Fuzzy match a single string against a query
21
+ */
22
+ export declare function fuzzyMatch(text: string, query: string, threshold?: number): boolean;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Fuzzy Search - v3.6.0
3
+ * Typo-tolerant search with fuse.js
4
+ */
5
+ import Fuse from 'fuse.js';
6
+ /**
7
+ * Perform fuzzy search on array of items
8
+ */
9
+ export function fuzzySearch(items, query, options = {}) {
10
+ const fuse = new Fuse(items, {
11
+ threshold: options.threshold ?? 0.4,
12
+ keys: options.keys,
13
+ includeScore: options.includeScore ?? true,
14
+ includeMatches: true,
15
+ minMatchCharLength: 2,
16
+ ignoreLocation: true,
17
+ });
18
+ const results = fuse.search(query);
19
+ return results.map(result => ({
20
+ item: result.item,
21
+ score: result.score,
22
+ matches: result.matches,
23
+ }));
24
+ }
25
+ /**
26
+ * Fuzzy match a single string against a query
27
+ */
28
+ export function fuzzyMatch(text, query, threshold = 0.4) {
29
+ const fuse = new Fuse([text], {
30
+ threshold,
31
+ includeScore: true,
32
+ });
33
+ const results = fuse.search(query);
34
+ return results.length > 0;
35
+ }
36
+ //# sourceMappingURL=fuzzySearch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fuzzySearch.js","sourceRoot":"","sources":["../../../src/utils/fuzzySearch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,IAAI,MAAM,SAAS,CAAC;AAc3B;;GAEG;AACH,MAAM,UAAU,WAAW,CACzB,KAAU,EACV,KAAa,EACb,UAA8B,EAAE;IAEhC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE;QAC3B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,GAAG;QACnC,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,IAAI;QAC1C,cAAc,EAAE,IAAI;QACpB,kBAAkB,EAAE,CAAC;QACrB,cAAc,EAAE,IAAI;KACrB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEnC,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC5B,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,KAAa,EAAE,YAAoB,GAAG;IAC7E,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE;QAC5B,SAAS;QACT,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Logger - v3.6.0
3
+ * Structured logging with pino (JSON to stderr, MCP-safe)
4
+ */
5
+ import pino from 'pino';
6
+ /**
7
+ * Create pino logger instance
8
+ * - Development: Pretty print to stderr
9
+ * - Production: JSON to stderr (MCP-safe)
10
+ */
11
+ export declare const logger: pino.Logger<never, boolean>;
12
+ /**
13
+ * Create child logger with context
14
+ */
15
+ export declare function createLogger(context: Record<string, any>): pino.Logger<never, boolean>;
16
+ /**
17
+ * Log directory path (for audit logs if needed)
18
+ */
19
+ export declare const LOG_DIR: string;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Logger - v3.6.0
3
+ * Structured logging with pino (JSON to stderr, MCP-safe)
4
+ */
5
+ import pino from 'pino';
6
+ import { tmpdir } from 'os';
7
+ import path from 'path';
8
+ import crypto from 'crypto';
9
+ const isDevelopment = process.env.NODE_ENV !== 'production';
10
+ // Calculate project-specific log directory in OS temp
11
+ const projectHash = crypto.createHash('md5')
12
+ .update(process.cwd())
13
+ .digest('hex')
14
+ .substring(0, 8);
15
+ const logDir = path.join(tmpdir(), 'mcp-logs', projectHash);
16
+ /**
17
+ * Create pino logger instance
18
+ * - Development: Pretty print to stderr
19
+ * - Production: JSON to stderr (MCP-safe)
20
+ */
21
+ export const logger = pino({
22
+ level: process.env.LOG_LEVEL || (isDevelopment ? 'debug' : 'info'),
23
+ transport: isDevelopment
24
+ ? {
25
+ target: 'pino-pretty',
26
+ options: {
27
+ colorize: true,
28
+ translateTime: 'HH:MM:ss',
29
+ ignore: 'pid,hostname',
30
+ destination: 2, // stderr
31
+ },
32
+ }
33
+ : undefined,
34
+ base: {
35
+ pid: process.pid,
36
+ service: 'mcp-code-context',
37
+ },
38
+ timestamp: pino.stdTimeFunctions.isoTime,
39
+ });
40
+ /**
41
+ * Create child logger with context
42
+ */
43
+ export function createLogger(context) {
44
+ return logger.child(context);
45
+ }
46
+ /**
47
+ * Log directory path (for audit logs if needed)
48
+ */
49
+ export const LOG_DIR = logDir;
50
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAC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
3
3
  * Token bucket algorithm for DoS protection
4
4
  */
5
5
  interface RateLimitConfig {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Rate Limiter - v3.5.3
2
+ * Rate Limiter - v3.6.0
3
3
  * Token bucket algorithm for DoS protection
4
4
  */
5
5
  export class RateLimiter {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Safe Regex - v3.5.3
2
+ * Safe Regex - v3.6.0
3
3
  * CRITICAL FIX: Real ReDoS protection via worker_threads
4
4
  *
5
5
  * Problem: setTimeout cannot interrupt regex.test() in Node.js single-threaded event loop.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Safe Regex - v3.5.3
2
+ * Safe Regex - v3.6.0
3
3
  * CRITICAL FIX: Real ReDoS protection via worker_threads
4
4
  *
5
5
  * Problem: setTimeout cannot interrupt regex.test() in Node.js single-threaded event loop.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Search Tools - Native tool detection (ripgrep > ugrep > ag > findstr/grep)
3
+ * Uses spawn + readline to avoid buffer overflow on large outputs
4
+ */
5
+ export interface SearchToolResult {
6
+ tool: string;
7
+ matches: Array<{
8
+ file: string;
9
+ line: number;
10
+ content: string;
11
+ }>;
12
+ timedOut: boolean;
13
+ }
14
+ export declare function searchWithNativeTool(pattern: string, dir: string, maxResults?: number, timeoutMs?: number): Promise<SearchToolResult | null>;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Search Tools - Native tool detection (ripgrep > ugrep > ag > findstr/grep)
3
+ * Uses spawn + readline to avoid buffer overflow on large outputs
4
+ */
5
+ import { spawn } from 'child_process';
6
+ import { createInterface } from 'readline';
7
+ import { logger } from './logger.js';
8
+ const SEARCH_TOOLS = [
9
+ { name: 'rg', args: (pattern, dir) => ['--json', pattern, dir] },
10
+ { name: 'ugrep', args: (pattern, dir) => ['--json', pattern, dir] },
11
+ { name: 'ag', args: (pattern, dir) => ['--json', pattern, dir] },
12
+ { name: 'findstr', args: (pattern, dir) => ['/S', '/N', pattern, `${dir}\\*`] },
13
+ { name: 'grep', args: (pattern, dir) => ['-rn', pattern, dir] },
14
+ ];
15
+ async function detectTool() {
16
+ for (const tool of SEARCH_TOOLS) {
17
+ try {
18
+ const proc = spawn(tool.name, ['--version'], { stdio: 'ignore' });
19
+ const exitCode = await new Promise((resolve) => {
20
+ proc.on('close', (code) => resolve(code ?? 1));
21
+ proc.on('error', () => resolve(1));
22
+ });
23
+ if (exitCode === 0) {
24
+ logger.debug({ tool: tool.name }, 'Detected search tool');
25
+ return tool.name;
26
+ }
27
+ }
28
+ catch {
29
+ continue;
30
+ }
31
+ }
32
+ return null;
33
+ }
34
+ export async function searchWithNativeTool(pattern, dir, maxResults = 10, timeoutMs = 30000) {
35
+ const tool = await detectTool();
36
+ if (!tool)
37
+ return null;
38
+ const toolConfig = SEARCH_TOOLS.find((t) => t.name === tool);
39
+ if (!toolConfig)
40
+ return null;
41
+ // Pass -m flag to ripgrep/ugrep for OS-level limit
42
+ let args = toolConfig.args(pattern, dir);
43
+ if (tool === 'rg' || tool === 'ugrep') {
44
+ args = ['--max-count', String(maxResults), ...args];
45
+ }
46
+ const proc = spawn(tool, args);
47
+ const matches = [];
48
+ let timedOut = false;
49
+ const timeout = setTimeout(() => {
50
+ timedOut = true;
51
+ proc.kill();
52
+ }, timeoutMs);
53
+ const rl = createInterface({ input: proc.stdout });
54
+ for await (const line of rl) {
55
+ if (timedOut)
56
+ break;
57
+ // CRITICAL: Stop collecting once maxResults is reached to prevent OOM
58
+ if (matches.length >= maxResults) {
59
+ proc.kill();
60
+ break;
61
+ }
62
+ // Parse JSON output (rg/ugrep/ag) or plain text (findstr/grep)
63
+ if (tool === 'rg' || tool === 'ugrep' || tool === 'ag') {
64
+ try {
65
+ const json = JSON.parse(line);
66
+ if (json.type === 'match') {
67
+ matches.push({
68
+ file: json.data.path.text,
69
+ line: json.data.line_number,
70
+ content: json.data.lines.text.trim(),
71
+ });
72
+ }
73
+ }
74
+ catch {
75
+ continue;
76
+ }
77
+ }
78
+ else {
79
+ // findstr/grep: "file:line:content"
80
+ const match = line.match(/^(.+?):(\d+):(.+)$/);
81
+ if (match) {
82
+ matches.push({
83
+ file: match[1],
84
+ line: parseInt(match[2], 10),
85
+ content: match[3].trim(),
86
+ });
87
+ }
88
+ }
89
+ }
90
+ clearTimeout(timeout);
91
+ await new Promise((resolve) => proc.on('close', () => resolve()));
92
+ return { tool, matches, timedOut };
93
+ }
94
+ //# sourceMappingURL=searchTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchTools.js","sourceRoot":"","sources":["../../../src/utils/searchTools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAQrC,MAAM,YAAY,GAAG;IACnB,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,OAAe,EAAE,GAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE;IAChF,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,OAAe,EAAE,GAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE;IACnF,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,OAAe,EAAE,GAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE;IAChF,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,OAAe,EAAE,GAAW,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,GAAG,KAAK,CAAC,EAAE;IAC/F,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,OAAe,EAAE,GAAW,EAAE,EAAE,CAAC,CAA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EAAE,IAAI,CAAC,IAAI,CAAC,WAAW;wBAC3B,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;qBACrC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,SAAS;YACX,CAAC;QACH,CAAC;aAAM,CAAC;YACN,oCAAoC;YACpC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;YAC/C,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;oBACd,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;oBAC5B,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;iBACzB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,YAAY,CAAC,OAAO,CAAC,CAAC;IACtB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAExE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACrC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * File Streaming - v3.5.3
2
+ * File Streaming - v3.6.0
3
3
  * Stream large files in chunks to avoid memory exhaustion
4
4
  */
5
5
  export interface StreamOptions {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * File Streaming - v3.5.3
2
+ * File Streaming - v3.6.0
3
3
  * Stream large files in chunks to avoid memory exhaustion
4
4
  */
5
5
  import * as fs from "node:fs";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Telemetry - v3.5.3
2
+ * Telemetry - v3.6.0
3
3
  * Metrics collection and monitoring
4
4
  */
5
5
  export interface Metric {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Telemetry - v3.5.3
2
+ * Telemetry - v3.6.0
3
3
  * Metrics collection and monitoring
4
4
  */
5
5
  export class TelemetryCollector {
package/llms.txt CHANGED
@@ -1,8 +1,8 @@
1
- # mcp-code-context v3.5.3
1
+ # mcp-code-context v3.6.0
2
2
 
3
3
  > A Model Context Protocol (MCP) server with **Tree-sitter WASM parsers** for 100% AST accuracy. Zero native dependencies. Production-ready with middleware pipeline.
4
4
 
5
- ## What's New in v3.5.3
5
+ ## What's New in v3.6.0
6
6
 
7
7
  🔒 **Production Hardening**:
8
8
  - ✅ Two-phase write workflow (dry-run + confirmation token)
@@ -142,13 +142,13 @@ This MCP server solves two problems:
142
142
  - `steps` (optional): Number of versions to go back (1-5, default: 1).
143
143
  **What it does:** Reverts the file to the state it was in before the last 1-5 modifications.
144
144
 
145
- ### Write Tools (v3.5.3 Two-Phase Workflow)
145
+ ### Write Tools (v3.6.0 Two-Phase Workflow)
146
146
 
147
147
  All write tools follow a **Two-Phase Workflow**:
148
148
  1. **Phase 1 (Preview)**: Call without a token to get a unified `diff` and a `confirmationToken`.
149
149
  2. **Phase 2 (Apply)**: Call with `confirmationToken` and `confirm: true` to apply the changes.
150
150
 
151
- **Important Notes (v3.5.3):**
151
+ **Important Notes (v3.6.0):**
152
152
  - ✅ **Windows CRLF Support**: Fully resolved. All operations work correctly on Windows files with CRLF line endings.
153
153
  - ✅ **Parameter Brace Handling**: Methods with braces in parameters (e.g., `{int? cart}`) are now handled correctly.
154
154
 
@@ -236,7 +236,7 @@ All write tools follow a **Two-Phase Workflow**:
236
236
  5. **Phase 2: Apply Edit** → Verify the diff, then call with the token and `confirm: true`.
237
237
  6. **Recovery** → Use `rollback_file` if needed.
238
238
 
239
- ### Additional Tools (v3.5.3)
239
+ ### Additional Tools (v3.6.0)
240
240
 
241
241
  #### 11. `parse_file`
242
242
  **Purpose:** Parse a file using Tree-sitter and extract all symbols.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcp-code-context",
3
- "version": "3.5.3",
4
- "description": "Powerful MCP server with Tree-sitter WASM parsers for 100% AST accuracy. Zero native dependencies. Production-ready with streaming, telemetry, audit logging, rate limiting, file locking, and ReDoS protection. Supports TypeScript, JavaScript, PHP, Dart, and Python.",
3
+ "version": "3.6.0",
4
+ "description": "Powerful MCP server with Tree-sitter WASM parsers for 100% AST accuracy. Zero native dependencies. Production-ready with persistent caching, structured logging, file watching, fuzzy search, rate limiting, file locking, and ReDoS protection. Supports TypeScript, JavaScript, PHP, Dart, and Python.",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
7
7
  "bin": {
@@ -9,10 +9,14 @@
9
9
  },
10
10
  "scripts": {
11
11
  "build": "tsc",
12
+ "test": "npm run build && npm run build:tests && node dist-tests/tests/test-security.js && node dist-tests/tests/test-file-lock.js && node dist-tests/tests/test-rate-limiter.js && node dist-tests/tests/test-v3.4.js && node dist-tests/tests/test-backup-manager.js && node dist-tests/tests/test-wasm-parsers.js",
13
+ "test:ui": "vitest --ui",
14
+ "test:run": "vitest run",
15
+ "test:coverage": "vitest run --coverage",
16
+ "test:watch": "vitest --watch",
12
17
  "build:tests": "tsc -p tsconfig.tests.json",
13
18
  "start": "node dist/src/index.js",
14
19
  "dev": "npm run build && node dist/src/index.js",
15
- "test": "npm run build && npm run build:tests && node dist-tests/tests/test-security.js && node dist-tests/tests/test-file-lock.js && node dist-tests/tests/test-rate-limiter.js && node dist-tests/tests/test-v3.4.js && node dist-tests/tests/test-backup-manager.js && node dist-tests/tests/test-wasm-parsers.js",
16
20
  "clean": "rimraf dist dist-tests",
17
21
  "rebuild": "npm run clean && npm run build",
18
22
  "prepublishOnly": "npm run rebuild"
@@ -58,15 +62,29 @@
58
62
  "email": "a.chataing.a@gmail.com"
59
63
  },
60
64
  "dependencies": {
61
- "@modelcontextprotocol/sdk": "^1.12.0",
62
- "ignore": "^6.0.2",
63
- "tree-sitter-wasms": "^0.1.13",
64
- "web-tree-sitter": "^0.25.1"
65
+ "@modelcontextprotocol/sdk": "1.12.0",
66
+ "chokidar": "5.0.0",
67
+ "diff-match-patch": "1.0.5",
68
+ "fuse.js": "7.3.0",
69
+ "ignore": "6.0.2",
70
+ "pino": "10.3.1",
71
+ "pino-pretty": "13.1.3",
72
+ "proper-lockfile": "4.1.2",
73
+ "sql.js": "1.14.1",
74
+ "tree-sitter-wasms": "0.1.13",
75
+ "web-tree-sitter": "0.25.1"
65
76
  },
66
77
  "devDependencies": {
67
- "@types/node": "^22.10.0",
68
- "rimraf": "^6.0.1",
69
- "typescript": "^5.7.0"
78
+ "@types/chokidar": "1.7.5",
79
+ "@types/diff-match-patch": "1.0.36",
80
+ "@types/node": "22.19.17",
81
+ "@types/proper-lockfile": "4.1.4",
82
+ "@types/sql.js": "1.4.11",
83
+ "@vitest/coverage-v8": "4.1.5",
84
+ "@vitest/ui": "4.1.5",
85
+ "rimraf": "6.0.1",
86
+ "typescript": "5.7.0",
87
+ "vitest": "4.1.5"
70
88
  },
71
89
  "engines": {
72
90
  "node": ">=18.0.0"
@@ -0,0 +1,37 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import path from 'path';
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ globals: true,
7
+ environment: 'node',
8
+ reporters: ['default'],
9
+ coverage: {
10
+ provider: 'v8',
11
+ reporter: ['text', 'json', 'html'],
12
+ exclude: [
13
+ 'node_modules/',
14
+ 'dist/',
15
+ 'dist-tests/',
16
+ '**/*.spec.ts',
17
+ '**/*.test.ts',
18
+ 'tests/',
19
+ 'scripts/'
20
+ ],
21
+ thresholds: {
22
+ lines: 80,
23
+ functions: 80,
24
+ branches: 75,
25
+ statements: 80
26
+ }
27
+ },
28
+ testTimeout: 60000,
29
+ hookTimeout: 60000,
30
+ outputTruncateLength: 80
31
+ },
32
+ resolve: {
33
+ alias: {
34
+ '@': path.resolve(__dirname, './src')
35
+ }
36
+ }
37
+ });