codemap-ai 3.0.0 → 3.1.1

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/README.md CHANGED
@@ -2,151 +2,261 @@
2
2
 
3
3
  **Call graph analyzer for understanding code impact and execution flows - built for Claude Code**
4
4
 
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.
5
+ Stop guessing what breaks when you change code. CodeMap builds a complete call graph so Claude can answer "what depends on this?" with surgical precision.
6
6
 
7
7
  ## Features
8
8
 
9
9
  - 🔍 **Call Graph Analysis** - Trace every function call across your entire codebase
10
10
  - 🎯 **Impact Analysis** - Know exactly what breaks before you change code
11
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
12
+ - 🚀 **FastAPI Support** - Detects HTTP endpoints and dependency injection
13
+ - 💾 **Incremental Updates** - Only re-indexes changed files (git-aware)
14
14
  - 🤖 **Claude Code Integration** - MCP server for AI-powered code queries
15
15
 
16
16
  ## Installation
17
17
 
18
18
  ```bash
19
19
  # Use directly with npx (recommended)
20
- npx codemap-ai index /path/to/project
20
+ npx codemap-ai init
21
21
 
22
22
  # Or install globally
23
23
  npm install -g codemap-ai
24
24
  ```
25
25
 
26
- ## Quick Start
26
+ ## Quick Start (3 Commands)
27
27
 
28
28
  ```bash
29
- # Index your codebase
30
- npx codemap-ai index /path/to/project
29
+ # 1. First time: Initialize (indexes + configures Claude Code)
30
+ npx codemap-ai init
31
31
 
32
- # Start MCP server for Claude Code
33
- npx codemap-ai mcp-server
32
+ # 2. Before PR: Check impact of your changes
33
+ npx codemap-ai impact
34
34
 
35
- # Add to Claude Code (one-time setup)
36
- claude mcp add codemap -- npx codemap-ai mcp-server --path /path/to/project
35
+ # 3. After major refactor: Force re-index
36
+ npx codemap-ai reindex
37
37
  ```
38
38
 
39
+ That's it! Now ask Claude questions like:
40
+ - "What would break if I change authenticate_user?"
41
+ - "Show me the flow from chat endpoint to database"
42
+ - "What functions call get_user_permissions?"
43
+
39
44
  ## Commands
40
45
 
41
- ### `codemap index [path]`
46
+ ### `codemap init` - First-Time Setup
42
47
 
43
- Build a call graph of your codebase:
48
+ Initialize CodeMap in your project (one command does everything):
44
49
 
45
50
  ```bash
46
- # Index current directory
47
- codemap index
48
-
49
- # Index specific directory
50
- codemap index /path/to/project
51
+ cd /path/to/project
52
+ npx codemap-ai init
53
+ ```
51
54
 
52
- # Force re-index everything
53
- codemap index --force
55
+ **What it does:**
56
+ 1. Indexes your entire codebase
57
+ 2. Automatically configures MCP server in Claude Code
58
+ 3. Ready to ask questions!
54
59
 
55
- # Custom file patterns
56
- codemap index --include "src/**/*.py" --exclude "**/tests/**"
60
+ **Output:**
61
+ ```
62
+ ✓ Indexed 290 files (3,987 calls resolved)
63
+ ✓ MCP server configured in Claude Code
64
+ ✓ Ready! Ask Claude: 'What would break if I change authenticate_user?'
57
65
  ```
58
66
 
59
67
  **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)
68
+ - `--skip-mcp` - Skip MCP server configuration
69
+ - `--include <patterns>` - File patterns to include
70
+ - `--exclude <patterns>` - File patterns to exclude
71
+
72
+ ---
73
+
74
+ ### `codemap impact` - Check What Changed
75
+
76
+ Analyze the impact of your uncommitted changes (smart git integration):
77
+
78
+ ```bash
79
+ # After editing files
80
+ npx codemap-ai impact
81
+ ```
82
+
83
+ **What it does:**
84
+ 1. Detects modified files (uses `git diff` if available)
85
+ 2. Finds which functions changed
86
+ 3. Re-indexes only changed files (fast!)
87
+ 4. Shows callers, affected endpoints, risk level
63
88
 
64
89
  **Output:**
