pi-codex-search 0.1.1 → 0.1.2

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
@@ -3,90 +3,223 @@
3
3
  [![npm](https://img.shields.io/npm/v/pi-codex-search)](https://www.npmjs.com/package/pi-codex-search)
4
4
  [![license](https://img.shields.io/npm/l/pi-codex-search)](./LICENSE)
5
5
 
6
- Pi extension that adds a `web_search` tool backed by the ChatGPT Codex backend.
6
+ **Search the web in Pi through your Codex subscription.**
7
7
 
8
- It reuses the `openai-codex` subscription already configured in pi-coding-agent. The extension does not read `ACCESS_TOKEN` during normal pi usage and does not start a separate login flow.
8
+ Pi keeps the harness small. Codex already has a ChatGPT-backed search path. This package connects the two: it adds a `codex_search` tool to Pi and uses the same `openai-codex` login Pi already knows about.
9
+
10
+ No `ACCESS_TOKEN` env var. No separate login flow. If Pi can use your Codex subscription, this extension can use the same auth.
11
+
12
+ ## Why this exists
13
+
14
+ Web search does not have to be built into Pi. It can be a tool.
15
+
16
+ This extension is for Pi workflows that need fresh or source-backed information:
17
+
18
+ - **Look up current docs and release notes.** Ask the model to check things that changed after its training cutoff.
19
+ - **Get sources with the answer.** Search results include citations when Codex returns them.
20
+ - **Reuse your Codex login.** The tool uses Pi's existing `openai-codex` OAuth credential instead of asking you to paste tokens.
21
+ - **Batch related searches.** One tool call can run up to five related queries in parallel and return the results grouped by query.
22
+ - **Keep projects in control.** Rename the tool, change defaults, or disable it per project.
23
+
24
+ ## What this package adds
25
+
26
+ - A `codex_search` Pi tool.
27
+ - 1–5 search queries per call, run in parallel.
28
+ - `live` or `cached` freshness, plus `low` / `medium` / `high` search context size.
29
+ - Streaming progress while Codex responds.
30
+ - Collapsed result previews in the TUI, with full text and sources available when expanded.
31
+ - Structured details: model, citations, search calls, response ids, usage, and per-query failures.
32
+ - Config files for home and project defaults.
33
+ - `/codex-search-settings` for status, editing, reset, rename, and disable.
9
34
 
10
35
  ## Install
11
36
 
12
- Local checkout:
37
+ From npm:
38
+
39
+ ```bash
40
+ pi install npm:pi-codex-search
41
+ ```
42
+
43
+ Or load a local checkout without installing:
13
44
 
14
45
  ```bash
15
46
  pi -e /path/to/pi-codex-search
16
47
  ```
17
48
 
18
- After publishing, the package can be installed through pi's npm package path:
49
+ ### Install from GitHub Release tarball
50
+
51
+ If you prefer not to use npm, download the tarball from the [latest release](https://github.com/Leechael/pi-codex-search/releases/latest), extract it, and install from the local path:
19
52
 
20
53
  ```bash
21
- pi install npm:pi-codex-search
54
+ curl -L https://github.com/Leechael/pi-codex-search/releases/latest/download/pi-codex-search.tar.gz | tar -xz -C /tmp
55
+ pi install /tmp/pi-codex-search
22
56
  ```
23
57
 
24
- The package manifest exposes the extension through:
58
+ ## Sign in
59
+
60
+ Inside Pi, run:
61
+
62
+ ```text
63
+ /login openai-codex
64
+ ```
65
+
66
+ Choose `ChatGPT Plus/Pro (Codex Subscription)` if Pi asks which provider to use. Pi stores and refreshes the credential.
67
+
68
+ The tool is registered by default. If Pi has no `openai-codex` token, or if the ChatGPT account id cannot be found from the stored OAuth credential or decoded access token, the first `codex_search` call fails with an `auth` error that points back to `/login openai-codex`.
69
+
70
+ Set `enabled: false` if you want the extension installed but hidden for a project.
71
+
72
+ ## Tool
73
+
74
+ Default tool name:
75
+
76
+ ```text
77
+ codex_search
78
+ ```
79
+
80
+ Example call:
25
81
 
26
82
  ```json
27
83
  {
28
- "pi": {
29
- "extensions": ["./index.ts"]
84
+ "name": "codex_search",
85
+ "arguments": {
86
+ "queries": ["latest OpenAI Codex release notes"],
87
+ "search_context_size": "medium",
88
+ "freshness": "live"
30
89
  }
31
90
  }
32
91
  ```
33
92
 
34
- ## Authentication
93
+ Arguments:
94
+
95
+ - `queries` — required array of 1–5 search questions. Queries run in parallel; results are grouped by query.
96
+ - `search_context_size` — optional, one of `low`, `medium`, `high`; defaults to `medium`.
97
+ - `freshness` — optional, `live` or `cached`; defaults to `live`.
98
+
99
+ The tool returns text. When citations are available, the text includes a `Sources:` section.
100
+
101
+ The structured `details` object includes:
102
+
103
+ - `model`
104
+ - `freshness` / `searchContextSize`
105
+ - `queryCount` / `failedQueryCount`
106
+ - `successes`: per-query `{ query, text, citations, searchCalls, responseId?, usage? }`
107
+ - `failures`: per-query `{ query, kind, message }`
108
+
109
+ Failure `kind` is one of `auth`, `rate_limit`, `transport`, `timeout`, `schema`, or `unknown`.
110
+
111
+ ## Model used for search
112
+
113
+ The search request needs a Codex model id. The extension chooses it in this order:
114
+
115
+ 1. `model` from env / project / home config, if set.
116
+ 2. The active Pi model, if it comes from the `openai-codex` provider.
117
+ 3. The default model from Codex's `/codex/models` response.
35
118
 
36
- Inside `pi`, run:
119
+ Most users do not need to set this.
120
+
121
+ ## Settings
122
+
123
+ Most users only need `/login openai-codex`. Use settings when you want to rename the tool, disable it for a project, pin a model, or change defaults.
124
+
125
+ Open the interactive settings dialog:
37
126
 
38
127
  ```text
39
- /login openai-codex
128
+ /codex-search-settings
129
+ ```
130
+
131
+ Useful subcommands:
132
+
133
+ ```text
134
+ /codex-search-settings status
135
+ /codex-search-settings reset
40
136
  ```
41
137
 
42
- Choose `ChatGPT Plus/Pro (Codex Subscription)` if pi prompts for a provider. Credentials are stored in pi's auth file and refreshed by pi.
138
+ Settings are merged from three layers, highest precedence first:
43
139
 
44
- At `session_start`, this extension calls `ctx.modelRegistry.getApiKeyForProvider("openai-codex")`. If no token is available, or if the account id cannot be found from the stored OAuth credential or decoded access token, it does not register `web_search`. In that case the model will not see the tool.
140
+ 1. Environment variables.
141
+ 2. Project file: `<cwd>/.pi/pi-codex-search.json`.
142
+ 3. Home file: `~/.pi/pi-codex-search.json`.
45
143
 
46
- ## Usage
144
+ Each layer is optional. Missing files are skipped. Malformed JSON or invalid values fail fast so you do not silently run with the wrong tool settings.
47
145
 
48
- When Codex auth is available at session start, the extension registers:
146
+ Full schema, all fields optional:
49
147
 
50
148
  ```json
51
149
  {
52
- "name": "web_search",
53
- "arguments": {
54
- "query": "latest OpenAI Codex release notes",
55
- "search_context_size": "medium",
56
- "live": true
57
- }
150
+ "enabled": true,
151
+ "toolName": "codex_search",
152
+ "model": "gpt-5-codex",
153
+ "baseUrl": "https://chatgpt.com/backend-api",
154
+ "clientVersion": "1.0.0",
155
+ "searchContextSize": "medium",
156
+ "freshness": "live"
58
157
  }
59
158
  ```
60
159
 
61
- Parameters:
160
+ `enabled: false` skips tool registration entirely. The model will not see `codex_search` at all.
62
161
 
63
- - `query`: required search question.
64
- - `search_context_size`: optional, one of `low`, `medium`, `high`.
65
- - `live`: optional boolean. Defaults to live web access.
162
+ `toolName` lets you avoid conflicts with another extension. Tool names must match `[a-zA-Z_][a-zA-Z0-9_]{0,63}`.
66
163
 
67
- Model selection:
164
+ Environment variable equivalents:
68
165
 
69
- - If `PI_CODEX_WEB_SEARCH_MODEL` is set, that model id is used.
70
- - Otherwise, if the active pi model provider is `openai-codex`, the active model id is used.
71
- - Otherwise, the extension fetches `/codex/models?client_version=...` and uses the default model from that response.
166
+ | Field | Env var |
167
+ | ------------------- | ------------------------------------ |
168
+ | `enabled` | `PI_CODEX_WEB_SEARCH_ENABLED` |
169
+ | `toolName` | `PI_CODEX_WEB_SEARCH_TOOL_NAME` |
170
+ | `model` | `PI_CODEX_WEB_SEARCH_MODEL` |
171
+ | `baseUrl` | `PI_CODEX_WEB_SEARCH_BASE_URL` |
172
+ | `clientVersion` | `PI_CODEX_WEB_SEARCH_CLIENT_VERSION` |
173
+ | `searchContextSize` | `PI_CODEX_WEB_SEARCH_CONTEXT_SIZE` |
174
+ | `freshness` | `PI_CODEX_WEB_SEARCH_FRESHNESS` |
72
175
 
73
- The tool returns text content. Its structured `details` include:
176
+ `PI_CODEX_WEB_SEARCH_ENABLED` accepts `true` / `false` (case-insensitive). Any other value fails config loading.
74
177
 
75
- - `model`
76
- - `responseId`
77
- - `searchCalls`
78
- - `citations`
79
- - `usage`
178
+ Interactive edits write the selected config file immediately. When you close the dialog, Pi reloads so the new tool name and defaults apply without restarting the whole terminal.
179
+
180
+ ## Notes
181
+
182
+ ### Codex search vs model search
183
+
184
+ This does not add browsing to the model provider itself. It adds a Pi tool. The model decides when to call `codex_search`, just like any other tool.
185
+
186
+ ### Account id
187
+
188
+ Codex requests need both the access token and the ChatGPT account id. The extension first checks Pi's stored OAuth credential. If that does not include an account id, it tries to extract one from the access token.
189
+
190
+ ## Troubleshooting
191
+
192
+ ### `codex_search` fails with an `auth` error
193
+
194
+ Run:
80
195
 
81
- ## Configuration
196
+ ```text
197
+ /login openai-codex
198
+ ```
199
+
200
+ If Pi asks for a provider, choose `ChatGPT Plus/Pro (Codex Subscription)`. The extension picks up the refreshed credential on the next call.
201
+
202
+ ### `codex_search` says the account id was not found
203
+
204
+ The stored OAuth credential did not include an account id, and the extension could not decode one from the access token. Re-run `/login openai-codex` so Pi refreshes the credential.
205
+
206
+ ### The model does not see `codex_search`
207
+
208
+ Check whether `enabled` is false in env, project config, or home config:
209
+
210
+ ```text
211
+ /codex-search-settings status
212
+ ```
213
+
214
+ Remember that env overrides project, and project overrides home.
215
+
216
+ ### Search uses the wrong model
82
217
 
83
- - `PI_CODEX_WEB_SEARCH_MODEL`: override the Codex model used by the tool.
84
- - `PI_CODEX_WEB_SEARCH_BASE_URL`: override the Codex backend base URL.
85
- - `PI_CODEX_WEB_SEARCH_CLIENT_VERSION`: override the `client_version` sent to `/codex/models`.
86
- - `PI_CODEX_WEB_SEARCH_CONTEXT_SIZE`: default search context size: `low`, `medium`, or `high`.
87
- - `PI_CODEX_WEB_SEARCH_LIVE`: set to `false` to use cached web access.
218
+ Set `model` in your config file, or set `PI_CODEX_WEB_SEARCH_MODEL`, to the Codex model id you want. If unset, the extension uses the active Codex model when possible, then falls back to the default model from `/codex/models`.
88
219
 
89
- The request headers are built by the extension. They include `Authorization`, `chatgpt-account-id`, `originator: pi`, `OpenAI-Beta: responses=experimental`, `accept`, and `content-type` for streaming response requests.
220
+ ### A different extension already registers `codex_search`
221
+
222
+ Use `/codex-search-settings` to rename this extension's tool, or set `toolName` in `~/.pi/pi-codex-search.json`. Tool renames apply after the settings dialog reloads Pi.
90
223
 
91
224
  ## Development
92
225
 
@@ -107,16 +240,9 @@ This repository follows the same release shape as `pi-provider-kimi-code`:
107
240
  - `.github/workflows/release-command.yml` creates release commits and tags.
108
241
  - `.github/workflows/release-on-tag.yml` publishes to npm with provenance and attaches `pi-codex-search.tar.gz` to the GitHub release.
109
242
 
110
- GitHub release tarball installs from the extracted directory:
111
-
112
- ```bash
113
- curl -L https://github.com/Leechael/pi-codex-search/releases/latest/download/pi-codex-search.tar.gz | tar -xz -C /tmp
114
- pi install /tmp/pi-codex-search
115
- ```
116
-
117
243
  ## References
118
244
 
119
- - Upstream harness: [earendil-works/pi](https://github.com/earendil-works/pi) · [pi-coding-agent](https://github.com/earendil-works/pi/tree/main/packages/coding-agent)
245
+ - Pi: [earendil-works/pi](https://github.com/earendil-works/pi)
120
246
 
121
247
  ## License
122
248