pi-openai-codex-compat 0.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/LICENSE +20 -0
- package/LICENSES/Apache-2.0.txt +201 -0
- package/LICENSES/pi-ai-MIT.txt +21 -0
- package/README.md +331 -0
- package/THIRD_PARTY_NOTICES.md +21 -0
- package/extensions/openai-codex-compat/apply-patch-diff-render.ts +436 -0
- package/extensions/openai-codex-compat/apply-patch-engine.ts +1004 -0
- package/extensions/openai-codex-compat/apply-patch-render.ts +133 -0
- package/extensions/openai-codex-compat/apply-patch.ts +142 -0
- package/extensions/openai-codex-compat/codex-protocol.ts +598 -0
- package/extensions/openai-codex-compat/codex-provider.ts +740 -0
- package/extensions/openai-codex-compat/codex-stream.ts +444 -0
- package/extensions/openai-codex-compat/codex-tool-surface.ts +186 -0
- package/extensions/openai-codex-compat/codex-transport.ts +855 -0
- package/extensions/openai-codex-compat/compaction-checkpoint.ts +304 -0
- package/extensions/openai-codex-compat/config.ts +268 -0
- package/extensions/openai-codex-compat/footer.ts +99 -0
- package/extensions/openai-codex-compat/image-generation-render.ts +166 -0
- package/extensions/openai-codex-compat/image-generation.ts +355 -0
- package/extensions/openai-codex-compat/index.ts +65 -0
- package/extensions/openai-codex-compat/model-policy.ts +67 -0
- package/extensions/openai-codex-compat/namespaced-tools.ts +43 -0
- package/extensions/openai-codex-compat/native-history.ts +78 -0
- package/extensions/openai-codex-compat/remote-compaction.ts +198 -0
- package/extensions/openai-codex-compat/request-options.ts +121 -0
- package/extensions/openai-codex-compat/responses-replay.ts +33 -0
- package/extensions/openai-codex-compat/settings-pane.ts +298 -0
- package/extensions/openai-codex-compat/tool-runtime.ts +32 -0
- package/extensions/openai-codex-compat/tools.ts +70 -0
- package/extensions/openai-codex-compat/vendor/pi-ai/README.md +15 -0
- package/extensions/openai-codex-compat/vendor/pi-ai/openai-responses-serialization.ts +660 -0
- package/extensions/openai-codex-compat/web-run-description.txt +105 -0
- package/extensions/openai-codex-compat/web-run-output.ts +172 -0
- package/extensions/openai-codex-compat/web-run-render.ts +681 -0
- package/extensions/openai-codex-compat/web-run-schema.ts +301 -0
- package/extensions/openai-codex-compat/web-run.ts +164 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
# pi-openai-codex-compat
|
|
2
|
+
|
|
3
|
+
OpenAI Codex compatibility for [Pi](https://github.com/earendil-works/pi-mono), combining priority fast mode, native Codex compaction, and Codex-optimized model features in one Pi package.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Request-level fast mode**: keeps the canonical `openai-codex` provider id and models selected while adding `service_tier: "priority"` at the request boundary.
|
|
8
|
+
- **Native compaction**: uses Codex `remote_compaction_v2` for `/compact`, Pi threshold compaction, context-overflow recovery, and an optional percentage threshold.
|
|
9
|
+
- **Codex `apply_patch`**: provides an optional patch tool with the Codex grammar, parser, fuzzy matcher, overwrite semantics, filesystem behavior, model-facing result format, structured history, and diff-oriented TUI rendering. Pi sends it as an OpenAI custom grammar tool when the model supports that protocol and as a normal function tool otherwise.
|
|
10
|
+
- **Standalone image generation**: exposes Pi's dotted `image_gen.imagegen` tool as a native Responses namespace and executes generation or edits through the Codex Images endpoints.
|
|
11
|
+
- **Standalone web search**: exposes Pi's dotted `web.run` tool as a native Responses namespace and executes search and browsing through Codex `alpha/search`.
|
|
12
|
+
- **Dedicated Codex tool UI**: renders `apply_patch`, `image_gen.imagegen`, and `web.run` on a shared configurable surface with compact summaries and `Ctrl+O` expansion.
|
|
13
|
+
- **Hosted web-search fallback**: injects native `web_search` only when `web.run` is inactive, with cached, indexed, or live modes.
|
|
14
|
+
- **Native request controls**: configures Responses API text verbosity, reasoning summaries, and GPT-5.6 standard/pro reasoning mode.
|
|
15
|
+
- **Session-local settings pane**: `/codex-settings` changes every compatibility setting for the current session; `Ctrl+S` explicitly persists the current values.
|
|
16
|
+
- **Compact footer indicators**: non-default Codex request modes are appended to the model side of Pi's normal second footer line.
|
|
17
|
+
|
|
18
|
+
Pi provides the Codex OAuth flow and model catalog. At session start, this package overrides the built-in `openai-codex` runtime under the same provider id so ordinary responses and remote compaction share one transport, parser, native-history store, and sticky WebSocket session.
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
- Node.js 22.19 or newer
|
|
23
|
+
- Pi `>=0.83.0 <0.84.0`
|
|
24
|
+
- An OpenAI Codex login in Pi
|
|
25
|
+
|
|
26
|
+
Authenticate through Pi if needed:
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
/login openai-codex
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Compatibility baseline and differences
|
|
33
|
+
|
|
34
|
+
The compatibility baseline is official Codex CLI `0.146.0`, released July 29, 2026. Upstream `main` at commit `bb5054fe47abe73ecbbd454751066a28c89f4bb9` was also inspected on August 3, 2026. This section is the package's explicit compatibility contract: it distinguishes close protocol adaptations from deliberate Pi behavior, configurable defaults, known gaps, and unsupported Codex runtimes.
|
|
35
|
+
|
|
36
|
+
### Configurable defaults that differ from Codex
|
|
37
|
+
|
|
38
|
+
| Area | This package by default | Official Codex | Configuration |
|
|
39
|
+
| --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
40
|
+
| Generated-image detail sent back to the model | Sends image tool-result content with `input_image.detail: "auto"`. On GPT-5.6, `auto` uses original-size image accounting. | Uses `high`. | `imageDetail`: `auto`, `low`, `high`, or `original`. |
|
|
41
|
+
| Image-generation tool | Enabled whenever an `openai-codex` model is selected. Backend capability and account failures surface when the tool executes. | Stable and enabled by default, but additionally gated by plan, model, provider, authentication, image-generation, and namespace capabilities. | `imageGeneration`: boolean. |
|
|
42
|
+
| Standalone `web.run` | Enabled and preferred over hosted `web_search`, using the complete reserved command schema and tool description. | The standalone feature is under development and disabled by default outside environments such as Responses Lite. | `webRun`: boolean. |
|
|
43
|
+
| Hosted web search | Omitted while `web.run` is active; otherwise injected in cached mode. | Normally uses hosted cached search because standalone `web.run` is disabled by default. | `webRun` and `webSearch`: `disabled`, `cached`, `indexed`, or `live`. |
|
|
44
|
+
| Coding mutation tools | Enables `apply_patch` and suppresses Pi's active `edit` and `write` tools. | Chooses its tool surface from model metadata and runtime capabilities; there are no Pi `edit` or `write` tools to suppress. | `applyPatch`: boolean. |
|
|
45
|
+
| Codex tool background | Uses a subtle theme-derived surface for extension-owned Codex tools. | Uses Codex's own TUI activity cells rather than Pi tool rows. | `toolBackground`: `subtle`, `status`, or `none`. |
|
|
46
|
+
| Auto-compaction trigger | Relies on Pi's reserve-token threshold unless a percentage is configured. | Tracks Codex's model/token-budget state before and between sampling steps. | `autoCompactAtPercent`: percentage or unset. Pi's own compaction settings remain separate. |
|
|
47
|
+
| Fast mode | Uses the normal tier. | Uses the configured Codex service tier. | `fastMode`: boolean; `true` requests the priority tier. |
|
|
48
|
+
| Text and reasoning request controls | Explicitly sends low text verbosity, automatic reasoning summaries, and standard GPT-5.6 reasoning mode. | Resolves these controls through Codex configuration, model metadata, and turn state. | `textVerbosity`, `reasoningSummary`, and `reasoningMode`. |
|
|
49
|
+
|
|
50
|
+
`web.run` is a reserved GPT-5.6 tool name. Its declaration therefore reproduces the complete current Codex post-normalization `SearchCommands` schema and official tool description instead of using Pi's normal compact tool schema. This intentionally omits generated annotations such as `format` and `minimum` that Codex removes before sending the declaration to Responses.
|
|
51
|
+
|
|
52
|
+
### Non-configurable implementation differences
|
|
53
|
+
|
|
54
|
+
| Area | Difference |
|
|
55
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
56
|
+
| Session storage | Pi remains the canonical session owner. Opaque Codex compaction checkpoints are stored in Pi `compaction` entries, and otherwise lossy Responses output is stored in sparse custom native-response entries. Official Codex owns a rollout/thread store directly. |
|
|
57
|
+
| Branching | Checkpoints and native response overrides follow Pi's active session branch. Official Codex uses its own thread, turn, rollback, fork, and context-window lineage. |
|
|
58
|
+
| Model switching | This package rejects model switches while the active Pi branch contains a native Codex checkpoint because the checkpoint is model-specific. |
|
|
59
|
+
| System instructions | Pi rebuilds the current system prompt and sends it through Responses `instructions`; normal Pi history does not store it as replayed system/developer input. `/reload` therefore updates the next request without rewriting old checkpoints. |
|
|
60
|
+
| Turn metadata | Requests do not yet send Codex's complete thread, turn, context-window, request-kind, workspace, and per-turn routing metadata. Sticky WebSocket continuation is implemented locally from response IDs and replayable items. |
|
|
61
|
+
| Mid-turn compaction | Provider-boundary percentage compaction installs a checkpoint and continues the intercepted request. Pi threshold compaction runs after the agent response and does not automatically continue unless Pi has queued messages. Official Codex compacts inline and continues when a completed sampling step says more model/tool work is required. |
|
|
62
|
+
| Incomplete responses | A Responses `status: "incomplete"` currently becomes Pi `stopReason: "length"`. Official Codex treats `response.incomplete` as a stream error. This can produce a Pi threshold compaction followed by an idle agent instead of an inline continuation or explicit error. |
|
|
63
|
+
| Compaction lifecycle events | Percentage compaction writes through Pi's mutable session manager but cannot emit Pi's internal `session_compact` event through the public extension API. Manual, threshold, and overflow compactions initiated by Pi do emit the normal lifecycle. |
|
|
64
|
+
| Header hooks | An internal percentage-compaction request reuses the already transformed provider headers. It cannot independently rerun Pi's `before_provider_headers` hook. |
|
|
65
|
+
| Native retained context | The v2 retained-message selection and truncation match Codex. In normal Pi operation, system instructions are carried separately through `instructions`, so retained API history usually contains user messages rather than Codex's complete initial-context lifecycle. |
|
|
66
|
+
| Tool namespaces | Pi registers dotted names such as `web.run` as exact flat identifiers. The provider converts only the fixed extension-owned allowlist into real Responses namespace/member identities and rejects unknown or ambiguously flat namespaced calls. |
|
|
67
|
+
| Capability gating | Tool activation is based on the selected `openai-codex` provider plus package settings. It does not reproduce every official model-metadata, plan, feature-stage, executor, mode, or account gate. |
|
|
68
|
+
| Sandbox and approvals | Pi extensions run with full process permissions. `apply_patch`, local image reads, generated-image writes, and sibling Codex endpoints do not use Codex's sandbox, permission-profile, or approval lifecycle. |
|
|
69
|
+
| Image artifact hint | When image saving succeeds, this package always returns the path hint, says “the generated image,” and has no 1,024-byte cutoff. Official Codex says “a generated image” and omits the hint when it exceeds 1,024 UTF-8 bytes. |
|
|
70
|
+
| Image artifacts | Generated files use Pi's agent directory and the Pi session/tool-call IDs. Official Codex uses its own artifact/output-directory lifecycle. |
|
|
71
|
+
| Web references | `web.run` structured results are retained branch-locally in Pi tool-result details rather than Codex extension events, and hosted native items are preserved for provider replay. Reference IDs are resolved remotely by `alpha/search`, as in Codex. Hosted citation annotations remain a separate unimplemented path. |
|
|
72
|
+
| UI | Pi renders its own conversation, footer, settings pane, branches, and compaction lifecycle. Extension-owned Codex tools have dedicated Pi renderers, but do not reproduce Codex app-server `WebSearchItem` or image-generation lifecycle notifications. |
|
|
73
|
+
|
|
74
|
+
### Tool and runtime coverage
|
|
75
|
+
|
|
76
|
+
The package implements the Codex-specific pieces that fit a provider compatibility extension:
|
|
77
|
+
|
|
78
|
+
- native Responses transport and history;
|
|
79
|
+
- remote compaction v2;
|
|
80
|
+
- `apply_patch`;
|
|
81
|
+
- hosted `web_search`;
|
|
82
|
+
- `web.run`;
|
|
83
|
+
- `image_gen.imagegen`;
|
|
84
|
+
- namespaced tool serialization;
|
|
85
|
+
- text verbosity, reasoning summaries/mode, and priority service tier.
|
|
86
|
+
|
|
87
|
+
The following official Codex facilities are not exact equivalents in this package:
|
|
88
|
+
|
|
89
|
+
| Official Codex facility | Pi/package behavior |
|
|
90
|
+
| ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
91
|
+
| `exec_command` and `write_stdin` persistent PTY sessions | Pi `bash` is a one-shot command tool; no persistent PTY/session protocol is implemented. |
|
|
92
|
+
| Legacy `shell_command` | Pi uses `bash`; the Codex schema and execution/approval envelope are not reproduced. |
|
|
93
|
+
| `view_image` | Pi `read` already accepts images; no canonical `view_image` alias is registered. |
|
|
94
|
+
| `update_plan`, `request_user_input`, permissions, and environment tools | Not implemented by this package. |
|
|
95
|
+
| Context-window and clock tools | Not implemented. Compaction remains host/provider managed rather than model managed. |
|
|
96
|
+
| MCP resources and dynamic MCP tools | Pi does not provide this package with Codex's MCP runtime. |
|
|
97
|
+
| Plugin/connector installation | Not implemented; package installation remains an explicit Pi/user operation. |
|
|
98
|
+
| Searchable `tool_search` catalog | Pi can replay additive tool-search history for capable models, but this package does not implement Codex's searchable deferred-tool catalog and ranking runtime. |
|
|
99
|
+
| Multi-agent V1/V2 coordination | Out of scope; no Codex agent tree, mailbox, task-path, or fork-depth runtime is implemented. |
|
|
100
|
+
| JavaScript Code Mode and yielded cells | Out of scope; no V8 isolate, nested tool namespace, cell storage, or `wait` lifecycle is implemented. |
|
|
101
|
+
| Goals, memories, and remote skill-resource tools | Not implemented; Pi's sessions, files, and native skills remain separate systems. |
|
|
102
|
+
| Remote/deferred execution environments | Not implemented. |
|
|
103
|
+
|
|
104
|
+
See [`OFFICIAL_CODEX_CLI_TOOL_CATALOG.md`](OFFICIAL_CODEX_CLI_TOOL_CATALOG.md) for the complete researched Codex tool inventory, and [`CUSTOM_CODEX_PROVIDER_WEB_REFERENCES.md`](CUSTOM_CODEX_PROVIDER_WEB_REFERENCES.md) for the unimplemented citation/reference design.
|
|
105
|
+
|
|
106
|
+
## Install
|
|
107
|
+
|
|
108
|
+
From npm after a release is published:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pi install npm:pi-openai-codex-compat
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
From a local checkout:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pi install .
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
For a temporary development run:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pi --no-extensions -e .
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Fast mode
|
|
127
|
+
|
|
128
|
+
Keep using an `openai-codex` model and enable **Fast mode** in `/codex-settings`. The extension adds `service_tier: "priority"` to ordinary and native-compaction requests without introducing another provider id or changing the selected model.
|
|
129
|
+
|
|
130
|
+
Fast mode applies to whichever built-in `openai-codex` model is selected. Priority-tier costs are reflected in Pi's usage totals, including when Codex echoes `service_tier: "default"` in its response.
|
|
131
|
+
|
|
132
|
+
## Configuration
|
|
133
|
+
|
|
134
|
+
Create a global configuration file at:
|
|
135
|
+
|
|
136
|
+
```text
|
|
137
|
+
~/.pi/agent/openai-codex-compat.json
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
A trusted project can override it at:
|
|
141
|
+
|
|
142
|
+
```text
|
|
143
|
+
<project>/.pi/openai-codex-compat.json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Each session inherits the effective file-backed settings. Open `/codex-settings` to make immediate session-local changes. Press `Ctrl+S` in the pane to persist the current values; the global file is the normal save target, while an existing trusted project override remains the target for that project.
|
|
147
|
+
|
|
148
|
+
The effective settings are printed once when a TUI session starts. The footer shows `fast` and `pro` only when enabled, and shows text verbosity or reasoning summary only when they differ from their defaults.
|
|
149
|
+
|
|
150
|
+
Example:
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"fastMode": true,
|
|
155
|
+
"toolBackground": "subtle",
|
|
156
|
+
"applyPatch": true,
|
|
157
|
+
"imageGeneration": true,
|
|
158
|
+
"imageDetail": "auto",
|
|
159
|
+
"webRun": true,
|
|
160
|
+
"autoCompactAtPercent": 90,
|
|
161
|
+
"webSearch": "cached",
|
|
162
|
+
"textVerbosity": "low",
|
|
163
|
+
"reasoningSummary": "auto",
|
|
164
|
+
"reasoningMode": "standard"
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Defaults:
|
|
169
|
+
|
|
170
|
+
| Setting | Values | Default | Behavior |
|
|
171
|
+
| ---------------------- | ---------------------------------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
172
|
+
| `fastMode` | boolean | `false` | Adds `service_tier: "priority"` to requests while retaining the current `openai-codex` provider and model. |
|
|
173
|
+
| `toolBackground` | `subtle`, `status`, `none` | `subtle` | Controls the shared self-rendered background for `apply_patch`, `image_gen.imagegen`, and `web.run`. `status` uses Pi's pending/success/error backgrounds; `none` keeps the custom layout transparent. |
|
|
174
|
+
| `applyPatch` | boolean | `true` | On selected `openai-codex` models, uses the extension's `apply_patch` tool instead of Pi's active `edit` and `write` tools. Other providers always use their normal Pi tool set. |
|
|
175
|
+
| `imageGeneration` | boolean | `true` | Enables the extension-owned `image_gen.imagegen` tool on selected `openai-codex` models. |
|
|
176
|
+
| `imageDetail` | `auto`, `low`, `high`, `original` | `auto` | Sets `input_image.detail` when an image tool result is sent back to the model. It does not change `gpt-image-2` generation quality. |
|
|
177
|
+
| `webRun` | boolean | `true` | Enables the extension-owned `web.run` tool on selected `openai-codex` models. When active, it replaces hosted `web_search` in the Responses tool list. |
|
|
178
|
+
| `autoCompactAtPercent` | number greater than `0` and at most `100`, or `null` | unset | Adds provider-boundary compaction independently of Pi's normal reserve-token threshold. A project value of `null` disables a global percentage threshold. |
|
|
179
|
+
| `webSearch` | `disabled`, `cached`, `indexed`, `live` | `cached` | Controls hosted search and standalone-search external access. `disabled` removes hosted search but leaves an independently enabled `web.run` in cached-only mode; `indexed` prefers indexed content; `live` permits live external access. |
|
|
180
|
+
| `textVerbosity` | `low`, `medium`, `high` | `low` | Sets Responses API `text.verbosity`. |
|
|
181
|
+
| `reasoningSummary` | `auto`, `concise`, `detailed`, `off` | `auto` | Sets `reasoning.summary` when reasoning is enabled; `off` omits the summary parameter. |
|
|
182
|
+
| `reasoningMode` | `standard`, `pro` | `standard` | Sets `reasoning.mode` on GPT-5.6 models independently of Pi's reasoning-effort control. |
|
|
183
|
+
|
|
184
|
+
Invalid values are ignored and invalid JSON does not prevent Pi from starting. The settings pane never writes on ordinary changes, refuses to overwrite invalid JSON when `Ctrl+S` is pressed, and retains unknown keys when saving. Project configuration is read only when the project is trusted.
|
|
185
|
+
|
|
186
|
+
## Native compaction
|
|
187
|
+
|
|
188
|
+
The extension handles native compaction for `openai-codex`. It follows the Codex v2 flow:
|
|
189
|
+
|
|
190
|
+
1. Send normal Responses history followed by `{ "type": "compaction_trigger" }`.
|
|
191
|
+
2. Validate the returned opaque `compaction` item.
|
|
192
|
+
3. Retain approximately 64,000 tokens of recent user, developer, and system context.
|
|
193
|
+
4. Persist the opaque checkpoint in the Pi session and replay it on later requests.
|
|
194
|
+
|
|
195
|
+
Ordinary responses and compaction use the same extension-managed SSE/WebSocket transport. The provider stores a native response override only when Pi's canonical assistant representation cannot round-trip the provider output exactly; normal text, reasoning, and tool responses therefore do not duplicate session data. Native overrides are associated with canonical assistants by response id and replayed only when they are present on the active Pi branch.
|
|
196
|
+
|
|
197
|
+
Any model switch is rejected while the active branch contains a native Codex checkpoint because checkpoints are model-specific. Navigate to a branch before the checkpoint or start a new session before switching. Toggling fast mode does not change the model id or invalidate the checkpoint.
|
|
198
|
+
|
|
199
|
+
Native compaction fails closed for Codex models: a failed compaction is cancelled instead of silently replacing the opaque state with a local text summary. Other providers continue to use Pi's default compaction behavior. `/tree` branch summarization is intentionally not intercepted.
|
|
200
|
+
|
|
201
|
+
When the active branch has no native Codex checkpoint, Pi model switching remains available. Selecting a provider other than `openai-codex` disables `apply_patch`, `image_gen.imagegen`, and `web.run`, and restores the Pi `edit` and `write` tools that `apply_patch` suppressed. Switching back to an `openai-codex` model reapplies the current session settings.
|
|
202
|
+
|
|
203
|
+
## `apply_patch`
|
|
204
|
+
|
|
205
|
+
The package registers an `apply_patch` tool using the Codex patch format:
|
|
206
|
+
|
|
207
|
+
```text
|
|
208
|
+
*** Begin Patch
|
|
209
|
+
*** Update File: src/example.ts
|
|
210
|
+
@@
|
|
211
|
+
-old value
|
|
212
|
+
+new value
|
|
213
|
+
*** End Patch
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
While `applyPatch` is enabled and an `openai-codex` model is selected, the extension temporarily disables Pi's active `edit` and `write` tools. Turning the setting off or selecting another provider restores only the tools that were active before `apply_patch` replaced them.
|
|
217
|
+
|
|
218
|
+
Supported operations:
|
|
219
|
+
|
|
220
|
+
- add files;
|
|
221
|
+
- update files with ordered context chunks;
|
|
222
|
+
- delete files;
|
|
223
|
+
- move an updated file;
|
|
224
|
+
- anchor updates at the end of a file.
|
|
225
|
+
|
|
226
|
+
Compatibility behavior:
|
|
227
|
+
|
|
228
|
+
- `*** Add File` overwrites an existing file, matching Codex.
|
|
229
|
+
- `*** Move to` overwrites an existing destination, matching Codex.
|
|
230
|
+
- Hunk matching retries exact text, trailing-whitespace-insensitive text, fully trimmed text, and Codex's Unicode punctuation normalization.
|
|
231
|
+
- The parser accepts Codex's lenient marker whitespace, blank update-context lines, and direct heredoc wrappers.
|
|
232
|
+
- Successful model-facing results use Codex's exit-code, wall-time, and `Success. Updated the following files:` format.
|
|
233
|
+
- Tool-result history stores per-file old/new content, display diffs, move destinations, overwrite information, and committed-prefix details after runtime failures.
|
|
234
|
+
- The TUI renders Codex-style `Added`, `Edited`, and `Deleted` diff blocks instead of the raw model-facing result.
|
|
235
|
+
- The collapsed view shows aggregate and per-file counts; `Ctrl+O` reveals complete hunks.
|
|
236
|
+
|
|
237
|
+
Filesystem behavior:
|
|
238
|
+
|
|
239
|
+
- Relative paths resolve from Pi's current working directory; absolute paths and `..` traversal are honored.
|
|
240
|
+
- `.git` paths and symlinks follow normal host filesystem semantics.
|
|
241
|
+
- The extension does not add path filtering, sandboxing, or approval prompts.
|
|
242
|
+
- Every hunk is parsed and validated before filesystem writes begin.
|
|
243
|
+
- Mutations participate in Pi's per-file mutation queue and `apply_patch` calls execute sequentially.
|
|
244
|
+
|
|
245
|
+
A low-level I/O failure can still leave a multi-file patch partially applied. The failed tool result records the known committed prefix, but inspect the working tree before retrying when that record is marked inexact.
|
|
246
|
+
|
|
247
|
+
## `image_gen.imagegen`
|
|
248
|
+
|
|
249
|
+
The package registers the dotted Pi tool name `image_gen.imagegen` and serializes it as a native Responses API namespace:
|
|
250
|
+
|
|
251
|
+
```json
|
|
252
|
+
{
|
|
253
|
+
"type": "namespace",
|
|
254
|
+
"name": "image_gen",
|
|
255
|
+
"tools": [{ "type": "function", "name": "imagegen" }]
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
The tool generates new images with `gpt-image-2` or edits up to five local/recent conversation images. Local edit inputs must use absolute paths and are read directly with the Pi process's filesystem permissions. PNG, JPEG, GIF, and WebP edit inputs are accepted. Generated PNGs are returned to Pi as image tool content and stored without overwriting existing files under:
|
|
260
|
+
|
|
261
|
+
```text
|
|
262
|
+
~/.pi/agent/generated_images/<session-id>/<call-id>.png
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
The active Pi agent directory replaces `~/.pi/agent` when configured differently. Turning `imageGeneration` off removes the tool immediately for the current session; `Ctrl+S` in `/codex-settings` persists the value.
|
|
266
|
+
|
|
267
|
+
Pi also persists the returned image content in tool-result history so later image edits and provider replay remain self-contained. Generated-image turns therefore increase the session file by approximately the base64 image size in addition to the saved PNG artifact.
|
|
268
|
+
|
|
269
|
+
When the image tool result is serialized back to the model, `imageDetail` controls its Responses `input_image.detail`. The default remains `auto`; select `high` for the official Codex default. The saved-path hint intentionally differs from Codex: it always uses “the generated image” and is not removed when the UTF-8 hint exceeds 1,024 bytes.
|
|
270
|
+
|
|
271
|
+
The TUI shows a compact generation/edit summary and saved artifact path instead of the model-facing path hint. `Ctrl+O` reveals the full prompt and artifact metadata; terminal image display continues to use Pi's normal image support.
|
|
272
|
+
|
|
273
|
+
## `web.run`
|
|
274
|
+
|
|
275
|
+
The package registers the dotted Pi tool name `web.run` and serializes it as a native Responses API `web` namespace. Calls are executed through `codex/alpha/search`. Like Codex, successful model-facing output is the unmodified plaintext `output` wrapped in a single `input_text` content item:
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
{
|
|
279
|
+
"type": "function_call_output",
|
|
280
|
+
"call_id": "<call-id>",
|
|
281
|
+
"output": [{ "type": "input_text", "text": "<alpha/search output>" }]
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Structured `results` are not sent to the model by either implementation. Codex stores them in extension-backed web-search events; this package stores the equivalent opaque JSON branch-locally in Pi tool-result `details`. Extensions and session readers can inspect those details, while subsequent `web.run` calls resolve model-visible reference IDs through `alpha/search` rather than querying the details directly.
|
|
286
|
+
|
|
287
|
+
The collapsed TUI view provides action-specific summaries for search, image search, page navigation, in-page find, PDF screenshots, finance, weather, sports, and time. `Ctrl+O` expands structured source or image cards, page metadata with line/page gutters, PDF page cards, operation-specific result cards, and readable labeled fields for forward-compatible result types. Citation markers and backend separators are normalized for display, while empty or unavailable operations use compact warning states instead of appearing successful.
|
|
288
|
+
|
|
289
|
+
Standalone `screenshot` calls return a plaintext PDF-page reference from `alpha/search`, not image bytes or an image content item. The TUI therefore labels these results as reference-only, and the next model request receives the same plaintext reference rather than screenshot pixels.
|
|
290
|
+
|
|
291
|
+
The exposed command schema includes:
|
|
292
|
+
|
|
293
|
+
- `search_query`;
|
|
294
|
+
- `image_query`;
|
|
295
|
+
- `open`;
|
|
296
|
+
- `click`;
|
|
297
|
+
- `find`;
|
|
298
|
+
- `screenshot`;
|
|
299
|
+
- `finance`;
|
|
300
|
+
- `weather`;
|
|
301
|
+
- `sports`;
|
|
302
|
+
- `time`;
|
|
303
|
+
- `response_length`.
|
|
304
|
+
|
|
305
|
+
The tool sends the current user message plus the preceding visible user/assistant turn as search context. When `web.run` is active, hosted `web_search` is omitted; turning `webRun` off restores the hosted tool according to `webSearch`.
|
|
306
|
+
|
|
307
|
+
Both namespace tools are accepted only from the fixed extension-owned allowlist. Unknown namespaced calls and flat wire calls named `web.run` or `image_gen.imagegen` fail instead of being routed ambiguously.
|
|
308
|
+
|
|
309
|
+
## Development
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
mise trust
|
|
313
|
+
mise install
|
|
314
|
+
npm install
|
|
315
|
+
npm run check
|
|
316
|
+
npm test
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
The focused Pi AI serializer copy lives under `extensions/openai-codex-compat/vendor/pi-ai/`. The custom Codex provider transport and stream parser are focused adaptations of Pi AI's corresponding implementation. Equivalence and protocol tests cover canonical serialization, native namespace round-trips, raw native replay, sibling Codex JSON endpoints, SSE request behavior, WebSocket reuse, grammar tools, image results, standalone search, and compaction continuation.
|
|
320
|
+
|
|
321
|
+
## Release staging
|
|
322
|
+
|
|
323
|
+
The GitHub Actions workflow stages npm releases when a `v*` tag is pushed. The tag must match `package.json` version and point at a commit whose subject is `release: v<version>`.
|
|
324
|
+
|
|
325
|
+
## Acknowledgements
|
|
326
|
+
|
|
327
|
+
The remote-compaction implementation follows the current OpenAI Codex `remote_compaction_v2` protocol. The `apply_patch`, standalone image-generation, and standalone web-search behavior is adapted from OpenAI Codex under Apache-2.0. The Codex provider transport, stream processing, and OpenAI Responses history serialization adapt selected Pi AI methods under MIT; see [third-party notices](THIRD_PARTY_NOTICES.md).
|
|
328
|
+
|
|
329
|
+
## License
|
|
330
|
+
|
|
331
|
+
MIT © 2026 Kaan Ozdokmeci. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
## OpenAI Codex
|
|
4
|
+
|
|
5
|
+
The `apply_patch` grammar, parser behavior, fuzzy matching, mutation semantics, result formatting, diff rendering, standalone image-generation behavior, standalone web-search behavior, tool schemas, and compatibility scenarios in this package are adapted for Pi from the public OpenAI Codex implementation.
|
|
6
|
+
|
|
7
|
+
OpenAI Codex, Copyright 2025 OpenAI
|
|
8
|
+
|
|
9
|
+
OpenAI Codex is licensed under the Apache License, Version 2.0. A copy is included at [`LICENSES/Apache-2.0.txt`](LICENSES/Apache-2.0.txt).
|
|
10
|
+
|
|
11
|
+
Source: <https://github.com/openai/codex>
|
|
12
|
+
|
|
13
|
+
## Pi AI
|
|
14
|
+
|
|
15
|
+
Selected OpenAI Codex transport, Responses stream processing, and history serialization methods are adapted from `@earendil-works/pi-ai`.
|
|
16
|
+
|
|
17
|
+
Pi AI, Copyright (c) 2025 Mario Zechner
|
|
18
|
+
|
|
19
|
+
Pi AI is licensed under the MIT License. A copy is included at [`LICENSES/pi-ai-MIT.txt`](LICENSES/pi-ai-MIT.txt).
|
|
20
|
+
|
|
21
|
+
Source: <https://github.com/earendil-works/pi/tree/main/packages/ai>
|