65
90
  ```
66
- CodeMap Call Graph Indexer
91
+ Detected 2 modified files
92
+
93
+ Modified Files:
94
+ • chat.py
95
+ • authentication.py
67
96
 
68
- Indexed: 290 files
69
- Resolved: 3,987 function calls
70
- Unresolved: 12,253 calls (external/dynamic)
97
+ Changed Functions:
98
+ handle_chat (chat.py:47)
99
+ authenticate_user (authentication.py:120)
71
100
 
72
- Framework Detection:
73
- HTTP Endpoints: 283 routes detected
74
- Dependencies: 30/30 resolved (FastAPI Depends)
101
+ Impact Analysis:
102
+ handle_chat:
103
+ 12 direct callers
104
+ authenticate_user:
105
+ 25 direct callers ⚠️
75
106
 
76
- Call resolution rate: 25%
77
- Database saved to: .codemap/graph.db
107
+ Affected HTTP Endpoints:
108
+ POST /api/chat
109
+ • POST /api/agents
110
+
111
+ Risk Assessment:
112
+ HIGH - 37 functions affected
78
113
  ```
79
114
 
80
- ### `codemap mcp-server`
115
+ **Options:**
116
+ - `-v, --verbose` - Show detailed caller information
117
+
118
+ **Use cases:**
119
+ - Before creating a PR
120
+ - After refactoring
121
+ - When debugging regressions
122
+
123
+ ---
81
124
 
82
- Start the MCP server for Claude Code integration:
125
+ ### `codemap reindex` - Force Full Rebuild
126
+
127
+ Force re-index everything from scratch:
83
128
 
84
129
  ```bash
85
- codemap mcp-server --path /path/to/project
130
+ npx codemap-ai reindex
86
131
  ```
87
132
 
88
- **Options:**
89
- - `--path <path>` - Path to indexed project (default: current directory)
133
+ **When to use:**
134
+ - After pulling major changes
135
+ - After changing many files
136
+ - When you want to rebuild the entire graph
90
137
 
91
- ## MCP Tools for Claude Code
138
+ ---
92
139
 
93
- Once connected via MCP, Claude gains these capabilities:
140
+ ## Claude Code Integration (MCP Tools)
94
141
 
95
- ### `codemap_callers`
96
- Find all functions that call a specific function:
142
+ Once you run `codemap init`, Claude gains these capabilities via MCP:
97
143
 
98
- ```
99
- Claude: "What calls the authenticate_user function?"
100
- → Returns: 12 callers with file:line references
101
- ```
144
+ ### 1. `codemap_impact` - Analyze Change Impact
102
145
 
103
- ### `codemap_impact`
104
- Analyze the blast radius of changing code:
146
+ **Ask Claude:**
147
+ > "If I change authenticate_user, what breaks?"
105
148
 
106
- ```
107
- Claude: "If I change authenticate_user, what breaks?"
108
- → Returns: 15 affected files, call chain, risk level
109
- ```
149
+ **Claude uses:** `codemap_impact` tool
110
150
 
111
- ### `codemap_trace_flow`
112
- Trace execution paths between functions:
151
+ **Returns:**
152
+ - Direct callers (functions that call it)
153
+ - Total impact (affected functions/files)
154
+ - Risk level (LOW/MEDIUM/HIGH)
155
+ - Recommendations
113
156
 
157
+ **Example response:**
114
158
  ```
115
- Claude: "Show me the flow from chat endpoint to database"
116
- → Returns: handle_chat → authenticate → get_handler → save_chat → db.insert
159
+ Impact Analysis: authenticate_user
160
+
161
+ Location: authentication.py:120
162
+ Risk Level: HIGH
163
+
164
+ Direct Callers (25):
165
+ - handle_chat in chat.py:47
166
+ - handle_agent in agents.py:85
167
+ - get_settings in settings.py:120
168
+ ...
169
+
170
+ Total Impact:
171
+ - Affected functions: 45
172
+ - Affected files: 15
173
+
174
+ ⚠️ Recommendation: High-risk change. Review all callers before modifying.
117
175
  ```
118
176
 
119
- ### `codemap_dependencies`
120
- Get import/export relationships:
177
+ ---
178
+
179
+ ### 2. `codemap_trace_flow` - Trace Execution Paths
180
+
181
+ **Ask Claude:**
182
+ > "Show me the flow from chat endpoint to database"
183
+
184
+ **Claude uses:** `codemap_trace_flow` tool
121
185
 
