codecompass-mcp 2.0.0__tar.gz → 2.2.0__tar.gz
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.
- codecompass_mcp-2.2.0/PKG-INFO +312 -0
- codecompass_mcp-2.2.0/README.md +275 -0
- codecompass_mcp-2.2.0/codecompass_mcp.egg-info/PKG-INFO +312 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/codecompass_mcp.egg-info/SOURCES.txt +1 -1
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/codecompass_mcp.egg-info/entry_points.txt +0 -1
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/codecompass_mcp.egg-info/requires.txt +1 -2
- codecompass_mcp-2.2.0/config.py +8 -0
- codecompass_mcp-2.2.0/graph/code_graph_client.py +545 -0
- codecompass_mcp-2.2.0/graph/code_query_cli.py +833 -0
- codecompass_mcp-2.2.0/graph/setup.py +36 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/ingestion/code_parser.py +52 -6
- codecompass_mcp-2.2.0/ingestion/entity_resolver.py +100 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/ingestion/file_watcher.py +1 -1
- codecompass_mcp-2.2.0/ingestion/graph_writer.py +16 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/ingestion/hierarchy_builder.py +1 -1
- codecompass_mcp-2.2.0/ingestion/source_context.py +155 -0
- codecompass_mcp-2.2.0/main.py +394 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/pyproject.toml +4 -6
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/tests/test_batch_impact.py +5 -5
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/tests/test_blast_radius.py +15 -26
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/tests/test_ingestion.py +24 -21
- codecompass_mcp-2.0.0/PKG-INFO +0 -368
- codecompass_mcp-2.0.0/README.md +0 -330
- codecompass_mcp-2.0.0/codecompass_mcp.egg-info/PKG-INFO +0 -368
- codecompass_mcp-2.0.0/config.py +0 -16
- codecompass_mcp-2.0.0/graph/code_graph_client.py +0 -485
- codecompass_mcp-2.0.0/graph/code_query_cli.py +0 -504
- codecompass_mcp-2.0.0/graph/mcp_server.py +0 -280
- codecompass_mcp-2.0.0/graph/setup.py +0 -255
- codecompass_mcp-2.0.0/ingestion/entity_resolver.py +0 -179
- codecompass_mcp-2.0.0/ingestion/graph_writer.py +0 -17
- codecompass_mcp-2.0.0/main.py +0 -306
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/LICENSE +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/codecompass_mcp.egg-info/dependency_links.txt +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/codecompass_mcp.egg-info/top_level.txt +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/graph/__init__.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/graph/cli.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/ingestion/__init__.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/ingestion/chunker.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/ingestion/code_normalizer.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/ingestion/reader_agent.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/models/__init__.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/models/code_types.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/models/types.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/setup.cfg +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/tests/test_code_parser.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/tests/test_lit_css_parser.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/utils/__init__.py +0 -0
- {codecompass_mcp-2.0.0 → codecompass_mcp-2.2.0}/utils/formatting.py +0 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codecompass-mcp
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Summary: Structural code context for AI coding agents — a local code knowledge graph for blast radius, impact, deps, dead code, and flow tracing
|
|
5
|
+
Author: CodeCompass contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: ai,code-graph,llm,coding-agent,tree-sitter
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
16
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: anthropic>=0.40.0
|
|
21
|
+
Requires-Dist: networkx>=3.0
|
|
22
|
+
Requires-Dist: pypdf2>=3.0.0
|
|
23
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
24
|
+
Requires-Dist: rich>=13.0.0
|
|
25
|
+
Requires-Dist: tqdm>=4.66.0
|
|
26
|
+
Requires-Dist: tree-sitter>=0.21.0
|
|
27
|
+
Requires-Dist: tree-sitter-python>=0.21.0
|
|
28
|
+
Requires-Dist: tree-sitter-javascript>=0.21.0
|
|
29
|
+
Requires-Dist: tree-sitter-typescript>=0.21.0
|
|
30
|
+
Requires-Dist: tree-sitter-html>=0.21.0
|
|
31
|
+
Requires-Dist: tree-sitter-css>=0.21.0
|
|
32
|
+
Requires-Dist: watchdog>=4.0.0
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# CodeCompass
|
|
39
|
+
|
|
40
|
+
A local code knowledge graph that gives AI agents (and humans) a map of your codebase — so they know what's connected before they edit.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## The problem
|
|
45
|
+
|
|
46
|
+
AI coding agents read files one at a time. They don't know that renaming a function in `auth.py` will break three importers, a test file, and a CSS class that shares the name. They guess which files to open, miss dependencies, and introduce bugs.
|
|
47
|
+
|
|
48
|
+
## The solution
|
|
49
|
+
|
|
50
|
+
CodeCompass parses your codebase into a dependency graph — functions, classes, modules, imports, CSS selectors, HTML references — and stores it as a local JSON file. Agents query the graph before editing to see exactly what's connected.
|
|
51
|
+
|
|
52
|
+
No database. No cloud. One JSON file per repo.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## In practice
|
|
57
|
+
|
|
58
|
+
**Scenario 1 — Safe rename.** An agent is asked to rename `authenticate`. Instead of
|
|
59
|
+
grepping and hoping, it runs `codecompass query --blast-radius src/auth/login.py`
|
|
60
|
+
and instantly sees the three importers, the test file, and a SCSS selector that
|
|
61
|
+
share the name — then edits all of them in one pass, no broken build.
|
|
62
|
+
|
|
63
|
+
**Scenario 2 — Onboarding onto an unfamiliar pipeline.** A new contributor (human or
|
|
64
|
+
agent) needs to understand how `ingest_code` works. Running
|
|
65
|
+
`codecompass query --flow ingest_code` traces the full forward call graph — which
|
|
66
|
+
parser runs, where the graph gets written, what normalizes the triples — in one
|
|
67
|
+
command, instead of opening a dozen files to follow the thread:
|
|
68
|
+
|
|
69
|
+

