Skip to main content

Crate rustbrain_core

Crate rustbrain_core 

Source
Expand description

§rustbrain-core

Project-scoped knowledge graph engine for software repositories: Markdown notes, optional Rust AST symbols, ranked full-text search, and graph-aware AI agent context.

§Quick start

use rustbrain_core::{Brain, ContextOptions, QueryOptions, Result};

fn main() -> Result<()> {
    let mut brain = Brain::open_or_create(".")?;
    brain.sync()?;
    let hits = brain.query_ranked("raft", &QueryOptions::human())?;
    let ctx = brain.context_for_prompt("explain raft", 1024)?;
    println!("{}", ctx.to_markdown());
    let _ = hits;
    Ok(())
}

§Published crates

PackageRole
rustbrain-coreThis library
rustbrainCLI (bootstrap, doctor, note, sync, …)

§Feature flags

FeatureDefaultPurpose
astyesTree-sitter Rust symbol extraction
obsidianyesWikiLinks, frontmatter, Canvas
mmapyesCSR graph.mmap
watchnoDebounced filesystem watcher
jshiftnoSparse path / in-place JSON helpers (not a serde_json replacement; see docs/JSON_STACK.md)
fullnoAll optional features

Re-exports§

pub use apply_links::ApplyEdit;
pub use apply_links::ApplyKind;
pub use apply_links::ApplyOptions;
pub use apply_links::ApplyReport;
pub use apply_links::ApplyStyle;
pub use apply_links::ApplyTier;
pub use autolink::is_auto_relation;
pub use autolink::is_explicit_relation;
pub use autolink::list_orphan_notes;
pub use autolink::normalize_target_arg;
pub use autolink::path_stem;
pub use autolink::AutoLinkReport;
pub use autolink::AutoLinkSuggestion;
pub use autolink::OrphanNote;
pub use autolink::REL_AUTO_FILENAME;
pub use autolink::REL_AUTO_TAG;
pub use autolink::WEIGHT_AUTO_FILENAME;
pub use autolink::WEIGHT_AUTO_TAG;
pub use bootstrap::bootstrap_noninteractive;
pub use bootstrap::bootstrap_workspace;
pub use bootstrap::default_agents_md_template;
pub use bootstrap::resolve_agents_md_template;
pub use bootstrap::BootstrapAction;
pub use bootstrap::BootstrapMode;
pub use bootstrap::BootstrapOptions;
pub use bootstrap::BootstrapReport;
pub use brain::find_brain_dir;
pub use brain::Brain;
pub use context::ContextOptions;
pub use crate_docs::collect_crate_deps;
pub use crate_docs::crates_io_url;
pub use crate_docs::docs_rs_url;
pub use crate_docs::write_crate_docs_notes;
pub use crate_docs::CrateDep;
pub use fts::is_generic_topic;
pub use fts::prepare_search_query;
pub use fts::tokenize_query;
pub use fts::PreparedQuery;
pub use hubs::changelog_latest_heading;
pub use hubs::changelog_version_aliases;
pub use hubs::detect_project_hub;
pub use hubs::is_hub_node_id;
pub use hubs::is_planning_intent;
pub use hubs::is_release_intent;
pub use hubs::ProjectHub;
pub use hubs::HUB_BACKLOG;
pub use hubs::HUB_CHANGELOG;
pub use hubs::HUB_README;
pub use hubs::HUB_ROADMAP;
pub use graph::graph_stats;
pub use graph::neighborhood;
pub use graph::resolve_graph_target;
pub use graph::GraphDirection;
pub use graph::GraphHopEdge;
pub use graph::GraphHub;
pub use graph::GraphNeighborhood;
pub use graph::GraphNodeRef;
pub use graph::GraphOptions;
pub use graph::GraphStats;
pub use doctor::run_doctor;
pub use doctor::run_doctor_with;
pub use doctor::DoctorFinding;
pub use doctor::DoctorOptions;
pub use doctor::DoctorReport;
pub use doctor::DoctorSeverity;
pub use error::BrainError;
pub use error::Result;
pub use exporter::BrainExporter;
pub use exporter::BrainImporter;
pub use exporter::PortableBrainBundle;
pub use exporter::BUNDLE_VERSION;
pub use ignore::recommended_ignore_extras;
pub use ignore::write_rustbrainignore;
pub use ignore::IgnoreSet;
pub use indexer::WorkspaceIndexer;
pub use mmap::CsrCompiler;
pub use mmap::CsrMmapGraph;
pub use mmap::MMAP_VERSION;
pub use note::create_note;
pub use note::default_dir_for_type;
pub use note::slugify_title;
pub use note::NoteCreated;
pub use note::NoteNewOptions;
pub use plan_status::densify_plan;
pub use plan_status::enrich_plan_index_fields;
pub use plan_status::PlanStatus;
pub use plan_status::PlanStatusDigest;
pub use plan_status::PlanTask;
pub use query::QueryOptions;
pub use query::RankedHit;
pub use registry::GlobalRankedHit;
pub use registry::GlobalRegistry;
pub use storage::Database;
pub use storage::SCHEMA_VERSION;
pub use symbols::extract_symbol_refs;
pub use symbols::symbol_node_id;
pub use symbols::SymbolRef;
pub use types::xml_escape;
pub use types::ContextBundle;
pub use types::ContextNode;
pub use types::ContextRole;
pub use types::Edge;
pub use types::Node;
pub use types::NodeType;
pub use types::SyncStats;
pub use watch::is_indexable;
pub use watch::is_under_skipped;
pub use watch::WatchConfig;
pub use ast::compute_symbol_hash;
pub use ast::AstError;
pub use ast::CodeAstParser;
pub use ast::SymbolAnchor;
pub use obsidian::parse_frontmatter;
pub use obsidian::CanvasEdge;
pub use obsidian::CanvasNode;
pub use obsidian::Frontmatter;
pub use obsidian::ObsidianCanvas;
pub use obsidian::WikiLinkSpan;
pub use mutator::extract_json_field_slice;
pub use mutator::update_json_field_inplace;
pub use watch::watch_workspace;

