codemap-ai 0.2.0 → 3.1.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,156 +1,544 @@
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
- **One command to understand your entire codebase.**
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
- ## Quick Start
7
+ ## Features
8
+
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
13
+ - 💾 **Incremental Updates** - Only re-indexes changed files (git-aware)
14
+ - 🤖 **Claude Code Integration** - MCP server for AI-powered code queries
15
+
16
+ ## Installation
8
17
 
9
18
  ```bash
10
- # Initialize everything in one command
19
+ # Use directly with npx (recommended)
11
20
  npx codemap-ai init
12
21
 
13
- # That's it! Now use skills in Claude Code:
14
- # /architecture - Project overview
15
- # /patterns - Code conventions
16
- # /impact - Change analysis
22
+ # Or install globally
23
+ npm install -g codemap-ai
17
24
  ```
18
25
 
19
- ## What It Does
26
+ ## Quick Start (3 Commands)
27
+
28
+ ```bash
29
+ # 1. First time: Initialize (indexes + configures Claude Code)
30
+ npx codemap-ai init
20
31
 
21
- 1. **Scans** your codebase using Tree-sitter (Python, TypeScript, JavaScript)
22
- 2. **Builds** a knowledge graph of all functions, classes, imports, and calls
23
- 3. **Generates** Claude Code skills that understand your project
24
- 4. **Connects** to Claude Code via MCP for intelligent queries
32
+ # 2. Before PR: Check impact of your changes
33
+ npx codemap-ai impact
25
34
 
26
- ## Installation
35
+ # 3. After major refactor: Force re-index
36
+ npx codemap-ai reindex
37
+ ```
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
+
44
+ ## Commands
45
+
46
+ ### `codemap init` - First-Time Setup
47
+
48
+ Initialize CodeMap in your project (one command does everything):
27
49
 
28
50
  ```bash
29
- # Option 1: Use directly with npx (recommended)
51
+ cd /path/to/project
30
52
  npx codemap-ai init
53
+ ```
31
54
 
32
- # Option 2: Install globally
33
- npm install -g codemap-ai
34
- codemap init
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!
59
+
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?'
35
65
  ```
36
66
 
37
- ## Commands
67
+ **Options:**
68
+ - `--skip-mcp` - Skip MCP server configuration
69
+ - `--include <patterns>` - File patterns to include
70
+ - `--exclude <patterns>` - File patterns to exclude
38
71
 
39
- ### `codemap init` (Recommended)
72
+ ---
40
73
 
41
- **One command that does everything:**
74
+ ### `codemap impact` - Check What Changed
75
+
76
+ Analyze the impact of your uncommitted changes (smart git integration):
42
77
 
43
78
  ```bash
44
- npx codemap-ai init /path/to/project --name "My Project"
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
88
+
89
+ **Output:**
90
+ ```
91
+ ✔ Detected 2 modified files
92
+
93
+ Modified Files:
94
+ • chat.py
95
+ • authentication.py
96
+
97
+ Changed Functions:
98
+ • handle_chat (chat.py:47)
99
+ • authenticate_user (authentication.py:120)
100
+
101
+ Impact Analysis:
102
+ handle_chat:
103
+ 12 direct callers
104
+ authenticate_user:
105
+ 25 direct callers ⚠️
106
+
107
+ Affected HTTP Endpoints:
108
+ • POST /api/chat
109
+ • POST /api/agents
110
+
111
+ Risk Assessment:
112
+ HIGH - 37 functions affected
113
+ ```
114
+
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
+ ---
124
+
125
+ ### `codemap reindex` - Force Full Rebuild
126
+
127
+ Force re-index everything from scratch:
128
+
129
+ ```bash
130
+ npx codemap-ai reindex
131
+ ```
132
+
133
+ **When to use:**
134
+ - After pulling major changes
135
+ - After changing many files
136
+ - When you want to rebuild the entire graph
137
+
138
+ ---
139
+
140
+ ## Claude Code Integration (MCP Tools)
141
+
142
+ Once you run `codemap init`, Claude gains these capabilities via MCP:
143
+
144
+ ### 1. `codemap_impact` - Analyze Change Impact
145
+
146
+ **Ask Claude:**
147
+ > "If I change authenticate_user, what breaks?"
148
+
149
+ **Claude uses:** `codemap_impact` tool
150
+
151
+ **Returns:**
152
+ - Direct callers (functions that call it)
153
+ - Total impact (affected functions/files)
154
+ - Risk level (LOW/MEDIUM/HIGH)
155
+ - Recommendations
156
+
157
+ **Example response:**
158
+ ```
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.
175
+ ```
176
+
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
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:**
192
+ ```
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
211
+ ```
212
+
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
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:**
228
+ ```
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
+ ...
45
243
  ```
