Skip to main content

Crate weavatrix_rust

Crate weavatrix_rust 

Source
Expand description

§weavatrix-rust

CI crates.io docs.rs MSRV license

Turn a repository into evidence your Rust code can trust.

weavatrix-rust maps a codebase into a deterministic, typed evidence graph with exact source provenance. It then answers impact, architecture, API, health, history, search, semantic, and temporal-memory questions without executing the repository it analyzes.

Use the crate to:

  • embed repository analysis in a Rust application;
  • produce a serializable Snapshot for CI, indexing, or review systems;
  • run 42 bounded read-only operations over repository and graph evidence in the default full build;
  • run the standalone weavatrix-rust CLI.

This crate is an engine, not an MCP server. Protocol transport, npm packaging, client profiles, and filesystem watching belong to the separate weavatrix product.

§What the crate gives you

SurfacePurpose
Analyzer / AnalyzerConfigBuild a repository snapshot from a path or explicit source inputs.
SnapshotSerialize nodes, edges, diagnostics, capabilities, and provenance.
Graph, Node, EdgeWork directly with typed evidence-carrying graph primitives.
Weavatrix / RepositoryStateKeep an analyzed repository live and execute bounded operations against one revision.
operationsCall the compiled read-only use cases from Rust or the CLI (42 in the default full build).

Release evidence:

PropertyResult
Read-only analysis operations42
Shared JavaScript call targets missing or wrong0 / 0
Shared imports, methods, and re-exports covered100%
Rust line coverage87.71%
Committed self-analysis192 files / 1,531 nodes / 7,287 edges
Cold build median73.21 ms
Hot graph_stats short load0.661 ms/call across 1,000 calls
Unsafe Rust in the engineforbidden
Network paths or application-source writes0
Required external executables0

§Use this engine through MCP

The canonical weavatrix product wraps this crate with MCP stdio, profile discovery, incremental refresh, and native filesystem watching:

npx -y weavatrix mcp .

Or compile the same adapter from crates.io:

cargo install weavatrix
weavatrix mcp .

Codex configuration:

[mcp_servers.weavatrix]
command = "npx"
args = ["-y", "weavatrix", "mcp", ".", "--profile=code"]

Claude Code:

claude mcp add weavatrix -- \
  npx -y weavatrix mcp . --profile=code

The MCP product delegates its catalog and every operation call to this engine. The weavatrix-rust crate itself remains protocol-independent and does not open stdio or start a watcher.

§Embed it as a Rust library

Choose the smallest feature set your application needs:

[dependencies]
weavatrix-rust = { version = "2.0.2", default-features = false }
use std::path::Path;
use weavatrix_rust::{Analyzer, AnalyzerConfig};

let snapshot = Analyzer::new(AnalyzerConfig::default())
    .analyze(Path::new("."))?;

println!(
    "{} nodes, {} edges, {} diagnostics",
    snapshot.nodes.len(),
    snapshot.edges.len(),
    snapshot.diagnostics.len()
);

Call the same bounded operation catalog used by the MCP product:

use weavatrix_rust::{Weavatrix, operations};

let mut engine = Weavatrix::open(".")?;
let result = operations::call(
    &mut engine,
    "graph_stats",
    blazingly_json::json!({}),
)?;

println!("{}", blazingly_json::to_string_pretty(&result)?);

The minimal build retains the analyzer, lossless parsing, scanner, graph, snapshot model, standalone analyze, list-tools, and tool commands:

cargo check --no-default-features
cargo run --no-default-features --bin weavatrix-rust -- analyze . --pretty

§Architecture

repository path or SourceInput[]
             |
             v
 language + contract adapters
             |
             v
      analysis pipeline
             |
             v
 evidence model + Snapshot
             |
             v
      repository engine
             |
             v
 read-only operations --> Rust facade
                     \--> standalone CLI

The engine composes focused first-party crates:

CrateResponsibility
weavatrix-scanDeterministic traversal and repository manifests.
weavatrix-parseLossless tokenization and structural extraction.
weavatrix-graphTyped nodes, relations, evidence, and traversal.
weavatrix-gitDirect Git-object history and cross-repository comparison.
weavatrix-searchBounded local text and structure search.
weavatrix-cloneType-1/2/3 clone-review evidence.
weavatrix-search-vectorDeterministic exact and approximate vector candidates.
weavatrix-semanticExact-rescored semantic and SEO link policy.
weavatrix-memoryRevision-aware temporal repository memory.

§Feature selection

FeatureAdds
core, always enabledAnalyzer, scanner, lossless parser, graph, snapshots, operation contracts, CLI.
lang-rustRicher Rust AST extraction through syn; the lossless fallback remains without it.
gitDirect Git history, diffs, and cross-repository operations.
searchBounded repository search.
cloneClone-family review.
vectorVector candidate search.
semanticSemantic and SEO link analysis.
memoryTemporal memory context.
fullgit, search, clone, vector, semantic, and memory.

The default feature set is the complete native engine: full + lang-rust. Embedders can disable default features and enable only the analysis components they use.

[dependencies]
weavatrix-rust = {
    version = "2.0.2",
    default-features = false,
    features = ["lang-rust", "git", "search"]
}

