mcp-code-context 2.1.3

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 (112) hide show
  1. package/AGENT_INSTRUCTIONS.md +135 -0
  2. package/CHANGELOG.md +84 -0
  3. package/DEPLOYMENT_INSTRUCTIONS.md +110 -0
  4. package/LICENSE +21 -0
  5. package/README.md +247 -0
  6. package/RELEASE_NOTES_v2.1.3.md +78 -0
  7. package/TROUBLESHOOTING.md +38 -0
  8. package/dist/src/ast/dartCompressor.d.ts +27 -0
  9. package/dist/src/ast/dartCompressor.js +859 -0
  10. package/dist/src/ast/dartCompressor.js.map +1 -0
  11. package/dist/src/ast/phpCompressor.d.ts +24 -0
  12. package/dist/src/ast/phpCompressor.js +634 -0
  13. package/dist/src/ast/phpCompressor.js.map +1 -0
  14. package/dist/src/ast/semanticCompressor.d.ts +22 -0
  15. package/dist/src/ast/semanticCompressor.js +677 -0
  16. package/dist/src/ast/semanticCompressor.js.map +1 -0
  17. package/dist/src/ast/writers/dartWriter.d.ts +37 -0
  18. package/dist/src/ast/writers/dartWriter.js +544 -0
  19. package/dist/src/ast/writers/dartWriter.js.map +1 -0
  20. package/dist/src/ast/writers/phpWriter.d.ts +37 -0
  21. package/dist/src/ast/writers/phpWriter.js +411 -0
  22. package/dist/src/ast/writers/phpWriter.js.map +1 -0
  23. package/dist/src/ast/writers/pyWriter.d.ts +37 -0
  24. package/dist/src/ast/writers/pyWriter.js +355 -0
  25. package/dist/src/ast/writers/pyWriter.js.map +1 -0
  26. package/dist/src/ast/writers/symbolWriter.d.ts +62 -0
  27. package/dist/src/ast/writers/symbolWriter.js +179 -0
  28. package/dist/src/ast/writers/symbolWriter.js.map +1 -0
  29. package/dist/src/ast/writers/tsWriter.d.ts +38 -0
  30. package/dist/src/ast/writers/tsWriter.js +344 -0
  31. package/dist/src/ast/writers/tsWriter.js.map +1 -0
  32. package/dist/src/index.d.ts +117 -0
  33. package/dist/src/index.js +1289 -0
  34. package/dist/src/index.js.map +1 -0
  35. package/dist/src/tests/test-confirmation-flow.d.ts +1 -0
  36. package/dist/src/tests/test-confirmation-flow.js +43 -0
  37. package/dist/src/tests/test-confirmation-flow.js.map +1 -0
  38. package/dist/src/utils/backupManager.d.ts +24 -0
  39. package/dist/src/utils/backupManager.js +59 -0
  40. package/dist/src/utils/backupManager.js.map +1 -0
  41. package/dist/src/utils/confirmationCache.d.ts +16 -0
  42. package/dist/src/utils/confirmationCache.js +40 -0
  43. package/dist/src/utils/confirmationCache.js.map +1 -0
  44. package/dist/src/utils/diffEngine.d.ts +21 -0
  45. package/dist/src/utils/diffEngine.js +163 -0
  46. package/dist/src/utils/diffEngine.js.map +1 -0
  47. package/dist/src/utils/fuzzyMatch.d.ts +8 -0
  48. package/dist/src/utils/fuzzyMatch.js +69 -0
  49. package/dist/src/utils/fuzzyMatch.js.map +1 -0
  50. package/dist/src/utils/ignoreManager.d.ts +22 -0
  51. package/dist/src/utils/ignoreManager.js +135 -0
  52. package/dist/src/utils/ignoreManager.js.map +1 -0
  53. package/dist/tests/debug-replace.d.ts +1 -0
  54. package/dist/tests/debug-replace.js +17 -0
  55. package/dist/tests/debug-replace.js.map +1 -0
  56. package/dist/tests/test-confirmation-flow.d.ts +1 -0
  57. package/dist/tests/test-confirmation-flow.js +43 -0
  58. package/dist/tests/test-confirmation-flow.js.map +1 -0
  59. package/dist/tests/test-dart.d.ts +1 -0
  60. package/dist/tests/test-dart.js +242 -0
  61. package/dist/tests/test-dart.js.map +1 -0
  62. package/dist/tests/test-php-ast.d.ts +1 -0
  63. package/dist/tests/test-php-ast.js +152 -0
  64. package/dist/tests/test-php-ast.js.map +1 -0
  65. package/dist/tests/test-php.d.ts +1 -0
  66. package/dist/tests/test-php.js +234 -0
  67. package/dist/tests/test-php.js.map +1 -0
  68. package/dist/tests/test-smoke.d.ts +5 -0
  69. package/dist/tests/test-smoke.js +83 -0
  70. package/dist/tests/test-smoke.js.map +1 -0
  71. package/dist/tests/writers/test-crlf-handling.d.ts +4 -0
  72. package/dist/tests/writers/test-crlf-handling.js +73 -0
  73. package/dist/tests/writers/test-crlf-handling.js.map +1 -0
  74. package/dist/tests/writers/test-write-smoke.d.ts +9 -0
  75. package/dist/tests/writers/test-write-smoke.js +346 -0
  76. package/dist/tests/writers/test-write-smoke.js.map +1 -0
  77. package/llms.txt +164 -0
  78. package/package.json +57 -0
  79. package/src/ast/dartCompressor.ts +1013 -0
  80. package/src/ast/phpCompressor.ts +814 -0
  81. package/src/ast/semanticCompressor.ts +808 -0
  82. package/src/ast/writers/dartWriter.ts +648 -0
  83. package/src/ast/writers/phpWriter.ts +508 -0
  84. package/src/ast/writers/pyWriter.ts +446 -0
  85. package/src/ast/writers/symbolWriter.ts +277 -0
  86. package/src/ast/writers/tsWriter.ts +418 -0
  87. package/src/index.ts +1553 -0
  88. package/src/utils/backupManager.ts +66 -0
  89. package/src/utils/confirmationCache.ts +61 -0
  90. package/src/utils/diffEngine.ts +223 -0
  91. package/src/utils/fuzzyMatch.ts +86 -0
  92. package/src/utils/ignoreManager.ts +144 -0
  93. package/tests/test-confirmation-flow.ts +49 -0
  94. package/tests/test-dart.d.ts +1 -0
  95. package/tests/test-dart.js +209 -0
  96. package/tests/test-dart.js.map +1 -0
  97. package/tests/test-dart.ts +265 -0
  98. package/tests/test-php-ast.d.ts +1 -0
  99. package/tests/test-php-ast.js +152 -0
  100. package/tests/test-php-ast.js.map +1 -0
  101. package/tests/test-php-ast.ts +155 -0
  102. package/tests/test-php.d.ts +1 -0
  103. package/tests/test-php.js +234 -0
  104. package/tests/test-php.js.map +1 -0
  105. package/tests/test-php.ts +261 -0
  106. package/tests/test-smoke.d.ts +5 -0
  107. package/tests/test-smoke.js +83 -0
  108. package/tests/test-smoke.js.map +1 -0
  109. package/tests/test-smoke.ts +93 -0
  110. package/tests/writers/test-crlf-handling.ts +100 -0
  111. package/tests/writers/test-write-smoke.ts +568 -0
  112. package/tsconfig.json +19 -0
