codemap-ai 0.1.2 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sahan Nishshanka, JUST ADD AI GmbH
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 CHANGED
@@ -1,181 +1,319 @@
1
- # CodeMap
1
+ # CodeMap AI
2
2
 
3
- AI-powered codebase knowledge graph generator with Claude Code integration.
3
+ **Call graph analyzer for understanding code impact and execution flows - built for Claude Code**
4
4
 
5
- **CodeMap** scans your codebase, builds a knowledge graph of all functions, classes, imports, and their relationships, then generates Claude Code skills that help the AI understand your project.
5
+ Stop guessing what breaks when you change code. CodeMap builds a complete call graph of your codebase so Claude can answer "what depends on this?" with surgical precision.
6
6
 
7
7
  ## Features
8
8
 
9
- - **Multi-language support**: Python, TypeScript, JavaScript (more coming)
10
- - **Knowledge graph**: SQLite-based graph of code relationships
11
- - **Auto-generated skills**: Creates Claude Code skills from your codebase
12
- - **Impact analysis**: See what files are affected by changes
13
- - **Web visualization**: Interactive D3 force-directed graph
14
- - **MCP server**: Direct integration with Claude Code
9
+ - 🔍 **Call Graph Analysis** - Trace every function call across your entire codebase
10
+ - 🎯 **Impact Analysis** - Know exactly what breaks before you change code
11
+ - 🔗 **Cross-File Resolution** - Follows imports and tracks dependencies
12
+ - 🚀 **FastAPI Support** - Detects HTTP endpoints and dependency injection patterns
13
+ - 💾 **Incremental Updates** - Only re-indexes changed files
14
+ - 🤖 **Claude Code Integration** - MCP server for AI-powered code queries
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ # Use directly with npx (recommended)
20
+ npx codemap-ai index /path/to/project
21
+
22
+ # Or install globally
23
+ npm install -g codemap-ai
24
+ ```
15
25
 
16
26
  ## Quick Start
17
27
 
18
28
  ```bash
19
- # Scan your project
20
- npx codemap-ai scan /path/to/project
29
+ # Index your codebase
30
+ npx codemap-ai index /path/to/project
21
31
 
22
- # Generate Claude Code skills
23
- npx codemap-ai generate-skills /path/to/project
32
+ # Start MCP server for Claude Code
33
+ npx codemap-ai mcp-server
24
34
 
25
- # Start visualization server
26
- npx codemap-ai serve /path/to/project
35
+ # Add to Claude Code (one-time setup)
36
+ claude mcp add codemap -- npx codemap-ai mcp-server --path /path/to/project
27
37
  ```
28
38
 
29
39
  ## Commands
30
40
 
31
- ### `codemap scan [path]`
41
+ ### `codemap index [path]`
32
42
 
33
- Scan a codebase and build the knowledge graph.
43
+ Build a call graph of your codebase:
34
44
 
35
45
  ```bash
36
- codemap scan .
37
- codemap scan /path/to/project --clean
38
- codemap scan . --include "src/**/*.ts" --exclude "**/*.test.ts"
46
+ # Index current directory
47
+ codemap index
48
+
49
+ # Index specific directory
50
+ codemap index /path/to/project
51
+
52
+ # Force re-index everything
53
+ codemap index --force
54
+
55
+ # Custom file patterns
56
+ codemap index --include "src/**/*.py" --exclude "**/tests/**"
39
57
  ```
40
58
 
41
- Options:
42
- - `-o, --output <dir>` - Output directory (default: `.codemap`)
43
- - `--include <patterns...>` - Glob patterns to include
44
- - `--exclude <patterns...>` - Glob patterns to exclude
45
- - `--clean` - Clear existing data before scanning
59
+ **Options:**
60
+ - `--force` - Force re-index all files (default: incremental)
61
+ - `--include <patterns>` - File patterns to include (can be repeated)
62
+ - `--exclude <patterns>` - File patterns to exclude (can be repeated)
46
63
 
47
- ### `codemap generate-skills [path]`
64
+ **Output:**
65
+ ```
66
+ CodeMap Call Graph Indexer
67
+
68
+ Indexed: 290 files
69
+ Resolved: 3,987 function calls
70
+ Unresolved: 12,253 calls (external/dynamic)
71
+
72
+ Framework Detection:
73
+ HTTP Endpoints: 283 routes detected
74
+ Dependencies: 30/30 resolved (FastAPI Depends)
75
+
76
+ Call resolution rate: 25%
77
+ Database saved to: .codemap/graph.db
78
+ ```
79
+
80
+ ### `codemap mcp-server`
48
81
 
49
- Generate Claude Code skills from the knowledge graph.
82
+ Start the MCP server for Claude Code integration:
50
83
 
51
84
  ```bash
