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