use sqlx::SqlitePool;
use std::process::Command;
struct AgentPreset {
id: &'static str,
display_name: &'static str,
command: &'static str,
args_json: &'static str,
}
const BUILTIN_PRESETS: &[AgentPreset] = &[
AgentPreset {
id: "preset-claude",
display_name: "Claude Code",
command: "npx",
args_json: r#"["-y", "@agentclientprotocol/claude-agent-acp"]"#,
},
AgentPreset {
id: "preset-codex",
display_name: "Codex",
command: "npx",
args_json: r#"["-y", "@agentclientprotocol/codex-acp"]"#,
},
AgentPreset {
id: "preset-gemini",
display_name: "Gemini CLI",
command: "gemini",
args_json: r#"["--experimental-acp"]"#,
},
AgentPreset {
id: "preset-opencode",
display_name: "OpenCode",
command: "opencode",
args_json: r#"["acp"]"#,
},
AgentPreset {
id: "preset-qwen",
display_name: "Qwen Code",
command: "qwen",
args_json: r#"["--experimental-acp"]"#,
},
AgentPreset {
id: "preset-kiro",
display_name: "Kiro",
command: "kiro-cli",
args_json: r#"["acp"]"#,
},
AgentPreset {
id: "preset-qoder",
display_name: "qoder",
command: "qodercli",
args_json: r#"["--acp"]"#,
},
AgentPreset {
id: "preset-qoder-cn",
display_name: "qoder cn",
command: "qoderclicn",
args_json: r#"["--acp"]"#,
},
AgentPreset {
id: "preset-oh-my-pi",
display_name: "oh-my-pi",
command: "omp",
args_json: r#"["acp"]"#,
},
];
fn command_exists(name: &str) -> bool {
#[cfg(windows)]
let (checker, arg) = ("where", name);
#[cfg(not(windows))]
let (checker, arg) = ("which", name);
Command::new(checker)
.arg(arg)
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status()
.map(|s| s.success())
.unwrap_or(false)
}
pub async fn seed_builtin_presets(db: &SqlitePool) {
for preset in BUILTIN_PRESETS {
if !command_exists(preset.command) {
continue;
}
let now = chrono::Utc::now().to_rfc3339();
let _ = sqlx::query(
"INSERT OR IGNORE INTO agents (id, display_name, command, args, env, created_at, updated_at) \
VALUES (?, ?, ?, ?, '[]', ?, ?)",
)
.bind(preset.id)
.bind(preset.display_name)
.bind(preset.command)
.bind(preset.args_json)
.bind(&now)
.bind(&now)
.execute(db)
.await;
}
}