pawan/lib.rs
1//! # Pawan (पवन) - Self-Healing CLI Coding Agent
2//!
3//! Core library for the Pawan coding agent. Provides:
4//!
5//! - **Agent**: Tool-calling loop engine with multi-provider LLM support
6//! - **Tools**: File operations, bash execution, git, search
7//! - **Healing**: Automatic detection and repair of compilation errors, test failures, warnings
8//! - **Config**: TOML-based configuration with provider/model management
9//!
10//! ## Architecture
11//!
12//! - `pawan-core` (this crate): Library with zero dirmacs dependencies
13//! - `pawan-cli`: Binary with TUI and CLI interface
14//!
15//! ## Quick Start
16//!
17//! ```bash
18//! pawan # Interactive TUI mode
19//! pawan heal # Auto-fix compilation issues
20//! pawan task "description" # Execute a coding task
21//! pawan run "prompt" # Headless single-prompt execution
22//! ```
23
24pub mod agent;
25pub mod config;
26pub mod eruka_bridge;
27pub mod healing;
28pub mod tasks;
29pub mod tools;
30
31pub use agent::PawanAgent;
32pub use config::PawanConfig;
33
34/// Error types for Pawan
35///
36/// Represents all possible error conditions that can occur in Pawan operations.
37#[derive(Debug, thiserror::Error)]
38pub enum PawanError {
39 /// I/O error
40 ///
41 /// Represents errors related to file operations, network operations, or other I/O.
42 #[error("IO error: {0}")]
43 Io(#[from] std::io::Error),
44
45 /// Configuration error
46 ///
47 /// Represents errors in Pawan configuration, such as invalid settings or missing required values.
48 #[error("Configuration error: {0}")]
49 Config(String),
50
51 /// Tool execution error
52 ///
53 /// Represents errors that occur when executing tools (file operations, bash commands, etc.).
54 #[error("Tool execution error: {0}")]
55 Tool(String),
56
57 /// Agent error
58 ///
59 /// Represents errors in the agent's logic or execution flow.
60 #[error("Agent error: {0}")]
61 Agent(String),
62
63 /// LLM error
64 ///
65 /// Represents errors from the language model backend or API.
66 #[error("LLM error: {0}")]
67 Llm(String),
68
69 /// Git error
70 ///
71 /// Represents errors from Git operations.
72 #[error("Git error: {0}")]
73 Git(String),
74
75 /// Parse error
76 ///
77 /// Represents errors in parsing JSON, TOML, or other structured data.
78 #[error("Parse error: {0}")]
79 Parse(String),
80
81 /// Timeout error
82 ///
83 /// Represents errors when an operation exceeds its time limit.
84 #[error("Timeout: {0}")]
85 Timeout(String),
86
87 /// Not found error
88 ///
89 /// Represents errors when a requested resource (file, tool, etc.) is not found.
90 #[error("Not found: {0}")]
91 NotFound(String),
92}
93
94/// Result type alias for Pawan operations
95///
96/// A convenience type alias that represents the result of Pawan operations,
97/// where success contains the desired value and failure contains a PawanError.
98pub type Result<T> = std::result::Result<T, PawanError>;
99
100/// Version information
101pub const VERSION: &str = env!("CARGO_PKG_VERSION");
102
103/// Default model for coding tasks (Mistral Small 4 119B MoE via NVIDIA NIM)
104/// First model to achieve 100% autonomous score (interval tree 6/6).
105/// Best for code generation, self-correction, and semantic reasoning.
106pub const DEFAULT_MODEL: &str = "mistralai/mistral-small-4-119b-2603";
107
108/// Default NVIDIA API URL
109pub const DEFAULT_NVIDIA_API_URL: &str = "https://integrate.api.nvidia.com/v1";
110
111/// Maximum iterations for tool calling loops
112pub const MAX_TOOL_ITERATIONS: usize = 50;
113
114/// Default timeout for bash commands (in seconds)
115pub const DEFAULT_BASH_TIMEOUT: u64 = 120;