@rob-c/pi-managed-tools 0.0.0-stage → 0.23.0
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/BUSYBOX-CONTRACT.md +440 -0
- package/CHANGELOG.md +775 -0
- package/LICENSE +338 -0
- package/README.md +849 -2
- package/package.json +79 -5
- package/skills/busybox-applets/SKILL.md +266 -0
- package/skills/managed-tools/SKILL.md +328 -0
- package/skills/managed-tools-reference/SKILL.md +738 -0
- package/src/agentops.ts +813 -0
- package/src/agenttools.ts +391 -0
- package/src/bashtool.ts +103 -0
- package/src/build.ts +142 -0
- package/src/context.ts +157 -0
- package/src/display.ts +79 -0
- package/src/extension.ts +1229 -0
- package/src/guard.ts +437 -0
- package/src/jobs.ts +1052 -0
- package/src/timing.ts +364 -0
- package/src/tools.ts +2223 -0
- package/src/userstdin.ts +524 -0
- package/src/wrap.ts +683 -0
package/README.md
CHANGED
|
@@ -1,3 +1,850 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-managed-tools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Published as **`@rob-c/pi-managed-tools`** on npm — install with
|
|
4
|
+
`pi install npm:@rob-c/pi-managed-tools`. The unscoped `pi-managed-tools` name
|
|
5
|
+
was an earlier publish of the same code and is deprecated; do not use it.
|
|
6
|
+
|
|
7
|
+
Pi ships no `fd` and no `rg` binary. It downloads exactly two static binaries on
|
|
8
|
+
demand, into the directory it searches first, and uses them for two built-in
|
|
9
|
+
tools:
|
|
10
|
+
|
|
11
|
+
| Tool | From | Used by | Installed to |
|
|
12
|
+
|---|---|---|---|
|
|
13
|
+
| `fd` | [sharkdp/fd](https://github.com/sharkdp/fd) | the `find` tool | `<agent dir>/bin/fd` (`fd.exe` on Windows) |
|
|
14
|
+
| `rg` (ripgrep) | [BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) | the `grep` tool | `<agent dir>/bin/rg` (`rg.exe` on Windows) |
|
|
15
|
+
| `bat` | [sharkdp/bat](https://github.com/sharkdp/bat) | `bash` only | `<agent dir>/bin/bat` |
|
|
16
|
+
| `prek` | [j178/prek](https://github.com/j178/prek) | `bash` only | `<agent dir>/bin/prek` |
|
|
17
|
+
| `just` | [casey/just](https://github.com/casey/just) | `bash` only | `<agent dir>/bin/just` |
|
|
18
|
+
| `gron` | [tomnomnom/gron](https://github.com/tomnomnom/gron) | `bash` only | `<agent dir>/bin/gron` |
|
|
19
|
+
| `shellcheck` | [koalaman/shellcheck](https://github.com/koalaman/shellcheck) | `bash` only | `<agent dir>/bin/shellcheck` |
|
|
20
|
+
| `ast-grep` | [ast-grep/ast-grep](https://github.com/ast-grep/ast-grep) | `bash` only | `<agent dir>/bin/ast-grep` and `sg` |
|
|
21
|
+
| `ninja` | [ninja-build/ninja](https://github.com/ninja-build/ninja) | `bash` only | `<agent dir>/bin/ninja` |
|
|
22
|
+
| `jq` | [jqlang/jq](https://github.com/jqlang/jq) | `bash` only | `<agent dir>/bin/jq` |
|
|
23
|
+
| `yq` | [mikefarah/yq](https://github.com/mikefarah/yq) (v4, Go) | `bash` only | `<agent dir>/bin/yq` |
|
|
24
|
+
| `fzf` | [junegunn/fzf](https://github.com/junegunn/fzf) | `bash` only | `<agent dir>/bin/fzf` |
|
|
25
|
+
| `uv` | [astral-sh/uv](https://github.com/astral-sh/uv) | `bash` only | `<agent dir>/bin/uv` and `uvx` |
|
|
26
|
+
| `gh` | [cli/cli](https://github.com/cli/cli) | `bash` only | `<agent dir>/bin/gh` |
|
|
27
|
+
| `bd` | [gastownhall/beads](https://github.com/gastownhall/beads) | `bash` only | `<agent dir>/bin/bd` |
|
|
28
|
+
| `agent-browser` | [vercel-labs/agent-browser](https://github.com/vercel-labs/agent-browser) | `bash` only | `<agent dir>/bin/agent-browser` |
|
|
29
|
+
| `ruff` | [astral-sh/ruff](https://github.com/astral-sh/ruff) | `bash` only | `<agent dir>/bin/ruff` |
|
|
30
|
+
| `mise` | [jdx/mise](https://github.com/jdx/mise) | `bash` only | `<agent dir>/bin/mise` |
|
|
31
|
+
| `scc` | [boyter/scc](https://github.com/boyter/scc) | `bash` only | `<agent dir>/bin/scc` |
|
|
32
|
+
| `duckdb` | [duckdb/duckdb](https://github.com/duckdb/duckdb) | `bash` only | `<agent dir>/bin/duckdb` |
|
|
33
|
+
| `miller` | [johnkerl/miller](https://github.com/johnkerl/miller) | `bash` only | `<agent dir>/bin/mlr` |
|
|
34
|
+
| `sd` | [chmln/sd](https://github.com/chmln/sd) | `bash` only | `<agent dir>/bin/sd` |
|
|
35
|
+
| `difftastic` | [Wilfred/difftastic](https://github.com/Wilfred/difftastic) | `bash` only | `<agent dir>/bin/difft` |
|
|
36
|
+
| `busybox` | [rob-c/busybox-static](https://github.com/rob-c/busybox-static) | **every `bash` call**, plus three model tools | `<agent dir>/bin/busybox` (276 applets on Darwin, 62 exposed by name in `<agent dir>/busybox-applets`) |
|
|
37
|
+
|
|
38
|
+
That download logic lives in `dist/utils/tools-manager.js` of
|
|
39
|
+
`@earendil-works/pi-coding-agent`: `ensureTool()` downloads the latest release
|
|
40
|
+
**only when the file is missing**, and `getToolPath()` prefers `<agent dir>/bin`
|
|
41
|
+
over anything on `PATH`. So a machine that installed pi a year ago keeps
|
|
42
|
+
whatever `fd`/`rg` release it fetched then, however many newer releases exist.
|
|
43
|
+
|
|
44
|
+
**`rtk` is no longer part of this package.** It is not downloaded, updated or
|
|
45
|
+
advertised any more: summarising output is a preference, not a pinned binary, and a proxy
|
|
46
|
+
that rewrites what a command printed is the wrong default for a model that must read
|
|
47
|
+
diffs and edit files. An existing `<agent dir>/bin/rtk` is left alone — nothing reads it,
|
|
48
|
+
and `managed_tools` will not mention it.
|
|
49
|
+
|
|
50
|
+
This package fills that gap. On a session start (at most once per interval) it
|
|
51
|
+
resolves the latest release of each project, compares it with the managed copy,
|
|
52
|
+
and replaces the copy in place — the same path pi already uses. pi's `find` and
|
|
53
|
+
`grep` tools call `getToolPath()` for every run, and pi puts `<agent dir>/bin`
|
|
54
|
+
first on the `PATH` of every `bash` command it runs, so both see the new binary
|
|
55
|
+
immediately.
|
|
56
|
+
|
|
57
|
+
Note that `find` and `grep` are not enabled by default: pi's `defaultTools` is
|
|
58
|
+
`read`, `bash`, `edit`, `write`. Turn them on with `pi --tools +grep,+find` or
|
|
59
|
+
`"defaultTools": ["+grep", "+find"]` in settings (see `docs/settings.md`
|
|
60
|
+
inside the pi package). The binaries and the update are the same either way —
|
|
61
|
+
pi's interactive mode prepares them at startup regardless of which tools are
|
|
62
|
+
enabled.
|
|
63
|
+
|
|
64
|
+
**Only `fd` and `rg` back a pi built-in tool.** Everything else is installed so
|
|
65
|
+
`bash` commands can use it, and `/managed-tools` reports that distinction rather
|
|
66
|
+
than implying otherwise.
|
|
67
|
+
|
|
68
|
+
### `tree` is not here
|
|
69
|
+
|
|
70
|
+
Upstream (`Old-Man-Programmer/tree`) publishes git tags but **no release
|
|
71
|
+
assets**, so there is no binary to download and nothing to verify. `fd -d 2 -td`
|
|
72
|
+
covers most of what `tree` is used for, from a binary this package already
|
|
73
|
+
manages.
|
|
74
|
+
|
|
75
|
+
### Command shadowing
|
|
76
|
+
|
|
77
|
+
pi searches `<agent dir>/bin` first, then `<agent dir>/busybox-applets` (the
|
|
78
|
+
curated applet names, see *BusyBox applet names on PATH*), then the user's own
|
|
79
|
+
`PATH` entries, so these win over anything else. That is intended for
|
|
80
|
+
`fd`/`rg`/`bat`. Two cases are worth knowing:
|
|
81
|
+
|
|
82
|
+
- `ast-grep` also installs its deprecated `sg` shim, which shadows util-linux's
|
|
83
|
+
`/usr/bin/sg` on Linux (the group-switching helper used by `newgrp`). Delete
|
|
84
|
+
`<agent dir>/bin/sg` if you need the system one.
|
|
85
|
+
- `git`, `python3`, `node`, `tree` and the rest of the toolchain still come from
|
|
86
|
+
the system. Nothing here replaces an *interpreter* — their versions belong to
|
|
87
|
+
each project's lockfile. `uv` is the one exception in spirit: it is a package
|
|
88
|
+
manager, so it creates its own Python toolchains and caches outside this bin
|
|
89
|
+
directory. Prefer `uv run <cmd>` so the project's pinned version is used.
|
|
90
|
+
- `yq` here is **mikefarah/yq v4** (Go). `kislyuk/yq` is a different tool with
|
|
91
|
+
different flags and no releases of this shape.
|
|
92
|
+
- `gh` is **credential-bearing**: it keeps an OAuth token in
|
|
93
|
+
`~/.config/gh/hosts.yml`. Its downloads are digest-verified like every other
|
|
94
|
+
tool, but auto-updating a binary that holds a token is a trust decision worth
|
|
95
|
+
making deliberately.
|
|
96
|
+
- `fzf` needs a TTY for interactive use, and pi's `bash` tool does not provide
|
|
97
|
+
one. `fzf --filter` works; the interactive picker does not.
|
|
98
|
+
- **`bd init` mutates the project.** It creates `.beads/` with an embedded Dolt
|
|
99
|
+
database, **rewrites `AGENTS.md` by default**, and installs editor/agent
|
|
100
|
+
integration files unless given `--skip-agents` or `--stealth`. `bd setup <tool>`
|
|
101
|
+
writes those integration files too. The read-only commands (`list`, `show`,
|
|
102
|
+
`status`, `query`) are safe.
|
|
103
|
+
- **`bd` sends anonymous usage metrics by default** — command names, version and
|
|
104
|
+
OS platform, not issues or paths. Set `DO_NOT_TRACK=1` to disable it. That is
|
|
105
|
+
the user's decision, so this package does not set it for you.
|
|
106
|
+
- **`agent-browser` needs a browser and leaves a daemon running.** It drives a
|
|
107
|
+
local Chrome/Chromium (or an existing one via `connect`), keeps state across
|
|
108
|
+
invocations through a background daemon, and `close --all` stops it. Its own
|
|
109
|
+
`agent-browser skills get core` **fails** on this build — the release binary
|
|
110
|
+
ships no skills directory, whatever `--help` claims. No win32-arm64 release.
|
|
111
|
+
- **`mise` is a version manager.** A managed copy sits ahead of whatever the user
|
|
112
|
+
installed, and its `activate` shell hook never runs in pi's `bash`, so only
|
|
113
|
+
`mise exec -- <cmd>` reliably picks up a project's pins. It installs toolchains
|
|
114
|
+
under `~/.local/share/mise`, outside this bin directory. This is the one entry
|
|
115
|
+
here that deliberately manages a tool whose job is managing other versions.
|
|
116
|
+
- **`busybox` is a multicall binary** that dispatches on `argv[0]`, so it is only
|
|
117
|
+
installed under the name `busybox` — renaming or copying it breaks every applet.
|
|
118
|
+
Use it as `busybox <applet>`, or by the bare applet name for the 62 in the
|
|
119
|
+
curated list (below). **Never run `busybox --install -s <dir>`**: in pi's bin
|
|
120
|
+
directory, which is first on `PATH`, that would put 276 applets ahead of the real
|
|
121
|
+
coreutils, including `sh`, `rm`, `mount` and `init`. The package links a curated
|
|
122
|
+
set into its own directory instead. Per-applet read-only vs mutating
|
|
123
|
+
classification is in the `busybox-applets` skill.
|
|
124
|
+
- **`sd` rewrites files in place.** With no file arguments it filters stdin to
|
|
125
|
+
stdout, but `sd FIND REPLACE file...` edits those files. Use `-p` to preview.
|
|
126
|
+
Its release binary also reports `sd 1.0.0` for tag `v1.1.0`; the tag is trusted
|
|
127
|
+
for version comparison (the digest already proves the asset), so it does not
|
|
128
|
+
reinstall in a loop.
|
|
129
|
+
- **`duckdb` prints an agent-mode banner** before every result when `AI_AGENT` is
|
|
130
|
+
set and stdout is not a terminal — which is always true inside pi. Pass
|
|
131
|
+
`-no-agent` (or set `DUCKDB_AGENT_MODE=0`).
|
|
132
|
+
- **`ruff` is normally pinned by the project.** Prefer `uv run ruff ...` so the
|
|
133
|
+
version CI uses decides the rules; the managed copy is for a check outside a
|
|
134
|
+
project environment, and should never rewrite files the project's own version
|
|
135
|
+
would format differently.
|
|
136
|
+
|
|
137
|
+
## Skills
|
|
138
|
+
|
|
139
|
+
The package ships two skills:
|
|
140
|
+
|
|
141
|
+
## How it integrates with pi
|
|
142
|
+
|
|
143
|
+
Four surfaces, in order of how reliably they reach the model:
|
|
144
|
+
|
|
145
|
+
1. **`tool_call`** (deterministic) — an absolute host path for a managed binary is
|
|
146
|
+
rewritten to its bare name before the command runs, so `/usr/bin/jq -r .a`
|
|
147
|
+
executes as `jq -r .a` and the packaged build runs. Only command-position tokens
|
|
148
|
+
are touched and only names this package manages (or links as an applet name), so
|
|
149
|
+
`/usr/bin/tar` is untouched. `PI_MANAGED_TOOLS_REWRITE=off` turns it off.
|
|
150
|
+
2. **PATH** (deterministic) — at session start the extension rebuilds
|
|
151
|
+
`process.env.PATH` as
|
|
152
|
+
`<agent dir>/bin : <agent dir>/busybox-applets : <user dirs> : <system dirs>`,
|
|
153
|
+
dropping any earlier occurrence of its own two entries first. pi's
|
|
154
|
+
`getShellEnv()` re-reads that value for every `bash` spawn and only prepends the
|
|
155
|
+
bin directory when it is *absent*, so this is the one hook that reaches every
|
|
156
|
+
command — including the case where a shell rc appended
|
|
157
|
+
`$HOME/.pi/agent/bin` to `PATH` and defeated pi's prepend.
|
|
158
|
+
3. **`before_agent_start`** (deterministic) — the two environment rules are appended
|
|
159
|
+
to `systemPromptOptions.promptGuidelines`, and a `managed_tools_environment`
|
|
160
|
+
section states the facts outright: that the bin directory is first on `PATH`,
|
|
161
|
+
which packaged versions that means, that the busybox applet names are on `PATH`
|
|
162
|
+
as well, and that no probing turn is needed. Idempotent, and the section text
|
|
163
|
+
is stable so pi does not re-patch it each turn.
|
|
164
|
+
4. **Skills** (opportunistic) — name, description and path are always in the system
|
|
165
|
+
prompt; the body loads only when the model decides it is relevant, which it does
|
|
166
|
+
not do for one-liners.
|
|
167
|
+
|
|
168
|
+
`/managed-tools status` reports how many absolute paths were rewritten this session,
|
|
169
|
+
how many applet names are linked (62 with the default policy), and what the installed
|
|
170
|
+
build says about itself (`busybox --caps`: version, applet count, features) — which is
|
|
171
|
+
the only honest answer when a binary was installed by hand ahead of a release.
|
|
172
|
+
|
|
173
|
+
### BusyBox applet names on PATH
|
|
174
|
+
|
|
175
|
+
`<agent dir>/busybox-applets` holds symlinks named after applets, each pointing at
|
|
176
|
+
`<agent dir>/bin/busybox`, so `xxd`, `hexdump`, `sha256sum`, `unzip`, `timeout` and
|
|
177
|
+
57 more run without the `busybox` prefix. The links live in a second directory, not
|
|
178
|
+
in the bin directory, because PATH order is the only thing that decides which build
|
|
179
|
+
a bare name runs and two names in one directory have no order. The dedicated static
|
|
180
|
+
builds stay first.
|
|
181
|
+
|
|
182
|
+
The default list is curated, not "all 276":
|
|
183
|
+
|
|
184
|
+
- **In** when the host may not have the tool (`cpio`, `dpkg-deb`, `rpm2cpio`,
|
|
185
|
+
`nproc`, `setsid`, `sha3sum`, `uuidgen`, `ipcalc`, `wget`, ...), when the busybox
|
|
186
|
+
implementation accepts the flags anyone actually passes (`xxd`, `hexdump`, `od`,
|
|
187
|
+
`strings`, `gzip`, `unzip`, `timeout`, ...), or when it is an agent-facing applet
|
|
188
|
+
with a distinctive name and no side effects (`peek`, `waitfor`, `doctor`, `brief`,
|
|
189
|
+
`why`, `patchcheck`).
|
|
190
|
+
- **Out** whenever a host build is near-universal and functionally richer, so no
|
|
191
|
+
working command changes meaning: `sed`, `grep`, `find`, `awk`, `tar`, `diff`,
|
|
192
|
+
`ls`, `cat`, `cp`, `mv`, `rm`, `ln`, `chmod`, `stat`, `df`, `du`, `ps`, `kill`,
|
|
193
|
+
`bc`, `mktemp`, `which`, `date`, `patch` and `tree` (busybox `tree` takes a
|
|
194
|
+
directory and no flags, so the usual `tree -L 2` fails). So do `replace`, `run`,
|
|
195
|
+
`log`, `bench`, `check`, `json` and `snapshot`: some run a command, some write a file,
|
|
196
|
+
and the rest are names a project script or another tool already owns. Everything left
|
|
197
|
+
out stays reachable as `busybox <applet>`, which is a deliberate act.
|
|
198
|
+
- **Never**, under any policy: shells (`sh`, `ash`, `hush`, `login`, `su`), boot and
|
|
199
|
+
device administration (`init`, `mount`, `mdev`, `sysctl`, `insmod`), servers
|
|
200
|
+
(`httpd`, `telnetd`, `tftpd`) and package managers (`dpkg`, `rpm`).
|
|
201
|
+
|
|
202
|
+
`PI_MANAGED_TOOLS_APPLETS` widens or disables it: `all` links every applet the
|
|
203
|
+
build has minus the never-list (the aggressive version, where busybox `sed` and
|
|
204
|
+
`grep` do win), `off` links nothing and leaves only the bin directory ahead. An
|
|
205
|
+
unrecognised value is the default, never a silent opt-in to `all`.
|
|
206
|
+
|
|
207
|
+
The always-on skill also pins two environment rules, because both are silent when
|
|
208
|
+
broken: call the packaged binaries by **bare name** (an absolute path like
|
|
209
|
+
`/usr/bin/jq` bypasses pi's `PATH` prepend and `getToolPath()`), and run multi-step
|
|
210
|
+
shell logic through **`busybox sh -c '…'`** so the shell does not depend on which
|
|
211
|
+
bash the host resolved. `busybox sh` covers `[[ ]]`, `<(…)`, `<<<`, `$'…'`, `local`
|
|
212
|
+
and `pipefail`, but not arrays, `${v^^}`, `read -a`, `mapfile` or `coproc`. The
|
|
213
|
+
curated applet names are bare on `PATH` too; the names that are *not* linked need the
|
|
214
|
+
`busybox` prefix.
|
|
215
|
+
|
|
216
|
+
- **`managed-tools`** — always advertised. pi adds every skill's *name and
|
|
217
|
+
description* to the system prompt and nothing else, so this description is the
|
|
218
|
+
advert: it sets the preference order (these binaries over the system ones), names all
|
|
219
|
+
twenty-four tools, and routes to the reference for flags.
|
|
220
|
+
- **`busybox-applets`** — loaded on demand, only when busybox is in play. All 276
|
|
221
|
+
applets classified read-only / mutating / destructive / exec, with the flags that
|
|
222
|
+
cause a write, plus the contract the six agent-facing applets share.
|
|
223
|
+
- **`managed-tools-reference`** — loaded on demand. The exact flag set and one
|
|
224
|
+
or two worked examples per tool, transcribed from the binaries this package
|
|
225
|
+
installs rather than from upstream docs, because the versions are pinned.
|
|
226
|
+
|
|
227
|
+
Both skills say where reduction happens now that `rtk` is gone: `busybox brief -d`
|
|
228
|
+
collapses identical records without cutting one in half, `-R` keeps a stack trace as a
|
|
229
|
+
single record, and `busybox_run` retains the full capture in an artifact, so a reduced
|
|
230
|
+
view never destroys the evidence. Nothing here summarises a diff behind your back.
|
|
231
|
+
|
|
232
|
+
That pinning is the point: the tool surface is fully known at install time, so
|
|
233
|
+
the skills can state flag names instead of telling the model to run `--help` and
|
|
234
|
+
spend the tokens anyway. `tests/skills.test.ts` keeps them honest — adding a tool
|
|
235
|
+
without documenting it in both skills fails the suite, as does a description over
|
|
236
|
+
the Agent Skills 1024-character limit or a version list that disagrees between
|
|
237
|
+
the two files.
|
|
238
|
+
|
|
239
|
+
### Pi-Time: every bash call is a timeline
|
|
240
|
+
|
|
241
|
+
**Pi-Time** is the name for what the wrapper gives the model: the concept of time, which a
|
|
242
|
+
plain text capture of an execution does not carry — and which a hosted LLM needs to reason
|
|
243
|
+
about a run instead of guessing. Three facts come back with every command, and each exists
|
|
244
|
+
because its absence made the model misread an execution:
|
|
245
|
+
|
|
246
|
+
- **Which stream.** Every line is tagged `out` or `err`, so a warning on stderr is never
|
|
247
|
+
misread as program output, and a tool's diagnostics keep their identity. A `2>&1` in the
|
|
248
|
+
command destroys exactly this — it merges stderr into stdout inside the child, before
|
|
249
|
+
the wrapper can tag anything — so the skills forbid it.
|
|
250
|
+
- **When.** A microsecond offset on every line, and a `timing:` digest on slow runs, so
|
|
251
|
+
ordering, durations and silences are readable facts. A merged capture does not just
|
|
252
|
+
lack them — it lies: block buffering puts a 0s stdout burst after an 8s stderr line, and
|
|
253
|
+
the probe below shows a model repeating that inverted order.
|
|
254
|
+
- **How long is too long.** A default deadline on every call, so a hang ends in a named
|
|
255
|
+
`TIMEOUT` state with its partial capture intact, instead of minutes of silence or an
|
|
256
|
+
exit code that reads like a failure.
|
|
257
|
+
|
|
258
|
+
Mechanically: pi's `bash` tool is re-registered (the supported override path: pi's own
|
|
259
|
+
runner with a spawn hook) so each command executes as
|
|
260
|
+
`busybox run --timestamps ... -- /bin/bash -c '<command>'`.
|
|
261
|
+
|
|
262
|
+
The **model** reads one interleaved line per record, with its offset in seconds and the
|
|
263
|
+
stream it arrived on:
|
|
264
|
+
|
|
265
|
+
```
|
|
266
|
+
run=R134 exit_code=0 timed_out=false cancelled=false idle=false duration_ms=8421
|
|
267
|
+
timeline_lines=4 shown=4 truncated=false
|
|
268
|
+
--- timeline ---
|
|
269
|
+
[0.011354789 out] ok 1
|
|
270
|
+
[= out] ok 2
|
|
271
|
+
[2.320004125 err] FAILED test_x
|
|
272
|
+
[8.421130000 out] done
|
|
273
|
+
timing: 8.42s total, 4 lines, output from 0.01s, stderr from 2.32s, longest pause 6.10s (2.32s → 8.42s)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
The child gets a pseudo-terminal (`busybox run --pty-split`): stdout on the pty, stderr
|
|
277
|
+
on a pipe. That is what makes the offsets honest: libc line-buffers when stdout is a
|
|
278
|
+
terminal, so a program that buffers on a pipe emits each line as it happens. A C program
|
|
279
|
+
printing three lines 1.2 s apart reported all three at `3.740564` on a pipe and at
|
|
280
|
+
`0.004561 / 1.209525 / 2.414571` on the pty; Python and Ruby have environment switches
|
|
281
|
+
(the wrapper sets them too), C stdio, Java and Go's `bufio` have only this. stderr is
|
|
282
|
+
unbuffered either way, so it keeps its own pipe and its `err` tag. `isatty()` is now true for the child, which is the one behavioural
|
|
283
|
+
change: programs take their terminal path (colours are suppressed by `NO_COLOR`/
|
|
284
|
+
`TERM=dumb`, pagers by `PAGER=cat`). `PI_MANAGED_TOOLS_PTY=off` restores plain pipes;
|
|
285
|
+
`merged` gives 0/1/2 one pty; `raw` adds `--pty-raw`.
|
|
286
|
+
|
|
287
|
+
A run longer than a second also gets the **`timing:` digest** appended to the tool
|
|
288
|
+
result, for the model only: total, line count, where output began, and the longest
|
|
289
|
+
silence (or the silence after the last line). It is a derived line, not a replacement
|
|
290
|
+
for the offsets, and the renderer strips it for the human.
|
|
291
|
+
|
|
292
|
+
`[= out]` is a line that arrived at the same offset as the one above: within a burst the
|
|
293
|
+
offset is printed once, and the stream tag stays on every line. (Stamps were measured at
|
|
294
|
+
a quarter of all bash-result bytes; `PI_MANAGED_TOOLS_COMPACT_STAMPS=off` prints them in
|
|
295
|
+
full.) The exact shape of a stamp is the build's — padded to 0.6.0, unpadded since — so
|
|
296
|
+
the example the model is shown is cut from a line the installed binary really printed,
|
|
297
|
+
at session start.
|
|
298
|
+
|
|
299
|
+
That is the ordering a merged stdout/stderr block destroys: the failure came after
|
|
300
|
+
`ok 1` and before `done`, and lines sharing one timestamp are a writer that flushed at
|
|
301
|
+
exit rather than streaming.
|
|
302
|
+
|
|
303
|
+
The **human** sees the command's own lines: the bash renderer strips the wrapper's
|
|
304
|
+
header, section markers and `[0.012345789 out]` prefixes, and keeps everything the
|
|
305
|
+
command printed — indentation, blank lines, a truncated view's `... [N bytes] ...`
|
|
306
|
+
marker — plus pi's usual `(full output: …)` hint when pi truncates. The tool result is
|
|
307
|
+
untouched, so the model's copy and the session transcript keep the timeline; only the
|
|
308
|
+
rendering differs (TUI and HTML export).
|
|
309
|
+
|
|
310
|
+
The wrapper is transparent in the ways that matter: the child's exit status, cwd and
|
|
311
|
+
shell are unchanged (still `/bin/bash`, so `[[ ]]` and arrays keep working), and the
|
|
312
|
+
unbuffered environment travels with the command rather than being exported into pi:
|
|
313
|
+
`PYTHONUNBUFFERED=1`, `PYTHONIOENCODING=utf-8`, `PYTHONDONTWRITEBYTECODE=1`, `NO_COLOR=1`,
|
|
314
|
+
`CLICOLOR=0`, `FORCE_COLOR=0`, `TERM=dumb`, `PAGER=cat`, `GIT_PAGER=cat`,
|
|
315
|
+
`GIT_TERMINAL_PROMPT=0`, `CARGO_TERM_COLOR=never`, `DEBIAN_FRONTEND=noninteractive`,
|
|
316
|
+
`MAVEN_ARGS=-B -ntp`, `GRADLE_OPTS=-Dorg.gradle.console=plain -Dorg.gradle.daemon=false`,
|
|
317
|
+
and `RUBYOPT=-r<agent dir>/pi-unbuffer.rb` for Ruby's `$stdout.sync`. Where no switch
|
|
318
|
+
exists — Go's `bufio.Writer`, Java's `System.out` — the timeline shows the flush: every
|
|
319
|
+
line of a burst carries the same offset.
|
|
320
|
+
|
|
321
|
+
Two escapes: `PI_MANAGED_TOOLS_WRAP=off` for the session, and `command <cmd>` for one
|
|
322
|
+
call (accepted at the start of the command or of any `&&`/`;` segment), which runs it
|
|
323
|
+
unwrapped for byte-exact output.
|
|
324
|
+
|
|
325
|
+
The human's own `!` commands go through the wrapper too (pi's `user_bash` hook hands the
|
|
326
|
+
local backend a wrapped command): the split pseudo-terminal and the unbuffered
|
|
327
|
+
environment, with the command's own bytes shown and nothing else — no timeline, because
|
|
328
|
+
the reader is a person in the TUI. No deadline is applied (a `!` command belongs to its
|
|
329
|
+
owner, Ctrl-C included), the `command` escape falls through to pi's plain path, and
|
|
330
|
+
`PI_MANAGED_TOOLS_USER_WRAP=off` turns it off.
|
|
331
|
+
|
|
332
|
+
**You can answer a `!` command.** pi starts every command with its stdin closed, so a
|
|
333
|
+
`[y/N]` prompt used to read end-of-file, take its default and exit 0; and `busybox run -q`
|
|
334
|
+
prints only when the command exits, so nothing was shown until then. Now:
|
|
335
|
+
|
|
336
|
+
- the output is shown as it arrives, an unfinished prompt line included (the run's capture
|
|
337
|
+
files are followed while it runs);
|
|
338
|
+
- when the command looks like it is waiting — output stopped on an unfinished line, or
|
|
339
|
+
three seconds of silence — pi's input dialog opens, titled with the command. Enter sends
|
|
340
|
+
the line to the command, through `busybox run --stdin` and the pty; the dialog reopens
|
|
341
|
+
for the next question;
|
|
342
|
+
- Esc in the dialog means "no more input": the command reads end-of-file and carries on,
|
|
343
|
+
and you get the editor back. Esc again stops the command, as before;
|
|
344
|
+
- **you have five minutes to answer** — not the two a model's command gets, because this
|
|
345
|
+
clock times a person, not a program. The dialog's title counts down, and the clock runs
|
|
346
|
+
only while the dialog is open: a command that is working is never timed by it. When it
|
|
347
|
+
runs out the command is **stopped**, with exit status 124 and a line in its output
|
|
348
|
+
saying it waited and nobody typed. It is not given end-of-file instead, because a
|
|
349
|
+
`[Y/n]` prompt would read that as *yes*. `PI_MANAGED_TOOLS_STDIN_TIMEOUT=<seconds>`
|
|
350
|
+
changes the wait; `0` waits for as long as it takes;
|
|
351
|
+
- what you type is **not** added to the output, which is recorded in the session and read
|
|
352
|
+
by the model — a password stays out of it. It is visible in the dialog while you type.
|
|
353
|
+
|
|
354
|
+
A command that draws to the whole screen (an editor, `less`, `top`) is still not something
|
|
355
|
+
a `!` command can host. This path keeps no capture afterwards: the run's private folder is
|
|
356
|
+
removed when the command ends. `PI_MANAGED_TOOLS_USER_STDIN=off` restores the old
|
|
357
|
+
behaviour (stdin empty, output at exit, capture kept for `busybox log`).
|
|
358
|
+
|
|
359
|
+
The model cannot be answered by anyone, and is told so: its commands read end-of-file at
|
|
360
|
+
once, so it puts the answer in the command (`printf 'y\n' | cmd`, a heredoc, `--yes`) or
|
|
361
|
+
in `busybox_run`'s `stdin` parameter.
|
|
362
|
+
|
|
363
|
+
Every wrapped command gets a 120-second deadline by default, so a hang cannot hold the
|
|
364
|
+
model in silence. A caller's own `timeout` still wins — the wrapper takes it over one
|
|
365
|
+
second earlier (`--timeout N-1`) because the applet's deadline cancels the child's process
|
|
366
|
+
group and still prints the timeline, while a SIGKILL from pi would print nothing at all.
|
|
367
|
+
`PI_MANAGED_TOOLS_TIMEOUT=<seconds>` changes the default for a session; `0` or `off`
|
|
368
|
+
removes it.
|
|
369
|
+
|
|
370
|
+
When the deadline fires, the result opens with `TIMEOUT — not a failure of the command` and
|
|
371
|
+
explains that the `exit_code=-1` / "Command exited with code 3" statuses are the kill, not
|
|
372
|
+
the command's own exit code; the partial capture is retrievable with `busybox log <run>`.
|
|
373
|
+
|
|
374
|
+
Stamps are nanosecond (`--stamp-ns`) where the build has them — two events in the same
|
|
375
|
+
microsecond stay distinguishable — and every shape a build has printed still parses:
|
|
376
|
+
padded microseconds, zero-padded nanoseconds (0.6.0), unpadded (0.6.1 on).
|
|
377
|
+
|
|
378
|
+
A 120-second silence watchdog (`run -W`) rides with every deadline: a command producing no
|
|
379
|
+
output at all is killed and reported `idle=true` — a hang, not slow work — even when the
|
|
380
|
+
deadline was raised. The result's notice names it `IDLE`, distinct from `TIMEOUT`, and
|
|
381
|
+
rules stdin out as the cause (stdin is empty under pi, so a read returns end-of-file at
|
|
382
|
+
once) in favour of a socket, a lock or a child that never exits.
|
|
383
|
+
`PI_MANAGED_TOOLS_IDLE=<seconds>` changes it; `0` disables it. And
|
|
384
|
+
`busybox run --format json` now reports what the command *did*, not just what it printed:
|
|
385
|
+
`cpu_user_ms`/`cpu_sys_ms`, `max_rss_kb`, `binary` (the output is not text), `dropped_bytes`,
|
|
386
|
+
`final_newline`, `cwd_start` and a re-runnable `replay` line — the `busybox_run` tool
|
|
387
|
+
surfaces the interpretation-changing ones on a `meta` line of its result.
|
|
388
|
+
|
|
389
|
+
### What a result says, and what is refused
|
|
390
|
+
|
|
391
|
+
A result is only as good as what the model can conclude from it without guessing. Each of
|
|
392
|
+
these was a place where it had to guess, or was told something false.
|
|
393
|
+
|
|
394
|
+
- **How it ended comes first, when that was not the command's own exit.** `TIMEOUT`,
|
|
395
|
+
`IDLE`, `CANCELLED` and `KILLED` open the result. A timeout used to start with
|
|
396
|
+
`exit_code=-1`, then up to 48 KB of output, and only then say nothing had failed.
|
|
397
|
+
- **A truncated view names what it lacks.** `busybox run` keeps the head *and* the tail of
|
|
398
|
+
a long timeline and marks the cut. The line after the result names the omitted range,
|
|
399
|
+
gives the command that reads from it, and says how many of the omitted lines are on
|
|
400
|
+
stderr — a view with no `[err]` line otherwise reads as "no errors".
|
|
401
|
+
- **pi's own cut is repaired.** pi's bash tool keeps the last 2000 lines or 50 KB. When
|
|
402
|
+
that removes the `run=` header, it is restored from the full output pi kept aside, and
|
|
403
|
+
the cut is said.
|
|
404
|
+
- **Facts instead of "unknown".** The guest shell leaves its last pipeline's stage
|
|
405
|
+
statuses and its final directory in the run's folder (an EXIT trap, about 4 ms). So
|
|
406
|
+
`cmd | head` gets `pipeline stage statuses: 1 141 0` — or no note at all when every
|
|
407
|
+
stage exited 0 — and a `cd` gets `this command ended in /repo/build; the next bash
|
|
408
|
+
call starts back in /repo`. A command that sets its own EXIT trap gets the old caveats.
|
|
409
|
+
- **A caveat is given in full once.** After that it comes back in a few words; the same
|
|
410
|
+
two lines on every `| head` call were being skimmed past.
|
|
411
|
+
- **A command that cannot end is refused before it runs**, with the rewrite: a pager, an
|
|
412
|
+
editor, `tail -f`, `watch`, `top`, `git rebase -i`, a foreground server. Nobody can
|
|
413
|
+
press a key here, so it would sit until the deadline and return a `TIMEOUT` with
|
|
414
|
+
nothing learned. Only the first word of a statement or pipeline stage is judged,
|
|
415
|
+
heredoc bodies are skipped, and `timeout …`, a trailing `&`, or a pipeline that ends
|
|
416
|
+
(`tail -f log | grep -m1 ready`) pass. `# pitime-safe` overrides it, as for a merge.
|
|
417
|
+
- **`busybox sh -c '…'` is wrapped.** Every direct `busybox …` call used to count as
|
|
418
|
+
"already wrapped" — and the guidelines recommend `busybox sh -c` for multi-step logic,
|
|
419
|
+
so exactly the longest commands ran with no timeline and no deadline. Only the applets
|
|
420
|
+
whose output is their own record (`run`, `log`, `peek`, `json`, …) are left alone now.
|
|
421
|
+
- **The binary is asked, not assumed.** At session start it is run once with the flags a
|
|
422
|
+
wrapped command gets. Its feature list decides `--stamp-ns` and the silence watchdog;
|
|
423
|
+
a refused pseudo-terminal means plain pipes for the session; and a binary that fails
|
|
424
|
+
turns the wrapper off, with a warning, instead of failing every bash call.
|
|
425
|
+
- **Captures are not deleted from under another session.** The artifact root is shared by
|
|
426
|
+
every session on the machine, and `--prune 20` let twenty commands in one delete a run
|
|
427
|
+
another had just been pointed at. Nothing is pruned by count now: the sweep removes a
|
|
428
|
+
run only when it is beyond the newest 200 *and* more than two hours old.
|
|
429
|
+
- **Other extensions see the model's command.** The wrapper is applied inside the bash
|
|
430
|
+
tool's own `execute`, not by rewriting the call in the `tool_call` hook, so a permission
|
|
431
|
+
or safety extension matches its rules against `npm test`, not `busybox run … -c '…'`.
|
|
432
|
+
|
|
433
|
+
### Buffering
|
|
434
|
+
|
|
435
|
+
An offset is only the truth if the program wrote the line when it printed it. On the
|
|
436
|
+
terminal most runtimes do. But a stage inside a pipeline (`make | tee build.log`,
|
|
437
|
+
`./server | grep ERROR`) and output sent to a file a later call reads write to a pipe or
|
|
438
|
+
a file, where a runtime that block-buffers holds its lines until 4–64 KB have piled up.
|
|
439
|
+
Measured with a probe per runtime (print, wait a second, print; stdout a pipe), on macOS
|
|
440
|
+
and Debian:
|
|
441
|
+
|
|
442
|
+
| Runtime | On a pipe, untouched | With the wrapper | How |
|
|
443
|
+
|---|---|---|---|
|
|
444
|
+
| sh builtins, Node, Deno, Bun, PHP, Tcl, R, Java, Elixir, Go, Rust, C++ iostream | live | live | nothing needed |
|
|
445
|
+
| Python | late | live | `PYTHONUNBUFFERED=1` |
|
|
446
|
+
| Ruby, Perl | late | live | a prelude loaded through `RUBYOPT` / `PERL5OPT` |
|
|
447
|
+
| LuaJIT | late | live | `LUA_INIT` |
|
|
448
|
+
| C stdio on macOS: compiled C, Swift, `grep`, `sed`, `awk`, `cut`, `tr`, `jq` | late | live | `STDBUF1=L`, read by the C library itself |
|
|
449
|
+
| C stdio on Linux | late | late — live with `PI_MANAGED_TOOLS_PRELOAD=on` | glibc has no variable; `stdbuf`'s preload library |
|
|
450
|
+
| Haskell (GHC), OCaml `Printf`, `mawk` | late | late | nothing outside the program changes it |
|
|
451
|
+
|
|
452
|
+
`RUBYOPT`, `PERL5OPT`, `MAVEN_ARGS` and `GRADLE_OPTS` are appended to what you already have
|
|
453
|
+
(a `GRADLE_OPTS=-Xmx4g` used to be replaced). The cost is bulk output: a line at a time is
|
|
454
|
+
a system call at a time — on macOS five million lines into a file took 15.5 s instead of
|
|
455
|
+
0.6 s, about 3 µs a line. `STDBUF1=F cmd` exempts one command, `PI_MANAGED_TOOLS_EXTRA_ENV`
|
|
456
|
+
set to `STDBUF1=F` every command, and `PI_MANAGED_TOOLS_UNBUFFER=off` turns all of it off.
|
|
457
|
+
The Linux preload is off by default because it reaches every program a command starts,
|
|
458
|
+
and an AddressSanitizer build refuses to run under one.
|
|
459
|
+
|
|
460
|
+
### What the model is sent of what it has already read
|
|
461
|
+
|
|
462
|
+
- **Old timelines lose their offsets at compaction.** A wrapped result older than the
|
|
463
|
+
latest compaction is sent with the command's own lines, `err| ` on its stderr lines, its
|
|
464
|
+
header and its digest — no stamps. Only then, because rewriting an old message changes
|
|
465
|
+
the prompt's prefix, and compaction is the one moment the prefix is rebuilt anyway.
|
|
466
|
+
The session file is never touched.
|
|
467
|
+
- **A `!` command reaches the model as a timeline.** You see the command's own bytes; the
|
|
468
|
+
capture took a timeline anyway, and the recorded message is swapped for it on the way
|
|
469
|
+
to the model.
|
|
470
|
+
|
|
471
|
+
### `busybox_job`: a command that outlives the call
|
|
472
|
+
|
|
473
|
+
pi has no background mode: a dev server in a bash call ends in a `TIMEOUT`, and `&` loses
|
|
474
|
+
the output. `busybox_job` starts a command under its own `busybox run`, returns a job id,
|
|
475
|
+
and then: `status` gives only the output that is new (stderr lines marked `err| `),
|
|
476
|
+
`wait_for` returns the moment a literal appears and says whether it did, `stop` ends the
|
|
477
|
+
whole process group. Jobs are stopped when the session ends; at most eight run at once.
|
|
478
|
+
|
|
479
|
+
### Agent-facing applets and the three tools
|
|
480
|
+
|
|
481
|
+
The packaged build carries fifteen applets that exist for a coding agent rather than a
|
|
482
|
+
shell, and they share one contract: text by default, `--format json` with
|
|
483
|
+
`"schema":1` on request, explicit byte budgets, `shown_bytes`/`truncated` always
|
|
484
|
+
reported, and exit codes that never use 124 or 128+N.
|
|
485
|
+
|
|
486
|
+
| applet | what it adds |
|
|
487
|
+
|---|---|
|
|
488
|
+
| `peek FILE -l A:B` | numbered lines **and** the file's `sha256` from the same bytes, a `--from-byte` continuation, merged `--around` windows, binary input flagged rather than dumped |
|
|
489
|
+
| `replace FILE --old S --new S` | literal replacement validated against the whole file before any write, `--expect N`, `--sha256` precondition, atomic write, `--dry-run` diff, `flock` for cooperating writers |
|
|
490
|
+
| `run -- CMD...` | exec argv verbatim or `--shell`, stdout/stderr captured to 0600 artifacts, bounded head+tail view, own deadline and process-group cleanup |
|
|
491
|
+
| `log RUN` | re-read a capture by `--lines`, `--match` (literal), `--context`, `--stream`, `--meta` |
|
|
492
|
+
| `waitfor` | bounded `--file`/`--tcp`/`--unix`/`--http` readiness with one deadline |
|
|
493
|
+
| `doctor` | cwd, argv[0] resolution, shell, writable temp, `--deps a,b` paths — no environment dump |
|
|
494
|
+
|
|
495
|
+
Three of them are wrapped as model tools, because the built-ins they resemble lack
|
|
496
|
+
exactly one property each:
|
|
497
|
+
|
|
498
|
+
- **`busybox_peek`** — a read that returns the file version, so the next edit can be
|
|
499
|
+
refused if the file moved underneath it. `read` is still the default for reading.
|
|
500
|
+
- **`busybox_replace`** — `edit` with a `sha256` precondition: a stale hash is
|
|
501
|
+
`STALE_INPUT` and the file stays byte-identical, `dry_run` returns the diff, and
|
|
502
|
+
several edits are all validated before any is written. `edit` stays the default.
|
|
503
|
+
- **`busybox_run`** — `bash` with retrievable evidence: the capture is complete even
|
|
504
|
+
when the view is trimmed, so `run_id` fetches the lines that were left out. A
|
|
505
|
+
nonzero `exit_code` is reported as the command's status, never as a tool failure.
|
|
506
|
+
`bash` stays the default.
|
|
507
|
+
|
|
508
|
+
Each tool spawns the packaged binary and formats the JSON it prints; none of the
|
|
509
|
+
guarantees (byte budget, `flock`, process-group cleanup, 0600 artifacts) is
|
|
510
|
+
re-implemented in TypeScript, so the plugin and the binary cannot disagree about
|
|
511
|
+
what "stale" or "truncated" means. Cancelling a tool call sends TERM to the applet
|
|
512
|
+
and KILL after two seconds, and the applet cleans up its own process group.
|
|
513
|
+
|
|
514
|
+
The exact argv, JSON field names, exit codes and payload shapes this plugin depends
|
|
515
|
+
on are written down for the upstream repository in
|
|
516
|
+
[`BUSYBOX-CONTRACT.md`](./BUSYBOX-CONTRACT.md), with
|
|
517
|
+
`scripts/capture-busybox-contract.sh` to re-capture them from any build. Two shapes
|
|
518
|
+
in that document differ from the binary's own design notes and are only right there
|
|
519
|
+
because they were captured: `peek`'s `next` is `{"from_byte":N}`, not a number, and
|
|
520
|
+
a zero-match `replace` answers `INVALID_ARGUMENT` with an empty message rather than
|
|
521
|
+
`NOT_FOUND`.
|
|
522
|
+
|
|
523
|
+
**Known build bug in the packaged binary:** `run --format json` prints an invalid
|
|
524
|
+
payload when the view is truncated (the head and the tail become two adjacent quoted
|
|
525
|
+
strings). The metadata is intact and the capture is complete, so `busybox_run`
|
|
526
|
+
recovers the fields and points at `run_id` for the view; it never re-runs the
|
|
527
|
+
command, because that repeats its side effects. `log --format json` and
|
|
528
|
+
`peek --format json` are unaffected.
|
|
529
|
+
|
|
530
|
+
## Verification
|
|
531
|
+
|
|
532
|
+
Every archive is checked against the sha256 digest GitHub records for the
|
|
533
|
+
release asset, **before** it is extracted. That digest is computed by GitHub at
|
|
534
|
+
upload time, so it does not depend on the project publishing sidecar checksums —
|
|
535
|
+
`fd` and `bat` publish none at all. It also means a compromised release page
|
|
536
|
+
cannot pass by replacing a binary and its `.sha256` sidecar together.
|
|
537
|
+
|
|
538
|
+
Verification is **fail-closed**:
|
|
539
|
+
|
|
540
|
+
- a digest mismatch fails the install and keeps the previous binary;
|
|
541
|
+
- a release API that cannot be reached fails the install rather than guessing;
|
|
542
|
+
- an asset published without a digest fails the install.
|
|
543
|
+
|
|
544
|
+
The single opt-out is `PI_MANAGED_TOOLS_ALLOW_UNVERIFIED=1`, which installs the
|
|
545
|
+
archive and records its digest anyway. Such an install is reported as
|
|
546
|
+
`UNVERIFIED` rather than `verified`, including in the TUI update line.
|
|
547
|
+
|
|
548
|
+
Digests are read from `api.github.com`, whose anonymous quota is 60 requests per
|
|
549
|
+
hour **per IP** and shared with everything else on the host. A verification only
|
|
550
|
+
runs when an update is actually downloaded, so a normal cycle costs one request
|
|
551
|
+
per outdated tool. If the quota is exhausted, installs fail closed with a
|
|
552
|
+
message saying so; set `GITHUB_TOKEN` (or `GH_TOKEN`) to raise the limit. The
|
|
553
|
+
installed binaries are never damaged by a failed verification.
|
|
554
|
+
|
|
555
|
+
After the swap the installed binary is **executed** and its version read back. A
|
|
556
|
+
binary that cannot run — wrong architecture, glibc against a musl build, a
|
|
557
|
+
truncated download — is rolled back to the previous copy and reported as a
|
|
558
|
+
failure. Reporting the version that was requested instead would claim success
|
|
559
|
+
for a dead file.
|
|
560
|
+
|
|
561
|
+
Installs land through a staged file on the same filesystem, so a failed download
|
|
562
|
+
or extraction never leaves a partial binary where pi expects a working one. On
|
|
563
|
+
POSIX the final rename replaces the old inode atomically, so a running pi keeps
|
|
564
|
+
working.
|
|
565
|
+
|
|
566
|
+
## Install
|
|
567
|
+
|
|
568
|
+
```bash
|
|
569
|
+
pi install npm:@rob-c/pi-managed-tools
|
|
570
|
+
pi list # shows the package
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
Then in a session:
|
|
574
|
+
|
|
575
|
+
```text
|
|
576
|
+
/managed-tools # status: versions, path, and any damaged binary
|
|
577
|
+
/managed-tools update # download the latest releases now
|
|
578
|
+
/managed-tools reinstall # replace every managed binary that cannot run
|
|
579
|
+
/managed-tools reinstall bat # force one tool to be re-downloaded
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
The model can do the same through the `managed_tools` tool (`action: "status"`,
|
|
583
|
+
optionally `check_latest: false` to stay offline; `action: "update"`; or
|
|
584
|
+
`action: "reinstall"` with an optional `tool`).
|
|
585
|
+
|
|
586
|
+
### Repairing a damaged binary
|
|
587
|
+
|
|
588
|
+
A managed binary can be broken without looking broken: truncated by a killed
|
|
589
|
+
download, left behind by a disk error, or copied from another architecture. A
|
|
590
|
+
version check misses all three, because the file is still at the expected path.
|
|
591
|
+
`status` therefore *executes* each managed binary and flags any that fail to run:
|
|
592
|
+
|
|
593
|
+
```text
|
|
594
|
+
bat: installed 0.26.1 - DAMAGED (present but does not execute); run reinstall
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
`/managed-tools reinstall` with no argument replaces only those. Naming a tool
|
|
598
|
+
forces a fresh download even when the version already matches upstream, which is
|
|
599
|
+
what you want when the file is wrong in a way that still reports a version.
|
|
600
|
+
|
|
601
|
+
Bundled shims are covered. `ast-grep`'s archive also installs `sg`, a deprecated
|
|
602
|
+
alias that is a small binary which **execs `ast-grep`** — so it dies the moment
|
|
603
|
+
its sibling is missing or unreadable. `status` probes every name an archive
|
|
604
|
+
provides and names the broken one:
|
|
605
|
+
|
|
606
|
+
```text
|
|
607
|
+
ast-grep: installed 0.51.3 - DAMAGED (sg does not execute); run reinstall
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
`/managed-tools reinstall sg` resolves to `ast-grep`, because that archive is
|
|
611
|
+
where `sg` comes from, and reinstalls the bundle.
|
|
612
|
+
|
|
613
|
+
An install is atomic per archive: every target is backed up, swapped, then
|
|
614
|
+
probed, and any failure restores all of them. A broken shim in a release can
|
|
615
|
+
never leave a new primary beside a dead one.
|
|
616
|
+
|
|
617
|
+
A repair still verifies the archive digest, still rolls back if the new binary
|
|
618
|
+
will not run, and falls back to the version already on disk when the release
|
|
619
|
+
lookup fails — so it works with a broken network, which is when a repair is most
|
|
620
|
+
likely to be needed.
|
|
621
|
+
|
|
622
|
+
To remove it: `pi remove npm:@rob-c/pi-managed-tools`.
|
|
623
|
+
|
|
624
|
+
To use the same binaries in your own shell (pi only adds them to the `PATH` of
|
|
625
|
+
its own `bash` tool):
|
|
626
|
+
|
|
627
|
+
```bash
|
|
628
|
+
export PATH="$HOME/.pi/agent/bin:$PATH" # add to ~/.zshrc or ~/.bashrc
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
Because pi searches that directory first, a managed copy **shadows** a copy you
|
|
632
|
+
installed yourself with Homebrew, cargo, `uv`, or a version manager. That is the
|
|
633
|
+
point for `fd`/`rg`/`bat`; if you deliberately pin `prek` to a specific
|
|
634
|
+
version, check `/managed-tools` before assuming which binary ran.
|
|
635
|
+
|
|
636
|
+
## What a session start does
|
|
637
|
+
|
|
638
|
+
0. `PATH` is rebuilt as `<agent dir>/bin : <agent dir>/busybox-applets : rest`, and
|
|
639
|
+
the applet directory is re-synced against the installed busybox (one
|
|
640
|
+
`busybox --list`, a readdir, and only symlinks touched). Local, so it happens
|
|
641
|
+
even when no network check is due.
|
|
642
|
+
1. A managed binary is missing, or the last check is older than the interval:
|
|
643
|
+
resolve `https://github.com/<repo>/releases/latest` (the redirect, not the
|
|
644
|
+
rate-limited API; the API is only a fallback).
|
|
645
|
+
2. Each binary whose installed version is older — or absent — is downloaded,
|
|
646
|
+
verified against GitHub's digest, extracted and renamed into place. The
|
|
647
|
+
archive is fetched and unpacked inside the bin directory so the final rename
|
|
648
|
+
stays on one filesystem and cannot leave a truncated binary where pi expects
|
|
649
|
+
a working one.
|
|
650
|
+
3. The result is recorded in `<agent dir>/bin/.pi-managed-tools.json`, which is
|
|
651
|
+
what the interval is measured against.
|
|
652
|
+
4. Otherwise nothing happens and no network request is made.
|
|
653
|
+
|
|
654
|
+
Status lines are shown in the TUI only when something changed. Print mode
|
|
655
|
+
(`pi -p`) still updates, silently.
|
|
656
|
+
|
|
657
|
+
A tool with no release for the current platform is skipped and does **not**
|
|
658
|
+
force a check on every start. `sd` publishes no `aarch64-pc-windows-msvc` archive, so
|
|
659
|
+
on Windows on ARM it is reported as unsupported while the others keep working. `sd` has no Windows arm64 build either, `busybox` has no Windows
|
|
660
|
+
build at all, and `difftastic` uses the gnu Linux build because it publishes no
|
|
661
|
+
linux-arm64 musl asset.
|
|
662
|
+
|
|
663
|
+
## Configuration
|
|
664
|
+
|
|
665
|
+
| Variable | Default | Meaning |
|
|
666
|
+
|---|---|---|
|
|
667
|
+
| `PI_MANAGED_TOOLS` | on | `off`/`0`/`false` disables the startup check (the `/managed-tools update` command and `managed_tools` tool still work) |
|
|
668
|
+
| `PI_MANAGED_TOOLS_INTERVAL_HOURS` | `12` | Minimum hours between startup checks; `0` checks every start |
|
|
669
|
+
| `PI_MANAGED_TOOLS_ALLOW_UNVERIFIED` | unset | `1`/`true`/`yes` installs an archive whose digest cannot be confirmed |
|
|
670
|
+
| `PI_MANAGED_TOOLS_REWRITE` | on | `off`/`0`/`false` disables rewriting absolute tool paths in bash tool calls |
|
|
671
|
+
| `PI_MANAGED_TOOLS_WRAP` | on | `off`/`0`/`false` stops wrapping bash commands (no timeline, no unbuffered environment) |
|
|
672
|
+
| `PI_MANAGED_TOOLS_VERBOSITY` | `normal` | `quiet` (6 KB view), `normal` (48 KB), `verbose` (49 KB, the most pi passes on) or `brief` (repeats collapsed, no timeline); `/managed-tools verbosity` overrides it for one session |
|
|
673
|
+
| `PI_MANAGED_TOOLS_EXTRA_ENV` | unset | Extra `NAME=VALUE,NAME2=VALUE2` pairs for wrapped commands, after the wrapper's own, so a pair here wins (`STDBUF1=F`) |
|
|
674
|
+
| `PI_MANAGED_TOOLS_UNBUFFER` | on | `off` leaves every program's output buffering as it is (see Buffering) |
|
|
675
|
+
| `PI_MANAGED_TOOLS_PRELOAD` | off | `on` preloads GNU coreutils' `libstdbuf.so` on Linux so C-stdio programs line-buffer too |
|
|
676
|
+
| `PI_MANAGED_TOOLS_GUARD` | on | `off` disables both refusals: a stream merge at a command's tail, and a command that cannot end |
|
|
677
|
+
| `PI_MANAGED_TOOLS_COMPACT_STAMPS` | on | `off` prints the full offset on every line instead of `[= out]` within a burst |
|
|
678
|
+
| `PI_MANAGED_TOOLS_AGE_OUT` | on | `off` keeps the offsets of results older than the latest compaction |
|
|
679
|
+
| `PI_MANAGED_TOOLS_USER_STDIN` | on | `off` runs `!` commands as before: stdin empty, output at exit |
|
|
680
|
+
| `PI_MANAGED_TOOLS_STDIN_TIMEOUT` | `300` | Seconds a `!` command may wait for you to answer before it is stopped; `0` waits for ever |
|
|
681
|
+
| `PI_MANAGED_TOOLS_APPLETS` | `core` | BusyBox applet names to link into `<agent dir>/busybox-applets`: `core` (curated), `all` (every applet except the never-list), `off` (none) |
|
|
682
|
+
| `GITHUB_TOKEN` / `GH_TOKEN` | unset | Optional. Raises the 60/hour anonymous quota used to read release digests |
|
|
683
|
+
| `PI_OFFLINE` | unset | Same `1`/`true`/`yes` values pi itself honours; disables startup checks |
|
|
684
|
+
|
|
685
|
+
Every one of these can also be set once, in pi's own settings file (global or project),
|
|
686
|
+
under a `managedTools` block — an exported variable still wins for one run:
|
|
687
|
+
|
|
688
|
+
```json
|
|
689
|
+
{ "managedTools": { "verbosity": "quiet", "timeout": 300, "preload": true, "extraEnv": "STDBUF1=F" } }
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
The keys are `wrap`, `verbosity`, `pty`, `timeout`, `idle`, `guard`, `unbuffer`, `preload`,
|
|
693
|
+
`extraEnv`, `userWrap`, `userStdin`, `stdinTimeout`, `compactStamps`, `ageOut` and `rewrite`.
|
|
694
|
+
A `/managed-tools verbosity` or `pty` switch is recorded in the session, so a resumed
|
|
695
|
+
session keeps it.
|
|
696
|
+
|
|
697
|
+
## Platform support
|
|
698
|
+
|
|
699
|
+
Downloads match what pi would have fetched itself:
|
|
700
|
+
|
|
701
|
+
| Platform | Archive |
|
|
702
|
+
|---|---|
|
|
703
|
+
| macOS (arm64 / x64) | `…-apple-darwin.tar.gz` |
|
|
704
|
+
| Linux (arm64 / x64, musl) | `…-unknown-linux-musl.tar.gz` |
|
|
705
|
+
| Windows (arm64 / x64) | `…-pc-windows-msvc.zip` |
|
|
706
|
+
|
|
707
|
+
Other architectures are left alone: these projects publish no matching prebuilt
|
|
708
|
+
binary and pi does not guess one either. Three of the projects deviate from the
|
|
709
|
+
Rust triple convention and are handled per tool:
|
|
710
|
+
|
|
711
|
+
| Tool | Asset scheme | Notable gaps |
|
|
712
|
+
|---|---|---|
|
|
713
|
+
| `gron` | `gron-<os>-<go arch>-<version>.tgz` (`.zip` on Windows) | no 32-bit arm |
|
|
714
|
+
| `shellcheck` | `shellcheck-v<ver>.<os>.<arch>.tar.gz` | one arch-less `.zip` for Windows x64 only |
|
|
715
|
+
| `ast-grep` | `app-<rust triple>.zip` (zip on every platform) | none |
|
|
716
|
+
| `just` | `just-<ver>-<rust triple>` | none |
|
|
717
|
+
| `ninja` | `ninja-mac.zip` / `ninja-linux.zip` / `ninja-linux-aarch64.zip` / `ninja-win.zip` / `ninja-winarm64.zip` | none; the macOS asset is universal2, so one file covers x86_64 and arm64 |
|
|
718
|
+
| `jq` | bare executable: `jq-macos-arm64`, `jq-linux-amd64` | no archive at all — the download is the binary |
|
|
719
|
+
| `yq` | bare executable: `yq_darwin_arm64`, `yq_linux_amd64` | no archive at all |
|
|
720
|
+
| `fzf` | `fzf-<ver>-darwin_arm64.tar.gz` (`.zip` on Windows) | none |
|
|
721
|
+
| `uv` | `uv-<rust triple>.tar.gz` / `.zip` | archive also contains `uvx` |
|
|
722
|
+
| `gh` | `gh_<ver>_linux_amd64.tar.gz`, `gh_<ver>_macOS_arm64.zip` | macOS ships a **zip**, Linux a tar.gz |
|
|
723
|
+
| `bd` | `beads_<ver>_darwin_arm64.tar.gz` | assets are named after the project, the binary is `bd`; Dolt is embedded |
|
|
724
|
+
| `agent-browser` | bare executable `agent-browser-darwin-arm64` | `x64` not `amd64`; **no win32-arm64** |
|
|
725
|
+
| `ruff` | `ruff-<rust triple>` | bare version tags |
|
|
726
|
+
| `mise` | `mise-v<ver>-macos-arm64.tar.gz` | dated tags; binary nests at `mise/bin/mise` |
|
|
727
|
+
| `scc` | `scc_Darwin_arm64.tar.gz` | capitalised OS, underscore, no version |
|
|
728
|
+
| `duckdb` | `duckdb-cli-osx-arm64.tar.gz` | says `osx`/`amd64`; bare binary in the archive |
|
|
729
|
+
| `miller` | `miller-6.22.0-darwin-arm64.tar.gz` | installs `mlr`, not `miller` |
|
|
730
|
+
| `sd` | `sd-v1.1.0-aarch64-apple-darwin.tar.gz` | keeps the `v`; **binary reports 1.0.0 for tag 1.1.0** |
|
|
731
|
+
| `difftastic` | `difft-0.72.0-aarch64-apple-darwin.tar.gz` | installs `difft`; linux uses gnu |
|
|
732
|
+
| `busybox` | `busybox-static-1.39.0-aac079e-darwin-universal` | bare binary; one universal2 mac asset; **no Windows build** |
|
|
733
|
+
|
|
734
|
+
`gron`'s release build reports no version at all (`gron version dev`), so its
|
|
735
|
+
installed version is recorded in the state file rather than read back from the
|
|
736
|
+
binary.
|
|
737
|
+
|
|
738
|
+
`rtk` is **no longer installed** by this package (see the note below the table). It
|
|
739
|
+
used to come from the `rtk-oss-` family — the plain `rtk-<target>` release bundles a
|
|
740
|
+
BUSL-1.1 engine (`LICENSE-ENGINE`), which is why the OSS build was used. `rtk-oss-` is the
|
|
741
|
+
Apache-2.0-only build of the same tool, with the same binary name and version
|
|
742
|
+
banner. Nothing here is redistributed — the binary is fetched from GitHub on the
|
|
743
|
+
user's own machine — but the distinction is kept explicit so the default install
|
|
744
|
+
is not silently pulling a source-available component.
|
|
745
|
+
|
|
746
|
+
## Layout
|
|
747
|
+
|
|
748
|
+
```
|
|
749
|
+
package.json pi manifest: loads src/extension.ts
|
|
750
|
+
src/extension.ts session_start check, PATH + applet sync, command and tools
|
|
751
|
+
src/tools.ts registry, release targets, digests, download/extract/install, cooldown,
|
|
752
|
+
busybox applet directory and PATH ordering
|
|
753
|
+
src/agentops.ts the agent-facing wrappers: argv, JSON, formatters, salvage, cancellation
|
|
754
|
+
BUSYBOX-CONTRACT.md what the binary must keep providing (handed to the busybox repo)
|
|
755
|
+
skills/managed-tools/ always-advertised short skill
|
|
756
|
+
skills/managed-tools-reference/ exact flags and examples per tool
|
|
757
|
+
tests/tools.test.ts offline tests: fixtures are real archives served by a fake fetch
|
|
758
|
+
tests/extension.test.ts loads the extension against a stand-in pi and agent directory
|
|
759
|
+
tests/agentops.test.ts wrapper argv/formatters plus a stand-in multicall binary
|
|
760
|
+
tests/skills.test.ts keeps the two skills in step with the tool registry
|
|
761
|
+
scripts/verify.sh runs the installed plugin inside the pi on PATH
|
|
762
|
+
scripts/capture-busybox-contract.sh re-captures every invocation and payload
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
## Does Pi-Time help the model?
|
|
766
|
+
|
|
767
|
+
A paired probe answers it with numbers instead of opinion: `npm run measure:timing`
|
|
768
|
+
(`-- --runs N`, `-- --keep`). One command (prints at 0 s, warns on stderr at 2 s, prints at
|
|
769
|
+
8 s) plus five questions whose answers are known, run with the wrapper on and off, same
|
|
770
|
+
model, alternating order.
|
|
771
|
+
|
|
772
|
+
| fact | wrapped | plain capture |
|
|
773
|
+
|---|---|---|
|
|
774
|
+
| order of the stderr line vs the first stdout line | 3/3 | **0/3** — reports "before", truth is "after" |
|
|
775
|
+
| which stream carried the warning | 3/3 | 3/3 (a lucky prior) |
|
|
776
|
+
| seconds between first and last line | 3/3 | 0/3 |
|
|
777
|
+
| where the longest silence was | 3/3 | 1/3 |
|
|
778
|
+
| streamed or flushed at exit | 3/3 | 1/3 |
|
|
779
|
+
| **total** | **15/15** | **5/15** |
|
|
780
|
+
|
|
781
|
+
The plain arm is wrong rather than vague: block-buffered stdout only appears at exit, so
|
|
782
|
+
the merged capture shows the stderr line first and a reader repeats that. The script prints
|
|
783
|
+
the observed order for each arm (`on: phase1 first (true order)` / `off: deprecated first
|
|
784
|
+
(inverted)`), so that claim is one command away rather than a claim about a temp file. The
|
|
785
|
+
timing questions come back as "undetermined — no timestamps". Both arms used one bash call,
|
|
786
|
+
so this is about the quality of one answer, not extra turns.
|
|
787
|
+
|
|
788
|
+
n=3, one model, one prompt shape — it shows the direction and the mechanism, not an effect
|
|
789
|
+
size. One trap for anyone re-running it: a probe launched from inside a wrapped bash call
|
|
790
|
+
inherits `PYTHONUNBUFFERED=1` and the plain arm silently becomes unbuffered; the script
|
|
791
|
+
strips the wrapper's variables first.
|
|
792
|
+
|
|
793
|
+
## Testbench
|
|
794
|
+
|
|
795
|
+
`npm test` covers the pure logic against stand-ins. `npm run testbench` drives the
|
|
796
|
+
*installed* extension through pi's real bash engine and the real busybox — no model in the
|
|
797
|
+
loop — so a failure is a bug rather than a prompt misunderstanding:
|
|
798
|
+
|
|
799
|
+
```sh
|
|
800
|
+
npm run testbench # 17 scenarios, ~30s
|
|
801
|
+
npm run testbench -- --list
|
|
802
|
+
npm run testbench -- --only pty # scenarios whose name matches
|
|
803
|
+
npm run testbench -- --verbose # every check, not only the failures
|
|
804
|
+
npm run testbench -- --keep # keep the scratch dirs
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
Each scenario runs in its own process with its own scratch `<agent dir>` — containing a
|
|
808
|
+
space, on purpose — and its own `TMPDIR`, so the wrapper's quoting, the applet symlinks and
|
|
809
|
+
the run-artifact sweep are exercised the way a real install exercises them. The checks
|
|
810
|
+
assert on tool results and exit codes, never on what a model said.
|
|
811
|
+
|
|
812
|
+
It found: an empty busybox silently silencing every command, zip installs broken by the
|
|
813
|
+
plugin's own `unzip` symlink, a truncated view with no way back, `busybox_run` losing its
|
|
814
|
+
timeline and looking for a match in stdout only, and unbounded run artifacts.
|
|
815
|
+
|
|
816
|
+
## Tests
|
|
817
|
+
|
|
818
|
+
```bash
|
|
819
|
+
npm test # node --test; no network access
|
|
820
|
+
npm run typecheck # tsc --noEmit
|
|
821
|
+
./scripts/verify.sh # end-to-end inside the installed pi (needs a model key)
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
The suite builds real `tar.gz` release archives in a temp directory, serves them
|
|
825
|
+
through a stub `fetch` that also synthesises the release API response from the
|
|
826
|
+
same bytes, and asserts the installed binary runs, reports the expected version,
|
|
827
|
+
replaces the old copy, and leaves no archive or staging directory behind. The
|
|
828
|
+
stub computes real digests, so verification is exercised rather than bypassed:
|
|
829
|
+
a tampered asset, a missing digest, and a binary that exits without printing a
|
|
830
|
+
version are each asserted to fail without damaging the installed copy. A second
|
|
831
|
+
file loads the extension itself against a stand-in `pi` to check registration,
|
|
832
|
+
the command, the tool, and that a startup inside the check interval, or with
|
|
833
|
+
`PI_MANAGED_TOOLS=off`/`PI_OFFLINE`, makes no network request at all.
|
|
834
|
+
|
|
835
|
+
## Licence
|
|
836
|
+
|
|
837
|
+
GPL-2.0-only. See [LICENSE](LICENSE).
|
|
838
|
+
|
|
839
|
+
This is a deliberate choice: the plugin itself is copyleft, so anyone distributing a
|
|
840
|
+
modified version must publish their source under the same terms.
|
|
841
|
+
|
|
842
|
+
Two things it does not cover, both by design:
|
|
843
|
+
|
|
844
|
+
- **The binaries it downloads are not distributed here.** `shellcheck` (GPL-3.0) and
|
|
845
|
+
`busybox` (GPL-2.0) among them are fetched from their own upstream releases onto
|
|
846
|
+
the user's machine. Bundling any of them into this package would create a licence
|
|
847
|
+
conflict, so don't.
|
|
848
|
+
- **pi itself is MIT** and is declared as a `peerDependency`, never bundled. Its own
|
|
849
|
+
dependency tree contains Apache-2.0 packages, which is fine precisely because none
|
|
850
|
+
of it ships in this tarball.
|