pi-openai-toolkit 0.14.4 → 0.14.5

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/README.md CHANGED
@@ -1,239 +1,211 @@
1
1
  # pi-openai-toolkit
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/pi-openai-toolkit.svg)](https://www.npmjs.com/package/pi-openai-toolkit)
4
- [![license: MIT](https://img.shields.io/npm/l/pi-openai-toolkit.svg)](./LICENSE)
5
- [简体中文](./README.zh.md)
3
+ Add Codex context windows, Responses compaction, hosted tools, and reviewed tool calls to Pi.
6
4
 
7
- OpenAI toolkit for Pi: lossless long-session context management, hosted web search, image generation, and approval-gated auto mode.
5
+ [![npm version](https://img.shields.io/npm/v/pi-openai-toolkit.svg)](https://www.npmjs.com/package/pi-openai-toolkit)
6
+ [![License: MIT](https://img.shields.io/npm/l/pi-openai-toolkit.svg)](LICENSE)
8
7
 
9
- Pi's built-in compaction summarizes older turns into text, permanently losing detail. The OpenAI Codex backend solves this with mechanisms generic clients never received: a context-window system (`new_context`, `history`, `notes`), encrypted lossless compaction, and hosted tools. This package ports those Codex capabilities into Pi by implementing their protocols against the live backends; Auto Mode is its own feature. One note: the context-window tools you see in a covered session are Codex's mechanism, surfaced by this toolkit, not something Pi or this package invented independently.
8
+ [简体中文](README.zh.md)
10
9
 
11
10
  ## Features
12
11
 
13
- - **Context windows** (Codex mechanism, ported) - roll over to a fresh window with `new_context`; nothing is re-summarized
14
- - **Cross-window recall** - search and read earlier windows with `history`
15
- - **Working-memory notes** - persistent checkpoint files with `notes`, gating every rollover
16
- - **Encrypted compaction (v2)** - OpenAI backend compaction capability, surfaced for Responses models
17
- - **Hosted web search** - OpenAI Responses native `web_search`, swapped in for Pi's local tool on listed models
18
- - **Image generation** - hosted `image_generation` (gpt-image-2) wrapped in a Pi tool that keeps image bytes out of history
19
- - **Auto mode** - this package's own feature: a reviewer-model approval gate for side-effecting tool calls
20
- - **Safety guarantees** - no lossy summary on covered models, credentials never leave the machine
12
+ | Feature | Use it to |
13
+ | --- | --- |
14
+ | Codex Remote Context | Start a new context window and retrieve earlier windows with `history`. |
15
+ | Remote Compaction v2 | Continue an eligible Responses session with an encrypted server checkpoint. |
16
+ | Hosted Web Search | Give selected models OpenAI's hosted search tool. |
17
+ | Image generation | Generate images or edit explicitly supplied local reference images. |
18
+ | Tool-call review | Ask a reviewer model whether selected tool calls may run. |
21
19
 
22
- Requires Pi >= 0.85.1 and Node.js >= 22.19.0. The toolkit registers no provider or model of its own; it works entirely through Pi's existing catalog, auth, and session storage. Do not run `pi-remote-compact`, `@lll9p/pi-better-compaction`, or a standalone `pi-openai-web-search` alongside it: duplicate hooks cause race conditions.
20
+ The package uses Pi's existing model, authentication, and session configuration. It does not add a provider or model.
23
21
 
24
22
  ## Install
25
23
 
24
+ Requires Pi 0.85.1 or newer and Node.js 22.19.0 or newer.
25
+
26
+ Install the extension:
27
+
26
28
  ```bash
27
29
  pi install npm:pi-openai-toolkit
28
30
  ```
29
31
 
30
- Per-project install:
32
+ Use `--local` to install it in the current project.
31
33
 
32
- ```bash
33
- pi install npm:pi-openai-toolkit --local
34
- ```
34
+ Installing the package alone does not enable every feature. With no extension config, compaction is enabled but Remote Context is off, the Web Search model list is empty, image generation is disabled, and Auto Mode has no allowed models or reviewer.
35
35
 
36
- Install from git for development or pinned builds:
36
+ The extension config file is:
37
37
 
38
- ```bash
39
- pi install git:github.com/awoaCrim/pi-openai-toolkit
40
- ```
38
+ `~/.pi/agent/extensions/pi-openai-toolkit/config.json`
41
39
 
42
- Update later with `pi update --extensions`.
40
+ All JSON configuration examples below, except the `models.json` example, go in this file. If it does not exist, create the file and its parent directory. If it already exists, merge fields into the matching objects and keep the other settings.
43
41
 
44
- ## Quick start
42
+ ## Quick start: enable Remote Context
45
43
 
46
- **1.** Create `~/.pi/agent/extensions/pi-openai-toolkit/config.json` (Windows: `C:\Users\<user>\.pi\agent\extensions\pi-openai-toolkit\config.json`):
44
+ This section is for users who want Codex-style context windows. If you only want Web Search, image generation, or tool-call review, skip to [Common tasks](#common-tasks).
45
+
46
+ ### Use Pi's built-in Codex provider
47
+
48
+ You must already be signed in to Pi's built-in `openai-codex` provider.
49
+
50
+ Create or merge this extension config:
47
51
 
48
52
  ```json
49
53
  {
50
54
  "compaction": {
51
- "contextManagement": "remote",
52
- "contextReminderThresholdPercent": 10
55
+ "contextManagement": "remote"
53
56
  }
54
57
  }
55
58
  ```
56
59
 
57
- **2.** Start Pi on a covered model: any session on Pi's built-in Codex provider (`openai-codex`), or a gateway model listed in `gatewayContextModels`:
60
+ Start Pi with a model from your existing Codex catalog:
58
61
 
59
62
  ```bash
60
- pi --model uwoacrimson/gpt-6-astra
63
+ pi --model openai-codex/<model-id>
61
64
  ```
62
65
 
63
- **3.** Confirm activation: the four Codex context tools (`new_context`, `get_context_remaining`, `history`, `notes`) appear in the session.
66
+ Replace `<model-id>` with the model ID shown by your Pi setup. The session is activated when `new_context`, `get_context_remaining`, `history`, and `notes` appear as available tools.
64
67
 
65
- When the window drops below the reminder threshold, the model gets one nudge to save notes and roll over. Everything earlier stays searchable through `history`. With no config file, Pi's defaults apply and every optional feature stays off.
68
+ ### Use a compatible gateway
66
69
 
67
- Gateway coverage is an explicit allowlist: `compaction.gatewayContextModels` holds exact `provider/model` keys, each on the `openai-responses` wire and actually relayed by your gateway with Codex window markers intact. If your gateway isn't configured in Pi yet, add it to `~/.pi/agent/models.json`:
70
+ This route requires the `openai-responses` API and a gateway that preserves the Codex protocol fields used by Remote Context. A successful ordinary chat request does not prove Remote Context compatibility.
71
+
72
+ If `~/.pi/agent/models.json` already contains a gateway model that meets these conditions, skip model configuration and set the extension allowlist directly. Otherwise, add or merge the provider entry below. Replace `my-gateway`, the URL, the environment variable name, and the model values with values from your setup. The numeric values shown are examples, not project defaults; they must match the actual model and gateway.
68
73
 
69
74
  ```json
70
75
  {
71
76
  "providers": {
72
- "uwoacrimson": {
73
- "baseUrl": "https://<your-gateway>/v1",
74
- "apiKeyRef": "uwoacrimson",
75
- "api": "openai",
77
+ "my-gateway": {
78
+ "baseUrl": "https://your-gateway.example/v1",
79
+ "api": "openai-responses",
80
+ "apiKey": "$MY_GATEWAY_KEY",
76
81
  "models": [{
77
- "id": "gpt-6-astra",
78
- "name": "GPT-6 Astra",
79
- "api": "openai-responses",
82
+ "id": "gpt-5.6-luna",
83
+ "name": "GPT-5.6 Luna",
80
84
  "reasoning": true,
81
85
  "input": ["text"],
82
86
  "contextWindow": 272000,
83
- "maxTokens": 16384,
84
- "compat": {"thinkingLevelMap": {"off": 0, "minimal": 0.1, "low": 0.2, "medium": 0.5, "high": 1, "xhigh": 2, "max": 2}}
87
+ "maxTokens": 128000
85
88
  }]
86
89
  }
87
90
  }
88
91
  }
89
92
  ```
90
93
 
91
- ## Usage
92
-
93
- ### Codex Remote Context
94
-
95
- This is Codex's own context-window mechanism, implemented for Pi by this toolkit. Covered sessions run like they do in the Codex client: the model works in context windows, checkpoints state into `notes`, and calls `new_context` before the window fills. Nothing is summarized; earlier windows remain fully readable through `history`. A rollover is refused unless a notes checkpoint succeeded in the current window, and the session survives resume and fork with the same rules. Reminder and exhausted-window messages only advise the model; every rollover is the model's own tool call.
94
+ Set the referenced key before starting Pi. In PowerShell:
96
95
 
97
- The toolkit owns compaction for covered models: Pi-native compaction is cancelled on every path, so no lossy summary can enter the session. If Remote Context cannot activate, the exact reason is reported as a notification.
98
-
99
- Lifecycle mechanics and protocol contracts: [docs/internals.md](docs/internals.md#rollover-lifecycle).
96
+ ```powershell
97
+ $env:MY_GATEWAY_KEY = "replace-with-your-gateway-key"
98
+ ```
100
99
 
101
- ### Remote Compaction v2
100
+ In a POSIX shell:
102
101
 
103
- For other Responses models: when compaction triggers, the toolkit asks the OpenAI backend's compaction capability for an encrypted checkpoint of the old prefix instead of allowing a text summary to replace it; the server computes the checkpoint, the client only stores and replays it. Later requests replay the checkpoint ahead of recent turns. Failed attempts degrade to Pi's native compaction (`nativeFallback`). Wire contract: [docs/internals.md](docs/internals.md#remote-compaction-v2-wire-contract).
102
+ ```bash
103
+ export MY_GATEWAY_KEY="replace-with-your-gateway-key"
104
+ ```
104
105
 
105
- ### Web search
106
+ Use the same terminal session to start Pi. Create or merge the extension config, and make the allowlist entry exactly match the provider and model ID:
106
107
 
107
108
  ```json
108
109
  {
109
- "webSearch": { "enabled": true, "models": ["uwoacrimson/gpt-5.6-luna"] }
110
+ "compaction": {
111
+ "contextManagement": "remote",
112
+ "gatewayContextModels": ["my-gateway/gpt-5.6-luna"]
113
+ }
110
114
  }
111
115
  ```
112
116
 
113
- Listed models get OpenAI's hosted `web_search`; their local `web_search` tool is removed from the payload. The live model connection is reused, no extra key.
117
+ Start Pi with the same model specification:
118
+
119
+ ```bash
120
+ pi --model my-gateway/gpt-5.6-luna
121
+ ```
122
+
123
+ The enablement check is the same: the session should expose `new_context`, `get_context_remaining`, `history`, and `notes`. If they do not appear, read the toolkit notification and check the exact provider/model string, API, key, base URL, and allowlist entry.
124
+
125
+ Earlier windows remain available through `history`, but they are not all automatically added to the current context.
126
+
127
+ ## Common tasks
128
+
129
+ ### Continue a session with server-side compaction
130
+
131
+ Leave Remote Context off when you want the Responses compaction path instead. Remote Compaction v2 stores and replays an encrypted checkpoint for eligible Responses models. Set `compaction.remoteCompactModel` only when the compaction request should use a separate model.
114
132
 
115
- ### Image generation
133
+ ### Enable hosted Web Search
134
+
135
+ List exact model specifications under `webSearch.models`:
116
136
 
117
137
  ```json
118
138
  {
119
- "imageGeneration": { "enabled": true }
139
+ "webSearch": {
140
+ "models": ["my-gateway/gpt-5.6-luna"]
141
+ }
120
142
  }
121
143
  ```
122
144
 
123
- Adds `openai_generate_image` to every Responses-wire session, wrapping OpenAI's hosted `image_generation` tool (`gpt-image-2`): text-to-image and edits from explicitly passed local reference files. The wrapper stores image bytes as artifacts instead of session history. Each successful request may incur a charge, hence the default off.
145
+ For those models, the extension replaces Pi's local `web_search` tool with OpenAI's hosted Responses search tool.
124
146
 
125
- ### Auto mode
147
+ ### Generate an image
148
+
149
+ Image generation requires a Responses session and may incur provider charges. Enable it with:
126
150
 
127
151
  ```json
128
152
  {
129
- "autoMode": {
153
+ "imageGeneration": {
130
154
  "enabled": true,
131
- "models": ["uwoacrimson/gpt-5.6-luna"],
132
- "reviewerModel": "uwoacrimson/gpt-5.6-luna"
155
+ "models": ["gpt-image-2.5", "grok-imagine-image-2.0"]
133
156
  }
134
157
  }
135
158
  ```
136
159
 
137
- Engage per session with `/auto on`. Side-effecting tool calls are approved by `reviewerModel` (intrinsic risk plus conversation authorization) instead of blocking on the user. The reviewer has read-only tools only, a timeout is never approval, and headless sessions block instead of guessing. Decisions are persisted for audit.
160
+ `models` contains the bare model IDs used by the nested Responses `image_generation` tool. The first entry is the default; `openai_generate_image` also accepts an optional `model` argument for a one-call override, but it must match a configured entry exactly. If `models` is omitted, the default is `gpt-image-2.5`. Empty or invalid lists are ignored with a warning and fall back to that default; set `enabled` to `false` to disable the tool. The provider or gateway must support the configured image model.
138
161
 
139
- ## Configuration
162
+ The `openai_generate_image` tool supports text-to-image requests and edits using explicitly supplied local reference images.
140
163
 
141
- One JSON file at `~/.pi/agent/extensions/pi-openai-toolkit/config.json`. Every key is optional; unknown keys are ignored with a warning. `models` keys are exact `provider/model-id` allowlists (no globbing); each feature stays off until a model is listed.
164
+ ### Review tool calls automatically
142
165
 
143
- <details>
144
- <summary><b>Full option reference</b> (compaction, webSearch, imageGeneration, autoMode)</summary>
166
+ Allow a model and reviewer in `autoMode`:
145
167
 
146
- ### `compaction`
147
-
148
- | Key | Type / default | Meaning |
149
- | --- | --- | --- |
150
- | `enabled` | *boolean*, `true` | Master switch for the compaction extension. |
151
- | `contextManagement` | `"off"` \| `"remote"`, `"off"` | Enables Codex Remote Context for covered models: any `openai-codex` session on the `openai-codex-responses` API, plus gateway models listed below. |
152
- | `gatewayContextModels` | *string[]*, `[]` | Exact `provider/model` keys allowed to use Codex Remote Context over the `openai-responses` gateway wire. Coverage is operator-configured; the native Codex route ignores this list. |
153
- | `contextReminderThresholdPercent` | *integer* `0`-`100`, `5` | Percentage of the usable budget (context window minus a fixed 16384-token output reserve) below which the once-per-window checkpoint reminder fires. `0` suppresses the reminder and, in the current implementation, the exhausted-window fallback too; keep it above 0. The threshold measures the toolkit's budget, a fixed pairing with Pi's native reserve rather than a live sync. |
154
- | `allowCompactionContinuityBreak` | *boolean*, `false` | v2: rebuild a fresh encrypted chain when the latest compaction came from another strategy (e.g. a pre-install text summary). |
155
- | `remoteCompactModel` | *string \| null*, `null` | v2: model for the server-side compaction request only; the session model never switches. Must resolve to the same base URL as the active model. |
156
- | `nativeFallback.enabled` | *boolean*, `true` | Native compaction fallback, only after a remote attempt actually failed. |
157
- | `nativeFallback.model` | *string \| null*, `null` | Summary model for models that cannot use v2 at all. `null` keeps the active model. |
158
- | `nativeFallback.thinkingLevel` | *string*, `"off"` | Thinking level for the fallback summary (`off`...`max`). |
159
- | `responsesApis` | *string[]*, both APIs | Which Responses API identifiers may use v2 compaction. v2 only applies to models that Remote Context does not cover. |
160
- | `notifyOnLoad` | *boolean*, `false` | Startup banner. |
161
- | `debug` | *boolean*, `false` | Write lifecycle and compaction artifacts under `artifactRoot`, including the activation reason per `session_start`. |
162
- | `logProviderPayloads` / `logCompactResponses` | *boolean*, `false` | Also write raw provider payloads and SSE bodies. Off unless debugging one request. |
163
- | `redactSensitiveData` | *boolean*, `true` | Artifact redaction; credentials, account ids, and encrypted payloads are always redacted. |
164
- | `artifactRoot` | *string*, `~/.pi/agent/artifacts/pi-openai-toolkit/compaction` | Artifact root; relative paths resolve against the config directory. |
165
-
166
- ### `webSearch`
167
-
168
- | Key | Type / default | Meaning |
169
- | --- | --- | --- |
170
- | `enabled` | *boolean*, `true` | Master switch. |
171
- | `models` | *string[]*, `[]` | Sessions receiving OpenAI's hosted `web_search`: the local `web_search` tool is removed and the native responses-API tool injected. |
168
+ ```json
169
+ {
170
+ "autoMode": {
171
+ "models": ["my-gateway/gpt-5.6-luna"],
172
+ "reviewerModel": "my-gateway/gpt-5.6-luna"
173
+ }
174
+ }
175
+ ```
172
176
 
173
- ### `imageGeneration`
177
+ Use `/auto on` in the session. The default `side-effect` gate reviews `bash`, `write`, `edit`, and configured extra tools. Set `gate` to `"all"` when every tool call needs review. A reviewer timeout does not approve a call.
174
178
 
175
- | Key | Type / default | Meaning |
176
- | --- | --- | --- |
177
- | `enabled` | *boolean*, `false` | Exposes `openai_generate_image` to all Responses-wire sessions. No model allowlist by design. |
179
+ ## Common configuration
178
180
 
179
- ### `autoMode`
181
+ The config file is `~/.pi/agent/extensions/pi-openai-toolkit/config.json`. Unknown keys are ignored with a warning. Most model lists use exact `provider/model-id` strings, not globs; `imageGeneration.models` is an exception and contains bare nested image-generation model IDs.
180
182
 
181
- | Key | Type / default | Meaning |
183
+ | Key | Default | Use |
182
184
  | --- | --- | --- |
183
- | `enabled` | *boolean*, `true` | Master switch; engaging still needs a listed model and `reviewerModel`. |
184
- | `models` | *string[]*, `[]` | Session models allowed to run auto mode. |
185
- | `reviewerModel` | *string \| null*, `null` | Approving model for one-off reviews; never becomes the conversation model. |
186
- | `gate` | `"side-effect"` \| `"all"`, `"side-effect"` | Review scope; `/auto all` switches per session. |
187
- | `extraTools` | *string[]*, `[]` | Additional reviewed tools beyond `bash`, `write`, `edit`. |
188
- | `timeoutMs` | *integer* 1000-120000, `30000` | Review deadline. Expiry is never approval. |
189
- | `transcript` | *boolean*, `true` | Bounded conversation view so the reviewer can judge authorization. |
190
- | `evidenceTools` | *boolean*, `true` | Reviewer may use `read`, `grep`, `find`, `ls`. Never `bash`, writes, or network. |
191
- | `maxEvidenceRounds` | *integer* 0-8, `3` | Investigation rounds before the verdict; `0` is a single completion. |
192
- | `classifier.*` | *object* | Optional non-blocking low-risk pre-scorer. Fast-path only, never denies. |
193
- | `circuitBreaker.*` | *object* | End the turn after repeated denials (`consecutiveDenials` `3`, or `recentDenials` `10` within `windowSize` `50`; `0` disables). |
194
-
195
- ### `codexAstra`
196
-
197
- Removed section. The Astra compatibility layer activates silently for any `gpt-6-astra` session on a Responses-family API; old `codexAstra` config sections are ignored with a warning. If another host (e.g. Oh My Pi) implements the same rewrite, enable only one.
198
-
199
- </details>
200
-
201
- ## Security
202
-
203
- - On covered models, every Pi-native compaction path (threshold, manual `/compact`, overflow) is cancelled while Remote Context owns the session; no lossy summary is possible.
204
- - Gateway mode forwards only the configured data-plane API key. OAuth tokens, account cookies, and account ids are never sent to a gateway and are always redacted from artifacts.
205
- - `new_context` cannot discard unsaved state: a successful notes checkpoint (or explicit user `force`) is required.
206
- - Image generation (billed) and Auto Mode are opt-in; Auto Mode fails closed where nobody can approve.
207
-
208
- For host-level insurance, set `"compaction": { "enabled": false }` in Pi's `settings.json`.
185
+ | `compaction.enabled` | `true` | Master switch for compaction. |
186
+ | `compaction.contextManagement` | `"off"` | Enables Codex Remote Context when set to `"remote"`. |
187
+ | `compaction.gatewayContextModels` | `[]` | Gateway models allowed to use Remote Context. |
188
+ | `compaction.remoteCompactModel` | unset | Optional model used only for a v2 compaction request. |
189
+ | `compaction.contextReminderThresholdPercent` | `5` | Remaining budget percentage for the once-per-window reminder. `0` disables the reminder and exhausted-window fallback. |
190
+ | `webSearch.models` | `[]` | Models that receive hosted Web Search. |
191
+ | `imageGeneration.enabled` | `false` | Enables `openai_generate_image`. |
192
+ | `imageGeneration.models` | `["gpt-image-2.5"]` | Bare image-generation model IDs; the first entry is the default. |
193
+ | `autoMode.models` | `[]` | Models allowed to use Auto Mode. |
194
+ | `autoMode.reviewerModel` | unset | Model that reviews Auto Mode calls. |
195
+ | `autoMode.gate` | `"side-effect"` | Use `"all"` to review every tool call. |
196
+ | `autoMode.timeoutMs` | `30000` | Review timeout in milliseconds. |
209
197
 
210
198
  ## Development
211
199
 
200
+ From the repository root, after dependencies are installed:
201
+
212
202
  ```bash
213
- npm run typecheck # tsc project check
214
- bun test # unit suite
215
- npm run test:pi # Pi integration smoke tests
216
- npm pack --dry-run # inspect the published archive
203
+ npm run typecheck # Type-check
204
+ bun test # Run tests
205
+ npm run test:pi # Run the Pi smoke test
206
+ npm pack --dry-run # Inspect the package contents
217
207
  ```
218
208
 
219
- ## Documentation
220
-
221
- - [docs/internals.md](docs/internals.md) - protocol endpoints, rollover lifecycle, v2 wire contract, artifacts, provenance
222
- - [README.zh.md](README.zh.md) - 简体中文
223
- - [NOTICE](./NOTICE) - third-party attribution
224
-
225
- ## Contributing
226
-
227
- Issues and pull requests are welcome at the [issue tracker](https://github.com/awoaCrim/pi-openai-toolkit/issues). Open an issue before behavior-changing work so protocol assumptions can be discussed. Run `bun test` and `npm run typecheck` before submitting; new wire behavior needs fixture-based tests.
228
-
229
- ## Maintainers
230
-
231
- [awoaCrim](https://github.com/awoaCrim)
232
-
233
209
  ## License
234
210
 
235
- MIT © awoaCrim and contributors. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
236
-
237
- ## Thanks
238
-
239
- Thanks to the [Linux.do](https://linux.do/) community for the support and discussions.
211
+ MIT © awoaCrim and contributors. See [LICENSE](LICENSE) and [NOTICE](NOTICE).