use std::path::Path;
use anyhow::Result;
use openmoat_core::Secret;
use openmoat_hosts::{Host, SandboxFormat};
use serde_json::Value;
use toml_edit::DocumentMut;
use super::install::Rendered;
use super::{Plan, Report, claude, codex, cursor};
use crate::home::Home;
use crate::integrity::Lock;
#[derive(Clone, Copy)]
pub enum Undo {
WithHooks(fn(&mut Value, &[String]) -> bool),
Toml(fn(&mut DocumentMut) -> bool),
Json(fn(&mut Value) -> bool),
}
#[derive(Clone, Copy)]
pub enum Pin {
WithHooks,
Whole(fn(&Path) -> Result<bool>),
Part {
carries: fn(&Path) -> Result<bool>,
digest: fn(&Path) -> Result<String>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MaskLevel {
Masked,
NotWritten,
Unmasked,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SecretMask<'a> {
pub secret: &'a Secret,
pub text: String,
pub level: MaskLevel,
}
pub trait SandboxBackend: Sync {
fn render(
&self,
home: &Home,
host: Host,
plan: &Plan,
current: &str,
) -> Result<Option<Rendered>>;
fn report<'a>(&self, plan: &'a Plan) -> &'a Report;
fn shown(&self, plan: &Plan) -> Result<String>;
fn problems(
&self,
home: &Home,
path: &Path,
plan: &Plan,
lock: Option<&Lock>,
) -> Result<Vec<String>>;
fn undo(&self) -> Undo;
fn pin(&self) -> Pin;
fn masks_secrets(&self) -> bool {
false
}
fn secret_masks<'a>(
&self,
_settings: &Value,
_secrets: &'a [Secret],
_plan: &Plan,
) -> Vec<SecretMask<'a>> {
Vec::new()
}
}
pub fn backend(format: SandboxFormat) -> &'static dyn SandboxBackend {
match format {
SandboxFormat::ClaudeSettings => &claude::backend::ClaudeSettings,
SandboxFormat::CodexProfile => &codex::backend::CodexProfile,
SandboxFormat::CursorSandbox => &cursor::backend::CursorSandbox,
}
}
pub(super) const OUT_OF_DATE: &str = "differs from the policy; run `openmoat sandbox sync`";
pub(super) const NOT_PINNED: &str = "not pinned by the lock; run `openmoat sandbox sync`";