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