Skip to main content

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 bootstrap;
26pub mod compaction;
27pub mod config;
28pub mod coordinator;
29pub mod credentials;
30pub mod eruka_bridge;
31pub mod handoff;
32pub mod init;
33pub mod healing;
34pub mod skill_distillation;
35pub mod skills;
36#[cfg(feature = "tasks")]
37pub mod tasks;
38pub mod tools;
39
40pub use agent::PawanAgent;
41pub use agent::{AgentEvent, FinishReason, TokenUsageInfo};
42pub use config::PawanConfig;
43
44/// Error types for Pawan
45///
46/// Represents all possible error conditions that can occur in Pawan operations.
47#[derive(Debug, thiserror::Error)]
48pub enum PawanError {
49    /// I/O error
50    ///
51    /// Represents errors related to file operations, network operations, or other I/O.
52    #[error("IO error: {0}")]
53    Io(#[from] std::io::Error),
54
55    /// Configuration error
56    ///
57    /// Represents errors in Pawan configuration, such as invalid settings or missing required values.
58    #[error("Configuration error: {0}")]
59    Config(String),
60
61    /// Tool execution error
62    ///
63    /// Represents errors that occur when executing tools (file operations, bash commands, etc.).
64    #[error("Tool execution error: {0}")]
65    Tool(String),
66
67    /// Agent error
68    ///
69    /// Represents errors in the agent's logic or execution flow.
70    #[error("Agent error: {0}")]
71    Agent(String),
72
73    /// LLM error
74    ///
75    /// Represents errors from the language model backend or API.
76    #[error("LLM error: {0}")]
77    Llm(String),
78
79    /// Git error
80    ///
81    /// Represents errors from Git operations.
82    #[error("Git error: {0}")]
83    Git(String),
84
85    /// Parse error
86    ///
87    /// Represents errors in parsing JSON, TOML, or other structured data.
88    #[error("Parse error: {0}")]
89    Parse(String),
90
91    /// Timeout error
92    ///
93    /// Represents errors when an operation exceeds its time limit.
94    #[error("Timeout: {0}")]
95    Timeout(String),
96
97    /// Not found error
98    ///
99    /// Represents errors when a requested resource (file, tool, etc.) is not found.
100    #[error("Not found: {0}")]
101    NotFound(String),
102}
103
104/// Result type alias for Pawan operations
105///
106/// A convenience type alias that represents the result of Pawan operations,
107/// where success contains the desired value and failure contains a PawanError.
108pub type Result<T> = std::result::Result<T, PawanError>;
109
110/// Version information
111pub const VERSION: &str = env!("CARGO_PKG_VERSION");
112
113/// Default model for coding tasks (Mistral Small 4 119B MoE via NVIDIA NIM)
114/// Default model — Qwen3.5 122B (S tier, 383ms, solid tool calling).
115/// Override via pawan.toml or PAWAN_MODEL env var.
116pub const DEFAULT_MODEL: &str = "qwen/qwen3.5-122b-a10b";
117
118/// Default NVIDIA API URL
119pub const DEFAULT_NVIDIA_API_URL: &str = "https://integrate.api.nvidia.com/v1";
120
121/// Maximum iterations for tool calling loops
122pub const MAX_TOOL_ITERATIONS: usize = 50;
123
124/// Default timeout for bash commands (in seconds)
125pub const DEFAULT_BASH_TIMEOUT: u64 = 120;