From 33afdaac9ad458056719da08fd92e15c5eb04f32 Mon Sep 17 00:00:00 2001 From: Phoebus Date: Tue, 22 Sep 2026 02:36:22 -0700 Subject: [PATCH] feat(ai): add an OpenCode backend to canonical configuration Add ai.backend (direct|opencode) plus opencode_server/provider/model fields, distinct from the direct provider. Require the change-object shape (action+value) in the proposal prompt: the shipped models keyed changes by the action name otherwise. --- .../crates/phoebus-ai/src/provider.rs | 9 +++- .../crates/phoebus-core/src/config.rs | 53 +++++++++++++++++++ installer-rs/crates/phoebus-core/src/lib.rs | 6 +-- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/installer-rs/crates/phoebus-ai/src/provider.rs b/installer-rs/crates/phoebus-ai/src/provider.rs index 6aa6edc..ed9f3d5 100644 --- a/installer-rs/crates/phoebus-ai/src/provider.rs +++ b/installer-rs/crates/phoebus-ai/src/provider.rs @@ -231,7 +231,14 @@ set_binary_packages (bool), set_build_jobs (1-256), set_package_use (atom, flag, enabled). Reply with ONLY a JSON object of the form: -{\"version\":1,\"changes\":[{\"action\":\"...\",...}],\"rationale\":[{\"action\":\"...\",\"reason\":\"...\",\"evidence\":[\"...\"]}]} +{\"version\":1,\"changes\":[{\"action\":\"\",\"value\":}],\"rationale\":[{\"action\":\"\",\"reason\":\"...\",\"evidence\":[\"...\"]}]} + +Every change object has EXACTLY the two keys `action` and `value`. Put the chosen +option in `value`; never use the action name as a key. Correct examples: +{\"action\":\"set_kernel_profile\",\"value\":\"safe\"} +{\"action\":\"set_filesystem\",\"value\":\"btrfs\"} +{\"action\":\"set_flatpak\",\"value\":true} +{\"action\":\"set_build_jobs\",\"value\":4} Rules: prefer stability and a proven boot over speculative performance; never propose disabling signature verification, enabling ~amd64 globally, weakening diff --git a/installer-rs/crates/phoebus-core/src/config.rs b/installer-rs/crates/phoebus-core/src/config.rs index a6bfdd2..54b25bd 100644 --- a/installer-rs/crates/phoebus-core/src/config.rs +++ b/installer-rs/crates/phoebus-core/src/config.rs @@ -361,6 +361,35 @@ impl Default for DesktopConfig { } } +/// How the assistant reaches a model. `Direct` is an OpenAI-compatible +/// endpoint; `OpenCode` is an OpenCode **agent server** (a different protocol +/// and trust boundary), never an OpenAI-compatible model endpoint. +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)] +pub enum AiBackend { + #[default] + #[serde(rename = "direct")] + Direct, + #[serde(rename = "opencode")] + OpenCode, +} + +impl AiBackend { + pub fn as_str(self) -> &'static str { + match self { + AiBackend::Direct => "direct", + AiBackend::OpenCode => "opencode", + } + } + + pub fn parse(value: &str) -> Option { + match value.trim().to_ascii_lowercase().as_str() { + "" | "direct" | "provider" => Some(AiBackend::Direct), + "opencode" | "open-code" | "open_code" => Some(AiBackend::OpenCode), + _ => None, + } + } +} + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)] #[serde(default)] pub struct AiConfig { @@ -368,6 +397,30 @@ pub struct AiConfig { pub provider: String, pub model: String, pub endpoint: String, + /// Direct provider endpoint or the OpenCode agent server. + pub backend: AiBackend, + /// OpenCode server base URL, e.g. `http://127.0.0.1:4096`. + pub opencode_server: String, + /// OpenCode provider id (e.g. `deepseek`). + pub opencode_provider: String, + /// OpenCode model id (e.g. `deepseek-chat`). + pub opencode_model: String, +} + +impl AiConfig { + pub fn is_opencode(&self) -> bool { + self.backend == AiBackend::OpenCode + } + + /// The OpenCode endpoint, if this configuration uses one. + pub fn opencode_endpoint(&self) -> Option<&str> { + let server = self.opencode_server.trim(); + if server.is_empty() { + None + } else { + Some(server) + } + } } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] diff --git a/installer-rs/crates/phoebus-core/src/lib.rs b/installer-rs/crates/phoebus-core/src/lib.rs index 22e4aa7..35705ff 100644 --- a/installer-rs/crates/phoebus-core/src/lib.rs +++ b/installer-rs/crates/phoebus-core/src/lib.rs @@ -24,9 +24,9 @@ pub mod update; pub mod validate; pub use config::{ - Bootloader, DesktopConfig, DesktopProfile, Encryption, EncryptionConfig, Filesystem, - InstallConfig, KernelConfig, KernelProfile, PackagePolicy, PackagesConfig, Stage3Config, - StorageConfig, SystemConfig, UserConfig, + AiBackend, AiConfig, Bootloader, DesktopConfig, DesktopProfile, Encryption, EncryptionConfig, + Filesystem, InstallConfig, KernelConfig, KernelProfile, PackagePolicy, PackagesConfig, + Stage3Config, StorageConfig, SystemConfig, UserConfig, }; pub use disk::{Disk, DiskKind, ProtectionReason}; pub use error::{CoreError, Result};