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