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. v1 deliberately
33//! scopes to a minimal-but-real CLI exercising the Rust harness end-to-end:
34//! no TUI (`modes/interactive`), no extension system, no package manager
35//! (`install`/`remove`/`update`/`config`), no OAuth/Copilot auth, no HTML
36//! export, no skills/prompt-template/theme discovery, no model cycling
37//! (`--models`), no `--fork`/`--export`/`--list-models`. The library APIs for
38//! many of these (skills, prompt templates, compaction, JSONL session fork)
39//! already exist; wiring them is future work.
40//!
41//! [`packages/coding-agent/src/cli.ts`]: ../../.reference/pi/packages/coding-agent/src/cli.ts
42//! [`main.ts`]: ../../.reference/pi/packages/coding-agent/src/main.ts
43//! [`cli/args.ts`]: ../../.reference/pi/packages/coding-agent/src/cli/args.ts
44//! [`modes/print-mode.ts`]: ../../.reference/pi/packages/coding-agent/src/modes/print-mode.ts
45
46pub mod args;
47pub mod app;
48pub mod auth;
49pub mod config;
50pub mod extras;
51pub mod interactive_tui;
52pub mod modes;
53pub mod provider;
54pub mod session;
55pub mod settings;
56
57/// Crate version, surfaced by `rpi --version`. Mirrors the TS `VERSION` export
58/// (sourced from `package.json`; here from `env!("CARGO_PKG_VERSION")`).
59pub const VERSION: &str = env!("CARGO_PKG_VERSION");
60
61/// The application name used in help + version output. Mirrors TS `APP_NAME`
62/// (the TS bin is `"pi"`; the Rust crate publishes under the `rpi-` namespace,
63/// so the binary + displayed name is `"rpi"` to match).
64pub const APP_NAME: &str = "rpi";