magi-code 0.102.1

Repository-aware CLI coding agent for terminal work
Documentation
mod agent;
mod appearance;
mod auth;
mod browser;
mod cancellation;
mod checkpoints;
mod cli;
mod code_mode;
mod commands;
mod compaction;
mod config;
mod context;
mod credentials;
mod diff_review;
mod herdr;
mod hooks;
mod instructions;
mod local_agent;
mod lsp;
mod mcp;
mod model_catalog;
mod output;
mod persistence;
mod primary_agents;
mod process_environment;
#[cfg(test)]
mod profiling;
mod progressive_session_maintenance;
mod prompt_file;
mod protection;
mod provider_ids;
mod providers;
mod rendering;
mod runtime_context;
mod session_titles;
mod sessions;
mod shell;
mod skills;
mod subagents;
mod summarizer;
mod support;
mod thinking;
mod tool_contract;
mod tool_output_measurement;
mod tools;
mod tui;
mod typesafe;
mod updates;

// The library only exposes the CLI entrypoints used by the binary.
// Settings, context, sessions and provider data are crate-private implementation details.

use anyhow::Result;
use clap::Parser;

pub fn run_from_env() -> Result<()> {
    run_from_env_inner().map_err(crate::cli::AppError::into_error)
}

pub fn run_from_env_with_exit_code() -> std::process::ExitCode {
    match run_from_env_inner() {
        Ok(()) => std::process::ExitCode::SUCCESS,
        Err(error) => {
            if !error.as_error().is::<local_agent::TransportStopped>() {
                eprintln!("Error: {:?}", error.as_error());
            }
            error.exit_code()
        }
    }
}

fn run_from_env_inner() -> crate::cli::AppResult<()> {
    // Claude CLI launches this binary as its inventory-only MCP server; dispatch before CLI parsing.
    if let Some(path) = std::env::var_os("MAGI_CLAUDE_INERT_MCP_INVENTORY") {
        return providers::claude_inert::serve_inventory(std::path::Path::new(&path))
            .map_err(crate::cli::AppError::runtime);
    }
    let args = cli::CliArgs::parse();
    cli::run(args)
}