feat: Rust core engine via napi-rs (Phase 1)#8
Merged
carlos-alm merged 12 commits intomainfrom Feb 22, 2026
Merged
Conversation
Move CPU-intensive parsing, import resolution, and cycle detection to Rust via napi-rs while keeping JS for CLI, SQLite, MCP, and embeddings. The WASM path remains as a fallback for unsupported platforms. Rust crate (crates/codegraph-core): - All 9 language extractors (JS/TS/TSX, Python, Go, Rust, Java, C#, Ruby, PHP, HCL) ported with SymbolExtractor trait - Rayon-based parallel file parsing - 6-level import resolution with confidence scoring - Tarjan's SCC cycle detection - Incremental parse tree cache for watch mode - napi-rs API: parseFile, parseFiles, resolveImport, resolveImports, computeConfidence, detectCycles, engineName, engineVersion JS integration: - src/native.js: platform-aware addon loader with graceful fallback - src/builder.js: dual-engine path (native fast path + WASM fallback) - src/cycles.js: dispatches to native detectCycles when available - src/watcher.js: uses native parseFile in watch mode - src/cli.js: --engine <native|wasm|auto> global option - src/index.js: exports isNativeAvailable CI & packaging: - GitHub Actions workflow for 4-platform matrix build - Platform optionalDependencies in package.json Tests: - Rust unit tests for JS, Python, Go extractors and cycle detection - Cross-engine parity tests for all 11 languages (skip when native N/A) - Full build parity test comparing SQLite output - Extended JS cycle tests for findCyclesJS
…se 1.2) Consolidate dual-engine dispatch into parser.js so builder.js and watcher.js never import native.js directly. The new parseFileAuto, parseFilesAuto, and getActiveEngine exports handle engine detection, delegation, and snake_case→camelCase normalization in one place. - parser.js: add unified API (parseFileAuto, parseFilesAuto, getActiveEngine) - builder.js: replace ~150 lines of dual-engine code with single parseFilesAuto call - watcher.js: replace dual-path updateFile with parseFileAuto call - index.js: export new unified API functions - tests/parsers/unified.test.js: 12 new tests for the unified API
Expose the Rust ParseTreeCache to JS via napi-rs so watch mode can reuse cached parse trees (old-tree hint) instead of full re-parses. WASM falls back to parseFileAuto when native is unavailable.
… 1.4) Extract resolveImportPath, computeConfidence into src/resolve.js with native dispatch and JS fallback. Batch pre-resolve all imports in a single native call before edge building. Add parity tests for import resolution, confidence scoring, and cycle detection.
…ation Proposal for (when, do, what) triplets as a complement to session-graph's (subject, predicate, object) knowledge graph, enabling scoped behavioral rules attached to codegraph's function-level dependency nodes.
- Plumb --engine flag to watch command (was hardcoded to 'auto') - Add `codegraph info` diagnostic command for engine/platform reporting - Stage CI workflows: cross-platform test matrix and native build pipeline
The 0.4 version constraint had no matching crate on crates.io — the published version is 1.1.0.
Contributor
Greptile SummaryThis PR introduces a Rust-based native parsing engine as an optional high-performance alternative to the existing WASM pipeline, maintaining backward compatibility through a dual-engine architecture. Key architecture decisions:
Implementation quality:
Deployment strategy:
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User: npm install] --> B{Native binary<br/>available?}
B -->|Yes| C[Load platform package<br/>via native.js]
B -->|No| D[Use WASM fallback]
C --> E[parseFilesAuto]
D --> E
E --> F{engine option}
F -->|'native'| G[Native Rust Parser<br/>Rayon parallel]
F -->|'wasm'| H[WASM tree-sitter]
F -->|'auto'| I{Native available?}
I -->|Yes| G
I -->|No| H
G --> J[Rust extractors<br/>11 languages]
H --> K[JS extractors<br/>11 languages]
J --> L[normalizeNativeSymbols]
K --> L
L --> M[builder.js]
M --> N[Import resolution<br/>resolve.js + native]
N --> O[Cycle detection<br/>cycles.js + native]
O --> P[SQLite graph.db]
Q[Watch mode] --> R[ParseTreeCache<br/>incremental.rs]
R --> G
Last reviewed commit: 151fceb |
tree-sitter-php 0.23 exports LANGUAGE_PHP directly without a feature gate. The "php" feature doesn't exist in this crate.
- Pin @napi-rs/cli to v3 to match napi crate dependencies - Remove invalid --platform flag (v2 only) from napi build command - Bump napi-build from v2 to v3 to align with napi/napi-derive v3 - Replace find with shell glob for Windows runner compatibility
The review action completed successfully but couldn't post comments because it only had read access to pull requests.
…sion The claude-code-review action requires the workflow file to be identical on the PR branch and default branch. Also napi-build v3 does not exist on crates.io — latest is 2.x.
carlos-alm
added a commit
that referenced
this pull request
Feb 22, 2026
feat: Rust core engine via napi-rs (Phase 1)
Add a native Rust parsing engine as an optional high-performance
alternative to the existing WASM pipeline. The WASM path remains the
always-available baseline; the native engine activates automatically
when platform binaries are installed.
Rust crate (crates/codegraph-core):
- All 11 language extractors ported with SymbolExtractor trait
- Rayon-based parallel file parsing
- 6-level import resolution with confidence scoring
- Tarjan's SCC cycle detection
- Incremental parse tree cache for watch mode
- napi-rs bindings: parseFile, parseFiles, resolveImport,
resolveImports, computeConfidence, detectCycles
JS integration:
- Unified API via parseFileAuto/parseFilesAuto/getActiveEngine
- Builder and watcher use unified API — no direct native imports
- Import resolution extracted to src/resolve.js with native dispatch
- --engine <native|wasm|auto> CLI flag and `codegraph info` command
- Graceful fallback when native binary is unavailable
CI & packaging:
- 4-platform matrix build workflow (build-native.yml)
- Cross-platform test matrix (ci.yml)
40 files changed, ~5200 additions
6 tasks
5 tasks
This was referenced Feb 25, 2026
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a native Rust parsing engine via napi-rs as an optional high-performance alternative to the existing WASM pipeline. The WASM path remains the always-available baseline; the native engine activates automatically when platform binaries are installed.
Phase 1 — Rust core (
napi-rsdual-engine)SymbolExtractortraitPhase 1.2 — Unified API
parseFileAuto,parseFilesAuto,getActiveEngineas the single entry point inparser.jsPhase 1.3 — Incremental parsing
ParseTreeCacheexposed via napi-rs for watch mode old-tree hintsPhase 1.4 — Native import resolution
resolveImportPathandcomputeConfidenceextracted tosrc/resolve.jswith native dispatchPhase 1.5 — Graceful degradation & diagnostics
--engineflag plumbed to watch commandcodegraph infodiagnostic commandChanges
crates/codegraph-core/src/native.js,src/resolve.jssrc/builder.js,src/parser.js,src/cli.js,src/watcher.js,src/cycles.jsbuild-native.yml(4-platform matrix),ci.ymlTest plan
npm test— full WASM test suite passes (no native required)codegraph inforeports correct engine status--engine wasmforces WASM even when native is available🤖 Generated with Claude Code