Skip to main content

Crate rpi_cli

Crate rpi_cli 

Source
Expand description

pi-cli — a terminal coding-agent CLI built on the pi-rust library crates.

This is the post-SDK deliverable per the user’s instruction “把sdk复制完后,把cli也写下” (after the SDK port, also write the CLI). It mirrors the CLI surface of the TypeScript reference packages/coding-agent (packages/coding-agent/src/cli.tsmain.tscli/args.tsmodes/print-mode.ts), ported onto the Rust AgentHarness instead of the TS AgentSession.

§What is ported (v1 scope)

  • Argument parsing (args) — parseArgs/printHelp for the flags a harness-backed CLI actually honors: --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) — Anthropic-only (v1), API key from --api-keyANTHROPIC_API_KEY; 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.

§What is NOT ported (deferred — tracked in docs/m6-cli-open-questions.md)

The TS coding-agent is a large, full-featured product. v1 deliberately scopes to a minimal-but-real CLI exercising the Rust harness end-to-end: no TUI (modes/interactive), no extension system, no package manager (install/remove/update/config), no OAuth/Copilot auth, no HTML export, no skills/prompt-template/theme discovery, no model cycling (--models), no --fork/--export/--list-models. The library APIs for many of these (skills, prompt templates, compaction, JSONL session fork) already exist; wiring them is future work.

Modules§

app
CLI entry orchestrator. Mirrors the v1-relevant slice of the TS packages/coding-agent/src/main.ts — the main(args) function that:
args
CLI argument parsing + help text. Mirrors the TS packages/coding-agent/src/cli/args.ts (parseArgs + printHelp), scoped to the flags the v1 Rust CLI honors.
auth
rpi auth subcommand — persistent credential management. Mirrors the Rust-relevant slice of the TS packages/coding-agent/src/cli/auth-command.ts
config
~/.rpi/ persistent configuration — auth + model catalog. Mirrors (a Rust-flattened slice of) the TS packages/coding-agent/src/config.ts (getAgentDir/getAuthPath/getModelsPath) + core/auth-storage.ts (FileAuthStorageBackend) + core/model-config.ts (ModelConfig).
modes
Output modes. Mirrors the v1-relevant slice of the TS packages/coding-agent/src/modes/{print-mode,json-event,rpc-mode}.ts — the three run shapes a harness-backed CLI needs:
provider
Provider + model resolution. Mirrors the Anthropic-protocol slice of the TS packages/coding-agent/src/core/model-resolver.ts (resolveCliModel + the provider/id[:thinking] parsing in crate::args).
session
Harness construction + session-storage wiring. Mirrors the Rust-side equivalent of the TS packages/coding-agent/src/core/sdk.ts (createAgentSession) — build the env, tools, durable session storage, and AgentHarnessOptions, then AgentHarness::create.

Constants§

APP_NAME
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).
VERSION
Crate version, surfaced by rpi --version. Mirrors the TS VERSION export (sourced from package.json; here from env!("CARGO_PKG_VERSION")).