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