truth-mirror 0.7.0

Truthfulness gate and adversarial reviewer harness for AI coding agents.
Documentation
use std::process::ExitCode;

use anyhow::Result;
use clap::{CommandFactory, FromArgMatches};
use tracing_subscriber::EnvFilter;

pub mod claim;
pub mod cli;
pub mod config;
pub mod context;
pub mod enforcement;
pub mod gate;
pub mod hooks;
pub mod ledger;
pub mod memory_skill;
mod messages;
pub mod provenance;
pub mod reinject;
pub mod reviewer;
mod shell;
pub mod skills;
pub mod status;
pub mod surface;
mod time;

pub fn init_tracing() {
    let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("warn"));
    let _ = tracing_subscriber::fmt().with_env_filter(filter).try_init();
}

pub fn run_from_env(command_name: &'static str) -> Result<ExitCode> {
    init_tracing();
    let matches = cli::Cli::command()
        .name(command_name)
        .bin_name(command_name)
        .get_matches();
    run(cli::Cli::from_arg_matches(&matches)?)
}

pub fn run(cli: cli::Cli) -> Result<ExitCode> {
    let cli::Cli {
        state_dir,
        config: config_path,
        command,
    } = cli;

    let command = match command {
        cli::Commands::Status(args) => return status::run(args, &state_dir),
        command => command,
    };

    let config = config::TruthMirrorConfig::load_for_cli(config_path.as_deref(), &state_dir)?;

    match command {
        cli::Commands::InstallHooks(args) => {
            hooks::run(args, &state_dir, config_path.as_deref(), &config)
        }
        cli::Commands::Review(args) => reviewer::run_review_command(args, &state_dir, &config),
        cli::Commands::Gate(args) => gate::run(args, &state_dir, config_path.as_deref(), &config),
        cli::Commands::Reinject(args) => reinject::run(args, &state_dir, &config),
        cli::Commands::Ledger(args) => ledger::run(args, &state_dir),
        cli::Commands::MemorySkill(args) => memory_skill::run(args, &state_dir, &config),
        cli::Commands::Watch(args) => reviewer::run_watch_command(args, &state_dir, &config),
        cli::Commands::Status(_) => unreachable!("status returns before config load"),
        cli::Commands::Skills(args) => skills::run(args),
        cli::Commands::Uninstall(args) => {
            hooks::run_uninstall(args, &state_dir, config_path.as_deref())
        }
        cli::Commands::HookDispatch(args) => {
            hooks::dispatch(args, &state_dir, config_path.as_deref(), &config)
        }
    }
}