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;
35
36// Intentional public API surface for the CLI crate. Keep this surface non-breaking unless a
37// SemVer-major plan explicitly changes it:
38// - `run_from_env()` is the supported binary entrypoint used by `src/bin/magi-code.rs`.
39// - `config`, `context`, and `sessions` stay public because they expose durable settings,
40//   context-budget/token helpers, and JSONL session IDs used by integration coverage.
41// - `ChatMessage`, `MessageRole`, `Usage`, and `ThinkingLevel` stay public because public
42//   config/context types use them directly.
43// Command, instruction, skill, provider, agent, shell, subagent, TUI, rendering, and tool
44// runtime internals stay private to the crate.
45
46pub use providers::{ChatMessage, MessageRole, Usage};
47pub use thinking::ThinkingLevel;
48
49use anyhow::Result;
50use clap::Parser;
51
52pub fn run_from_env() -> Result<()> {
53    run_from_env_inner().map_err(crate::cli::AppError::into_error)
54}
55
56pub fn run_from_env_with_exit_code() -> std::process::ExitCode {
57    match run_from_env_inner() {
58        Ok(()) => std::process::ExitCode::SUCCESS,
59        Err(error) => {
60            eprintln!("Error: {:?}", error.as_error());
61            error.exit_code()
62        }
63    }
64}
65
66fn run_from_env_inner() -> crate::cli::AppResult<()> {
67    let args = cli::CliArgs::parse();
68    cli::run(args)
69}