186
+ **Returns:**
187
+ - Complete call path from source to target
188
+ - File locations for each step
189
+ - Total steps in the flow
190
+
191
+ **Example response:**
122
192
  ```
123
- Claude: "What does auth.py import?"
124
- → Returns: All imports and what they're used for
193
+ Execution Flow: handle_chat save_message
194
+
195
+ 1. handle_chat
196
+ File: chat.py:47
197
+ ↓ calls
198
+
199
+ 2. authenticate_user
200
+ File: authentication.py:120
201
+ ↓ calls
202
+
203
+ 3. ChatHandler.save_message
204
+ File: handlers/chat.py:200
205
+ ↓ calls
206
+
207
+ 4. db.chats.insert_one
208
+ File: external
209
+
210
+ Total steps: 4
125
211
  ```
126
212
 
127
- ### `codemap_search`
128
- Search for functions, classes, files:
213
+ ---
214
+
215
+ ### 3. `codemap_callers` - Find Who Calls a Function
216
+
217
+ **Ask Claude:**
218
+ > "What functions call get_user_permissions?"
219
+
220
+ **Claude uses:** `codemap_callers` tool
129
221
 
222
+ **Returns:**
223
+ - All functions that call the target
224
+ - File locations with line numbers
225
+ - Function types (function, method, etc.)
226
+
227
+ **Example response:**
130
228
  ```
131
- Claude: "Find all database operations"
132
- → Returns: 476 operations (find_one: 137, update_one: 122, ...)
229
+ Callers of get_user_permissions
230
+
231
+ Total callers: 12
232
+
233
+ Who Calls This Function:
234
+ - handle_chat (function)
235
+ File: chat.py:47
236
+
237
+ - handle_agent (function)
238
+ File: agents.py:85
239
+
240
+ - verify_access (function)
241
+ File: auth.py:150
242
+ ...
133
243
  ```
134
244
 
245
+ ---
246
+
135
247
  ## Supported Languages
136
248
 
137
- | Language | Parsing | Imports | Calls | Classes | Methods |
138
- |------------|---------|---------|-------|---------|---------|
139
- | Python | ✅ | ✅ | ✅ | ✅ | ✅ |
140
- | TypeScript | ✅ | ✅ | ✅ | ✅ | ✅ |
141
- | JavaScript | ✅ | ✅ | ✅ | ✅ | ✅ |
249
+ | Language | Parsing | Imports | Calls | Classes | Methods | Inheritance |
250
+ |------------|---------|---------|-------|---------|---------|-------------|
251
+ | Python | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
252
+ | TypeScript | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
253
+ | JavaScript | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
142
254
 
143
255
  ## Framework Detection
144
256
 
145
- CodeMap understands framework-specific patterns:
146
-
147
- **FastAPI:**
148
- - HTTP route decorators (`@router.post("/chat")`)
149
- - Dependency injection (`Depends()`)
257
+ **FastAPI** (Python):
258
+ - HTTP route decorators: `@router.post("/chat")`
259
+ - Dependency injection: `Depends(get_user)`
150
260
  - Request handlers and middleware
151
261
 
152
262
  **Coming Soon:**
@@ -157,83 +267,142 @@ CodeMap understands framework-specific patterns:
157
267
  ## How It Works
158
268
 
159
269
  ```
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
193
-
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
270
+ ┌──────────────────────────────────────────────────────────────┐
271
+ Step 1: codemap init
272
+ Parse all files with Tree-sitter
273
+ │ • Extract: functions, classes, calls, imports │
274
+ • Resolve: variable types, inheritance, cross-file refs │
275
+ │ • Store: SQLite database (.codemap/graph.db) │
276
+ │ • Configure: MCP server in Claude Code │
277
+ └──────────────────────────────────────────────────────────────┘
278
+
279
+
280
+ ┌──────────────────────────────────────────────────────────────┐
281
+ │ Step 2: codemap impact (before PR) │
282
+ │ • Detect: git diff finds changed files │
283
+ Parse: extract changed function names │
284
+ • Re-index: only modified files (fast!) │
285
+ │ • Calculate: who calls changed functions │
286
+ • Report: risk level + affected files │
287
+ └──────────────────────────────────────────────────────────────┘
288
+
289
+
290
+ ┌──────────────────────────────────────────────────────────────┐
291
+ │ Step 3: Ask Claude (via MCP) │
292
+ • Claude calls: codemap_impact / codemap_trace_flow │
293
+ │ • Returns: markdown with analysis │
294
+ │ • You decide: safe to merge or need more testing │
295
+ └──────────────────────────────────────────────────────────────┘
199
296
  ```
