pi package for Codex-style remote compaction on the OpenAI Responses path without changing pi core.
Recommended project-local install:
pi install -l git:https://github.com/san-tian/pi-codex-remote-compactionRecommended global install:
pi install git:https://github.com/san-tian/pi-codex-remote-compactionUpdate later with:
pi updateAfter install, pi loads the package automatically from settings.
- tries remote Codex-style compaction first
- stores remote compact results in compaction
details - rewrites the first post-compaction provider request
- sends a standard item-only
/responses/compactbody (model+input) instead of Pi-specific top-level compaction fields - normalizes legacy provider
compaction_summaryoutput items back into standardcompactionitems before the next/responsescall - if Claude-style session memory is present, uses it as the summary base and keeps only the recent unsummarized tail before calling remote compaction
- otherwise preserves the original remote-compaction behavior with no session-memory dependency
- retries transient
/responses/compactgateway failures (502/503/504) up to 3 times before falling back - warns and falls back to default
picompaction if remote compaction still fails - if
/responses/compactis unavailable, disables remote compaction for the rest of the session after the first warning - writes debug artifacts to
.tmp/codex-remote-compaction/
The package is loaded after installation, but it only takes over compaction when the active model uses the OpenAI Responses path:
- model
apiisopenai-responses - model has a
baseUrl - backend supports
POST /responses/compact
That means it works with:
- OpenAI-compatible backends
- OpenAI relay or proxy services
- OpenAI-compatible middleboxes that expose both
/responsesand/responses/compact
If the backend does not support that path, the package shows a warning, falls back to default pi compaction, and skips remote compaction attempts for the rest of the session.
This package works on its own. Installing pi-session-memory-extension changes its behavior only when a valid session-memory summary is available for the current session.
- without
pi-session-memory-extension: pure Codex/OpenAI remote compaction behavior - with
pi-session-memory-extensioninstalled but no usable summary yet: pure Codex/OpenAI remote compaction behavior - with
pi-session-memory-extensioninstalled and a usable summary present: memory-aware remote compaction
If you do not want to use pi install, you can still install it as a project-local extension:
mkdir -p .pi/extensions
git clone https://github.com/san-tian/pi-codex-remote-compaction.git .pi/extensions/codex-remote-compactionIf a pi agent is reading this README to install the package for the current project, it should prefer the package flow:
pi install -l git:https://github.com/san-tian/pi-codex-remote-compactionThen verify installation:
pi -C "$PWD" --no-session -p 'Reply with exactly: extension smoke ok'Optional backend check inside pi:
/codex-compact-probe
View the latest remote compaction summary or raw response without inserting a chat message:
/codex-compact-show
/codex-compact-show-raw
如果你是 pi agent,并且用户要求你为当前项目安装这个扩展,优先使用 pi package 安装方式:
pi install -l git:https://github.com/san-tian/pi-codex-remote-compaction
pi -C "$PWD" --no-session -p 'Reply with exactly: extension smoke ok'如果 smoke test 返回 extension smoke ok,说明包已经被 pi 正常加载。
如果用户还要求确认后端是否支持远程 compaction,可以在 pi 里再执行:
/codex-compact-probe
如果用户想查看最近一次远程 compaction 的摘要或原始返回,而不把结果写进对话历史,可以执行:
/codex-compact-show
/codex-compact-show-raw
如果后端不支持 /responses/compact,扩展会给出 warning,然后自动回退到默认 pi compaction;这表示远程 compaction 没有生效,但对话仍然可以继续。
pi install -l ...writes the package to the current project's.pi/settings.jsonpi install ...writes the package to~/.pi/agent/settings.jsonpi updateupdates non-pinned package installs- if you want to pin a version later, install from a ref such as
git:https://github.com/san-tian/pi-codex-remote-compaction@v0.1.0
index.ts: extension entrypoint and hook wiringsrc/types.ts: compaction detail and cached-template typessrc/state.ts: session-scoped cachessrc/wrapper.ts: AGENTS or CLAUDE wrapper synthesissrc/codex-input.ts:pisession history to Codex Responses input conversionsrc/provider-request.ts: request-template capture and post-compaction payload overridesrc/remote-client.ts:/responses/compacttransportsrc/debug.ts: debug artifact persistencetools/proxy.py: local request logger plus overflow injectortools/verify_auto_compaction.mjs: SDK harness for forced auto-compaction checkstools/normalize-request.mjs: request normalizer for parity checkstools/compare_requests.mjs: normalized diff for Codex vspirequest capturesfixtures/codex/post-compaction.request.json: sanitized Codex reference request fixturefixtures/pi/overflow-retry.request.json: sanitizedpioverflow retry fixture
Compare the committed Codex fixture against the committed pi overflow fixture:
npm run compareExercise the SDK auto-compaction harness:
node tools/verify_auto_compaction.mjs --pi-root /path/to/pi-coding-agent --provider <provider-id> --model <model-id>Run the local proxy logger or overflow injector:
UPSTREAM=https://api.example.com/openai/v1 python3 tools/proxy.pyThe committed fixtures are intentionally sanitized:
- no real authorization headers
- no local absolute host paths
- no private workspace prompts
- only the normalized request shape needed for parity regression checks
- manual post-compaction request parity is verified
- standalone compact requests now use the standard OpenAI/Codex
model+inputrequest shape - first overflow immediate retry request parity is verified after normalization
- request-shape regressions can be checked against committed fixtures
- transient remote compaction gateway failures (
502/503/504) retry up to 3 times before warning - remote compaction failures warn and then fall back to default
picompaction - endpoint-unavailable failures stop retrying remote compaction for the rest of the session
piwith package loading enabled- a model on the
openai-responsespath - a backend that supports
/responsesand/responses/compact - Node.js for the maintenance scripts
- Python 3 for
tools/proxy.py