rpi_cli/lib.rs
1//! `pi-cli` — a terminal coding-agent CLI built on the pi-rust library crates.
2//!
3//! This is the post-SDK deliverable per the user's instruction "把sdk复制完后,把cli也写下"
4//! (after the SDK port, also write the CLI). It mirrors the *CLI surface* of the
5//! TypeScript reference `packages/coding-agent` ([`packages/coding-agent/src/cli.ts`]
6//! → [`main.ts`] → [`cli/args.ts`] → [`modes/print-mode.ts`]), ported onto the Rust
7//! `AgentHarness` instead of the TS `AgentSession`.
8//!
9//! # What is ported (v1 scope)
10//!
11//! - **Argument parsing** ([`args`]) — `parseArgs`/`printHelp` for the flags a
12//! harness-backed CLI actually honors: `--provider`/`--model`/`--api-key`,
13//! `--thinking`, `--print`/`-p`, `--mode {text,json}`, `-c`/`--continue`,
14//! `-r`/`--resume`, `--session`/`--session-dir`/`--no-session`, `--tools`/
15//! `-t`, `--exclude-tools`/`-xt`, `--no-tools`, `--no-builtin-tools`,
16//! `--system-prompt`, `--append-system-prompt`, `--name`/`-n`, `--verbose`,
17//! `--help`/`-h`, `--version`/`-v`, positional `messages`, and `@file`
18//! attachments.
19//! - **Provider/model resolution** ([`provider`]) — Anthropic-only (v1), API key
20//! from `--api-key` → `ANTHROPIC_API_KEY`; model pattern `provider/id[:thinking]`
21//! resolved against the provider's catalog.
22//! - **Harness construction + run loop** ([`session`]) — `OsExecutionEnv` +
23//! built-in `read`/`write`/`edit`/`bash` tools, durable JSONL session storage,
24//! `AgentHarness`, and the `prompt_text → outcome` run.
25//! - **Output modes** ([`modes`]) — `print` (text, single-shot) and `json`
26//! (newline-delimited harness events), plus a simple interactive REPL.
27//! - **`app`** ([`app`]) — argument dispatch, model resolution, harness build,
28//! mode dispatch, exit codes.
29//!
30//! # What is NOT ported (deferred — tracked in `docs/m6-cli-open-questions.md`)
31//!
32//! The TS `coding-agent` is a large, full-featured product. The current Rust
33//! CLI includes the interactive TUI, extension loading, skills and prompt
34//! templates, compaction, session fork/export, and lane-aware harness runs.
35//! OAuth/Copilot auth, HTML export, and full model cycling remain outside the
36//! current implementation. `rpi install` supports Rust cdylib extensions.
37//!
38//! [`packages/coding-agent/src/cli.ts`]: ../../.reference/pi/packages/coding-agent/src/cli.ts
39//! [`main.ts`]: ../../.reference/pi/packages/coding-agent/src/main.ts
40//! [`cli/args.ts`]: ../../.reference/pi/packages/coding-agent/src/cli/args.ts
41//! [`modes/print-mode.ts`]: ../../.reference/pi/packages/coding-agent/src/modes/print-mode.ts
42
43pub mod app;
44pub mod args;
45pub mod auth;
46pub mod config;
47pub mod extensions_actions;
48pub mod extras;
49pub mod install;
50pub mod interactive_tui;
51pub mod modes;
52pub mod provider;
53pub mod resource_dirs;
54pub mod resume_picker;
55pub mod session;
56pub mod settings;
57
58/// Crate version, surfaced by `rpi --version`. Mirrors the TS `VERSION` export
59/// (sourced from `package.json`; here from `env!("CARGO_PKG_VERSION")`).
60pub const VERSION: &str = env!("CARGO_PKG_VERSION");
61
62/// The application name used in help + version output. Mirrors TS `APP_NAME`
63/// (the TS bin is `"pi"`; the Rust crate publishes under the `rpi-` namespace,
64/// so the binary + displayed name is `"rpi"` to match).
65pub const APP_NAME: &str = "rpi";