Skip to main content

magi_code/
lib.rs

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