@optave/codegraph 3.0.4 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +59 -52
  2. package/grammars/tree-sitter-go.wasm +0 -0
  3. package/package.json +9 -10
  4. package/src/ast-analysis/rules/csharp.js +201 -0
  5. package/src/ast-analysis/rules/go.js +182 -0
  6. package/src/ast-analysis/rules/index.js +82 -0
  7. package/src/ast-analysis/rules/java.js +175 -0
  8. package/src/ast-analysis/rules/javascript.js +246 -0
  9. package/src/ast-analysis/rules/php.js +219 -0
  10. package/src/ast-analysis/rules/python.js +196 -0
  11. package/src/ast-analysis/rules/ruby.js +204 -0
  12. package/src/ast-analysis/rules/rust.js +173 -0
  13. package/src/ast-analysis/shared.js +223 -0
  14. package/src/ast.js +15 -28
  15. package/src/audit.js +4 -5
  16. package/src/boundaries.js +1 -1
  17. package/src/branch-compare.js +84 -79
  18. package/src/builder.js +274 -159
  19. package/src/cfg.js +111 -341
  20. package/src/check.js +3 -3
  21. package/src/cli.js +122 -167
  22. package/src/cochange.js +1 -1
  23. package/src/communities.js +13 -16
  24. package/src/complexity.js +196 -1239
  25. package/src/cycles.js +1 -1
  26. package/src/dataflow.js +274 -697
  27. package/src/db/connection.js +88 -0
  28. package/src/db/migrations.js +312 -0
  29. package/src/db/query-builder.js +280 -0
  30. package/src/db/repository.js +134 -0
  31. package/src/db.js +19 -392
  32. package/src/embedder.js +145 -141
  33. package/src/export.js +1 -1
  34. package/src/flow.js +160 -228
  35. package/src/index.js +36 -2
  36. package/src/kinds.js +49 -0
  37. package/src/manifesto.js +3 -8
  38. package/src/mcp.js +97 -20
  39. package/src/owners.js +132 -132
  40. package/src/parser.js +58 -131
  41. package/src/queries-cli.js +866 -0
  42. package/src/queries.js +1356 -2261
  43. package/src/resolve.js +11 -2
  44. package/src/result-formatter.js +21 -0
  45. package/src/sequence.js +364 -0
  46. package/src/structure.js +200 -199
  47. package/src/test-filter.js +7 -0
  48. package/src/triage.js +120 -162
  49. package/src/viewer.js +1 -1
package/README.md CHANGED
@@ -21,7 +21,7 @@
21
21
  <a href="#-quick-start">Quick Start</a> &middot;
22
22
  <a href="#-commands">Commands</a> &middot;
23
23
  <a href="#-language-support">Languages</a> &middot;
24
- <a href="#-ai-agent-integration">AI Integration</a> &middot;
24
+ <a href="#-ai-agent-integration-core">AI Integration</a> &middot;
25
25
  <a href="#-how-it-works">How It Works</a> &middot;
26
26
  <a href="#-recommended-practices">Practices</a> &middot;
27
27
  <a href="#-roadmap">Roadmap</a>
@@ -31,28 +31,30 @@
31
31
 
32
32
  ## The Problem
33
33
 
34
- Large codebases are opaque. The structure lives in people's heads, not in tools.
34
+ AI agents are the primary interface to large codebases and they're flying blind.
35
35
 
36
- A developer inherits a project and spends days grepping to understand what calls what. An AI agent burns half its token budget on `grep`, `find`, `cat` — re-discovering the same structure every session. An architect draws boundary rules on a whiteboard that erode within weeks because nothing enforces them. A CI pipeline catches test failures but can't tell you _"this change silently affects 14 callers across 9 files."_
36
+ An agent burns a great portion of its token budget on `grep`, `find`, `cat` — re-discovering the same structure every session. It modifies `parseConfig()` without knowing 9 files import it. It hallucinates a function signature because it never saw the real one. Multiply that by every session, every developer, every repo.
37
37
 
