Skip to main content

magi_code/
lib.rs

1mod agent;
2mod bash_mode;
3mod checkpoints;
4mod cli;
5mod commands;
6mod compaction;
7pub mod config;
8pub mod context;
9mod hash;
10mod herdr;
11mod hex;
12mod hooks;
13mod http_body;
14mod instructions;
15mod login;
16mod lsp;
17mod mcp;
18mod model_catalog;
19mod output;
20mod persistence;
21mod primary_agents;
22mod prompt_file;
23mod providers;
24mod rendering;
25pub mod sessions;
26mod shell;
27mod skills;
28mod subagents;
29#[cfg(test)]
30mod test_support;
31mod thinking;
32mod tool_display;
33mod tools;
34mod tui;
35mod tui2;
36
37// Intentional public API surface for the CLI crate. Keep this surface non-breaking unless a
38// SemVer-major plan explicitly changes it:
39// - `run_from_env()` is the supported binary entrypoint used by `src/bin/magi-code.rs`.
40// - `config`, `context`, and `sessions` stay public because they expose durable settings,
41//   context-budget/token helpers, and JSONL session IDs used by integration coverage.
42// - `ChatMessage`, `MessageRole`, `Usage`, and `ThinkingLevel` stay public because public
43//   config/context types use them directly.
44// Command, instruction, skill, provider, agent, shell, subagent, TUI, rendering, and tool
45// runtime internals stay private to the crate.
46
47pub use providers::{ChatMessage, MessageRole, Usage};
48pub use thinking::ThinkingLevel;
49
50use anyhow::Result;
51use clap::Parser;
52
53pub fn run_from_env() -> Result<()> {
54    run_from_env_inner().map_err(crate::cli::AppError::into_error)
55}
56
57pub fn run_from_env_with_exit_code() -> std::process::ExitCode {
58    match run_from_env_inner() {
59        Ok(()) => std::process::ExitCode::SUCCESS,
60        Err(error) => {
61            eprintln!("Error: {:?}", error.as_error());
62            error.exit_code()
63        }
64    }
65}
66
67fn run_from_env_inner() -> crate::cli::AppResult<()> {
68    let args = cli::CliArgs::parse();
69    cli::run(args)
70}