@jordyvd/pi-openai-compaction
OpenAI native standalone compaction replay for Pi.
Package details
Install @jordyvd/pi-openai-compaction from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@jordyvd/pi-openai-compaction- Package
@jordyvd/pi-openai-compaction- Version
0.1.0- Published
- Mar 21, 2026
- Downloads
- 32/mo · 9/wk
- Author
- jordymvd
- License
- MIT
- Types
- extension
- Size
- 88.5 KB
- Dependencies
- 0 dependencies · 2 peers
Pi manifest JSON
{
"extensions": [
"./index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
@jordyvd/pi-openai-compaction
A distributable Pi extension package that replays OpenAI native standalone compaction windows without patching Pi core.
This package preserves the raw compacted window returned by OpenAI's compact endpoint, stores it in Pi compaction entry details, and rewrites later supported OpenAI Responses requests to:
- fresh current prompt envelope
- stored opaque compacted window
- live post-compaction tail
Supported scope
This package is intentionally narrow.
- Providers:
openai,openai-codex - APIs:
openai-responses,openai-codex-responses - Failure mode: fail open back to normal Pi behavior
- Persistence model: store the raw compacted window in
CompactionEntry.details
How it works
The extension uses two hooks:
session_before_compact- serialize the current Pi session into an OpenAI Responses-compatible compact request
- call the compact endpoint
- persist the returned compacted window in the compaction entry details
before_provider_request- intercept the next supported Responses request
- replace Pi's summary-oriented replay with native replay
Install
From a checkout of this repo:
git clone https://github.com/jordyvandomselaar/pi-codex-compaction.git
cd pi-codex-compaction
pi install .
Try without installing from the repo root:
pi -e .
After installation, run:
/reload
Configuration
Settings resolve in this order, with later layers overriding earlier ones:
- package-local
settings.json - global
~/.pi/agent/settings.jsonunderopenaiNativeCompaction - project
<cwd>/.pi/settings.jsonunderopenaiNativeCompaction - environment variables with the
PI_OPENAI_NATIVE_COMPACTION_prefix
Default package settings:
{
"enabled": true,
"debug": false,
"logProviderPayloads": false,
"logCompactResponses": false,
"redactSensitiveData": true,
"artifactRoot": "~/.pi/agent/artifacts/openai-native-compaction",
"supportedProviders": ["openai", "openai-codex"],
"supportedApis": ["openai-responses", "openai-codex-responses"],
"notifyOnLoad": false
}
Useful global override example:
{
"openaiNativeCompaction": {
"enabled": true,
"debug": true,
"logProviderPayloads": true,
"logCompactResponses": true,
"redactSensitiveData": true
}
}
Available environment overrides:
PI_OPENAI_NATIVE_COMPACTION_ENABLEDPI_OPENAI_NATIVE_COMPACTION_DEBUGPI_OPENAI_NATIVE_COMPACTION_LOG_PROVIDER_PAYLOADSPI_OPENAI_NATIVE_COMPACTION_LOG_COMPACT_RESPONSESPI_OPENAI_NATIVE_COMPACTION_REDACT_SENSITIVE_DATAPI_OPENAI_NATIVE_COMPACTION_ARTIFACT_ROOTPI_OPENAI_NATIVE_COMPACTION_SUPPORTED_PROVIDERSPI_OPENAI_NATIVE_COMPACTION_SUPPORTED_APISPI_OPENAI_NATIVE_COMPACTION_NOTIFY_ON_LOAD
Debug artifacts
Artifacts are written per session under:
~/.pi/agent/artifacts/openai-native-compaction/sessions/<session-id>/
Subdirectories:
provider-requests/compact-responses/compaction-events/lifecycle/
Recommended troubleshooting flow:
- enable
debug: true - enable
logProviderPayloads: true - keep
redactSensitiveData: true /reload- run
/compactand then send a follow-up message - inspect the newest artifact in the session directory
Package structure
package-root/
├── index.ts # package entrypoint declared in package.json
├── settings.json # package-local defaults
├── src/
│ ├── extension-runtime.ts # hook registration and top-level wiring
│ ├── settings.ts # layered settings loader + env overrides
│ ├── debug.ts # artifact writing + redaction helpers
│ ├── runtime.ts # provider/api/model/baseUrl/apiKey resolution
│ ├── supported-environment.ts
│ ├── types.ts # settings + persisted native-compaction types
│ ├── details-store.ts # latest-valid native compaction lookup helpers
│ ├── serializer.ts # compaction input serialization helpers
│ ├── compact-client.ts # compact endpoint client
│ └── payload-rewrite.ts # native replay rewrite logic
├── src/unit.test.ts
├── src/validation.test.ts
└── test/pi-smoke.test.ts
Tests
git clone https://github.com/jordyvandomselaar/pi-codex-compaction.git
cd pi-codex-compaction
bun test
bun test --coverage --coverage-reporter=text --coverage-reporter=lcov
bun test ./test/pi-smoke.test.ts