Skip to main content

magi_code/
lib.rs

1mod agent;
2mod appearance;
3mod auth;
4mod bash_mode;
5mod cancellation;
6mod checkpoints;
7mod cli;
8mod code_mode;
9mod commands;
10mod compaction;
11pub mod config;
12pub mod context;
13mod diff_review;
14mod fast;
15mod hash;
16mod herdr;
17mod hex;
18mod hooks;
19mod http_body;
20mod instructions;
21mod local_agent;
22mod lsp;
23mod mcp;
24mod model_catalog;
25mod output;
26mod path_utils;
27mod persistence;
28mod primary_agents;
29mod process_environment;
30#[cfg(test)]
31mod profiling;
32mod prompt_file;
33mod protection;
34mod providers;
35mod rendering;
36mod runtime_context;
37mod security;
38mod session_titles;
39pub mod sessions;
40mod shell;
41mod skills;
42mod subagents;
43mod summarizer;
44mod thinking;
45mod thread_join;
46mod tool_output_measurement;
47mod tools;
48mod tui;
49mod typesafe;
50mod updates;
51
52// Intentional public API surface for the CLI crate. Keep additions and removals explicit:
53// - `run_from_env()` and `run_from_env_with_exit_code()` are the supported binary entrypoints.
54// - `config` exposes durable paths, settings, hooks, and custom-provider data.
55// - `context` exposes context-budget and token-estimation helpers.
56// - `sessions` exposes session managers, session IDs, and latest-title lookup.
57// - `ChatMessage`, `MessageRole`, `Usage`, and `ThinkingLevel` are shared data contracts.
58// Provider, auth, command, instruction, skill, agent, shell, subagent, TUI, rendering, and
59// persistence internals stay private to the crate.
60
61pub use providers::{ChatMessage, MessageRole, Usage};
62pub use thinking::ThinkingLevel;
63
64use anyhow::Result;
65use clap::Parser;
66
67pub fn run_from_env() -> Result<()> {
68    run_from_env_inner().map_err(crate::cli::AppError::into_error)
69}
70
71pub fn run_from_env_with_exit_code() -> std::process::ExitCode {
72    if let Some(path) = std::env::var_os("MAGI_CLAUDE_INERT_MCP_INVENTORY") {
73        return match providers::claude_inert::serve_inventory(std::path::Path::new(&path)) {
74            Ok(()) => std::process::ExitCode::SUCCESS,
75            Err(_) => std::process::ExitCode::FAILURE,
76        };
77    }
78    match run_from_env_inner() {
79        Ok(()) => std::process::ExitCode::SUCCESS,
80        Err(error) => {
81            if !error.as_error().is::<local_agent::TransportStopped>() {
82                eprintln!("Error: {:?}", error.as_error());
83            }
84            error.exit_code()
85        }
86    }
87}
88
89fn run_from_env_inner() -> crate::cli::AppResult<()> {
90    let args = cli::CliArgs::parse();
91    cli::run(args)
92}