@rob-c/pi-managed-tools 0.0.0-stage → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,738 @@
1
+ ---
2
+ name: managed-tools-reference
3
+ description: "Exact flags and worked examples for the pinned fd, rg, bat, just, gron, shellcheck, ast-grep, ninja, prek and busybox binaries. Load before invoking any of them, especially for structural edits (ast-grep), build invocation (ninja, just) or reducing a long log (brief)."
4
+ ---
5
+
6
+ # Managed tools — exact reference
7
+
8
+ Versions are fixed by `pi-managed-tools`; every flag listed exists in the
9
+ installed build and nothing else is needed.
10
+
11
+ fd 10.5.2 · rg 15.2.0 · bat 0.26.1 · just 1.59.0 · gron 0.7.1 ·
12
+ shellcheck 0.11.0 · ast-grep 0.51.3 · ninja 1.13.2 · prek 0.5.11
13
+ jq 1.8.2 · yq 4.54.3 · fzf 0.75.0 · uv 0.13.9 · gh 2.105.0 · bd 1.3.4
14
+ agent-browser 0.43.0 · ruff 0.17.6 · mise 2026.11.11
15
+ scc 4.1.0 · duckdb 2.0.1 · miller 6.22.0 · sd 1.1.0 · difftastic 0.72.0 · busybox 1.39.0
16
+
17
+ ## Policy
18
+
19
+ Order: these binaries over the system ones, then `brief` when a log is long. Nothing
20
+ here decides *for* you what to keep: `brief -d` collapses identical records and `-k` keeps
21
+ the ones you name verbatim, and `busybox_run` keeps the full capture in an artifact, so a
22
+ reduction never destroys the evidence.
23
+
24
+ Precedence for every other task: `rg` over `grep`, `fd` over `find`, `bat` over
25
+ `cat`, `ast-grep` over regex on code, `gron` over ad-hoc JSON parsing, `just -l`
26
+ over guessing a recipe, `ninja -t targets`/`-n` over guessing a build step,
27
+ `shellcheck` for shell (advisory), `prek` for hooks.
28
+
29
+ ## Why the bare name resolves to the packaged binary
30
+
31
+ Two independent mechanisms, and one way to defeat both.
32
+
33
+ | Mechanism | Where | Effect |
34
+ |---|---|---|
35
+ | `getShellEnv()` prepends `<agent dir>/bin` | `dist/utils/shell.js` | first entry on `PATH` for every bash call |
36
+ | `getToolPath()` checks `TOOLS_DIR` before `PATH` | `dist/utils/tools-manager.js` | pi's built-in `grep`/`find` use the managed `rg`/`fd` regardless of `PATH` |
37
+
38
+ ```bash
39
+ command -v jq gh rg bat scc # should all print <agent dir>/bin/<tool>
40
+ echo "$PATH" | tr ':' '\n' | head -1 # should be <agent dir>/bin
41
+ ```
42
+
43
+ `getShellEnv()` only prepends **when the directory is not already in `PATH`**. If a
44
+ shell rc appends it (`PATH="$PATH:$HOME/.pi/agent/bin"`), the order is left alone and
45
+ a host copy can win for bash calls — while pi's built-in tools keep using the managed
46
+ ones, so the two paths diverge. Tell the user to prepend and restart pi; an
47
+ `export PATH=…` inside a bash call dies with that call, because each call is a new
48
+ `spawn(shell, [...args, command])`.
49
+
50
+ Never write an absolute binary path (`/usr/bin/jq`, `/opt/homebrew/bin/gh`) to run
51
+ work — it bypasses both mechanisms and pins the host's version forever. The only
52
+ legitimate use is deliberately inspecting the host copy for comparison.
53
+
54
+ ## Read-only vs mutating
55
+
56
+ Assume a bare tool name mutates. `just`, `ninja`, `prek run`, `mise <task>`, `uv run`,
57
+ `sd`, `ruff format`, `agent-browser open`, `duckdb FILE` and any `bd` write verb all
58
+ change something with no flag needed.
59
+
60
+ Dry-run when unsure: `just -n` · `ninja -n` · `uv --dry-run` · `mise -n` ·
61
+ `prek run --dry-run` · `bd --readonly` · `duckdb -readonly` · `ast-grep` without `-U` ·
62
+ `sd -p`.
63
+
64
+ | tool | read-only | mutates (★ = destructive) |
65
+ |---|---|---|
66
+ | fd | everything | nothing itself; `-x`/`-X CMD` runs a child per result |
67
+ | rg | everything (`-r` only changes printed output) | nothing; `--pre CMD` runs a child per file |
68
+ | bat | everything, incl. `--diff` (reads git index) | `cache --build` writes `~/.cache/bat`; ★`cache --clear` deletes it; `--pager CMD` execs |
69
+ | gron | everything (`-u` prints JSON) | nothing |
70
+ | shellcheck | everything (`-f diff` prints a patch only) | nothing |
71
+ | jq | everything (1.8.2 has **no** `-i`) | nothing |
72
+ | mlr | every verb, all format flags | ★`tee FILE` overwrites; ★`split` writes/overwrites `split_*` in cwd; DSL `tee >`/`emit >`; `--prepipe CMD`; `--no-shell` disables |
73
+ | difft | everything (`--check-only` is a pure report) | nothing |
74
+ | fzf | everything, provided no `--history`/`--bind` | `--history FILE` writes; `--bind`/`--preview`/`--info-command` exec; `--listen` allows remote exec |
75
+ | scc | everything except the three below | `-o FILE`, `--format-multi`, `--report=PATH` write (bare `--report` prompts first) |
76
+ | ast-grep | `-p … -r …` only prints; `scan` has **no** `--fix` | ★`-U/--update-all` and `-i/--interactive` rewrite files |
77
+ | sd | `-p/--preview`; stdin to stdout | ★**in place by default** whenever file arguments are given |
78
+ | ruff | `check`, `check --diff`, `format --check`, `format --diff` | ★`format` rewrites by default; `check --fix`/`--unsafe-fixes`; ★`clean` deletes `.ruff_cache` |
79
+ | yq | default prints to stdout | ★`-i/--inplace` rewrites the **first file only**; ★`-s/--split-exp` creates files and dirs (cwd unless `--security-allow-write-any-path`) |
80
+ | duckdb | `-readonly`, `-c` with a plain SELECT | ★`duckdb FILE` creates or opens that db; SQL can CREATE/INSERT/COPY TO; `.shell`, `INSTALL`, `LOAD` |
81
+ | just | `-n/--dry-run`, `-l`, `-s`, `--summary`, `--dump`, `--fmt --check` | ★bare `just` runs the first recipe (arbitrary shell); `--fmt` rewrites the justfile; `--init` creates one; ★`--clean` deletes cached recipe metadata |
82
+ | ninja | `-n` (writes nothing), `-t targets`, `-t commands`, `-t query`, `-t graph`, `-t rules`, `-t deps` | ★bare `ninja` builds (outputs, `.ninja_log`); ★`-t clean`, ★`-t cleandead` delete outputs; `-t restat`, `-t recompact` rewrite the log |
83
+ | prek | `list`, `validate-config`, `validate-manifest`, `run --dry-run`, `cache dir` | `run` executes hooks (often auto-fixers); `install`/`uninstall` write or remove `.git/hooks`; `update` rewrites config revs; ★`cache clean`, ★`cache gc` delete; `self update` replaces the binary |
84
+ | mise | `ls`, `outdated`, `env`, `bin-paths`, `where`, `doctor`, `config ls`, `fmt -c`, any `-n/--dry-run` | `use`/`install` install toolchains and write config; ★`prune`, ★`uninstall --all`, ★`cache clear`, ★`implode` delete; `fmt` rewrites config; `trust`; `self-update`; ★`install-into` wipes the target path |
85
+ | uv | `pip list`, `pip freeze`, `pip tree`, `pip check`, `lock --check`, `python list`, `tree`, `--dry-run` forms | ★`run`/`sync`/`add`/`remove`/`lock` modify env and lockfile with no flag; `pip install`/`pip uninstall`; ★`venv --clear`; `python install`; `tool install`; ★`publish` (remote, irreversible); ★`cache clean`; `auth login`/`auth logout` |
86
+ | gh | subcommand decides; `gh api` is a GET unless `-f`/`-F`/`--input`/`-X` is given | `pr create`/`pr merge`, `issue`, `release`, `run rerun`, `secret set`, `auth login` (writes `hosts.yml`); ★`repo delete`, ★`release delete`, ★`cache delete`, ★`secret delete` |
87
+ | bd | `list`, `show`, `query`, `status`, `count`, `graph`, `history`, `stale`, `lint`; `--readonly` blocks writes | write verbs: `create`, `q`, `update`, `close`, ★`delete`, `comment`, `dep`, `label`; ★`init` also rewrites `AGENTS.md`; writes auto-commit by default |
88
+ | busybox | applet decides; R/M/M★ for all 236 are in `busybox-applets`. `busybox <applet>` only | ★`busybox --install -s DIR` (236 symlinks), ★`bb <mutating applet>` |
89
+ | agent-browser | `snapshot`, `get`, `read`, `vitals`, `console`, `errors` | `open`/`click`/`fill`/`type`/`eval` drive the live page; ★`screenshot` writes a file even with no path; `pdf`, `download`, `state save`, ★`close --all`; starts a background daemon |
90
+
91
+ ## fd — files
92
+
93
+ `fd [opts] [pattern] [path...]` · regex by default, all entries with no pattern.
94
+
95
+ `-e EXT` · `-t f|d|l|x|e|s|p` type · `-d N` depth · `-H` hidden · `-I` no-ignore
96
+ `-L` follow links · `-g` glob pattern · `-s` case-sensitive · `-i` ignore case
97
+ `-a` absolute · `-0` NUL-separate · `-x CMD` run per result · `-X CMD` run once
98
+ `--exclude GLOB` · `--changed-within DUR`
99
+
100
+ ```bash
101
+ fd -e ts . src # pattern first: '.' = everything, then the path
102
+ fd -td -d 2 # directories to depth 2 — the tree replacement
103
+ fd -H -I '\.env' -d 1 # hidden + ignored
104
+ fd -0 -e json | xargs -0 jq -r .name
105
+ fd -e sh -x shellcheck -f gcc # lint each match
106
+ ```
107
+
108
+ `fd PATTERN PATH` — the first positional is the pattern, so a bare directory
109
+ name becomes a search term. Pass `.` to match everything in a path.
110
+
111
+ ## rg — contents
112
+
113
+ `rg [opts] PATTERN [path...]`
114
+
115
+ `-i` ignore case · `-S` smart case · `-w` word · `-F` fixed string · `-n` line no
116
+ `-c` count · `-l` names only · `-o` match only · `-A/-B/-C N` context
117
+ `-t TYPE` · `-g GLOB` · `--hidden` · `-u` unrestrict (repeatable) · `-U` multiline
118
+ Skips hidden and `.gitignore`d files by default: use `--hidden -I` (or `-uu`) when a
119
+ search must see everything, or results silently go missing.
120
+ `-r REPL` · `-z` inside .gz · `--json` · `--stats` · `--files` · `--type-list`
121
+
122
+ ```bash
123
+ rg -n -C2 'TODO' src
124
+ rg -l -t ts 'deprecated'
125
+ rg -F -f patterns.txt # patterns from a file
126
+ rg --json 'x' | jq -r 'select(.type=="match") | .data.path.text' | sort -u
127
+ ```
128
+
129
+ ## bat — view
130
+
131
+ `bat [opts] FILE...` · always add `--paging=never` here; stdout is not a TTY.
132
+
133
+ `-p` plain · `-pp` plain + no paging · `-n` numbers · `-A` non-printing chars
134
+ `-r A:B` line range · `-H/--highlight-line N:M` highlight lines · `--diff` git diff
135
+ `-l LANG` · `--style plain,numbers,header,grid,changes` (header = filename)
136
+ `--decorations=always` — required, or style is dropped when stdout is a pipe
137
+
138
+ ```bash
139
+ bat --paging=never -r 40:80 src/app.ts
140
+ bat --paging=never --diff --diff-context 3 src/app.ts # vs git index
141
+ bat --paging=never --decorations=always --style header,numbers src/app.ts
142
+ ```
143
+
144
+ `-H` is `--highlight-line`, not a filename header — use `--style header` for that.
145
+
146
+ ## just — task runner
147
+
148
+ `just [opts] [recipe] [args...]`
149
+
150
+ `-l` list recipes · `--summary` names only · `-s RECIPE` show recipe source
151
+ `-n` dry run · `-f FILE` · `-d DIR` · `--set VAR VAL` · `--choose` picker
152
+
153
+ ```bash
154
+ just -l # discover before assuming
155
+ just -s build # read what a recipe does
156
+ just test -- --nocapture # args after -- reach the recipe
157
+ just -n deploy # dry run
158
+ ```
159
+
160
+ ## gron — JSON to greppable
161
+
162
+ `gron [opts] [file|URL|-]`
163
+
164
+ `-u` reverse (assignments → JSON) · `-v` values only · `-s` stream JSONL
165
+ `-j` JSON stream · `-m` monochrome · `--no-sort` · `-k` skip TLS verify
166
+
167
+ ```bash
168
+ gron data.json | rg 'users'
169
+ gron data.json | gron -v | rg -c . # -v reads assignments, so pipe into it
170
+ gron -u out.gron > restored.json
171
+ ```
172
+
173
+ `-v` filters *assignments* on stdin; it does not read a JSON file on its own.
174
+
175
+ ## shellcheck — shell lint, advisory
176
+
177
+ `shellcheck [opts] FILES`
178
+
179
+ `-f checkstyle|diff|gcc|json|json1|quiet|tty` · `-e CODES` exclude
180
+ `-i CODES` include only · `-S error|warning|info|style` · `-s sh|bash|dash|ksh|busybox`
181
+ `-x` follow sources · `-a` include sourced warnings · `-o all` optional checks
182
+ `-P PATH` source path · `--norc` · `--rcfile FILE`
183
+
184
+ ```bash
185
+ shellcheck -f gcc -S warning scripts/*.sh
186
+ shellcheck -s bash -e SC1091 -f json1 script.sh
187
+ ```
188
+
189
+ Never use `-f diff` to rewrite: report findings and let the user decide.
190
+
191
+ ## ast-grep — structural search and rewrite
192
+
193
+ `ast-grep run -p 'PATTERN' -l LANG [paths]` · `$VAR` = one node, `$$$` = many.
194
+
195
+ `-p/--pattern` · `-l/--lang` · `-r/--rewrite` · `-A/-B/-C N` context · `-i` interact
196
+ `--json[=STYLE]` · `--globs GLOB` (there is no `-g`) · `-A/--after N` · `-B/--before N`
197
+ `--strictness cst|smart|ast|relaxed|signature|template` · `--selector KIND`
198
+
199
+ Subcommands: `run` · `scan` (rule files) · `test` · `outline` · `lsp` · `new`
200
+
201
+ ```bash
202
+ ast-grep run -p 'console.log($A)' -l ts src # preview first
203
+ ast-grep run -p 'console.log($A)' -l ts -r 'logger.info($A)' src
204
+ ast-grep run -p 'if ($C) { $$$B }' -l go # multi-statement body
205
+ ast-grep outline src/app.ts # symbols, imports, members
206
+ ```
207
+
208
+ Preview without `-r`, then add `-r`. Never regex a codebase you intend to edit.
209
+
210
+ The archive also installs `sg`, a deprecated alias that **execs `ast-grep`**: it
211
+ only works while `ast-grep` is present and runnable. Use `ast-grep` in new
212
+ commands. `sg` shadows util-linux's `/usr/bin/sg` on Linux; delete
213
+ `<agent dir>/bin/sg` if you need the system one.
214
+
215
+ ## ninja — build
216
+
217
+ `ninja [opts] [targets...]` · no target builds `default`.
218
+
219
+ `-C DIR` · `-f FILE` (default `build.ninja`) · `-j N` · `-k N` · `-l N` load avg
220
+ `-n` dry run · `-v` verbose · `--quiet` · `-t TOOL` subtool · `-d MODE` · `-w FLAG`
221
+
222
+ Subtools: `-t targets` · `-t commands` · `-t query TARGET` · `-t graph`
223
+ `-t compdb RULES` · `-t clean` · `-t list`
224
+
225
+ ```bash
226
+ ninja -t targets all | head
227
+ ninja -n -v # dry run before a real build
228
+ ninja -C build -j8
229
+ ninja -t compdb cc cxx > compile_commands.json
230
+ ```
231
+
232
+ `-t` ends option parsing; later flags belong to the subtool.
233
+
234
+ ## prek — git hooks (pre-commit compatible, Rust)
235
+
236
+ `prek [opts] [HOOK|PROJECT]... [COMMAND]`
237
+
238
+ Commands: `run` · `install` · `list` · `init` · `update` · `prepare-hooks`
239
+ `uninstall` · `validate-config` · `validate-manifest` · `cache` · `try-repo` · `exec`
240
+
241
+ `-a/--all-files` · `--files PATH...` · `--files0-from FILE` · `--last-commit`
242
+ `--skip HOOK` · `--stage STAGE` · `-v`
243
+
244
+ ```bash
245
+ prek list # configured hooks
246
+ prek run --all-files
247
+ prek run ruff --files src/x.py
248
+ ```
249
+
250
+ `install` writes `.git/hooks` — confirm with the user before running it.
251
+
252
+ ## jq — JSON
253
+
254
+ `jq [opts] FILTER [file...]` · input from stdin or files.
255
+
256
+ `-r` raw output (no quotes) · `-c` compact · `-e` exit status from filter · `-s` slurp
257
+ `-n` null input · `-j` join without newlines · `-S` sort keys · `-f FILE` filter file
258
+ `--arg k v` string var · `--argjson k v` JSON var · `--slurpfile` · `-C` colour · `-M` monochrome
259
+
260
+ ```bash
261
+ jq -r '.items[].name' data.json
262
+ jq -c 'select(.level == "error")' log.jsonl
263
+ jq -e '.ok' <<< '{"ok":true}' >/dev/null && echo pass
264
+ jq -S --arg n "$USER" '. + {user: $n}' in.json
265
+ ```
266
+
267
+ `-r` is the difference between usable and quoted output in a pipeline. Prefer `gron`
268
+ for exploring an unknown document and `jq` for a filter you already know.
269
+
270
+ ## yq — YAML/JSON/XML
271
+
272
+ `yq [opts] EXPRESSION [file...]` · **mikefarah/yq v4** (Go). kislyuk/yq is a
273
+ different Python tool with different flags; do not mix their syntax.
274
+
275
+ `-r` raw · `-o json|yaml|props|xml|csv|tsv` output format · `-i` in place
276
+ `-e` exit status · `-N` no doc separator · `-P` pretty print · `-I N` indent
277
+ `env(NAME)`/`strenv(NAME)` read the environment (there is no `--arg`) · `-n` null input
278
+
279
+ ```bash
280
+ yq '.services.web.image' compose.yaml
281
+ yq -o json '.spec' k8s.yaml | jq .replicas
282
+ yq -i '.version = "2"' chart/Chart.yaml
283
+ yq -r '.users[].email' users.yaml
284
+ ```
285
+
286
+ `-i` writes the file: print first, then re-run with `-i`.
287
+
288
+ ## fzf — fuzzy select
289
+
290
+ `fzf [opts]` · **needs a TTY for interactive use**, which pi's bash does not provide.
291
+ Interactive selection fails; filtering does not.
292
+
293
+ `--filter TEXT` non-interactive match · `-f` alias · `--select-1` · `--exit-0`
294
+ `-1/--first` · `-n` field index · `--delimiter` · `-q` query · `--height` · `--preview`
295
+
296
+ ```bash
297
+ fd -e ts | fzf --filter auth # works without a TTY
298
+ fd -e ts | fzf --filter auth -1 # best single match
299
+ rg -l TODO | fzf --filter '' --select-1
300
+ ```
301
+
302
+ There is no pipe-friendly interactive mode: use `--filter` to narrow, or ask the user.
303
+
304
+ ## uv — Python packaging
305
+
306
+ `uv <cmd>` · also installs `uvx` (run a tool without installing it globally).
307
+
308
+ `uv run` · `uvx` · `uv pip install|sync|compile` · `uv venv` · `uv add|remove`
309
+ `uv lock` · `uv sync --frozen` · `uv python install|pin` · `uv tool install`
310
+
311
+ ```bash
312
+ uv run pytest -q # project env, no activation
313
+ uvx ruff check . # ephemeral tool run
314
+ uv sync --frozen # exactly the lockfile
315
+ uv pip compile requirements.in -o requirements.txt
316
+ ```
317
+
318
+ `uv` creates Python toolchains and caches outside this bin directory. Prefer
319
+ `uv run <cmd>` so the project's own pinned version is used.
320
+
321
+ ## gh — GitHub CLI
322
+
323
+ `gh <cmd>` · **credential-bearing**: it stores an OAuth token in `~/.config/gh/hosts.yml`.
324
+
325
+ `gh pr|issue|repo|run|release|api|search|auth` · `--json FIELDS` · `-q JQ`
326
+ `gh api` for anything the porcelain lacks · `GH_TOKEN` overrides stored auth
327
+
328
+ ```bash
329
+ gh pr list --json number,title --jq '.[].title'
330
+ gh run list --limit 5
331
+ gh api repos/{owner}/{repo}/pulls --jq '.[].title'
332
+ gh pr diff 123
333
+ ```
334
+
335
+ `gh pr diff` is content you must read as written.
336
+
337
+ ## bd — issue tracker
338
+
339
+ `bd <cmd>` · gastownhall/beads, a Dolt-backed issue tracker stored in `.beads/`
340
+ in the current project. Dolt is embedded, so the single binary is enough.
341
+
342
+ Reading (safe): `list` · `show <id>` · `status` · `count` · `search TEXT` ·
343
+ `query <expr>` · `graph` · `children <id>` · `stale` · `lint` · `history <id>`
344
+
345
+ Writing: `create` · `q` (quick capture, prints only the ID) · `update` ·
346
+ `close` · `reopen` · `comment` · `note` · `dep` · `label` · `priority` · `assign`
347
+
348
+ Sync: `bd dolt push` / `bd dolt pull`
349
+
350
+ ```bash
351
+ bd list --status open
352
+ bd show bd-42
353
+ bd q "login button does nothing on safari" # prints just the new ID
354
+ bd query 'status=open priority>2'
355
+ bd graph
356
+ bd comment bd-42 --body "reproduced on main"
357
+ ```
358
+
359
+ **`bd init` mutates the project.** It creates `.beads/` with a Dolt database,
360
+ **rewrites `AGENTS.md` by default**, and installs editor/agent integration files
361
+ unless given `--skip-agents` or `--stealth`. `bd setup <tool>` writes those
362
+ integration files too (`--global` writes into your home directory). Ask before
363
+ running either; prefer the read-only commands otherwise.
364
+
365
+ Not present: there is no `.beads/` until someone runs `bd init`, so an empty
366
+ `bd list` usually means "not initialised", not "no issues".
367
+
368
+ `bd` sends **anonymous usage metrics by default** (command names, version, OS —
369
+ not issues, paths or identities). Set `DO_NOT_TRACK=1` to disable it; that is the
370
+ user's call, not something to set for them.
371
+
372
+ ## agent-browser — browser automation
373
+
374
+ `agent-browser <command>` — drives a real browser through a **daemon**, so the
375
+ page survives between separate invocations.
376
+
377
+ `open <url>` · `read [url]` · `snapshot` (accessibility tree with `@eN` refs) ·
378
+ `click @eN` · `fill @eN TEXT` · `type` · `press KEY` · `wait <sel|ms>` ·
379
+ `screenshot [path]` · `pdf <path>` · `eval <js>` · `close [--all]`
380
+ `get text|html|value|attr <name>|title|url|count|box|styles`
381
+ `--session NAME` · `--restore` · `session id|info` · `--profile Default` ·
382
+ `connect <port|url>` (CDP) · `chat "..."`
383
+
384
+ ```bash
385
+ agent-browser open example.com && agent-browser snapshot -i
386
+ agent-browser fill @e1 "user@example.com" && agent-browser click @e2
387
+ agent-browser read https://example.com
388
+ agent-browser screenshot /tmp/shot.png
389
+ ```
390
+
391
+ Snapshot first, then act on the `@eN` refs it returns — do not guess selectors.
392
+
393
+ Three things this build does not give you: it needs a local Chrome/Chromium (or an
394
+ existing browser via `connect`), it leaves a daemon running (stop it with
395
+ `close --all`), and **`agent-browser skills get core` fails** — the release binary
396
+ ships no skills directory despite what `--help` says. No win32-arm64 build.
397
+
398
+ ## ruff — Python lint and format
399
+
400
+ `ruff check [paths]` · `ruff format [paths]`
401
+
402
+ `--select CODE` · `--ignore CODE` · `--fix` · `--diff` (preview) · `--unsafe-fixes`
403
+ `--output-format concise|json|github|gitlab|junit|sarif` · `--statistics` ·
404
+ `--no-cache` · `--line-length N` · `--check` (format only)
405
+
406
+ ```bash
407
+ ruff check --statistics .
408
+ ruff check --diff --fix . # preview the fix, change nothing
409
+ ruff format --check .
410
+ ruff check --select E,F --output-format json .
411
+ ```
412
+
413
+ Most repositories pin ruff in their own environment. Prefer `uv run ruff ...` so
414
+ the pinned version decides the rules; use the managed copy for a quick check
415
+ outside a project environment, and never let it rewrite files the project's own
416
+ version would format differently.
417
+
418
+ ## mise — dev tool and task runner
419
+
420
+ `mise <cmd>` — installs toolchains and runs project tasks. It is a **version
421
+ manager**, and pi's `bash` never sources rc files, so `mise activate` is inert
422
+ here: use `mise exec` instead.
423
+
424
+ `mise exec -- CMD` (alias `x`) · `mise run TASK` · `mise ls` · `mise current` ·
425
+ `mise env` · `mise install` · `mise use` · `mise trust` · `mise doctor` ·
426
+ `mise bin-paths` · `mise tasks`
427
+
428
+ ```bash
429
+ mise exec -- node --version
430
+ mise run test
431
+ mise ls --current
432
+ mise doctor
433
+ ```
434
+
435
+ Ask before `mise install`, `mise use` or `mise trust`: they write `mise.toml` and
436
+ install toolchains under `~/.local/share/mise`, outside this bin directory.
437
+ `mise exec --` is the only form that reliably picks up a project's pins from here.
438
+
439
+ ## scc — lines of code
440
+
441
+ `scc [flags] [paths...]` · ignores vendor/generated files by default.
442
+
443
+ `-f/--format tabular|wide|json|json2|csv|sql|html|openmetrics` · `--by-file` ·
444
+ `-i/--include-ext` · `-x/--exclude-ext` · `--exclude-dir` · `--no-gen` ·
445
+ `-c/--no-complexity` · `--no-cocomo`
446
+
447
+ ```bash
448
+ scc .
449
+ scc --by-file -f csv . | head
450
+ scc -i go,ts --no-gen .
451
+ ```
452
+
453
+ ## duckdb — SQL over files
454
+
455
+ `duckdb [OPTIONS] [FILENAME] [SQL]` · no filename means an in-memory database, and
456
+ CSV/Parquet/JSON are queryable directly by path.
457
+
458
+ `-c COMMAND` run and exit · `-csv` · `-json` · `-jsonlines` · `-header` · `-f FILE` ·
459
+ `-no-agent` · dot-commands via `.help`
460
+
461
+ ```bash
462
+ duckdb -c "select 1"
463
+ duckdb -csv -no-agent -c "select * from 'data.csv' limit 5"
464
+ duckdb -json -c "select count(*) n from read_parquet('x.parquet')"
465
+ duckdb -c "create table t as select * from 'a.csv'; select count(*) from t"
466
+ ```
467
+
468
+ Agent mode prints a banner before every result when `AI_AGENT` is set and stdout is
469
+ not a terminal — i.e. always here — so pass `-no-agent` (or `DUCKDB_AGENT_MODE=0`)
470
+ when the banner would pollute the output.
471
+
472
+ ## miller — CSV, TSV and JSON
473
+
474
+ `mlr [flags] [verb] [verb options] [files...]` · with no verb it behaves like `cat`;
475
+ chain verbs with `then`.
476
+
477
+ `--csv` · `--tsv` · `--json` · `--icsv`/`--ojson` · `--c2j` · `-N` no header ·
478
+ verbs: `cut` `filter` `put` `sort` `join` `stats1` `count-distinct` `nest`
479
+ `flatten` `head` `tail`
480
+
481
+ ```bash
482
+ mlr --csv cut -f name,email users.csv
483
+ mlr --c2j cat data.csv
484
+ mlr --csv filter '$qty > 10' then sort -f sku data.csv
485
+ mlr --csv stats1 -a mean -f price sales.csv
486
+ ```
487
+
488
+ ## sd — find and replace
489
+
490
+ `sd [OPTIONS] <FIND> <REPLACE_WITH> [FILES]...` · regex by default ·
491
+ **rewrites files in place**; with no files it filters stdin to stdout.
492
+
493
+ `-p/--preview` · `-F/--fixed-strings` · `-n/--max-replacements N` · `-f/--flags` ·
494
+ `-A/--across`
495
+
496
+ ```bash
497
+ sd -p '\d+' 'N' file.txt # preview, changes nothing
498
+ sd 'foo' 'bar' src/*.ts # rewrites in place
499
+ sd -F 'a.b' 'a-b' file.txt # literal, not regex
500
+ echo 'x=1' | sd 'x' 'y'
501
+ ```
502
+
503
+ Always preview with `-p` first: without it the matched files are rewritten.
504
+
505
+ ## busybox — 276 applets in one binary
506
+
507
+ `busybox <applet> [args]` · v1.39.0, statically linked. Dispatches on **argv[0]**, so
508
+ the installed file must stay named `busybox`.
509
+
510
+ ```bash
511
+ busybox --list # all 276 applet names
512
+ busybox hexdump -C file.bin
513
+ busybox sha256sum file
514
+ busybox unzip archive.zip
515
+ busybox date -u +%FT%TZ
516
+ ```
517
+
518
+ Per-applet read-only vs mutating classification, including which flags cause a
519
+ write, is in the `busybox-applets` skill — load it before running any applet that
520
+ is not obviously an inspection command.
521
+
522
+ **Do not run `busybox --install -s <dir>`.** In pi's bin directory (first on `PATH`)
523
+ it would put 276 applets ahead of the real coreutils, and busybox `sed`, `grep`,
524
+ `find`, `tar` and `awk` are not GNU-compatible. Prefer this package's dedicated
525
+ tools (`rg`, `fd`, `bat`, `jq`, `scc`, `difft`) and use busybox for what nothing
526
+ else covers: `hexdump`, `xxd`, `unzip`, `gzip`, `patch`, `cpio`, `dpkg-deb`,
527
+ `sha*sum`, `date`, `hostname`.
528
+
529
+ ### The three pi tools, and which applet each wraps
530
+
531
+ The tools are registered by this package; `/managed-tools status` says whether the wrapper is
532
+ on and at which verbosity/pty mode.
533
+
534
+ | tool | wraps | use it when |
535
+ |---|---|---|
536
+ | `busybox_peek` | `peek PATH --lines/--around … --format json` | you need the file's `sha256` to guard an edit, lines around a literal match, or a byte-bounded read with a continuation cursor |
537
+ | `busybox_replace` | `busybox replace` (single edit) or `busybox replace --request` (a batch) | you have a version from `busybox_peek` and want stale-input rejection, `dry_run` diffs, and all edits validated before any write |
538
+ | `busybox_run` | `busybox run --timestamps --pty-split --format json`, and `busybox log RUN` when `run_id` is given | you need the structured record rather than the timeline: separate stdout/stderr, artifacts, `--stream timeline`, or a retrieval by `lines`/`match` |
539
+
540
+ Both `--sha256` and the tools' `sha256` accept the 12-character prefix `peek` prints. A
541
+ `match` with no `stream` searches stdout and then stderr before reporting NOT_FOUND.
542
+
543
+ ### brief — reduce a log to its shape, without cutting it
544
+
545
+ `brief [OPTS] [FILE]` · stdin or a file · text by default, `-F json` for schema 1.
546
+ It reduces **records**, and a record is one line — or, with `-R STR`, every line up to the
547
+ next match, so a stack trace, a commit or a test failure is one record. A record is shown
548
+ whole or not at all: the byte budget drops records, it never truncates one.
549
+
550
+ | flag | effect |
551
+ |---|---|
552
+ | `-d` | group identical records, print `Nx <line>` |
553
+ | `-s` | group records equal **after masking digits** (implies `-d`) — the flag that fires on real logs |
554
+ | `-t N` | order groups by count, highest first |
555
+ | `-m N` | only groups seen at least N times |
556
+ | `-o STR` / `-x STR` | show only / drop records containing STR (repeatable, OR) |
557
+ | `-R STR` | a record *starts* at each line containing STR — **literal, not a regex**; `-R '^FAILED'` matches nothing |
558
+ | `-k STR` | keep records containing STR verbatim, never merged |
559
+ | `-c LIST` | group by these 1-based fields (`1`, `3-4`) and count them |
560
+ | `-f LIST` | show only these fields; `-i SEP` input separators, `-S SEP` join |
561
+ | `-q` | bare records: no `Nx ` and no `+ ` prefix (for piping on) |
562
+ | `-B N` | output budget, default 8000 bytes. Must exceed the body you want: `-B 0` shows **nothing** in this build, so use a number larger than the input for "everything" |
563
+ | `-n N` | maximum distinct records kept, default 2000 |
564
+ | `-a N` | samples per group, 1–8, printed with a `+ ` prefix so they cannot read as repeats |
565
+
566
+ ```bash
567
+ brief -o error -o FAILED build.log # the failures, whole, nothing merged
568
+ brief -s -t 10 pytest.log # the ten most frequent shapes
569
+ brief -s -k FAILED pytest.log # collapse repeats, keep failures verbatim
570
+ brief -R FAILED pytest.log # each failure with its traceback and summary (literal match)
571
+ brief -o error -c 1 -t 10 -i : tsc.log # ten files with the most errors
572
+ brief -B 500000 -q build.log | sort -u # hand the whole body to another command (note: -B 0 shows nothing)
573
+ brief -s -F json pytest.log # numbers, a summary sentence, and hints
574
+ ```
575
+
576
+ Measured on a 646-line pytest log (33 500 B): `-s` returned 8 records in 381 B
577
+ (`merged=638`); `-d` alone left 162 records and hit the budget, because every line had a
578
+ different index. `-o error` returned the 40 diagnostic lines exactly (`truncated_by=selection`).
579
+
580
+ Two build behaviours to know before trusting a number: `-R` matches **literal** text, so an anchored pattern reports `matched=1, shown_lines=0` and shows nothing, and `-B 0` is a *zero* budget — it prints the marker and no records, even though the JSON hint calls it "no limit". Verify with the marker rather than the hint.
581
+
582
+ **The marker line is the honest part.** `[brief] lines_in=… records=… kept=… shown_lines=…
583
+ merged=… dropped_records=… dropped_lines=… nul=… bytes=… truncated=… shown_groups=…
584
+ projected=… bare=… top=… min=… matched=… in_bytes=… truncated_by=…`. Read `merged` (what
585
+ collapsed), `dropped_records` (what was not shown, including records before the first `-R`
586
+ match), and `truncated_by`: `budget` (raise `-B`), `selection` (that *is* everything that
587
+ matched), `record_size` (a single record did not fit or had no match) or `-` (nothing cut).
588
+
589
+ **`-F json`** adds `schema`, a one-sentence `summary` ("646 lines in, 8 records, all shown,
590
+ 381 of 33500 body bytes, complete"), `pct_of_input`, and `hints[]` that name the flag which
591
+ would change the answer ("638 lines are repeats of a shown record: -t 10 ranks them first").
592
+ Per-group objects are `items[]: {n, lines, kept, line}`; `records` is a count, not the list.
593
+
594
+ Rules of thumb: `-s` before `-d`; `-t` when you want the shape rather than the list; `-k`
595
+ for anything you must see verbatim; never reduce the only copy of the evidence; and never
596
+ `brief` output you are about to parse or diff — that is what `command` and `busybox_run` are
597
+ for.
598
+
599
+ ### The other agent-facing applets: waitfor, doctor, json, snapshot, patchcheck, bench, why, mark, outline, patchapply
600
+
601
+ The six applets with a full section above (`peek`, `replace`, `run`, `log`, `brief`) and the
602
+ three pi tools cover reads, edits and runs. These ten cover everything else a session
603
+ tends to hand-roll:
604
+
605
+ | applet | what it is for | example |
606
+ |---|---|---|
607
+ | `waitfor` | bounded readiness: `--file`, `--tcp host:port`, `--unix`, `--http url --expect 200`; `-T` deadline, `-i` poll interval | `busybox waitfor --tcp 127.0.0.1:8080 --timeout 20` |
608
+ | `doctor` | what this CLI is: `platform`, `cwd`, `exe`, `shell`, `tmp` writability, `--deps a,b` paths | `busybox doctor --deps git,python3` |
609
+ | `json` | query without `jq` (`-f FILE`, `-g '.a.b[2]'`, `-k`/`-t`/`-n`, `-c` validate) and now **edit guarded**: `-g PATH --set --value S` or `--json-value JSON`, `-g PATH --delete`, `--dry-run` previews; parses first, a missing parent is refused (exit 1), temp+rename | `busybox json -f pkg.json -g '.version' --set --json-value '"2.0.0"'`, `busybox json -f d.json -g '.stale' --delete --dry-run` |
610
+ | `snapshot` | hash a tree in one pass (`<sha256> <bytes> <path>` per file), `-o FILE`, `--diff A B` | `busybox snapshot -d src -o before.txt`, then `--diff before.txt after.txt` |
611
+ | `patchcheck` | every `*.patch` in a directory parses: `ok <file>` + `checked=N bad=M` | `busybox patchcheck -d patches` |
612
+ | `bench` | time a command N times after warmup: `run=1 ms=5.530 status=0` + `min/median/max` | `busybox bench -n 5 -w 1 -- ./build.sh` |
613
+ | `why` | is this applet in the binary, and which config line decided it (`-C .config`, `-p prune`) | `busybox why grep --format json` |
614
+ | `mark` | name a moment inside the current run's timeline (`<run>/marks`, µs + name) | `busybox mark built-ok` inside a script, then `busybox log <R> --marks` |
615
+ | `outline` | a file's definitions with line, byte offset and a version each — the index to `peek`/`busybox_replace` | `busybox outline -f json src/tools.ts` |
616
+ | `patchapply` | apply a unified diff with every hunk verified first; `-c PATH=HASH` refuses on drift; `-n` dry-run | `busybox patchapply -c src/a.ts=<sha256> fix.patch` |
617
+
618
+ Each takes `--format json` (schema 1) and follows the same exit codes (0 ok, 1 refused, 2
619
+ usage, 3 timeout). Details worth knowing before trusting an answer:
620
+
621
+ - `busybox json -c` prints nothing on success and `INVALID_JSON at byte N: …` with exit 1 on
622
+ failure — validation, not a parse-then-report.
623
+ - `snapshot --diff` reports `added` / `removed` / `changed` counts and the paths; it compares
624
+ content hashes, so it cannot say *what* changed inside a file.
625
+ - `patchcheck` checks that each patch **parses**. A patch that parses but would conflict
626
+ still reports `ok`, so use it as a format gate, not an apply test.
627
+ - `bench` discards the command's output and reports timing only; `-w` warmup runs are not
628
+ counted.
629
+ - `why` needs a `.config` (`-C`). With none it answers `unknown <applet>` plus `symbol=…` and
630
+ `config: (no <APPLET> entry in .config)`, and exits **0** even though the JSON payload
631
+ carries `"status":"error","code":"NOT_FOUND"` — read the payload, not the exit code.
632
+ - `waitfor --tcp` proves the port accepts connections, not that the application behind it is
633
+ ready; `--http` is implemented for `http://` only.
634
+
635
+ ### Agent-facing applets: peek, replace, run, log, waitfor, doctor
636
+
637
+ Six applets with one contract: text by default, `--format json` (`"schema":1`) on
638
+ request, byte budgets, and `shown_bytes`/`truncated` reported. Exit codes are the
639
+ same everywhere: **0** ok (truncation is still 0), **1** refused/failed, **2** usage,
640
+ **3** timeout or cancellation. Error codes in the payload decide the message
641
+ (`STALE_INPUT`, `AMBIGUOUS_MATCH`, `NOT_FOUND`, `INVALID_ARGUMENT`, `TIMEOUT`,
642
+ `CANCELLED`, `CAPTURE_INCOMPLETE`, `UNSUPPORTED`). Exit 3 from a kill is **not** the
643
+ command failing: every wrapped bash call has a 120s default deadline, and when it fires the
644
+ result says `TIMEOUT — not a failure of the command` and points at `busybox log <R>` for
645
+ the partial capture — recover (extend `timeout`, narrow the command) rather than debug.
646
+
647
+ `peek` — numbered lines plus the file's version; ranges are 1-based and inclusive:
648
+
649
+ ```bash
650
+ busybox peek src/server.ts --lines 120:180 # 120 through 180
651
+ busybox peek src/server.ts --around handleConnection --context 20
652
+ busybox peek src/server.ts --around 'def \w+' --regex --context 5
653
+ busybox peek big.log --from-byte 2841 --max-bytes 16000 # continue a truncated read
654
+ busybox peek --request reads.json --format json # batch, one shared budget
655
+ ```
656
+
657
+ `replace` — literal, validated-before-write, atomic; `--expect` defaults to 1 and a
658
+ mismatch leaves the file byte-identical:
659
+
660
+ ```bash
661
+ busybox replace a.ts --old 'const timeout = 1000;' --new 'const timeout = 5000;' --dry-run
662
+ busybox replace a.ts --old 'timeout = 1000' --new 'timeout = 5000' --sha256 <hex from peek>
663
+ busybox replace a.ts --old 'x' --new 'y' --expect 3
664
+ busybox replace --request edits.json --format json # {"edits":[{"path","old","new","expect"}]}
665
+ ```
666
+
667
+ `run`/`log` — argv is exec'd verbatim, or `--shell` for a shell line; stdout and
668
+ stderr are separate 0600 artifacts and the view is a bounded head+tail. `-t` is the
669
+ timeline (`[0.011354789 out] line`, ns stamps with `-n`, interleaved by arrival; a truncated view keeps the head and the tail and marks the cut between them), `-q` drops the summary,
670
+ `-b WHICH` reduces a stream through `brief`, `-e NAME=VALUE` sets one variable for the
671
+ child, `-P` prints the child's process group, `-i FILE` feeds stdin, `-r N` prunes old runs, `-W SECS` is an idle timeout (kill after silence; the wrapper always applies 120s), `-C N` bounds capture bytes per stream, `-d DIR` sets the child's cwd, `-x/--effects` reports files created/changed/removed under the run's cwd (**JSON output only** — text mode does not print it in this build), and `--format json` reports what the command *did*: `cpu_user_ms`/`cpu_sys_ms`, `max_rss_kb`, `binary`, `dropped_bytes`, `final_newline`, `cwd_start`, `argv`, `effects` and a re-runnable `replay` line
672
+ runs. `--timestamps` overrides `--brief` in this build. **Do not use `2>&1` in any command
673
+ here**: it points the child's fd 2 at stdout before the wrapper ever sees the bytes, so
674
+ stderr arrives tagged `[out]` and the timeline cannot tell a warning from program output
675
+ (`echo err >&2` alone is fine — that is a *demonstration* of the `err` tag; it is the merge
676
+ that destroys the fact). The two reflexes and their replacements, benchmarked on real
677
+ sessions: silencing noise → `cmd >/dev/null` or `cmd 2>/dev/null` (drop one stream, keep
678
+ the other tagged) instead of `cmd >/dev/null 2>&1`; filtering stderr → run plainly, read
679
+ the `[err]` lines, or `busybox log <R> --stream stderr --match <literal>` instead of
680
+ `cmd 2>&1 | grep …`; a background server's logs — `cmd >srv.log 2>srv.err &`, never
681
+ `>srv.log 2>&1 &`, so a crash read back from the log still reads as what it is:
682
+
683
+ The wrapper blocks a merge found in the command's *tail* (last two lines, ~24 chars each)
684
+ before running it — the blocked call returns the rewrite guidance above. Deep scripting is
685
+ out of its scope by design; declare a deliberate merge with `# pitime-safe` and the result
686
+ will say its tags are not evidence. Results also state their own holes: a discarded
687
+ stream, a backgrounded process, or a fully `command`-escaped call each earn a note saying
688
+ what is unknowable from them:
689
+
690
+ ```bash
691
+ busybox run --timeout 120 -- python -m pytest -q
692
+ busybox run -t --pty-split --max-bytes 48000 -- sh -c 'make -j8; echo done >&2'
693
+ busybox run -q -t --env PYTHONUNBUFFERED=1 -- python3 app.py
694
+ busybox run --brief both --max-bytes 12000 -- pytest -q # one call, both streams reduced
695
+ busybox run --format json -- sh -c 'echo out; echo err >&2'
696
+ busybox log R7 --stream timeline
697
+ busybox log R7 --match FAILED --context 8
698
+ busybox log R7 --lines 200:280 --stream stderr
699
+ busybox log R7 --meta
700
+ busybox log --diff R7:R8
701
+ busybox brief -d -t 5 -- less /tmp/build.log
702
+ ```
703
+
704
+ `waitfor` — one deadline, poll interval backing off 20 ms → 200 ms; TCP means the
705
+ port accepts connections, not that the app is ready:
706
+
707
+ ```bash
708
+ busybox waitfor --tcp 127.0.0.1:8080 --timeout 20
709
+ busybox waitfor --http http://127.0.0.1:8080/health --expect 200 --timeout 20
710
+ busybox waitfor --file /tmp/ready --timeout 5
711
+ ```
712
+
713
+ `doctor` and `--caps` — what this build actually is, without dumping secrets:
714
+
715
+ ```bash
716
+ busybox --caps --format json
717
+ busybox doctor --deps git,make,python3
718
+ ```
719
+
720
+ **Known build bug:** `run --format json` prints an invalid payload when the view is
721
+ truncated (head and tail become two adjacent quoted strings). The metadata is intact
722
+ and the capture is complete — read the fields, then `busybox log RUN` for the view.
723
+ Never re-run the command to get a parseable answer.
724
+
725
+ ## difftastic — structural diffs
726
+
727
+ `difft [OPTIONS] OLD-PATH NEW-PATH` · compares syntax trees; unknown languages fall
728
+ back to line diffs.
729
+
730
+ `--display inline|side-by-side|json` · `--color WHEN` · `--background dark|light` ·
731
+ `-c/--context N` · `--skip-unchanged` · `--check-only` · `--list-languages` ·
732
+ `--byte-limit N`
733
+
734
+ ```bash
735
+ difft old.ts new.ts
736
+ difft --display inline --color never a.go b.go
737
+ difft --check-only a.py b.py
738
+ ```