@rob-c/pi-managed-tools 0.16.0 → 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 +441 -0
- package/README.md +464 -35
- package/package.json +7 -4
- package/skills/busybox-applets/SKILL.md +142 -15
- package/skills/managed-tools/SKILL.md +201 -25
- package/skills/managed-tools-reference/SKILL.md +206 -38
- 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 +817 -28
- package/src/guard.ts +437 -0
- package/src/jobs.ts +1052 -0
- package/src/timing.ts +364 -0
- package/src/tools.ts +525 -42
- package/src/userstdin.ts +524 -0
- package/src/wrap.ts +683 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rob-c/pi-managed-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Keeps pi's managed binaries, and a few PATH-only extras, at the latest upstream release",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"ripgrep",
|
|
11
11
|
"bat",
|
|
12
12
|
"prek",
|
|
13
|
-
"rtk",
|
|
14
13
|
"just",
|
|
15
14
|
"gron",
|
|
16
15
|
"shellcheck",
|
|
@@ -47,15 +46,19 @@
|
|
|
47
46
|
"src/",
|
|
48
47
|
"skills/",
|
|
49
48
|
"README.md",
|
|
49
|
+
"BUSYBOX-CONTRACT.md",
|
|
50
50
|
"CHANGELOG.md"
|
|
51
51
|
],
|
|
52
52
|
"scripts": {
|
|
53
|
-
"test": "node --test tests/tools.test.ts tests/extension.test.ts tests/skills.test.ts",
|
|
53
|
+
"test": "node --test tests/tools.test.ts tests/agentops.test.ts tests/wrap.test.ts tests/display.test.ts tests/timing.test.ts tests/extension.test.ts tests/skills.test.ts tests/userstdin.test.ts tests/guard.test.ts tests/hardening.test.ts tests/jobs.test.ts tests/benchmark-probes.test.ts tests/benchmark-runner.test.ts tests/gauntlet.test.ts",
|
|
54
54
|
"typecheck": "tsc -p .",
|
|
55
|
-
"verify": "./scripts/verify.sh"
|
|
55
|
+
"verify": "./scripts/verify.sh",
|
|
56
|
+
"testbench": "node scripts/testbench.mjs",
|
|
57
|
+
"measure:timing": "node scripts/measure-timing-value.mjs"
|
|
56
58
|
},
|
|
57
59
|
"peerDependencies": {
|
|
58
60
|
"@earendil-works/pi-coding-agent": "*",
|
|
61
|
+
"@earendil-works/pi-tui": "*",
|
|
59
62
|
"typebox": "*"
|
|
60
63
|
},
|
|
61
64
|
"devDependencies": {
|
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: busybox-applets
|
|
3
|
-
description: "All
|
|
3
|
+
description: "All 279 Darwin BusyBox applets with a read-only vs mutating classification: which applets never change anything, which write, which are destructive or system-level, and which flags cause the write. Load before running any busybox applet that is not obviously an inspection command."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# BusyBox applets
|
|
7
7
|
|
|
8
|
-
`busybox <applet> [args]` —
|
|
8
|
+
`busybox <applet> [args]` — 279 applets in the Darwin build inside one static binary
|
|
9
|
+
(v1.39.0.git, project release 0.4.0).
|
|
9
10
|
BusyBox dispatches on **argv[0]**, so the installed file must stay named `busybox`;
|
|
10
11
|
if you copy or rename it, `busybox` no longer works and the new name is treated as
|
|
11
12
|
the applet name.
|
|
12
13
|
|
|
13
|
-
**Never run `busybox --install -s <dir
|
|
14
|
-
first on `PATH` for every bash command — that would create
|
|
14
|
+
**Never run `busybox --install -s <dir>` yourself.** In pi's bin directory — which is
|
|
15
|
+
first on `PATH` for every bash command — that would create 279 symlinks ahead of the
|
|
15
16
|
real coreutils, and busybox `sed`, `grep`, `find`, `tar`, `awk` and `xxd` are not
|
|
16
17
|
GNU-compatible. Every later command in the session, including the other tools in
|
|
17
18
|
this package, would silently change behaviour.
|
|
18
19
|
|
|
20
|
+
The package already exposes a curated subset, which is why some of these applets are
|
|
21
|
+
bare names: `<agent dir>/busybox-applets` holds a symlink per applet in `core`
|
|
22
|
+
(62 of them — `xxd`, `hexdump`, `od`, `strings`, `sha*sum`, `base64`, `gzip`,
|
|
23
|
+
`unzip`, `cpio`, `dpkg-deb`, `rpm2cpio`, `timeout`, `setsid`, `nproc`, `realpath`,
|
|
24
|
+
`seq`, `nl`, `paste`, `ts`, `peek`, `waitfor`, `doctor`, `brief`, `why`, `patchcheck`, ...),
|
|
25
|
+
and it sits on `PATH` *after* `<agent dir>/bin` so the dedicated builds still win. `sed`, `grep`, `find`, `awk`, `tar`, `diff`, `ls`,
|
|
26
|
+
`cp`, `rm`, `stat`, `date`, `patch`, `tree` and `sh` are deliberately left out: use
|
|
27
|
+
`busybox <applet>` for those. `replace`, `run`, `log`, `bench`, `check`, `json`,
|
|
28
|
+
`snapshot` and `brief` are also not linked - some run a command, some write a file, and
|
|
29
|
+
the rest are names a project script or another tool already owns. `PI_MANAGED_TOOLS_APPLETS=all` widens the linked set and `off` disables it.
|
|
30
|
+
|
|
19
31
|
Prefer the dedicated tools where they exist: `rg` over `busybox grep`, `fd` over
|
|
20
32
|
`busybox find`, `bat` over `busybox cat`, `jq` over `busybox awk`, `diff`/`difft`
|
|
21
33
|
over `busybox diff`, `scc` over `busybox wc`-loops. Use busybox for the applets
|
|
@@ -26,24 +38,123 @@ Legend: **R** never changes state · **M** writes files or state · **M★**
|
|
|
26
38
|
destructive, irreversible or system-level · **E** runs a program you name, so its
|
|
27
39
|
effect is whatever that program does.
|
|
28
40
|
|
|
41
|
+
## Output shapes: timeline and brief
|
|
42
|
+
|
|
43
|
+
Two applets decide what an agent actually *sees* on a busy machine, and they are
|
|
44
|
+
mutually exclusive in this build (see the note below).
|
|
45
|
+
|
|
46
|
+
`busybox run --timestamps` (`-t`) prints one interleaved line per record — dmesg style — with a
|
|
47
|
+
microsecond offset from process start and the stream it arrived on:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
[0.011354 out] ok 1
|
|
51
|
+
[0.066632 err] FAILED test_x
|
|
52
|
+
[0.128234 out] done
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
(Unpadded since busybox-static 0.6.1; an older build pads the number, `[ 0.011354 out]`. With `-n` the fraction is nine digits. A bash result shows `[= out]` for a line at the same offset as the one above.)
|
|
56
|
+
|
|
57
|
+
Read it as ordering evidence: a warning that lands *before* a failure was printed
|
|
58
|
+
before it, and a burst of lines sharing one timestamp is a writer that flushed at exit
|
|
59
|
+
(Python without `PYTHONUNBUFFERED`, Java's `System.out`, Ruby's `$stdout`, a `bufio`
|
|
60
|
+
writer in Go). `log RUN --stream timeline` replays the same view from the artifacts, and
|
|
61
|
+
`log RUN --stream timeline --format json` returns `timeline: [{us, stream, text}]` plus
|
|
62
|
+
`started_unix_us`.
|
|
63
|
+
|
|
64
|
+
`brief` reduces line-oriented output to a bounded view without inventing or eliding
|
|
65
|
+
bytes inside a record: identical records collapse to `Nx <first line>`, `-R` makes a
|
|
66
|
+
record span lines (a stack trace stays one record), `-o`/`-x` select, `-c`/`-t`/`-m`
|
|
67
|
+
group, and its own `[brief] lines_in=… records=… merged=… truncated_by=…` marker line
|
|
68
|
+
reports what it did. `busybox run --brief stdout|stderr|both` pipes a stream through `brief -d`,
|
|
69
|
+
and `--brief-json` puts brief's schema-1 payload in the view instead of text.
|
|
70
|
+
|
|
71
|
+
`-R` matches literal text (not a regex) and `-B 0` means a *zero* budget, not "no limit" —
|
|
72
|
+
two flags whose names suggest more than they do.
|
|
73
|
+
|
|
74
|
+
Three properties decide whether a reduction is trustworthy, and all three are in the
|
|
75
|
+
marker: a record is shown **whole or not at all** (the budget drops records, never
|
|
76
|
+
truncates one); `-s` groups lines that differ only in digits, which is what actually
|
|
77
|
+
collapses a real log (`-d` needs byte-identical lines); and `truncated_by` says *why* the
|
|
78
|
+
view is short — `budget`, `selection` (everything that matched, nothing cut) or
|
|
79
|
+
`record_size`. `-F json` carries the same numbers plus a summary sentence and `hints[]`
|
|
80
|
+
naming the flag that would change the answer. The full flag set and worked examples are in
|
|
81
|
+
`managed-tools-reference`.
|
|
82
|
+
|
|
83
|
+
**`--timestamps` wins over `--brief` here**: `busybox run -t -b both` prints the timeline and
|
|
84
|
+
ignores the brief flags entirely, because the timeline branch is taken first. Pick one.
|
|
85
|
+
|
|
86
|
+
## Agent-facing applets
|
|
87
|
+
|
|
88
|
+
Fifteen applets exist for a coding agent rather than for a shell. They share one
|
|
89
|
+
contract: text by default, `--format json` on request with `"schema":1`, explicit
|
|
90
|
+
byte budgets, and `shown_bytes`/`truncated` always reported. `busybox --list` names them
|
|
91
|
+
all; `busybox --caps --format json` reports the version, applet count and the agent-ops
|
|
92
|
+
features this build actually carries.
|
|
93
|
+
|
|
94
|
+
| exit | meaning |
|
|
95
|
+
|---|---|
|
|
96
|
+
| 0 | success — including "read completed, output truncated": truncation is data |
|
|
97
|
+
| 1 | refused or failed (not found, ambiguous, stale, invalid argument) |
|
|
98
|
+
| 2 | usage error |
|
|
99
|
+
| 3 | timeout or cancellation |
|
|
100
|
+
|
|
101
|
+
Error codes appear inside the payload and decide the message: `INVALID_ARGUMENT`,
|
|
102
|
+
`NOT_FOUND`, `STALE_INPUT`, `AMBIGUOUS_MATCH`, `TIMEOUT`, `CANCELLED`,
|
|
103
|
+
`CAPTURE_INCOMPLETE`, `UNSUPPORTED`. Never 124, never 128+N.
|
|
104
|
+
|
|
105
|
+
| applet | does | does not |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| `peek FILE -l A:B` or `-a STR` | numbered lines *and* the file's `sha256` version, taken from the bytes it printed; continues at `--from-byte N` when truncated; flags binary input instead of dumping it | invent line numbers, skip content when truncating, match a regex unless `-r` |
|
|
108
|
+
| `replace FILE --old S --new S` | literal replacement validated against the whole file first; `--expect N` (default 1), `--sha256` precondition, atomic write, `--dry-run` diff | chain one edit into the next, apply a partial batch, edit through a symlink without `--follow`, or coordinate with an editor that ignores `flock` |
|
|
109
|
+
| `run -- CMD...` | exec argv verbatim (or `--shell` for a shell line), separate stdout/stderr artifacts, bounded head+tail view, own deadline and process-group cleanup; `-x/--effects` reports files created/changed/removed under the run's cwd (JSON output: `effects: [{op, path, size}]`, bounded) | record cross-stream ordering, or keep a grandchild that detaches from the process group |
|
|
110
|
+
| `log RUN` | re-read a captured run: `--lines`, `--match` (literal), `--context`, `--stream`, `--meta` | read anything the capture quota dropped (`capture_complete=false` says so) |
|
|
111
|
+
| `waitfor` | bounded readiness: `--file`, `--tcp`, `--unix`, `--http` + `--expect` | prove *application* readiness from a TCP connect, or speak `https://` (use `wget --spider`) |
|
|
112
|
+
| `doctor` | cwd, argv[0] resolution, shell, writable temp storage, `--deps a,b` paths | dump the environment or a variable's value |
|
|
113
|
+
| `brief` | reduce a log to its shape: `-s` masks digits so repeats collapse, `-o`/`-x` select, `-R` makes a record span lines, `-k` keeps records verbatim; the `[brief]` marker says what was merged and dropped | cut a record in half (the budget drops records), or treat `-R` as a regex |
|
|
114
|
+
| `busybox json` | query a document: `-f FILE`, `-g '.a.b[2]'`, then `-k` keys / `-t` type / `-n` count; `-c` validates (`INVALID_JSON at byte N: …`, exit 1); **write guarded**: `-g PATH --set --value STR` (or `--json-value JSON`), `-g PATH --delete`, `--dry-run` shows without writing — parses first, missing parent refused exit 1, temp+rename | parse JSON with `awk`/`sed`, read YAML as JSON, or hand-roll a python one-liner to edit a document |
|
|
115
|
+
| `busybox mark NAME` | name this moment in the current run's timeline (`<run>/marks`, read with `busybox log <R> --marks`); outside a run it prints | replace timestamps the model needs to compute itself |
|
|
116
|
+
| `busybox outline FILE` | a file's definitions with line, byte offset and a version each (`-f json`) — the index `peek`/`replace` work from | read the whole file to find where a symbol lives |
|
|
117
|
+
| `busybox patchapply` | apply a unified diff with every hunk verified first; `-c PATH=HASH` refuses on drift, `-n` previews, temp+rename | apply a patch whose hunks were never checked (`patch`), or skip `patchcheck` first |
|
|
118
|
+
| `busybox snapshot` | hash a tree in one pass (`<sha256> <bytes> <path>` per file), `-o FILE` to save, `--diff A B` to compare (`added=1 removed=0 changed=0`) | tell you *what* changed inside a file — it compares content hashes |
|
|
119
|
+
| `patchcheck` | check every `*.patch` in a directory parses: `ok <file>` lines and `checked=N bad=M` | prove a patch *applies* — a patch that parses but would conflict still reports `ok` |
|
|
120
|
+
| `busybox bench` | time a command N times with warmup: `run=1 ms=5.530 status=0` lines plus `runs= ok= failed= min_ms= median_ms= max_ms=` | account for what the command printed (it is discarded) |
|
|
121
|
+
| `why` | say whether an applet is in this binary and which config line decided it (`-C .config`, `-p prune list`) | work without a `.config`: with none it answers `unknown … (no GREP entry in .config)` and exits 0 |
|
|
122
|
+
|
|
123
|
+
Bare names (linked into `<agent dir>/busybox-applets`): `peek`, `waitfor`, `doctor`, `brief`, `why`, `patchcheck`. Everything else here — `replace`, `run`, `log`, `json`, `snapshot`, `bench` — needs the `busybox ` prefix; the table above writes them that way.
|
|
124
|
+
|
|
125
|
+
`busybox --caps --format json` reports the version, platform, schema, applet count
|
|
126
|
+
and the features this build actually has, so none of the above has to be guessed.
|
|
127
|
+
|
|
128
|
+
**Fixed in 0.4.0, still worth knowing:** `busybox run --format json` used to emit an invalid
|
|
129
|
+
payload when the view was truncated (head and tail printed as two adjacent quoted strings).
|
|
130
|
+
It now emits one string with an in-band `... [N bytes] ...` marker. On an older build, read
|
|
131
|
+
the scalar fields, use `log RUN` for the view, and never re-run the command to get a
|
|
132
|
+
parseable answer — that repeats its side effects.
|
|
133
|
+
|
|
29
134
|
## Read-only (R)
|
|
30
135
|
|
|
31
136
|
Safe for inspection. These only read input and write to stdout/stderr.
|
|
32
137
|
|
|
33
138
|
```
|
|
34
|
-
[ [[ arch ascii base32 base64 basename bc blkid bzcat cal cat chat cksum
|
|
35
|
-
comm crc32 cut dc df diff dirname dnsdomainname du
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
139
|
+
[ [[ arch ascii base32 base64 basename bc blkid brief bzcat cal cat chat cksum
|
|
140
|
+
clear cmp column comm crc32 cut dc df diff dirname dnsdomainname doctor du
|
|
141
|
+
echo egrep expand expr factor false fgconsole fgrep fold free fuser getopt
|
|
142
|
+
grep groups hd head hexdump hostid id iostat ipcalc join json less log logname
|
|
143
|
+
ls lsattr lsblk lsof lspci lsscsi lsusb lzcat man mark md5sum mkpasswd more
|
|
144
|
+
mountpoint mpstat netstat nl nmeter nologin nproc nslookup od outline paste patchcheck
|
|
145
|
+
peek pgrep pidof ping ping6 pipe_progress printenv printf ps pscan pstree pwd
|
|
146
|
+
pwdx readahead readlink realpath resize rev rpm2cpio scriptreplay seq sha1sum
|
|
147
|
+
sha256sum sha384sum sha3sum sha512sum sleep stat strings sum svok tac tail
|
|
148
|
+
test top tr tree true ts tsort tty ttysize uname unexpand uptime usleep
|
|
149
|
+
uuencode uuidgen vmstat volname waitfor wc which whoami whois why xxd xzcat
|
|
150
|
+
yes zcat
|
|
43
151
|
```
|
|
44
152
|
|
|
45
|
-
|
|
46
|
-
|
|
153
|
+
Four caveats inside "read-only": `busybox xxd -r` only prints (it cannot write back),
|
|
154
|
+
`busybox find` is read-only **only** with its default `-print`, `busybox mark` writes
|
|
155
|
+
only the current run's own marks artifact (read it back with `busybox log <R> --marks`),
|
|
156
|
+
and `busybox json` is read-only until `--set`/`--delete` — those rewrite the document
|
|
157
|
+
(temp+rename, parsed first; a missing parent path is refused, exit 1).
|
|
47
158
|
|
|
48
159
|
## Writes files or state (M)
|
|
49
160
|
|
|
@@ -56,6 +167,7 @@ and `busybox find` is read-only **only** with its default `-print`.
|
|
|
56
167
|
| `chgrp` `chmod` `chown` | ownership and mode bits | normal form, `-R` |
|
|
57
168
|
| `dos2unix` | the file, in place | any file argument |
|
|
58
169
|
| `dpkg-deb` | extracted tree | `-e DIR`, `-x DIR`, `-X DIR` |
|
|
170
|
+
| `fallocate` | allocates blocks in a file | `-l LEN`, any file argument |
|
|
59
171
|
| `fatattr` | FAT attributes | `-/+rhsvda` |
|
|
60
172
|
| `flock` | lock file (created if absent) | `FILE`, `FILE -c PROG` |
|
|
61
173
|
| `fsync` | flushes blocks (no content change) | any file argument |
|
|
@@ -68,6 +180,9 @@ and `busybox find` is read-only **only** with its default `-print`.
|
|
|
68
180
|
| `nc` | hex-dump file | `-o FILE` |
|
|
69
181
|
| `nohup` | `nohup.out` | when stdout is a tty |
|
|
70
182
|
| `remove-shell` | `/etc/shells` | rewrites it |
|
|
183
|
+
| `replace` | the file, atomically | `--old/--new`, `--dry-run` to preview |
|
|
184
|
+
| `reset` | terminal modes and screen | any invocation |
|
|
185
|
+
| `snapshot` | a snapshot file | `-o FILE` (stdout without it) |
|
|
71
186
|
| `renice` | nice values of running processes | `PRIORITY ID`, `-p/-g/-u` |
|
|
72
187
|
| `run-parts` | whatever the scripts do | `DIRECTORY` |
|
|
73
188
|
| `rx` | received file | `FILE` |
|
|
@@ -100,6 +215,7 @@ Confirm before running any of these.
|
|
|
100
215
|
| `tar` | creates/extracts, overwrites | `c`, `x`, `-C DIR` (`t` only lists) |
|
|
101
216
|
| `unzip` `unxz` `unlzma` `gunzip` `xz` `gzip` `bzip2` `bunzip2` `lzma` `lzop` | write output and **delete the input** unless `-k` | `-f` forces overwrite; `-c`/`-t` are read-only |
|
|
102
217
|
| `patch` | rewrites targets in place | `-i DIFF`, `ORIGFILE` |
|
|
218
|
+
| `patchapply` | the files a patch touches, via temp+rename | applies a unified diff with every hunk verified first; `-c PATH=HASH` refuses on drift, `-n` previews |
|
|
103
219
|
| `ed` `vi` `hexedit` | overwrite the file on save | file argument (`vi -R` is read-only) |
|
|
104
220
|
| `kill` `killall` `killall5` | terminate processes | `-SIG PID`, name |
|
|
105
221
|
| `timeout` | signals the child | `-s`, `-k` |
|
|
@@ -114,6 +230,11 @@ Confirm before running any of these.
|
|
|
114
230
|
| `chroot` | changes root, runs `PROG` | `NEWROOT PROG` |
|
|
115
231
|
| `install` | copies and overwrites, sets owner/mode | always writes |
|
|
116
232
|
| `cpio` | extracts or creates archives | `-i`, `-o -F`, `-p DIR` |
|
|
233
|
+
| `fdisk` | partition table on a block device | `-l` only lists; every other mode writes |
|
|
234
|
+
| `mount` `umount` | mounts and unmounts filesystems | any argument (`mount` alone lists) |
|
|
235
|
+
| `ifconfig` `ip` `route` | interface addressing, links and routes | any mutation form (`ifconfig -a`, `ip a`, `route -n` read) |
|
|
236
|
+
| `pkill` `killall` | terminate processes by name | any invocation |
|
|
237
|
+
| `fuser` | with `-k`: kills what holds the file | `-k` (`-v`/`-u` only report) |
|
|
117
238
|
| `fatlabel` | FAT label on a block device | `BLOCKDEV LABEL` |
|
|
118
239
|
| `ftpd` `ftpput` `ftpget` `tftpd` `tftp` `telnet` `telnetd` `httpd` `inetd` `ssl_server` `tcpsvd` `udpsvd` | serve, upload or run remote-triggered commands | server/upload modes |
|
|
119
240
|
| `find` | deletes or runs commands | `-delete`, `-exec CMD ;` |
|
|
@@ -130,6 +251,12 @@ Read-only *by themselves*; the effect is entirely the child's. `env`, `envdir`,
|
|
|
130
251
|
`nice`, `setsid`, `cttyhack`, `xargs` (`-a FILE` only reads), plus `find -exec`,
|
|
131
252
|
`awk system()`, `sed e`, `tar --to-command`, `vi !cmd`.
|
|
132
253
|
|
|
254
|
+
The agent-facing `run` applet belongs here too: it execs whatever follows `--`, or a
|
|
255
|
+
shell line with `--shell`, and keeps the output in artifacts. `bench` runs its command
|
|
256
|
+
N times and `check` runs the cases in its table, so both are E. `chpst`, `envuidgid`,
|
|
257
|
+
`setuidgid` and `softlimit` also run a program, with a changed uid/gid or limits.
|
|
258
|
+
`watch` runs its command repeatedly, so its effect is not once.
|
|
259
|
+
|
|
133
260
|
## BusyBox is not GNU
|
|
134
261
|
|
|
135
262
|
Before reaching for an applet that shadows a GNU tool, remember the flag gaps:
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: managed-tools
|
|
3
|
-
description: "Prefer
|
|
3
|
+
description: "Prefer this toolkit over the system binaries: it is the pinned set, first on PATH. Wrap multi-step shell logic as `busybox sh -c '...'`; plain bash only for arrays, ${v^^} or mapfile. Every bash result is a `[00000.012345789 out]`-prefixed ns timeline, and a slow run gets a `timing:` digest line; prefix a command with `command` for byte-exact output. BusyBox applet names are bare on PATH (`xxd`, `hexdump`, `brief`, `peek`, `waitfor`, `json`, `snapshot`); `sed`/`grep`/`find`/`awk`/`tar` are not. Versioned reads: busybox_peek. Guarded edits: busybox_replace. Captured runs: busybox_run. Prefer rg over grep, fd over find, bat over cat (bat -n -r A:B reads a line range), jq for JSON, gron to explore it, ast-grep over regex edits, just/ninja over guessed builds, shellcheck for shell, prek for hooks. Never `2>&1` — it merges the streams before the timeline can tag them. Call them by bare name: the packaged copy is first on PATH. Flags and which write: managed-tools-reference. Busybox safety: busybox-applets."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Managed tools
|
|
7
7
|
|
|
8
|
-
Twenty-
|
|
8
|
+
Twenty-four binaries on `PATH`, installed and version-tracked by `pi-managed-tools`.
|
|
9
9
|
Their flags are fully known — load `managed-tools-reference` instead of running
|
|
10
10
|
`--help`.
|
|
11
11
|
|
|
12
12
|
fd 10.5.2 · rg 15.2.0 · bat 0.26.1 · just 1.59.0 · gron 0.7.1 ·
|
|
13
|
-
shellcheck 0.11.0 · ast-grep 0.51.3 · ninja 1.13.2 · prek 0.5.11
|
|
13
|
+
shellcheck 0.11.0 · ast-grep 0.51.3 · ninja 1.13.2 · prek 0.5.11
|
|
14
14
|
jq 1.8.2 · yq 4.54.3 · fzf 0.75.0 · uv 0.13.9 · gh 2.105.0 · bd 1.3.4
|
|
15
15
|
agent-browser 0.43.0 · ruff 0.17.6 · mise 2026.11.11
|
|
16
16
|
scc 4.1.0 · duckdb 2.0.1 · miller 6.22.0 · sd 1.1.0 · difftastic 0.72.0
|
|
@@ -32,17 +32,19 @@ Read it as three facts, then continue:
|
|
|
32
32
|
not, say so once (see *Which binary runs*) and keep using bare names anyway.
|
|
33
33
|
2. **Every tool resolves under `<agent dir>/bin`** → versions are the ones in the
|
|
34
34
|
version list above, not the host's.
|
|
35
|
-
3. **`busybox` is present** → multi-step shell logic can use `busybox sh -c '…'
|
|
35
|
+
3. **`busybox` is present** → multi-step shell logic can use `busybox sh -c '…'`,
|
|
36
|
+
and the applet names listed under *Which binary runs* are bare on `PATH`.
|
|
36
37
|
|
|
37
38
|
Do not re-derive this per step: once at the start is enough, and re-checking it
|
|
38
39
|
mid-task is how a session drifts back to `awk`/`python3 -c`.
|
|
39
40
|
|
|
40
41
|
## Order of preference
|
|
41
42
|
|
|
42
|
-
1.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
1. **These binaries over system ones** — they are the same tools, newer, and already on
|
|
44
|
+
`PATH` ahead of `/usr/bin`.
|
|
45
|
+
2. **`brief` when output is long** — `busybox brief -d` collapses repeats without cutting
|
|
46
|
+
a record in half, and `busybox_run` keeps the full capture so nothing is lost.
|
|
47
|
+
3. Plain commands only when you need the bytes exactly as written.
|
|
46
48
|
|
|
47
49
|
This holds for one-liners as much as for whole tasks: a 25-line excerpt is still
|
|
48
50
|
read with `bat`, a single JSON field is still extracted with `jq`, a directory
|
|
@@ -59,13 +61,19 @@ resolves to it; an absolute path is how you silently pick the host's older build
|
|
|
59
61
|
|
|
60
62
|
Check rather than assume: `command -v jq` should print `<agent dir>/bin/jq`.
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
This package sets `PATH` itself at session start —
|
|
65
|
+
`<agent dir>/bin : <agent dir>/busybox-applets : everything else` — so it holds even
|
|
66
|
+
when a shell rc appended the agent bin instead of prepending it. If `command -v jq`
|
|
67
|
+
still prints a host path, do not work around it with an absolute path and do not
|
|
68
|
+
`export PATH=…` in a command (each bash call is a fresh shell): report it and show
|
|
69
|
+
`/managed-tools status`.
|
|
70
|
+
|
|
71
|
+
BusyBox applet names are bare on `PATH` too — `xxd`, `hexdump`, `od`, `strings`,
|
|
72
|
+
`sha256sum` and the other `sha*sum`s, `base64`, `gzip`/`gunzip`/`unzip`, `cpio`,
|
|
73
|
+
`dpkg-deb`, `rpm2cpio`, `timeout`, `setsid`, `nproc`, `realpath`, `seq`, `nl`,
|
|
74
|
+
`paste`, `ts`. `sed`, `grep`, `find`, `awk`, `tar`, `diff`, `ls`, `cp`, `rm`,
|
|
75
|
+
`stat`, `date`, `patch` and `sh` are **not** shadowed, so those keep the host
|
|
76
|
+
build: write `busybox sed …` when you want busybox.
|
|
69
77
|
|
|
70
78
|
One exception: an absolute path is correct when the task is to *inspect* the host
|
|
71
79
|
copy ("is `/usr/bin/jq` older?"). That is a deliberate comparison, not a choice of
|
|
@@ -110,16 +118,182 @@ mutate with **no flag at all** (`sd`, `ruff format`, `just`, `ninja`, `uv run`,
|
|
|
110
118
|
`uv --dry-run`, `mise -n`, `prek run --dry-run`, `bd --readonly`,
|
|
111
119
|
`duckdb -readonly`, `sd -p`, `ast-grep` without `-U`.
|
|
112
120
|
|
|
113
|
-
##
|
|
121
|
+
## Every command comes back as a timeline
|
|
122
|
+
|
|
123
|
+
This is **Pi-Time**: the wrapper attaches time itself — stream, offset, deadline — to
|
|
124
|
+
every execution, because a plain capture cannot say which stream a line came from, when it
|
|
125
|
+
arrived, or how long is too long.
|
|
126
|
+
|
|
127
|
+
pi's `bash` tool is re-registered so each command runs through
|
|
128
|
+
`busybox run --timestamps`: one interleaved line per record, with its offset in seconds and
|
|
129
|
+
the stream it arrived on.
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
[0.011354789 out] ok 1
|
|
133
|
+
[= out] ok 2
|
|
134
|
+
[2.320004125 err] FAILED test_x
|
|
135
|
+
[8.421130000 out] done
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`[= out]` is a line that arrived at the same offset as the one above it: within a burst
|
|
139
|
+
the offset is printed once, and the stream tag stays on every line. (An older build pads
|
|
140
|
+
the number — `[ 0.011354 out]` — and it is the same field.)
|
|
141
|
+
|
|
142
|
+
That is the ordering information a merged stdout/stderr block throws away: the failure
|
|
143
|
+
came *after* `ok 1` and *before* `done`, and a burst of lines sharing one timestamp means
|
|
144
|
+
the writer flushed at exit rather than streaming. Read the offsets before concluding
|
|
145
|
+
anything about causality.
|
|
146
|
+
|
|
147
|
+
- The child gets a split pseudo-terminal: stdout is a tty, so Python, Node, Ruby, C
|
|
148
|
+
stdio and Java line-buffer and their lines carry real intervals; stderr stays a pipe
|
|
149
|
+
and keeps its `err` tag. `isatty()` is therefore **true** — a program that takes a
|
|
150
|
+
different path when interactive will take it here.
|
|
151
|
+
- The timeline is for you. The human watching sees the same output with the prefixes
|
|
152
|
+
stripped, so do not strip or re-print them yourself. A run over a second also gets a
|
|
153
|
+
`timing:` line (total, where output began, the longest silence) — that is the quickest
|
|
154
|
+
way to see where the time went.
|
|
155
|
+
- **Byte-exact output, rarely**: prefix one `&&`/`;` segment with `command`
|
|
156
|
+
(e.g. `command sha256sum f`) and it runs unwrapped — no timeline, no stream tags, no
|
|
157
|
+
timing. That is the point, so do not do it by reflex: keep the timeline unless a
|
|
158
|
+
consumer genuinely needs exact bytes.
|
|
159
|
+
- The wrapper keeps the child's exit status, cwd, shell and environment; it adds
|
|
160
|
+
`PYTHONUNBUFFERED=1`, `NO_COLOR=1`, `TERM=dumb`, `PAGER=cat`, `MAVEN_ARGS=-B -ntp`,
|
|
161
|
+
`GRADLE_OPTS=...console=plain` and a Ruby prelude through `RUBYOPT`, so runtimes stream
|
|
162
|
+
what they can and draw no progress bars.
|
|
163
|
+
- A truncated view is retrievable: `busybox_run run_id=<R> match=<literal>` or
|
|
164
|
+
`busybox log <R> --stream timeline`.
|
|
165
|
+
- **Never `2>&1`** (nor `>&2 2>&1`, `|&`, `2>&1 |`). It merges stderr into stdout *inside
|
|
166
|
+
the child*, before the wrapper can tag anything, so every line arrives `[out]` and the
|
|
167
|
+
warning you needed to see as `[err]` loses its identity — it defeats Pi-Time. The two
|
|
168
|
+
streams are captured separately already: keep them separate and read the tags. Use the
|
|
169
|
+
replacement, not the reflex: to silence noise, drop only the stream you do not want
|
|
170
|
+
(`cmd >/dev/null` keeps stderr tagged; `cmd 2>/dev/null` keeps stdout); to filter
|
|
171
|
+
stderr, run the command plainly and read the `[err]` lines, or re-read a past run with
|
|
172
|
+
`busybox log <R> --stream stderr --match <literal>`; to log a background server, two
|
|
173
|
+
files — `cmd >srv.log 2>srv.err &` — never `>srv.log 2>&1 &`, so a crash report in the
|
|
174
|
+
log keeps its identity as stderr when you read it back. For a quiet test of a command's
|
|
175
|
+
exit status, `cmd >/dev/null` is enough (its stderr stays tagged); for "is a port
|
|
176
|
+
ready", `waitfor --tcp host:port` — not `lsof >/dev/null 2>&1`.
|
|
177
|
+
- **The guard enforces the tail reflex.** A merge at the very end of a command (last
|
|
178
|
+
couple of lines) is refused *before running*: the call comes back blocked with the
|
|
179
|
+
rewrite, so write the replacement instead of retrying the same text. A merge buried
|
|
180
|
+
deep inside a script you authored is left alone; if you genuinely want a merge and will
|
|
181
|
+
not read that output back as evidence, append `# pitime-safe` and the result will say
|
|
182
|
+
its tags are not evidence.
|
|
183
|
+
- **What a result cannot show, it says.** A command that discards a stream
|
|
184
|
+
(`>/dev/null`, `2>/dev/null`), leaves a process in the background, or ran unwrapped
|
|
185
|
+
via `command` gets a line on its result naming exactly what you cannot know from it.
|
|
186
|
+
A pipeline ending in `grep`, `head`/`tail`, or a `|| true` mask gets a line saying whose
|
|
187
|
+
exit code the header shows (grep's 1 = "no match"; `head` SIGPIPEs the command).
|
|
188
|
+
- **Two facts about the shell, worth knowing before they bite**: each bash call starts
|
|
189
|
+
fresh in the session's cwd — `cd` does not persist between calls; and a command's stdin
|
|
190
|
+
is empty: a read returns end-of-file at once, so a prompt (`[y/N]`, a password) takes
|
|
191
|
+
its default or fails instead of waiting, and nobody can answer it. Put the answer in the
|
|
192
|
+
command (`printf 'y\n' | cmd`, `cmd < file`, a heredoc, a `--yes` flag) or in
|
|
193
|
+
`busybox_run`'s `stdin`.
|
|
194
|
+
- Every command has a **120s default deadline**, plus a **120s silence watchdog**: a
|
|
195
|
+
command that produces *no output* for 120s is killed even under a raised deadline, and
|
|
196
|
+
its result says `IDLE — not a failure of the command and not a timeout … this was a
|
|
197
|
+
hang, not slow work` — never stdin (it is empty; a read ends at once), so look at a
|
|
198
|
+
socket, a lock, or a child process that never exits.
|
|
199
|
+
When the deadline fires the result says `TIMEOUT — not a failure of the command`: the
|
|
200
|
+
command was killed for overrunning, it did not error. Genuinely long work? Raise
|
|
201
|
+
`timeout` (seconds) on the bash call, narrow the command, or background it and poll
|
|
202
|
+
with `waitfor`. The partial capture is complete — read it with `busybox log <R>` before
|
|
203
|
+
deciding.
|
|
204
|
+
|
|
205
|
+
Verbosity is per session: `managed_tools` with action `verbosity` (or
|
|
206
|
+
`/managed-tools verbosity`) takes `quiet` (6 KB view), `normal` (48 KB, the default),
|
|
207
|
+
`verbose` (49 KB, the most pi passes on) or `brief` (repeats collapsed, no timeline). `PI_MANAGED_TOOLS_WRAP=off`
|
|
208
|
+
turns the wrapper off entirely.
|
|
209
|
+
|
|
210
|
+
Reading a result, in the order it is laid out:
|
|
211
|
+
|
|
212
|
+
- **A first line in capitals is how it ended, when that was not the command's own exit**:
|
|
213
|
+
`TIMEOUT`, `IDLE`, `CANCELLED`, `KILLED`. Nothing failed; the notice says what to do.
|
|
214
|
+
- **`truncated=true` means the middle is missing.** The view keeps the head and the tail
|
|
215
|
+
with a `... [timeline truncated: …] ...` line between them. The line after the result
|
|
216
|
+
names the omitted lines, the `busybox log <R> --stream timeline --lines A:B` that reads
|
|
217
|
+
from them, and how many of them are on stderr — do not conclude "no errors" from a view
|
|
218
|
+
whose omitted part holds stderr lines.
|
|
219
|
+
- **`pipeline stage statuses: 1 141 0`** is each stage's own exit status, in order; the
|
|
220
|
+
header's `exit_code` is the last one. 141 is a stage cut off because the next one stopped
|
|
221
|
+
reading (`head`), not a failure. No such line means every stage exited 0.
|
|
222
|
+
- **`this command ended in <dir>`** is where a `cd` left it; the next call starts back in
|
|
223
|
+
the session's directory.
|
|
224
|
+
|
|
225
|
+
Three things cannot work in a bash call, because nobody can press a key: answering a
|
|
226
|
+
prompt (stdin is empty — put the answer in the command), a pager or an editor, and anything
|
|
227
|
+
that never ends (`tail -f`, `watch`, a foreground server). The last two are refused before
|
|
228
|
+
they run, with what to write instead. For a command that must keep running, use
|
|
229
|
+
**`busybox_job`**: `action: "start"` with `shell` and a `wait_for` readiness line, then
|
|
230
|
+
`action: "status"` for the output that is new (stderr lines start `err| `), and
|
|
231
|
+
`action: "stop"` when done.
|
|
232
|
+
|
|
233
|
+
## Guarded reads, edits and runs
|
|
234
|
+
|
|
235
|
+
Three tools wrap the packaged busybox agent applets. Each exists because the built-in
|
|
236
|
+
it resembles cannot do one thing:
|
|
237
|
+
|
|
238
|
+
| need | tool | why not the built-in |
|
|
239
|
+
|---|---|---|
|
|
240
|
+
| read a file you are about to edit | `busybox_peek` | returns the file sha256 with the lines, so a later edit can be refused if the file moved |
|
|
241
|
+
| edit with a version guard | `busybox_replace` | a stale sha256 is `STALE_INPUT` and the file stays byte-identical; `dry_run` prints the diff; every edit is validated before anything is written |
|
|
242
|
+
| run something whose output you may need twice | `busybox_run` | stdout and stderr go to artifacts, so `run_id` retrieves lines the bounded view left out; a nonzero `exit_code` is the command status, not a tool failure |
|
|
243
|
+
|
|
244
|
+
Read with `read`, edit with `edit`, run with `bash` when none of those three things
|
|
245
|
+
matter - they are the defaults, and a versioned read costs a call you may not need.
|
|
246
|
+
|
|
247
|
+
The same applets are bare commands for shell work: `peek file -l 20:40`,
|
|
248
|
+
`waitfor --tcp 127.0.0.1:8080`, `doctor`. `replace`, `run`, `log`, `json`, `bench`,
|
|
249
|
+
`snapshot` and `check` are reached as `busybox <applet>` because those words are too generic
|
|
250
|
+
to put ahead of the host.
|
|
251
|
+
|
|
252
|
+
Seven more applets exist for jobs that otherwise become a `python3 -c` one-liner — reach for
|
|
253
|
+
them before writing a script:
|
|
254
|
+
|
|
255
|
+
| instead of | use | what it gives you back |
|
|
256
|
+
|---|---|---|
|
|
257
|
+
| `sleep 5` and hope the server is up | `waitfor --tcp 127.0.0.1:8080 -T 20` | ready/not-ready as an exit code (0 ready, 3 deadline) |
|
|
258
|
+
| `python3 -c 'import json…'` | `busybox json -f pkg.json -g '.deps.react'` (`-k` keys, `-t` type, `-n` count, `-c` validate) | one value on stdout, or `INVALID_JSON at byte N` |
|
|
259
|
+
| `find … -newer` / a manual tree checksum | `busybox snapshot -d src -o before.txt`, later `busybox snapshot --diff before.txt after.txt` | `added=1 removed=0 changed=0` plus the paths |
|
|
260
|
+
| "does this patch series still parse?" | `patchcheck -d patches` | `ok <file>` lines + `checked=N bad=M` (format only, not apply) |
|
|
261
|
+
| timing a command by hand | `busybox bench -n 5 -w 1 -- ./build.sh` | `min_ms/median_ms/max_ms` and a status per run |
|
|
262
|
+
| "why is this applet missing from my build?" | `why grep --format json` | `state`, `decided_by`, and the config/prune line that decided it |
|
|
263
|
+
| "what CLI am I on?" | `doctor --deps git,python3` | platform, cwd, exe, shell, writable temp, dep paths — no environment dump |
|
|
264
|
+
|
|
265
|
+
Full flags and one worked example per applet: `managed-tools-reference`.
|
|
266
|
+
|
|
267
|
+
## Long output: timing first, reduction second
|
|
268
|
+
|
|
269
|
+
Every bash result is already a timeline, so a long run comes with its own order and
|
|
270
|
+
offsets; a run that took more than a second also gets a `timing:` line saying where the
|
|
271
|
+
time went (`3.2s total, silent 2.8s after the last line`). Read that before concluding a
|
|
272
|
+
command "hung" or "was slow": the silence usually names the phase.
|
|
273
|
+
|
|
274
|
+
When the *volume* is the problem, `brief` reduces a log to its shape without cutting a
|
|
275
|
+
record in half. Pick by the question you are asking:
|
|
276
|
+
|
|
277
|
+
| you want | command | why that flag |
|
|
278
|
+
|---|---|---|
|
|
279
|
+
| what failed | `brief -o error -o FAILED log` | selection only: every matching record, whole, nothing merged |
|
|
280
|
+
| what dominates this noise | `brief -s -t 10 log` | `-s` masks digits so lines that differ only by id/percent collapse (646 lines → 8 records, 33 500 B → 381 B on a pytest log); `-d` alone merges only *identical* lines and rarely fires |
|
|
281
|
+
| which file has the most errors | `brief -o error -c 1 -t 10 -i : log` | count instead of list; `-i :` for `path:line: error` output |
|
|
282
|
+
| one failure with its traceback | `brief -R FAILED log` | `-R` is a *literal* substring (no regex): the record starts at each match and runs to the next, so the trace and its summary stay one record |
|
|
283
|
+
| these lines verbatim | `brief -s -k FAILED log` | `-k` records are never merged |
|
|
114
284
|
|
|
115
|
-
`
|
|
116
|
-
`
|
|
117
|
-
|
|
285
|
+
Read the `[brief] …` marker line before trusting the view: `merged=N` is what collapsed,
|
|
286
|
+
`dropped_records` is what was not shown, `truncated_by=budget|selection|record_size` is
|
|
287
|
+
*why*, and `in_bytes` vs `bytes` is the saving. `-F json` returns the same numbers plus a
|
|
288
|
+
one-sentence `summary` and `hints[]` naming the flag that would change the answer.
|
|
118
289
|
|
|
119
|
-
-
|
|
120
|
-
|
|
121
|
-
- Need
|
|
122
|
-
|
|
290
|
+
- **Never reduce the only copy.** Keep the capture (`busybox_run`, `busybox log RUN`) and
|
|
291
|
+
reduce a view of it; a reduction is a lens, not the evidence.
|
|
292
|
+
- **Need exact bytes** (a diff you will edit, JSON you will parse, a checksum): no `brief`.
|
|
293
|
+
Use `bat --paging=never`, `git diff`, `rg`, or prefix the command with `command`.
|
|
294
|
+
- **One call for a run**: `busybox run --brief both` pipes both streams through `brief -d`.
|
|
295
|
+
`--timestamps` silently wins over `--brief` in this build, so choose one.
|
|
296
|
+
- **Unsure**: run it plainly. A re-run costs more than the tokens saved.
|
|
123
297
|
|
|
124
298
|
## Tool choice
|
|
125
299
|
|
|
@@ -129,12 +303,13 @@ pass?" and dangerous for "show me what changed".
|
|
|
129
303
|
| `grep -r` | `rg` (add `--hidden -I` when hidden or gitignored files matter) |
|
|
130
304
|
| `cat` | `bat --paging=never` |
|
|
131
305
|
| regex edit of code | `ast-grep run -p '<pattern>'` (preview, then `-r`) |
|
|
132
|
-
| ad-hoc JSON poking | `gron`, or `
|
|
306
|
+
| ad-hoc JSON poking | `gron`, or `jq -c` |
|
|
133
307
|
| guessing a task command | `just -l` then `just -n` |
|
|
134
308
|
| guessing a build | `ninja -t targets`, then `ninja -n` |
|
|
135
309
|
| eyeballing shell bugs | `shellcheck -f gcc` (advisory; never rewrite) |
|
|
136
310
|
| reading a line range of a file | `bat --paging=never -n -r 900:925 file` — not awk/sed/head |
|
|
137
311
|
| reading or querying JSON | `jq -r '.path'`, `jq -c 'select(...)'` — not python3 -c or grep |
|
|
312
|
+
| editing a JSON document | `busybox json -f f.json -g '.a.b' --set --json-value 42` (or `--delete`, `--dry-run` first) — guarded, no python one-liner |
|
|
138
313
|
| exploring an unknown JSON document | `gron file.json \| rg 'users'` |
|
|
139
314
|
| hand-run hooks | `prek run` (`install` mutates `.git/hooks` — confirm first) |
|
|
140
315
|
| a JSON/YAML fishing trip | `gron`, `jq -r`, or `yq -o json` |
|
|
@@ -149,4 +324,5 @@ pass?" and dangerous for "show me what changed".
|
|
|
149
324
|
| awk-ing CSV or joining tables | `mlr --csv ...` or `duckdb -c "select ..."` |
|
|
150
325
|
| regex rewrite of many files | `sd -p` first, then `sd` (it edits in place) |
|
|
151
326
|
| reading a big diff | `difft --display inline` (structural, falls back to lines) |
|
|
152
|
-
| an applet this package
|
|
327
|
+
| an applet this package links by bare name (`xxd`, `hexdump`, `sha256sum`, `unzip`, `timeout`, `nproc`, `cpio`) | just the name — it is on `PATH` |
|
|
328
|
+
| an applet it does not (`sed`, `grep`, `find`, `awk`, `tar`, `patch`, `tree`) | `busybox <applet>` — never `busybox --install -s` |
|