//! The agent layer (plan §10): the task/outcome types, the write sandbox, the
//! tool set, the raw-model tool-calling loop, and prompt builders.

pub mod prompts;
pub mod runner;
pub mod sandbox;
pub mod tools;

use std::path::PathBuf;

/// A unit of agentic work handed to a [`crate::providers::Provider`].
#[derive(Debug, Clone)]
pub struct AgentTask {
    /// System prompt: role + wiki conventions.
    pub system: String,
    /// The specific instruction (what to do).
    pub instruction: String,
    /// Short precomputed context (diff summary or index.md) appended to the prompt.
    pub context: String,
    /// The repository map. Native backends inline it; raw backends serve it via
    /// the `read_repo_map` tool (kept out of the prompt to save tokens).
    pub repo_map: String,
    pub repo_root: PathBuf,
    pub wiki_dir: PathBuf,
    pub model: Option<String>,
    /// Read-only tasks (e.g. `ask`) disable wiki-write tools.
    pub read_only: bool,
    /// Iteration cap for the raw-model loop.
    pub max_iters: usize,
}

impl AgentTask {
    /// The combined user-facing prompt (instruction + context).
    pub fn prompt(&self) -> String {
        if self.context.trim().is_empty() {
            self.instruction.clone()
        } else {
            format!("{}\n\n{}", self.instruction, self.context)
        }
    }
}

/// Result of running an agent task.
#[derive(Debug, Clone, Default)]
pub struct AgentOutcome {
    pub final_text: String,
    pub tool_calls: usize,
    pub cost_usd: Option<f64>,
}
