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