200
297
 
201
- ### Understanding Legacy Code
298
+ ## Real-World Workflows
299
+
300
+ ### Workflow 1: Before Refactoring
301
+
202
302
  ```bash
203
- codemap index
204
- # Ask Claude: "How does the payment flow work from API to database?"
205
- # Get complete execution traces
303
+ # Scenario: Need to change authenticate_user() signature
304
+
305
+ # Step 1: Check current state
306
+ npx codemap-ai init
307
+
308
+ # Step 2: Ask Claude
309
+ # "Show me all functions that call authenticate_user"
310
+ # Claude uses codemap_callers → Shows 25 callers
311
+
312
+ # Step 3: Make changes
313
+ vim authentication.py
314
+
315
+ # Step 4: Check impact
316
+ npx codemap-ai impact
317
+ # → HIGH risk: 25 functions affected
318
+
319
+ # Step 5: Ask Claude for help
320
+ # "Review the impact of my authentication changes"
321
+ # Claude analyzes and suggests testing strategy
206
322
  ```
207
323
 
208
- ### Security Audits
324
+ ---
325
+
326
+ ### Workflow 2: Understanding Legacy Code
327
+
209
328
  ```bash
210
- codemap index
211
- # Ask Claude: "Find all functions that access user credentials"
212
- # Trace data flow through the system
329
+ # Scenario: New to codebase, need to understand payment flow
330
+
331
+ # Step 1: Initialize
332
+ npx codemap-ai init
333
+
334
+ # Step 2: Ask Claude
335
+ # "How does payment processing work from API to database?"
336
+ # Claude uses codemap_trace_flow → Shows complete path
337
+
338
+ # Step 3: Deep dive
339
+ # "What calls process_payment?"
340
+ # Claude uses codemap_callers → Shows all entry points
213
341
  ```
214
342
 
215
- ### Dependency Analysis
343
+ ---
344
+
345
+ ### Workflow 3: Pre-PR Safety Check
346
+
216
347
  ```bash
217
- codemap index
218
- # Ask Claude: "What would break if I remove this utility function?"
219
- # Impact analysis before deletion
348
+ # Scenario: Made changes to 10 files, need PR review
349
+
350
+ # Step 1: Already initialized (ran init on day 1)
351
+
352
+ # Step 2: Check impact
353
+ npx codemap-ai impact
354
+ # → Detects 10 modified files
355
+ # → Shows 3 changed functions
356
+ # → 15 callers affected
357
+ # → MEDIUM risk
358
+
359
+ # Step 3: Ask Claude
360
+ # "Analyze the impact of my changes and suggest test cases"
361
+ # Claude reviews impact report + generates test plan
362
+
363
+ # Step 4: Create PR with confidence
220
364
  ```
221
365
 
366
+ ---
367
+
222
368
  ## Advanced Features
223
369
 
370
+ ### Smart Git Integration
371
+
372
+ CodeMap uses `git diff` to detect exactly what changed:
373
+
374
+ ```python
375
+ # Before: def authenticate_user(token: str)
376
+ # After: def authenticate_user(token: str, role: str) # Added parameter
377
+
378
+ # codemap impact detects:
379
+ # - Signature changed at line 120
380
+ # - 25 callers need updating
381
+ # - Risk: HIGH
382
+ ```
383
+
384
+ **Fallback:** If not a git repo, uses file hash comparison.
385
+
386
+ ---
387
+
224
388
  ### Incremental Indexing
225
389
 
226
- CodeMap uses file hashing to only re-index changed files:
390
+ CodeMap only re-indexes changed files:
227
391
 
228
392
  ```bash
229
- # First run: indexes all 290 files
230
- codemap index
393
+ # First run: Index all 290 files (5 seconds)
394
+ codemap init
395
+
396
+ # Edit 2 files...
231
397
 
232
- # Second run: only indexes changed files
233
- codemap index
234
- → Indexed: 3 files, Skipped: 287 files (unchanged)
398
+ # Second run: Only index 2 files (< 1 second)
399
+ codemap impact
235
400
  ```
236
401
 
402
+ Uses SHA-256 file hashing for change detection.
403
+
404
+ ---
405
+
237
406
  ### Variable Type Tracking
238
407
 
239
408
  Resolves method calls through type inference:
@@ -243,6 +412,8 @@ user = UserService() # Type tracked
243
412
  user.authenticate() # ✅ Resolved to UserService.authenticate
