@zuvia-software-solutions/code-mapper 1.4.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/README.md +215 -0
- package/dist/cli/ai-context.d.ts +19 -0
- package/dist/cli/ai-context.js +168 -0
- package/dist/cli/analyze.d.ts +7 -0
- package/dist/cli/analyze.js +325 -0
- package/dist/cli/augment.d.ts +7 -0
- package/dist/cli/augment.js +27 -0
- package/dist/cli/clean.d.ts +5 -0
- package/dist/cli/clean.js +56 -0
- package/dist/cli/eval-server.d.ts +25 -0
- package/dist/cli/eval-server.js +365 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +102 -0
- package/dist/cli/lazy-action.d.ts +6 -0
- package/dist/cli/lazy-action.js +19 -0
- package/dist/cli/list.d.ts +2 -0
- package/dist/cli/list.js +27 -0
- package/dist/cli/mcp.d.ts +8 -0
- package/dist/cli/mcp.js +35 -0
- package/dist/cli/refresh.d.ts +12 -0
- package/dist/cli/refresh.js +165 -0
- package/dist/cli/serve.d.ts +5 -0
- package/dist/cli/serve.js +8 -0
- package/dist/cli/setup.d.ts +6 -0
- package/dist/cli/setup.js +218 -0
- package/dist/cli/status.d.ts +2 -0
- package/dist/cli/status.js +33 -0
- package/dist/cli/tool.d.ts +28 -0
- package/dist/cli/tool.js +87 -0
- package/dist/config/ignore-service.d.ts +32 -0
- package/dist/config/ignore-service.js +282 -0
- package/dist/config/supported-languages.d.ts +23 -0
- package/dist/config/supported-languages.js +52 -0
- package/dist/core/augmentation/engine.d.ts +22 -0
- package/dist/core/augmentation/engine.js +232 -0
- package/dist/core/embeddings/embedder.d.ts +35 -0
- package/dist/core/embeddings/embedder.js +171 -0
- package/dist/core/embeddings/embedding-pipeline.d.ts +41 -0
- package/dist/core/embeddings/embedding-pipeline.js +402 -0
- package/dist/core/embeddings/index.d.ts +5 -0
- package/dist/core/embeddings/index.js +6 -0
- package/dist/core/embeddings/text-generator.d.ts +20 -0
- package/dist/core/embeddings/text-generator.js +159 -0
- package/dist/core/embeddings/types.d.ts +60 -0
- package/dist/core/embeddings/types.js +23 -0
- package/dist/core/graph/graph.d.ts +4 -0
- package/dist/core/graph/graph.js +65 -0
- package/dist/core/graph/types.d.ts +69 -0
- package/dist/core/graph/types.js +3 -0
- package/dist/core/incremental/child-process.d.ts +8 -0
- package/dist/core/incremental/child-process.js +649 -0
- package/dist/core/incremental/refresh-coordinator.d.ts +32 -0
- package/dist/core/incremental/refresh-coordinator.js +147 -0
- package/dist/core/incremental/types.d.ts +78 -0
- package/dist/core/incremental/types.js +153 -0
- package/dist/core/incremental/watcher.d.ts +63 -0
- package/dist/core/incremental/watcher.js +338 -0
- package/dist/core/ingestion/ast-cache.d.ts +12 -0
- package/dist/core/ingestion/ast-cache.js +34 -0
- package/dist/core/ingestion/call-processor.d.ts +34 -0
- package/dist/core/ingestion/call-processor.js +937 -0
- package/dist/core/ingestion/call-routing.d.ts +40 -0
- package/dist/core/ingestion/call-routing.js +97 -0
- package/dist/core/ingestion/cluster-enricher.d.ts +30 -0
- package/dist/core/ingestion/cluster-enricher.js +151 -0
- package/dist/core/ingestion/community-processor.d.ts +26 -0
- package/dist/core/ingestion/community-processor.js +272 -0
- package/dist/core/ingestion/constants.d.ts +5 -0
- package/dist/core/ingestion/constants.js +8 -0
- package/dist/core/ingestion/entry-point-scoring.d.ts +23 -0
- package/dist/core/ingestion/entry-point-scoring.js +317 -0
- package/dist/core/ingestion/export-detection.d.ts +11 -0
- package/dist/core/ingestion/export-detection.js +203 -0
- package/dist/core/ingestion/filesystem-walker.d.ts +18 -0
- package/dist/core/ingestion/filesystem-walker.js +64 -0
- package/dist/core/ingestion/framework-detection.d.ts +42 -0
- package/dist/core/ingestion/framework-detection.js +405 -0
- package/dist/core/ingestion/heritage-processor.d.ts +15 -0
- package/dist/core/ingestion/heritage-processor.js +237 -0
- package/dist/core/ingestion/import-processor.d.ts +31 -0
- package/dist/core/ingestion/import-processor.js +416 -0
- package/dist/core/ingestion/language-config.d.ts +32 -0
- package/dist/core/ingestion/language-config.js +161 -0
- package/dist/core/ingestion/mro-processor.d.ts +32 -0
- package/dist/core/ingestion/mro-processor.js +343 -0
- package/dist/core/ingestion/named-binding-extraction.d.ts +51 -0
- package/dist/core/ingestion/named-binding-extraction.js +343 -0
- package/dist/core/ingestion/parsing-processor.d.ts +20 -0
- package/dist/core/ingestion/parsing-processor.js +282 -0
- package/dist/core/ingestion/pipeline.d.ts +3 -0
- package/dist/core/ingestion/pipeline.js +416 -0
- package/dist/core/ingestion/process-processor.d.ts +42 -0
- package/dist/core/ingestion/process-processor.js +357 -0
- package/dist/core/ingestion/resolution-context.d.ts +40 -0
- package/dist/core/ingestion/resolution-context.js +171 -0
- package/dist/core/ingestion/resolvers/csharp.d.ts +10 -0
- package/dist/core/ingestion/resolvers/csharp.js +101 -0
- package/dist/core/ingestion/resolvers/go.d.ts +8 -0
- package/dist/core/ingestion/resolvers/go.js +33 -0
- package/dist/core/ingestion/resolvers/index.d.ts +14 -0
- package/dist/core/ingestion/resolvers/index.js +10 -0
- package/dist/core/ingestion/resolvers/jvm.d.ts +9 -0
- package/dist/core/ingestion/resolvers/jvm.js +74 -0
- package/dist/core/ingestion/resolvers/php.d.ts +7 -0
- package/dist/core/ingestion/resolvers/php.js +30 -0
- package/dist/core/ingestion/resolvers/ruby.d.ts +9 -0
- package/dist/core/ingestion/resolvers/ruby.js +13 -0
- package/dist/core/ingestion/resolvers/rust.d.ts +5 -0
- package/dist/core/ingestion/resolvers/rust.js +62 -0
- package/dist/core/ingestion/resolvers/standard.d.ts +16 -0
- package/dist/core/ingestion/resolvers/standard.js +144 -0
- package/dist/core/ingestion/resolvers/utils.d.ts +18 -0
- package/dist/core/ingestion/resolvers/utils.js +113 -0
- package/dist/core/ingestion/structure-processor.d.ts +4 -0
- package/dist/core/ingestion/structure-processor.js +39 -0
- package/dist/core/ingestion/symbol-table.d.ts +34 -0
- package/dist/core/ingestion/symbol-table.js +48 -0
- package/dist/core/ingestion/tree-sitter-queries.d.ts +20 -0
- package/dist/core/ingestion/tree-sitter-queries.js +691 -0
- package/dist/core/ingestion/type-env.d.ts +52 -0
- package/dist/core/ingestion/type-env.js +349 -0
- package/dist/core/ingestion/type-extractors/c-cpp.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/c-cpp.js +214 -0
- package/dist/core/ingestion/type-extractors/csharp.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/csharp.js +224 -0
- package/dist/core/ingestion/type-extractors/go.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/go.js +261 -0
- package/dist/core/ingestion/type-extractors/index.d.ts +20 -0
- package/dist/core/ingestion/type-extractors/index.js +30 -0
- package/dist/core/ingestion/type-extractors/jvm.d.ts +5 -0
- package/dist/core/ingestion/type-extractors/jvm.js +386 -0
- package/dist/core/ingestion/type-extractors/php.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/php.js +280 -0
- package/dist/core/ingestion/type-extractors/python.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/python.js +175 -0
- package/dist/core/ingestion/type-extractors/ruby.d.ts +12 -0
- package/dist/core/ingestion/type-extractors/ruby.js +218 -0
- package/dist/core/ingestion/type-extractors/rust.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/rust.js +290 -0
- package/dist/core/ingestion/type-extractors/shared.d.ts +81 -0
- package/dist/core/ingestion/type-extractors/shared.js +322 -0
- package/dist/core/ingestion/type-extractors/swift.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/swift.js +140 -0
- package/dist/core/ingestion/type-extractors/types.d.ts +111 -0
- package/dist/core/ingestion/type-extractors/types.js +4 -0
- package/dist/core/ingestion/type-extractors/typescript.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/typescript.js +227 -0
- package/dist/core/ingestion/utils.d.ts +73 -0
- package/dist/core/ingestion/utils.js +992 -0
- package/dist/core/ingestion/workers/parse-worker.d.ts +99 -0
- package/dist/core/ingestion/workers/parse-worker.js +1055 -0
- package/dist/core/ingestion/workers/worker-pool.d.ts +15 -0
- package/dist/core/ingestion/workers/worker-pool.js +123 -0
- package/dist/core/lbug/csv-generator.d.ts +28 -0
- package/dist/core/lbug/csv-generator.js +355 -0
- package/dist/core/lbug/lbug-adapter.d.ts +96 -0
- package/dist/core/lbug/lbug-adapter.js +753 -0
- package/dist/core/lbug/schema.d.ts +46 -0
- package/dist/core/lbug/schema.js +402 -0
- package/dist/core/search/bm25-index.d.ts +20 -0
- package/dist/core/search/bm25-index.js +123 -0
- package/dist/core/search/hybrid-search.d.ts +32 -0
- package/dist/core/search/hybrid-search.js +131 -0
- package/dist/core/search/query-cache.d.ts +18 -0
- package/dist/core/search/query-cache.js +47 -0
- package/dist/core/search/query-expansion.d.ts +19 -0
- package/dist/core/search/query-expansion.js +75 -0
- package/dist/core/search/reranker.d.ts +29 -0
- package/dist/core/search/reranker.js +122 -0
- package/dist/core/search/types.d.ts +154 -0
- package/dist/core/search/types.js +51 -0
- package/dist/core/semantic/tsgo-service.d.ts +67 -0
- package/dist/core/semantic/tsgo-service.js +355 -0
- package/dist/core/tree-sitter/parser-loader.d.ts +12 -0
- package/dist/core/tree-sitter/parser-loader.js +71 -0
- package/dist/lib/memory-guard.d.ts +35 -0
- package/dist/lib/memory-guard.js +70 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.js +6 -0
- package/dist/mcp/compatible-stdio-transport.d.ts +32 -0
- package/dist/mcp/compatible-stdio-transport.js +209 -0
- package/dist/mcp/core/embedder.d.ts +24 -0
- package/dist/mcp/core/embedder.js +168 -0
- package/dist/mcp/core/lbug-adapter.d.ts +29 -0
- package/dist/mcp/core/lbug-adapter.js +330 -0
- package/dist/mcp/local/local-backend.d.ts +188 -0
- package/dist/mcp/local/local-backend.js +2759 -0
- package/dist/mcp/resources.d.ts +22 -0
- package/dist/mcp/resources.js +379 -0
- package/dist/mcp/server.d.ts +10 -0
- package/dist/mcp/server.js +217 -0
- package/dist/mcp/staleness.d.ts +10 -0
- package/dist/mcp/staleness.js +25 -0
- package/dist/mcp/tools.d.ts +21 -0
- package/dist/mcp/tools.js +202 -0
- package/dist/server/api.d.ts +5 -0
- package/dist/server/api.js +340 -0
- package/dist/server/mcp-http.d.ts +7 -0
- package/dist/server/mcp-http.js +95 -0
- package/dist/storage/git.d.ts +6 -0
- package/dist/storage/git.js +35 -0
- package/dist/storage/repo-manager.d.ts +87 -0
- package/dist/storage/repo-manager.js +249 -0
- package/dist/types/pipeline.d.ts +35 -0
- package/dist/types/pipeline.js +20 -0
- package/hooks/claude/code-mapper-hook.cjs +238 -0
- package/hooks/claude/pre-tool-use.sh +79 -0
- package/hooks/claude/session-start.sh +42 -0
- package/models/mlx-embedder.py +185 -0
- package/package.json +100 -0
- package/scripts/patch-tree-sitter-swift.cjs +74 -0
- package/vendor/leiden/index.cjs +355 -0
- package/vendor/leiden/utils.cjs +392 -0
package/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# Code Mapper
|
|
2
|
+
|
|
3
|
+
**Graph-powered code intelligence for AI agents.** Index any codebase into a knowledge graph, then query it via MCP or CLI.
|
|
4
|
+
|
|
5
|
+
Works with **Cursor**, **Claude Code**, **Windsurf**, **Cline**, **OpenCode**, and any MCP-compatible tool.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/code-mapper)
|
|
8
|
+
[](https://polyformproject.org/licenses/noncommercial/1.0.0/)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Why?
|
|
13
|
+
|
|
14
|
+
AI coding tools don't understand your codebase structure. They edit a function without knowing 47 other functions depend on it. Code Mapper fixes this by **precomputing every dependency, call chain, and relationship** into a queryable graph.
|
|
15
|
+
|
|
16
|
+
**Three commands to give your AI agent full codebase awareness.**
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Index your repo (run from repo root)
|
|
22
|
+
npx code-mapper analyze
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
That's it. This indexes the codebase, installs agent skills, registers Claude Code hooks, and creates `AGENTS.md` / `CLAUDE.md` context files — all in one command.
|
|
26
|
+
|
|
27
|
+
To configure MCP for your editor, run `npx code-mapper setup` once — or set it up manually below.
|
|
28
|
+
|
|
29
|
+
`code-mapper setup` auto-detects your editors and writes the correct global MCP config. You only need to run it once.
|
|
30
|
+
|
|
31
|
+
### Editor Support
|
|
32
|
+
|
|
33
|
+
| Editor | MCP | Skills | Hooks (auto-augment) | Support |
|
|
34
|
+
|--------|-----|--------|---------------------|---------|
|
|
35
|
+
| **Claude Code** | Yes | Yes | Yes (PreToolUse) | **Full** |
|
|
36
|
+
| **Cursor** | Yes | Yes | — | MCP + Skills |
|
|
37
|
+
| **Windsurf** | Yes | — | — | MCP |
|
|
38
|
+
| **OpenCode** | Yes | Yes | — | MCP + Skills |
|
|
39
|
+
|
|
40
|
+
> **Claude Code** gets the deepest integration: MCP tools + agent skills + PreToolUse hooks that automatically enrich grep/glob/bash calls with knowledge graph context.
|
|
41
|
+
|
|
42
|
+
### Community Integrations
|
|
43
|
+
|
|
44
|
+
| Agent | Install | Source |
|
|
45
|
+
|-------|---------|--------|
|
|
46
|
+
| [pi](https://pi.dev) | `pi install npm:pi-code-mapper` | [pi-code-mapper](https://github.com/tintinweb/pi-code-mapper) |
|
|
47
|
+
|
|
48
|
+
## MCP Setup (manual)
|
|
49
|
+
|
|
50
|
+
If you prefer to configure manually instead of using `code-mapper setup`:
|
|
51
|
+
|
|
52
|
+
### Claude Code (full support — MCP + skills + hooks)
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
claude mcp add code-mapper -- npx -y code-mapper@latest mcp
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Cursor / Windsurf
|
|
59
|
+
|
|
60
|
+
Add to `~/.cursor/mcp.json` (global — works for all projects):
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"mcpServers": {
|
|
65
|
+
"code-mapper": {
|
|
66
|
+
"command": "npx",
|
|
67
|
+
"args": ["-y", "code-mapper@latest", "mcp"]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### OpenCode
|
|
74
|
+
|
|
75
|
+
Add to `~/.config/opencode/config.json`:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"mcp": {
|
|
80
|
+
"code-mapper": {
|
|
81
|
+
"command": "npx",
|
|
82
|
+
"args": ["-y", "code-mapper@latest", "mcp"]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## How It Works
|
|
89
|
+
|
|
90
|
+
Code Mapper builds a complete knowledge graph of your codebase through a multi-phase indexing pipeline:
|
|
91
|
+
|
|
92
|
+
1. **Structure** — Walks the file tree and maps folder/file relationships
|
|
93
|
+
2. **Parsing** — Extracts functions, classes, methods, and interfaces using Tree-sitter ASTs
|
|
94
|
+
3. **Resolution** — Resolves imports and function calls across files with language-aware logic
|
|
95
|
+
4. **Clustering** — Groups related symbols into functional communities
|
|
96
|
+
5. **Processes** — Traces execution flows from entry points through call chains
|
|
97
|
+
6. **Search** — Builds hybrid search indexes for fast retrieval
|
|
98
|
+
|
|
99
|
+
The result is a **LadybugDB graph database** stored locally in `.code-mapper/` with full-text search and semantic embeddings.
|
|
100
|
+
|
|
101
|
+
## MCP Tools
|
|
102
|
+
|
|
103
|
+
Your AI agent gets these tools automatically:
|
|
104
|
+
|
|
105
|
+
| Tool | What It Does | `repo` Param |
|
|
106
|
+
|------|-------------|--------------|
|
|
107
|
+
| `list_repos` | Discover all indexed repositories | — |
|
|
108
|
+
| `query` | Process-grouped hybrid search (BM25 + semantic + RRF) | Optional |
|
|
109
|
+
| `context` | 360-degree symbol view — categorized refs, process participation | Optional |
|
|
110
|
+
| `impact` | Blast radius analysis with depth grouping and confidence | Optional |
|
|
111
|
+
| `detect_changes` | Git-diff impact — maps changed lines to affected processes | Optional |
|
|
112
|
+
| `rename` | Multi-file coordinated rename with graph + text search | Optional |
|
|
113
|
+
| `cypher` | Raw Cypher graph queries | Optional |
|
|
114
|
+
|
|
115
|
+
> With one indexed repo, the `repo` param is optional. With multiple, specify which: `query({query: "auth", repo: "my-app"})`.
|
|
116
|
+
|
|
117
|
+
## MCP Resources
|
|
118
|
+
|
|
119
|
+
| Resource | Purpose |
|
|
120
|
+
|----------|---------|
|
|
121
|
+
| `code-mapper://repos` | List all indexed repositories (read first) |
|
|
122
|
+
| `code-mapper://repo/{name}/context` | Codebase stats, staleness check, and available tools |
|
|
123
|
+
| `code-mapper://repo/{name}/clusters` | All functional clusters with cohesion scores |
|
|
124
|
+
| `code-mapper://repo/{name}/cluster/{name}` | Cluster members and details |
|
|
125
|
+
| `code-mapper://repo/{name}/processes` | All execution flows |
|
|
126
|
+
| `code-mapper://repo/{name}/process/{name}` | Full process trace with steps |
|
|
127
|
+
| `code-mapper://repo/{name}/schema` | Graph schema for Cypher queries |
|
|
128
|
+
|
|
129
|
+
## MCP Prompts
|
|
130
|
+
|
|
131
|
+
| Prompt | What It Does |
|
|
132
|
+
|--------|-------------|
|
|
133
|
+
| `detect_impact` | Pre-commit change analysis — scope, affected processes, risk level |
|
|
134
|
+
| `generate_map` | Architecture documentation from the knowledge graph with mermaid diagrams |
|
|
135
|
+
|
|
136
|
+
## CLI Commands
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
code-mapper setup # Configure MCP for your editors (one-time)
|
|
140
|
+
code-mapper analyze [path] # Index a repository (or update stale index)
|
|
141
|
+
code-mapper analyze --force # Force full re-index
|
|
142
|
+
code-mapper analyze --embeddings # Enable embedding generation (slower, better search)
|
|
143
|
+
code-mapper analyze --verbose # Log skipped files when parsers are unavailable
|
|
144
|
+
code-mapper mcp # Start MCP server (stdio) — serves all indexed repos
|
|
145
|
+
code-mapper serve # Start local HTTP server (multi-repo) for web UI
|
|
146
|
+
code-mapper list # List all indexed repositories
|
|
147
|
+
code-mapper status # Show index status for current repo
|
|
148
|
+
code-mapper clean # Delete index for current repo
|
|
149
|
+
code-mapper clean --all --force # Delete all indexes
|
|
150
|
+
code-mapper wiki [path] # Generate LLM-powered docs from knowledge graph
|
|
151
|
+
code-mapper wiki --model <model> # Wiki with custom LLM model (default: gpt-4o-mini)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Multi-Repo Support
|
|
155
|
+
|
|
156
|
+
Code Mapper supports indexing multiple repositories. Each `code-mapper analyze` registers the repo in a global registry (`~/.code-mapper/registry.json`). The MCP server serves all indexed repos automatically.
|
|
157
|
+
|
|
158
|
+
## Supported Languages
|
|
159
|
+
|
|
160
|
+
TypeScript, JavaScript, Python, Java, C, C++, C#, Go, Rust, PHP, Kotlin, Swift, Ruby
|
|
161
|
+
|
|
162
|
+
### Language Feature Matrix
|
|
163
|
+
|
|
164
|
+
| Language | Imports | Named Bindings | Exports | Heritage | Type Annotations | Constructor Inference | Config | Frameworks | Entry Points |
|
|
165
|
+
|----------|---------|----------------|---------|----------|-----------------|---------------------|--------|------------|-------------|
|
|
166
|
+
| TypeScript | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
167
|
+
| JavaScript | ✓ | ✓ | ✓ | ✓ | — | ✓ | ✓ | ✓ | ✓ |
|
|
168
|
+
| Python | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
169
|
+
| Java | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — | ✓ | ✓ |
|
|
170
|
+
| Kotlin | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — | ✓ | ✓ |
|
|
171
|
+
| C# | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
172
|
+
| Go | ✓ | — | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
173
|
+
| Rust | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — | ✓ | ✓ |
|
|
174
|
+
| PHP | ✓ | ✓ | ✓ | — | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
175
|
+
| Ruby | ✓ | — | ✓ | ✓ | — | ✓ | — | ✓ | ✓ |
|
|
176
|
+
| Swift | — | — | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
177
|
+
| C | — | — | ✓ | — | ✓ | ✓ | — | ✓ | ✓ |
|
|
178
|
+
| C++ | — | — | ✓ | ✓ | ✓ | ✓ | — | ✓ | ✓ |
|
|
179
|
+
|
|
180
|
+
**Imports** — cross-file import resolution · **Named Bindings** — `import { X as Y }` / re-export tracking · **Exports** — public/exported symbol detection · **Heritage** — class inheritance, interfaces, mixins · **Type Annotations** — explicit type extraction for receiver resolution · **Constructor Inference** — infer receiver type from constructor calls (`self`/`this` resolution included for all languages) · **Config** — language toolchain config parsing (tsconfig, go.mod, etc.) · **Frameworks** — AST-based framework pattern detection · **Entry Points** — entry point scoring heuristics
|
|
181
|
+
|
|
182
|
+
## Agent Skills
|
|
183
|
+
|
|
184
|
+
Code Mapper ships with skill files that teach AI agents how to use the tools effectively:
|
|
185
|
+
|
|
186
|
+
- **Exploring** — Navigate unfamiliar code using the knowledge graph
|
|
187
|
+
- **Debugging** — Trace bugs through call chains
|
|
188
|
+
- **Impact Analysis** — Analyze blast radius before changes
|
|
189
|
+
- **Refactoring** — Plan safe refactors using dependency mapping
|
|
190
|
+
|
|
191
|
+
Installed automatically by both `code-mapper analyze` (per-repo) and `code-mapper setup` (global).
|
|
192
|
+
|
|
193
|
+
## Requirements
|
|
194
|
+
|
|
195
|
+
- Node.js >= 18
|
|
196
|
+
- Git repository (uses git for commit tracking)
|
|
197
|
+
|
|
198
|
+
## Privacy
|
|
199
|
+
|
|
200
|
+
- All processing happens locally on your machine
|
|
201
|
+
- No code is sent to any server
|
|
202
|
+
- Index stored in `.code-mapper/` inside your repo (gitignored)
|
|
203
|
+
- Global registry at `~/.code-mapper/` stores only paths and metadata
|
|
204
|
+
|
|
205
|
+
## Web UI
|
|
206
|
+
|
|
207
|
+
Code Mapper also has a browser-based UI at [code-mapper.vercel.app](https://code-mapper.vercel.app) — 100% client-side, your code never leaves the browser.
|
|
208
|
+
|
|
209
|
+
**Local Backend Mode:** Run `code-mapper serve` and open the web UI locally — it auto-detects the server and shows all your indexed repos, with full AI chat support. No need to re-upload or re-index. The agent's tools (Cypher queries, search, code navigation) route through the backend HTTP API automatically.
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
[PolyForm Noncommercial 1.0.0](https://polyformproject.org/licenses/noncommercial/1.0.0/)
|
|
214
|
+
|
|
215
|
+
Free for non-commercial use. Contact for commercial licensing.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file AI context generator — creates AGENTS.md and CLAUDE.md with inline Code Mapper context
|
|
3
|
+
* @description AGENTS.md is read by Cursor, Windsurf, OpenCode, Cline etc; CLAUDE.md is for Claude Code
|
|
4
|
+
*/
|
|
5
|
+
interface RepoStats {
|
|
6
|
+
files?: number;
|
|
7
|
+
nodes?: number;
|
|
8
|
+
edges?: number;
|
|
9
|
+
communities?: number;
|
|
10
|
+
clusters?: number;
|
|
11
|
+
processes?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generate AI context files after indexing
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateAIContextFiles(repoPath: string, _storagePath: string, projectName: string, stats: RepoStats): Promise<{
|
|
17
|
+
files: string[];
|
|
18
|
+
}>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// code-mapper/src/cli/ai-context.ts
|
|
2
|
+
/**
|
|
3
|
+
* @file AI context generator — creates AGENTS.md and CLAUDE.md with inline Code Mapper context
|
|
4
|
+
* @description AGENTS.md is read by Cursor, Windsurf, OpenCode, Cline etc; CLAUDE.md is for Claude Code
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'fs/promises';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
const CODE_MAPPER_START_MARKER = '<!-- code-mapper:start -->';
|
|
9
|
+
const CODE_MAPPER_END_MARKER = '<!-- code-mapper:end -->';
|
|
10
|
+
/**
|
|
11
|
+
* Generate the full Code Mapper context content.
|
|
12
|
+
*
|
|
13
|
+
* Design principles:
|
|
14
|
+
* - Use RFC 2119 language (MUST, NEVER, ALWAYS) — models follow imperative rules
|
|
15
|
+
* - Three-tier boundaries (Always/When/Never) — proven to change model behavior
|
|
16
|
+
* - Keep under 120 lines — adherence degrades past 150 lines
|
|
17
|
+
* - Exact tool commands with parameters — vague directives get ignored
|
|
18
|
+
* - Self-review checklist — forces model to verify its own work
|
|
19
|
+
*/
|
|
20
|
+
function generateCodeMapperContent(projectName, stats) {
|
|
21
|
+
return `${CODE_MAPPER_START_MARKER}
|
|
22
|
+
# Code Mapper — Code Intelligence
|
|
23
|
+
|
|
24
|
+
This project is indexed by Code Mapper as **${projectName}** (${stats.nodes || 0} symbols, ${stats.edges || 0} relationships, ${stats.processes || 0} execution flows). Use the Code Mapper MCP tools to understand code, assess impact, and navigate safely.
|
|
25
|
+
|
|
26
|
+
> If any Code Mapper tool warns the index is stale, run \`npx code-mapper analyze\` in terminal first.
|
|
27
|
+
|
|
28
|
+
## Always Do
|
|
29
|
+
|
|
30
|
+
- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run \`code-mapper_impact({target: "symbolName", direction: "upstream"})\` and report the blast radius (direct callers, affected processes, risk level) to the user.
|
|
31
|
+
- **MUST run \`code-mapper_detect_changes()\` before committing** to verify your changes only affect expected symbols and execution flows.
|
|
32
|
+
- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
|
|
33
|
+
- When exploring unfamiliar code, use \`code-mapper_query({query: "concept"})\` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance.
|
|
34
|
+
- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use \`code-mapper_context({name: "symbolName"})\`.
|
|
35
|
+
|
|
36
|
+
## When Debugging
|
|
37
|
+
|
|
38
|
+
1. \`code-mapper_query({query: "<error or symptom>"})\` — find execution flows related to the issue
|
|
39
|
+
2. \`code-mapper_context({name: "<suspect function>"})\` — see all callers, callees, and process participation
|
|
40
|
+
3. \`READ code-mapper://repo/${projectName}/process/{processName}\` — trace the full execution flow step by step
|
|
41
|
+
4. For regressions: \`code-mapper_detect_changes({scope: "compare", base_ref: "main"})\` — see what your branch changed
|
|
42
|
+
|
|
43
|
+
## When Refactoring
|
|
44
|
+
|
|
45
|
+
- **Renaming**: MUST use \`code-mapper_rename({symbol_name: "old", new_name: "new", dry_run: true})\` first. Review the preview — graph edits are safe, text_search edits need manual review. Then run with \`dry_run: false\`.
|
|
46
|
+
- **Extracting/Splitting**: MUST run \`code-mapper_context({name: "target"})\` to see all incoming/outgoing refs, then \`code-mapper_impact({target: "target", direction: "upstream"})\` to find all external callers before moving code.
|
|
47
|
+
- After any refactor: run \`code-mapper_detect_changes({scope: "all"})\` to verify only expected files changed.
|
|
48
|
+
|
|
49
|
+
## Never Do
|
|
50
|
+
|
|
51
|
+
- NEVER edit a function, class, or method without first running \`code-mapper_impact\` on it.
|
|
52
|
+
- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
|
|
53
|
+
- NEVER rename symbols with find-and-replace — use \`code-mapper_rename\` which understands the call graph.
|
|
54
|
+
- NEVER commit changes without running \`code-mapper_detect_changes()\` to check affected scope.
|
|
55
|
+
|
|
56
|
+
## Tools Quick Reference
|
|
57
|
+
|
|
58
|
+
| Tool | When to use | Command |
|
|
59
|
+
|------|-------------|---------|
|
|
60
|
+
| \`query\` | Find code by concept | \`code-mapper_query({query: "auth validation"})\` |
|
|
61
|
+
| \`context\` | 360-degree view of one symbol | \`code-mapper_context({name: "validateUser"})\` |
|
|
62
|
+
| \`impact\` | Blast radius before editing | \`code-mapper_impact({target: "X", direction: "upstream"})\` |
|
|
63
|
+
| \`detect_changes\` | Pre-commit scope check | \`code-mapper_detect_changes({scope: "staged"})\` |
|
|
64
|
+
| \`rename\` | Safe multi-file rename | \`code-mapper_rename({symbol_name: "old", new_name: "new", dry_run: true})\` |
|
|
65
|
+
| \`cypher\` | Custom graph queries | \`code-mapper_cypher({query: "MATCH ..."})\` |
|
|
66
|
+
|
|
67
|
+
## Impact Risk Levels
|
|
68
|
+
|
|
69
|
+
| Depth | Meaning | Action |
|
|
70
|
+
|-------|---------|--------|
|
|
71
|
+
| d=1 | WILL BREAK — direct callers/importers | MUST update these |
|
|
72
|
+
| d=2 | LIKELY AFFECTED — indirect deps | Should test |
|
|
73
|
+
| d=3 | MAY NEED TESTING — transitive | Test if critical path |
|
|
74
|
+
|
|
75
|
+
## Resources
|
|
76
|
+
|
|
77
|
+
| Resource | Use for |
|
|
78
|
+
|----------|---------|
|
|
79
|
+
| \`code-mapper://repo/${projectName}/context\` | Codebase overview, check index freshness |
|
|
80
|
+
| \`code-mapper://repo/${projectName}/clusters\` | All functional areas |
|
|
81
|
+
| \`code-mapper://repo/${projectName}/processes\` | All execution flows |
|
|
82
|
+
| \`code-mapper://repo/${projectName}/process/{name}\` | Step-by-step execution trace |
|
|
83
|
+
|
|
84
|
+
## Self-Check Before Finishing
|
|
85
|
+
|
|
86
|
+
Before completing any code modification task, verify:
|
|
87
|
+
1. \`code-mapper_impact\` was run for all modified symbols
|
|
88
|
+
2. No HIGH/CRITICAL risk warnings were ignored
|
|
89
|
+
3. \`code-mapper_detect_changes()\` confirms changes match expected scope
|
|
90
|
+
4. All d=1 (WILL BREAK) dependents were updated
|
|
91
|
+
|
|
92
|
+
## Keeping the Index Fresh
|
|
93
|
+
|
|
94
|
+
After committing code changes, the Code Mapper index becomes stale. Re-run analyze to update it:
|
|
95
|
+
|
|
96
|
+
\`\`\`bash
|
|
97
|
+
npx code-mapper analyze
|
|
98
|
+
\`\`\`
|
|
99
|
+
|
|
100
|
+
If the index previously included embeddings, preserve them by adding \`--embeddings\`:
|
|
101
|
+
|
|
102
|
+
\`\`\`bash
|
|
103
|
+
npx code-mapper analyze --embeddings
|
|
104
|
+
\`\`\`
|
|
105
|
+
|
|
106
|
+
To check whether embeddings exist, inspect \`.code-mapper/meta.json\` — the \`stats.embeddings\` field shows the count (0 means no embeddings). **Running analyze without \`--embeddings\` will delete any previously generated embeddings.**
|
|
107
|
+
|
|
108
|
+
> Claude Code users: A PostToolUse hook handles this automatically after \`git commit\` and \`git merge\`.
|
|
109
|
+
|
|
110
|
+
${CODE_MAPPER_END_MARKER}`;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Check if a file exists
|
|
114
|
+
*/
|
|
115
|
+
async function fileExists(filePath) {
|
|
116
|
+
try {
|
|
117
|
+
await fs.access(filePath);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create or update Code Mapper section in a file
|
|
126
|
+
* - If file doesn't exist: create with Code Mapper content
|
|
127
|
+
* - If file exists without Code Mapper section: append
|
|
128
|
+
* - If file exists with Code Mapper section: replace that section
|
|
129
|
+
*/
|
|
130
|
+
async function upsertCodeMapperSection(filePath, content) {
|
|
131
|
+
const exists = await fileExists(filePath);
|
|
132
|
+
if (!exists) {
|
|
133
|
+
await fs.writeFile(filePath, content, 'utf-8');
|
|
134
|
+
return 'created';
|
|
135
|
+
}
|
|
136
|
+
const existingContent = await fs.readFile(filePath, 'utf-8');
|
|
137
|
+
// Check if Code Mapper section already exists
|
|
138
|
+
const startIdx = existingContent.indexOf(CODE_MAPPER_START_MARKER);
|
|
139
|
+
const endIdx = existingContent.indexOf(CODE_MAPPER_END_MARKER);
|
|
140
|
+
if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
|
|
141
|
+
// Replace existing section
|
|
142
|
+
const before = existingContent.substring(0, startIdx);
|
|
143
|
+
const after = existingContent.substring(endIdx + CODE_MAPPER_END_MARKER.length);
|
|
144
|
+
const newContent = before + content + after;
|
|
145
|
+
await fs.writeFile(filePath, newContent.trim() + '\n', 'utf-8');
|
|
146
|
+
return 'updated';
|
|
147
|
+
}
|
|
148
|
+
// Append new section
|
|
149
|
+
const newContent = existingContent.trim() + '\n\n' + content + '\n';
|
|
150
|
+
await fs.writeFile(filePath, newContent, 'utf-8');
|
|
151
|
+
return 'appended';
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Generate AI context files after indexing
|
|
155
|
+
*/
|
|
156
|
+
export async function generateAIContextFiles(repoPath, _storagePath, projectName, stats) {
|
|
157
|
+
const content = generateCodeMapperContent(projectName, stats);
|
|
158
|
+
const createdFiles = [];
|
|
159
|
+
// Create AGENTS.md (standard for Cursor, Windsurf, OpenCode, Cline, etc.)
|
|
160
|
+
const agentsPath = path.join(repoPath, 'AGENTS.md');
|
|
161
|
+
const agentsResult = await upsertCodeMapperSection(agentsPath, content);
|
|
162
|
+
createdFiles.push(`AGENTS.md (${agentsResult})`);
|
|
163
|
+
// Create CLAUDE.md (for Claude Code)
|
|
164
|
+
const claudePath = path.join(repoPath, 'CLAUDE.md');
|
|
165
|
+
const claudeResult = await upsertCodeMapperSection(claudePath, content);
|
|
166
|
+
createdFiles.push(`CLAUDE.md (${claudeResult})`);
|
|
167
|
+
return { files: createdFiles };
|
|
168
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** @file analyze.ts @description Indexes a repository, builds the knowledge graph, and stores it in .code-mapper/ */
|
|
2
|
+
export interface AnalyzeOptions {
|
|
3
|
+
force?: boolean;
|
|
4
|
+
embeddings?: boolean;
|
|
5
|
+
verbose?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const analyzeCommand: (inputPath?: string, options?: AnalyzeOptions) => Promise<void>;
|