52
- codemap generate-skills .
53
- codemap generate-skills . --name "My Project"
85
+ codemap mcp-server --path /path/to/project
54
86
  ```
55
87
 
56
- This creates skills in `.claude/skills/codemap/`:
57
- - `/architecture` - Project structure overview
58
- - `/patterns` - Common code patterns
59
- - `/dependencies` - Dependency explorer
60
- - `/impact` - Change impact analysis
61
- - `/navigate` - Code navigation helper
88
+ **Options:**
89
+ - `--path <path>` - Path to indexed project (default: current directory)
62
90
 
63
- ### `codemap affected <target>`
91
+ ## MCP Tools for Claude Code
64
92
 
65
- Show files that would be affected by changes.
93
+ Once connected via MCP, Claude gains these capabilities:
66
94
 
67
- ```bash
68
- codemap affected src/auth/login.ts
69
- codemap affected UserService
70
- codemap affected handleSubmit --depth 3
95
+ ### `codemap_callers`
96
+ Find all functions that call a specific function:
97
+
98
+ ```
99
+ Claude: "What calls the authenticate_user function?"
100
+ → Returns: 12 callers with file:line references
71
101
  ```
72
102
 
73
- ### `codemap stats`
103
+ ### `codemap_impact`
104
+ Analyze the blast radius of changing code:
105
+
106
+ ```
107
+ Claude: "If I change authenticate_user, what breaks?"
108
+ → Returns: 15 affected files, call chain, risk level
109
+ ```
74
110
 
75
- Show statistics about the analyzed codebase.
111
+ ### `codemap_trace_flow`
112
+ Trace execution paths between functions:
76
113
 
77
- ```bash
78
- codemap stats
79
114
  ```
115
+ Claude: "Show me the flow from chat endpoint to database"
116
+ → Returns: handle_chat → authenticate → get_handler → save_chat → db.insert
117
+ ```
118
+
119
+ ### `codemap_dependencies`
120
+ Get import/export relationships:
80
121
 
81
- ### `codemap serve [path]`
122
+ ```
123
+ Claude: "What does auth.py import?"
124
+ → Returns: All imports and what they're used for
125
+ ```
82
126
 
83
- Start the web visualization server.
127
+ ### `codemap_search`
128
+ Search for functions, classes, files:
84
129
 
85
- ```bash
86
- codemap serve .
87
- codemap serve . --port 8080
130
+ ```
131
+ Claude: "Find all database operations"
132
+ Returns: 476 operations (find_one: 137, update_one: 122, ...)
88
133
  ```
89
134
 
90
- Opens an interactive graph at `http://localhost:3333`.
135
+ ## Supported Languages
91
136
 
92
- ### `codemap mcp-server`
137
+ | Language | Parsing | Imports | Calls | Classes | Methods |
138
+ |------------|---------|---------|-------|---------|---------|
139
+ | Python | ✅ | ✅ | ✅ | ✅ | ✅ |
140
+ | TypeScript | ✅ | ✅ | ✅ | ✅ | ✅ |
141
+ | JavaScript | ✅ | ✅ | ✅ | ✅ | ✅ |
93
142
 
94
- Start the MCP server for Claude Code integration.
143
+ ## Framework Detection
95
144
 
96
- ```bash
97
- # Add to Claude Code
98
- claude mcp add codemap -- npx codemap-ai mcp-server --path /path/to/project
145
+ CodeMap understands framework-specific patterns:
146
+
147
+ **FastAPI:**
148
+ - HTTP route decorators (`@router.post("/chat")`)
149
+ - Dependency injection (`Depends()`)
150
+ - Request handlers and middleware
151
+
152
+ **Coming Soon:**
153
+ - Django views and models
154
+ - Express.js routes
155
+ - React component hierarchy
156
+
157
+ ## How It Works
99
158
 
100
- # Or run directly
101
- codemap mcp-server --path .
102
159
  ```
