@bermudi/pi-codex
v0.1.10
Published
Codex-native apply_patch, web search, and remote compaction for pi
Maintainers
Readme
pi-codex
A pi package maintained by bermudi, forked from Manaflow
that gives Codex models OpenAI Codex's native apply_patch and web search tools.
When the selected model uses the openai-codex provider, its model ID contains codex, or it is a deepseek-v4 model (trained on the Codex harness), the extension replaces active edit and write tools with apply_patch. Switching to any other model restores the tools it removed.
Install
Install pi, then install this package directly from GitHub:
npm install -g --ignore-scripts @earendil-works/pi-coding-agent
pi install git:github.com/bermudi/manaflow-pi-codex
piUse /login to authenticate with ChatGPT, then select an openai-codex model
with /model. To pin this release instead of following the default
branch:
pi install git:github.com/bermudi/[email protected]The unscoped
pi-codexpackage on npm is an unrelated project. Install this package from GitHub as shown above.
Pi packages execute code with your user permissions. Review the source before installing it.
Why the Codex dependency?
The model-facing tool does not require a provider workaround. Pi supports OpenAI custom/freeform tools with Lark grammars, and pi's Codex model catalog enables that capability.
Applying a patch correctly is separate. This package pins @openai/codex and invokes its native binary's internal apply_patch entrypoint, so parsing, fuzzy context matching, file moves, errors, and output match the upstream implementation instead of a partial TypeScript rewrite.
Launcher
The package also includes a pi-codex launcher that loads the extension for
one run and defaults pi to the openai-codex provider. Install it from a
checkout:
git clone https://github.com/bermudi/manaflow-pi-codex.git
cd pi-codex
npm install
npm link
pi-codexThe launcher loads this package and defaults pi to the openai-codex provider. Normal pi arguments work:
pi-codex --model gpt-5.6-sol:high
pi-codex --model openai/gpt-5.3-codexTo install only the extension into pi without the launcher:
pi install git:github.com/bermudi/manaflow-pi-codexThe native Codex package is large because it includes the platform binary.
Behavior
- Uses the upstream freeform patch format and Lark grammar.
- Keeps each registered tool's TypeBox schema, exposure, execution mode, capabilities, and output budget in one Codex tool contract. Remote compaction sends the same direct model-visible schema projection as the active Pi tools, while preserving deferred-loading metadata for discovery.
- Supports add, update, move, and delete hunks.
- Executes patches sequentially relative to other tool calls.
- Respects tool selection: if
apply_patchwas excluded initially,editandwriteare not replaced. - Falls back to pi's normal
editandwritetools after switching away from a Codex model. - Enables Codex's standalone live
web_searchtool for theopenai-codexprovider. Rendering adapts: standalone (or with goodies' clean-tui disabled) it renders like pi's native tool rows with the search output visible; with bermudis-pi-goodies' clean-tui enabled it renders as a clean burst row (same-tool calls share one block; output hidden until the row is expanded). - Sends standalone search to the resolved Codex
/alpha/searchendpoint, preserving provider base URL and header overrides. - Uses current Codex remote compaction V2 for the
openai-codexprovider. - Applies Codex's model-facing middle-output truncation policy to package
tools and the
tool_resultboundary, while retaining raw search output and patch details for rendering and inspection. Structured non-text result content remains attached to the truncated model-facing result. - Applies Codex Fast mode (
service_tier: "priority") when enabled for models that advertise the Fast tier, covering both normal turns and remote-compaction turns. Fast mode defaults to off (see/fastbelow). - Renders
apply_patchlike pi's native edit row (colored diffs visible) by default; with bermudis-pi-goodies' clean-tui enabled it renders as a clean burst row — collapsed header shows the touched paths,Ctrl+Oexpands to pi-native colored diffs generated from the actual before/after files. - Collapses the normal compaction notice to one line;
Ctrl+Ostill expands its summary. - Keeps Pi's normal working spinner and adds a once-per-second elapsed-time
label (
Working (12s),Working (1m 5s)) to the working row.
Remote compaction
Current OpenAI Codex enables RemoteCompactionV2 by default. pi-codex mirrors that flow:
- Sends a streaming request to the resolved Codex provider base URL plus
/codex/responses(normallyhttps://chatgpt.com/backend-api/codex/responses), the same route as normal turns. Auth-provided base URL overrides are honored. - Appends
{ "type": "compaction_trigger" }to the Responses input. - Requires exactly one
{ "type": "compaction" }output item. - Persists the opaque replacement history in pi's compaction entry and reinstalls it verbatim in later Codex requests, including after resume.
- Stores the response ID, token usage, tool-catalog fingerprint, retained suffix fingerprint, and checkpoint version with the replacement history. A v2 checkpoint is replayed only when its marker, active tool catalog, and retained suffix still match; legacy v1 entries remain readable.
- Replays
x-codex-turn-stateonly within the active Pi turn, including an immediate overflow retry.
For every model under the openai-codex provider, pi-codex matches Codex's default automatic-compaction boundary at 90% of that model's context window. For example, the live 272,000-token models compact beginning at 244,800 tokens, while the 128,000-token Spark model begins at 115,200. Internally the pi reserve includes one extra token because pi's comparison is > while Codex's is >=. The override is in-memory, applies only while an openai-codex model is selected, preserves an explicit compaction.enabled: false, and does not rewrite settings.json or affect other providers.
The older /codex/responses/compact endpoint remains in Codex for the legacy implementation, but it is not the default in the inspected upstream revision. There is no additional compaction-specific subrouter path: both normal and compaction V2 traffic use the resolved base URL's /backend-api/codex/responses route.
Remote compaction is intentionally limited to the openai-codex provider. Other providers retain pi's normal local summary compaction.
The package targets Pi 0.84 APIs. It does not attempt to reproduce Codex's
subagent tool surface yet. First-class namespace routing, model-owned tool
search dispatch, and provider response continuation remain Pi core concerns.
Deferred contracts therefore stay out of the initial model-visible tool list,
matching Codex's model_visible_specs() projection, while their schemas remain
available to the tool-search lifecycle and checkpoint fingerprint.
Fast mode
Fast mode defaults to off for supported openai-codex models. Use:
/fast # toggle
/fast on
/fast off
/fast statusThe selection is stored in the session, survives /reload and resume, and resets to off for a new session. Unsupported models and non-Codex providers ignore the tier selection.
Development
npm install
npm run check
npm testThe upstream grammar is copied from codex-rs/core/src/tools/handlers/apply_patch.lark in openai/codex. See THIRD_PARTY_NOTICES.md.