244
413
  ```
245
414
 
415
+ ---
416
+
246
417
  ### Super() Resolution
247
418
 
248
419
  Follows inheritance chains:
@@ -253,20 +424,24 @@ class Child(Parent):
253
424
  super().method() # ✅ Resolved to Parent.method
254
425
  ```
255
426
 
256
- ### Database Operation Detection
427
+ ---
428
+
429
+ ### Database Operation Tracking
257
430
 
258
431
  Tracks MongoDB operations:
259
432
 
260
433
  ```python
261
434
  db.users.find_one({"id": user_id})
262
- # ✅ Tracked as database operation: find_one on users collection
435
+ # ✅ Tracked as: find_one on users collection
263
436
  ```
264
437
 
438
+ ---
439
+
265
440
  ## Performance
266
441
 
267
442
  - **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
443
+ - **Impact Analysis**: < 1 second (only re-indexes changed files)
444
+ - **Resolution Rate**: 25% (75% are external libraries - expected)
270
445
  - **Memory Usage**: ~50MB for 290 Python files
271
446
  - **Database Size**: ~2MB for 290 files, 16K nodes, 12K edges
272
447
 
@@ -274,31 +449,54 @@ db.users.find_one({"id": user_id})
274
449
 
275
450
  CodeMap stores data in `.codemap/graph.db` (SQLite) in your project root.
276
451
 
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)
452
+ **Default patterns:**
453
+ - Include: `**/*.py`, `**/*.ts`, `**/*.tsx`, `**/*.js`, `**/*.jsx`
454
+ - Exclude: `**/node_modules/**`, `**/__pycache__/**`, `**/venv/**`
455
+ - Max file size: 200KB
456
+
457
+ **Custom patterns:**
458
+ ```bash
459
+ codemap init \
460
+ --include "src/**/*.py" "lib/**/*.py" \
461
+ --exclude "**/tests/**" "**/migrations/**"
462
+ ```
281
463
 
282
464
  ## Troubleshooting
283
465
 
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)
466
+ ### "Not initialized" error
467
+ ```bash
468
+ # Run init first
469
+ npx codemap-ai init
470
+ ```
471
+
472
+ ### No changes detected
473
+ ```bash
474
+ # Make sure you have uncommitted changes
475
+ git status
476
+
477
+ # Or force re-index
478
+ npx codemap-ai reindex
479
+ ```
480
+
481
+ ### MCP not working in Claude Code
482
+ ```bash
483
+ # Check if MCP is configured
484
+ cat ~/.claude/config.json
485
+
486
+ # Re-run init to reconfigure
487
+ npx codemap-ai init
488
+
489
+ # Restart Claude Code
490
+ ```
288
491
 
289
492
  ### Low resolution rate
290
493
  - Normal for projects with many external libraries
291
494
  - 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
495
+ - Use `codemap_callers` to verify specific functions
298
496
 
299
497
  ## Contributing
300
498
 
301
- CodeMap is focused on call graph accuracy and performance. We welcome:
499
+ We welcome contributions focused on:
302
500
  - Parser improvements for better resolution
303
501
  - New language support (Go, Rust, Java)
304
502
  - Framework-specific pattern detection
@@ -317,3 +515,30 @@ Sahan Nishshanka, JUST ADD AI GmbH
317
515
  - Repository: https://github.com/justaddai/codemap-ai
318
516
  - Issues: https://github.com/justaddai/codemap-ai/issues
319
517
  - NPM: https://www.npmjs.com/package/codemap-ai
518
+
519
+ ---
520
+
521
+ ## Why CodeMap?
522
+
523
+ **Traditional approach:**
524
+ ```
525
+ Developer: "I need to change this function..."
526
+ Developer: *searches codebase manually*
527
+ Developer: *finds 10 references*
528
+ Developer: *misses 15 hidden callers*
529
+ Developer: *deploys*
530
+ 💥 Production breaks
531
+ ```
532
+
533
+ **With CodeMap:**
534
+ ```
535
+ Developer: "I need to change this function..."
536
+ Developer: npx codemap-ai impact
537
+ Developer: "Shows 25 callers - HIGH risk"
538
+ Claude: "Here's a test plan for all affected areas"
539
+ Developer: *tests thoroughly*
540
+ Developer: *deploys with confidence*
541
+ ✅ Production stable
542
+ ```
543
+
544
+ **Stop breaking prod. Use CodeMap.** 🚀