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, RPC, and full model cycling remain outside the current
36//! implementation. `rpi install` supports Rust cdylib extensions and
37//! `rpi install-pi` supports Pi npm/git/local packages through a Node JS/TS
38//! extension bridge.
39//!
40//! [`packages/coding-agent/src/cli.ts`]: ../../.reference/pi/packages/coding-agent/src/cli.ts
41//! [`main.ts`]: ../../.reference/pi/packages/coding-agent/src/main.ts
42//! [`cli/args.ts`]: ../../.reference/pi/packages/coding-agent/src/cli/args.ts
43//! [`modes/print-mode.ts`]: ../../.reference/pi/packages/coding-agent/src/modes/print-mode.ts
44
45pub mod app;
46pub mod args;
47pub mod auth;
48pub mod config;
49pub mod dev_extension;
50pub mod docs_tool;
51pub mod export;
52pub mod extension_api;
53pub mod extensions_actions;
54pub mod extras;
55pub mod install;
56pub mod install_pi;
57pub mod interactive_tui;
58pub mod js_extensions;
59pub mod modes;
60pub mod node_transport;
61pub mod packages;
62pub mod provider;
63pub mod resource_dirs;
64pub mod resume_picker;
65pub mod session;
66pub mod settings;
67pub mod updates;
68
69/// Crate version, surfaced by `rpi --version`. Mirrors the TS `VERSION` export
70/// (sourced from `package.json`; here from `env!("CARGO_PKG_VERSION")`).
71pub const VERSION: &str = env!("CARGO_PKG_VERSION");
72
73/// The application name used in help + version output. Mirrors TS `APP_NAME`
74/// (the TS bin is `"pi"`; the Rust crate publishes under the `rpi-` namespace,
75/// so the binary + displayed name is `"rpi"` to match).
76pub const APP_NAME: &str = "rpi";