Disabled capabilities disappear from the operation catalog; they are not advertised as unavailable stubs.

§Evidence model

Each relationship can carry:

  • extractor identity;
  • evidence class;
  • confidence;
  • source file and exact span;
  • optional extractor detail.

The enclosing Snapshot binds the graph to a repository and revision and records the scan, graph, and language capabilities evaluated for that snapshot.

Static reachability is never relabeled as measured test coverage. Ambiguous dynamic behavior remains bounded evidence instead of being connected to an arbitrary same-named symbol. Missing artifacts remain explicit rather than becoming reassuring zeroes.

See the evidence model for the exact interpretation rules.

§Repository and language surfaces

The engine extracts evidence from:

  • Rust, JavaScript, TypeScript, Python, Go, Java, C#, C, C++, Bash, SQL, Solidity, Swift, HTML, CSS-family sources, Terraform, XML, Markdown, MDX, reStructuredText, and AsciiDoc;
  • HTTP routes, GraphQL operations, Protobuf/gRPC services and streaming modes;
  • Kafka, RabbitMQ/AMQP, JMS, NATS, SQS, SNS, and MongoDB usage;
  • JSON/JSONC, YAML, Kubernetes, package manifests, lockfiles, architecture contracts, and measured coverage artifacts.

The first-party lossless tokenizer preserves the complete input byte stream while structural facts retain exact spans. This supports diagnostics, round-trip validation, and future source-to-source consumers without making the graph depend on regex reconstruction.

§The 42 default analysis operations

The default full build exposes 42 operations. The public operations layer sits above the engine and is usable from Rust or the CLI. Feature-minimal builds expose only operations backed by compiled capabilities.

WorkflowOperations
Graph orientationgraph_stats, get_node, get_neighbors, query_graph, god_nodes, shortest_path, get_community, list_communities, module_map, build_graph
Change impact and proofget_dependents, change_impact, select_tests, verified_change, prepare_change, graph_diff
Exact source contextsearch_code, read_source, inspect_symbol, context_bundle, map_stacktrace
Health and qualityfind_duplicates, find_dead_code, run_audit, coverage_map, hot_path_review
APIs and transportslist_endpoints, trace_endpoint, trace_api_contract
Architectureget_architecture_contract, verify_architecture, explain_architecture_violation, propose_architecture_exception
Git and repositoriesgit_history, cross_repo_git, open_repo, list_known_repos, rebuild_graph
Native extensionsvector_search, semantic_link, seo_link_suggestions, memory_context

§Standalone CLI

Install the binary from crates.io:

cargo install weavatrix-rust

Analyze and query without an MCP client:

weavatrix-rust analyze . --pretty
weavatrix-rust list-tools
weavatrix-rust tool graph_stats .

The CLI calls the same engine and operation implementations as an embedded application.

§Product boundary

This repository owns analysis, evidence, repository state, and read-only operations. The prebuilt npm/MCP distribution for Codex, Claude Code, and other clients is weavatrix. Source editing belongs to weavatrix-refactor; licensed network workflows belong to weavatrix-online.

§Performance and parity evidence

The native engine was checked against an immutable 502-file JavaScript-engine revision after normalizing paths, symbols, and relation identities:

RelationRustJavaScriptJavaScript evidence covered
imports2,3201,126100%
methods634100%
re-exports8075100%
calls3,4032,323100% of targets

For calls, 2,024 edges matched exactly and 299 reached the same source-line target with an additional Rust owner. There were zero missing and zero wrong shared targets.

Repository and operation benchmarks measure this engine directly. The separate npm product additionally measures packaging, startup, protocol initialization, discovery, calls, shutdown, and process-tree memory. See the methodology and raw evidence.

§Safety boundary

  • #![forbid(unsafe_code)] in the engine;
  • no network implementation;
  • no application-source writes or commit creation;
  • no execution of analyzed repository code;
  • no spawning git, rg, Node.js, Python, or language servers;
  • canonical-path containment for repository reads;
  • deterministic pagination and bounded results;
  • explicit evidence limitations instead of fabricated certainty.

§Development gates

cargo fmt --all -- --check
cargo clippy --locked --all-targets --all-features -- -D warnings
cargo clippy --locked --all-targets --no-default-features -- -D warnings
cargo test --locked --all-targets --all-features
cargo test --locked --no-default-features
cargo test --locked --test architecture_self
RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps --all-features
cargo publish --locked --dry-run

§Documentation

§License

MIT. Third-party crates retain their own licenses.

Re-exports§

pub use operations as tools;
pub use language::Language;
pub use weavatrix_memory as memory;

Modules§

language
operations

Structs§

Analyzer
AnalyzerConfig
Capability
Diagnostic
Edge
Graph
GraphBuilder
Node
NodeId
Provenance
RepositoryState
Snapshot
SourceInput
SourcePosition
SourceSpan
Weavatrix

Enums§

CapabilityState
Confidence
EdgeKind
Semantic relationship between two graph nodes.
Error
EvidenceKind
Origin of the evidence supporting an edge.
NodeKind
Semantic role of a graph node.

Constants§

SNAPSHOT_SCHEMA_VERSION
VERSION
Version of the evidence engine compiled into this library.

Type Aliases§

Result