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 doctor;
50pub mod error;
51pub mod exporter;
52pub mod fts;
53pub mod graph;
54pub mod hubs;
55pub mod id;
56pub mod ignore;
57pub mod indexer;
58pub mod mmap;
59pub mod mutator;
60pub mod note;
61#[cfg(feature = "obsidian")]
62pub mod obsidian;
63pub mod query;
64pub mod registry;
65pub mod storage;
66pub mod symbols;
67pub mod types;
68pub mod watch;
69
70pub use apply_links::{
71    apply_links, ApplyEdit, ApplyKind, ApplyOptions, ApplyReport, ApplyStyle, ApplyTier,
72};
73pub use autolink::{
74    is_auto_relation, is_explicit_relation, list_orphan_notes, normalize_target_arg, path_stem,
75    run_auto_link, AutoLinkReport, AutoLinkSuggestion, OrphanNote, REL_AUTO_FILENAME,
76    REL_AUTO_TAG, WEIGHT_AUTO_FILENAME, WEIGHT_AUTO_TAG,
77};
78pub use bootstrap::{
79    bootstrap_noninteractive, bootstrap_workspace, default_agents_md_template,
80    resolve_agents_md_template, BootstrapAction, BootstrapMode, BootstrapOptions, BootstrapReport,
81};
82pub use brain::{find_brain_dir, Brain};
83pub use context::ContextOptions;
84pub use fts::{is_generic_topic, prepare_search_query, tokenize_query, PreparedQuery};
85pub use hubs::{
86    changelog_latest_heading, changelog_version_aliases, detect_project_hub, is_hub_node_id,
87    is_planning_intent, is_release_intent, ProjectHub, HUB_BACKLOG, HUB_CHANGELOG, HUB_README,
88    HUB_ROADMAP,
89};
90pub use graph::{
91    graph_stats, neighborhood, resolve_graph_target, GraphDirection, GraphHopEdge, GraphHub,
92    GraphNeighborhood, GraphNodeRef, GraphOptions, GraphStats,
93};
94pub use doctor::{run_doctor, run_doctor_with, DoctorFinding, DoctorOptions, DoctorReport, DoctorSeverity};
95pub use error::{BrainError, Result};
96pub use exporter::{BrainExporter, BrainImporter, PortableBrainBundle, BUNDLE_VERSION};
97pub use ignore::{recommended_ignore_extras, write_rustbrainignore, IgnoreSet};
98pub use indexer::WorkspaceIndexer;
99pub use mmap::{CsrCompiler, CsrMmapGraph, MMAP_VERSION};
100pub use note::{create_note, default_dir_for_type, slugify_title, NoteCreated, NoteNewOptions};
101pub use query::{PendingLink, QueryOptions, RankedHit};
102pub use registry::{GlobalRankedHit, GlobalRegistry};
103pub use storage::{Database, SCHEMA_VERSION};
104pub use symbols::{extract_symbol_refs, symbol_node_id, SymbolRef};
105pub use types::{
106    xml_escape, ContextBundle, ContextNode, ContextRole, Edge, Node, NodeType, SyncStats,
107};
108pub use watch::{is_indexable, is_under_skipped, WatchConfig};
109
110#[cfg(feature = "ast")]
111pub use ast::{compute_symbol_hash, AstError, CodeAstParser, SymbolAnchor};
112
113#[cfg(feature = "obsidian")]
114pub use obsidian::{
115    extract_wikilink_spans, extract_wikilinks, parse_frontmatter, CanvasEdge, CanvasNode,
116    Frontmatter, ObsidianCanvas, WikiLink, WikiLinkSpan,
117};
118
119#[cfg(feature = "jshift")]
120pub use mutator::{extract_json_field_slice, update_json_field_inplace};
121
122#[cfg(feature = "watch")]
123pub use watch::watch_workspace;