use anyhow::Result;
use clap::{Parser, Subcommand};
use std::net::SocketAddr;
use trusty_memory::commands::migrate::{handle_migrate, MigrateTarget};
use trusty_memory::{run_http, run_stdio, AppState};
#[derive(Debug, Parser)]
#[command(
name = "trusty-memory",
version,
about = "Memory palace MCP server + migration utility",
long_about = "MCP server (stdio + HTTP/SSE) for trusty-memory, plus a \
`migrate kuzu-memory` subcommand that rewrites Claude \
settings files referencing the legacy kuzu-memory server."
)]
struct Cli {
#[arg(short, long, action = clap::ArgAction::Count, global = true)]
verbose: u8,
#[command(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
Serve {
#[arg(long, value_name = "ADDR")]
http: Option<SocketAddr>,
#[arg(long, value_name = "NAME")]
palace: Option<String>,
},
Migrate {
#[arg(value_enum)]
target: MigrateTarget,
#[arg(long)]
dry_run: bool,
#[arg(long)]
config_only: bool,
},
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
trusty_common::init_tracing(cli.verbose);
match cli.command {
Command::Serve { http, palace } => run_serve(http, palace).await,
Command::Migrate {
target,
dry_run,
config_only,
} => handle_migrate(target, dry_run, config_only),
}
}
async fn run_serve(http: Option<SocketAddr>, palace: Option<String>) -> Result<()> {
let data_root = trusty_common::resolve_data_dir("trusty-memory")?;
let state = AppState::new(data_root).with_default_palace(palace);
if let Some(addr) = http {
run_http(state, addr).await
} else {
run_stdio(state).await
}
}