@optave/codegraph 2.4.0 → 2.5.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
@@ -55,7 +55,7 @@ cd your-project
55
55
  codegraph build
56
56
  ```
57
57
 
58
- That's it. No config files, no Docker, no JVM, no API keys, no accounts. The graph is ready to query. Add `codegraph mcp` to your AI agent's config and it has full access to your dependency graph through 19 MCP tools.
58
+ That's it. No config files, no Docker, no JVM, no API keys, no accounts. The graph is ready to query. Add `codegraph mcp` to your AI agent's config and it has full access to your dependency graph through 24 MCP tools (25 in multi-repo mode).
59
59
 
60
60
  ### Why it matters
61
61
 
@@ -97,7 +97,7 @@ That's it. No config files, no Docker, no JVM, no API keys, no accounts. The gra
97
97
  | **🔓** | **Zero-cost core, LLM-enhanced when you want** | Full graph analysis with no API keys, no accounts, no cost. Optionally bring your own LLM provider — your code only goes where you choose |
98
98
  | **🔬** | **Function-level, not just files** | Traces `handleAuth()` → `validateToken()` → `decryptJWT()` and shows 14 callers across 9 files break if `decryptJWT` changes |
99
99
  | **🏷️** | **Role classification** | Every symbol auto-tagged as `entry`/`core`/`utility`/`adapter`/`dead`/`leaf` — agents instantly know what they're looking at |
100
- | **🤖** | **Built for AI agents** | 19-tool [MCP server](https://modelcontextprotocol.io/) — AI assistants query your graph directly. Single-repo by default |
100
+ | **🤖** | **Built for AI agents** | 24-tool [MCP server](https://modelcontextprotocol.io/) — AI assistants query your graph directly. Single-repo by default |
101
101
  | **🌐** | **Multi-language, one CLI** | JS/TS + Python + Go + Rust + Java + C# + PHP + Ruby + HCL in a single graph |
102
102
  | **💥** | **Git diff impact** | `codegraph diff-impact` shows changed functions, their callers, and full blast radius — enriched with historically coupled files from git co-change analysis. Ships with a GitHub Actions workflow |
103
103
  | **🧠** | **Semantic search** | Local embeddings by default, LLM-powered when opted in — multi-query with RRF ranking via `"auth; token; JWT"` |
@@ -144,7 +144,7 @@ After modifying code:
144
144
  Or connect directly via MCP:
145
145
 
146
146
  ```bash
147
- codegraph mcp # 19-tool MCP server — AI queries the graph directly
147
+ codegraph mcp # 24-tool MCP server — AI queries the graph directly
148
148
  ```
149
149
 
150
150
  Full agent setup: [AI Agent Guide](docs/guides/ai-agent-guide.md) · [CLAUDE.md template](docs/guides/ai-agent-guide.md#claudemd-template)
@@ -158,7 +158,7 @@ Full agent setup: [AI Agent Guide](docs/guides/ai-agent-guide.md) · [CLAU
158
158
  | 🔍 | **Symbol search** | Find any function, class, or method by name — exact match priority, relevance scoring, `--file` and `--kind` filters |
159
159
  | 📁 | **File dependencies** | See what a file imports and what imports it |
160
160
  | 💥 | **Impact analysis** | Trace every file affected by a change (transitive) |
161
- | 🧬 | **Function-level tracing** | Call chains, caller trees, and function-level impact with qualified call resolution |
161
+ | 🧬 | **Function-level tracing** | Call chains, caller trees, function-level impact, and A→B pathfinding with qualified call resolution |
162
162
  | 🎯 | **Deep context** | `context` gives AI agents source, deps, callers, signature, and tests for a function in one call; `explain` gives structural summaries of files or functions |
163
163
  | 📍 | **Fast lookup** | `where` shows exactly where a symbol is defined and used — minimal, fast |
164
164
  | 📊 | **Diff impact** | Parse `git diff`, find overlapping functions, trace their callers |
@@ -170,8 +170,11 @@ Full agent setup: [AI Agent Guide](docs/guides/ai-agent-guide.md) · [CLAU
170
170
  | 📤 | **Export** | DOT (Graphviz), Mermaid, and JSON graph export |
171
171
  | 🧠 | **Semantic search** | Embeddings-powered natural language search with multi-query RRF ranking |
172
172
  | 👀 | **Watch mode** | Incrementally update the graph as files change |
173
- | 🤖 | **MCP server** | 19-tool MCP server for AI assistants; single-repo by default, opt-in multi-repo |
173
+ | 🤖 | **MCP server** | 24-tool MCP server for AI assistants; single-repo by default, opt-in multi-repo |
174
174
  | ⚡ | **Always fresh** | Three-tier incremental detection — sub-second rebuilds even on large codebases |
175
+ | 🧮 | **Complexity metrics** | Cognitive, cyclomatic, nesting depth, Halstead, and Maintainability Index per function |
176
+ | 🏘️ | **Community detection** | Louvain clustering to discover natural module boundaries and architectural drift |
177
+ | 📜 | **Manifesto rule engine** | Configurable pass/fail rules with warn/fail thresholds for CI gates (exit code 1 on fail) |
175
178
 
176
179
  See [docs/examples](docs/examples) for real-world CLI and MCP usage examples.
177
180
 
@@ -217,6 +220,9 @@ codegraph impact <file> # Transitive reverse dependency trace
217
220
  codegraph fn <name> # Function-level: callers, callees, call chain
218
221
  codegraph fn <name> --no-tests --depth 5
219
222
  codegraph fn-impact <name> # What functions break if this one changes
223
+ codegraph path <from> <to> # Shortest path between two symbols (A calls...calls B)
224
+ codegraph path <from> <to> --reverse # Follow edges backward
225
+ codegraph path <from> <to> --max-depth 5 --kinds calls,imports
220
226
  codegraph diff-impact # Impact of unstaged git changes
221
227
  codegraph diff-impact --staged # Impact of staged changes
222
228
  codegraph diff-impact HEAD~3 # Impact vs a specific ref
@@ -247,6 +253,20 @@ codegraph hotspots # Files with extreme fan-in, fan-out, or density
247
253
  codegraph hotspots --metric coupling --level directory --no-tests
248
254
  ```
