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