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