249
255
 
256
+ ### Code Health & Architecture
257
+
258
+ ```bash
259
+ codegraph complexity # Per-function cognitive, cyclomatic, nesting, MI
260
+ codegraph complexity --health -T # Full Halstead health view (volume, effort, bugs, MI)
261
+ codegraph complexity --sort mi -T # Sort by worst maintainability index
262
+ codegraph complexity --above-threshold -T # Only functions exceeding warn thresholds
263
+ codegraph communities # Louvain community detection — natural module boundaries
264
+ codegraph communities --drift -T # Drift analysis only — split/merge candidates
265
+ codegraph communities --functions # Function-level community detection
266
+ codegraph manifesto # Pass/fail rule engine (exit code 1 on fail)
267
+ codegraph manifesto -T # Exclude test files from rule evaluation
268
+ ```
269
+
250
270
  ### Export & Visualization
251
271
 
252
272
  ```bash
@@ -316,7 +336,7 @@ codegraph registry remove <name> # Unregister
316
336
  | Flag | Description |
317
337
  |---|---|
318
338
  | `-d, --db <path>` | Custom path to `graph.db` |
319
- | `-T, --no-tests` | Exclude `.test.`, `.spec.`, `__test__` files (available on `fn`, `fn-impact`, `context`, `explain`, `where`, `diff-impact`, `search`, `map`, `hotspots`, `deps`, `impact`) |
339
+ | `-T, --no-tests` | Exclude `.test.`, `.spec.`, `__test__` files (available on `fn`, `fn-impact`, `path`, `context`, `explain`, `where`, `diff-impact`, `search`, `map`, `hotspots`, `roles`, `co-change`, `deps`, `impact`, `complexity`, `communities`, `manifesto`) |
320
340
  | `--depth <n>` | Transitive trace depth (default varies by command) |
321
341
  | `-j, --json` | Output as JSON |
322
342
  | `-v, --verbose` | Enable debug output |
@@ -403,10 +423,14 @@ Self-measured on every release via CI ([build benchmarks](generated/BUILD-BENCHM
403
423
 
404
424
  | Metric | Latest |
405
425
  |---|---|
406
- | Build speed (native) | **1.9 ms/file** |
407
- | Build speed (WASM) | **6.6 ms/file** |
426
+ | Build speed (native) | **2 ms/file** |
427
+ | Build speed (WASM) | **8.4 ms/file** |
408
428
  | Query time | **2ms** |
409
- | ~50,000 files (est.) | **~95.0s build** |
429
+ | No-op rebuild (native) | **4ms** |
430
+ | 1-file rebuild (native) | **97ms** |
431
+ | Query: fn-deps | **2.1ms** |
432
+ | Query: path | **1.2ms** |
433
+ | ~50,000 files (est.) | **~100.0s build** |
410
434
 
411
435
  Metrics are normalized per file for cross-version comparability. Times above are for a full initial build — incremental rebuilds only re-parse changed files.
412
436
 
@@ -428,7 +452,7 @@ Optional: `@huggingface/transformers` (semantic search), `@modelcontextprotocol/
428
452
 
429
453
  ### MCP Server
430
454
 
