nucel_agent_core/executor.rs
1use std::path::Path;
2
3use async_trait::async_trait;
4
5use crate::error::Result;
6use crate::session::AgentSession;
7use crate::types::{ExecutorType, PermissionMode};
8
9/// Capability flags for a provider implementation.
10#[derive(Debug, Clone)]
11pub struct AgentCapabilities {
12 /// Can resume/fork from an existing session.
13 pub session_resume: bool,
14 /// Exposes token usage information.
15 pub token_usage: bool,
16 /// Supports MCP tool integration.
17 pub mcp_support: bool,
18 /// Can run autonomously (bash, file ops).
19 pub autonomous_mode: bool,
20 /// Supports structured output via JSON Schema.
21 pub structured_output: bool,
22}
23
24/// Runtime availability of the provider.
25#[derive(Debug, Clone)]
26pub struct AvailabilityStatus {
27 pub available: bool,
28 pub reason: Option<String>,
29}
30
31/// Configuration for spawning a new session.
32#[derive(Debug, Clone, Default)]
33pub struct SpawnConfig {
34 /// Model to use (e.g. "claude-opus-4-6", "gpt-5-codex").
35 pub model: Option<String>,
36 /// Maximum tokens for responses.
37 pub max_tokens: Option<u32>,
38 /// Budget limit in USD for this session.
39 pub budget_usd: Option<f64>,
40 /// Permission mode for file/command operations.
41 pub permission_mode: Option<PermissionMode>,
42 /// Extra environment variables for the subprocess.
43 pub env: Vec<(String, String)>,
44 /// System prompt override.
45 pub system_prompt: Option<String>,
46 /// Reasoning effort level (provider-specific).
47 pub reasoning: Option<String>,
48 /// Maximum autonomous turns before returning (0 or None = provider default).
49 pub max_turns: Option<u32>,
50}
51
52/// Configuration for the executor itself (not per-session).
53#[derive(Debug, Clone, Default)]
54pub struct ExecutorConfig {
55 /// API key for authentication.
56 pub api_key: Option<String>,
57 /// Base URL override (for OpenCode server, etc.).
58 pub base_url: Option<String>,
59 /// Working directory for CLI discovery.
60 pub working_dir: Option<String>,
61}
62
63/// Core trait — every provider implements this.
64///
65/// This is intentionally narrow: spawn, resume, capabilities, availability.
66/// Provider-specific features stay in the provider crate.
67#[async_trait]
68pub trait AgentExecutor: Send + Sync {
69 /// Which provider this executor implements.
70 fn executor_type(&self) -> ExecutorType;
71
72 /// Create a new session and send the first prompt.
73 async fn spawn(
74 &self,
75 working_dir: &Path,
76 prompt: &str,
77 config: &SpawnConfig,
78 ) -> Result<AgentSession>;
79
80 /// Resume an existing session with a follow-up prompt.
81 async fn resume(
82 &self,
83 working_dir: &Path,
84 session_id: &str,
85 prompt: &str,
86 config: &SpawnConfig,
87 ) -> Result<AgentSession>;
88
89 /// Static capability flags.
90 fn capabilities(&self) -> AgentCapabilities;
91
92 /// Check if the runtime dependency (CLI, server) is available.
93 fn availability(&self) -> AvailabilityStatus;
94}