magi-code 0.77.1

Repository-aware CLI coding agent for terminal work
Documentation
mod agent;
mod appearance;
mod bash_mode;
mod cancellation;
mod checkpoints;
mod cli;
mod commands;
mod compaction;
pub mod config;
pub mod context;
mod fast;
mod hash;
mod herdr;
mod hex;
mod hooks;
mod http_body;
mod instructions;
mod login;
mod lsp;
mod mcp;
mod model_catalog;
mod output;
mod path_utils;
mod persistence;
mod primary_agents;
mod process_environment;
mod prompt_file;
mod providers;
mod rendering;
mod security;
mod service;
mod session_titles;
pub mod sessions;
mod shell;
mod skills;
mod subagents;
mod summarizer;
#[cfg(test)]
mod test_support;
mod thinking;
mod tool_display;
mod tool_output_measurement;
mod tools;
mod tui;
mod updates;

// Intentional public API surface for the CLI crate. Keep additions and removals explicit:
// - `run_from_env()` and `run_from_env_with_exit_code()` are the supported binary entrypoints.
// - `config` exposes durable paths, settings, hooks, and custom-provider data.
// - `context` exposes context-budget and token-estimation helpers.
// - `sessions` exposes session managers, session IDs, and latest-title lookup.
// - `ChatMessage`, `MessageRole`, `Usage`, and `ThinkingLevel` are shared data contracts.
// Provider, auth, command, instruction, skill, agent, shell, subagent, TUI, rendering, and
// persistence internals stay private to the crate.

pub use providers::{ChatMessage, MessageRole, Usage};
// Explicit transport-independent owner for the persistent service adapter (#502/#503).
// This does not expose runtime internals or add a CLI/socket transport.
pub use service::PersistentService;
pub use thinking::ThinkingLevel;

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) => {
            eprintln!("Error: {:?}", error.as_error());
            error.exit_code()
        }
    }
}

fn run_from_env_inner() -> crate::cli::AppResult<()> {
    let args = cli::CliArgs::parse();
    cli::run(args)
}