Skip to main content

bamboo_agent/
lib.rs

1//! Bamboo - A fully self-contained AI agent backend framework
2//!
3//! Bamboo provides a complete backend system for AI agents, including:
4//! - Built-in HTTP/HTTPS server (Actix-web)
5//! - Agent execution loop with tool support
6//! - LLM provider integrations (OpenAI, Anthropic, Google Gemini, GitHub Copilot)
7//! - Session management and persistence
8//! - Workflow and slash command systems
9//! - Process management for external tools
10//! - Claude Code integration
11//!
12//! # Features
13//!
14//! - **Dual mode**: Binary (standalone server) or library (embedded)
15//! - **Unified directory**: All data in ~/.bamboo directory
16//! - **Production-ready**: Built-in CORS, rate limiting, security headers
17//!
18//! # Quick Start
19//!
20//! ## Binary Mode
21
22// Allow some clippy lints that are pre-existing
23#![allow(clippy::module_inception)]
24#![allow(clippy::doc_overindented_list_items)]
25#![allow(clippy::incompatible_msrv)]
26//!
27//! ```bash
28//! bamboo serve --port 8080 --data-dir ~/.bamboo
29//! ```
30//!
31//! ## Library Mode
32//!
33//! ```rust,ignore
34//! use bamboo_agent::{BambooServer, core::Config};
35//!
36//! #[tokio::main]
37//! async fn main() {
38//!     let config = Config::new();
39//!     let server = BambooServer::new(config);
40//!     // server.start().await.unwrap(); // Not yet implemented
41//! }
42//! ```
43
44use std::path::PathBuf;
45
46pub mod error;
47
48// Placeholder modules (will be populated during migration)
49pub mod agent;
50pub mod claude;
51pub mod commands;
52pub mod core;
53pub mod process;
54pub mod server;
55
56// Ergonomic module re-exports for the agent subsystem (keeps docs and external
57// imports stable without forcing callers through `bamboo_agent::agent::*`).
58pub use agent::{llm, skill, tools};
59
60// Re-export core Config as the primary configuration type
61pub use core::config::ServerConfig;
62pub use core::Config;
63pub use error::{BambooError, Result};
64pub use process::ProcessRegistry;
65
66/// Main Bamboo server instance
67pub struct BambooServer {
68    config: core::Config,
69}
70
71impl BambooServer {
72    /// Create a new Bamboo server with configuration
73    pub fn new(config: core::Config) -> Self {
74        Self { config }
75    }
76
77    /// Start the HTTP server (blocking)
78    pub async fn start(self) -> Result<()> {
79        // TODO: Implement server startup
80        todo!("Server startup not yet implemented")
81    }
82
83    /// Get the server address
84    pub fn server_addr(&self) -> String {
85        self.config.server_addr()
86    }
87}
88
89/// Builder pattern for creating BambooServer
90///
91/// Provides a fluent API for configuring and instantiating a BambooServer.
92///
93/// # Example
94///
95/// ```rust,ignore
96/// use bamboo_agent::{BambooBuilder, BambooServer};
97/// use std::path::PathBuf;
98///
99/// let server = BambooBuilder::new()
100///     .port(8080)
101///     .bind("127.0.0.1")
102///     .data_dir(PathBuf::from("~/.bamboo"))
103///     .build()
104///     .unwrap();
105/// ```
106pub struct BambooBuilder {
107    config: core::Config,
108}
109
110impl BambooBuilder {
111    /// Create a new BambooBuilder with default configuration
112    pub fn new() -> Self {
113        Self {
114            config: core::Config::new(),
115        }
116    }
117
118    /// Set the server port
119    ///
120    /// # Arguments
121    ///
122    /// * `port` - Port number to listen on
123    pub fn port(mut self, port: u16) -> Self {
124        self.config.server.port = port;
125        self
126    }
127
128    /// Set the bind address
129    ///
130    /// # Arguments
131    ///
132    /// * `addr` - IP address to bind to (e.g., "127.0.0.1", "0.0.0.0")
133    pub fn bind(mut self, addr: impl Into<String>) -> Self {
134        self.config.server.bind = addr.into();
135        self
136    }
137
138    /// Set the data directory for storing configuration and data
139    ///
140    /// # Arguments
141    ///
142    /// * `dir` - Path to the data directory
143    pub fn data_dir(mut self, dir: PathBuf) -> Self {
144        self.config.data_dir = dir;
145        self
146    }
147
148    /// Set the static files directory
149    ///
150    /// # Arguments
151    ///
152    /// * `dir` - Path to static files directory
153    pub fn static_dir(mut self, dir: PathBuf) -> Self {
154        self.config.server.static_dir = Some(dir);
155        self
156    }
157
158    /// Set the number of workers
159    ///
160    /// # Arguments
161    ///
162    /// * `workers` - Number of worker threads
163    pub fn workers(mut self, workers: usize) -> Self {
164        self.config.server.workers = workers;
165        self
166    }
167
168    /// Build the BambooServer instance
169    ///
170    /// # Returns
171    ///
172    /// A Result containing the configured BambooServer or an error
173    pub fn build(self) -> Result<BambooServer> {
174        Ok(BambooServer::new(self.config))
175    }
176}
177
178impl Default for BambooBuilder {
179    fn default() -> Self {
180        Self::new()
181    }
182}