46
244
 
47
- This will:
48
- 1. Scan your codebase and build the knowledge graph
49
- 2. Generate Claude Code skills
50
- 3. Add the MCP server to Claude Code
245
+ ---
51
246
 
52
- Options:
53
- - `--name <name>` - Project name for skill descriptions
54
- - `--skip-mcp` - Skip adding MCP server (just scan + skills)
247
+ ## Supported Languages
248
+
249
+ | Language | Parsing | Imports | Calls | Classes | Methods | Inheritance |
250
+ |------------|---------|---------|-------|---------|---------|-------------|
251
+ | Python | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
252
+ | TypeScript | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
253
+ | JavaScript | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
254
+
255
+ ## Framework Detection
256
+
257
+ **FastAPI** (Python):
258
+ - HTTP route decorators: `@router.post("/chat")`
259
+ - Dependency injection: `Depends(get_user)`
260
+ - Request handlers and middleware
261
+
262
+ **Coming Soon:**
263
+ - Django views and models
264
+ - Express.js routes
265
+ - React component hierarchy
266
+
267
+ ## How It Works
268
+
269
+ ```
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
+ └──────────────────────────────────────────────────────────────┘
296
+ ```
55
297
 
56
- ### `codemap serve`
298
+ ## Real-World Workflows
57
299
 
58
- Start the web visualization:
300
+ ### Workflow 1: Before Refactoring
59
301
 
60
302
  ```bash
61
- npx codemap-ai serve
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
62
322
  ```
63
323
 
64
- Opens an interactive graph at `http://localhost:3333`
324
+ ---
325
+
326
+ ### Workflow 2: Understanding Legacy Code
65
327
 
66
- ### `codemap stats`
328
+ ```bash
329
+ # Scenario: New to codebase, need to understand payment flow
330
+
331
+ # Step 1: Initialize
332
+ npx codemap-ai init
67
333
 
68
- Show codebase statistics:
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
341
+ ```
342
+
343
+ ---
344
+
345
+ ### Workflow 3: Pre-PR Safety Check
69
346
 
70
347
  ```bash
71
- npx codemap-ai stats
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
72
364
  ```
73
365
 
74
- ### `codemap affected <target>`
366
+ ---
367
+
368
+ ## Advanced Features
369
+
370
+ ### Smart Git Integration
75
371
 
76
- Analyze what files would be affected by changes:
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
+
388
+ ### Incremental Indexing
389
+
390
+ CodeMap only re-indexes changed files:
77
391
 
78
392
  ```bash
79
- npx codemap-ai affected src/auth/login.ts
80
- npx codemap-ai affected UserService
393
+ # First run: Index all 290 files (5 seconds)
394
+ codemap init
395
+
396
+ # Edit 2 files...
397
+
398
+ # Second run: Only index 2 files (< 1 second)
399
+ codemap impact
81
400
  ```
82
401
 
83
- ## Generated Skills
402
+ Uses SHA-256 file hashing for change detection.
84
403
 
85
- After initialization, these skills are available in Claude Code:
404
+ ---
86
405
 
87
- | Skill | Description |
88
- |-------|-------------|
89
- | `/architecture` | Project overview, stats, directory structure |
90
- | `/patterns` | Key classes, common functions, conventions |
91
- | `/impact <file>` | What's affected by changes to a file |
92
- | `/navigate <query>` | Find code by name |
93
- | `/dependencies <file>` | Import/export relationships |
406
+ ### Variable Type Tracking
94
407
 
95
- ## How It Works
408
+ Resolves method calls through type inference:
96
409
 
410
+ ```python
411
+ user = UserService() # Type tracked
412
+ user.authenticate() # ✅ Resolved to UserService.authenticate
97
413
  ```
98
- ┌──────────────┐ ┌─────────────┐ ┌──────────────┐
99
- │ Your Code │ ───► │ Tree-sitter │ ───► │ Knowledge │
100
- │ .ts/.py/.js │ │ Parser │ │ Graph (SQLite)│
101
- └──────────────┘ └─────────────┘ └──────────────┘
102
-
103
- ┌───────────────────────────┼───────────────────────────┐
104
- │ │ │
105
- ▼ ▼ ▼
106
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
107
- Skills │ │ MCP Server │ │ Web UI │
108
- /impact │ │ codemap_* │ │ Graph Viz │
109
- │ /patterns │ │ tools │ │ │
110
- └─────────────┘ └─────────────┘ └─────────────┘
414
+
415
+ ---
416
+
417
+ ### Super() Resolution
418
+
419
+ Follows inheritance chains:
420
+
421
+ ```python
422
+ class Child(Parent):
423
+ def method(self):
424
+ super().method() # Resolved to Parent.method
111
425
  ```
