Skip to main content

magi_code/
lib.rs

1mod agent;
2mod appearance;
3mod auth;
4mod browser;
5mod cancellation;
6mod checkpoints;
7mod cli;
8mod code_mode;
9mod commands;
10mod compaction;
11mod config;
12mod context;
13mod credentials;
14mod diff_review;
15mod herdr;
16mod hooks;
17mod instructions;
18mod local_agent;
19mod mcp;
20mod model_catalog;
21mod output;
22mod persistence;
23mod primary_agents;
24mod process_environment;
25#[cfg(test)]
26mod profiling;
27mod progressive_session_maintenance;
28mod prompt_file;
29mod protection;
30mod provider_ids;
31mod providers;
32mod rendering;
33mod runtime_context;
34mod session_titles;
35mod sessions;
36mod shell;
37mod skills;
38mod subagents;
39mod summarizer;
40mod support;
41mod thinking;
42mod tool_contract;
43mod tool_output_measurement;
44mod tools;
45mod tui;
46mod typesafe;
47mod updates;
48
49// The library only exposes the CLI entrypoints used by the binary.
50// Settings, context, sessions and provider data are crate-private implementation details.
51
52use anyhow::Result;
53use clap::Parser;
54
55pub fn run_from_env() -> Result<()> {
56    run_from_env_inner().map_err(crate::cli::AppError::into_error)
57}
58
59pub fn run_from_env_with_exit_code() -> std::process::ExitCode {
60    match run_from_env_inner() {
61        Ok(()) => std::process::ExitCode::SUCCESS,
62        Err(error) => {
63            if !error.as_error().is::<local_agent::TransportStopped>() {
64                eprintln!("Error: {:?}", error.as_error());
65            }
66            error.exit_code()
67        }
68    }
69}
70
71fn run_from_env_inner() -> crate::cli::AppResult<()> {
72    // Claude CLI launches this binary as its inventory-only MCP server; dispatch before CLI parsing.
73    if let Some(path) = std::env::var_os("MAGI_CLAUDE_INERT_MCP_INVENTORY") {
74        return providers::claude_inert::serve_inventory(std::path::Path::new(&path))
75            .map_err(crate::cli::AppError::runtime);
76    }
77    let args = cli::CliArgs::parse();
78    cli::run(args)
79}