Skip to main content

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 agent_session;
46pub mod app;
47pub mod args;
48pub mod attribution;
49pub mod auth;
50pub mod auth_guidance;
51pub mod brand;
52pub mod changelog;
53pub mod config;
54pub mod dev_extension;
55pub mod docs_tool;
56pub mod events;
57pub mod experimental;
58pub mod export;
59pub mod extension_api;
60pub mod extensions_actions;
61pub mod extras;
62pub mod fs_watch;
63pub mod install;
64pub mod install_pi;
65pub mod interactive_tui;
66pub mod js_extensions;
67pub mod key_trace;
68pub mod llama_command;
69pub mod model_registry;
70pub mod modes;
71pub mod node_transport;
72pub mod npm;
73pub mod oauth;
74pub mod packages;
75pub mod provider;
76pub mod remote;
77pub mod remote_catalog;
78pub mod resource_dirs;
79pub mod resume_picker;
80pub mod session;
81pub mod session_cwd;
82pub mod settings;
83pub mod source_info;
84pub mod timings;
85pub mod trust;
86pub mod updates;
87
88/// Crate version, surfaced by `rpi --version`. Mirrors the TS `VERSION` export
89/// (sourced from `package.json`; here from `env!("CARGO_PKG_VERSION")`).
90pub const VERSION: &str = env!("CARGO_PKG_VERSION");
91
92/// The application name used in help + version output. Mirrors TS `APP_NAME`
93/// (the TS bin is `"pi"`; the Rust crate publishes under the `rpi-` namespace,
94/// so the binary + displayed name is `"rpi"` to match).
95pub const APP_NAME: &str = "rpi";