Install
Install with PiG
pig install npm:@rob-c/pi-managed-toolsInstall with Pi
pi install npm:@rob-c/pi-managed-toolsPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"skills": [
"./skills"
],
"extensions": [
"./src/extension.ts"
],
"changelogPath": "./CHANGELOG.md"
}README
Written by the package's publisher, shown as published in version 0.25.0 (README.md). PiG does not review it.
pi-managed-tools
Published as @rob-c/pi-managed-tools on npm; Install is four commands
below. The unscoped pi-managed-tools name was an earlier publish of the same code and is
deprecated; do not use it.
Install
Requires pi, Node 22.19 or newer (engines in package.json), and macOS, Linux or
Windows. There is nothing for npm to resolve: the plugin has no runtime dependencies, and
its own weight — the managed binaries, busybox included — is downloaded from GitHub
releases on the first session start, not by the install.
From npm
pi install npm:@rob-c/pi-managed-tools
pi list # the package appears under "User packages"
Add -l (--local) to install it for one project instead, recorded in that project's
.pi/settings.json — the way to pin a team to one tool set:
pi install npm:@rob-c/pi-managed-tools -l
Either way the extension is loaded by the next pi session; a running session is not retro-fitted.
From a checkout (development)
A local path needs no publish step — nothing is copied, so the working tree is the
installed version and an edit under src/ is live in the next pi process:
git clone https://github.com/rob-c/pi-managed-tools
cd pi-managed-tools && npm run typecheck && npm test # no network
pi install ./pi-managed-tools
pi update --extensions prints nothing for a local path by design: there is nothing to
download, and package.json is the version that runs.
What the first session does
On start the plugin resolves each project's latest release and downloads only what is
missing into <agent dir>/bin — ~/.pi/agent/bin on macOS and Linux,
%USERPROFILE%\.pi\agent\bin on Windows — then records the versions in
<agent dir>/bin/.pi-managed-tools.json. Later starts re-check at most once every 12 hours
(PI_MANAGED_TOOLS_INTERVAL_HOURS) and make no network request when there is nothing to do.
busybox is fetched the same way; without it the timeline wrapper turns itself off rather
than failing, so a failed download degrades instead of breaking bash.
Check that it is working
/managed-tools # versions, path, and any damaged binary
/managed-tools update # run the check now
/managed-tools reinstall # replace every managed binary that cannot run
/managed-tools reinstall bat # force one tool to be re-downloaded
The model can do the same through the managed_tools tool (action: "status", optionally
check_latest: false to stay offline; action: "update"; action: "reinstall" with an
optional tool).
A working install also shows up in the system prompt of every session: "Commands run under
pi's own shell, with …/.pi/agent/bin first on PATH". If that sentence is absent, the
extension did not load — check pi list and the pi version rather than the binaries.
Upgrading
pi update --extension npm:@rob-c/pi-managed-tools # this package only
pi update --extensions # every installed package
That moves the extension code. The binaries update themselves at session start, and
/managed-tools update forces that check.
Uninstalling
pi remove npm:@rob-c/pi-managed-tools # add -l if it was installed locally
The downloaded binaries are left in <agent dir>/bin: they sit first on pi's PATH and
other packages may use them. Delete the ones you do not want by hand; keeping busybox is
what keeps the timeline working.
If something goes wrong
| Symptom | Cause and fix |
|---|---|
pi install refuses the Node version | Node older than 22.19; upgrade Node |
no /managed-tools command | the extension did not load — pi list should show it, then restart pi |
| nothing downloaded on the first start | PI_MANAGED_TOOLS=off or PI_OFFLINE=1; /managed-tools update runs it anyway |
| a managed binary will not run | /managed-tools reinstall — see Repairing a damaged binary |
bash output arrives without a timeline | PI_MANAGED_TOOLS_WRAP=off, or busybox is missing or failed its self-test — /managed-tools names which |
Why this package exists
Pi ships no fd and no rg binary. It downloads exactly two static binaries on
demand, into the directory it searches first, and uses them for two built-in
tools:
| Tool | From | Used by | Installed to |
|---|---|---|---|
fd | sharkdp/fd | the find tool | <agent dir>/bin/fd (fd.exe on Windows) |
rg (ripgrep) | BurntSushi/ripgrep | the grep tool | <agent dir>/bin/rg (rg.exe on Windows) |
bat | sharkdp/bat | bash only | <agent dir>/bin/bat |
prek | j178/prek | bash only | <agent dir>/bin/prek |
just | casey/just | bash only | <agent dir>/bin/just |
gron | tomnomnom/gron | bash only | <agent dir>/bin/gron |
shellcheck | koalaman/shellcheck | bash only | <agent dir>/bin/shellcheck |
ast-grep | ast-grep/ast-grep | bash only | <agent dir>/bin/ast-grep and sg |
ninja | ninja-build/ninja | bash only | <agent dir>/bin/ninja |
jq | jqlang/jq | bash only | <agent dir>/bin/jq |
yq | mikefarah/yq (v4, Go) | bash only | <agent dir>/bin/yq |
fzf | junegunn/fzf | bash only | <agent dir>/bin/fzf |
uv | astral-sh/uv | bash only | <agent dir>/bin/uv and uvx |
gh | cli/cli | bash only | <agent dir>/bin/gh |
bd | gastownhall/beads | bash only | <agent dir>/bin/bd |
agent-browser | vercel-labs/agent-browser | bash only | <agent dir>/bin/agent-browser |
ruff | astral-sh/ruff | bash only | <agent dir>/bin/ruff |
mise | jdx/mise | bash only | <agent dir>/bin/mise |
scc | boyter/scc | bash only | <agent dir>/bin/scc |
duckdb | duckdb/duckdb | bash only | <agent dir>/bin/duckdb |
miller | johnkerl/miller | bash only | <agent dir>/bin/mlr |
sd | chmln/sd | bash only | <agent dir>/bin/sd |
difftastic | Wilfred/difftastic | bash only | <agent dir>/bin/difft |
busybox | 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) |
That download logic lives in dist/utils/tools-manager.js of
@earendil-works/pi-coding-agent: ensureTool() downloads the latest release
only when the file is missing, and getToolPath() prefers <agent dir>/bin
over anything on PATH. So a machine that installed pi a year ago keeps
whatever fd/rg release it fetched then, however many newer releases exist.
rtk is no longer part of this package. It is not downloaded, updated or
advertised any more: summarising output is a preference, not a pinned binary, and a proxy
that rewrites what a command printed is the wrong default for a model that must read
diffs and edit files. An existing <agent dir>/bin/rtk is left alone — nothing reads it,
and managed_tools will not mention it.
This package fills that gap. On a session start (at most once per interval) it
resolves the latest release of each project, compares it with the managed copy,
and replaces the copy in place — the same path pi already uses. pi's find and
grep tools call getToolPath() for every run, and pi puts <agent dir>/bin
first on the PATH of every bash command it runs, so both see the new binary
immediately.
Note that find and grep are not enabled by default: pi's defaultTools is
read, bash, edit, write. Turn them on with pi --tools +grep,+find or
"defaultTools": ["+grep", "+find"] in settings (see docs/settings.md
inside the pi package). The binaries and the update are the same either way —
pi's interactive mode prepares them at startup regardless of which tools are
enabled.
Only fd and rg back a pi built-in tool. Everything else is installed so
bash commands can use it, and /managed-tools reports that distinction rather
than implying otherwise.
tree is not here
Upstream (Old-Man-Programmer/tree) publishes git tags but no release
assets, so there is no binary to download and nothing to verify. fd -d 2 -td
covers most of what tree is used for, from a binary this package already
manages.
Command shadowing
pi searches <agent dir>/bin first, then <agent dir>/busybox-applets (the
curated applet names, see BusyBox applet names on PATH), then the user's own
PATH entries, so these win over anything else. That is intended for
fd/rg/bat. Two cases are worth knowing:
ast-grepalso installs its deprecatedsgshim, which shadows util-linux's/usr/bin/sgon Linux (the group-switching helper used bynewgrp). Delete<agent dir>/bin/sgif you need the system one.git,python3,node,treeand the rest of the toolchain still come from the system. Nothing here replaces an interpreter — their versions belong to each project's lockfile.uvis the one exception in spirit: it is a package manager, so it creates its own Python toolchains and caches outside this bin directory. Preferuv run <cmd>so the project's pinned version is used.yqhere is mikefarah/yq v4 (Go).kislyuk/yqis a different tool with different flags and no releases of this shape.ghis credential-bearing: it keeps an OAuth token in~/.config/gh/hosts.yml. Its downloads are digest-verified like every other tool, but auto-updating a binary that holds a token is a trust decision worth making deliberately.fzfneeds a TTY for interactive use, and pi'sbashtool does not provide one.fzf --filterworks; the interactive picker does not.bd initmutates the project. It creates.beads/with an embedded Dolt database, rewritesAGENTS.mdby default, and installs editor/agent integration files unless given--skip-agentsor--stealth.bd setup <tool>writes those integration files too. The read-only commands (list,show,status,query) are safe.bdsends anonymous usage metrics by default — command names, version and OS platform, not issues or paths. SetDO_NOT_TRACK=1to disable it. That is the user's decision, so this package does not set it for you.agent-browserneeds a browser and leaves a daemon running. It drives a local Chrome/Chromium (or an existing one viaconnect), keeps state across invocations through a background daemon, andclose --allstops it. Its ownagent-browser skills get corefails on this build — the release binary ships no skills directory, whatever--helpclaims. No win32-arm64 release.miseis a version manager. A managed copy sits ahead of whatever the user installed, and itsactivateshell hook never runs in pi'sbash, so onlymise exec -- <cmd>reliably picks up a project's pins. It installs toolchains under~/.local/share/mise, outside this bin directory. This is the one entry here that deliberately manages a tool whose job is managing other versions.busyboxis a multicall binary that dispatches onargv[0], so it is only installed under the namebusybox— renaming or copying it breaks every applet. Use it asbusybox <applet>, or by the bare applet name for the 62 in the curated list (below). Never runbusybox --install -s <dir>: in pi's bin directory, which is first onPATH, that would put 276 applets ahead of the real coreutils, includingsh,rm,mountandinit. The package links a curated set into its own directory instead. Per-applet read-only vs mutating classification is in thebusybox-appletsskill.sdrewrites files in place. With no file arguments it filters stdin to stdout, butsd FIND REPLACE file...edits those files. Use-pto preview. Its release binary also reportssd 1.0.0for tagv1.1.0; the tag is trusted for version comparison (the digest already proves the asset), so it does not reinstall in a loop.duckdbprints an agent-mode banner before every result whenAI_AGENTis set and stdout is not a terminal — which is always true inside pi. Pass-no-agent(or setDUCKDB_AGENT_MODE=0).ruffis normally pinned by the project. Preferuv run ruff ...so the version CI uses decides the rules; the managed copy is for a check outside a project environment, and should never rewrite files the project's own version would format differently.
Skills
The package ships two skills:
How it integrates with pi
Four surfaces, in order of how reliably they reach the model:
tool_call(deterministic) — an absolute host path for a managed binary is rewritten to its bare name before the command runs, so/usr/bin/jq -r .aexecutes asjq -r .aand the packaged build runs. Only command-position tokens are touched and only names this package manages (or links as an applet name), so/usr/bin/taris untouched.PI_MANAGED_TOOLS_REWRITE=offturns it off.- PATH (deterministic) — at session start the extension rebuilds
process.env.PATHas<agent dir>/bin : <agent dir>/busybox-applets : <user dirs> : <system dirs>, dropping any earlier occurrence of its own two entries first. pi'sgetShellEnv()re-reads that value for everybashspawn and only prepends the bin directory when it is absent, so this is the one hook that reaches every command — including the case where a shell rc appended$HOME/.pi/agent/bintoPATHand defeated pi's prepend. before_agent_start(deterministic) — the two environment rules are appended tosystemPromptOptions.promptGuidelines, and amanaged_tools_environmentsection states the facts outright: that the bin directory is first onPATH, which packaged versions that means, that the busybox applet names are onPATHas well, and that no probing turn is needed. Idempotent, and the section text is stable so pi does not re-patch it each turn.- Skills (opportunistic) — name, description and path are always in the system prompt; the body loads only when the model decides it is relevant, which it does not do for one-liners.
/managed-tools status reports how many absolute paths were rewritten this session,
how many applet names are linked (62 with the default policy), and what the installed
build says about itself (busybox --caps: version, applet count, features) — which is
the only honest answer when a binary was installed by hand ahead of a release.
BusyBox applet names on PATH
<agent dir>/busybox-applets holds symlinks named after applets, each pointing at
<agent dir>/bin/busybox, so xxd, hexdump, sha256sum, unzip, timeout and
57 more run without the busybox prefix. The links live in a second directory, not
in the bin directory, because PATH order is the only thing that decides which build
a bare name runs and two names in one directory have no order. The dedicated static
builds stay first.
The default list is curated, not "all 276":
- In when the host may not have the tool (
cpio,dpkg-deb,rpm2cpio,nproc,setsid,sha3sum,uuidgen,ipcalc,wget, ...), when the busybox implementation accepts the flags anyone actually passes (xxd,hexdump,od,strings,gzip,unzip,timeout, ...), or when it is an agent-facing applet with a distinctive name and no side effects (peek,waitfor,doctor,brief,why,patchcheck). - Out whenever a host build is near-universal and functionally richer, so no
working command changes meaning:
sed,grep,find,awk,tar,diff,ls,cat,cp,mv,rm,ln,chmod,stat,df,du,ps,kill,bc,mktemp,which,date,patchandtree(busyboxtreetakes a directory and no flags, so the usualtree -L 2fails). So doreplace,run,log,bench,check,jsonandsnapshot: some run a command, some write a file, and the rest are names a project script or another tool already owns. Everything left out stays reachable asbusybox <applet>, which is a deliberate act. - Never, under any policy: shells (
sh,ash,hush,login,su), boot and device administration (init,mount,mdev,sysctl,insmod), servers (httpd,telnetd,tftpd) and package managers (dpkg,rpm).
PI_MANAGED_TOOLS_APPLETS widens or disables it: all links every applet the
build has minus the never-list (the aggressive version, where busybox sed and
grep do win), off links nothing and leaves only the bin directory ahead. An
unrecognised value is the default, never a silent opt-in to all.
The always-on skill also pins two environment rules, because both are silent when
broken: call the packaged binaries by bare name (an absolute path like
/usr/bin/jq bypasses pi's PATH prepend and getToolPath()), and run multi-step
shell logic through busybox sh -c '…' so the shell does not depend on which
bash the host resolved. busybox sh covers [[ ]], <(…), <<<, $'…', local
and pipefail, but not arrays, ${v^^}, read -a, mapfile or coproc. The
curated applet names are bare on PATH too; the names that are not linked need the
busybox prefix.
managed-tools— always advertised. pi adds every skill's name and description to the system prompt and nothing else, so this description is the advert: it sets the preference order (these binaries over the system ones), names all twenty-four tools, and routes to the reference for flags.busybox-applets— loaded on demand, only when busybox is in play. All 276 applets classified read-only / mutating / destructive / exec, with the flags that cause a write, plus the contract the six agent-facing applets share.managed-tools-reference— loaded on demand. The exact flag set and one or two worked examples per tool, transcribed from the binaries this package installs rather than from upstream docs, because the versions are pinned.
Both skills say where reduction happens now that rtk is gone: busybox brief -d
collapses identical records without cutting one in half, -R keeps a stack trace as a
single record, and busybox_run retains the full capture in an artifact, so a reduced
view never destroys the evidence. Nothing here summarises a diff behind your back.
That pinning is the point: the tool surface is fully known at install time, so
the skills can state flag names instead of telling the model to run --help and
spend the tokens anyway. tests/skills.test.ts keeps them honest — adding a tool
without documenting it in both skills fails the suite, as does a description over
the Agent Skills 1024-character limit or a version list that disagrees between
the two files.
Pi-Time: every bash call is a timeline
Pi-Time is the name for what the wrapper gives the model: the concept of time, which a plain text capture of an execution does not carry — and which a hosted LLM needs to reason about a run instead of guessing. Three facts come back with every command, and each exists because its absence made the model misread an execution:
- Which stream. Every line is tagged
outorerr, so a warning on stderr is never misread as program output, and a tool's diagnostics keep their identity. A2>&1in the command destroys exactly this — it merges stderr into stdout inside the child, before the wrapper can tag anything — so the skills forbid it. - When. A microsecond offset on every line, and a
timing:digest on slow runs, so ordering, durations and silences are readable facts. A merged capture does not just lack them — it lies: block buffering puts a 0s stdout burst after an 8s stderr line, and the probe below shows a model repeating that inverted order. - How long is too long. A default deadline on every call, so a hang ends in a named
TIMEOUTstate with its partial capture intact, instead of minutes of silence or an exit code that reads like a failure.
Mechanically: pi's bash tool is re-registered (the supported override path: pi's own
runner with a spawn hook) so each command executes as
busybox run --timestamps ... -- /bin/bash -c '<command>'.
The model reads one interleaved line per record, with its offset in seconds and the stream it arrived on:
run=R134 exit_code=0 timed_out=false cancelled=false idle=false duration_ms=8421
timeline_lines=4 shown=4 truncated=false
--- timeline ---
[0.011354789 out] ok 1
[= out] ok 2
[2.320004125 err] FAILED test_x
[8.421130000 out] done
timing: 8.42s total, 4 lines, output from 0.01s, stderr from 2.32s, longest pause 6.10s (2.32s → 8.42s)
The child gets a pseudo-terminal (busybox run --pty-split): stdout on the pty, stderr
on a pipe. That is what makes the offsets honest: libc line-buffers when stdout is a
terminal, so a program that buffers on a pipe emits each line as it happens. A C program
printing three lines 1.2 s apart reported all three at 3.740564 on a pipe and at
0.004561 / 1.209525 / 2.414571 on the pty; Python and Ruby have environment switches
(the wrapper sets them too), C stdio, Java and Go's bufio have only this. stderr is
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
change: programs take their terminal path (colours are suppressed by NO_COLOR/
TERM=dumb, pagers by PAGER=cat). PI_MANAGED_TOOLS_PTY=off restores plain pipes;
merged gives 0/1/2 one pty; raw adds --pty-raw.
A run longer than a second also gets the timing: digest appended to the tool
result, for the model only: total, line count, where output began, and the longest
silence (or the silence after the last line). It is a derived line, not a replacement
for the offsets, and the renderer strips it for the human.
[= out] is a line that arrived at the same offset as the one above: within a burst the
offset is printed once, and the stream tag stays on every line. (Stamps were measured at
a quarter of all bash-result bytes; PI_MANAGED_TOOLS_COMPACT_STAMPS=off prints them in
full.) The exact shape of a stamp is the build's — padded to 0.6.0, unpadded since — so
the example the model is shown is cut from a line the installed binary really printed,
at session start.
That is the ordering a merged stdout/stderr block destroys: the failure came after
ok 1 and before done, and lines sharing one timestamp are a writer that flushed at
exit rather than streaming.
The human sees the command's own lines: the bash renderer strips the wrapper's
header, section markers and [0.012345789 out] prefixes, and keeps everything the
command printed — indentation, blank lines, a truncated view's ... [N bytes] ...
marker — plus pi's usual (full output: …) hint when pi truncates. The tool result is
untouched, so the model's copy and the session transcript keep the timeline; only the
rendering differs (TUI and HTML export).
The wrapper is transparent in the ways that matter: the child's exit status, cwd and
shell are unchanged (still /bin/bash, so [[ ]] and arrays keep working), and the
unbuffered environment travels with the command rather than being exported into pi:
PYTHONUNBUFFERED=1, PYTHONIOENCODING=utf-8, PYTHONDONTWRITEBYTECODE=1, NO_COLOR=1,
CLICOLOR=0, FORCE_COLOR=0, TERM=dumb, PAGER=cat, GIT_PAGER=cat,
GIT_TERMINAL_PROMPT=0, CARGO_TERM_COLOR=never, DEBIAN_FRONTEND=noninteractive,
MAVEN_ARGS=-B -ntp, GRADLE_OPTS=-Dorg.gradle.console=plain -Dorg.gradle.daemon=false,
and RUBYOPT=-r<agent dir>/pi-unbuffer.rb for Ruby's $stdout.sync. Where no switch
exists — Go's bufio.Writer, Java's System.out — the timeline shows the flush: every
line of a burst carries the same offset.
While a command runs you see its output as it arrives: run itself prints only at exit,
so the running view is read from the capture it writes (both streams, unterminated prompts
included) and drawn in the tool call; the model is sent only the final result.
Two escapes: PI_MANAGED_TOOLS_WRAP=off for the session, and # pitime-raw at the end
of one command, which runs that call unwrapped. Neither is needed for exact bytes: a
pipe, a redirect or a checksum inside a command sees the real bytes already, and only the
result read back carries the offsets. (command <cmd> was the per-call escape through
0.23.0. It is the shell's builtin, models write it to bypass an alias, and a third of one
measured session's calls lost their timeline to it; it now runs wrapped like anything else.)
The human's own ! commands go through the wrapper too (pi's user_bash hook hands the
local backend a wrapped command): the split pseudo-terminal and the unbuffered
environment, with the command's own bytes shown and nothing else — no timeline, because
the reader is a person in the TUI. No deadline is applied (a ! command belongs to its
owner, Ctrl-C included), the # pitime-raw escape falls through to pi's plain path, and
PI_MANAGED_TOOLS_USER_WRAP=off turns it off.
You can answer a ! command. pi starts every command with its stdin closed, so a
[y/N] prompt used to read end-of-file, take its default and exit 0; and busybox run -q
prints only when the command exits, so nothing was shown until then. Now:
- the output is shown as it arrives, an unfinished prompt line included (the run's capture files are followed while it runs);
- when the command looks like it is waiting — output stopped on an unfinished line, or
three seconds of silence — pi's input dialog opens, titled with the command. Enter sends
the line to the command, through
busybox run --stdinand the pty; the dialog reopens for the next question; - Esc in the dialog means "no more input": the command reads end-of-file and carries on, and you get the editor back. Esc again stops the command, as before;
- you have five minutes to answer — not the two a model's command gets, because this
clock times a person, not a program. The dialog's title counts down, and the clock runs
only while the dialog is open: a command that is working is never timed by it. When it
runs out the command is stopped, with exit status 124 and a line in its output
saying it waited and nobody typed. It is not given end-of-file instead, because a
[Y/n]prompt would read that as yes.PI_MANAGED_TOOLS_STDIN_TIMEOUT=<seconds>changes the wait;0waits for as long as it takes; - what you type is not added to the output, which is recorded in the session and read by the model — a password stays out of it. It is visible in the dialog while you type.
A command that draws to the whole screen (an editor, less, top) is still not something
a ! command can host. This path keeps no capture afterwards: the run's private folder is
removed when the command ends. PI_MANAGED_TOOLS_USER_STDIN=off restores the old
behaviour (stdin empty, output at exit, capture kept for busybox log).
The model cannot be answered by anyone, and is told so: its commands read end-of-file at
once, so it puts the answer in the command (printf 'y\n' | cmd, a heredoc, --yes) or
in busybox_run's stdin parameter.
Every wrapped command gets a 120-second deadline by default, so a hang cannot hold the
model in silence. A caller's own timeout still wins — the wrapper takes it over one
second earlier (--timeout N-1) because the applet's deadline cancels the child's process
group and still prints the timeline, while a SIGKILL from pi would print nothing at all.
PI_MANAGED_TOOLS_TIMEOUT=<seconds> changes the default for a session; 0 or off
removes it.
When the deadline fires, the result opens with TIMEOUT — not a failure of the command and
explains that the exit_code=-1 / "Command exited with code 3" statuses are the kill, not
the command's own exit code; the partial capture is retrievable with busybox log <run>.
Stamps are nanosecond (--stamp-ns) where the build has them — two events in the same
microsecond stay distinguishable — and every shape a build has printed still parses:
padded microseconds, zero-padded nanoseconds (0.6.0), unpadded (0.6.1 on).
A 120-second silence watchdog (run -W) rides with every deadline: a command producing no
output at all is killed and reported idle=true — a hang, not slow work — even when the
deadline was raised. The result's notice names it IDLE, distinct from TIMEOUT, and
rules stdin out as the cause (stdin is empty under pi, so a read returns end-of-file at
once) in favour of a socket, a lock or a child that never exits.
PI_MANAGED_TOOLS_IDLE=<seconds> changes it; 0 disables it. What counts as silence is the binary’s to say: a build with the idle-cpu feature treats CPU use as activity, so a compile or a test that prints nothing while it works is left alone; an older build reads output alone, and there the watchdog is armed only when the call asked for no deadline longer than its window, so that it cannot end a long, quiet command that is working. And
busybox run --format json now reports what the command did, not just what it printed:
cpu_user_ms/cpu_sys_ms, max_rss_kb, binary (the output is not text), dropped_bytes,
final_newline, cwd_start and a re-runnable replay line — the busybox_run tool
surfaces the interpretation-changing ones on a meta line of its result.
What a result says, and what is refused
A result is only as good as what the model can conclude from it without guessing. Each of these was a place where it had to guess, or was told something false.
- How it ended comes first, when that was not the command's own exit.
TIMEOUT,IDLE,CANCELLEDandKILLEDopen the result. A timeout used to start withexit_code=-1, then up to 48 KB of output, and only then say nothing had failed. - A truncated view names what it lacks.
busybox runkeeps the head and the tail of a long timeline and marks the cut. The line after the result names the omitted range, gives the command that reads from it, and says how many of the omitted lines are on stderr — a view with no[err]line otherwise reads as "no errors". - pi's own cut is repaired. pi's bash tool keeps the last 2000 lines or 50 KB. When
that removes the
run=header, it is restored from the full output pi kept aside, and the cut is said. - Facts instead of "unknown". The guest shell leaves its last pipeline's stage
statuses and its final directory in the run's folder (an EXIT trap, about 4 ms). So
cmd | headgetspipeline stage statuses: 1 141 0— or no note at all when every stage exited 0 — and acdgetsthis command ended in /repo/build; the next bash call starts back in /repo. A command that sets its own EXIT trap gets the old caveats. - A caveat is given in full once. After that it comes back in a few words; the same
two lines on every
| headcall were being skimmed past. - A command that cannot end is refused before it runs, with the rewrite: a pager, an
editor,
tail -f,watch,top,git rebase -i, a foreground server. Nobody can press a key here, so it would sit until the deadline and return aTIMEOUTwith nothing learned. Only the first word of a statement or pipeline stage is judged, heredoc bodies are skipped, andtimeout …, a trailing&, or a pipeline that ends (tail -f log | grep -m1 ready) pass.# pitime-safeoverrides it, as for a merge. busybox sh -c '…'is wrapped. Every directbusybox …call used to count as "already wrapped" — and the guidelines recommendbusybox sh -cfor multi-step logic, so exactly the longest commands ran with no timeline and no deadline. Only the applets whose output is their own record (run,log,peek,json, …) are left alone now.- The binary is asked, not assumed. At session start it is run once with the flags a
wrapped command gets. Its feature list decides
--stamp-nsand the silence watchdog; a refused pseudo-terminal means plain pipes for the session; and a binary that fails turns the wrapper off, with a warning, instead of failing every bash call. - Captures are not deleted from under another session. The artifact root is shared by
every session on the machine, and
--prune 20let twenty commands in one delete a run another had just been pointed at. Nothing is pruned by count now: the sweep removes a run only when it is beyond the newest 200 and more than two hours old. - Other extensions see the model's command. The wrapper is applied inside the bash
tool's own
execute, not by rewriting the call in thetool_callhook, so a permission or safety extension matches its rules againstnpm test, notbusybox run … -c '…'.
Buffering
An offset is only the truth if the program wrote the line when it printed it. On the
terminal most runtimes do. But a stage inside a pipeline (make | tee build.log,
./server | grep ERROR) and output sent to a file a later call reads write to a pipe or
a file, where a runtime that block-buffers holds its lines until 4–64 KB have piled up.
Measured with a probe per runtime (print, wait a second, print; stdout a pipe), on macOS
and Debian:
| Runtime | On a pipe, untouched | With the wrapper | How |
|---|---|---|---|
| sh builtins, Node, Deno, Bun, PHP, Tcl, R, Java, Elixir, Go, Rust, C++ iostream | live | live | nothing needed |
| Python | late | live | PYTHONUNBUFFERED=1 |
| Ruby, Perl | late | live | a prelude loaded through RUBYOPT / PERL5OPT |
| LuaJIT | late | live | LUA_INIT |
C stdio on macOS: compiled C, Swift, grep, sed, awk, cut, tr, jq | late | live | STDBUF1=L, read by the C library itself |
| C stdio on Linux | late | late — live with PI_MANAGED_TOOLS_PRELOAD=on | glibc has no variable; stdbuf's preload library |
Haskell (GHC), OCaml Printf, mawk | late | late | nothing outside the program changes it |
RUBYOPT, PERL5OPT, MAVEN_ARGS and GRADLE_OPTS are appended to what you already have
(a GRADLE_OPTS=-Xmx4g used to be replaced). The cost is bulk output: a line at a time is
a system call at a time — on macOS five million lines into a file took 15.5 s instead of
0.6 s, about 3 µs a line. STDBUF1=F cmd exempts one command, PI_MANAGED_TOOLS_EXTRA_ENV
set to STDBUF1=F every command, and PI_MANAGED_TOOLS_UNBUFFER=off turns all of it off.
The Linux preload is off by default because it reaches every program a command starts,
and an AddressSanitizer build refuses to run under one.
What the model is sent of what it has already read
- Old timelines lose their offsets at compaction. A wrapped result older than the
latest compaction is sent with the command's own lines,
err|on its stderr lines, its header and its digest — no stamps. Only then, because rewriting an old message changes the prompt's prefix, and compaction is the one moment the prefix is rebuilt anyway. The session file is never touched. - A
!command reaches the model as a timeline. You see the command's own bytes; the capture took a timeline anyway, and the recorded message is swapped for it on the way to the model.
busybox_job: a command that outlives the call
pi has no background mode: a dev server in a bash call ends in a TIMEOUT, and & loses
the output. busybox_job starts a command under its own busybox run, returns a job id,
and then: status gives only the output that is new (stderr lines marked err| ),
wait_for returns the moment a literal appears and says whether it did, stop ends the
whole process group. Jobs are stopped when the session ends; at most eight run at once.
Agent-facing applets and the three tools
The packaged build carries fifteen applets that exist for a coding agent rather than a
shell, and they share one contract: text by default, --format json with
"schema":1 on request, explicit byte budgets, shown_bytes/truncated always
reported, and exit codes that never use 124 or 128+N.
| applet | what it adds |
|---|---|
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 |
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 |
run -- CMD... | exec argv verbatim or --shell, stdout/stderr captured to 0600 artifacts, bounded head+tail view, own deadline and process-group cleanup |
log RUN | re-read a capture by --lines, --match (literal), --context, --stream, --meta |
waitfor | bounded --file/--tcp/--unix/--http readiness with one deadline |
doctor | cwd, argv[0] resolution, shell, writable temp, --deps a,b paths — no environment dump |
Three of them are wrapped as model tools, because the built-ins they resemble lack exactly one property each:
busybox_peek— a read that returns the file version, so the next edit can be refused if the file moved underneath it.readis still the default for reading.busybox_replace—editwith asha256precondition: a stale hash isSTALE_INPUTand the file stays byte-identical,dry_runreturns the diff, and several edits are all validated before any is written.editstays the default.busybox_run—bashwith retrievable evidence: the capture is complete even when the view is trimmed, sorun_idfetches the lines that were left out. A nonzeroexit_codeis reported as the command's status, never as a tool failure.bashstays the default.
Each tool spawns the packaged binary and formats the JSON it prints; none of the
guarantees (byte budget, flock, process-group cleanup, 0600 artifacts) is
re-implemented in TypeScript, so the plugin and the binary cannot disagree about
what "stale" or "truncated" means. Cancelling a tool call sends TERM to the applet
and KILL after two seconds, and the applet cleans up its own process group.
The exact argv, JSON field names, exit codes and payload shapes this plugin depends
on are written down for the upstream repository in
BUSYBOX-CONTRACT.md, with
scripts/capture-busybox-contract.sh to re-capture them from any build. Two shapes
in that document differ from the binary's own design notes and are only right there
because they were captured: peek's next is {"from_byte":N}, not a number, and
a zero-match replace answers INVALID_ARGUMENT with an empty message rather than
NOT_FOUND.
Known build bug in the packaged binary: run --format json prints an invalid
payload when the view is truncated (the head and the tail become two adjacent quoted
strings). The metadata is intact and the capture is complete, so busybox_run
recovers the fields and points at run_id for the view; it never re-runs the
command, because that repeats its side effects. log --format json and
peek --format json are unaffected.
Verification
Every archive is checked against the sha256 digest GitHub records for the
release asset, before it is extracted. That digest is computed by GitHub at
upload time, so it does not depend on the project publishing sidecar checksums —
fd and bat publish none at all. It also means a compromised release page
cannot pass by replacing a binary and its .sha256 sidecar together.
Verification is fail-closed:
- a digest mismatch fails the install and keeps the previous binary;
- a release API that cannot be reached fails the install rather than guessing;
- an asset published without a digest fails the install.
The single opt-out is PI_MANAGED_TOOLS_ALLOW_UNVERIFIED=1, which installs the
archive and records its digest anyway. Such an install is reported as
UNVERIFIED rather than verified, including in the TUI update line.
Digests are read from api.github.com, whose anonymous quota is 60 requests per
hour per IP and shared with everything else on the host. A verification only
runs when an update is actually downloaded, so a normal cycle costs one request
per outdated tool. If the quota is exhausted, installs fail closed with a
message saying so; set GITHUB_TOKEN (or GH_TOKEN) to raise the limit. The
installed binaries are never damaged by a failed verification.
After the swap the installed binary is executed and its version read back. A binary that cannot run — wrong architecture, glibc against a musl build, a truncated download — is rolled back to the previous copy and reported as a failure. Reporting the version that was requested instead would claim success for a dead file.
Installs land through a staged file on the same filesystem, so a failed download or extraction never leaves a partial binary where pi expects a working one. On POSIX the final rename replaces the old inode atomically, so a running pi keeps working.
Repairing a damaged binary
A managed binary can be broken without looking broken: truncated by a killed
download, left behind by a disk error, or copied from another architecture. A
version check misses all three, because the file is still at the expected path.
status therefore executes each managed binary and flags any that fail to run:
bat: installed 0.26.1 - DAMAGED (present but does not execute); run reinstall
/managed-tools reinstall with no argument replaces only those. Naming a tool
forces a fresh download even when the version already matches upstream, which is
what you want when the file is wrong in a way that still reports a version.
Bundled shims are covered. ast-grep's archive also installs sg, a deprecated
alias that is a small binary which execs ast-grep — so it dies the moment
its sibling is missing or unreadable. status probes every name an archive
provides and names the broken one:
ast-grep: installed 0.51.3 - DAMAGED (sg does not execute); run reinstall
/managed-tools reinstall sg resolves to ast-grep, because that archive is
where sg comes from, and reinstalls the bundle.
An install is atomic per archive: every target is backed up, swapped, then probed, and any failure restores all of them. A broken shim in a release can never leave a new primary beside a dead one.
A repair still verifies the archive digest, still rolls back if the new binary will not run, and falls back to the version already on disk when the release lookup fails — so it works with a broken network, which is when a repair is most likely to be needed.
To remove it: pi remove npm:@rob-c/pi-managed-tools.
To use the same binaries in your own shell (pi only adds them to the PATH of
its own bash tool):
export PATH="$HOME/.pi/agent/bin:$PATH" # add to ~/.zshrc or ~/.bashrc
Because pi searches that directory first, a managed copy shadows a copy you
installed yourself with Homebrew, cargo, uv, or a version manager. That is the
point for fd/rg/bat; if you deliberately pin prek to a specific
version, check /managed-tools before assuming which binary ran.
What a session start does
PATHis rebuilt as<agent dir>/bin : <agent dir>/busybox-applets : rest, and the applet directory is re-synced against the installed busybox (onebusybox --list, a readdir, and only symlinks touched). Local, so it happens even when no network check is due.- A managed binary is missing, or the last check is older than the interval:
resolve
https://github.com/<repo>/releases/latest(the redirect, not the rate-limited API; the API is only a fallback). - Each binary whose installed version is older — or absent — is downloaded, verified against GitHub's digest, extracted and renamed into place. The archive is fetched and unpacked inside the bin directory so the final rename stays on one filesystem and cannot leave a truncated binary where pi expects a working one.
- The result is recorded in
<agent dir>/bin/.pi-managed-tools.json, which is what the interval is measured against. - Otherwise nothing happens and no network request is made.
Status lines are shown in the TUI only when something changed. Print mode
(pi -p) still updates, silently.
A tool with no release for the current platform is skipped and does not
force a check on every start. sd publishes no aarch64-pc-windows-msvc archive, so
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
build at all, and difftastic uses the gnu Linux build because it publishes no
linux-arm64 musl asset.
Configuration
| Variable | Default | Meaning |
|---|---|---|
PI_MANAGED_TOOLS | on | off/0/false disables the startup check (the /managed-tools update command and managed_tools tool still work) |
PI_MANAGED_TOOLS_INTERVAL_HOURS | 12 | Minimum hours between startup checks; 0 checks every start |
PI_MANAGED_TOOLS_ALLOW_UNVERIFIED | unset | 1/true/yes installs an archive whose digest cannot be confirmed |
PI_MANAGED_TOOLS_REWRITE | on | off/0/false disables rewriting absolute tool paths in bash tool calls |
PI_MANAGED_TOOLS_WRAP | on | off/0/false stops wrapping bash commands (no timeline, no unbuffered environment) |
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 |
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) |
PI_MANAGED_TOOLS_UNBUFFER | on | off leaves every program's output buffering as it is (see Buffering) |
PI_MANAGED_TOOLS_PRELOAD | off | on preloads GNU coreutils' libstdbuf.so on Linux so C-stdio programs line-buffer too |
PI_MANAGED_TOOLS_GUARD | on | off disables both refusals: a stream merge at a command's tail, and a command that cannot end |
PI_MANAGED_TOOLS_COMPACT_STAMPS | on | off prints the full offset on every line instead of [= out] within a burst |
PI_MANAGED_TOOLS_AGE_OUT | on | off keeps the offsets of results older than the latest compaction |
PI_MANAGED_TOOLS_LIVE | on | off leaves a running bash or busybox_run call blank until the command ends |
PI_MANAGED_TOOLS_USER_STDIN | on | off runs ! commands as before: stdin empty, output at exit |
PI_MANAGED_TOOLS_STDIN_TIMEOUT | 300 | Seconds a ! command may wait for you to answer before it is stopped; 0 waits for ever |
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) |
GITHUB_TOKEN / GH_TOKEN | unset | Optional. Raises the 60/hour anonymous quota used to read release digests |
PI_OFFLINE | unset | Same 1/true/yes values pi itself honours; disables startup checks |
Every one of these can also be set once, in pi's own settings file (global or project),
under a managedTools block — an exported variable still wins for one run:
{ "managedTools": { "verbosity": "quiet", "timeout": 300, "preload": true, "extraEnv": "STDBUF1=F" } }
The keys are wrap, verbosity, pty, timeout, idle, guard, unbuffer, preload,
extraEnv, userWrap, userStdin, stdinTimeout, compactStamps, ageOut, live and rewrite.
A /managed-tools verbosity or pty switch is recorded in the session, so a resumed
session keeps it.
Platform support
Downloads match what pi would have fetched itself:
| Platform | Archive |
|---|---|
| macOS (arm64 / x64) | …-apple-darwin.tar.gz |
| Linux (arm64 / x64, musl) | …-unknown-linux-musl.tar.gz |
| Windows (arm64 / x64) | …-pc-windows-msvc.zip |
Other architectures are left alone: these projects publish no matching prebuilt binary and pi does not guess one either. Three of the projects deviate from the Rust triple convention and are handled per tool:
| Tool | Asset scheme | Notable gaps |
|---|---|---|
gron | gron-<os>-<go arch>-<version>.tgz (.zip on Windows) | no 32-bit arm |
shellcheck | shellcheck-v<ver>.<os>.<arch>.tar.gz | one arch-less .zip for Windows x64 only |
ast-grep | app-<rust triple>.zip (zip on every platform) | none |
just | just-<ver>-<rust triple> | none |
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 |
jq | bare executable: jq-macos-arm64, jq-linux-amd64 | no archive at all — the download is the binary |
yq | bare executable: yq_darwin_arm64, yq_linux_amd64 | no archive at all |
fzf | fzf-<ver>-darwin_arm64.tar.gz (.zip on Windows) | none |
uv | uv-<rust triple>.tar.gz / .zip | archive also contains uvx |
gh | gh_<ver>_linux_amd64.tar.gz, gh_<ver>_macOS_arm64.zip | macOS ships a zip, Linux a tar.gz |
bd | beads_<ver>_darwin_arm64.tar.gz | assets are named after the project, the binary is bd; Dolt is embedded |
agent-browser | bare executable agent-browser-darwin-arm64 | x64 not amd64; no win32-arm64 |
ruff | ruff-<rust triple> | bare version tags |
mise | mise-v<ver>-macos-arm64.tar.gz | dated tags; binary nests at mise/bin/mise |
scc | scc_Darwin_arm64.tar.gz | capitalised OS, underscore, no version |
duckdb | duckdb-cli-osx-arm64.tar.gz | says osx/amd64; bare binary in the archive |
miller | miller-6.22.0-darwin-arm64.tar.gz | installs mlr, not miller |
sd | sd-v1.1.0-aarch64-apple-darwin.tar.gz | keeps the v; binary reports 1.0.0 for tag 1.1.0 |
difftastic | difft-0.72.0-aarch64-apple-darwin.tar.gz | installs difft; linux uses gnu |
busybox | busybox-static-1.39.0-aac079e-darwin-universal | bare binary; one universal2 mac asset; no Windows build |
gron's release build reports no version at all (gron version dev), so its
installed version is recorded in the state file rather than read back from the
binary.
rtk is no longer installed by this package (see the note below the table). It
used to come from the rtk-oss- family — the plain rtk-<target> release bundles a
BUSL-1.1 engine (LICENSE-ENGINE), which is why the OSS build was used. rtk-oss- is the
Apache-2.0-only build of the same tool, with the same binary name and version
banner. Nothing here is redistributed — the binary is fetched from GitHub on the
user's own machine — but the distinction is kept explicit so the default install
is not silently pulling a source-available component.
Layout
package.json pi manifest: loads src/extension.ts
src/extension.ts session_start check, PATH + applet sync, command and tools
src/tools.ts registry, release targets, digests, download/extract/install, cooldown,
busybox applet directory and PATH ordering
src/agentops.ts the agent-facing wrappers: argv, JSON, formatters, salvage, cancellation
BUSYBOX-CONTRACT.md what the binary must keep providing (handed to the busybox repo)
skills/managed-tools/ always-advertised short skill
skills/managed-tools-reference/ exact flags and examples per tool
tests/tools.test.ts offline tests: fixtures are real archives served by a fake fetch
tests/extension.test.ts loads the extension against a stand-in pi and agent directory
tests/agentops.test.ts wrapper argv/formatters plus a stand-in multicall binary
tests/skills.test.ts keeps the two skills in step with the tool registry
scripts/verify.sh runs the installed plugin inside the pi on PATH
scripts/capture-busybox-contract.sh re-captures every invocation and payload
Does Pi-Time help the model?
A paired probe answers it with numbers instead of opinion: npm run measure:timing
(-- --runs N, -- --keep). One command (prints at 0 s, warns on stderr at 2 s, prints at
8 s) plus five questions whose answers are known, run with the wrapper on and off, same
model, alternating order.
| fact | wrapped | plain capture |
|---|---|---|
| order of the stderr line vs the first stdout line | 3/3 | 0/3 — reports "before", truth is "after" |
| which stream carried the warning | 3/3 | 3/3 (a lucky prior) |
| seconds between first and last line | 3/3 | 0/3 |
| where the longest silence was | 3/3 | 1/3 |
| streamed or flushed at exit | 3/3 | 1/3 |
| total | 15/15 | 5/15 |
The plain arm is wrong rather than vague: block-buffered stdout only appears at exit, so
the merged capture shows the stderr line first and a reader repeats that. The script prints
the observed order for each arm (on: phase1 first (true order) / off: deprecated first (inverted)), so that claim is one command away rather than a claim about a temp file. The
timing questions come back as "undetermined — no timestamps". Both arms used one bash call,
so this is about the quality of one answer, not extra turns.
n=3, one model, one prompt shape — it shows the direction and the mechanism, not an effect
size. One trap for anyone re-running it: a probe launched from inside a wrapped bash call
inherits PYTHONUNBUFFERED=1 and the plain arm silently becomes unbuffered; the script
strips the wrapper's variables first.
Testbench
npm test covers the pure logic against stand-ins. npm run testbench drives the
installed extension through pi's real bash engine and the real busybox — no model in the
loop — so a failure is a bug rather than a prompt misunderstanding:
npm run testbench # 17 scenarios, ~30s
npm run testbench -- --list
npm run testbench -- --only pty # scenarios whose name matches
npm run testbench -- --verbose # every check, not only the failures
npm run testbench -- --keep # keep the scratch dirs
Each scenario runs in its own process with its own scratch <agent dir> — containing a
space, on purpose — and its own TMPDIR, so the wrapper's quoting, the applet symlinks and
the run-artifact sweep are exercised the way a real install exercises them. The checks
assert on tool results and exit codes, never on what a model said.
It found: an empty busybox silently silencing every command, zip installs broken by the
plugin's own unzip symlink, a truncated view with no way back, busybox_run losing its
timeline and looking for a match in stdout only, and unbounded run artifacts.
Tests
npm test # node --test; no network access
npm run typecheck # tsc --noEmit
./scripts/verify.sh # end-to-end inside the installed pi (needs a model key)
The suite builds real tar.gz release archives in a temp directory, serves them
through a stub fetch that also synthesises the release API response from the
same bytes, and asserts the installed binary runs, reports the expected version,
replaces the old copy, and leaves no archive or staging directory behind. The
stub computes real digests, so verification is exercised rather than bypassed:
a tampered asset, a missing digest, and a binary that exits without printing a
version are each asserted to fail without damaging the installed copy. A second
file loads the extension itself against a stand-in pi to check registration,
the command, the tool, and that a startup inside the check interval, or with
PI_MANAGED_TOOLS=off/PI_OFFLINE, makes no network request at all.
Licence
GPL-2.0-only. See LICENSE.
This is a deliberate choice: the plugin itself is copyleft, so anyone distributing a modified version must publish their source under the same terms.
Two things it does not cover, both by design:
- The binaries it downloads are not distributed here.
shellcheck(GPL-3.0) andbusybox(GPL-2.0) among them are fetched from their own upstream releases onto the user's machine. Bundling any of them into this package would create a licence conflict, so don't. - pi itself is MIT and is declared as a
peerDependency, never bundled. Its own dependency tree contains Apache-2.0 packages, which is fine precisely because none of it ships in this tarball.