160
+ ┌──────────────┐
161
+ │ Your Code │
162
+ │ .py/.ts/.js │
163
+ └──────┬───────┘
164
+
165
+
166
+ ┌──────────────┐
167
+ │ Tree-sitter │ Parse AST for every file
168
+ │ Parser │ Extract: functions, classes, calls, imports
169
+ └──────┬───────┘
170
+
171
+
172
+ ┌──────────────┐
173
+ │ Resolution │ Resolve all calls to definitions
174
+ │ Engine │ Track: variable types, inheritance, imports
175
+ └──────┬───────┘
176
+
177
+
178
+ ┌──────────────┐
179
+ │ SQLite │ Store: nodes (functions/classes)
180
+ │ Database │ edges (calls/imports)
181
+ └──────┬───────┘
182
+
183
+ ├─────────────┬─────────────┐
184
+ ▼ ▼ ▼
185
+ ┌───────────┐ ┌───────────┐ ┌───────────┐
186
+ │ MCP Tools │ │ Stats │ │ Impact │
187
+ │ Impact │ │ Reporting │ │ Analysis │
188
+ │ Callers │ │ │ │ │
189
+ └───────────┘ └───────────┘ └───────────┘
190
+ ```
191
+
192
+ ## Use Cases
103
193
 
104
- ## MCP Tools
194
+ ### Before Refactoring
195
+ ```bash
196
+ codemap index
197
+ # Ask Claude: "Show me everything that calls UserService.authenticate"
198
+ # → Make informed decisions about API changes
199
+ ```
105
200
 
106
- When connected to Claude Code, these tools become available:
201
+ ### Understanding Legacy Code
202
+ ```bash
203
+ codemap index
204
+ # Ask Claude: "How does the payment flow work from API to database?"
205
+ # → Get complete execution traces
206
+ ```
107
207
 
108
- - `codemap_search` - Search for functions, classes, files
109
- - `codemap_callers` - Find all callers of a function
110
- - `codemap_dependencies` - Get import/dependency info
111
- - `codemap_impact` - Analyze change impact
112
- - `codemap_stats` - Get codebase statistics
113
- - `codemap_file_contents` - List contents of a file
208
+ ### Security Audits
209
+ ```bash
210
+ codemap index
211
+ # Ask Claude: "Find all functions that access user credentials"
212
+ # Trace data flow through the system
213
+ ```
114
214
 
115
- ## Generated Skills
215
+ ### Dependency Analysis
216
+ ```bash
217
+ codemap index
218
+ # Ask Claude: "What would break if I remove this utility function?"
219
+ # → Impact analysis before deletion
220
+ ```
116
221
 
117
- After running `generate-skills`, Claude Code can use these commands:
222
+ ## Advanced Features
118
223
 
119
- ### `/architecture`
120
- Shows project structure, statistics, and key directories.
224
+ ### Incremental Indexing
121
225
 
122
- ### `/patterns`
123
- Explains common patterns, key classes, and coding conventions.
226
+ CodeMap uses file hashing to only re-index changed files:
124
227
 
125
- ### `/dependencies [module]`
126
- Explores what a module imports and what imports it.
228
+ ```bash
229
+ # First run: indexes all 290 files
230
+ codemap index
127
231
 
128
- ### `/impact [file or function]`
129
- Analyzes what would be affected by changes.
232
+ # Second run: only indexes changed files
233
+ codemap index
234
+ → Indexed: 3 files, Skipped: 287 files (unchanged)
235
+ ```
130
236
 
131
- ### `/navigate [query]`
132
- Finds and navigates to specific code.
237
+ ### Variable Type Tracking
133
238
 
134
- ## Programmatic Usage
239
+ Resolves method calls through type inference:
135
240
 
136
- ```typescript
137
- import { scan, generateSkills, scanAndGenerate } from 'codemap-ai';
241
+ ```python
242
+ user = UserService() # Type tracked
243
+ user.authenticate() # ✅ Resolved to UserService.authenticate
244
+ ```
138
245
 
139
- // Scan only
140
- const { analysis, dbPath } = await scan('/path/to/project');
246
+ ### Super() Resolution
141
247
 