@@ -0,0 +1,135 @@
1
+ # Smart Code Analysis & Editing Tools
2
+ **Available tools for efficient code analysis, context management, and surgical code modification.**
3
+
4
+ ## Read Tools
5
+
6
+ ### 1. `get_semantic_repo_map` — Architectural Map
7
+ **When to use**: At the start of a session, before a major refactor, or when you need to understand a new codebase or directory structure.
8
+ **NEVER use**: For reading specific implementations — this tool extracts ONLY structural signatures (classes, functions), not the code bodies.
9
+ ```ts
10
+ get_semantic_repo_map(directoryPath: "/path/to/project/src", format: "markdown")
11
+ ```
12
+
13
+ ### 2. `read_file_surgical` — Surgical Reading
14
+ **When to use**: When you need a specific method, class, or symbol. ALWAYS prefer this over reading the entire file (like `fsRead`) if the symbol name is known.
15
+ **NEVER use**: For reading complete files if you only need a single function or symbol.
16
+ ```ts
17
+ read_file_surgical(filePath: "/path/to/file.ts", symbolName: "ClassName")
18
+ read_file_surgical(filePath: "/path/to/file.dart", symbolName: "WidgetName")
19
+ // Omitting symbolName will read the entire file
20
+ read_file_surgical(filePath: "/path/to/file.php")
21
+ ```
22
+ - If the symbol is not found, the tool returns a **structured JSON error** with `available_symbols` and `suggestions` (e.g., if a `className` scope is missing but the symbol exists in a class).
23
+ - **Pro-tip**: Use the suggestions to fix your next tool call (e.g., adding the correct `className`).
24
+
25
+ ### 3. `analyze_impact` — Blast Radius Detection
26
+ **When to use**: ALWAYS before modifying a file that might be imported or depended upon by other parts of the system.
27
+ **NEVER use**: Ignore or skip this step when refactoring shared services, utilities, or core components.
28
+ **Features**: Detects imports across ecosystems (e.g., `use Namespace\Class` in PHP, `import` in JS/TS/Dart/Python).
29
+ ```ts
30
+ analyze_impact(filePath: "/path/to/project/src/services/MyService.ts")
31
+ analyze_impact(filePath: "/path/to/project/src/Services/GeoIPService.php")
32
+ analyze_impact(filePath: "/path/to/detodo24_mobile/lib/services/tracking_service.dart")
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Write Tools
38
+
39
+ ### Mandatory Two-Phase Write Workflow (v2.1.1+)
40
+
41
+ All write tools (`write_file_surgical`, `insert_symbol`, `rename_symbol`, `remove_symbol`) now enforce a safety-first confirmation flow.
42
+
43
+ **Phase 1: Dry-Run / Preview**
44
+ Call the tool with your proposed changes. You will receive:
45
+ 1. A unified `diff` of the proposed changes.
46
+ 2. A `confirmationToken`.
47
+
48
+ **Phase 2: Confirmation**
49
+ To apply the changes, call the SAME tool again with:
50
+ 1. `confirmationToken`: The token from Phase 1.
51
+ 2. `confirm: true`.
52
+
53
+ ---
54
+
55
+ ### 4. `write_file_surgical` — Surgical Symbol Replacement
56
+ **When to use**: Replace a specific function, method, class, or interface.
57
+ **Phase 1 (Preview)**:
58
+ ```ts
59
+ write_file_surgical(filePath: "/path/to/file.ts", symbolName: "processOrder", newContent: "...")
60
+ ```
61
+ **Phase 2 (Apply)**:
62
+ ```ts
63
+ write_file_surgical(filePath: "/path/to/file.ts", symbolName: "processOrder", confirmationToken: "TOKEN_FROM_P1", confirm: true)
64
+ ```
65
+
66
+ ### 5. `insert_symbol` — Precise Code Insertion
67
+ **When to use**: Adding new members relative to an existing anchor symbol.
68
+ **Phase 1 (Preview)**:
69
+ ```ts
70
+ insert_symbol(filePath: "/path/to/file.dart", code: "void clear() { ... }", anchorSymbol: "getUser", position: "after")
71
+ ```
72
+ **Phase 2 (Apply)**:
73
+ ```ts
74
+ insert_symbol(filePath: "/path/to/file.dart", code: "void clear() { ... }", confirmationToken: "TOKEN_FROM_P1", confirm: true)
75
+ ```
76
+
77
+ ### 6. `rename_symbol` — Repository-Wide Rename
78
+ **When to use**: Atomic identifier renaming across the entire project.
79
+ **Phase 1 (Preview)**:
80
+ ```ts
81
+ rename_symbol(filePath: "/path/to/UserService.ts", oldName: "UserService", newName: "AccountService")
82
+ ```
83
+ **Phase 2 (Apply)**:
84
+ ```ts
85
+ rename_symbol(filePath: "/path/to/UserService.ts", oldName: "UserService", newName: "AccountService", confirmationToken: "TOKEN_FROM_P1", confirm: true)
86
+ ```
87
+
88
+ ### 7. `remove_symbol` — Safe Symbol Deletion
89
+ **When to use**: Removing code with dependency checking.
90
+ **Phase 1 (Preview)**:
91
+ ```ts
92
+ remove_symbol(filePath: "/path/to/file.ts", symbolName: "deprecatedHelper")
93
+ ```
94
+ **Phase 2 (Apply)**:
95
+ ```ts
96
+ remove_symbol(filePath: "/path/to/file.ts", symbolName: "deprecatedHelper", confirmationToken: "TOKEN_FROM_P1", confirm: true)
97
+ ```
98
+ - **Safety**: Safe removal check happens in Phase 1. If dependents exist, use `force: true` in your next Phase 1 call to override.
99
+
100
+ ### 8. `rollback_file` — Surgical Restoration
101
+ **When to use**: If an applied change introduces an unexpected error or side effect.
102
+ **Safety**: The server automatically keeps the last 5 versions in `.mcp-backups/`.
103
+ ```ts
104
+ rollback_file(filePath: "/path/to/file.ts", steps: 1)
105
+ ```
106
+
107
+ ### 7. `remove_symbol` — Safe Symbol Deletion
108
+ **When to use**: When removing a function, method, or class from a file.
109
+ **Safety**: By default, checks for dependents and **refuses** to remove if other files reference it.
110
+ ```ts
111
+ // Safe removal (checks dependents first)
112
+ remove_symbol(filePath: "/path/to/file.ts", symbolName: "deprecatedHelper")
113
+ // Force removal (skip dependency check)
114
+ remove_symbol(filePath: "/path/to/file.php", symbolName: "oldMethod", force: true)
115
+ ```
116
+
117
+ ---
118
+
119
+ ## Mandatory Workflow
120
+ 1. **New Session / Unknown Context** → Use `get_semantic_repo_map` on the relevant directory to understand the structure.
121
+ 2. **Read Code** → Use `read_file_surgical` with a `symbolName` whenever possible.
122
+ 3. **Handle Missing Symbols** → If you get a JSON error, use the `suggestions` to refine your `symbolName` or `className`.
123
+ 4. **Before Modifying** → Use `analyze_impact` if the file is a shared module or component.
124
+ 5. **Modify Code (Phase 1)** → Use write tools to generate a `diff` and `confirmationToken`.
125
+ 6. **Verify Diff** → Read the diff carefully. If incorrect, correct your prompt and start Phase 1 again.
126
+ 7. **Apply (Phase 2)** → Call the same write tool with the token and `confirm: true`.
127
+ 8. **Verify Result** → Ensure nothing broke. Use `rollback_file` if needed.
128
+
129
+ ## Supported Languages (Read + Write)
130
+ | Language | Read | Write | Engine |
131
+ |----------|------|-------|--------|
132
+ | TypeScript / JavaScript | ✅ | ✅ | AST (ts-morph) |
133
+ | PHP | ✅ | ✅ | AST (php-parser) |
134
+ | Dart | ✅ | ✅ | Brace-counting + regex |
135
+ | Python | ✅ | ✅ | Indentation-based |
package/CHANGELOG.md ADDED
@@ -0,0 +1,84 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.1.3] - 2025-04-17
9
+
10
+ ### Fixed
11
+ - **Windows CRLF Line Ending Support**: Completely resolved false brace imbalance errors on Windows files with CRLF line endings. All Dart writer functions (`replaceDartSymbol`, `insertDartCode`, `renameDartSymbol`, `removeDartSymbol`) now normalize `\r\n` to `\n` before processing, ensuring consistent behavior across all platforms.
12
+ - **Method Parameter Brace Handling**: Fixed critical bug where braces in method parameters (e.g., `{int? cart}`) were incorrectly counted as method body braces, causing false "unbalanced braces" errors. The `findMatchingBraceStateAware` function now correctly identifies the method body opening brace by tracking the closing parenthesis of the method signature.
13
+ - **Helper Function Normalization**: Added CRLF normalization to `hasBraceBalance()` and `reindentCode()` helper functions for defensive consistency.
14
+
15
+ ### Added
16
+ - **CRLF Test Suite**: New comprehensive test suite (`tests/writers/test-crlf-handling.ts`) covering all write operations with Windows line endings, mixed line endings, and edge cases.
17
+ - **Parameter Brace Test Cases**: Added test cases for methods with braces in parameters to prevent regression.
18
+
19
+ ## [2.1.2] - 2026-04-17
20
+
21
+ ### Fixed
22
+ - **State-Aware Brace Balancing**: Upgraded Dart parsing engine to correctly ignore braces inside string literals (single, double, and triple quotes) and comments. This eliminates "False Imbalance" errors during surgical writes.
23
+ - **Improved Block Boundary Detection**: Block extraction now respects nested literals, fixing issues where \`insert_symbol\` would incorrectly place code inside a method body when using \`position: "after"\`.
24
+ - **Cross-File Rename Propagation**: Refactored repository-wide renaming to update references in dependent files even if they don't contain a symbol definition, ensuring comprehensive refactoring.
25
+ - **Dependency Guard Precision**: Refined the safe-removal dependency check to use whole-word regex, reducing false positives caused by sub-string matches in unrelated files.
26
+
27
+ ### Added
28
+ - **Troubleshooting Guide**: New \`TROUBLESHOOTING.md\` documenting known architectural behaviors and recommended workarounds for complex editing scenarios.
29
+
30
+ ## [2.1.1] - 2026-04-17
31
+
32
+ ### Added
33
+ - **Mandatory Preview-then-Confirm Workflow**: All surgical writing tools now implement a safety-first two-phase flow (Phase 1: Dry-Run Preview with \`confirmationToken\`, Phase 2: Atomic Apply).
34
+ - **Rolling Multi-Step Backups**: Automatic rolling window of the last 5 versions for every modified file, stored in a hidden \`.mcp-backups/\` directory.
35
+ - **Rollback Tool**: New \`rollback_file\` MCP tool enabling surgical restoration to any of the 5 previous versions.
36
+ - **Fuzzy Symbol Matching**: Structured JSON error reporting for missing symbols, providing \`available_symbols\` and context-aware \`suggestions\` (e.g., suggesting a missing \`className\` scope or similar top-level symbols).
37
+ - **Private Symbol Support**: Full surgical read/write support for \`_\` and \`__\` prefixed symbols in Dart and Python (fixing previous regex word-boundary limitations).
38
+ - **Repository-Wide Rename Refinement**: Updated \`rename_symbol\` to automatically discover and propose renames across the entire dependency graph with multi-file diff previews.
39
+
40
+ ### Internal
41
+ - Refactored write handlers to perform unconditional backups before modification.
42
+ - Optimized Dart block extraction to correctly track nested parentheses within method signatures.
43
+ - Stabilized TypeScript build process and resolved all existing type inconsistencies.
44
+
45
+
46
+ ## [2.1.0] - 2026-04-17
47
+
48
+ ### Added
49
+ - **Class Scope Disambiguation**: Added a \`className\` parameter to all read and write tools (\`read_file_surgical\`, \`write_file_surgical\`, \`insert_symbol\`, \`remove_symbol\`).
50
+ - Fixed collisions across duplicate method names (e.g., \`build\` methods in Flutter or identical controllers in PHP/Python) by enforcing boundaries based on the requested class wrapper.
51
+ - Automatic smart detection block-bounding across 4 languages:
52
+ - TypeScript: Native TS-Morph class-level resolution mapping.
53
+ - PHP: Custom AST container mapping inside \`php-parser\`.
54
+ - Dart: Dynamic AST brace-bound indexing block extraction.
55
+ - Python: Dynamic regex scaling block extractor enforcing indentation thresholds.
56
+ - **Enhanced Testing Options**: Increased overall smoke & unit testing assertion matrix (from 52 assertions to 59).
57
+
58
+ ## [2.0.0] - 2026-04-15
59
+
60
+ ### Added
61
+ - **Surgical Writing Tools**: Four new tools for precise, AST-aware code modification:
62
+ - `write_file_surgical`: Replace symbol implementation while preserving file structure.
63
+ - `insert_symbol`: Insert new code relative to existing symbols (before, after, inside).
64
+ - `rename_symbol`: Repository-wide renaming with import/usage updates.
65
+ - `remove_symbol`: Safe deletion of symbols with automatic dependency checking.
66
+ - **Language-Specific Writers**: Custom AST adapters for TypeScript, JavaScript, PHP, Dart, and Python.
67
+ - **Dry-Run Engine**: Native unified diff generator for previewing changes without modifying the filesystem.
68
+ - **Backup System**: Opt-in `.bak` file management with automatic atomic rollback on multi-file operation failures.
69
+ - **Enhanced Agent Instructions**: Updated `AGENT_INSTRUCTIONS.md` and `llms.txt` for better AI integration.
70
+
71
+ ### Changed
72
+ - Refactored project structure to separate read-only analysis from surgical editing logic.
73
+ - Updated `README.md` with comprehensive v2.0 documentation and tool usage examples.
74
+ - Standardized error reporting across all MCP tools.
75
+ - Modernized `package.json` scripts and metadata.
76
+
77
+ ## [1.0.0] - 2026-04-14
78
+
79
+ ### Added
80
+ - **Initial Release**: Basic MCP server for semantic code compression.
81
+ - **Semantic Repository Map**: Generate structural maps of entire codebases.
82
+ - **Surgical Reading**: Extract specific symbols to save context tokens.
83
+ - **Impact Analysis**: Identify files that depend on or import a specific file.
84
+ - **Multi-Language Support**: Initial support for TS, JS, PHP, Dart, and Python.
@@ -0,0 +1,110 @@
1
+ # Deployment Instructions for v2.1.3
2
+
3
+ ## ✅ Completed Steps
4
+ 1. ✅ Code fixes implemented and tested
5
+ 2. ✅ Version bumped to 2.1.3 in package.json
6
+ 3. ✅ CHANGELOG.md updated
7
+ 4. ✅ TROUBLESHOOTING.md updated
8
+ 5. ✅ llms.txt updated
9
+ 6. ✅ Test suite created and passing (11/11 tests)
10
+ 7. ✅ Git commit created with semantic message
11
+ 8. ✅ Git tag v2.1.3 created with release notes
12
+ 9. ✅ Pushed to GitHub (main branch + tag)
13
+
14
+ ## 🚀 Next Steps (Manual)
15
+
16
+ ### 1. Publish to npm
17
+ You need to be logged in to npm. Run:
18
+
19
+ ```bash
20
+ cd C:\code\antigravity-mcp-context
21
+
22
+ # Login to npm (if not already)
23
+ npm login
24
+
25
+ # Publish the package
26
+ npm publish
27
+
28
+ # Verify publication
29
+ npm view mcp-code-context@2.1.3
30
+ ```
31
+
32
+ ### 2. Create GitHub Release
33
+ Go to: https://github.com/achatainga/mcp-code-context/releases/new
34
+
35
+ - **Tag**: Select `v2.1.3` (already pushed)
36
+ - **Title**: `v2.1.3 - Windows CRLF & Parameter Brace Fixes`
37
+ - **Description**: Copy content from `RELEASE_NOTES_v2.1.3.md`
38
+ - **Attach files**: None needed (npm package is the artifact)
39
+ - Click **Publish release**
40
+
41
+ ### 3. Verify Installation
42
+ Test that users can install the new version:
43
+
44
+ ```bash
45
+ # Global install
46
+ npm install -g mcp-code-context@2.1.3
47
+
48
+ # Verify version
49
+ npx mcp-code-context --version # Should show 2.1.3
50
+
51
+ # Test with MCP client (Claude Desktop, Amazon Q, etc.)
52
+ # Update config to use @2.1.3 and restart client
53
+ ```
54
+
55
+ ### 4. Announce (Optional)
56
+ Consider announcing on:
57
+ - GitHub Discussions
58
+ - Twitter/X
59
+ - Reddit (r/LocalLLaMA, r/ClaudeAI)
60
+ - Discord communities
61
+
62
+ ## 📋 Verification Checklist
63
+
64
+ Before announcing:
65
+ - [ ] npm package published successfully
66
+ - [ ] GitHub release created
67
+ - [ ] Can install via `npm install -g mcp-code-context@2.1.3`
68
+ - [ ] Version shows correctly in `package.json`
69
+ - [ ] Tag visible on GitHub releases page
70
+ - [ ] CHANGELOG.md shows v2.1.3 entry
71
+ - [ ] Tests passing on CI (if configured)
72
+
73
+ ## 🐛 Rollback Plan (If Needed)
74
+
75
+ If critical issues are discovered:
76
+
77
+ ```bash
78
+ # Unpublish from npm (within 72 hours)
79
+ npm unpublish mcp-code-context@2.1.3
80
+
81
+ # Delete GitHub release
82
+ # Go to releases page and delete v2.1.3
83
+
84
+ # Delete git tag
85
+ git tag -d v2.1.3
86
+ git push origin :refs/tags/v2.1.3
87
+
88
+ # Revert commit
89
+ git revert f0bfcfe
90
+ git push origin main
91
+ ```
92
+
93
+ ## 📊 Monitoring
94
+
95
+ After release, monitor:
96
+ - npm download stats: https://npm-stat.com/charts.html?package=mcp-code-context
97
+ - GitHub issues for bug reports
98
+ - GitHub stars/forks for adoption
99
+
100
+ ## 🎉 Success Criteria
101
+ - No critical bugs reported within 48 hours
102
+ - Windows users confirm CRLF issues resolved
103
+ - Download count increases
104
+ - Positive feedback from users
105
+
106
+ ---
107
+
108
+ **Current Status**: Ready for npm publish and GitHub release creation
109
+ **Blocked By**: npm authentication required
110
+ **Next Action**: Run `npm login` then `npm publish`
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,247 @@
1
+ # mcp-code-context
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
+ [![Tests](https://img.shields.io/badge/tests-passing-success.svg)]()
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-100%25-blue.svg)]()
6
+ [![Version](https://img.shields.io/badge/version-2.1.1-blue.svg)]()
7
+
8
+ > MCP server that compresses any codebase into LLM-ready semantic context **and provides surgical code editing tools**. AST-based read & write for TypeScript, JavaScript, PHP, Dart & Python.
9
+
10
+ ## 🚀 Quick Start (Claude Desktop)
11
+
12
+ 1. **Install**: `npm install -g mcp-code-context`
13
+ 2. **Configure**: Add to `claude_desktop_config.json`:
14
+ ```json
15
+ {
16
+ "mcpServers": {
17
+ "code-context": {
18
+ "command": "npx",
19
+ "args": ["-y", "mcp-code-context"]
20
+ }
21
+ }
22
+ }
23
+ ```
24
+ 3. **Enjoy**: Use symbols like `@code-context` to map repos or edit code surgically.
25
+
26
+ Works with **Claude Desktop**, **Cursor**, **Windsurf**, **GitHub Copilot**, **Amazon Q**, and any [Model Context Protocol](https://modelcontextprotocol.io/) compatible client.
27
+
28
+ ## The Problem
29
+
30
+ LLMs working with code face two bottlenecks:
31
+ 1. **Reading**: Sending raw source files wastes the context window on function bodies and boilerplate. A 500-line file might contain only 30 lines of *structural* information the LLM needs.
32
+ 2. **Writing**: Rewriting entire files to change one function is error-prone, token-expensive, and risks corrupting unrelated code.
33
+
34
+ ## The Solution
35
+
36
+ `mcp-code-context` provides **7 tools** — 3 for reading and 4 for writing — that operate at the **symbol level** (functions, classes, methods). Furthermore, tools support a `className` scope which correctly isolates identical symbol names in the same file (e.g. Flutter `build()` methods) to avoid reading or changing the wrong logic. Read tools extract structural skeletons. Write tools splice changes into the exact AST location.
37
+
38
+ | File | Original | Compressed | Reduction |
39
+ |------|----------|------------|-----------|
40
+ | PHP class (426 lines) | 426 | 60 | **85.9%** |
41
+ | Dart repository (230 lines) | 230 | 30 | **87.0%** |
42
+ | PHP config (68 lines) | 68 | 15 | **77.9%** |
43
+
44
+ ## Reliability & Testing
45
+
46
+ Built to be robust and precise. Both read and write engines are tested against real-world, complex codebases (including nested generic types in Dart, complex interfaces in PHP, and multi-file rename operations) with a **100% test pass rate** across all languages and operations.
47
+
48
+ ## Features
49
+
50
+ ### Read
51
+ - 🌳 **AST-based compression** — Real parsers for TypeScript/JavaScript ([ts-morph](https://ts-morph.com/)) and PHP ([php-parser](https://github.com/nickygerritsen/php-parser)). Brace-counting engine for Dart. Regex-based extraction for Python.
52
+ - 🔬 **Surgical symbol extraction** — Extract a single function, class, or method from a file by name. Use `className` to scope disambiguation (e.g., getting multiple `build()` methods in Dart).
53
+ - 💥 **Impact analysis** — Discover all files that depend on a given file before refactoring. Supports ES imports, CommonJS `require()`, Python imports, PHP `use`/`require_once`/`include`, and Dart imports.
54
+ - 📁 **Smart file walking** — Respects `.gitignore` and `.repomixignore` rules. Automatically excludes `node_modules`, `dist`, `vendor`, `.git`, etc.
55
+ - 📄 **Multi-format output** — XML (optimized for LLM consumption) or Markdown (human-readable).
56
+
57
+ ### Write
58
+ - ✏️ **Surgical symbol replacement** — Replace a function, method, or class body without touching the rest of the file. Narrow down the target using the `className` parameter.
59
+ - ➕ **Precise code insertion** — Insert new code before/after a symbol, or inside a class at the start/end.
60
+ - 🔄 **Repository-wide rename** — Rename a symbol in its definition AND all files that import it, atomically.
61
+ - 🗑️ **Safe symbol removal** — Delete code with automatic dependency checking to prevent breakage.
62
+ - 🔍 **Mandatory dry-run flow** — Write tools return a preview diff and a `confirmationToken` by default. Changes are only applied after explicit confirmation.
63
+ - 💾 **Robust rolling backups** — Automatically keeps the last 5 versions of modified files in a hidden `.mcp-backups/` directory.
64
+ - ⏪ **Surgical rollback** — Revert files to any of the 5 previous states using the new `rollback_file` tool.
65
+ - 🤖 **Fuzzy symbol matching** — When a symbol is not found, the server provides structured suggestions based on Levenshtein distance.
66
+ - 🔐 **Private symbol support** — Full support for `_` and `__` prefixed symbols in Dart and Python.
67
+
68
+ ## Supported Languages
69
+
70
+ | Language | Read (Compress + Extract) | Write (Replace + Insert + Rename + Remove) | Import Analysis |
71
+ |----------|---------------------------|---------------------------------------------|------------------|
72
+ | TypeScript / JavaScript | ✅ AST (ts-morph) | ✅ AST (ts-morph) | ✅ |
73
+ | PHP | ✅ AST (php-parser) | ✅ AST + line-splice | ✅ |
74
+ | Dart | ✅ Brace-counting + regex | ✅ Brace-counting + regex | ✅ |
75
+ | Python | ✅ Regex-based | ✅ Indentation-aware | ✅ |
76
+ | Others (JSON, YAML, CSS, etc.) | Passthrough / truncation | — | — |
77
+
78
+ ## Installation
79
+
80
+ ```bash
81
+ # Clone the repository
82
+ git clone https://github.com/YOUR_USERNAME/mcp-code-context.git
83
+ cd mcp-code-context
84
+
85
+ # Install dependencies
86
+ npm install
87
+
88
+ # Build
89
+ npm run build
90
+ ```
91
+
92
+ ## Configuration
93
+
94
+ ### Claude Desktop
95
+
96
+ Add to your `claude_desktop_config.json`:
97
+
98
+ ```json
99
+ {
100
+ "mcpServers": {
101
+ "mcp-code-context": {
102
+ "command": "node",
103
+ "args": ["/absolute/path/to/mcp-code-context/dist/index.js"]
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ ### Cursor
110
+
111
+ Add to your Cursor MCP settings (`.cursor/mcp.json`):
112
+
113
+ ```json
114
+ {
115
+ "mcpServers": {
116
+ "mcp-code-context": {
117
+ "command": "node",
118
+ "args": ["/absolute/path/to/mcp-code-context/dist/index.js"]
119
+ }
120
+ }
121
+ }
122
+ ```
123
+
124
+ ### Windsurf
125
+
126
+ Add to your Windsurf MCP config:
127
+
128
+ ```json
129
+ {
130
+ "mcpServers": {
131
+ "mcp-code-context": {
132
+ "command": "node",
133
+ "args": ["/absolute/path/to/mcp-code-context/dist/index.js"]
134
+ }
135
+ }
136
+ }
137
+ ```
138
+
139
+ ### Amazon Q / Other MCP Clients
140
+
141
+ Any MCP-compatible client can use this server. The transport is **stdio** (JSON-RPC over stdin/stdout). Point your client to `node dist/index.js`.
142
+
143
+ ## Tools
144
+
145
+ ### Read Tools
146
+
147
+ #### 1. `get_semantic_repo_map`
148
+ Generate a compressed architectural overview of an entire repository.
149
+ - `directoryPath` (required) — Path to the repo root
150
+ - `format` (optional) — `"xml"` (default) or `"markdown"`
151
+
152
+ #### 2. `read_file_surgical`
153
+ Read a file, or extract only a specific named symbol. Returns structured suggestions if the symbol is missing.
154
+ - `filePath` (required) — Path to the source file
155
+ - `symbolName` (optional) — Name of a function, class, method, or type
156
+ - `className` (optional) — Scope the symbol to a specific class (to avoid duplicates)
157
+
158
+ #### 3. `analyze_impact`
159
+ Find all files that depend on a given file.
160
+ - `filePath` (required) — Path to the file being modified
161
+ - `rootDir` (optional) — Repository root (auto-detected)
162
+
163
+ #### 4. `rollback_file`
164
+ Surgically restore a file to a previous state from the automated backup system.
165
+ - `filePath` (required) — Path to the file to restore
166
+ - `steps` (optional) — Number of versions to go back (1-5, default: 1)
167
+
168
+ ### Write Tools (Phase 1: Preview)
169
+
170
+ All write tools follow a **Two-Phase Workflow**:
171
+ 1. **Call without token**: Returns a unified `diff` and a `confirmationToken`.
172
+ 2. **Call with token**: Set `confirm: true` and provide the token to apply the changes.
173
+
174
+ #### 5. `write_file_surgical`
175
+ Replace the full source code of a named symbol in a file.
176
+ - `filePath` (required) — Path to the file
177
+ - `symbolName` (required) — Symbol to replace
178
+ - `newContent` (required) — Replacement code (signature + body)
179
+ - `confirmationToken` (optional) — Token from Phase 1 to apply changes
180
+ - `confirm` (optional) — Set to `true` to apply
181
+ - `className` (optional) — Scope the symbol to a specific class
182
+
183
+ #### 5. `insert_symbol`
184
+ Insert new code at a precise location relative to an existing symbol.
185
+ - `filePath` (required) — Path to the file
186
+ - `code` (required) — Code to insert
187
+ - `anchorSymbol` (optional) — Symbol to position relative to
188
+ - `position` (optional) — `"before"`, `"after"`, `"inside_start"`, `"inside_end"`
189
+ - `className` (optional) — Scope the anchor to a specific class
190
+ - `confirmationToken`, `confirm` (optional)
191
+
192
+ #### 6. `rename_symbol`
193
+ Rename a symbol across the entire repository (definition + all usages).
194
+ - `filePath` (required) — File where the symbol is defined
195
+ - `oldName` (required) — Current name
196
+ - `newName` (required) — New name
197
+ - `rootDir` (optional) — Repository root
198
+ - `confirmationToken`, `confirm` (optional)
199
+
200
+ #### 7. `remove_symbol`
201
+ Safely remove a symbol from a file with dependency checking.
202
+ - `filePath` (required) — Path to the file
203
+ - `symbolName` (required) — Symbol to remove
204
+ - `className` (optional) — Scope the symbol to a specific class
205
+ - `force` (optional) — Skip dependency check
206
+ - `confirmationToken`, `confirm` (optional)
207
+
208
+ ## Recommended Workflow
209
+
210
+ 1. **Understand** → `get_semantic_repo_map` to see the architecture
211
+ 2. **Read** → `read_file_surgical` with symbol name for specific implementations
212
+ 3. **Assess** → `analyze_impact` before modifying shared files
213
+ 4. **Edit (Preview)** → Call write tools to generate a `diff` and `confirmationToken`
214
+ 5. **Confim** → Call the same write tool with the token and `confirm: true` to apply
215
+ 6. **Recovery** → Use `rollback_file` if something goes wrong after confirmation
216
+
217
+ ## Development
218
+
219
+ ```bash
220
+ # Build
221
+ npm run build
222
+
223
+ # Run read tests (compression + extraction)
224
+ npm run build && node dist/tests/test-dart.js && node dist/tests/test-php.js
225
+
226
+ # Run write tests (replace, insert, rename, remove)
227
+ npm run build && node dist/tests/writers/test-write-smoke.js
228
+
229
+ # Run all tests
230
+ npm run build && node dist/tests/test-dart.js && node dist/tests/test-php.js && node dist/tests/writers/test-write-smoke.js
231
+
232
+ # Development (build + start)
233
+ npm run dev
234
+ ```
235
+
236
+ ## Technical Details
237
+
238
+ - **Transport:** stdio (JSON-RPC over stdin/stdout)
239
+ - **Runtime:** Node.js >= 18
240
+ - **Protocol:** [Model Context Protocol](https://modelcontextprotocol.io/)
241
+ - **AST Engines:** ts-morph (TypeScript/JS), php-parser (PHP), brace-counting (Dart), regex (Python)
242
+ - **Ignore Engine:** `ignore` npm package (full .gitignore spec support)
243
+ - **Safety Features:** Mandatory two-phase confirmation, rolling 5-version backups, fuzzy matching, dependency checking, surgical restoration.
244
+
245
+ ## License
246
+
247
+ [MIT](LICENSE)
@@ -0,0 +1,78 @@
1
+ # Release v2.1.3 - Windows CRLF & Parameter Brace Fixes
2
+
3
+ ## 🎯 Overview
4
+ This release completely resolves false brace imbalance errors on Windows systems and fixes a critical bug with Dart method parameters containing braces.
5
+
6
+ ## ✨ What's Fixed
7
+
8
+ ### Windows CRLF Support (Complete Resolution)
9
+ - ✅ All Dart writer functions now normalize `\r\n` to `\n` before processing
10
+ - ✅ No more false "unbalanced braces" errors on Windows files
11
+ - ✅ Consistent behavior across Windows, macOS, and Linux
12
+ - ✅ Helper functions (`hasBraceBalance`, `reindentCode`) also normalize line endings
13
+
14
+ ### Method Parameter Brace Handling
15
+ - ✅ Fixed critical bug where braces in method parameters (e.g., `{int? cart}`) were incorrectly counted as method body braces
16
+ - ✅ `findMatchingBraceStateAware` now tracks closing parenthesis to identify method body start
17
+ - ✅ Correctly handles Dart named parameters, optional parameters, and destructuring syntax
18
+
19
+ ## 🧪 Testing
20
+ - **11 new test cases** covering:
21
+ - CRLF line endings
22
+ - Mixed CRLF/LF line endings
23
+ - Methods with braces in parameters
24
+ - All write operations (replace, insert, rename, remove)
25
+ - **100% test pass rate** on Windows 11
26
+
27
+ ## 📝 Changes
28
+
29
+ ### Modified Files
30
+ - `src/ast/writers/dartWriter.ts` - Core CRLF normalization and parameter brace detection
31
+ - `package.json` - Version bump to 2.1.3
32
+ - `CHANGELOG.md` - Detailed release notes
33
+ - `TROUBLESHOOTING.md` - Marked CRLF issue as resolved
34
+ - `llms.txt` - Updated for LLM consumption
35
+
36
+ ### New Files
37
+ - `tests/writers/test-crlf-handling.ts` - Comprehensive CRLF test suite
38
+
39
+ ## 🔄 Migration Guide
40
+ No breaking changes. Simply update:
41
+
42
+ ```bash
43
+ npm install -g mcp-code-context@2.1.3
44
+ ```
45
+
46
+ Or in your MCP client config:
47
+ ```json
48
+ {
49
+ "mcpServers": {
50
+ "code-context": {
51
+ "command": "npx",
52
+ "args": ["-y", "mcp-code-context@2.1.3"]
53
+ }
54
+ }
55
+ }
56
+ ```
57
+
58
+ ## 🐛 Bug Reports Resolved
59
+ - Windows CRLF false positive errors
60
+ - Parameter brace detection in Dart methods
61
+ - Mixed line ending handling
62
+
63
+ ## 📊 Impact
64
+ - **Platforms affected**: Windows (primary), all platforms benefit from improved robustness
65
+ - **Languages affected**: Dart (primary fix), all languages benefit from CRLF normalization
66
+ - **Backward compatible**: Yes, no breaking changes
67
+
68
+ ## 🙏 Credits
69
+ Special thanks to the Amazon Q Developer user who reported the Windows CRLF bug with detailed reproduction steps.
70
+
71
+ ## 📚 Documentation
72
+ - [CHANGELOG.md](./CHANGELOG.md) - Full version history
73
+ - [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) - Known issues and solutions
74
+ - [README.md](./README.md) - Complete usage guide
75
+
76
+ ---
77
+
78
+ **Full Changelog**: https://github.com/achatainga/mcp-code-context/compare/v2.1.2...v2.1.3