Skip to main content

Crate weavatrix_rust

Crate weavatrix_rust 

Source
Expand description

§weavatrix-rust

CI crates.io docs.rs MSRV license

Build repository-aware Rust systems on evidence, not filename guesses.

weavatrix-rust is the native, embeddable repository-intelligence engine behind Weavatrix. It builds a deterministic evidence graph from source, manifests, infrastructure, and API contracts, then layers bounded Git, coverage, clone, search, vector, semantic, and temporal-memory operations over that graph through typed Rust APIs.

Use the crate to:

  • embed repository analysis in a Rust application;
  • produce a serializable Snapshot for CI, indexing, or review systems;
  • run 39 bounded read-only operations over repository and graph evidence in the default full build;
  • run the standalone weavatrix CLI;
  • optionally expose the same operation catalog through an MCP stdio adapter.

This crate is not an MCP SDK. Its core abstractions are analyzers, snapshots, evidence graphs, and repository state. MCP is an optional transport behind the mcp Cargo feature; the library and standalone CLI work without it.

§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.
toolsUse the compiled operation contracts from Rust or the CLI (39 in the default full build).
mcp featureAdd the optional mcport stdio adapter for MCP clients.

Release evidence:

PropertyResult
Read-only analysis operations39
Shared JavaScript call targets missing or wrong0 / 0
Shared imports, methods, and re-exports covered100%
Rust line coverage release gate87.18%
Unsafe Rust in the engineforbidden
Network paths or application-source writes0
Required external executables0

§Add the library

Choose the smallest feature set your application needs:

[dependencies]
weavatrix-rust = { version = "1.0.3", 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()
);

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 -- analyze . --pretty

§Architecture

repository path or SourceInput[]
             |
             v
     lossless extraction
   code + config + contracts
             |
             v
 typed evidence graph + Snapshot
             |
             +--> Rust API
             +--> standalone CLI
             +--> optional MCP adapter

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.
mcpOptional stdio transport through mcport and filesystem refresh notifications.

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

[dependencies]
weavatrix-rust = {
    version = "1.0.3",
    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 39 default analysis operations

The default full build exposes 39 operations. The public operation layer sits above the graph and is usable from Rust, the CLI, or the optional MCP adapter. 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
Change impact and proofget_dependents, change_impact, verified_change, prepare_change, graph_diff
Exact source contextsearch_code, read_source, inspect_symbol, context_bundle
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 analyze . --pretty
weavatrix list-tools
weavatrix tool graph_stats .

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

§Optional MCP adapter

When an MCP client is the consumer, enable the mcp feature or use the default binary build:

weavatrix mcp . --profile=all

Profiles all, code, and seo expose bounded views of the same repository state. The adapter supplies stdio framing, discovery, schemas, pagination, and refresh; it does not define the engine architecture.

The prebuilt npm distribution for Codex, Claude Code, and other MCP clients is the separate weavatrix product.

§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.

The installed npm distribution also provides an end-to-end process-boundary benchmark. It measures packaging, startup, MCP initialization, catalog discovery, identical operations, shutdown, and process-tree memory rather than presenting a library microbenchmark as a product result. See benchmarks and the checked-in raw reports.

§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.

Source editing belongs to the separate weavatrix-refactor package. Network workflows belong to weavatrix-online.

§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
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 language::Language;
pub use weavatrix_memory as memory;

Modules§

language
mcp
tools

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

Type Aliases§

Result