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    #[allow(dead_code)]
70    data_dir: PathBuf,
71}
72
73impl BambooServer {
74    /// Create a new Bamboo server with configuration
75    pub fn new(config: core::Config) -> Self {
76        Self {
77            config,
78            data_dir: core::paths::bamboo_dir(),
79        }
80    }
81
82    /// Create a new Bamboo server with an explicit data directory.
83    pub fn new_with_data_dir(config: core::Config, data_dir: PathBuf) -> Self {
84        Self { config, data_dir }
85    }
86
87    /// Start the HTTP server (blocking)
88    pub async fn start(self) -> Result<()> {
89        // TODO: Implement server startup
90        todo!("Server startup not yet implemented")
91    }
92
93    /// Get the server address
94    pub fn server_addr(&self) -> String {
95        self.config.server_addr()
96    }
97}
98
99/// Builder pattern for creating BambooServer
100///
101/// Provides a fluent API for configuring and instantiating a BambooServer.
102///
103/// # Example
104///
105/// ```rust,ignore
106/// use bamboo_agent::{BambooBuilder, BambooServer};
107/// use std::path::PathBuf;
108///
109/// let server = BambooBuilder::new()
110///     .port(8080)
111///     .bind("127.0.0.1")
112///     .data_dir(PathBuf::from("~/.bamboo"))
113///     .build()
114///     .unwrap();
115/// ```
116pub struct BambooBuilder {
117    config: core::Config,
118    data_dir: PathBuf,
119}
120
121impl BambooBuilder {
122    /// Create a new BambooBuilder with default configuration
123    pub fn new() -> Self {
124        Self {
125            config: core::Config::new(),
126            data_dir: core::paths::bamboo_dir(),
127        }
128    }
129
130    /// Set the server port
131    ///
132    /// # Arguments
133    ///
134    /// * `port` - Port number to listen on
135    pub fn port(mut self, port: u16) -> Self {
136        self.config.server.port = port;
137        self
138    }
139
140    /// Set the bind address
141    ///
142    /// # Arguments
143    ///
144    /// * `addr` - IP address to bind to (e.g., "127.0.0.1", "0.0.0.0")
145    pub fn bind(mut self, addr: impl Into<String>) -> Self {
146        self.config.server.bind = addr.into();
147        self
148    }
149
150    /// Set the data directory for storing configuration and data
151    ///
152    /// # Arguments
153    ///
154    /// * `dir` - Path to the data directory
155    pub fn data_dir(mut self, dir: PathBuf) -> Self {
156        self.data_dir = dir;
157        self
158    }
159
160    /// Set the static files directory
161    ///
162    /// # Arguments
163    ///
164    /// * `dir` - Path to static files directory
165    pub fn static_dir(mut self, dir: PathBuf) -> Self {
166        self.config.server.static_dir = Some(dir);
167        self
168    }
169
170    /// Set the number of workers
171    ///
172    /// # Arguments
173    ///
174    /// * `workers` - Number of worker threads
175    pub fn workers(mut self, workers: usize) -> Self {
176        self.config.server.workers = workers;
177        self
178    }
179
180    /// Build the BambooServer instance
181    ///
182    /// # Returns
183    ///
184    /// A Result containing the configured BambooServer or an error
185    pub fn build(self) -> Result<BambooServer> {
186        Ok(BambooServer::new_with_data_dir(self.config, self.data_dir))
187    }
188}
189
190impl Default for BambooBuilder {
191    fn default() -> Self {
192        Self::new()
193    }
194}