Vendored from [`nicobailon/pi-custom-compaction`](https://github.com/nicobailon/pi-custom-compaction)

- Upstream commit: `ac69e833c4dc00b4961c65daa2807017bed86e8b`
- Vendored for: `docyrus agent` / `docyrus coder`
- Local adaptation:
  - prefer `PI_CODING_AGENT_DIR` for global policy/template lookup so scoped Docyrus agent state works
