use super::super::resolve_binary_path;
use crate::core::editor_registry::{
ConfigType, EditorTarget, WriteAction, WriteOptions, write_config_with_options,
};
pub(crate) fn install_openclaw_hook() {
if !super::super::should_register_mcp() {
return;
}
let binary = resolve_binary_path();
let home = crate::core::home::resolve_home_dir().unwrap_or_default();
let display_path = "~/.openclaw/openclaw.json";
let target = EditorTarget {
name: "OpenClaw",
agent_key: "openclaw".to_string(),
config_path: home.join(".openclaw/openclaw.json"),
detect_path: home.join(".openclaw"),
config_type: ConfigType::OpenClaw,
};
match write_config_with_options(&target, &binary, WriteOptions::default()) {
Ok(result) => {
if super::super::mcp_server_quiet_mode() {
return;
}
match result.action {
WriteAction::Already => {
eprintln!("OpenClaw MCP already configured at {display_path}");
}
WriteAction::Created | WriteAction::Updated => {
eprintln!(" \x1b[32m✓\x1b[0m OpenClaw MCP configured at {display_path}");
if let Some(note) = result.note {
eprintln!(" ({note})");
}
}
}
}
Err(e) => {
tracing::error!("Failed to configure OpenClaw: {e}");
if !super::super::mcp_server_quiet_mode() {
eprintln!(" \x1b[31m✗\x1b[0m OpenClaw MCP configuration failed: {e}");
}
}
}
}