Skip to main content

codive_core/
lib.rs

1//! Codive Core - Core types, traits, and utilities for the AI Coding Agent
2//!
3//! This crate contains the foundational types and abstractions used throughout
4//! the agent system. It's designed to be a dependency of all other agent crates.
5//!
6//! # Modules
7//!
8//! - [`agent`] - The core agent loop
9//! - [`config`] - Configuration types
10//! - [`error`] - Error types for the agent system
11//! - [`event`] - Event bus for pub/sub
12//! - [`message`] - Message and conversation types
13//! - [`provider`] - LLM provider trait and types
14//! - [`session`] - Session management
15//! - [`tool`] - Tool trait and registry
16
17pub mod agent;
18pub mod config;
19pub mod error;
20pub mod event;
21pub mod message;
22pub mod provider;
23pub mod session;
24pub mod tool;
25pub mod verification;
26
27// Re-export commonly used types at crate root for convenience
28pub use agent::{Agent, AgentRunError, CancellationToken, TurnResult};
29pub use config::{
30    AgentConfig, AppConfig, ConfigError, ModelConfig, PromptConfig, ServerConfig, TuiConfig,
31    VerificationConfig,
32};
33pub use error::AgentError;
34pub use event::{Event, EventBus};
35pub use message::{ContentPart, Message, Role, ToolCall, ToolResult};
36pub use provider::{CompletionRequest, CompletionStream, Provider, ProviderError, StreamEvent};
37pub use session::{Session, SessionStatus, SessionSummary};
38pub use tool::{FileChangeMetadata, Tool, ToolInfo, ToolOutput, ToolRegistry};
39pub use verification::VerificationResult;
40
41// Re-export prompt types from codive-prompts
42pub use codive_prompts::{
43    compose_standard, EnvironmentContext, PromptComposer, PromptStore, ProviderFamily,
44};
45
46// ============================================================================
47// RUST CONCEPTS EXPLAINED (for learning)
48// ============================================================================
49//
50// 1. `lib.rs` vs `main.rs`
51//    - `lib.rs` = library crate entry point (can be used by other crates)
52//    - `main.rs` = binary crate entry point (produces an executable)
53//    - A crate can have both (library + binary)
54//
55// 2. `pub mod error;`
56//    - `mod` declares a module (looks for error.rs or error/mod.rs)
57//    - `pub` makes it public (accessible from outside this crate)
58//    - Without `pub`, the module is private to this crate
59//
60// 3. `pub use error::AgentError;`
61//    - Re-exports AgentError at the crate root
62//    - Users can do `use codive_core::AgentError` instead of
63//      `use codive_core::error::AgentError`
64//    - This is called "facade pattern" or "prelude pattern"
65//
66// 4. `//!` doc comments
67//    - These are "inner" doc comments - they document the containing item
68//    - In lib.rs, they document the entire crate
69//    - Appear in generated documentation (cargo doc)
70//
71// 5. Crate naming
72//    - Directory: `codive-core` (with hyphen)
73//    - Rust identifier: `codive_core` (with underscore)
74//    - Cargo automatically converts hyphens to underscores