use clap::Parser;
use std::env;
mod api_client;
mod commands;
mod config;
mod credentials;
mod hooks;
#[derive(Parser)]
#[command(name = "tracevault", version, about = "AI code governance platform")]
enum Cli {
Init {
#[arg(long)]
server_url: Option<String>,
},
Status,
#[command(hide = true)]
Stream {
#[arg(long)]
event: String,
},
Check,
Sync,
Stats,
Login {
#[arg(long)]
server_url: String,
#[arg(long)]
no_browser: bool,
},
Logout,
#[command(hide = true)]
CommitPush,
Flush,
Verify {
#[arg(long)]
commits: Option<String>,
#[arg(long)]
range: Option<String>,
},
}
#[tokio::main]
async fn main() {
let cli = Cli::parse();
match cli {
Cli::Init { server_url } => {
let cwd = env::current_dir().expect("Cannot determine current directory");
match commands::init::init_in_directory(&cwd, server_url.as_deref()).await {
Ok(()) => {
println!("TraceVault initialized in {}", cwd.display());
println!("Claude Code hooks installed (.claude/settings.json)");
println!("Git hooks installed (pre-push, post-commit)");
println!("Added .tracevault/ and .claude/settings.json to .gitignore");
println!(
"Nothing needs to be committed — all TraceVault files are local only."
);
println!(
"Other contributors run `tracevault init` to set up their own local hooks."
);
}
Err(e) => eprintln!("Error: {e}"),
}
}
Cli::Status => {
let cwd = env::current_dir().expect("Cannot determine current directory");
let code = commands::status::run_status(&cwd).await;
if code != 0 {
std::process::exit(code);
}
}
Cli::Stream { event } => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::stream::run_stream(&cwd, &event).await {
eprintln!("Stream error: {e}");
}
}
Cli::Check => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::check::check_policies(&cwd).await {
eprintln!("Check error: {e}");
std::process::exit(1);
}
}
Cli::Sync => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::sync::sync_repo(&cwd).await {
eprintln!("Sync error: {e}");
}
}
Cli::Stats => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::stats::show_stats(&cwd) {
eprintln!("Stats error: {e}");
}
}
Cli::Login {
server_url,
no_browser,
} => {
if let Err(e) = commands::login::login(&server_url, no_browser).await {
eprintln!("Login error: {e}");
}
}
Cli::Logout => {
if let Err(e) = commands::logout::logout().await {
eprintln!("Logout error: {e}");
}
}
Cli::CommitPush => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::commit_push::run_commit_push(&cwd).await {
eprintln!("Commit push error: {e}");
}
}
Cli::Flush => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) = commands::flush::run_flush(&cwd).await {
eprintln!("Flush error: {e}");
}
}
Cli::Verify { commits, range } => {
let cwd = env::current_dir().expect("Cannot determine current directory");
if let Err(e) =
commands::verify::verify(&cwd, commits.as_deref(), range.as_deref()).await
{
eprintln!("Verify error: {e}");
std::process::exit(1);
}
}
}
}