{"_id":"@capyup/pi-auto-compact","_rev":"5-58cd2bc800863699b557e582abc89313","name":"@capyup/pi-auto-compact","dist-tags":{"latest":"0.2.4"},"versions":{"0.2.0":{"name":"@capyup/pi-auto-compact","version":"0.2.0","keywords":["pi-package"],"author":{"name":"capyup"},"license":"MIT","_id":"@capyup/pi-auto-compact@0.2.0","maintainers":[{"name":"capyup","email":"lucas@knowecon.com"}],"homepage":"https://github.com/lulucatdev/pi-auto-compact#readme","bugs":{"url":"https://github.com/lulucatdev/pi-auto-compact/issues"},"pi":{"extensions":["./extensions"]},"dist":{"shasum":"d350c125cbd27325c206d30499c4a407603641ec","tarball":"https://registry.npmjs.org/@capyup/pi-auto-compact/-/pi-auto-compact-0.2.0.tgz","fileCount":3,"integrity":"sha512-xEZM7bgsAFRa267MF6DokyFMNqMQVLDmFCy7lBV8yS7RW+nCd7VHb30jVq7UwOifiEcdB43Bg0WM63AHjDu5iA==","signatures":[{"sig":"MEUCIQDKhe6N0lI81zqTPZ8NY7hklt1WmUPJWnWQNjTgC8+diwIgI6IlL/UQsfvxh6k9nFaBfFop0nf+HEN5bLcknaqD4Pk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24014},"gitHead":"be6843d2f3b29b0458414266999056414c2e3d8b","_npmUser":{"name":"capyup","email":"lucas@knowecon.com"},"repository":{"url":"git+https://github.com/lulucatdev/pi-auto-compact.git","type":"git"},"_npmVersion":"11.12.1","description":"Pre-turn auto-compaction for pi","directories":{},"_nodeVersion":"25.9.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"@earendil-works/pi-coding-agent":"*"},"_npmOperationalInternal":{"tmp":"tmp/pi-auto-compact_0.2.0_1778293822766_0.42283470461355344","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@capyup/pi-auto-compact","version":"0.2.1","keywords":["pi-package","pi","pi-extension","auto-compact","compaction","context-window"],"author":{"name":"capyup"},"license":"MIT","_id":"@capyup/pi-auto-compact@0.2.1","maintainers":[{"name":"capyup","email":"lucas@knowecon.com"}],"homepage":"https://github.com/lulucatdev/pi-auto-compact#readme","bugs":{"url":"https://github.com/lulucatdev/pi-auto-compact/issues"},"pi":{"extensions":["./extensions"]},"dist":{"shasum":"74c9566ffa0ed1471d173a6fb7d35c5eaa49d93b","tarball":"https://registry.npmjs.org/@capyup/pi-auto-compact/-/pi-auto-compact-0.2.1.tgz","fileCount":3,"integrity":"sha512-OJC1ZMrX1B1z92Hnh92oZAm0meWB6ob0BfBzP107decgg2cMwI4ph6KNn/uZQYfS0FiQDz4yUbzCpzcC77umag==","signatures":[{"sig":"MEYCIQCeJLJ01B8WtSBBfD/K9NIPRbPhcpAtVShNdnFTEOtIIgIhAKNhKVeZDDYTrhSu7/GWxcZOAyZHRjjORN6fO4jNgl87","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24124},"gitHead":"be6843d2f3b29b0458414266999056414c2e3d8b","_npmUser":{"name":"capyup","email":"lucas@knowecon.com"},"repository":{"url":"git+https://github.com/lulucatdev/pi-auto-compact.git","type":"git"},"_npmVersion":"11.12.1","description":"Pre-turn auto-compaction for pi","directories":{},"_nodeVersion":"25.9.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"@earendil-works/pi-coding-agent":"*"},"_npmOperationalInternal":{"tmp":"tmp/pi-auto-compact_0.2.1_1778294230487_0.49193178349573685","host":"s3://npm-registry-packages-npm-production"}},"0.2.2":{"name":"@capyup/pi-auto-compact","version":"0.2.2","keywords":["pi-package","pi","pi-extension","auto-compact","compaction","context-window"],"author":{"name":"capyup"},"license":"MIT","_id":"@capyup/pi-auto-compact@0.2.2","maintainers":[{"name":"capyup","email":"lucas@knowecon.com"}],"homepage":"https://github.com/capyup/pi-auto-compact#readme","bugs":{"url":"https://github.com/capyup/pi-auto-compact/issues"},"pi":{"extensions":["./extensions"]},"dist":{"shasum":"cafd896c0a5548f7491fefde5a4e898aee74e55d","tarball":"https://registry.npmjs.org/@capyup/pi-auto-compact/-/pi-auto-compact-0.2.2.tgz","fileCount":3,"integrity":"sha512-4VkosCE9ZQlMEqCCymnfO5wo7jdt2o03n77EP8dZmav/r3QEgYQ2SSQ17khmHKuyLK8YTqASyIIfydgsvkMqsw==","signatures":[{"sig":"MEQCIE9z1ZSjJDoxuFQzAV4wNmPDmdlUXs8VZdlXBBHvMK4RAiAkOVhXqcGS9au2mjmlbivJjbPB4WDsmkG/oILU3i8TZA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22127},"gitHead":"39ae0bb2bcf3fd871acb4f91dde2bd1481a7b007","_npmUser":{"name":"capyup","email":"lucas@knowecon.com"},"repository":{"url":"git+https://github.com/capyup/pi-auto-compact.git","type":"git"},"_npmVersion":"11.12.1","description":"Pre-turn auto-compaction for pi","directories":{},"_nodeVersion":"25.9.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"@earendil-works/pi-coding-agent":"*"},"_npmOperationalInternal":{"tmp":"tmp/pi-auto-compact_0.2.2_1778295480000_0.793732174206472","host":"s3://npm-registry-packages-npm-production"}},"0.2.3":{"name":"@capyup/pi-auto-compact","version":"0.2.3","keywords":["pi-package","pi","pi-extension","auto-compact","compaction","context-window"],"author":{"name":"capyup"},"license":"MIT","_id":"@capyup/pi-auto-compact@0.2.3","maintainers":[{"name":"capyup","email":"lucas@knowecon.com"}],"homepage":"https://github.com/capyup/pi-auto-compact#readme","bugs":{"url":"https://github.com/capyup/pi-auto-compact/issues"},"pi":{"extensions":["./extensions"]},"dist":{"shasum":"72eb97bc0b1f56dcb9a095196f0450548b56bbb3","tarball":"https://registry.npmjs.org/@capyup/pi-auto-compact/-/pi-auto-compact-0.2.3.tgz","fileCount":3,"integrity":"sha512-19pIZAuetFf47IXlaT6cSZYLse0XreP+BFr9nuUALco3Yjw7Hqz2/nDIfD6c4ZLwbdnYpi+d6/BIYRQjwuHlsg==","signatures":[{"sig":"MEYCIQDUER7bH87Svk9RujAJjHQ5cfpwZl6n32r+lhZUhGKBcAIhAKnsbv6wZ5OZV2P7Zyod70QOJWEXRBxT7UDpe1VUo1up","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24561},"gitHead":"39c0cf065bcab7eb9233f405cbdee9ec721b7a29","_npmUser":{"name":"capyup","email":"lucas@knowecon.com"},"repository":{"url":"git+https://github.com/capyup/pi-auto-compact.git","type":"git"},"_npmVersion":"11.12.1","description":"Pre-turn auto-compaction for pi","directories":{},"_nodeVersion":"25.9.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"peerDependencies":{"@earendil-works/pi-coding-agent":"*"},"_npmOperationalInternal":{"tmp":"tmp/pi-auto-compact_0.2.3_1778313791757_0.5140206644359737","host":"s3://npm-registry-packages-npm-production"}},"0.2.4":{"name":"@capyup/pi-auto-compact","version":"0.2.4","description":"Pre-turn auto-compaction for pi","keywords":["pi-package","pi","pi-extension","auto-compact","compaction","context-window"],"repository":{"type":"git","url":"git+https://github.com/capyup/pi-auto-compact.git"},"author":{"name":"capyup"},"license":"MIT","publishConfig":{"access":"public"},"pi":{"extensions":["./extensions"]},"peerDependencies":{"@earendil-works/pi-coding-agent":"*"},"gitHead":"2d8bde795191f1913618b315b104d8563821fd39","_id":"@capyup/pi-auto-compact@0.2.4","bugs":{"url":"https://github.com/capyup/pi-auto-compact/issues"},"homepage":"https://github.com/capyup/pi-auto-compact#readme","_nodeVersion":"25.9.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-jrzHiPETC59gc4TlNvohlKYgzJXwvIaWJbR7Ul5OdQaDWGLH7/lNU7Ci5Q7p/T2179XmUgcxfbvZfru3XKtidA==","shasum":"8948dcc7047306c871965e757e43e63037631c92","tarball":"https://registry.npmjs.org/@capyup/pi-auto-compact/-/pi-auto-compact-0.2.4.tgz","fileCount":3,"unpackedSize":25323,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDxDPmBv4MfpZ3op3BNOypARQp4vYv9JYkda474xtRU4QIhALt4HBCrA0Kn4ifrvZSAQYH1lrXoEJhJ4ULRLfGxvqCW"}]},"_npmUser":{"name":"capyup","email":"lucas@knowecon.com"},"directories":{},"maintainers":[{"name":"capyup","email":"lucas@knowecon.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pi-auto-compact_0.2.4_1778323553204_0.4636662284986186"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-09T02:30:22.698Z","modified":"2026-05-09T10:45:53.448Z","0.2.0":"2026-05-09T02:30:22.927Z","0.2.1":"2026-05-09T02:37:10.613Z","0.2.2":"2026-05-09T02:58:00.156Z","0.2.3":"2026-05-09T08:03:11.900Z","0.2.4":"2026-05-09T10:45:53.335Z"},"bugs":{"url":"https://github.com/capyup/pi-auto-compact/issues"},"author":{"name":"capyup"},"license":"MIT","homepage":"https://github.com/capyup/pi-auto-compact#readme","keywords":["pi-package","pi","pi-extension","auto-compact","compaction","context-window"],"repository":{"type":"git","url":"git+https://github.com/capyup/pi-auto-compact.git"},"description":"Pre-turn auto-compaction for pi","maintainers":[{"name":"capyup","email":"lucas@knowecon.com"}],"readme":"# pi-auto-compact\n\nPre-turn auto-compaction extension for pi. Proactively manages context window usage to prevent overflow errors.\n\n## The Problem\n\nPi's default auto-compaction only checks **after `agent_end`**. This means context can overflow during long multi-tool turns before compaction triggers.\n\n## Strategy\n\nThis extension checks tokens at **three points**:\n\n1. **Pre-turn:** Before sending any request to the LLM (`turn_start`)\n2. **Mid-turn:** After tool execution, before follow-up LLM calls (`turn_end`)\n3. **Emergency:** Synchronous truncation in the `context` event as a last resort\n\nIt also handles the **session resume** case: when an existing session is\nreopened above the threshold, compaction kicks off as soon as the session\nstarts.\n\n### Continuing After Auto-Compaction\n\n`ctx.compact()` aborts the running agent internally, so without a nudge the\nsession would sit idle once the summary is written. After every\n**auto-triggered** compaction this extension sends a short English follow-up\nuser message to make pi resume the in-flight task. The exact wording depends\non which check fired (pre-turn, mid-turn, emergency, or session-resume).\n\nThe follow-up is suppressed in two cases:\n\n- The user ran `/compact` manually — the callback path used here only fires\n  for compactions this extension started, so manual compaction is never\n  touched.\n- The agent is no longer idle when the summary finishes, e.g. the user\n  already typed something or another extension started a turn while\n  summarising. Their input acts as the kickoff and we stay quiet.\n\n### Compaction Strategies\n\n| Strategy | Description |\n|----------|-------------|\n| `keep-recent` | Keep only the most recent messages (default) |\n| `keep-bookends` | Keep oldest + newest messages, compact the middle |\n| `summarize-all` | Remove everything except the last user message |\n\n## Configuration\n\nUse `/auto-compact` to open the interactive settings menu:\n\n```\n/auto-compact              # Open settings menu\n/auto-compact status       # Show current status\n/auto-compact reset        # Reset to defaults\n```\n\n### Settings\n\n| Setting | Default | Options |\n|---------|---------|---------|\n| Auto-compact threshold | **90%** | 80%, 85%, 90%, 95% |\n| Keep recent budget | **15%** | 5%, 10%, 15%, 20% |\n| Strategy | **keep-recent** | keep-recent, keep-bookends, summarize-all |\n| Debug logging | **off** | on/off |\n\n### Example\n\nFor a 200K context window model:\n- Compact at **180K** tokens (90%)\n- Keep **30K** recent tokens (15%)\n\n## Install\n\nAs a pi package:\n\n```bash\npi install npm:@capyup/pi-auto-compact\n```\n\nOr via git:\n\n```bash\npi install git:github.com/capyup/pi-auto-compact\n```\n\nOr run directly:\n\n```bash\npi -e ./extensions/auto-compact.ts\n```\n\n## How It Differs from Pi's Default\n\n| Aspect | Pi Default | This Extension |\n|--------|-----------|----------------|\n| Check timing | After `agent_end` only | Before requests + after tools |\n| Overflow protection | None | Emergency truncation |\n| Mid-turn handling | None | Checks after each tool batch |\n| Auto-continue | No | Yes — sends an English follow-up nudge after auto-compaction |\n\n## License\n\nMIT\n","readmeFilename":"README.md"}