agengo 0.5.4

Orchestrate AI coding agents (Claude Code) to build, verify, review and integrate tasks in isolated Git worktrees
//! A custom adapter: any executable that reads the request as JSON on stdin
//! and prints the reply as JSON on stdout (`docs/reference.md`, "Adapter
//! protocol").

use super::{Driver, Prepared};
use crate::config::Pick;
use anyhow::Result;
use serde_json::Value;
use std::process::Command;

pub struct Custom {
    pub executable: String,
}

impl Driver for Custom {
    fn name(&self) -> String {
        self.executable.clone()
    }

    fn prepare(&self, request: &Value, _profile: &Value, pick: &Pick) -> Result<Prepared> {
        // The tier, and the model and effort the user set for it, are for
        // the adapter to use or ignore.
        let mut request = request.clone();
        request["tier"] = pick.tier.into();
        if let Some(model) = &pick.model {
            request["model"] = model.clone().into();
        }
        if let Some(effort) = pick.effort {
            request["effort"] = effort.as_str().into();
        }
        Ok(Prepared {
            command: Command::new(&self.executable),
            stdin: request.to_string(),
        })
    }

    fn usage(&self, output: &mut Value) -> Option<Value> {
        output
            .as_object_mut()
            .and_then(|object| object.remove("usage"))
            .and_then(|raw| crate::usage::from_adapter(&raw))
    }

    fn reported_error(&self, _output: &Value) -> Option<String> {
        None
    }

    fn reply(&self, output: Value) -> Value {
        output
    }
}