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}
49
50/// Configuration for the executor itself (not per-session).
51#[derive(Debug, Clone, Default)]
52pub struct ExecutorConfig {
53 /// API key for authentication.
54 pub api_key: Option<String>,
55 /// Base URL override (for OpenCode server, etc.).
56 pub base_url: Option<String>,
57 /// Working directory for CLI discovery.
58 pub working_dir: Option<String>,
59}
60
61/// Core trait — every provider implements this.
62///
63/// This is intentionally narrow: spawn, resume, capabilities, availability.
64/// Provider-specific features stay in the provider crate.
65#[async_trait]
66pub trait AgentExecutor: Send + Sync {
67 /// Which provider this executor implements.
68 fn executor_type(&self) -> ExecutorType;
69
70 /// Create a new session and send the first prompt.
71 async fn spawn(
72 &self,
73 working_dir: &Path,
74 prompt: &str,
75 config: &SpawnConfig,
76 ) -> Result<AgentSession>;
77
78 /// Resume an existing session with a follow-up prompt.
79 async fn resume(
80 &self,
81 working_dir: &Path,
82 session_id: &str,
83 prompt: &str,
84 config: &SpawnConfig,
85 ) -> Result<AgentSession>;
86
87 /// Static capability flags.
88 fn capabilities(&self) -> AgentCapabilities;
89
90 /// Check if the runtime dependency (CLI, server) is available.
91 fn availability(&self) -> AvailabilityStatus;
92}