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.ts
→ main.ts → cli/args.ts → modes/print-mode.ts), ported onto the Rust
AgentHarness instead of the TS AgentSession.
§What is ported (v1 scope)
- Argument parsing (
args) —parseArgs/printHelpfor 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, positionalmessages, and@fileattachments. - Provider/model resolution (
provider) — Anthropic-only (v1), API key from--api-key→ANTHROPIC_API_KEY; model patternprovider/id[:thinking]resolved against the provider’s catalog. - Harness construction + run loop (
session) —OsExecutionEnv+ built-inread/write/edit/bashtools, durable JSONL session storage,AgentHarness, and theprompt_text → outcomerun. - Output modes (
modes) —print(text, single-shot) andjson(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. The current Rust
CLI includes the interactive TUI, extension loading, skills and prompt
templates, compaction, session fork/export, and lane-aware harness runs.
OAuth/Copilot auth, RPC, and full model cycling remain outside the current
implementation. rpi install supports Rust cdylib extensions and
rpi install-pi supports Pi npm/git/local packages through a Node JS/TS
extension bridge.
Modules§
- app
- CLI entry orchestrator. Mirrors the v1-relevant slice of the TS
packages/coding-agent/src/main.ts— themain(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 authsubcommand — persistent credential management. Mirrors the Rust-relevant slice of the TSpackages/coding-agent/src/cli/auth-command.ts- config
- Layout
- dev_
extension - Development workflow for Rust-native rpi extensions.
- docs_
tool - Built-in
docstool for looking up rpi usage documentation. - export
- Session file export helpers.
- extension_
api - Stable capability contracts shared by native and Node extension backends.
- extensions_
actions - B5a — the
RuntimeActionHostimpl over the harness, lived inrpi-cli(NOTrpi-harness) sorpi-extensionsstays a leaf in the crate DAG. The trait is defined inrpi-extensions(JSON + primitives only); this is the host side that bridges the 16 [RuntimeActionId] actions to the harness. - extras
- Extras & easter-egg wiring — thin host wrappers over the rpi-tui components.
- install
rpi install— install a Rustcdylibextension from crates.io.- install_
pi - Pi package installer (
rpi install-pi). - interactive_
tui - Interactive mode for pi-cli.
- js_
extensions - Minimal Pi JS/TS extension host.
- 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: - node_
transport - Multiplexed JSON-lines transport for long-lived Node extension runtimes.
- npm
- Native Pi-compatible npm command selection and argument construction.
- packages
- Discovery of Pi-compatible package resources.
- provider
- Provider + model resolution. Mirrors the provider/model selection and request-auth portions of native Pi’s model runtime.
- resource_
dirs - Resource-directory resolution + project-wins dedupe for skills and
prompt templates. Mirrors the precedence contract from pi’s
DefaultResourceLoader/package-manager(resource-loader.ts:676-681,package-manager.ts:178-181): resources are ranked project=0/1 < user=2/3 < package=4, andaddSkills/dedupePromptsare first-registration-wins on name → loading project before global means project wins on collision (skills.ts:399-428), with a collision diagnostic naming the winner (kept) and loser (dropped) paths. - resume_
picker - Startup session picker used by
-r/--resume. - 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, andAgentHarnessOptions, thenAgentHarness::create. - settings
~/.rpi/agent/settings.json— saved user defaults. Mirrors the slice of pi’sSettingsinterface (packages/coding-agent/src/core/settings-manager.ts) that rpi honors:defaultProvider/defaultModel/defaultThinkingLevel(consumed byprovider::resolveas pi’sfindInitialModelstep 3 — the saved default, when authed, wins over the built-in fallback),theme, packages, and configurable resource directories.- updates
- Lightweight update discovery and update commands.
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 therpi-namespace, so the binary + displayed name is"rpi"to match). - VERSION
- Crate version, surfaced by
rpi --version. Mirrors the TSVERSIONexport (sourced frompackage.json; here fromenv!("CARGO_PKG_VERSION")).