431
- Codegraph includes a built-in [Model Context Protocol](https://modelcontextprotocol.io/) server with 19 tools, so AI assistants can query your dependency graph directly:
455
+ Codegraph includes a built-in [Model Context Protocol](https://modelcontextprotocol.io/) server with 24 tools (25 in multi-repo mode), so AI assistants can query your dependency graph directly:
432
456
 
433
457
  ```bash
434
458
  codegraph mcp # Single-repo mode (default) — only local project
@@ -462,7 +486,14 @@ This project uses codegraph. The database is at `.codegraph/graph.db`.
462
486
  - `codegraph build .` — rebuild the graph (incremental by default)
463
487
  - `codegraph map` — module overview
464
488
  - `codegraph fn <name> -T` — function call chain
489
+ - `codegraph path <from> <to> -T` — shortest call path between two symbols
465
490
  - `codegraph deps <file>` — file-level dependencies
491
+ - `codegraph roles --role dead -T` — find dead code (unreferenced symbols)
492
+ - `codegraph roles --role core -T` — find core symbols (high fan-in)
493
+ - `codegraph co-change <file>` — files that historically change together
494
+ - `codegraph complexity -T` — per-function complexity metrics (cognitive, cyclomatic, MI)
495
+ - `codegraph communities --drift -T` — module boundary drift analysis
496
+ - `codegraph manifesto -T` — pass/fail rule check (CI gate, exit code 1 on fail)
466
497
  - `codegraph search "<query>"` — semantic search (requires `codegraph embed`)
467
498
  - `codegraph cycles` — check for circular dependencies
468
499
 
@@ -534,10 +565,35 @@ Create a `.codegraphrc.json` in your project root to customize behavior:
534
565
  },
535
566
  "build": {
536
567
  "incremental": true
568
+ },
569
+ "query": {
570
+ "excludeTests": true
537
571
  }
538
572
  }
539
573
  ```
540
574
 
575
+ > **Tip:** `excludeTests` can also be set at the top level as a shorthand — `{ "excludeTests": true }` is equivalent to nesting it under `query`. If both are present, the nested `query.excludeTests` takes precedence.
576
+
577
+ ### Manifesto rules
578
+
579
+ Configure pass/fail thresholds for `codegraph manifesto`:
580
+
581
+ ```json
582
+ {
583
+ "manifesto": {
584
+ "rules": {
585
+ "cognitive_complexity": { "warn": 15, "fail": 30 },
586
+ "cyclomatic_complexity": { "warn": 10, "fail": 20 },
587
+ "nesting_depth": { "warn": 4, "fail": 6 },
588
+ "maintainability_index": { "warn": 40, "fail": 20 },
589
+ "halstead_bugs": { "warn": 0.5, "fail": 1.0 }
590
+ }
591
+ }
592
+ }
593
+ ```
594
+
595
+ When any function exceeds a `fail` threshold, `codegraph manifesto` exits with code 1 — perfect for CI gates.
596
+
541
597
  ### LLM credentials
542
598
 
543
599
  Codegraph supports an `apiKeyCommand` field for secure credential management. Instead of storing API keys in config files or environment variables, you can shell out to a secret manager at runtime:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optave/codegraph",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "description": "Local code graph CLI — parse codebases with tree-sitter, build dependency graphs, query them",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -57,14 +57,24 @@
57
57
  "dependencies": {
58
58
  "better-sqlite3": "^12.6.2",
59
59
  "commander": "^14.0.3",
60
+ "graphology": "^0.25.4",
61
+ "graphology-communities-louvain": "^2.0.2",
60
62
  "web-tree-sitter": "^0.26.5"
61
63
  },
64
+ "peerDependencies": {
65
+ "@huggingface/transformers": "^3.8.1"
66
+ },
67
+ "peerDependenciesMeta": {
68
+ "@huggingface/transformers": {
69
+ "optional": true
70
+ }
71
+ },
62
72
  "optionalDependencies": {
63
- "@huggingface/transformers": "^3.8.1",
64
73
  "@modelcontextprotocol/sdk": "^1.0.0",
65
- "@optave/codegraph-darwin-arm64": "2.4.0",
66
- "@optave/codegraph-darwin-x64": "2.4.0",
67
- "@optave/codegraph-linux-x64-gnu": "2.4.0"
74
+ "@optave/codegraph-darwin-arm64": "2.5.1",
75
+ "@optave/codegraph-darwin-x64": "2.5.1",
76
+ "@optave/codegraph-linux-x64-gnu": "2.5.1",
77
+ "@optave/codegraph-win32-x64-msvc": "2.5.1"
68
78
  },
69
79
  "devDependencies": {
70
80
  "@biomejs/biome": "^2.4.4",