112
426
 
113
- ## Supported Languages
427
+ ---
428
+
429
+ ### Database Operation Tracking
430
+
431
+ Tracks MongoDB operations:
432
+
433
+ ```python
434
+ db.users.find_one({"id": user_id})
435
+ # ✅ Tracked as: find_one on users collection
436
+ ```
437
+
438
+ ---
439
+
440
+ ## Performance
114
441
 
115
- | Language | Parsing | Imports | Calls | Classes |
116
- |----------|---------|---------|-------|---------|
117
- | TypeScript | | | | ✅ |
118
- | JavaScript | | | ✅ | ✅ |
119
- | Python | | | | |
120
- | Go | 🚧 | 🚧 | 🚧 | 🚧 |
121
- | Rust | 🚧 | 🚧 | 🚧 | 🚧 |
442
+ - **Indexing Speed**: ~290 files in 2-3 seconds
443
+ - **Impact Analysis**: < 1 second (only re-indexes changed files)
444
+ - **Resolution Rate**: 25% (75% are external libraries - expected)
445
+ - **Memory Usage**: ~50MB for 290 Python files
446
+ - **Database Size**: ~2MB for 290 files, 16K nodes, 12K edges
122
447
 
123
- ## Advanced Usage
448
+ ## Configuration
124
449
 
125
- ### Individual Commands
450
+ CodeMap stores data in `.codemap/graph.db` (SQLite) in your project root.
126
451
 
127
- If you prefer step-by-step:
452
+ **Default patterns:**
453
+ - Include: `**/*.py`, `**/*.ts`, `**/*.tsx`, `**/*.js`, `**/*.jsx`
454
+ - Exclude: `**/node_modules/**`, `**/__pycache__/**`, `**/venv/**`
455
+ - Max file size: 200KB
128
456
 
457
+ **Custom patterns:**
129
458
  ```bash
130
- # Step 1: Scan
131
- npx codemap-ai scan /path/to/project
459
+ codemap init \
460
+ --include "src/**/*.py" "lib/**/*.py" \
461
+ --exclude "**/tests/**" "**/migrations/**"
462
+ ```
132
463
 
133
- # Step 2: Generate skills
134
- npx codemap-ai generate-skills /path/to/project --name "My Project"
464
+ ## Troubleshooting
135
465
 
136
- # Step 3: Add MCP server (optional, for database queries)
137
- claude mcp add codemap -- npx codemap-ai mcp-server --path /path/to/project
466
+ ### "Not initialized" error
467
+ ```bash
468
+ # Run init first
469
+ npx codemap-ai init
138
470
  ```
139
471
 
140
- ### MCP Tools
472
+ ### No changes detected
473
+ ```bash
474
+ # Make sure you have uncommitted changes
475
+ git status
141
476
 
142
- When the MCP server is connected, Claude Code gains these tools:
477
+ # Or force re-index
478
+ npx codemap-ai reindex
479
+ ```
143
480
 
144
- - `codemap_search` - Search functions, classes, files
145
- - `codemap_callers` - Find who calls a function
146
- - `codemap_dependencies` - Get import relationships
147
- - `codemap_impact` - Analyze change impact
148
- - `codemap_stats` - Get codebase statistics
481
+ ### MCP not working in Claude Code
482
+ ```bash
483
+ # Check if MCP is configured
484
+ cat ~/.claude/config.json
149
485
 
150
- ## Author
486
+ # Re-run init to reconfigure
487
+ npx codemap-ai init
488
+
489
+ # Restart Claude Code
490
+ ```
491
+
492
+ ### Low resolution rate
493
+ - Normal for projects with many external libraries
494
+ - Internal calls should resolve at ~90%+
495
+ - Use `codemap_callers` to verify specific functions
496
+
497
+ ## Contributing
151
498
 
152
- Sahan Nishshanka (Hub.KI GmbH)
499
+ We welcome contributions focused on:
500
+ - Parser improvements for better resolution
501
+ - New language support (Go, Rust, Java)
502
+ - Framework-specific pattern detection
503
+ - Performance optimizations
153
504
 
154
505
  ## License
155
506
 
156
- MIT
507
+ MIT License - see [LICENSE](LICENSE) file
508
+
509
+ ## Author
510
+
511
+ Sahan Nishshanka, JUST ADD AI GmbH
512
+
513
+ ## Links
514
+
515
+ - Repository: https://github.com/justaddai/codemap-ai
516
+ - Issues: https://github.com/justaddai/codemap-ai/issues
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.** 🚀