Modules§

apply_links
Safe Markdown link application: pending normalize (Phase 0) + AC discover (Phase 1).
ast
Tree-sitter Rust symbol extraction and BLAKE3 hashing.
autolink
Orphan detection and soft auto-links (algorithmic, low weight).
bootstrap
Deterministic workspace bootstrap for mature repositories.
brain
Primary library façade: Brain.
context
Graph-aware AI context assembly with token budgeting.
crate_docs
Harvest crates.io → docs.rs links from Cargo.toml (+ optional Cargo.lock).
doctor
Health checks for a project brain (rustbrain doctor).
error
Typed errors for the rustbrain library boundary.
exporter
Portable .brainbundle export and import (schema v1).
fts
FTS5 query helpers: escaping, stopword stripping, and safe MATCH construction.
graph
Neighborhood inspection of the knowledge graph.
hubs
Recognized project hub Markdown files at the workspace root.
id
Stable node ID scheme based on repository-relative path slugs.
ignore
Workspace ignore patterns for indexing (.rustbrainignore + optional .gitignore).
indexer
Workspace walker: Markdown notes, optional Canvas, optional Rust AST.
mmap
CSR graph mmap cache (format v1).
mutator
Optional jshift-backed in-place JSON field mutation helpers.
note
Create structured Markdown notes for the brain (note new).
obsidian
Obsidian-compatible WikiLink, frontmatter, and Canvas parsing.
plan_status
Algorithmic plan / task status densification for FTS and agent summaries.
query
Ranked hybrid query: FTS5 BM25 + tag / alias / title boosts.
registry
Global developer registry of rustbrain workspaces (XDG-aware).
storage
SQLite master store for rustbrain.
symbols
Symbol reference parsing and stable symbol node IDs.
types
Domain types for the rustbrain knowledge graph.
watch
Debounced filesystem watcher for live re-indexing.