Skip to main content

rustbrain_core/
lib.rs

1//! # rustbrain-core
2//!
3//! Project-scoped **knowledge graph engine** for software repositories: Markdown notes,
4//! optional Rust AST symbols, ranked full-text search, and graph-aware AI agent context.
5//!
6//! ## Quick start
7//!
8//! ```no_run
9//! use rustbrain_core::{Brain, ContextOptions, QueryOptions, Result};
10//!
11//! fn main() -> Result<()> {
12//!     let mut brain = Brain::open_or_create(".")?;
13//!     brain.sync()?;
14//!     let hits = brain.query_ranked("raft", &QueryOptions::human())?;
15//!     let ctx = brain.context_for_prompt("explain raft", 1024)?;
16//!     println!("{}", ctx.to_markdown());
17//!     let _ = hits;
18//!     Ok(())
19//! }
20//! ```
21//!
22//! ## Published crates
23//!
24//! | Package | Role |
25//! |---------|------|
26//! | **`rustbrain-core`** | This library |
27//! | **`rustbrain`** | CLI (`bootstrap`, `doctor`, `note`, `sync`, …) |
28//!
29//! ## Feature flags
30//!
31//! | Feature | Default | Purpose |
32//! |---------|---------|---------|
33//! | `ast` | yes | Tree-sitter Rust symbol extraction |
34//! | `obsidian` | yes | WikiLinks, frontmatter, Canvas |
35//! | `mmap` | yes | CSR `graph.mmap` |
36//! | `watch` | no | Debounced filesystem watcher |
37//! | `jshift` | no | Sparse path / in-place JSON helpers (not a serde_json replacement; see `docs/JSON_STACK.md`) |
38//! | `full` | no | All optional features |
39
40#![warn(missing_docs)]
41
42#[cfg(feature = "ast")]
43pub mod ast;
44pub mod apply_links;
45pub mod autolink;
46pub mod bootstrap;
47pub mod brain;
48pub mod context;
49pub mod crate_docs;
50pub mod doctor;
51pub mod error;
52pub mod exporter;
53pub mod fts;
54pub mod graph;
55pub mod hubs;
56pub mod id;
57pub mod ignore;
58pub mod indexer;
59pub mod mmap;
60pub mod mutator;
61pub mod note;
62pub mod plan_status;
63#[cfg(feature = "obsidian")]
64pub mod obsidian;
65pub mod query;
66pub mod registry;
67pub mod storage;
68pub mod symbols;
69pub mod types;
70pub mod watch;
71
72pub use apply_links::{
73    apply_links, ApplyEdit, ApplyKind, ApplyOptions, ApplyReport, ApplyStyle, ApplyTier,
74};
75pub use autolink::{
76    is_auto_relation, is_explicit_relation, list_orphan_notes, normalize_target_arg, path_stem,
77    run_auto_link, AutoLinkReport, AutoLinkSuggestion, OrphanNote, REL_AUTO_FILENAME,
78    REL_AUTO_TAG, WEIGHT_AUTO_FILENAME, WEIGHT_AUTO_TAG,
79};
80pub use bootstrap::{
81    bootstrap_noninteractive, bootstrap_workspace, default_agents_md_template,
82    resolve_agents_md_template, BootstrapAction, BootstrapMode, BootstrapOptions, BootstrapReport,
83};
84pub use brain::{find_brain_dir, Brain};
85pub use context::ContextOptions;
86pub use crate_docs::{
87    collect_crate_deps, crates_io_url, docs_rs_url, write_crate_docs_notes, CrateDep,
88};
89pub use fts::{is_generic_topic, prepare_search_query, tokenize_query, PreparedQuery};
90pub use hubs::{
91    changelog_latest_heading, changelog_version_aliases, detect_project_hub, is_hub_node_id,
92    is_planning_intent, is_release_intent, ProjectHub, HUB_BACKLOG, HUB_CHANGELOG, HUB_README,
93    HUB_ROADMAP,
94};
95pub use graph::{
96    graph_stats, neighborhood, resolve_graph_target, GraphDirection, GraphHopEdge, GraphHub,
97    GraphNeighborhood, GraphNodeRef, GraphOptions, GraphStats,
98};
99pub use doctor::{run_doctor, run_doctor_with, DoctorFinding, DoctorOptions, DoctorReport, DoctorSeverity};
100pub use error::{BrainError, Result};
101pub use exporter::{BrainExporter, BrainImporter, PortableBrainBundle, BUNDLE_VERSION};
102pub use ignore::{recommended_ignore_extras, write_rustbrainignore, IgnoreSet};
103pub use indexer::WorkspaceIndexer;
104pub use mmap::{CsrCompiler, CsrMmapGraph, MMAP_VERSION};
105pub use note::{create_note, default_dir_for_type, slugify_title, NoteCreated, NoteNewOptions};
106pub use plan_status::{
107    densify_plan, enrich_plan_index_fields, PlanStatus, PlanStatusDigest, PlanTask,
108};
109pub use query::{PendingLink, QueryOptions, RankedHit};
110pub use registry::{GlobalRankedHit, GlobalRegistry};
111pub use storage::{Database, SCHEMA_VERSION};
112pub use symbols::{extract_symbol_refs, symbol_node_id, SymbolRef};
113pub use types::{
114    xml_escape, ContextBundle, ContextNode, ContextRole, Edge, Node, NodeType, SyncStats,
115};
116pub use watch::{is_indexable, is_under_skipped, WatchConfig};
117
118#[cfg(feature = "ast")]
119pub use ast::{compute_symbol_hash, AstError, CodeAstParser, SymbolAnchor};
120
121#[cfg(feature = "obsidian")]
122pub use obsidian::{
123    extract_wikilink_spans, extract_wikilinks, parse_frontmatter, CanvasEdge, CanvasNode,
124    Frontmatter, ObsidianCanvas, WikiLink, WikiLinkSpan,
125};
126
127#[cfg(feature = "jshift")]
128pub use mutator::{extract_json_field_slice, update_json_field_inplace};
129
130#[cfg(feature = "watch")]
131pub use watch::watch_workspace;