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.
This commit is contained in:
Phoebus 2026-09-22 02:36:22 -07:00
parent fb4dcc5683
commit 33afdaac9a
3 changed files with 64 additions and 4 deletions

View file

@ -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\":\"<action>\",\"value\":<value>}],\"rationale\":[{\"action\":\"<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

View file

@ -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<Self> {
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)]

View file

@ -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};