One of my diet context engineering and workflow extensions. Explore the complete collection: https://www.npmjs.com/~probabilityengineer
Compact oversized Pi tool results with transparent previews and spill files.
pi-diet keeps Pi sessions lean by filtering runaway tool outputs before they bloat model context and session JSONL files. Small results pass through unchanged. Large results are saved losslessly under ~/.pi/agent/pi-diet/spills/ and replaced with a compact preview, tail, omitted-size count, and spill path.
From npm:
pi install npm:pi-dietFrom GitHub:
pi install git:github.com/ProbabilityEngineer/pi-dietFor local development without installing:
pi -e ./index.tsEarly MVP, but validated against a real Pi session for oversized bash output.
- pass through small tool results unchanged
- compact oversized tool results automatically via the Pi
tool_resulthook - spill full original output to disk before replacing model-visible content
- preserve transparent access to the full output via a spill-file path
- when compacting, replace original metadata larger than 4,000 serialized characters with an omission summary and spill-file reference; retain complete metadata in the spill file
- provide specialized previews for bash, read-image, noisy LSP JSON, and generic search-style output
thresholdChars: 64000headChars: 8000tailChars: 8000
The compaction threshold includes content and metadata. The 4,000-character metadata limit applies only when a result is compacted; smaller results still pass through unchanged.
pi-diet reduces oversized results immediately through the tool_result hook,
including oversized metadata on the compaction path. SoL-Pi's ObservationPack
instead reduces repeated replay of large text results in model-facing context
while leaving stored history unchanged.
These mechanisms overlap but are not equivalent. When both are enabled, ObservationPack may archive pi-diet's compacted preview, so recovering the original can require recalling the preview and then reading its spill file. Other SoL-Pi output reducers can add further overlap. Coexistence has not been integration-tested; choose enabled mechanisms deliberately rather than assuming that more reducers are always better.
/diettoggles compaction between enabled and disabled./diet-footertoggles the pi-diet footer entry between visible and hidden.
The footer preference persists in ~/.pi/agent/pi-diet/config.json; the footer status is visible by default.
Ask Pi to run a command with very large output. Instead of storing the whole result in model context, pi-diet will replace it with a compact marker and a spill path like:
[pi-diet: compacted oversized bash result]
Original size: 102955 chars
Full output: ~/.pi/agent/pi-diet/spills/...
Rescue a single session file:
node scripts/rescue-session.mjs ~/.pi/agent/sessions/.../session.jsonl --out /tmp/pi-diet-rescueRescue every session file under a directory:
node scripts/rescue-session.mjs ~/.pi/agent/sessions/some-project --out /tmp/pi-diet-rescuenpm testpi-diet does not silently discard oversized tool results. It writes the full original result to a spill file first, then replaces the model-visible content with a compact preview.