142
- // Generate skills from existing scan
143
- const skills = generateSkills('/path/to/project', 'My Project');
248
+ Follows inheritance chains:
144
249
 
145
- // Scan and generate in one step
146
- const result = await scanAndGenerate('/path/to/project', 'My Project');
250
+ ```python
251
+ class Child(Parent):
252
+ def method(self):
253
+ super().method() # ✅ Resolved to Parent.method
147
254
  ```
148
255
 
149
- ## How It Works
256
+ ### Database Operation Detection
150
257
 
151
- 1. **Parsing**: Uses Tree-sitter to parse source files into ASTs
152
- 2. **Graph Building**: Extracts nodes (files, functions, classes) and edges (imports, calls, extends)
153
- 3. **Storage**: Stores everything in a SQLite database for fast queries
154
- 4. **Skill Generation**: Analyzes the graph to create helpful Claude Code skills
155
- 5. **MCP Server**: Exposes graph queries as MCP tools
258
+ Tracks MongoDB operations:
156
259
 
157
- ## Supported Languages
260
+ ```python
261
+ db.users.find_one({"id": user_id})
262
+ # ✅ Tracked as database operation: find_one on users collection
263
+ ```
158
264
 
159
- | Language | Parsing | Imports | Calls | Classes |
160
- |----------|---------|---------|-------|---------|
161
- | TypeScript | | | ✅ | ✅ |
162
- | JavaScript | | | | ✅ |
163
- | Python | | | ✅ | ✅ |
164
- | Go | 🚧 | 🚧 | 🚧 | 🚧 |
165
- | Rust | 🚧 | 🚧 | 🚧 | 🚧 |
265
+ ## Performance
266
+
267
+ - **Indexing Speed**: ~290 files in 2-3 seconds
268
+ - **Resolution Rate**: 25% internal calls (75% are external libraries/builtins)
269
+ - **Incremental Updates**: Only re-indexes changed files
270
+ - **Memory Usage**: ~50MB for 290 Python files
271
+ - **Database Size**: ~2MB for 290 files, 16K nodes, 12K edges
166
272
 
167
273
  ## Configuration
168
274
 
169
- Create a `codemap.config.json` in your project root:
275
+ CodeMap stores data in `.codemap/graph.db` (SQLite) in your project root.
170
276
 
171
- ```json
172
- {
173
- "include": ["src/**/*.ts", "lib/**/*.py"],
174
- "exclude": ["**/*.test.ts", "**/node_modules/**"],
175
- "languages": ["typescript", "python"]
176
- }
177
- ```
277
+ **File patterns:**
278
+ - Default include: `**/*.py`, `**/*.ts`, `**/*.tsx`, `**/*.js`, `**/*.jsx`
279
+ - Default exclude: `**/node_modules/**`, `**/__pycache__/**`, `**/venv/**`
280
+ - Max file size: 200KB (larger files skipped)
281
+
282
+ ## Troubleshooting
283
+
284
+ ### No functions detected
285
+ - Check file patterns with `--include` and `--exclude`
286
+ - Ensure files are under 200KB
287
+ - Verify supported language (.py, .ts, .js)
288
+
289
+ ### Low resolution rate
290
+ - Normal for projects with many external libraries
291
+ - Internal calls should resolve at ~90%+
292
+ - Use `codemap_search` to find unresolved patterns
293
+
294
+ ### MCP server not connecting
295
+ - Ensure Claude Code is running
296
+ - Check `~/.claude/config.json` for MCP configuration
297
+ - Restart Claude Code after adding MCP server
298
+
299
+ ## Contributing
300
+
301
+ CodeMap is focused on call graph accuracy and performance. We welcome:
302
+ - Parser improvements for better resolution
303
+ - New language support (Go, Rust, Java)
304
+ - Framework-specific pattern detection
305
+ - Performance optimizations
178
306
 
179
307
  ## License
180
308
 
181
- MIT
309
+ MIT License - see [LICENSE](LICENSE) file
310
+
311
+ ## Author
312
+
313
+ Sahan Nishshanka, JUST ADD AI GmbH
314
+
315
+ ## Links
316
+
317
+ - Repository: https://github.com/justaddai/codemap-ai
318
+ - Issues: https://github.com/justaddai/codemap-ai/issues
319
+ - NPM: https://www.npmjs.com/package/codemap-ai