@bigfishnpm/rpi 0.0.0-stage → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/NOTICE +24 -0
- package/README.md +586 -3
- package/npm/bin/rpi.cjs +36 -0
- package/npm/install.cjs +69 -0
- package/npm/lib.cjs +91 -0
- package/npm/release.json +70 -0
- package/package.json +52 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mario Zechner (https://github.com/earendil-works/pi)
|
|
4
|
+
Copyright (c) 2026 pi-rust contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
rpi
|
|
2
|
+
===
|
|
3
|
+
|
|
4
|
+
This crate family is a Rust port of the TypeScript `pi` SDK, not a verbatim
|
|
5
|
+
copy of it.
|
|
6
|
+
|
|
7
|
+
Upstream project
|
|
8
|
+
----------------
|
|
9
|
+
|
|
10
|
+
pi — https://github.com/earendil-works/pi
|
|
11
|
+
Copyright (c) 2025 Mario Zechner
|
|
12
|
+
Licensed under the MIT License.
|
|
13
|
+
|
|
14
|
+
The `rpi-*` crates re-implement the original MIT-licensed TypeScript SDK in
|
|
15
|
+
Rust. The license text in `LICENSE` therefore carries both the upstream
|
|
16
|
+
copyright notice and the notice for the Rust port, as required by the MIT
|
|
17
|
+
License's retention clause.
|
|
18
|
+
|
|
19
|
+
Third-party dependencies
|
|
20
|
+
------------------------
|
|
21
|
+
|
|
22
|
+
Runtime dependencies and their licenses are listed by `cargo metadata` and on
|
|
23
|
+
each crate's crates.io page. Vendored or copied source, where it exists, keeps
|
|
24
|
+
its original attribution in the file header.
|
package/README.md
CHANGED
|
@@ -1,3 +1,586 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# rpi — a Rust-native coding-agent runtime
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="docs/images/rpi-logo.jpg" width="240" alt="rpi project logo">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
[](https://crates.io/crates/rpi-cli)
|
|
8
|
+
[](https://crates.io/crates/rpi-cli)
|
|
9
|
+
[](https://docs.rs/rpi-cli)
|
|
10
|
+
[](#license)
|
|
11
|
+
[](#install)
|
|
12
|
+
[](https://github.com/bigfish1913/pi-rust/actions/workflows/ci.yml)
|
|
13
|
+
[](https://github.com/bigfish1913/pi-rust/stargazers)
|
|
14
|
+
[](https://github.com/bigfish1913/pi-rust/releases/latest)
|
|
15
|
+
[](https://github.com/RyanAlberts/best-of-Agent-Harnesses)
|
|
16
|
+
|
|
17
|
+
`rpi` is a library-first coding-agent runtime written in Rust, plus a terminal
|
|
18
|
+
agent built on top of it. Eleven composable crates span provider adapters, a
|
|
19
|
+
durable crash-resumable agent loop, a reusable runtime, a terminal UI, and a
|
|
20
|
+
stable plugin ABI — so the same code works as an embedded SDK or as a ready-to-run
|
|
21
|
+
`rpi` command.
|
|
22
|
+
|
|
23
|
+
rpi began as a Rust reimplementation of the [Pi TypeScript SDK](https://github.com/earendil-works/pi)
|
|
24
|
+
by Mario Zechner. It now includes its own Rust-native plugin ABI and execution
|
|
25
|
+
infrastructure. See [Acknowledgements](#acknowledgements) and [NOTICE](NOTICE)
|
|
26
|
+
for upstream attribution.
|
|
27
|
+
|
|
28
|
+
[Website](https://rpi.bigfisharc.cn/) · [Docs](https://rpi.bigfisharc.cn/docs.html) · [Extension catalog](https://rpi.bigfisharc.cn/packages.html) · [rpi-package](https://github.com/pi-rust/rpi-package)
|
|
29
|
+
|
|
30
|
+
## See it in action
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
<sub>Interactive TUI, recorded with an isolated configuration. See the [user guide](docs/guides/user-guide.md) for the full command surface.</sub>
|
|
35
|
+
|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
<sub>Open the terminal agent and explore `/help`, with no real API key or model request. Recording script: [`demo/tui.tape`](demo/tui.tape).</sub>
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
<sub>The agent loop and a real `write` tool round-trip, recorded with no API key and no network — the same path the tests take. Source of truth is [`demo/sdk.tape`](demo/sdk.tape); regenerate with `task demo`.</sub>
|
|
43
|
+
|
|
44
|
+
## Three ways to use it
|
|
45
|
+
|
|
46
|
+
| You want | Depend on | Start at |
|
|
47
|
+
| -------- | --------- | -------- |
|
|
48
|
+
| A working terminal coding agent | nothing | `cargo install rpi-cli` |
|
|
49
|
+
| Your own agent inside your process | `rpi-agent` (+ `rpi-ai`, `rpi-tools`) | [`examples/minimal`](examples/minimal) |
|
|
50
|
+
| A tool/provider that extends every session | `rpi-plugin-sdk` | [`examples/plugin-stub`](examples/plugin-stub) |
|
|
51
|
+
|
|
52
|
+
The three share one implementation. Build your tools once, debug them inside an
|
|
53
|
+
embedded agent, and ship the same code as a `cdylib` plugin that the global `rpi`
|
|
54
|
+
loads. See [`docs/agent/project-structure.md`](docs/agent/project-structure.md) for the recommended
|
|
55
|
+
project layout.
|
|
56
|
+
|
|
57
|
+
## Install
|
|
58
|
+
|
|
59
|
+
**Prebuilt binary** (no Rust toolchain needed):
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
curl -fsSL https://raw.githubusercontent.com/bigfish1913/pi-rust/main/scripts/install.sh | sh
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Verifies the published SHA-256 checksum and installs to `/usr/local/bin` or
|
|
66
|
+
`~/.local/bin`. Preview first with `--dry-run`.
|
|
67
|
+
|
|
68
|
+
On **Windows (x64)**, run in PowerShell 5.1 or later:
|
|
69
|
+
|
|
70
|
+
```powershell
|
|
71
|
+
& ([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing https://raw.githubusercontent.com/bigfish1913/pi-rust/main/scripts/install.ps1).Content))
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Verifies the published SHA-256 checksum and installs to
|
|
75
|
+
`$env:LOCALAPPDATA\Programs\rpi`. Follow the printed instructions to add it to
|
|
76
|
+
PATH, then run `rpi --version`. Append `-DryRun` to preview, or use
|
|
77
|
+
`-Version <version>` and `-Dir 'C:\Tools\rpi'` to select a version and directory.
|
|
78
|
+
|
|
79
|
+
**From npm** (requires Node.js 20+; no Rust toolchain needed):
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm install -g @bigfishnpm/rpi
|
|
83
|
+
rpi --version
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The npm installer downloads the matching GitHub Release binary and verifies both
|
|
87
|
+
archive and executable SHA-256 checksums pinned in the package. It supports macOS
|
|
88
|
+
(x64/ARM64), Windows (x64), and Linux (x64 glibc/musl and ARM64 glibc).
|
|
89
|
+
|
|
90
|
+
**From crates.io** (requires Rust 1.88+):
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
cargo install rpi-cli
|
|
94
|
+
rpi --version
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Package managers:**
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
brew tap bigfish1913/tap && brew install rpi # macOS (Apple silicon), Linux
|
|
101
|
+
scoop bucket add bigfish1913 https://github.com/bigfish1913/scoop-bucket
|
|
102
|
+
scoop install rpi # Windows
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The Homebrew formula currently supports Apple silicon on macOS. Intel Macs can
|
|
106
|
+
use the prebuilt installer for releases with an `x86_64-apple-darwin` asset, or
|
|
107
|
+
`cargo install rpi-cli`. A winget manifest is [open for
|
|
108
|
+
review](https://github.com/microsoft/winget-pkgs/pull/444745).
|
|
109
|
+
|
|
110
|
+
**From source:**
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
git clone https://github.com/bigfish1913/pi-rust.git
|
|
114
|
+
cd pi-rust && cargo run -p minimal # offline agent, no API key required
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Real output of the two offline examples — no credentials, no network, identical
|
|
118
|
+
bytes every run. Regenerate with `task demo-transcript`:
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
$ cargo run -q -p minimal
|
|
122
|
+
minimal example: 2 messages after run
|
|
123
|
+
- user
|
|
124
|
+
- assistant
|
|
125
|
+
assistant reply: Hello from the faux provider!
|
|
126
|
+
AgentEnd observed.
|
|
127
|
+
|
|
128
|
+
$ cargo run -q -p tools-example
|
|
129
|
+
tools example: 4 messages after run
|
|
130
|
+
wrote out.txt (28 bytes): "hello from the tools example"
|
|
131
|
+
AgentEnd observed; tool ran against OsExecutionEnv.
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Quick start
|
|
135
|
+
|
|
136
|
+
### The CLI
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
export ANTHROPIC_API_KEY=... # or OPENAI_API_KEY, or ~/.rpi/agent/models.json
|
|
140
|
+
rpi # interactive TUI
|
|
141
|
+
rpi -p "summarize the README" # one-shot
|
|
142
|
+
rpi --mode json -p "list the crates" # machine-readable event stream
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Sessions persist as JSONL and survive a crash mid-run; `rpi` resumes from the
|
|
146
|
+
last committed frame rather than replaying the turn. Custom Anthropic or
|
|
147
|
+
OpenAI-compatible gateways are declared in `~/.rpi/agent/models.json` and
|
|
148
|
+
selected with `--model <provider>/<model>`.
|
|
149
|
+
|
|
150
|
+
### Runtime diagnostics
|
|
151
|
+
|
|
152
|
+
To investigate slow model preparation, context construction, tool execution, or
|
|
153
|
+
persistent assistant-frame writes, temporarily enable stderr diagnostics:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
RPI_AGENT_DIAGNOSTICS=1 RPI_FRAME_DIAGNOSTICS=1 \
|
|
157
|
+
rpi -p "reproduce the issue" 2>rpi-diagnostics.log
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`RPI_AGENT_DIAGNOSTICS` reports context, request, tool, and session append
|
|
161
|
+
latencies. `RPI_FRAME_DIAGNOSTICS` reports durable frame batching, flush barriers,
|
|
162
|
+
and writer failures. Diagnostics are disabled when the variables are unset or
|
|
163
|
+
set to `0`; they do not change the JSONL format. See
|
|
164
|
+
[`docs/debugging/rust-debugging.md`](docs/debugging/rust-debugging.md) for the
|
|
165
|
+
field reference. The built-in read-only `docs` tool can retrieve it with
|
|
166
|
+
`{"topic":"debugging","query":"RPI_FRAME_DIAGNOSTICS"}`.
|
|
167
|
+
|
|
168
|
+
### Request timeouts and model compatibility
|
|
169
|
+
|
|
170
|
+
`--timeout 600` limits a whole LLM request, including its streamed response.
|
|
171
|
+
`--stream-idle-timeout 300` independently limits silence between response body
|
|
172
|
+
bytes after the response starts. Every non-empty chunk resets the idle timer,
|
|
173
|
+
including SSE keepalives and partial frames. A stalled stream produces a
|
|
174
|
+
retryable error; the configured retry policy controls whether it is retried.
|
|
175
|
+
Healthy streams may run longer than the idle timeout, up to the total deadline.
|
|
176
|
+
Use `--stream-idle-timeout 0` to disable the idle timer. You can also set
|
|
177
|
+
`"streamIdleTimeout": 300` (seconds) in `~/.rpi/agent/settings.json`; the CLI flag
|
|
178
|
+
takes precedence. `httpIdleTimeout` only expires unused pooled connections and
|
|
179
|
+
does not control an active response.
|
|
180
|
+
|
|
181
|
+
For providers with `"api": "openai-completions"`, put compatibility flags in
|
|
182
|
+
each model's `compat` object in `~/.rpi/agent/models.json`, for example:
|
|
183
|
+
|
|
184
|
+
```json
|
|
185
|
+
"compat": {
|
|
186
|
+
"thinkingFormat": "deepseek",
|
|
187
|
+
"requiresReasoningContent": true
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`requiresReasoningContent` replays assistant thinking in `reasoning_content`,
|
|
192
|
+
including an empty string for assistant messages without thinking. The pi name
|
|
193
|
+
`requiresReasoningContentOnAssistantMessages` is accepted as an alias; if both
|
|
194
|
+
are present, the rpi spelling wins and conflicting values produce a warning.
|
|
195
|
+
`thinkingFormat` supports `"openai"` (the default request
|
|
196
|
+
shape) and `"deepseek"` (also sends `thinking: { "type": "enabled" | "disabled" }`
|
|
197
|
+
for reasoning-capable models). `supportsReasoningEffort: false` suppresses
|
|
198
|
+
`reasoning_effort` if the gateway does not accept it. `requiresThinkingAsText`
|
|
199
|
+
instead places thinking in ordinary text content. Unknown compat fields and
|
|
200
|
+
invalid values produce warnings naming the provider and model; invalid compat
|
|
201
|
+
objects are ignored. Other pi thinking formats are not currently supported.
|
|
202
|
+
|
|
203
|
+
### The SDK
|
|
204
|
+
|
|
205
|
+
Build an agent against a deterministic in-process provider — no API key, no
|
|
206
|
+
network, no flakiness:
|
|
207
|
+
|
|
208
|
+
```rust
|
|
209
|
+
use rpi_agent::AgentBuilder;
|
|
210
|
+
use rpi_ai::providers::faux::{FauxProvider, FauxScript};
|
|
211
|
+
use rpi_ai::Provider;
|
|
212
|
+
|
|
213
|
+
#[tokio::main]
|
|
214
|
+
async fn main() {
|
|
215
|
+
// `FauxProvider::new` already returns an `Arc<Self>`.
|
|
216
|
+
let provider = FauxProvider::new(FauxScript::new().with_text("Hello from the faux provider!"));
|
|
217
|
+
let model = provider.default_model().clone();
|
|
218
|
+
|
|
219
|
+
let agent = AgentBuilder::new()
|
|
220
|
+
.model(model)
|
|
221
|
+
.system_prompt("You are a helpful assistant.")
|
|
222
|
+
.stream_fn(make_stream_fn(provider))
|
|
223
|
+
.build()
|
|
224
|
+
.expect("agent builds");
|
|
225
|
+
|
|
226
|
+
let mut events = agent.subscribe();
|
|
227
|
+
agent.prompt("hi").await.expect("prompt completes");
|
|
228
|
+
|
|
229
|
+
while let Ok(ev) = events.try_recv() {
|
|
230
|
+
let _ = ev; // AgentEvent::{MessageUpdate, ToolEnd, AgentEnd, …}
|
|
231
|
+
}
|
|
232
|
+
println!("{} messages after the run", agent.state().messages.len());
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
`make_stream_fn` bridges the synchronous `StreamFn` contract to the async
|
|
237
|
+
provider — the full version is in [`examples/minimal/src/main.rs`](examples/minimal/src/main.rs)
|
|
238
|
+
(`cargo run -p minimal`).
|
|
239
|
+
|
|
240
|
+
## Crates
|
|
241
|
+
|
|
242
|
+
Eleven workspace crates, one shared version. Dependency direction is one-way
|
|
243
|
+
and enforced in review:
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
rpi-telemetry → rpi-ai → rpi-agent → rpi-tools → rpi-harness
|
|
247
|
+
↘ rpi-runtime
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Six crates sit outside that chain:
|
|
251
|
+
|
|
252
|
+
- `rpi-durable` provides backend-independent checkpoint validation and progress
|
|
253
|
+
projection for `rpi-harness`; it has no `rpi-*` dependencies. It is a native
|
|
254
|
+
library, distinct from the workflow extension of the same name.
|
|
255
|
+
- `rpi-tui` depends on no other `rpi-*` crate.
|
|
256
|
+
- `rpi-runtime` depends on `rpi-ai` and provides embeddable model catalogs,
|
|
257
|
+
credential resolution and execution bindings. See the
|
|
258
|
+
[runtime guide](docs/architecture/reusable-runtime.md).
|
|
259
|
+
- `rpi-plugin-sdk` is a leaf too (it has no `rpi-*` deps), but it is not only
|
|
260
|
+
the host's plugin contract: `rpi-tools` also reads its env-var names, so the
|
|
261
|
+
host and its plugins cannot disagree about the strings they exchange across
|
|
262
|
+
the ABI. That edge is names-only — nothing is linked or called.
|
|
263
|
+
- `rpi-extensions` is `rpi-plugin-sdk` plus `rpi-ai`/`rpi-agent`, since it hosts
|
|
264
|
+
plugins that run tools.
|
|
265
|
+
- `rpi-cli` brings together the TUI, the harness and the plugin loader, with
|
|
266
|
+
`rpi-durable` included through `rpi-harness`.
|
|
267
|
+
|
|
268
|
+
| Crate | What it is |
|
|
269
|
+
| ----- | ---------- |
|
|
270
|
+
| [`rpi-telemetry`](https://crates.io/crates/rpi-telemetry) | Span/event contracts with a no-op default — instrumentation is opt-in, and pulls in no tracing or OpenTelemetry backend |
|
|
271
|
+
| [`rpi-ai`](https://crates.io/crates/rpi-ai) | Provider-agnostic message, streaming and tool-schema types; Anthropic + OpenAI-compatible + `faux` providers |
|
|
272
|
+
| [`rpi-runtime`](https://crates.io/crates/rpi-runtime) | Embeddable model catalog, credential resolution, model selection and execution bindings |
|
|
273
|
+
| [`rpi-agent`](https://crates.io/crates/rpi-agent) | The agent loop: `AgentTool`, events, hooks, queues, cancellation |
|
|
274
|
+
| [`rpi-tools`](https://crates.io/crates/rpi-tools) | `read`/`write`/`edit`/`bash` (+ `grep`, `find`, `ls`, `powershell`) and the `ExecutionEnv` seam |
|
|
275
|
+
| [`rpi-durable`](crates/rpi-durable) | Backend-independent checkpoint validation and assistant-progress projection; no tool execution or storage backend |
|
|
276
|
+
| [`rpi-harness`](https://crates.io/crates/rpi-harness) | Session tree, JSONL persistence, compaction, crash recovery, the run loop |
|
|
277
|
+
| [`rpi-tui`](https://crates.io/crates/rpi-tui) | Terminal UI primitives: components, layout, editor, transcript rendering |
|
|
278
|
+
| [`rpi-cli`](https://crates.io/crates/rpi-cli) | The `rpi` binary: TUI, one-shot and JSON modes, config, plugin loading |
|
|
279
|
+
| [`rpi-plugin-sdk`](https://crates.io/crates/rpi-plugin-sdk) | The stable `#[repr(C)]` ABI contract for plugins. No `rpi-*` deps; only `serde_json`, behind a default `json` feature that can be turned off |
|
|
280
|
+
| [`rpi-extensions`](https://crates.io/crates/rpi-extensions) | Host-side plugin loader and the async-across-ABI tool bridge |
|
|
281
|
+
|
|
282
|
+
Every crate has its own README and docs.rs page. The `crates/rpi-*`
|
|
283
|
+
directories and the published crate names use the same `rpi-` prefix.
|
|
284
|
+
|
|
285
|
+
## Why rpi
|
|
286
|
+
|
|
287
|
+
Most coding agents are CLIs. `rpi` is a **runtime with a CLI attached**, which
|
|
288
|
+
changes what you can build with it:
|
|
289
|
+
|
|
290
|
+
- **Embeddable.** The agent loop is a library. `rpi-agent` + `rpi-ai` is enough
|
|
291
|
+
to run an agent inside your own process, with your own event handling and
|
|
292
|
+
output — no shelling out to a tool and scraping stdout.
|
|
293
|
+
- **Testable offline.** A deterministic `faux` provider and an in-memory
|
|
294
|
+
execution environment are first-class, not mocks bolted on. `rpi-ai` puts its
|
|
295
|
+
real HTTP providers behind a `providers` feature flag, so your test suite
|
|
296
|
+
cannot silently depend on the network for the paths you exercise.
|
|
297
|
+
- **Durable.** Sessions are a tree with JSONL persistence and per-frame
|
|
298
|
+
progress. Recovery resumes from committed progress; it does not guarantee
|
|
299
|
+
exactly-once external side effects. Tools still need appropriate idempotency
|
|
300
|
+
and recovery checks.
|
|
301
|
+
- **Extensible across a stable boundary.** Plugins are Rust `cdylib`s behind a
|
|
302
|
+
hand-written, panic-contained C ABI with version negotiation — the ABI
|
|
303
|
+
survives compiler and crate version skew, so extensions do not break on every
|
|
304
|
+
release.
|
|
305
|
+
- **One implementation, two surfaces.** The global CLI and an embedded agent load
|
|
306
|
+
the same tools. You do not maintain a plugin and a library variant separately.
|
|
307
|
+
|
|
308
|
+
### How it compares
|
|
309
|
+
|
|
310
|
+
Structural differences against other terminal coding agents. Facts about other
|
|
311
|
+
tools are as of 2026-09 and change often — check their documentation; only the
|
|
312
|
+
`rpi` column is maintained here.
|
|
313
|
+
|
|
314
|
+
| | rpi | Claude Code | Codex CLI | opencode | aider |
|
|
315
|
+
| --- | --- | --- | --- | --- | --- |
|
|
316
|
+
| Language | Rust | TypeScript | Rust | TypeScript/Go | Python |
|
|
317
|
+
| Source available | ✅ MIT | ❌ | ✅ | ✅ | ✅ |
|
|
318
|
+
| Usable as an embedded library | ✅ | ❌ | ❌ | ⚠️ | ⚠️ |
|
|
319
|
+
| First-class plugin ABI | ✅ | hooks/MCP | ❌ | plugin API | ❌ |
|
|
320
|
+
| Headless server + remote client | ✅ | ⚠️ | ✅ | ✅ | ⚠️ |
|
|
321
|
+
| Provider-agnostic gateways | ✅ | ❌ | ❌ | ✅ | ✅ |
|
|
322
|
+
|
|
323
|
+
If you want the most polished single-vendor experience, use the vendor's tool.
|
|
324
|
+
`rpi` is for people who want to own the loop.
|
|
325
|
+
|
|
326
|
+
rpi is listed in [Best of Agent Harnesses](https://github.com/RyanAlberts/best-of-Agent-Harnesses)
|
|
327
|
+
under *Coding agent products*, scored **bounded** and **durable** — the durable
|
|
328
|
+
score comes from the crash-resumable JSONL sessions.
|
|
329
|
+
|
|
330
|
+
## Performance
|
|
331
|
+
|
|
332
|
+
Measured on Windows 11 (x86_64), rustc 1.97.1, `--release`. Both scripts
|
|
333
|
+
rebuild and re-measure on your own machine.
|
|
334
|
+
|
|
335
|
+
`sh scripts/bench.sh` — standalone numbers:
|
|
336
|
+
|
|
337
|
+
| Metric | Value |
|
|
338
|
+
| ------ | ----- |
|
|
339
|
+
| Release binary size | **21.8 MiB** |
|
|
340
|
+
| `rpi --version` wall time | **~17 ms** median |
|
|
341
|
+
| RSS once the agent is ready | **12.0 MiB** |
|
|
342
|
+
|
|
343
|
+
`node scripts/bench-vs-pi.mjs --pi <path-to-pi>` — against native Pi on the same
|
|
344
|
+
machine, both offline, each with a fresh isolated config directory:
|
|
345
|
+
|
|
346
|
+
| Metric | rpi (Rust) | pi (TypeScript) | Difference |
|
|
347
|
+
| ------ | ---------: | --------------: | ---------- |
|
|
348
|
+
| `--version` | **17.5 ms** | 169.5 ms | **9.7× faster** |
|
|
349
|
+
| Cold start | **17.7 ms** | 189.5 ms | **10.7× faster** |
|
|
350
|
+
| RSS at ready | **12.0 MiB** | 91.5 MiB | **7.6× smaller** |
|
|
351
|
+
| Install footprint | **21.8 MiB** (one binary) | ~385 MiB (+ ~91 MiB Node) | **~18–22× smaller** |
|
|
352
|
+
|
|
353
|
+
**Cold start** is spawn → the agent answering its first command: process creation
|
|
354
|
+
plus full initialisation, excluding teardown and any LLM work. rpi's `--version`
|
|
355
|
+
(17.5 ms) and cold start (17.7 ms) are effectively equal, so startup is process
|
|
356
|
+
creation, not initialisation; Pi is dominated by Node boot.
|
|
357
|
+
|
|
358
|
+
Isolation caveat: rpi reads `RPI_CODING_AGENT_DIR` / `RPI_OFFLINE`, native Pi reads
|
|
359
|
+
`PI_CODING_AGENT_DIR` / `PI_OFFLINE`. Set the matching pair for each, or rpi
|
|
360
|
+
silently loads the machine's global plugins.
|
|
361
|
+
|
|
362
|
+
Method, raw per-run numbers, and what is *not* measured (LLM latency, tool-loop
|
|
363
|
+
throughput, long sessions, TUI frame cost) are in
|
|
364
|
+
[`docs/performance/benchmark-vs-pi.md`](docs/performance/benchmark-vs-pi.md).
|
|
365
|
+
|
|
366
|
+
## Plugins
|
|
367
|
+
|
|
368
|
+
Plugins are Rust `cdylib` libraries behind a stable `#[repr(C)]` ABI. A plugin
|
|
369
|
+
can register tools, providers, slash commands, event handlers, markdown
|
|
370
|
+
renderers and discovered resources.
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
rpi install rpi-todo # prebuilt extension; no Rust toolchain needed
|
|
374
|
+
rpi install my-ext --path ../my-ext # local, for development
|
|
375
|
+
rpi extension update [name] # all eligible extensions, or one by name
|
|
376
|
+
rpi dev # build + watch + live reload
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Use `rpi extension update` to update all project-linked extensions and globally
|
|
380
|
+
installed registry/prebuilt extensions, or `rpi extension update <name>` to select
|
|
381
|
+
one by name. Updates preserve the original Cargo build backend or explicit GitHub
|
|
382
|
+
source. Global development installs made with `--path` are excluded. The old
|
|
383
|
+
`rpi package update [name]` remains compatible; prefer `extension update` for
|
|
384
|
+
extension updates. Project linking commands remain `rpi package link`,
|
|
385
|
+
`rpi package list`, and `rpi package unlink`.
|
|
386
|
+
|
|
387
|
+
The host loads project `.rpi/extensions`, then global
|
|
388
|
+
`~/.rpi/agent/extensions`, then any `--extensions-dir`.
|
|
389
|
+
|
|
390
|
+
For a new Rust plugin, start with [`docs/extensions/authoring.md`](docs/extensions/authoring.md)
|
|
391
|
+
and `examples/plugin-stub`. Use `rpi-plugin-sdk` for the `cdylib` ABI. If the plugin
|
|
392
|
+
project also needs reusable session, workspace, native RPC or durable-runtime logic
|
|
393
|
+
for a Web/ACP adapter, add [`rpi-extcore`](https://crates.io/crates/rpi-extcore)
|
|
394
|
+
(`rpi-extcore = "0.1"`). It is a normal Rust library, not the `cdylib` entry point,
|
|
395
|
+
and it does not replace `rpi-plugin-sdk`; a simple tool plugin should not add it
|
|
396
|
+
unnecessarily.
|
|
397
|
+
|
|
398
|
+
Ready-to-install extensions live in the companion
|
|
399
|
+
[`pi-rust/rpi-package`](https://github.com/pi-rust/rpi-package) repository, with
|
|
400
|
+
an [online catalog](https://rpi.bigfisharc.cn/packages.html).
|
|
401
|
+
|
|
402
|
+
Browse the catalog for install commands, or open the
|
|
403
|
+
[`packages/` source directory](https://github.com/pi-rust/rpi-package/tree/main/packages)
|
|
404
|
+
for extension READMEs and examples. Start with `rpi install rpi-todo` above,
|
|
405
|
+
then use the [extension authoring guide](docs/extensions/authoring.md) to build your own.
|
|
406
|
+
|
|
407
|
+
### Web access
|
|
408
|
+
|
|
409
|
+
Web access is optional, not part of the CLI's default tool set:
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
rpi install rpi-websearch # websearch: titles, URLs and snippets
|
|
413
|
+
rpi install rpi-webfetch # webfetch: readable text from public pages
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
Restart rpi after installation to load the tools. These extensions do not
|
|
417
|
+
provide an interactive browser: clicking, login flows and page JavaScript
|
|
418
|
+
execution require separate browser tooling.
|
|
419
|
+
|
|
420
|
+
### Subagents with inherited configuration
|
|
421
|
+
|
|
422
|
+
Install the companion `rpi-subagents` extension to expose `delegate_task`:
|
|
423
|
+
|
|
424
|
+
```bash
|
|
425
|
+
rpi install rpi-subagents
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
The host snapshots the parent's effective model/provider binding, thinking
|
|
429
|
+
level, system prompt, resources, request options, active tools, project cwd and
|
|
430
|
+
approval hooks. It does not reconstruct CLI defaults or pass credentials through
|
|
431
|
+
plugin JSON. Each child runs in a separate in-memory session without copying or
|
|
432
|
+
modifying the parent's conversation history.
|
|
433
|
+
|
|
434
|
+
The host API can narrow the inherited tool set, never expand it; `delegate_task`
|
|
435
|
+
is excluded and recursive delegation is rejected. Approvals use the parent's UI,
|
|
436
|
+
and parent completion or cancellation stops the child. This is capability
|
|
437
|
+
inheritance and session isolation, not an OS sandbox.
|
|
438
|
+
|
|
439
|
+
Use a compatible host and subagent extension; unsupported hosts fail explicitly
|
|
440
|
+
rather than falling back to a differently configured subprocess. The SDK entry
|
|
441
|
+
point is `AgentHarness::create_child`; extensions use `GetExecutionContext` and
|
|
442
|
+
`ChildAgent` runtime actions. See the [subagent protocol](docs/extensions/subagents.md)
|
|
443
|
+
for lifecycle, limits and compatibility details.
|
|
444
|
+
|
|
445
|
+
### Authoring an extension
|
|
446
|
+
|
|
447
|
+
```rust
|
|
448
|
+
use rpi_plugin_sdk::{export_plugin, StbStringRef};
|
|
449
|
+
|
|
450
|
+
export_plugin!(|api| {
|
|
451
|
+
if let Some(declare) = api.declare {
|
|
452
|
+
declare(StbStringRef::from_str(r#"{"priority":60,"platforms":["linux"]}"#));
|
|
453
|
+
}
|
|
454
|
+
// register tools / handlers through `api`
|
|
455
|
+
0
|
|
456
|
+
});
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
Start from [`examples/plugin-stub`](examples/plugin-stub) — a complete plugin
|
|
460
|
+
with the full `execute`→`poll`→`cancel`→`destroy` lifecycle — and read
|
|
461
|
+
[`docs/extensions/authoring.md`](docs/extensions/authoring.md) for the safety
|
|
462
|
+
rules, which are load-bearing rather than stylistic.
|
|
463
|
+
|
|
464
|
+
## Remote mode
|
|
465
|
+
|
|
466
|
+
```bash
|
|
467
|
+
rpi --server # headless agent over TCP, prints an auth token
|
|
468
|
+
rpi --connect host:port --token T # TUI client with zero local agent resources
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
The client holds no provider, tools, extensions or session files — all agent
|
|
472
|
+
work happens on the server, so a thin terminal anywhere can drive a beefy
|
|
473
|
+
machine. See [`docs/remote/user-guide.md`](docs/remote/user-guide.md).
|
|
474
|
+
|
|
475
|
+
## Project status
|
|
476
|
+
|
|
477
|
+
| | |
|
|
478
|
+
| --- | --- |
|
|
479
|
+
| Current release | **[0.22.1](https://github.com/bigfish1913/pi-rust/releases)** (eleven workspace crates, one shared version) |
|
|
480
|
+
| Stability | `rpi-ai`, `rpi-agent`, `rpi-tools`, `rpi-harness`, `rpi-plugin-sdk` are the intended stable surface |
|
|
481
|
+
| MSRV | 1.88 |
|
|
482
|
+
| Platforms | Linux (GNU and musl), macOS, Windows (CI runs the suite on Linux) |
|
|
483
|
+
| Binary release targets | Linux (x86_64 GNU/musl, aarch64 GNU), macOS (Intel/Apple silicon), Windows (x86_64) |
|
|
484
|
+
|
|
485
|
+
`rpi` is a self-contained Rust coding-agent stack. No Node component is
|
|
486
|
+
required and none is loaded.
|
|
487
|
+
|
|
488
|
+
## Documentation
|
|
489
|
+
|
|
490
|
+
Start with the [documentation index](docs/README.md), grouped by feature.
|
|
491
|
+
|
|
492
|
+
- [User guide](docs/guides/user-guide.md) — commands, config, sessions, skills
|
|
493
|
+
- [Architecture](docs/architecture/overview.md) — how the crates fit together and why
|
|
494
|
+
- [Building an agent project](docs/agent/project-structure.md) — recommended structure
|
|
495
|
+
- [Extension authoring](docs/extensions/authoring.md) — plugin templates and ABI rules
|
|
496
|
+
- [Subagents](docs/extensions/subagents.md) — configuration inheritance, permissions and lifecycle
|
|
497
|
+
- [Native RPC resource selection](docs/resource-selection-rpc.md) — exact startup Packages, Skills, extensions, instructions and tools (stage A)
|
|
498
|
+
- [Local native resource management](docs/local-resource-management.md) — scoped snapshot install/inspect/update/remove, ownership, recovery and host leases (stage B)
|
|
499
|
+
- [Remote mode](docs/remote/user-guide.md) — protocol, tokens, limitations
|
|
500
|
+
- [Roadmap](ROADMAP.md) · [Changelog](CHANGELOG.md)
|
|
501
|
+
- [docs.rs](https://docs.rs/rpi-cli) for per-crate API docs
|
|
502
|
+
|
|
503
|
+
## Contributing
|
|
504
|
+
|
|
505
|
+
Issues and PRs are welcome. Start with [CONTRIBUTING.md](CONTRIBUTING.md) for the
|
|
506
|
+
build/test commands and the repository layout, and the
|
|
507
|
+
[roadmap](ROADMAP.md) for what is already planned. Security problems should go
|
|
508
|
+
through [SECURITY.md](SECURITY.md), not a public issue.
|
|
509
|
+
|
|
510
|
+
The whole test suite runs offline: `cargo test --workspace --locked`.
|
|
511
|
+
|
|
512
|
+
## Acknowledgements
|
|
513
|
+
|
|
514
|
+
Thank you to Mario Zechner and the [Pi contributors](https://github.com/earendil-works/pi)
|
|
515
|
+
for the original TypeScript SDK and the agent, tool and session designs that
|
|
516
|
+
formed rpi's starting point. rpi reimplements that foundation in Rust and adds
|
|
517
|
+
its own runtime and extension infrastructure; it does not load the TypeScript
|
|
518
|
+
SDK or its npm extensions. Upstream copyright and MIT license notices are
|
|
519
|
+
retained in [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
520
|
+
|
|
521
|
+
## License
|
|
522
|
+
|
|
523
|
+
MIT. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
524
|
+
|
|
525
|
+
The `rpi-*` crates are a Rust-native coding-agent stack.
|
|
526
|
+
|
|
527
|
+
## Support / 赞赏支持
|
|
528
|
+
|
|
529
|
+
If rpi helps you, consider buying the author a coffee. Donations support
|
|
530
|
+
continued development and maintenance. Thank you!
|
|
531
|
+
|
|
532
|
+
如果 rpi 帮到了你,欢迎请作者喝杯咖啡,支持持续开发与维护。感谢每一份支持!
|
|
533
|
+
|
|
534
|
+
<table>
|
|
535
|
+
<tr>
|
|
536
|
+
<th>微信支付 / WeChat Pay</th>
|
|
537
|
+
<th>支付宝 / Alipay</th>
|
|
538
|
+
<th>Binance Pay</th>
|
|
539
|
+
</tr>
|
|
540
|
+
<tr>
|
|
541
|
+
<td align="center"><a href="https://assets.bigfisharc.cn/images/support/wechat.png"><img src="https://assets.bigfisharc.cn/images/support/wechat.png" width="200" alt="微信支付赞赏码 / WeChat Pay donation QR code"></a></td>
|
|
542
|
+
<td align="center"><a href="https://assets.bigfisharc.cn/images/support/alipay.jpg"><img src="https://assets.bigfisharc.cn/images/support/alipay.jpg" width="200" alt="支付宝赞赏码 / Alipay donation QR code"></a></td>
|
|
543
|
+
<td align="center"><a href="https://assets.bigfisharc.cn/images/support/binance.png"><img src="https://assets.bigfisharc.cn/images/support/binance.png" width="200" alt="Binance Pay donation QR code"></a></td>
|
|
544
|
+
</tr>
|
|
545
|
+
</table>
|
|
546
|
+
|
|
547
|
+
Scan a code or click an image to view the original. On mobile, save the image
|
|
548
|
+
and scan it from the matching app’s photo library.
|
|
549
|
+
|
|
550
|
+
扫码或点击图片查看原图;手机上可保存图片后,在对应 App 中识别。
|
|
551
|
+
|
|
552
|
+
## Community / 交流群
|
|
553
|
+
|
|
554
|
+
Join us to ask questions, share ideas and try early builds.
|
|
555
|
+
欢迎交流使用问题、分享想法和体验新功能。
|
|
556
|
+
|
|
557
|
+
<table>
|
|
558
|
+
<tr>
|
|
559
|
+
<td align="center" width="50%">
|
|
560
|
+
<a href="https://assets.bigfisharc.cn/images/support/weixin.png?date=2026-11-09"><img src="https://assets.bigfisharc.cn/images/support/weixin.png?date=2026-11-09" width="230" alt="微信交流群二维码 / WeChat group QR code"></a><br>
|
|
561
|
+
<sub><b>WeChat / 微信交流群</b> — 扫码加入 / Scan to join</sub>
|
|
562
|
+
</td>
|
|
563
|
+
<td align="center" width="50%">
|
|
564
|
+
<a href="https://t.me/+7YfN4TZPP7Y0M2Q1"><img src="https://assets.bigfisharc.cn/images/support/tg.png" width="230" alt="Telegram group QR code"></a><br>
|
|
565
|
+
<sub><b>Telegram</b> — <a href="https://t.me/+7YfN4TZPP7Y0M2Q1">t.me/+7YfN4TZPP7Y0M2Q1</a></sub>
|
|
566
|
+
</td>
|
|
567
|
+
</tr>
|
|
568
|
+
</table>
|
|
569
|
+
|
|
570
|
+
<sub>The WeChat image URL is refreshed daily with a date parameter (UTC+8) by
|
|
571
|
+
<a href=".github/workflows/readme-images.yml">README image refresh</a> to avoid stale cached
|
|
572
|
+
images. This does not renew the group invitation itself; if it expires, please
|
|
573
|
+
open an issue. / 微信群图片链接每日更新日期参数以刷新缓存;若入群邀请失效,请提 issue。</sub>
|
|
574
|
+
|
|
575
|
+
## Star history
|
|
576
|
+
|
|
577
|
+
[](https://www.star-history.com/#bigfish1913/pi-rust&pi-rust/rpi-package&Date)
|
|
578
|
+
|
|
579
|
+
## Contributors
|
|
580
|
+
|
|
581
|
+
Thank you to everyone who contributes code, documentation, bug reports and ideas.
|
|
582
|
+
感谢所有参与代码、文档、问题反馈和建议的贡献者!
|
|
583
|
+
|
|
584
|
+
[](https://github.com/bigfish1913/pi-rust/graphs/contributors)
|
|
585
|
+
|
|
586
|
+
[View the full contributor list](https://github.com/bigfish1913/pi-rust/graphs/contributors) · [How to contribute](CONTRIBUTING.md)
|
package/npm/bin/rpi.cjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { existsSync } = require('node:fs');
|
|
5
|
+
const { spawn } = require('node:child_process');
|
|
6
|
+
const { installedBinary } = require('../lib.cjs');
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const binary = installedBinary();
|
|
10
|
+
if (!existsSync(binary)) await require('../install.cjs').install();
|
|
11
|
+
const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit' });
|
|
12
|
+
const handlers = new Map();
|
|
13
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
14
|
+
const handler = () => { if (!child.killed) child.kill(signal); };
|
|
15
|
+
handlers.set(signal, handler);
|
|
16
|
+
process.on(signal, handler);
|
|
17
|
+
}
|
|
18
|
+
const cleanup = () => {
|
|
19
|
+
for (const [signal, handler] of handlers) process.removeListener(signal, handler);
|
|
20
|
+
};
|
|
21
|
+
child.on('error', error => {
|
|
22
|
+
cleanup();
|
|
23
|
+
console.error(`rpi: ${error.message}`);
|
|
24
|
+
process.exitCode = 1;
|
|
25
|
+
});
|
|
26
|
+
child.on('exit', (code, signal) => {
|
|
27
|
+
cleanup();
|
|
28
|
+
if (signal && process.platform !== 'win32') process.kill(process.pid, signal);
|
|
29
|
+
else process.exitCode = code ?? 1;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
main().catch(error => {
|
|
34
|
+
console.error(`rpi: ${error.message}`);
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
});
|
package/npm/install.cjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } = require('node:fs');
|
|
4
|
+
const { tmpdir } = require('node:os');
|
|
5
|
+
const { dirname, join } = require('node:path');
|
|
6
|
+
const { spawnSync } = require('node:child_process');
|
|
7
|
+
const { distributionFor, download, installedBinary, targetFor, verifyBinary, verifyHash } = require('./lib.cjs');
|
|
8
|
+
|
|
9
|
+
async function install() {
|
|
10
|
+
const { version } = require('../package.json');
|
|
11
|
+
const manifest = JSON.parse(readFileSync(join(__dirname, 'release.json'), 'utf8'));
|
|
12
|
+
const target = targetFor();
|
|
13
|
+
const distribution = distributionFor(manifest, version, target);
|
|
14
|
+
const destination = installedBinary();
|
|
15
|
+
if (existsSync(destination)) {
|
|
16
|
+
try {
|
|
17
|
+
verifyBinary(destination, distribution);
|
|
18
|
+
return;
|
|
19
|
+
} catch {
|
|
20
|
+
// Replace an incomplete or outdated installation only after verification.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
console.error(`@bigfishnpm/rpi: downloading rpi ${version} (${target})...`);
|
|
24
|
+
const temporary = mkdtempSync(join(tmpdir(), 'pi-rust-'));
|
|
25
|
+
let staged;
|
|
26
|
+
try {
|
|
27
|
+
const archive = join(temporary, `release.${distribution.format}`);
|
|
28
|
+
const data = await download(distribution.url, distribution.size);
|
|
29
|
+
if (data.length !== distribution.size) throw new Error('Downloaded archive has the wrong size.');
|
|
30
|
+
verifyHash(data, distribution.sha256, 'release archive');
|
|
31
|
+
writeFileSync(archive, data);
|
|
32
|
+
let extraction;
|
|
33
|
+
if (process.platform === 'win32') {
|
|
34
|
+
// PowerShell is present on supported Windows hosts and handles ZIP files
|
|
35
|
+
// even when a GNU tar from Git happens to precede Windows tar on PATH.
|
|
36
|
+
extraction = spawnSync('powershell.exe', [
|
|
37
|
+
'-NoLogo', '-NoProfile', '-NonInteractive', '-Command',
|
|
38
|
+
'$ErrorActionPreference = "Stop"; Expand-Archive -LiteralPath $env:RPI_NPM_ARCHIVE -DestinationPath $env:RPI_NPM_EXTRACT',
|
|
39
|
+
], {
|
|
40
|
+
stdio: 'inherit',
|
|
41
|
+
env: { ...process.env, RPI_NPM_ARCHIVE: archive, RPI_NPM_EXTRACT: temporary },
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
extraction = spawnSync('tar', ['-xzf', archive, '-C', temporary, `./${distribution.binary.path}`], { stdio: 'inherit' });
|
|
45
|
+
}
|
|
46
|
+
if (extraction.error) throw extraction.error;
|
|
47
|
+
if (extraction.status !== 0) throw new Error('Could not extract the release archive.');
|
|
48
|
+
const extracted = join(temporary, distribution.binary.path);
|
|
49
|
+
verifyBinary(extracted, distribution);
|
|
50
|
+
chmodSync(extracted, 0o755);
|
|
51
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
52
|
+
staged = `${destination}.${process.pid}.tmp`;
|
|
53
|
+
copyFileSync(extracted, staged);
|
|
54
|
+
chmodSync(staged, 0o755);
|
|
55
|
+
renameSync(staged, destination);
|
|
56
|
+
} finally {
|
|
57
|
+
if (staged) rmSync(staged, { force: true });
|
|
58
|
+
rmSync(temporary, { recursive: true, force: true });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (require.main === module) {
|
|
63
|
+
install().catch(error => {
|
|
64
|
+
console.error(`@bigfishnpm/rpi: ${error.message}`);
|
|
65
|
+
process.exitCode = 1;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = { install };
|
package/npm/lib.cjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { createHash } = require('node:crypto');
|
|
4
|
+
const { readFileSync } = require('node:fs');
|
|
5
|
+
const { join } = require('node:path');
|
|
6
|
+
|
|
7
|
+
const repository = 'https://github.com/bigfish1913/pi-rust';
|
|
8
|
+
|
|
9
|
+
function targetFor(platform = process.platform, arch = process.arch, report) {
|
|
10
|
+
const targets = {
|
|
11
|
+
'darwin-arm64': 'aarch64-apple-darwin',
|
|
12
|
+
'darwin-x64': 'x86_64-apple-darwin',
|
|
13
|
+
'win32-x64': 'x86_64-pc-windows-msvc',
|
|
14
|
+
'linux-arm64': 'aarch64-unknown-linux-gnu',
|
|
15
|
+
'linux-x64': 'x86_64-unknown-linux-gnu',
|
|
16
|
+
};
|
|
17
|
+
let target = targets[`${platform}-${arch}`];
|
|
18
|
+
if (!target) throw new Error(`Unsupported platform: ${platform}/${arch}. See ${repository}#install.`);
|
|
19
|
+
if (platform === 'linux') {
|
|
20
|
+
report ??= process.report.getReport();
|
|
21
|
+
if (!report.header.glibcVersionRuntime) {
|
|
22
|
+
if (arch !== 'x64') throw new Error('Linux ARM64 requires glibc; no musl ARM64 binary is available.');
|
|
23
|
+
target = 'x86_64-unknown-linux-musl';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function distributionFor(manifest, version, target) {
|
|
30
|
+
if (manifest.schema_version !== 1 || manifest.name !== 'rpi-cli' ||
|
|
31
|
+
manifest.version !== version || manifest.tag !== `v${version}` ||
|
|
32
|
+
manifest.repository !== repository || !/^[a-f0-9]{40}$/.test(manifest.source_commit)) {
|
|
33
|
+
throw new Error('Release manifest does not match this package.');
|
|
34
|
+
}
|
|
35
|
+
const distribution = manifest.targets?.[target];
|
|
36
|
+
const windows = target.endsWith('-windows-msvc');
|
|
37
|
+
const format = windows ? 'zip' : 'tar.gz';
|
|
38
|
+
const binary = windows ? 'rpi.exe' : 'rpi';
|
|
39
|
+
const expectedUrl = `${repository}/releases/download/v${version}/rpi-v${version}-${target}.${format}`;
|
|
40
|
+
if (!distribution || distribution.url !== expectedUrl || distribution.format !== format ||
|
|
41
|
+
!Number.isSafeInteger(distribution.size) || distribution.size <= 0 || distribution.size > 256 * 1024 * 1024 ||
|
|
42
|
+
!/^[a-f0-9]{64}$/.test(distribution.sha256) || distribution.binary?.path !== binary ||
|
|
43
|
+
!/^[a-f0-9]{64}$/.test(distribution.binary.sha256)) {
|
|
44
|
+
throw new Error(`Invalid or missing release distribution for ${target}.`);
|
|
45
|
+
}
|
|
46
|
+
return distribution;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function verifyHash(data, expected, label) {
|
|
50
|
+
const actual = createHash('sha256').update(data).digest('hex');
|
|
51
|
+
if (actual !== expected) throw new Error(`SHA-256 mismatch for ${label}.`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function installedBinary() {
|
|
55
|
+
return join(__dirname, 'native', process.platform === 'win32' ? 'rpi.exe' : 'rpi');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function verifyBinary(path, distribution) {
|
|
59
|
+
verifyHash(readFileSync(path), distribution.binary.sha256, distribution.binary.path);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function download(url, limit, fetcher = fetch) {
|
|
63
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
64
|
+
try {
|
|
65
|
+
const response = await fetcher(url, { signal: AbortSignal.timeout(300_000) });
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
await response.body?.cancel();
|
|
68
|
+
const error = new Error(`Download failed (${response.status}): ${url}`);
|
|
69
|
+
error.retryable = response.status === 408 || response.status === 429 || response.status >= 500;
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
const chunks = [];
|
|
73
|
+
let size = 0;
|
|
74
|
+
for await (const chunk of response.body) {
|
|
75
|
+
size += chunk.length;
|
|
76
|
+
if (size > limit) {
|
|
77
|
+
const error = new Error(`Download exceeds expected size: ${url}`);
|
|
78
|
+
error.retryable = false;
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
chunks.push(chunk);
|
|
82
|
+
}
|
|
83
|
+
return Buffer.concat(chunks);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error.retryable === false || attempt === 3) throw error;
|
|
86
|
+
console.error(`rpi: download interrupted (${error.cause?.code ?? error.message}); retrying (${attempt}/3)...`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = { targetFor, distributionFor, verifyHash, installedBinary, verifyBinary, download };
|
package/npm/release.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema_version": 1,
|
|
3
|
+
"name": "rpi-cli",
|
|
4
|
+
"version": "0.22.1",
|
|
5
|
+
"repository": "https://github.com/bigfish1913/pi-rust",
|
|
6
|
+
"tag": "v0.22.1",
|
|
7
|
+
"source_commit": "f17841aaa7b761dcd59a13f98932de21d8bfef6d",
|
|
8
|
+
"targets": {
|
|
9
|
+
"aarch64-apple-darwin": {
|
|
10
|
+
"url": "https://github.com/bigfish1913/pi-rust/releases/download/v0.22.1/rpi-v0.22.1-aarch64-apple-darwin.tar.gz",
|
|
11
|
+
"format": "tar.gz",
|
|
12
|
+
"size": 15956412,
|
|
13
|
+
"sha256": "6ccc7ca18d06ca8325242cdefd7c3ef76d2810510dda5e2d5806e32785ebf797",
|
|
14
|
+
"binary": {
|
|
15
|
+
"path": "rpi",
|
|
16
|
+
"sha256": "3039809b55af7d6df63314a780537404a37d290b88e609e39761cbda37d7e0ce"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"aarch64-unknown-linux-gnu": {
|
|
20
|
+
"url": "https://github.com/bigfish1913/pi-rust/releases/download/v0.22.1/rpi-v0.22.1-aarch64-unknown-linux-gnu.tar.gz",
|
|
21
|
+
"format": "tar.gz",
|
|
22
|
+
"size": 16352576,
|
|
23
|
+
"sha256": "2e6384f65c2efcbf392290e5af610cff1a36da8b51e9352e4d65bb6f62b5bac3",
|
|
24
|
+
"binary": {
|
|
25
|
+
"path": "rpi",
|
|
26
|
+
"sha256": "0c7b4035ea1fe58267cbb35e2214166071b664c63b0f9e6a9b5a43e592c1a312"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"x86_64-apple-darwin": {
|
|
30
|
+
"url": "https://github.com/bigfish1913/pi-rust/releases/download/v0.22.1/rpi-v0.22.1-x86_64-apple-darwin.tar.gz",
|
|
31
|
+
"format": "tar.gz",
|
|
32
|
+
"size": 17018834,
|
|
33
|
+
"sha256": "debe216bd08c6f41a82876a3f15665be2ad79b599332dd735d8ec153bc0dc4e8",
|
|
34
|
+
"binary": {
|
|
35
|
+
"path": "rpi",
|
|
36
|
+
"sha256": "4972d51bf477d7dda42108e037e408ae73136a43f1a9a27a0429884faaf41c43"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"x86_64-pc-windows-msvc": {
|
|
40
|
+
"url": "https://github.com/bigfish1913/pi-rust/releases/download/v0.22.1/rpi-v0.22.1-x86_64-pc-windows-msvc.zip",
|
|
41
|
+
"format": "zip",
|
|
42
|
+
"size": 17010955,
|
|
43
|
+
"sha256": "f18885bcb64bd5045918c24f1406f9a64754a3789aff86b784df4706912df6e2",
|
|
44
|
+
"binary": {
|
|
45
|
+
"path": "rpi.exe",
|
|
46
|
+
"sha256": "05a21657392fd34eb57325d55748fb0760d067dc76061b258a31c85a30c6ad5e"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"x86_64-unknown-linux-gnu": {
|
|
50
|
+
"url": "https://github.com/bigfish1913/pi-rust/releases/download/v0.22.1/rpi-v0.22.1-x86_64-unknown-linux-gnu.tar.gz",
|
|
51
|
+
"format": "tar.gz",
|
|
52
|
+
"size": 17508453,
|
|
53
|
+
"sha256": "bdc9239cf090d6a9208b2b8fb70bf58f754965b5d66336a26017b8ea06c70d5c",
|
|
54
|
+
"binary": {
|
|
55
|
+
"path": "rpi",
|
|
56
|
+
"sha256": "286f2479cf553b9bffad997fcb68679aaa9e77fa8b6264f657692d84b87b9b21"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"x86_64-unknown-linux-musl": {
|
|
60
|
+
"url": "https://github.com/bigfish1913/pi-rust/releases/download/v0.22.1/rpi-v0.22.1-x86_64-unknown-linux-musl.tar.gz",
|
|
61
|
+
"format": "tar.gz",
|
|
62
|
+
"size": 17663903,
|
|
63
|
+
"sha256": "b5cb6e9715fb477f0360955b1b4a330e45a3944bb14ff899a09f6a663ab6a7f2",
|
|
64
|
+
"binary": {
|
|
65
|
+
"path": "rpi",
|
|
66
|
+
"sha256": "7f3bacebd89efa923d032a1e700571e343047cccf6f32af31c5dab6902c90b03"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigfishnpm/rpi",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.22.1",
|
|
4
|
+
"description": "Rust-native coding agent for your terminal",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "BigFish <fuwei201473@gmail.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/bigfish1913/pi-rust.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://rpi.bigfisharc.cn/",
|
|
12
|
+
"bugs": "https://github.com/bigfish1913/pi-rust/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"ai",
|
|
15
|
+
"coding-agent",
|
|
16
|
+
"cli",
|
|
17
|
+
"rust",
|
|
18
|
+
"rpi"
|
|
19
|
+
],
|
|
20
|
+
"bin": {
|
|
21
|
+
"rpi": "npm/bin/rpi.cjs"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"npm/bin/rpi.cjs",
|
|
25
|
+
"npm/install.cjs",
|
|
26
|
+
"npm/lib.cjs",
|
|
27
|
+
"npm/release.json",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"NOTICE",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20"
|
|
34
|
+
},
|
|
35
|
+
"os": [
|
|
36
|
+
"darwin",
|
|
37
|
+
"linux",
|
|
38
|
+
"win32"
|
|
39
|
+
],
|
|
40
|
+
"cpu": [
|
|
41
|
+
"x64",
|
|
42
|
+
"arm64"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"prepare:release": "node scripts/prepare-npm.mjs",
|
|
46
|
+
"prepublishOnly": "node scripts/prepare-npm.mjs",
|
|
47
|
+
"postinstall": "node npm/install.cjs",
|
|
48
|
+
"test": "node --test scripts/test-npm.cjs"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public",
|
|
52
|
+
"registry": "https://registry.npmjs.org/"
|
|
53
|
+
}
|
|
54
|
+
}
|