1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! `pi-cli` — a terminal coding-agent CLI built on the rpi library crates.
//!
//! It provides the argument surface, provider/model resolution, harness
//! construction, output modes, and the interactive TUI that a harness-backed
//! CLI needs.
//!
//! # Surface
//!
//! - **Argument parsing** ([`args`]) — `--provider`/`--model`/`--api-key`,
//! `--thinking`, `--print`/`-p`, `--mode {text,json}`, `-c`/`--continue`,
//! `-r`/`--resume`, `--session`/`--session-dir`/`--no-session`, `--tools`/
//! `-t`, `--exclude-tools`/`-xt`, `--no-tools`, `--no-builtin-tools`,
//! `--system-prompt`, `--append-system-prompt`, `--name`/`-n`, `--verbose`,
//! `--help`/`-h`, `--version`/`-v`, positional `messages`, and `@file`
//! attachments.
//! - **Provider/model resolution** ([`provider`]) — API key from `--api-key`
//! or the provider's environment variable; model pattern
//! `provider/id[:thinking]` resolved against the provider's catalog.
//! - **Harness construction + run loop** ([`session`]) — `OsExecutionEnv` +
//! built-in `read`/`write`/`edit`/`bash` tools, durable JSONL session storage,
//! `AgentHarness`, and the `prompt_text → outcome` run.
//! - **Output modes** ([`modes`]) — `print` (text, single-shot) and `json`
//! (newline-delimited harness events), plus a simple interactive REPL.
//! - **`app`** ([`app`]) — argument dispatch, model resolution, harness build,
//! mode dispatch, exit codes.
//!
//! Resources load from `.rpi/` and `~/.rpi/agent/`; extensions are Rust
//! `cdylib` plugins installed and developed with `rpi install` / `rpi dev`.
/// Crate version, surfaced by `rpi --version`. Mirrors the TS `VERSION` export
/// (sourced from `package.json`; here from `env!("CARGO_PKG_VERSION")`).
///
/// Aliases [`rpi_plugin_sdk::HOST_VERSION`] so the version the CLI prints and
/// the version handed to plugins (and, through it, the version extensions stamp
/// on their own telemetry) can never disagree.
pub const VERSION: &str = HOST_VERSION;
/// The application name used in help + version output. Mirrors TS `APP_NAME`
/// (the TS bin is `"pi"`; the Rust crate publishes under the `rpi-` namespace,
/// so the binary + displayed name is `"rpi"` to match).
///
/// Aliases [`rpi_plugin_sdk::HOST_NAME`] — the plugin contract owns the
/// identity, so an extension can label its output (a trace name, a tag) without
/// hardcoding a brand that a rename would silently invalidate.
pub const APP_NAME: &str = HOST_NAME;