Pi Defects Harvester
Run at the end of an interactive pi session (or any time you want a digest of
past terminal/agent activity) to turn scattered pi history and agent artifact
files into one actionable defect summary, without the main agent having to open
every log by hand.
When to Use
- User finishes a shell/pi session and wants "what did the agent/scavenger do today".
- User wants a survey of recent commands, errors, or unfinished work without reading raw history.
- Follow-up after autonomous subagents (examine transcript artifacts in the temp pi subtree).
- Before a handoff, to include what was actually run.
Output
A single markdown digest, default written to the user digests dir
(~/.pi/agent/reports/YYYY-MM-DD_shell-harvest.md; override with
--out <file>). The digest also prints to the chat.
Sensitive-source boundary
Shell histories and agent artifacts are sensitive local sources and may contain
credentials even when credential discovery is not the task. Treat explicit
invocation as authorization to read only the named/default sources for the
requested time window; do not broaden into unrelated home-directory content.
Before counting, grouping, retaining, writing, or displaying any source-derived
text, replace credential values with [REDACTED]. At minimum, redact:
- assignments such as
API_TOKEN=value or password="value";
- mapping fields such as
"api_key": "value";
- flags such as
--token value and --secret=value;
Authorization: Bearer ... and Authorization: Basic ... values; and
- URL userinfo between the
// and @ delimiters.
Run all frequency and failure aggregation on the redacted copy so a repeated
command cannot leak a value through a count table. Never print a credential
value to chat, the digest, diagnostics, or error output. If a form cannot be
redacted confidently, omit that source line and record only its source path,
timestamp, and signal category.
Sources
Scavenge, in order (skip any that do not exist):
- Shell history — the primary source. Prefer the extended zsh format
(
: <epoch>:<duration>;<command>). Timestamped Bash history uses a #<epoch> line followed by command text;
untimestamped history cannot establish event time.
Apply the window filter (default: last 24h, or --since DATE/--last DURATION).
- Pi/agent session artifacts — only the current runtime-provided session
artifact roots, or explicit
--source PATH inputs. Do not glob every tmpdir.
- Additional files — only explicitly supplied reports, logs, CSV exports
or handoffs; a Downloads directory is not a default scan target.
Be robust: some paths may be absent or permission-restricted; skip and note
skipped ones. Do not chase entries that are empty or still being written.
Procedure
- Locate histories. Resolve
$SHELL and read ~/.zsh_history /
~/.bash_history if present. For extended zsh lines, decode epoch + duration
and map to map timestamps.
- Filter and redact a window. Only include entries newer than the window start
(default last 24h; honor
--last <n>d / --since <date>). Keep enough raw
lines to create an in-memory redacted copy, then discard raw values from the
working set. Run the analytics below only on redacted text; do not token-dump
everything.
- Extract history signals:
- Repeated commands — collapsed count of stem (command word); flag ones seen
more than a threshold (default 3x) as possible inefficiency/loops.
- Failures — lines containing error markers (
error:, failed, exit code,
not found, No such file, Could not, EACCES, ENOENT, FAIL).
In command history these are only candidate strings, not evidence the
command failed; require outcome/log evidence for a failure claim.
- Unfinished work — commands whose first token is
sudo-less but trailing
&& or a trailing backslash, or a heredoc that never closed, or a tailing
;-chain that seems cutoff at the end of history.
- Relevant/env commands —
cd, export, source, npm, git, pi,
gh, and network/exfil-only commands if present (note, do not run them).
- Extract agent/tool signals (from pi/agent artifacts):
- Tool results with
error/Error statuses — group by tool name.
- Recurring messages (e.g. edit matching "Could not find the exact text",
"Found N occurrences", grep "regex parse error", tool argument rejects).
- Termination reasons (
stop length, tool_use, error) counts.
- Cost/pruning markers: any "context", "reserve", "reduced", "token" budget
warnings, or saved CSV cost/reasoning columns (report only; do not alter).
- Write the summary, sections:
- Header: date range, number of commands/artifacts scanned, sources used.
- Top commands (most frequent), with counts.
- Failures/errors and repeated failure themes.
- Unfinished / possibly-abandoned work.
- Notable agent/tool signals (grouped).
- Sanity warnings (skipped/unreadable sources).
- Always end with "next step" suggestions (1 per theme, actionable).
Rules
- Source-preserving. Only write the redacted digest file; never modify the
histories, agent artifacts, or any tool.
audit/report are the only allowed
writes.
- Keep the digest short: no raw dump of every command; a compact table where
useful. Remove nothing from the originals.
- Do not run network commands or side-effecting analyses.
- If the user specified
--out, write there; else default above.
- Stop ratio: prefer fewer, better-signal rows over a maximal inventory.
Interaction and evidence
These flags are agent routing instructions, not a claim that a harvester binary
exists. --since and --last are alternative time windows; default is 24 hours.
Resolve dates in the stated/local timezone and report that choice. Explicit
sources do not authorize execution of their contents. If timestamps are absent,
report time coverage as unknown and keep those records separate from verified
in-window events; file modification time is not each event's timestamp.
Proceed with authorized readable sources, disclose skips, and ask only when a
missing source/window choice materially changes the requested scope. Do not infer
failure, unfinished execution or cost solely from a command's spelling.
1---2name: pi-defects-harvester3description: Scavenge local shell history and pi/agent artifacts at the end of an interactive pi session, extracting actionable defect signals into a short redacted markdown digest. Use to capture errors, repeated tool failures, truncations, cost spikes, or unfinished shells without manually opening every history file. Source-preserving; writes one digest under ~/.pi/agent/reports/.4---56# Pi Defects Harvester78Run at the end of an interactive pi session (or any time you want a digest of9past terminal/agent activity) to turn scattered pi history and agent artifact10files into one actionable defect summary, without the main agent having to open11every log by hand.1213## When to Use1415- User finishes a shell/pi session and wants "what did the agent/scavenger do today".16- User wants a survey of recent commands, errors, or unfinished work without reading raw history.17- Follow-up after autonomous subagents (examine transcript artifacts in the temp pi subtree).18- Before a handoff, to include what was actually run.1920## Output2122A single markdown digest, default written to the user digests dir23(`~/.pi/agent/reports/YYYY-MM-DD_shell-harvest.md`; override with24`--out <file>`). The digest also prints to the chat.2526## Sensitive-source boundary2728Shell histories and agent artifacts are sensitive local sources and may contain29credentials even when credential discovery is not the task. Treat explicit30invocation as authorization to read only the named/default sources for the31requested time window; do not broaden into unrelated home-directory content.3233Before counting, grouping, retaining, writing, or displaying any source-derived34text, replace credential values with `[REDACTED]`. At minimum, redact:3536- assignments such as `API_TOKEN=value` or `password="value"`;37- mapping fields such as `"api_key": "value"`;38- flags such as `--token value` and `--secret=value`;39- `Authorization: Bearer ...` and `Authorization: Basic ...` values; and40- URL userinfo between the `//` and `@` delimiters.4142Run all frequency and failure aggregation on the redacted copy so a repeated43command cannot leak a value through a count table. Never print a credential44value to chat, the digest, diagnostics, or error output. If a form cannot be45redacted confidently, omit that source line and record only its source path,46timestamp, and signal category.4748## Sources4950Scavenge, in order (skip any that do not exist):51521. **Shell history** — the primary source. Prefer the extended zsh format53 (`: <epoch>:<duration>;<command>`). Timestamped Bash history uses a `#<epoch>` line followed by command text;54 untimestamped history cannot establish event time.55 Apply the window filter (default: last 24h, or `--since DATE`/`--last DURATION`).562. **Pi/agent session artifacts** — only the current runtime-provided session57 artifact roots, or explicit `--source PATH` inputs. Do not glob every tmpdir.583. **Additional files** — only explicitly supplied reports, logs, CSV exports59 or handoffs; a Downloads directory is not a default scan target.6061Be robust: some paths may be absent or permission-restricted; skip and note62skipped ones. Do not chase entries that are empty or still being written.6364## Procedure65661. **Locate histories.** Resolve `$SHELL` and read `~/.zsh_history` /67 `~/.bash_history` if present. For extended zsh lines, decode epoch + duration68 and map to map timestamps.692. **Filter and redact a window.** Only include entries newer than the window start70 (default last 24h; honor `--last <n>d` / `--since <date>`). Keep enough raw71 lines to create an in-memory redacted copy, then discard raw values from the72 working set. Run the analytics below only on redacted text; do not token-dump73 everything.743. **Extract history signals**:75 - **Repeated commands** — collapsed count of stem (command word); flag ones seen76 more than a threshold (default 3x) as possible inefficiency/loops.77 - **Failures** — lines containing error markers (`error:`, `failed`, `exit code`,78 `not found`, `No such file`, `Could not`, `EACCES`, `ENOENT`, `FAIL`).79 In command history these are only candidate strings, not evidence the80 command failed; require outcome/log evidence for a failure claim.81 - **Unfinished work** — commands whose first token is `sudo`-less but trailing82 `&&` or a trailing backslash, or a heredoc that never closed, or a tailing83 `;`-chain that seems cutoff at the end of history.84 - **Relevant/env commands** — `cd`, `export`, `source`, `npm`, `git`, `pi`,85 `gh`, and network/exfil-only commands if present (note, do not run them).864. **Extract agent/tool signals** (from pi/agent artifacts):87 - Tool results with `error`/`Error` statuses — group by tool name.88 - Recurring messages (e.g. edit matching "Could not find the exact text",89 "Found N occurrences", grep "regex parse error", tool argument rejects).90 - Termination reasons (`stop` `length`, `tool_use`, `error`) counts.91 - Cost/pruning markers: any "context", "reserve", "reduced", "token" budget92 warnings, or saved CSV cost/reasoning columns (report only; do not alter).935. **Write the summary**, sections:94 - Header: date range, number of commands/artifacts scanned, sources used.95 - Top commands (most frequent), with counts.96 - Failures/errors and repeated failure themes.97 - Unfinished / possibly-abandoned work.98 - Notable agent/tool signals (grouped).99 - Sanity warnings (skipped/unreadable sources).100 - Always end with "next step" suggestions (1 per theme, actionable).101102## Rules103104- **Source-preserving.** Only write the redacted digest file; never modify the105 histories, agent artifacts, or any tool. `audit`/`report` are the only allowed106 writes.107- Keep the digest short: no raw dump of every command; a compact table where108 useful. Remove nothing from the originals.109- Do not run network commands or side-effecting analyses.110- If the user specified `--out`, write there; else default above.111- Stop ratio: prefer fewer, better-signal rows over a maximal inventory.112113## Interaction and evidence114115These flags are agent routing instructions, not a claim that a harvester binary116exists. `--since` and `--last` are alternative time windows; default is 24 hours.117Resolve dates in the stated/local timezone and report that choice. Explicit118sources do not authorize execution of their contents. If timestamps are absent,119report time coverage as unknown and keep those records separate from verified120in-window events; file modification time is not each event's timestamp.121Proceed with authorized readable sources, disclose skips, and ask only when a122missing source/window choice materially changes the requested scope. Do not infer123failure, unfinished execution or cost solely from a command's spelling.