|
|
70
|
+
|
|
71
|
+
The `json` flow format hands each node its real signature, docstring, and source
|
|
72
|
+
snippet, plus the numbered call order. An agent reads that and narrates the
|
|
73
|
+
flow in plain language — for example, the diagram above becomes:
|
|
74
|
+
|
|
75
|
+
> **How `ingest_code` works** (narrated by an agent from `--flow ... --format json`)
|
|
76
|
+
>
|
|
77
|
+
> 1. **`init_project`** — sets up the `.codecompass/` directory and registers the
|
|
78
|
+
> project's `AGENTS.md` rules before anything is parsed.
|
|
79
|
+
> 2. **`get_client`** — opens the local NetworkX graph that everything will be
|
|
80
|
+
> written into.
|
|
81
|
+
> 3. **`build_hierarchy`** — walks the repo and writes the Project → Folder → File
|
|
82
|
+
> skeleton nodes.
|
|
83
|
+
> 4. **`parse_directory`** — recursively parses every supported file, extracting
|
|
84
|
+
> functions, classes, imports, and call relationships.
|
|
85
|
+
> 5. **`normalize_triples`** — (optional) runs the Haiku pass to canonicalize
|
|
86
|
+
> entity names.
|
|
87
|
+
> 6. **`write_code_triples_batch`** — persists all extracted relationships into the
|
|
88
|
+
> graph, then reports the node count and refreshes `AGENTS.md`.
|
|
89
|
+
>
|
|
90
|
+
> Net effect: a repo goes from raw files to a queryable dependency graph in one
|
|
91
|
+
> pass, with the graph saved locally as JSON.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## What you get
|
|
96
|
+
|
|
97
|
+
Every node in the graph carries:
|
|
98
|
+
- **`kind`** — type and language combined (e.g. `function:python`, `class:typescript`, `css_selector:scss`)
|
|
99
|
+
- **`description`** — human-readable label (e.g. `python function in src/auth/login.py`)
|
|
100
|
+
- **Typed edges** — `CALLS`, `IMPORTS`, `INHERITS`, `DEFINED_IN`, `STYLES`, `USES_VAR`, `REFERENCES`, etc.
|
|
101
|
+
|
|
102
|
+
Agents can answer structural questions in milliseconds without reading a single file:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# What breaks if I edit this?
|
|
106
|
+
codecompass query --blast-radius src/auth/login.py
|
|
107
|
+
|
|
108
|
+
# Who calls this function?
|
|
109
|
+
codecompass query --impact "authenticate"
|
|
110
|
+
|
|
111
|
+
# What does this file depend on?
|
|
112
|
+
codecompass query --deps src/api/routes.py
|
|
113
|
+
|
|
114
|
+
# Full project structure with entity types
|
|
115
|
+
codecompass query --tree
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
All commands default to the current directory.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Setup
|
|
123
|
+
|
|
124
|
+
### Prerequisites
|
|
125
|
+
|
|
126
|
+
- Python 3.10+
|
|
127
|
+
- pip
|
|
128
|
+
|
|
129
|
+
### Install
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# From the codecompass directory
|
|
133
|
+
pip install -e .
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Index a project
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
cd /path/to/your/project
|
|
140
|
+
codecompass init
|
|
141
|
+
codecompass ingest-code
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
That's it. Two commands:
|
|
145
|
+
1. **`init`** creates `.codecompass/` and writes agent instructions into `AGENTS.md`
|
|
146
|
+
2. **`ingest-code`** parses all source files and builds the graph
|
|
147
|
+
|
|
148
|
+
`ingest-code` runs `init` automatically if `.codecompass/` doesn't exist yet.
|
|
149
|
+
|
|
150
|
+
### What happens on init
|
|
151
|
+
|
|
152
|
+
- Creates `.codecompass/` with `graph.json`, `overview.md`, `memory.md`, and `learnings.md`
|
|
153
|
+
- Writes a `## Code graph` section into the project's `AGENTS.md` with mandatory rules for agents:
|
|
154
|
+
- Run `--blast-radius` before editing any file
|
|
155
|
+
- Run `--impact` before calling unfamiliar symbols
|
|
156
|
+
- Re-ingest after creating or deleting files
|
|
157
|
+
|
|
158
|
+
Any AI agent that reads `AGENTS.md` (Claude Code, OpenCode, Cursor, etc.) will follow these rules automatically.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Queries
|
|
163
|
+
|
|
164
|
+
| Command | When to use it |
|
|
165
|
+
|---|---|
|
|
166
|
+
| `codecompass query --blast-radius <file_or_symbol>` | Before editing — see everything that depends on it |
|
|
167
|
+
| `codecompass query --impact <symbol>` | Before renaming/removing — find all callers and importers |
|
|
168
|
+
| `codecompass query --deps <file>` | Understanding a file — see what it imports and uses |
|
|
169
|
+
| `codecompass query --trace <function>` | Follow a call chain forward |
|
|
170
|
+
| `codecompass query --tree` | Orient yourself — full project structure |
|
|
171
|
+
| `codecompass query --styles <element>` | Find CSS selectors for an HTML element |
|
|
172
|
+
| `codecompass query --batch-impact <f1> <f2> ...` | Multi-file PR — union blast radius |
|
|
173
|
+
| `codecompass query --flow <entry_symbol>` | Trace the call/import flow from an entry point |
|
|
174
|
+
| `codecompass query --dead-code` | Find functions/classes with no caller or importer |
|
|
175
|
+
|
|
176
|
+
Add `--rich` for formatted table output. Add `--hops N` to control traversal depth (default: 3).
|
|
177
|
+
|
|
178
|
+
### Dead code
|
|
179
|
+
|
|
180
|
+
`--dead-code` reports entities with no inbound `CALLS`/`IMPORTS`/`REFERENCES` edge — candidates for removal such as old helpers, superseded function versions, or orphaned scripts:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
codecompass query --dead-code # likely-dead only
|
|
184
|
+
codecompass query --dead-code --include-entrypoints # also show probable entry points
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Results are split into **likely dead** (private/internal, no caller) and **possible entry points** (`run_*`, handlers, tests — invoked by a runtime, not a static call). This is **static analysis**: dynamic dispatch, reflection, and string-based invocation are invisible, so every result is a candidate to verify (grep the name across the repo) before deleting.
|
|
188
|
+
|
|
189
|
+
### Flow charts
|
|
190
|
+
|
|
191
|
+
`--flow` traces forward from an entry point along `CALLS` and `IMPORTS` edges. Pick an output format with `--format`:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
codecompass query --flow "src.main" --hops 3 # draw.io (default)
|
|
195
|
+
codecompass query --flow "src.main" --format mermaid # Markdown + mermaid
|
|
196
|
+
codecompass query --flow "src.main" --format json # agent narration
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Every format numbers each call by source line so call order is explicit. By default, external/stdlib symbols are filtered out — add `--include-external` to show everything. Output is written to `.codecompass/flow_<entry>.{drawio,md,json}`.
|
|
200
|
+
|
|
201
|
+
- **`drawio`** — opens in [draw.io](https://app.diagrams.net) (desktop or web). Nodes color-coded by type, entry point has a thick border, edges color-coded by relationship (blue = CALLS, green = IMPORTS).
|
|
202
|
+
- **`mermaid`** — a Markdown file with an embedded mermaid flowchart that renders directly on GitHub. Convert to SVG with `npx @mermaid-js/mermaid-cli -i flow_<entry>.md -o flow_<entry>.svg`.
|
|
203
|
+
- **`json`** — each node carries its real signature, docstring, source snippet, and line range; each edge carries its call order and call site. Built for agents: feed it to an LLM to generate a comprehensive data-flow explanation of how a pipeline or feature actually works.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Commands
|
|
208
|
+
|
|
209
|
+
| Command | Purpose |
|
|
210
|
+
|---|---|
|
|
211
|
+
| `codecompass init [path]` | Create `.codecompass/` and register in `AGENTS.md` |
|
|
212
|
+
| `codecompass ingest-code [path]` | Parse source files and build/rebuild the graph |
|
|
213
|
+
| `codecompass query <flags> [path]` | Query the graph (blast-radius, impact, deps, flow, tree, etc.) |
|
|
214
|
+
| `codecompass watch [path]` | Live re-index on file changes |
|
|
215
|
+
| `codecompass load-triples <file> <path>` | Load pre-processed triples from JSON |
|
|
216
|
+
| `codecompass setup` | Copy instructions to `~/.config/opencode/codecompass/` |
|
|
217
|
+
|
|
218
|
+
All commands default to `.` (current directory) when path is omitted.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Supported languages
|
|
223
|
+
|
|
224
|
+
| Language | Entity types extracted |
|
|
225
|
+
|---|---|
|
|
226
|
+
| Python | modules, functions, classes, imports, calls, inheritance |
|
|
227
|
+
| JavaScript | modules, functions, classes, imports, calls |
|
|
228
|
+
| TypeScript / TSX | modules, functions, classes, imports, calls |
|
|
229
|
+
| HTML | elements, references, includes |
|
|
230
|
+
| CSS | selectors, variables, definitions |
|
|
231
|
+
| SCSS | selectors, variables, mixins, imports |
|
|
232
|
+
| `.styles.ts` (Lit) | CSS-in-JS — `var(--token)` usages, `:host` declarations |
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## How it works
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
Source files
|
|
240
|
+
│
|
|
241
|
+
▼
|
|
242
|
+
hierarchy_builder — walks repo → Project / Folder / File skeleton
|
|
243
|
+
│
|
|
244
|
+
▼
|
|
245
|
+
code_parser — tree-sitter extraction (no API calls)
|
|
246
|
+
│ extracts entities + relationships as CodeTriples
|
|
247
|
+
▼
|
|
248
|
+
graph.json — NetworkX MultiDiGraph serialized as JSON node-link data
|
|
249
|
+
│ typed edges: CALLS, IMPORTS, INHERITS, STYLES, DEFINED_IN, …
|
|
250
|
+
│ node attrs: kind, description, language, entity_type, file
|
|
251
|
+
▼
|
|
252
|
+
code_query_cli — graph traversal: blast-radius, impact, deps, trace, tree
|
|
253
|
+
│
|
|
254
|
+
▼
|
|
255
|
+
AGENTS.md — mandatory rules injected into the project for any AI agent
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Everything runs locally, in-process. No network calls, no database, no API keys.
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Project structure
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
codecompass/
|
|
266
|
+
├── graph/
|
|
267
|
+
│ ├── cli.py pip entry point → main.py
|
|
268
|
+
│ ├── code_graph_client.py NetworkX graph client — nodes, edges, traversal
|
|
269
|
+
│ ├── code_query_cli.py query CLI — blast-radius / impact / deps / trace / tree / dead-code / flow
|
|
270
|
+
│ └── setup.py opencode setup wizard
|
|
271
|
+
├── ingestion/
|
|
272
|
+
│ ├── code_parser.py tree-sitter entity + relationship extraction
|
|
273
|
+
│ ├── hierarchy_builder.py Project → Folder → File skeleton
|
|
274
|
+
│ ├── file_watcher.py incremental re-index on file changes
|
|
275
|
+
│ └── code_normalizer.py optional entity name normalization (Haiku)
|
|
276
|
+
├── models/
|
|
277
|
+
│ └── code_types.py CodeTriple, FileNode, FolderNode
|
|
278
|
+
├── opencode/
|
|
279
|
+
│ └── instructions.md agent instructions for opencode integration
|
|
280
|
+
├── config.py env var config with fallback defaults
|
|
281
|
+
└── main.py CLI dispatch: init / ingest-code / query / watch
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Inside each indexed project:
|
|
285
|
+
|
|
286
|
+
```
|
|
287
|
+
your-project/
|
|
288
|
+
├── .codecompass/
|
|
289
|
+
│ ├── graph.json the code knowledge graph (auto-generated)
|
|
290
|
+
│ ├── overview.md what the repo is / how to run it (read first)
|
|
291
|
+
│ ├── memory.md architecture & data flow (human-editable)
|
|
292
|
+
│ └── learnings.md gotchas, decisions, dead code (human-editable)
|
|
293
|
+
└── AGENTS.md agent instructions (auto-updated by codecompass)
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## Tips
|
|
299
|
+
|
|
300
|
+
- **Commit or gitignore** `.codecompass/graph.json` — your choice. Committing it means teammates and CI get the graph for free.
|
|
301
|
+
- **Re-ingest after refactors** — moved functions, renamed classes, deleted files. The graph doesn't auto-update unless `watch` is running.
|
|
302
|
+
- **Use `watch` during active development** — `codecompass watch` keeps the graph current as you save files.
|
|
303
|
+
- **Install once, use everywhere** — `pip install -e .` from the codecompass directory. The `codecompass` command works in any project.
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Limitations
|
|
308
|
+
|
|
309
|
+
- **Structure only** — the graph knows what calls what, not what anything *means*
|
|
310
|
+
- **No cross-repo edges** — entities outside the indexed repo won't appear
|
|
311
|
+
- **Lit CSS** covers explicit `var(--foo)` and `:host` declarations; generated property names from `theme.props()` are not indexed
|
|
312
|
+
- **Large repos** (50k+ files) may produce sizable graph files — benchmark before committing
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# CodeCompass
|
|
2
|
+
|
|
3
|
+
A local code knowledge graph that gives AI agents (and humans) a map of your codebase — so they know what's connected before they edit.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## The problem
|
|
8
|
+
|
|
9
|
+
AI coding agents read files one at a time. They don't know that renaming a function in `auth.py` will break three importers, a test file, and a CSS class that shares the name. They guess which files to open, miss dependencies, and introduce bugs.
|
|
10
|
+
|
|
11
|
+
## The solution
|
|
12
|
+
|
|
13
|
+
CodeCompass parses your codebase into a dependency graph — functions, classes, modules, imports, CSS selectors, HTML references — and stores it as a local JSON file. Agents query the graph before editing to see exactly what's connected.
|
|
14
|
+
|
|
15
|
+
No database. No cloud. One JSON file per repo.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## In practice
|
|
20
|
+
|
|
21
|
+
**Scenario 1 — Safe rename.** An agent is asked to rename `authenticate`. Instead of
|
|
22
|
+
grepping and hoping, it runs `codecompass query --blast-radius src/auth/login.py`
|
|
23
|
+
and instantly sees the three importers, the test file, and a SCSS selector that
|
|
24
|
+
share the name — then edits all of them in one pass, no broken build.
|
|
25
|
+
|
|
26
|
+
**Scenario 2 — Onboarding onto an unfamiliar pipeline.** A new contributor (human or
|
|
27
|
+
agent) needs to understand how `ingest_code` works. Running
|
|
28
|
+
`codecompass query --flow ingest_code` traces the full forward call graph — which
|
|
29
|
+
parser runs, where the graph gets written, what normalizes the triples — in one
|
|
30
|
+
command, instead of opening a dozen files to follow the thread:
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
The `json` flow format hands each node its real signature, docstring, and source
|
|
35
|
+
snippet, plus the numbered call order. An agent reads that and narrates the
|
|
36
|
+
flow in plain language — for example, the diagram above becomes:
|
|
37
|
+
|
|
38
|
+
> **How `ingest_code` works** (narrated by an agent from `--flow ... --format json`)
|
|
39
|
+
>
|
|
40
|
+
> 1. **`init_project`** — sets up the `.codecompass/` directory and registers the
|
|
41
|
+
> project's `AGENTS.md` rules before anything is parsed.
|
|
42
|
+
> 2. **`get_client`** — opens the local NetworkX graph that everything will be
|
|
43
|
+
> written into.
|
|
44
|
+
> 3. **`build_hierarchy`** — walks the repo and writes the Project → Folder → File
|
|
45
|
+
> skeleton nodes.
|
|
46
|
+
> 4. **`parse_directory`** — recursively parses every supported file, extracting
|
|
47
|
+
> functions, classes, imports, and call relationships.
|
|
48
|
+
> 5. **`normalize_triples`** — (optional) runs the Haiku pass to canonicalize
|
|
49
|
+
> entity names.
|
|
50
|
+
> 6. **`write_code_triples_batch`** — persists all extracted relationships into the
|
|
51
|
+
> graph, then reports the node count and refreshes `AGENTS.md`.
|
|
52
|
+
>
|
|
53
|
+
> Net effect: a repo goes from raw files to a queryable dependency graph in one
|
|
54
|
+
> pass, with the graph saved locally as JSON.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## What you get
|
|
59
|
+
|
|
60
|
+
Every node in the graph carries:
|
|
61
|
+
- **`kind`** — type and language combined (e.g. `function:python`, `class:typescript`, `css_selector:scss`)
|
|
62
|
+
- **`description`** — human-readable label (e.g. `python function in src/auth/login.py`)
|
|
63
|
+
- **Typed edges** — `CALLS`, `IMPORTS`, `INHERITS`, `DEFINED_IN`, `STYLES`, `USES_VAR`, `REFERENCES`, etc.
|
|
64
|
+
|
|
65
|
+
Agents can answer structural questions in milliseconds without reading a single file:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# What breaks if I edit this?
|
|
69
|
+
codecompass query --blast-radius src/auth/login.py
|
|
70
|
+
|
|
71
|
+
# Who calls this function?
|
|
72
|
+
codecompass query --impact "authenticate"
|
|
73
|
+
|
|
74
|
+
# What does this file depend on?
|
|
75
|
+
codecompass query --deps src/api/routes.py
|
|
76
|
+
|
|
77
|
+
# Full project structure with entity types
|
|
78
|
+
codecompass query --tree
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
All commands default to the current directory.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Setup
|
|
86
|
+
|
|
87
|
+
### Prerequisites
|
|
88
|
+
|
|
89
|
+
- Python 3.10+
|
|
90
|
+
- pip
|
|
91
|
+
|
|
92
|
+
### Install
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# From the codecompass directory
|
|
96
|
+
pip install -e .
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Index a project
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
cd /path/to/your/project
|
|
103
|
+
codecompass init
|
|
104
|
+
codecompass ingest-code
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
That's it. Two commands:
|
|
108
|
+
1. **`init`** creates `.codecompass/` and writes agent instructions into `AGENTS.md`
|
|
109
|
+
2. **`ingest-code`** parses all source files and builds the graph
|
|
110
|
+
|
|
111
|
+
`ingest-code` runs `init` automatically if `.codecompass/` doesn't exist yet.
|
|
112
|
+
|
|
113
|
+
### What happens on init
|
|
114
|
+
|
|
115
|
+
- Creates `.codecompass/` with `graph.json`, `overview.md`, `memory.md`, and `learnings.md`
|
|
116
|
+
- Writes a `## Code graph` section into the project's `AGENTS.md` with mandatory rules for agents:
|
|
117
|
+
- Run `--blast-radius` before editing any file
|
|
118
|
+
- Run `--impact` before calling unfamiliar symbols
|
|
119
|
+
- Re-ingest after creating or deleting files
|
|
120
|
+
|
|
121
|
+
Any AI agent that reads `AGENTS.md` (Claude Code, OpenCode, Cursor, etc.) will follow these rules automatically.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Queries
|
|
126
|
+
|
|
127
|
+
| Command | When to use it |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `codecompass query --blast-radius <file_or_symbol>` | Before editing — see everything that depends on it |
|
|
130
|
+
| `codecompass query --impact <symbol>` | Before renaming/removing — find all callers and importers |
|
|
131
|
+
| `codecompass query --deps <file>` | Understanding a file — see what it imports and uses |
|
|
132
|
+
| `codecompass query --trace <function>` | Follow a call chain forward |
|
|
133
|
+
| `codecompass query --tree` | Orient yourself — full project structure |
|
|
134
|
+
| `codecompass query --styles <element>` | Find CSS selectors for an HTML element |
|
|
135
|
+
| `codecompass query --batch-impact <f1> <f2> ...` | Multi-file PR — union blast radius |
|
|
136
|
+
| `codecompass query --flow <entry_symbol>` | Trace the call/import flow from an entry point |
|
|
137
|
+
| `codecompass query --dead-code` | Find functions/classes with no caller or importer |
|
|
138
|
+
|
|
139
|
+
Add `--rich` for formatted table output. Add `--hops N` to control traversal depth (default: 3).
|
|
140
|
+
|
|
141
|
+
### Dead code
|
|
142
|
+
|
|
143
|
+
`--dead-code` reports entities with no inbound `CALLS`/`IMPORTS`/`REFERENCES` edge — candidates for removal such as old helpers, superseded function versions, or orphaned scripts:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
codecompass query --dead-code # likely-dead only
|
|
147
|
+
codecompass query --dead-code --include-entrypoints # also show probable entry points
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Results are split into **likely dead** (private/internal, no caller) and **possible entry points** (`run_*`, handlers, tests — invoked by a runtime, not a static call). This is **static analysis**: dynamic dispatch, reflection, and string-based invocation are invisible, so every result is a candidate to verify (grep the name across the repo) before deleting.
|
|
151
|
+
|
|
152
|
+
### Flow charts
|
|
153
|
+
|
|
154
|
+
`--flow` traces forward from an entry point along `CALLS` and `IMPORTS` edges. Pick an output format with `--format`:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
codecompass query --flow "src.main" --hops 3 # draw.io (default)
|
|
158
|
+
codecompass query --flow "src.main" --format mermaid # Markdown + mermaid
|
|
159
|
+
codecompass query --flow "src.main" --format json # agent narration
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Every format numbers each call by source line so call order is explicit. By default, external/stdlib symbols are filtered out — add `--include-external` to show everything. Output is written to `.codecompass/flow_<entry>.{drawio,md,json}`.
|
|
163
|
+
|
|
164
|
+
- **`drawio`** — opens in [draw.io](https://app.diagrams.net) (desktop or web). Nodes color-coded by type, entry point has a thick border, edges color-coded by relationship (blue = CALLS, green = IMPORTS).
|
|
165
|
+
- **`mermaid`** — a Markdown file with an embedded mermaid flowchart that renders directly on GitHub. Convert to SVG with `npx @mermaid-js/mermaid-cli -i flow_<entry>.md -o flow_<entry>.svg`.
|
|
166
|
+
- **`json`** — each node carries its real signature, docstring, source snippet, and line range; each edge carries its call order and call site. Built for agents: feed it to an LLM to generate a comprehensive data-flow explanation of how a pipeline or feature actually works.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Commands
|
|
171
|
+
|
|
172
|
+
| Command | Purpose |
|
|
173
|
+
|---|---|
|
|
174
|
+
| `codecompass init [path]` | Create `.codecompass/` and register in `AGENTS.md` |
|
|
175
|
+
| `codecompass ingest-code [path]` | Parse source files and build/rebuild the graph |
|
|
176
|
+
| `codecompass query <flags> [path]` | Query the graph (blast-radius, impact, deps, flow, tree, etc.) |
|
|
177
|
+
| `codecompass watch [path]` | Live re-index on file changes |
|
|
178
|
+
| `codecompass load-triples <file> <path>` | Load pre-processed triples from JSON |
|
|
179
|
+
| `codecompass setup` | Copy instructions to `~/.config/opencode/codecompass/` |
|
|
180
|
+
|
|
181
|
+
All commands default to `.` (current directory) when path is omitted.
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Supported languages
|
|
186
|
+
|
|
187
|
+
| Language | Entity types extracted |
|
|
188
|
+
|---|---|
|
|
189
|
+
| Python | modules, functions, classes, imports, calls, inheritance |
|
|
190
|
+
| JavaScript | modules, functions, classes, imports, calls |
|
|
191
|
+
| TypeScript / TSX | modules, functions, classes, imports, calls |
|
|
192
|
+
| HTML | elements, references, includes |
|
|
193
|
+
| CSS | selectors, variables, definitions |
|
|
194
|
+
| SCSS | selectors, variables, mixins, imports |
|
|
195
|
+
| `.styles.ts` (Lit) | CSS-in-JS — `var(--token)` usages, `:host` declarations |
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## How it works
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
Source files
|
|
203
|
+
│
|
|
204
|
+
▼
|
|
205
|
+
hierarchy_builder — walks repo → Project / Folder / File skeleton
|
|
206
|
+
│
|
|
207
|
+
▼
|
|
208
|
+
code_parser — tree-sitter extraction (no API calls)
|
|
209
|
+
│ extracts entities + relationships as CodeTriples
|
|
210
|
+
▼
|
|
211
|
+
graph.json — NetworkX MultiDiGraph serialized as JSON node-link data
|
|
212
|
+
│ typed edges: CALLS, IMPORTS, INHERITS, STYLES, DEFINED_IN, …
|
|
213
|
+
│ node attrs: kind, description, language, entity_type, file
|
|
214
|
+
▼
|
|
215
|
+
code_query_cli — graph traversal: blast-radius, impact, deps, trace, tree
|
|
216
|
+
│
|
|
217
|
+
▼
|
|
218
|
+
AGENTS.md — mandatory rules injected into the project for any AI agent
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Everything runs locally, in-process. No network calls, no database, no API keys.
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Project structure
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
codecompass/
|
|
229
|
+
├── graph/
|
|
230
|
+
│ ├── cli.py pip entry point → main.py
|
|
231
|
+
│ ├── code_graph_client.py NetworkX graph client — nodes, edges, traversal
|
|
232
|
+
│ ├── code_query_cli.py query CLI — blast-radius / impact / deps / trace / tree / dead-code / flow
|
|
233
|
+
│ └── setup.py opencode setup wizard
|
|
234
|
+
├── ingestion/
|
|
235
|
+
│ ├── code_parser.py tree-sitter entity + relationship extraction
|
|
236
|
+
│ ├── hierarchy_builder.py Project → Folder → File skeleton
|
|
237
|
+
│ ├── file_watcher.py incremental re-index on file changes
|
|
238
|
+
│ └── code_normalizer.py optional entity name normalization (Haiku)
|
|
239
|
+
├── models/
|
|
240
|
+
│ └── code_types.py CodeTriple, FileNode, FolderNode
|
|
241
|
+
├── opencode/
|
|
242
|
+
│ └── instructions.md agent instructions for opencode integration
|
|
243
|
+
├── config.py env var config with fallback defaults
|
|
244
|
+
└── main.py CLI dispatch: init / ingest-code / query / watch
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Inside each indexed project:
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
your-project/
|
|
251
|
+
├── .codecompass/
|
|
252
|
+
│ ├── graph.json the code knowledge graph (auto-generated)
|
|
253
|
+
│ ├── overview.md what the repo is / how to run it (read first)
|
|
254
|
+
│ ├── memory.md architecture & data flow (human-editable)
|
|
255
|
+
│ └── learnings.md gotchas, decisions, dead code (human-editable)
|
|
256
|
+
└── AGENTS.md agent instructions (auto-updated by codecompass)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Tips
|
|
262
|
+
|
|
263
|
+
- **Commit or gitignore** `.codecompass/graph.json` — your choice. Committing it means teammates and CI get the graph for free.
|
|
264
|
+
- **Re-ingest after refactors** — moved functions, renamed classes, deleted files. The graph doesn't auto-update unless `watch` is running.
|
|
265
|
+
- **Use `watch` during active development** — `codecompass watch` keeps the graph current as you save files.
|
|
266
|
+
- **Install once, use everywhere** — `pip install -e .` from the codecompass directory. The `codecompass` command works in any project.
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Limitations
|
|
271
|
+
|
|
272
|
+
- **Structure only** — the graph knows what calls what, not what anything *means*
|
|
273
|
+
- **No cross-repo edges** — entities outside the indexed repo won't appear
|
|
274
|
+
- **Lit CSS** covers explicit `var(--foo)` and `:host` declarations; generated property names from `theme.props()` are not indexed
|
|
275
|
+
- **Large repos** (50k+ files) may produce sizable graph files — benchmark before committing
|