feat: Rust core engine via napi-rs (Phase 1) by carlos-alm · Pull Request #8 · optave/ops-codegraph-tool · GitHub
Skip to content

feat: Rust core engine via napi-rs (Phase 1)#8

Merged
carlos-alm merged 12 commits into
mainfrom
feat/rust-core
Feb 22, 2026
Merged

feat: Rust core engine via napi-rs (Phase 1)#8
carlos-alm merged 12 commits into
mainfrom
feat/rust-core

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

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-rs dual-engine)

  • All 11 language extractors (JS/TS/TSX, Python, Go, Rust, Java, C#, Ruby, PHP, HCL) ported to Rust with a 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

Phase 1.2 — Unified API

  • parseFileAuto, parseFilesAuto, getActiveEngine as the single entry point in parser.js
  • Builder and watcher use the unified API — no direct native imports

Phase 1.3 — Incremental parsing

  • Native ParseTreeCache exposed via napi-rs for watch mode old-tree hints

Phase 1.4 — Native import resolution

  • resolveImportPath and computeConfidence extracted to src/resolve.js with native dispatch
  • Batch pre-resolution of all imports in a single native call

Phase 1.5 — Graceful degradation & diagnostics

  • --engine flag plumbed to watch command
  • codegraph info diagnostic command
  • CI workflows for cross-platform test matrix and native build pipeline

Changes

  • 40 files changed, ~5,500 lines added
  • New Rust crate at crates/codegraph-core/
  • New JS modules: src/native.js, src/resolve.js
  • Refactored: src/builder.js, src/parser.js, src/cli.js, src/watcher.js, src/cycles.js
  • CI: build-native.yml (4-platform matrix), ci.yml
  • Tests: engine parity, unified API, import resolution parity, build parity, incremental cache

Test plan

  • npm test — full WASM test suite passes (no native required)
  • Cross-engine parity tests pass when native binary is available
  • Build parity test confirms identical graph output from both engines
  • codegraph info reports correct engine status
  • --engine wasm forces WASM even when native is available
  • Watch mode falls back gracefully when native unavailable

🤖 Generated with Claude Code

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.
@greptile-apps

greptile-apps Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

40 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

carlos-alm and others added 5 commits February 21, 2026 19:11
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 carlos-alm merged commit 9944f37 into main Feb 22, 2026
9 checks passed
@carlos-alm carlos-alm deleted the feat/rust-core branch February 22, 2026 02:58
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
@greptile-apps greptile-apps Bot mentioned this pull request Mar 3, 2026
3 tasks
carlos-alm added a commit that referenced this pull request Mar 21, 2026
Re-rank codegraph from #8 (4.0) to #5 (4.5) reflecting v3.2.0 features:
41 CLI commands, 32 MCP tools, dataflow across all 11 languages, CFG,
sequence diagrams, architecture boundaries, unified graph model.

Add new competitors: GitNexus (#1, 18k stars), DeusData/codebase-memory-mcp
(#6, 793 stars in 25 days). Update star counts and feature status across
all 85+ ranked projects. Mark 7 roadmap items as DONE. Flag stagnant
projects. Update joern.md (3,021 stars, 75 contributors, 4 community MCP
wrappers) and narsil-mcp.md (129 stars, SPA frontend, +36 security rules,
development paused since Feb 25).
carlos-alm added a commit that referenced this pull request Mar 23, 2026
…#559)

* docs: update competitive analysis for v3.2.0 and March 2026 landscape

Re-rank codegraph from #8 (4.0) to #5 (4.5) reflecting v3.2.0 features:
41 CLI commands, 32 MCP tools, dataflow across all 11 languages, CFG,
sequence diagrams, architecture boundaries, unified graph model.

Add new competitors: GitNexus (#1, 18k stars), DeusData/codebase-memory-mcp
(#6, 793 stars in 25 days). Update star counts and feature status across
all 85+ ranked projects. Mark 7 roadmap items as DONE. Flag stagnant
projects. Update joern.md (3,021 stars, 75 contributors, 4 community MCP
wrappers) and narsil-mcp.md (129 stars, SPA frontend, +36 security rules,
development paused since Feb 25).

* docs: fix narsil SPA version attribution in competitive analysis overview

Line 18 incorrectly stated "v1.6.1" as the version when the SPA feature
was introduced. The SPA frontend was added in v1.6.0; v1.6.1 is the
current release. Updated to "added v1.6.0, current v1.6.1" to match the
detailed narsil-mcp.md entry.

* docs: remove hardcoded star count from joern comparison table

The "32 stars, growing" value in the Community & maturity row hardcodes
a stale star count. Other comparison tables use "Growing" consistently
for codegraph's community status. Updated to match.

* fix: correct GitNexus score, Tier 2 rank numbering, and jelly star count

- GitNexus overall score corrected from 4.7 to 4.5 to match the
  arithmetic mean of its six sub-scores (5+5+4+4+4+5)/6 = 4.5
- Tier 2 renumbered starting at #38 (was duplicating #37 with Tier 1);
  also resolves the pre-existing duplicate #43 (Bikach/ChrisRoyse now
  #44/#45), with all subsequent entries incremented accordingly
- jelly section header updated from 417 to 423 stars to match the
  ranking table

* fix: correct aider rank and codegraph star count per review feedback

* fix: align scoring breakdown sub-scores with overall rankings for stagnant projects

glimpse: Community 4→2 (stagnant since Jan 2026), avg now 3.83≈3.8 matching ranking.
autodev-codebase: Community 3→1 (stagnant since Jan 2026), avg now 3.33, ranking updated 3.4→3.3.

* fix: align ranking scores with sub-score averages for colbymchenry and axon

* fix: correct ranking inversion at positions #23/#24 (#559)

autodev-codebase (3.3) was ranked #23 above Claude-code-memory (3.4)
at #24. Swapped to maintain descending score order.

* fix: correct score mismatches for code-graph-rag (4.5→4.2) and arbor (3.7→4.2) (#559)

* fix: sync breakdown table row order with ranking table for #23/#24 (#559)

* fix: correct ranking inversions and stale rank references (#559)

* fix: correct sub-score/overall-score mismatches for codexray, loregrep, MATE

* fix: correct score mismatches and aider header rank

* fix: update narsil-mcp Key Metrics to reflect development stagnation (#559)

* fix: add missing "vs arbor" comparison section (#559)

* fix: remove duplicate vs-glimpse section and correct role names in vs-arbor (#559)

The duplicate vs-glimpse block (stale rank #10) was left behind when
vs-arbor was inserted. Removed it — the correct version exists at #11.
Also fixed role vocabulary in vs-arbor: bridge → adapter, added entry.
Zeeeepa pushed a commit to Zeeeepa/codegraph that referenced this pull request Jun 22, 2026
…optave#559)

* docs: update competitive analysis for v3.2.0 and March 2026 landscape

Re-rank codegraph from optave#8 (4.0) to optave#5 (4.5) reflecting v3.2.0 features:
41 CLI commands, 32 MCP tools, dataflow across all 11 languages, CFG,
sequence diagrams, architecture boundaries, unified graph model.

Add new competitors: GitNexus (optave#1, 18k stars), DeusData/codebase-memory-mcp
(optave#6, 793 stars in 25 days). Update star counts and feature status across
all 85+ ranked projects. Mark 7 roadmap items as DONE. Flag stagnant
projects. Update joern.md (3,021 stars, 75 contributors, 4 community MCP
wrappers) and narsil-mcp.md (129 stars, SPA frontend, +36 security rules,
development paused since Feb 25).

* docs: fix narsil SPA version attribution in competitive analysis overview

Line 18 incorrectly stated "v1.6.1" as the version when the SPA feature
was introduced. The SPA frontend was added in v1.6.0; v1.6.1 is the
current release. Updated to "added v1.6.0, current v1.6.1" to match the
detailed narsil-mcp.md entry.

* docs: remove hardcoded star count from joern comparison table

The "32 stars, growing" value in the Community & maturity row hardcodes
a stale star count. Other comparison tables use "Growing" consistently
for codegraph's community status. Updated to match.

* fix: correct GitNexus score, Tier 2 rank numbering, and jelly star count

- GitNexus overall score corrected from 4.7 to 4.5 to match the
  arithmetic mean of its six sub-scores (5+5+4+4+4+5)/6 = 4.5
- Tier 2 renumbered starting at optave#38 (was duplicating optave#37 with Tier 1);
  also resolves the pre-existing duplicate optave#43 (Bikach/ChrisRoyse now
  optave#44/optave#45), with all subsequent entries incremented accordingly
- jelly section header updated from 417 to 423 stars to match the
  ranking table

* fix: correct aider rank and codegraph star count per review feedback

* fix: align scoring breakdown sub-scores with overall rankings for stagnant projects

glimpse: Community 4→2 (stagnant since Jan 2026), avg now 3.83≈3.8 matching ranking.
autodev-codebase: Community 3→1 (stagnant since Jan 2026), avg now 3.33, ranking updated 3.4→3.3.

* fix: align ranking scores with sub-score averages for colbymchenry and axon

* fix: correct ranking inversion at positions optave#23/optave#24 (optave#559)

autodev-codebase (3.3) was ranked optave#23 above Claude-code-memory (3.4)
at optave#24. Swapped to maintain descending score order.

* fix: correct score mismatches for code-graph-rag (4.5→4.2) and arbor (3.7→4.2) (optave#559)

* fix: sync breakdown table row order with ranking table for optave#23/optave#24 (optave#559)

* fix: correct ranking inversions and stale rank references (optave#559)

* fix: correct sub-score/overall-score mismatches for codexray, loregrep, MATE

* fix: correct score mismatches and aider header rank

* fix: update narsil-mcp Key Metrics to reflect development stagnation (optave#559)

* fix: add missing "vs arbor" comparison section (optave#559)

* fix: remove duplicate vs-glimpse section and correct role names in vs-arbor (optave#559)

The duplicate vs-glimpse block (stale rank optave#10) was left behind when
vs-arbor was inserted. Removed it — the correct version exists at optave#11.
Also fixed role vocabulary in vs-arbor: bridge → adapter, added entry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant