rusty_beads/
lib.rs

1//! # Rusty Beads
2//!
3//! A Git-backed graph issue tracker for AI coding agents.
4//!
5//! Rusty Beads provides a powerful issue tracking system designed specifically for AI coding
6//! agents, with features like dependency graphs, semantic compaction, and a context store
7//! for caching file summaries, symbol indexes, and project metadata.
8//!
9//! ## Features
10//!
11//! - **Issue Management**: Create, update, and track issues with rich metadata
12//! - **Dependency Graphs**: Model complex relationships with cycle detection
13//! - **Context Store**: Git-aware caching for file summaries, symbols, and project context
14//! - **Semantic Compaction**: Reduce context size while preserving essential information
15//! - **SQLite Storage**: Fast, reliable local storage with WAL mode
16//! - **JSONL Export**: Git-friendly format for version control
17//! - **Background Daemon**: RPC server for concurrent access
18//!
19//! ## Quick Start
20//!
21//! ### As a Library
22//!
23//! Add to your `Cargo.toml`:
24//!
25//! ```toml
26//! [dependencies]
27//! rusty-beads = "0.1"
28//! ```
29//!
30//! ### Basic Usage
31//!
32//! ```rust,no_run
33//! use rusty_beads::{SqliteStorage, Storage, Issue, generate_id};
34//! use anyhow::Result;
35//!
36//! fn main() -> Result<()> {
37//!     // Open or create a database
38//!     let storage = SqliteStorage::open(".beads/beads.db")?;
39//!
40//!     // Create an issue
41//!     let id = generate_id("bd");
42//!     let issue = Issue::new(&id, "Implement new feature", "developer");
43//!     storage.create_issue(&issue)?;
44//!
45//!     // Get ready work (unblocked issues)
46//!     let ready = storage.get_ready_work()?;
47//!     for issue in ready {
48//!         println!("{}: {}", issue.id, issue.title);
49//!     }
50//!
51//!     Ok(())
52//! }
53//! ```
54//!
55//! ### Context Store
56//!
57//! The context store helps AI agents cache and retrieve contextual information
58//! with automatic git-aware invalidation:
59//!
60//! ```rust,no_run
61//! use rusty_beads::{ContextStore, ContextEntry, FileContext, Namespace};
62//! use serde_json::json;
63//! use anyhow::Result;
64//!
65//! fn main() -> Result<()> {
66//!     // Open context store
67//!     let store = ContextStore::open(".beads/context.db")?;
68//!
69//!     // Store file context
70//!     let file_ctx = FileContext {
71//!         path: "src/main.rs".to_string(),
72//!         summary: Some("Application entry point".to_string()),
73//!         language: Some("rust".to_string()),
74//!         ..Default::default()
75//!     };
76//!     store.set_file_context("src/main.rs", &file_ctx)?;
77//!
78//!     // Store arbitrary key-value data
79//!     let entry = ContextEntry::new(
80//!         "custom:my-key",
81//!         json!({"data": "value"})
82//!     ).with_ttl(3600); // Expires in 1 hour
83//!     store.set(entry)?;
84//!
85//!     // Retrieve context
86//!     if let Some(ctx) = store.get_file_context("src/main.rs")? {
87//!         println!("Summary: {:?}", ctx.summary);
88//!     }
89//!
90//!     Ok(())
91//! }
92//! ```
93//!
94//! ### Dependencies
95//!
96//! Model complex task relationships:
97//!
98//! ```rust,no_run
99//! use rusty_beads::{SqliteStorage, Storage, Dependency, DependencyType};
100//! use anyhow::Result;
101//!
102//! fn main() -> Result<()> {
103//!     let storage = SqliteStorage::open(".beads/beads.db")?;
104//!
105//!     // Create a blocking dependency (bd-0002 is blocked by bd-0001)
106//!     let dep = Dependency::blocks("bd-0002", "bd-0001");
107//!
108//!     // Check for cycles before adding
109//!     if !storage.would_create_cycle("bd-0002", "bd-0001", DependencyType::Blocks)? {
110//!         storage.add_dependency(&dep)?;
111//!     }
112//!
113//!     Ok(())
114//! }
115//! ```
116//!
117//! ## Modules
118//!
119//! - [`types`] - Core data types (Issue, Status, Dependency, etc.)
120//! - [`storage`] - Storage backends (SQLite, JSONL export/import)
121//! - [`context`] - Context store for AI agents
122//! - [`idgen`] - Hash-based ID generation
123//! - [`compact`] - Semantic compaction
124//! - [`daemon`] - Background RPC server
125//! - [`git`] - Git integration utilities
126//! - [`cli`] - Command-line interface
127//!
128//! ## CLI Tool
129//!
130//! Install the `bd` command-line tool:
131//!
132//! ```bash
133//! cargo install rusty-beads
134//! ```
135//!
136//! Basic commands:
137//!
138//! ```bash
139//! # Initialize a new repository
140//! bd init
141//!
142//! # Create an issue
143//! bd create -t "Fix bug in parser"
144//!
145//! # List ready (unblocked) issues
146//! bd ready
147//!
148//! # Add a dependency
149//! bd dep add bd-0002 bd-0001
150//!
151//! # Use context store
152//! bd context set "file:main.rs" '{"summary": "Entry point"}'
153//! bd context get "file:main.rs"
154//! ```
155//!
156//! ## Architecture
157//!
158//! ```text
159//! rusty-beads/
160//! ├── types/       # Core data types
161//! ├── storage/     # SQLite + JSONL backends
162//! ├── context/     # Context store with git-aware invalidation
163//! ├── idgen/       # Hash-based ID generation (bd-xxxx)
164//! ├── compact/     # Semantic compaction (3 levels)
165//! ├── daemon/      # Background RPC server
166//! ├── git/         # Git integration
167//! └── cli/         # Command-line interface
168//! ```
169
170pub mod types;
171pub mod storage;
172pub mod idgen;
173pub mod git;
174pub mod daemon;
175pub mod compact;
176pub mod cli;
177pub mod context;
178
179// Re-export CLI types for binary
180pub use cli::{Cli, run};
181
182// Re-export commonly used types
183pub use types::{
184    Issue, Status, IssueType, Dependency, DependencyType,
185    Comment, Event, EventType, Label, IssueFilter,
186    AgentState, MolType, BlockedIssue, Statistics,
187};
188
189pub use storage::{Storage, SqliteStorage};
190pub use idgen::generate_id;
191pub use context::{ContextStore, ContextEntry, Namespace, FileContext, ProjectContext, SessionContext};
192
193/// Library version.
194pub const VERSION: &str = env!("CARGO_PKG_VERSION");
195
196/// Default ID prefix for issues.
197pub const DEFAULT_PREFIX: &str = "bd";