38
- The information exists it's in the code itself. But without a structured map, everyone is navigating blind: developers guess, AI agents hallucinate, and architecture degrades one unreviewed change at a time.
38
+ Developers aren't much better off. They inherit projects and spend days grepping to understand what calls what. Architects draw boundary rules that erode within weeks because nothing enforces them. CI catches test failures but can't tell you _"this change silently affects 14 callers across 9 files."_
39
+
40
+ The information exists — it's in the code itself. But without a structured map, agents hallucinate, developers guess, and architecture degrades one unreviewed change at a time.
39
41
 
40
42
  ## What Codegraph Does
41
43
 
42
44
  Codegraph builds a function-level dependency graph of your entire codebase — every function, every caller, every dependency — and keeps it current with sub-second incremental rebuilds.
43
45
 
44
- It parses your code with [tree-sitter](https://tree-sitter.github.io/) (native Rust or WASM), stores the graph in SQLite, and gives you multiple ways to consume it:
46
+ It parses your code with [tree-sitter](https://tree-sitter.github.io/) (native Rust or WASM), stores the graph in SQLite, and exposes it where it matters most:
45
47
 
46
- - **CLI** — developers explore, query, and audit their code from the terminal
47
- - **MCP server** — AI agents query the graph directly through 30 tools
48
+ - **MCP server** — AI agents query the graph directly through 30 tools — one call instead of 30 `grep`/`find`/`cat` invocations
49
+ - **CLI** — developers and agents explore, query, and audit code from the terminal
48
50
  - **CI gates** — `check` and `manifesto` commands enforce quality thresholds with exit codes
49
51
  - **Programmatic API** — embed codegraph in your own tools via `npm install`
50
52
 
51
- Instead of 30 tool calls to maybe discover half your dependencies, you get _"this function has 14 callers across 9 files"_ instantly. Instead of hoping architecture rules are followed, you enforce them. Instead of finding breakage in production, `diff-impact --staged` catches it before you commit.
53
+ Instead of an agent burning 30 tool calls to maybe discover half your dependencies, it gets _"this function has 14 callers across 9 files"_ in one MCP call. Instead of hoping architecture rules are followed, you enforce them. Instead of finding breakage in production, `diff-impact --staged` catches it before you commit.
52
54
 
53
55
  **Free. Open source. Fully local.** Zero network calls, zero telemetry. Your code stays on your machine. When you want deeper intelligence, bring your own LLM provider — your code only goes where you choose to send it.
54
56
 
55
- **Three commands to get started:**
57
+ **Three commands to a queryable graph:**
56
58
 
57
59
  ```bash
58
60
  npm install -g @optave/codegraph
@@ -60,7 +62,7 @@ cd your-project
60
62
  codegraph build
61
63
  ```
62
64
 
63
- That's it. No config files, no Docker, no JVM, no API keys, no accounts. The graph is ready to query.
65
+ No config files, no Docker, no JVM, no API keys, no accounts. Point your agent at the MCP server and it has full structural awareness of your codebase.
64
66
 
65
67
  ### Why it matters
66
68
 
@@ -68,9 +70,10 @@ That's it. No config files, no Docker, no JVM, no API keys, no accounts. The gra
68
70
  |---|---|---|
69
71
  | **AI agents** | Spend 20+ tool calls per session re-discovering code structure | Get full dependency context in one MCP call |
70
72
  | **AI agents** | Modify `parseConfig()` without knowing 9 files import it | `fn-impact parseConfig` shows every caller before the edit |
71
- | **Developers** | Inherit a codebase and grep for hours to understand what calls what | `context handleAuth -T` gives source, deps, callers, and tests in one command |
72
- | **Developers** | Rename a function, break 14 call sites silently | `diff-impact --staged` catches breakage before you commit |
73
+ | **AI agents** | Hallucinate function signatures and miss callers | `context <name> -T` returns source, deps, callers, and tests no guessing |
73
74
  | **CI pipelines** | Catch test failures but miss structural degradation | `check --staged` fails the build when blast radius or complexity thresholds are exceeded |
75
+ | **Developers** | Inherit a codebase and grep for hours to understand what calls what | `context handleAuth -T` gives the same structured view agents use |
76
+ | **Developers** | Rename a function, break 14 call sites silently | `diff-impact --staged` catches breakage before you commit |
74
77
  | **Architects** | Draw boundary rules that erode within weeks | `manifesto` and `boundaries` enforce architecture rules on every commit |
75
78
 
76
79
  ### Feature comparison
@@ -79,6 +82,9 @@ That's it. No config files, no Docker, no JVM, no API keys, no accounts. The gra
79
82
 
80
83
  | Capability | codegraph | [joern](https://github.com/joernio/joern) | [narsil-mcp](https://github.com/postrv/narsil-mcp) | [code-graph-rag](https://github.com/vitali87/code-graph-rag) | [cpg](https://github.com/Fraunhofer-AISEC/cpg) | [GitNexus](https://github.com/abhigyanpatwari/GitNexus) | [CodeMCP](https://github.com/SimplyLiz/CodeMCP) | [axon](https://github.com/harshkedia177/axon) |
81
84
  |---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
85
+ | MCP / AI agent support | **Yes** | — | **Yes** | **Yes** | **Yes** | **Yes** | **Yes** | **Yes** |
86
+ | Batch querying | **Yes** | — | — | — | — | — | — | — |
87
+ | Composite audit command | **Yes** | — | — | — | — | — | — | — |
82
88
  | Function-level analysis | **Yes** | **Yes** | **Yes** | **Yes** | **Yes** | **Yes** | **Yes** | **Yes** |
83
89
  | Multi-language | **11** | **14** | **32** | **11** | **~10** | **12** | **12** | **3** |
84
90
  | Semantic search | **Yes** | — | **Yes** | **Yes** | — | **Yes** | — | **Yes** |
@@ -86,10 +92,7 @@ That's it. No config files, no Docker, no JVM, no API keys, no accounts. The gra
86
92
  | CODEOWNERS integration | **Yes** | — | — | — | — | — | — | — |
87
93
  | Architecture boundary rules | **Yes** | — | — | — | — | — | — | — |
88
94
  | CI validation predicates | **Yes** | — | — | — | — | — | — | — |
89
- | Composite audit command | **Yes** | — | — | — | — | — | — | — |
90
- | Batch querying | **Yes** | — | — | — | — | — | — | — |
91
95
  | Graph snapshots | **Yes** | — | — | — | — | — | — | — |
92
- | MCP / AI agent support | **Yes** | — | **Yes** | **Yes** | **Yes** | **Yes** | **Yes** | **Yes** |
93
96
  | Git diff impact | **Yes** | — | — | — | — | **Yes** | **Yes** | **Yes** |
94
97
  | Branch structural diff | **Yes** | — | — | — | — | — | — | **Yes** |
95
98
  | Git co-change analysis | **Yes** | — | — | — | — | — | — | **Yes** |
@@ -113,46 +116,37 @@ That's it. No config files, no Docker, no JVM, no API keys, no accounts. The gra
113
116
 
114
117
  | | Differentiator | In practice |
115
118
  |---|---|---|
116
- | **⚡** | **Always-fresh graph** | Three-tier change detection: journal (O(changed)) mtime+size (O(n) stats) hash (O(changed) reads). Sub-second rebuilds even on large codebases |
117
- | **🔓** | **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 |
119
+ | **🤖** | **AI-first architecture** | 30-tool [MCP server](https://modelcontextprotocol.io/) agents query the graph directly instead of scraping the filesystem. One call replaces 20+ grep/find/cat invocations |
120
+ | **🏷️** | **Role classification** | Every symbol auto-tagged as `entry`/`core`/`utility`/`adapter`/`dead`/`leaf` agents instantly know what they're looking at without reading the code |
118
121
  | **🔬** | **Function-level, not just files** | Traces `handleAuth()` → `validateToken()` → `decryptJWT()` and shows 14 callers across 9 files break if `decryptJWT` changes |
119
- | **🏷️** | **Role classification** | Every symbol auto-tagged as `entry`/`core`/`utility`/`adapter`/`dead`/`leaf` — agents instantly know what they're looking at |
120
- | **🤖** | **Built for AI agents** | 30-tool [MCP server](https://modelcontextprotocol.io/) — AI assistants query your graph directly. Single-repo by default |
121
- | **🌐** | **Multi-language, one CLI** | JS/TS + Python + Go + Rust + Java + C# + PHP + Ruby + HCL in a single graph |
122
+ | **⚡** | **Always-fresh graph** | Three-tier change detection: journal (O(changed)) → mtime+size (O(n) stats) → hash (O(changed) reads). Sub-second rebuilds — agents always work with current data |
122
123
  | **💥** | **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 |
124
+ | **🌐** | **Multi-language, one graph** | JS/TS + Python + Go + Rust + Java + C# + PHP + Ruby + HCL in a single graph — agents don't need per-language tools |
123
125
  | **🧠** | **Hybrid search** | BM25 keyword + semantic embeddings fused via RRF — `hybrid` (default), `semantic`, or `keyword` mode; multi-query via `"auth; token; JWT"` |
124
126
  | **🔬** | **Dataflow + CFG** | Track how data flows through functions (`flows_to`, `returns`, `mutates`) and visualize intraprocedural control flow graphs for all 11 languages |
127
+ | **🔓** | **Fully local, zero cost** | No API keys, no accounts, no network calls. Optionally bring your own LLM provider — your code only goes where you choose |
125
128
 
126
129
  ---
127
130
 
128
131
  ## 🚀 Quick Start
129
132
 
130
133
  ```bash
131
- # Install
132
134
  npm install -g @optave/codegraph
133
-
134
- # Build a graph for any project
135
135
  cd your-project
136
136
  codegraph build # → .codegraph/graph.db created
137
-
138
- # Start exploring
139
- codegraph map # see most-connected files
140
- codegraph query myFunc # find any function, see callers & callees
141
- codegraph deps src/index.ts # file-level import/export map
142
137
  ```
143
138
 
144
- Or install from source:
139
+ That's it. The graph is ready. Now connect your AI agent.
145
140
 
146
- ```bash
147
- git clone https://github.com/optave/codegraph.git
148
- cd codegraph && npm install && npm link
149
- ```
141
+ ### For AI agents (primary use case)
150
142
 
151
- > **Dev builds:** Pre-release tarballs are attached to [GitHub Releases](https://github.com/optave/codegraph/releases). Install with `npm install -g <path-to-tarball>`. Note that `npm install -g <tarball-url>` does not work because npm cannot resolve optional platform-specific dependencies from a URL — download the `.tgz` first, then install from the local file.
143
+ Connect directly via MCP your agent gets 30 tools to query the graph:
152
144
 
153
- ### For AI agents
145
+ ```bash
146
+ codegraph mcp # 30-tool MCP server — AI queries the graph directly
147
+ ```
154
148
 
155
- Add codegraph to your agent's instructions (e.g. `CLAUDE.md`):
149
+ Or add codegraph to your agent's instructions (e.g. `CLAUDE.md`):
156
150
 
157
151
  ```markdown
158
152
  Before modifying code, always:
@@ -164,13 +158,26 @@ After modifying code:
164
158
  4. `codegraph diff-impact --staged -T` — verify impact before committing
165
159
  ```
166
160
 
167
- Or connect directly via MCP:
161
+ Full agent setup: [AI Agent Guide](docs/guides/ai-agent-guide.md) &middot; [CLAUDE.md template](docs/guides/ai-agent-guide.md#claudemd-template)
162
+
163
+ ### For developers
164
+
165
+ The same graph is available via CLI:
168
166
 
169
167
  ```bash
170
- codegraph mcp # 30-tool MCP server — AI queries the graph directly
168
+ codegraph map # see most-connected files
169
+ codegraph query myFunc # find any function, see callers & callees
170
+ codegraph deps src/index.ts # file-level import/export map
171
171
  ```
172
172
 
173
- Full agent setup: [AI Agent Guide](docs/guides/ai-agent-guide.md) &middot; [CLAUDE.md template](docs/guides/ai-agent-guide.md#claudemd-template)
173
+ Or install from source:
174
+
175
+ ```bash
176
+ git clone https://github.com/optave/codegraph.git
177
+ cd codegraph && npm install && npm link
178
+ ```
179
+
180
+ > **Dev builds:** Pre-release tarballs are attached to [GitHub Releases](https://github.com/optave/codegraph/releases). Install with `npm install -g <path-to-tarball>`. Note that `npm install -g <tarball-url>` does not work because npm cannot resolve optional platform-specific dependencies from a URL — download the `.tgz` first, then install from the local file.
174
181
 
175
182
  ---
176
183
 
@@ -178,22 +185,23 @@ Full agent setup: [AI Agent Guide](docs/guides/ai-agent-guide.md) &middot; [CLAU
178
185
 
179
186
  | | Feature | Description |
180
187
  |---|---|---|
181
- | 🔍 | **Symbol search** | Find any function, class, or method by name — exact match priority, relevance scoring, `--file` and `--kind` filters |
182
- | 📁 | **File dependencies** | See what a file imports and what imports it |
188
+ | 🤖 | **MCP server** | 30-tool MCP server for AI assistants; single-repo by default, opt-in multi-repo |
189
+ | 🎯 | **Deep context** | `context` gives agents source, deps, callers, signature, and tests for a function in one call; `audit --quick` gives structural summaries |
190
+ | 🏷️ | **Node role classification** | Every symbol auto-tagged as `entry`/`core`/`utility`/`adapter`/`dead`/`leaf` based on connectivity — agents instantly know architectural role |
191
+ | 📦 | **Batch querying** | Accept a list of targets and return all results in one JSON payload — enables multi-agent parallel dispatch |
183
192
  | 💥 | **Impact analysis** | Trace every file affected by a change (transitive) |
184
193
  | 🧬 | **Function-level tracing** | Call chains, caller trees, function-level impact, and A→B pathfinding with qualified call resolution |
185
- | 🎯 | **Deep context** | `context` gives AI agents source, deps, callers, signature, and tests for a function in one call; `audit --quick` gives structural summaries of files or functions |
186
194
  | 📍 | **Fast lookup** | `where` shows exactly where a symbol is defined and used — minimal, fast |
195
+ | 🔍 | **Symbol search** | Find any function, class, or method by name — exact match priority, relevance scoring, `--file` and `--kind` filters |
196
+ | 📁 | **File dependencies** | See what a file imports and what imports it |
187
197
  | 📊 | **Diff impact** | Parse `git diff`, find overlapping functions, trace their callers |
188
198
  | 🔗 | **Co-change analysis** | Analyze git history for files that always change together — surfaces hidden coupling the static graph can't see; enriches `diff-impact` with historically coupled files |
189
199
  | 🗺️ | **Module map** | Bird's-eye view of your most-connected files |
190
200
  | 🏗️ | **Structure & hotspots** | Directory cohesion scores, fan-in/fan-out hotspot detection, module boundaries |
191
- | 🏷️ | **Node role classification** | Every symbol auto-tagged as `entry`/`core`/`utility`/`adapter`/`dead`/`leaf` based on connectivity patterns — agents instantly know architectural role |
192
201
  | 🔄 | **Cycle detection** | Find circular dependencies at file or function level |
193
202
  | 📤 | **Export** | DOT, Mermaid, JSON, GraphML, GraphSON, and Neo4j CSV graph export |
194
203
  | 🧠 | **Semantic search** | Embeddings-powered natural language search with multi-query RRF ranking |
195
204
  | 👀 | **Watch mode** | Incrementally update the graph as files change |
196
- | 🤖 | **MCP server** | 30-tool MCP server for AI assistants; single-repo by default, opt-in multi-repo |
197
205
  | ⚡ | **Always fresh** | Three-tier incremental detection — sub-second rebuilds even on large codebases |
198
206
  | 🔬 | **Data flow analysis** | Intraprocedural parameter tracking, return consumers, argument flows, and mutation detection — all 11 languages |
199
207
  | 🧮 | **Complexity metrics** | Cognitive, cyclomatic, nesting depth, Halstead, and Maintainability Index per function |
@@ -208,7 +216,6 @@ Full agent setup: [AI Agent Guide](docs/guides/ai-agent-guide.md) &middot; [CLAU
208
216
  | ✅ | **CI validation predicates** | `check` command with configurable gates: complexity, blast radius, cycles, boundary violations — exit code 0/1 for CI |
209
217
  | 📋 | **Composite audit** | Single `audit` command combining explain + impact + health metrics per function — one call instead of 3-4 |
210
218
  | 🚦 | **Triage queue** | `triage` merges connectivity, hotspots, roles, and complexity into a ranked audit priority queue |
211
- | 📦 | **Batch querying** | Accept a list of targets and return all results in one JSON payload — enables multi-agent parallel dispatch |
212
219
  | 🔬 | **Dataflow analysis** | Track how data moves through functions with `flows_to`, `returns`, and `mutates` edges — all 11 languages, included by default, skip with `--no-dataflow` |
213
220
  | 🧩 | **Control flow graph** | Intraprocedural CFG construction for all 11 languages — `cfg` command with text/DOT/Mermaid output, included by default, skip with `--no-cfg` |
214
221
  | 🔎 | **AST node querying** | Stored queryable AST nodes (calls, `new`, string, regex, throw, await) — `ast` command with SQL GLOB pattern matching |
@@ -248,7 +255,7 @@ codegraph exports src/queries.js # Per-symbol consumer analysis (who calls each
248
255
  codegraph children <name> # List parameters, properties, constants of a symbol
249
256
  ```
250
257
 
251
- ### Deep Context (AI-Optimized)
258
+ ### Deep Context (designed for AI agents)
252
259
 
253
260
  ```bash
254
261
  codegraph context <name> # Full context: source, deps, callers, signature, tests
@@ -555,14 +562,14 @@ Self-measured on every release via CI ([build benchmarks](generated/benchmarks/B
555
562
 
556
563
  | Metric | Latest |
557
564
  |---|---|
558
- | Build speed (native) | **12.3 ms/file** |
559
- | Build speed (WASM) | **16.3 ms/file** |
565
+ | Build speed (native) | **6.1 ms/file** |
566
+ | Build speed (WASM) | **16.5 ms/file** |
560
567
  | Query time | **3ms** |
561
568
  | No-op rebuild (native) | **5ms** |
562
- | 1-file rebuild (native) | **375ms** |
569
+ | 1-file rebuild (native) | **332ms** |
563
570
  | Query: fn-deps | **0.8ms** |
564
571
  | Query: path | **0.8ms** |
565
- | ~50,000 files (est.) | **~615.0s build** |
572
+ | ~50,000 files (est.) | **~305.0s build** |
566
573
 
567
574
  Metrics are normalized per file for cross-version comparability. Times above are for a full initial build — incremental rebuilds only re-parse changed files.
568
575
 
@@ -580,11 +587,11 @@ Only **3 runtime dependencies** — everything else is optional or a devDependen
580
587
 
581
588
  Optional: `@huggingface/transformers` (semantic search), `@modelcontextprotocol/sdk` (MCP server) — lazy-loaded only when needed.
582
589
 
583
- ## 🤖 AI Agent Integration
590
+ ## 🤖 AI Agent Integration (Core)
584
591
 
585
592
  ### MCP Server
586
593
 
587
- Codegraph includes a built-in [Model Context Protocol](https://modelcontextprotocol.io/) server with 30 tools (31 in multi-repo mode), so AI assistants can query your dependency graph directly:
594
+ Codegraph is built around a [Model Context Protocol](https://modelcontextprotocol.io/) server with 30 tools (31 in multi-repo mode) the primary way agents consume the graph:
588
595
 
589
596
  ```bash
590
597
  codegraph mcp # Single-repo mode (default) — only local project
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optave/codegraph",
3
- "version": "3.0.4",
3
+ "version": "3.1.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,7 +57,7 @@
57
57
  "dependencies": {
58
58
  "better-sqlite3": "^12.6.2",
59
59
  "commander": "^14.0.3",
60
- "graphology": "^0.25.4",
60
+ "graphology": "^0.26.0",
61
61
  "graphology-communities-louvain": "^2.0.2",
62
62
  "web-tree-sitter": "^0.26.5"
63
63
  },
@@ -71,13 +71,12 @@
71
71
  },
72
72
  "optionalDependencies": {
73
73
  "@modelcontextprotocol/sdk": "^1.0.0",
74
- "@optave/codegraph-darwin-arm64": "3.0.4",
75
- "@optave/codegraph-darwin-x64": "3.0.4",
76
- "@optave/codegraph-linux-arm64-gnu": "3.0.4",
77
- "@optave/codegraph-linux-arm64-musl": "3.0.4",
78
- "@optave/codegraph-linux-x64-gnu": "3.0.4",
79
- "@optave/codegraph-linux-x64-musl": "3.0.4",
80
- "@optave/codegraph-win32-x64-msvc": "3.0.4"
74
+ "@optave/codegraph-darwin-arm64": "3.1.1",
75
+ "@optave/codegraph-darwin-x64": "3.1.1",
76
+ "@optave/codegraph-linux-arm64-gnu": "3.1.1",
77
+ "@optave/codegraph-linux-x64-gnu": "3.1.1",
78
+ "@optave/codegraph-linux-x64-musl": "3.1.1",
79
+ "@optave/codegraph-win32-x64-msvc": "3.1.1"
81
80
  },
82
81
  "devDependencies": {
83
82
  "@biomejs/biome": "^2.4.4",
@@ -90,7 +89,7 @@
90
89
  "husky": "^9.1",
91
90
  "tree-sitter-c-sharp": "^0.23.1",
92
91
  "tree-sitter-cli": "^0.26.5",
93
- "tree-sitter-go": "^0.23.4",
92
+ "tree-sitter-go": "^0.25.0",
94
93
  "tree-sitter-java": "^0.23.5",
95
94
  "tree-sitter-javascript": "^0.25.0",
96
95
  "tree-sitter-php": "^0.24.2",
@@ -0,0 +1,201 @@
1
+ /**
2
+ * C# — AST analysis rules.
3
+ */
4
+
5
+ import { makeCfgRules, makeDataflowRules } from '../shared.js';
6
+
7
+ // ─── Complexity ───────────────────────────────────────────────────────────
8
+
9
+ export const complexity = {
10
+ branchNodes: new Set([
11
+ 'if_statement',
12
+ 'else_clause',
13
+ 'for_statement',
14
+ 'foreach_statement',
15
+ 'while_statement',
16
+ 'do_statement',
17
+ 'catch_clause',
18
+ 'conditional_expression',
19
+ 'switch_statement',
20
+ ]),
21
+ caseNodes: new Set(['switch_section']),
22
+ logicalOperators: new Set(['&&', '||', '??']),
23
+ logicalNodeType: 'binary_expression',
24
+ optionalChainType: 'conditional_access_expression',
25
+ nestingNodes: new Set([
26
+ 'if_statement',
27
+ 'for_statement',
28
+ 'foreach_statement',
29
+ 'while_statement',
30
+ 'do_statement',
31
+ 'catch_clause',
32
+ 'conditional_expression',
33
+ 'switch_statement',
34
+ ]),
35
+ functionNodes: new Set([
36
+ 'method_declaration',
37
+ 'constructor_declaration',
38
+ 'lambda_expression',
39
+ 'local_function_statement',
40
+ ]),
41
+ ifNodeType: 'if_statement',
42
+ elseNodeType: null,
43
+ elifNodeType: null,
44
+ elseViaAlternative: true,
45
+ switchLikeNodes: new Set(['switch_statement']),
46
+ };
47
+
48
+ // ─── Halstead ─────────────────────────────────────────────────────────────
49
+
50
+ export const halstead = {
51
+ operatorLeafTypes: new Set([
52
+ '+',
53
+ '-',
54
+ '*',
55
+ '/',
56
+ '%',
57
+ '=',
58
+ '+=',
59
+ '-=',
60
+ '*=',
61
+ '/=',
62
+ '%=',
63
+ '&=',
64
+ '|=',
65
+ '^=',
66
+ '<<=',
67
+ '>>=',
68
+ '==',
69
+ '!=',
70
+ '<',
71
+ '>',
72
+ '<=',
73
+ '>=',
74
+ '&&',
75
+ '||',
76
+ '!',
77
+ '??',
78
+ '??=',
79
+ '&',
80
+ '|',
81
+ '^',
82
+ '~',
83
+ '<<',
84
+ '>>',
85
+ '++',
86
+ '--',
87
+ 'is',
88
+ 'as',
89
+ 'new',
90
+ 'typeof',
91
+ 'sizeof',
92
+ 'nameof',
93
+ 'if',
94
+ 'else',
95
+ 'for',
96
+ 'foreach',
97
+ 'while',
98
+ 'do',
99
+ 'switch',
100
+ 'case',
101
+ 'return',
102
+ 'throw',
103
+ 'break',
104
+ 'continue',
105
+ 'try',
106
+ 'catch',
107
+ 'finally',
108
+ 'await',
109
+ 'yield',
110
+ '.',
111
+ '?.',
112
+ ',',
113
+ ';',
114
+ ':',
115
+ '=>',
116
+ '->',
117
+ ]),
118
+ operandLeafTypes: new Set([
119
+ 'identifier',
120
+ 'integer_literal',
121
+ 'real_literal',
122
+ 'string_literal',
123
+ 'character_literal',
124
+ 'verbatim_string_literal',
125
+ 'interpolated_string_text',
126
+ 'true',
127
+ 'false',
128
+ 'null',
129
+ 'this',
130
+ 'base',
131
+ ]),
132
+ compoundOperators: new Set([
133
+ 'invocation_expression',
134
+ 'element_access_expression',
135
+ 'object_creation_expression',
136
+ ]),
137
+ skipTypes: new Set(['type_argument_list', 'type_parameter_list']),
138
+ };
139
+
140
+ // ─── CFG ──────────────────────────────────────────────────────────────────
141
+
142
+ export const cfg = makeCfgRules({
143
+ ifNode: 'if_statement',
144
+ elseViaAlternative: true,
145
+ forNodes: new Set(['for_statement', 'foreach_statement']),
146
+ whileNode: 'while_statement',
147
+ doNode: 'do_statement',
148
+ switchNode: 'switch_statement',
149
+ caseNode: 'switch_section',
150
+ tryNode: 'try_statement',
151
+ catchNode: 'catch_clause',
152
+ finallyNode: 'finally_clause',
153
+ returnNode: 'return_statement',
154
+ throwNode: 'throw_statement',
155
+ breakNode: 'break_statement',
156
+ continueNode: 'continue_statement',
157
+ blockNode: 'block',
158
+ labeledNode: 'labeled_statement',
159
+ functionNodes: new Set([
160
+ 'method_declaration',
161
+ 'constructor_declaration',
162
+ 'lambda_expression',
163
+ 'local_function_statement',
164
+ ]),
165
+ });
166
+
167
+ // ─── Dataflow ─────────────────────────────────────────────────────────────
168
+
169
+ export const dataflow = makeDataflowRules({
170
+ functionNodes: new Set([
171
+ 'method_declaration',
172
+ 'constructor_declaration',
173
+ 'lambda_expression',
174
+ 'local_function_statement',
175
+ ]),
176
+ returnNode: 'return_statement',
177
+ varDeclaratorNode: 'variable_declarator',
178
+ varNameField: 'name',
179
+ assignmentNode: 'assignment_expression',
180
+ callNode: 'invocation_expression',
181
+ callFunctionField: 'function',
182
+ callArgsField: 'arguments',
183
+ memberNode: 'member_access_expression',
184
+ memberObjectField: 'expression',
185
+ memberPropertyField: 'name',
186
+ awaitNode: 'await_expression',
187
+ argumentWrapperType: 'argument',
188
+ mutatingMethods: new Set(['Add', 'Remove', 'Clear', 'Insert', 'Sort', 'Reverse', 'Push', 'Pop']),
189
+ extractParamName(node) {
190
+ if (node.type === 'parameter') {
191
+ const nameNode = node.childForFieldName('name');
192
+ return nameNode ? [nameNode.text] : null;
193
+ }
194
+ if (node.type === 'identifier') return [node.text];
195
+ return null;
196
+ },
197
+ });
198
+
199
+ // ─── AST Node Types ───────────────────────────────────────────────────────
200
+
201
+ export const astTypes = null;