mod cmd_doctor;
mod cmd_hook;
mod cmd_init;
mod cmd_log;
mod cmd_mcp;
mod cmd_models;
mod cmd_replay;
mod cmd_wrap;
mod util;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(
name = "aiguard",
about = "Security guardrails for AI coding agents",
version,
propagate_version = true
)]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(short, long, action = clap::ArgAction::Count, global = true)]
verbose: u8,
}
#[derive(Subcommand)]
enum Commands {
Init(cmd_init::InitArgs),
Doctor,
Hook(cmd_hook::HookArgs),
Replay(cmd_replay::ReplayArgs),
Log(cmd_log::LogArgs),
Mcp(cmd_mcp::McpArgs),
Models(ModelsArgs),
Wrap(cmd_wrap::WrapArgs),
}
#[derive(Parser)]
struct ModelsArgs {
#[command(subcommand)]
command: ModelsCommand,
}
#[derive(Subcommand)]
enum ModelsCommand {
Pull {
model: String,
},
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let filter = match cli.verbose {
0 => "warn",
1 => "info",
2 => "debug",
_ => "trace",
};
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new(filter)),
)
.with_target(false)
.init();
match cli.command {
Commands::Init(args) => cmd_init::run(args).await,
Commands::Doctor => cmd_doctor::run().await,
Commands::Hook(args) => cmd_hook::run(args).await,
Commands::Replay(args) => cmd_replay::run(args),
Commands::Log(args) => cmd_log::run(args).await,
Commands::Mcp(args) => cmd_mcp::run(args).await,
Commands::Models(args) => match args.command {
ModelsCommand::Pull { model } => cmd_models::run_pull(&model).await,
},
Commands::Wrap(args) => cmd_wrap::run(args).await,
}
}