pi-codex-search 0.1.1 → 0.1.3
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 +198 -50
- package/index.ts +922 -93
- package/package.json +10 -4
- package/scripts/codex-e2e.ts +797 -0
- package/src/codex.ts +90 -352
- package/src/command.ts +564 -0
- package/src/config.ts +287 -0
- package/src/cookies.ts +131 -0
- package/src/errors.ts +56 -0
- package/src/modes/responses.ts +310 -0
- package/src/modes/standalone.ts +378 -0
- package/src/modes/types.ts +41 -0
- package/src/ref-store.ts +74 -0
- package/src/transport.ts +110 -0
- package/src/ua.ts +67 -0
package/README.md
CHANGED
|
@@ -3,90 +3,245 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/pi-codex-search)
|
|
4
4
|
[](./LICENSE)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
**Search the web in Pi through your Codex subscription.**
|
|
7
7
|
|
|
8
|
-
|
|
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. An optional `codex_standalone_web` tool exposes Codex's experimental webpage actions.
|
|
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 in Responses mode.** One `codex_search` call can run related queries together.
|
|
22
|
+
- **Inspect webpages when explicitly enabled.** `codex_standalone_web` sends one standalone action per tool call because `/alpha/search` rejects multi-action batching.
|
|
23
|
+
- **Keep projects in control.** Change defaults, enable the standalone tool, or disable the extension per project.
|
|
24
|
+
|
|
25
|
+
## What this package adds
|
|
26
|
+
|
|
27
|
+
- A `codex_search` Pi tool using the Responses API.
|
|
28
|
+
- 1–32 search queries per `codex_search` call, controlled by `batchSize`.
|
|
29
|
+
- Optional `codex_standalone_web` using experimental `/alpha/search` with open, find, click, screenshot, finance, weather, sports, and time commands. It accepts exactly one action per tool call.
|
|
30
|
+
- `live`, `indexed`, or `cached` freshness, plus `low` / `medium` / `high` search context size. Standalone mode disables `low` because Codex returns Cloudflare challenges for low-context standalone requests.
|
|
31
|
+
- Streaming progress while Codex responds.
|
|
32
|
+
- Collapsed result previews in the TUI, with full text and sources available when expanded.
|
|
33
|
+
- Structured details: model, citations, search calls, response ids, usage, and per-query failures.
|
|
34
|
+
- Config files for home and project defaults.
|
|
35
|
+
- `/codex-search-settings` for status, editing, reset, standalone enablement, and disable.
|
|
9
36
|
|
|
10
37
|
## Install
|
|
11
38
|
|
|
12
|
-
|
|
39
|
+
From npm:
|
|
13
40
|
|
|
14
41
|
```bash
|
|
15
|
-
pi
|
|
42
|
+
pi install npm:pi-codex-search
|
|
16
43
|
```
|
|
17
44
|
|
|
18
|
-
|
|
45
|
+
Or load a local checkout without installing:
|
|
19
46
|
|
|
20
47
|
```bash
|
|
21
|
-
pi
|
|
48
|
+
pi -e /path/to/pi-codex-search
|
|
22
49
|
```
|
|
23
50
|
|
|
24
|
-
|
|
51
|
+
### Install from GitHub Release tarball
|
|
25
52
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
53
|
+
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:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
curl -L https://github.com/Leechael/pi-codex-search/releases/latest/download/pi-codex-search.tar.gz | tar -xz -C /tmp
|
|
57
|
+
pi install /tmp/pi-codex-search
|
|
32
58
|
```
|
|
33
59
|
|
|
34
|
-
##
|
|
60
|
+
## Sign in
|
|
35
61
|
|
|
36
|
-
Inside
|
|
62
|
+
Inside Pi, run:
|
|
37
63
|
|
|
38
64
|
```text
|
|
39
65
|
/login openai-codex
|
|
40
66
|
```
|
|
41
67
|
|
|
42
|
-
Choose `ChatGPT Plus/Pro (Codex Subscription)` if
|
|
68
|
+
Choose `ChatGPT Plus/Pro (Codex Subscription)` if Pi asks which provider to use. Pi stores and refreshes the credential.
|
|
69
|
+
|
|
70
|
+
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`.
|
|
71
|
+
|
|
72
|
+
Set `enabled: false` if you want the extension installed but hidden for a project.
|
|
73
|
+
|
|
74
|
+
## Tool
|
|
43
75
|
|
|
44
|
-
|
|
76
|
+
Default tools:
|
|
45
77
|
|
|
46
|
-
|
|
78
|
+
```text
|
|
79
|
+
codex_search
|
|
80
|
+
codex_standalone_web
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`codex_search` is always registered when the extension is enabled. `codex_standalone_web` is optional and off by default.
|
|
47
84
|
|
|
48
|
-
|
|
85
|
+
Example call:
|
|
49
86
|
|
|
50
87
|
```json
|
|
51
88
|
{
|
|
52
|
-
"name": "
|
|
89
|
+
"name": "codex_search",
|
|
53
90
|
"arguments": {
|
|
54
|
-
"
|
|
91
|
+
"queries": ["latest OpenAI Codex release notes"],
|
|
55
92
|
"search_context_size": "medium",
|
|
56
|
-
"
|
|
93
|
+
"freshness": "live"
|
|
57
94
|
}
|
|
58
95
|
}
|
|
59
96
|
```
|
|
60
97
|
|
|
61
|
-
|
|
98
|
+
Arguments for `codex_search`:
|
|
62
99
|
|
|
63
|
-
- `
|
|
64
|
-
- `search_context_size
|
|
65
|
-
- `
|
|
100
|
+
- `queries` — required array of search questions. Queries run in parallel and results are grouped by query. The default max is 5 and the hard max is 32.
|
|
101
|
+
- `search_context_size` — optional, one of `low`, `medium`, `high`; defaults to `medium`.
|
|
102
|
+
- `freshness` — optional, `live`, `indexed`, or `cached`; defaults to `live`.
|
|
66
103
|
|
|
67
|
-
|
|
104
|
+
Arguments for optional `codex_standalone_web`:
|
|
68
105
|
|
|
69
|
-
-
|
|
70
|
-
-
|
|
71
|
-
-
|
|
106
|
+
- `urls` — one page to open/fetch directly.
|
|
107
|
+
- `find` — one `{ "url", "pattern" }` object for in-page text search after opening the URL.
|
|
108
|
+
- `click` — one `{ "url", "id" }` object for following a link id from an opened page.
|
|
109
|
+
- `screenshot` — one `{ "url", "pageno" }` object for page screenshots after opening the URL.
|
|
110
|
+
- `finance`, `weather`, `sports`, `time` — one Codex web lookup command.
|
|
72
111
|
|
|
73
|
-
|
|
112
|
+
Standalone uses `medium` or `high` search context only. If standalone is enabled while the saved context is `low`, settings normalize it to `medium`.
|
|
113
|
+
|
|
114
|
+
The tool returns text. When citations are available, the text includes a `Sources:` section.
|
|
115
|
+
|
|
116
|
+
The structured `details` object includes:
|
|
74
117
|
|
|
75
118
|
- `model`
|
|
76
|
-
- `
|
|
77
|
-
- `
|
|
78
|
-
- `
|
|
79
|
-
- `usage`
|
|
119
|
+
- `api`
|
|
120
|
+
- `freshness` / `searchContextSize`
|
|
121
|
+
- `queryCount` / `failedQueryCount`
|
|
122
|
+
- `successes`: per-query `{ query, text, citations, searchCalls, responseId?, usage? }`
|
|
123
|
+
- `failures`: per-query `{ query, kind, message }`
|
|
124
|
+
|
|
125
|
+
Failure `kind` is one of `auth`, `rate_limit`, `transport`, `timeout`, `schema`, or `unknown`.
|
|
126
|
+
|
|
127
|
+
## Model used for search
|
|
128
|
+
|
|
129
|
+
The search request needs a Codex model id. The extension chooses it in this order:
|
|
130
|
+
|
|
131
|
+
1. `model` from env / project / home config, if set.
|
|
132
|
+
2. The active Pi model, if it comes from the `openai-codex` provider.
|
|
133
|
+
3. The default model from Codex's `/codex/models` response.
|
|
134
|
+
|
|
135
|
+
Most users do not need to set this.
|
|
136
|
+
|
|
137
|
+
## Settings
|
|
138
|
+
|
|
139
|
+
Most users only need `/login openai-codex`. Use settings when you want to enable `codex_standalone_web`, disable the extension for a project, pin a model, or change defaults.
|
|
140
|
+
|
|
141
|
+
Open the interactive settings dialog:
|
|
142
|
+
|
|
143
|
+
```text
|
|
144
|
+
/codex-search-settings
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Useful subcommands:
|
|
148
|
+
|
|
149
|
+
```text
|
|
150
|
+
/codex-search-settings status
|
|
151
|
+
/codex-search-settings reset
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Settings are merged from three layers, highest precedence first:
|
|
155
|
+
|
|
156
|
+
1. Environment variables.
|
|
157
|
+
2. Project file: `<cwd>/.pi/pi-codex-search.json`.
|
|
158
|
+
3. Home file: `~/.pi/pi-codex-search.json`.
|
|
80
159
|
|
|
81
|
-
|
|
160
|
+
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.
|
|
82
161
|
|
|
83
|
-
|
|
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.
|
|
162
|
+
Because the project file lives under `<cwd>/.pi/`, it follows Pi's project trust rules. If you decline to trust a project, the extension reads only the home file and environment variables; the project scope is hidden in the settings dialog and cannot be saved or deleted until the project is trusted.
|
|
88
163
|
|
|
89
|
-
|
|
164
|
+
Full schema, all fields optional:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"enabled": true,
|
|
169
|
+
"standaloneEnabled": false,
|
|
170
|
+
"model": "gpt-5-codex",
|
|
171
|
+
"baseUrl": "https://chatgpt.com/backend-api",
|
|
172
|
+
"clientVersion": "1.0.0",
|
|
173
|
+
"searchContextSize": "medium",
|
|
174
|
+
"freshness": "live",
|
|
175
|
+
"batchSize": 5
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`enabled: false` skips tool registration entirely. The model will not see `codex_search` or `codex_standalone_web`.
|
|
180
|
+
|
|
181
|
+
`standaloneEnabled: true` registers `codex_standalone_web`. It posts web commands to `/codex/alpha/search` on `chatgpt.com/backend-api` or `/v1/alpha/search` for `api.openai.com/v1`-style bases, accepts one action per tool call, stores returned ref ids for follow-up open/find/click/screenshot actions, disables `low` search context, and may be blocked by Cloudflare or backend session limits. Use `codex_search` for web search queries.
|
|
182
|
+
|
|
183
|
+
`searchApi: "standalone"` from older configs is treated as `standaloneEnabled: true` for compatibility.
|
|
184
|
+
|
|
185
|
+
Environment variable equivalents:
|
|
186
|
+
|
|
187
|
+
| Field | Env var |
|
|
188
|
+
| ------------------- | ------------------------------------ |
|
|
189
|
+
| `enabled` | `PI_CODEX_WEB_SEARCH_ENABLED` |
|
|
190
|
+
| `standaloneEnabled` | `PI_CODEX_WEB_STANDALONE_ENABLED` |
|
|
191
|
+
| `model` | `PI_CODEX_WEB_SEARCH_MODEL` |
|
|
192
|
+
| `baseUrl` | `PI_CODEX_WEB_SEARCH_BASE_URL` |
|
|
193
|
+
| `clientVersion` | `PI_CODEX_WEB_SEARCH_CLIENT_VERSION` |
|
|
194
|
+
| `searchContextSize` | `PI_CODEX_WEB_SEARCH_CONTEXT_SIZE` |
|
|
195
|
+
| `freshness` | `PI_CODEX_WEB_SEARCH_FRESHNESS` |
|
|
196
|
+
| `batchSize` | `PI_CODEX_WEB_SEARCH_BATCH_SIZE` |
|
|
197
|
+
|
|
198
|
+
`PI_CODEX_WEB_SEARCH_ENABLED` accepts `true` / `false` (case-insensitive). Any other value fails config loading.
|
|
199
|
+
|
|
200
|
+
The settings dialog shows a unified `SettingsList` view. The model picker loads available Codex models asynchronously after the dialog opens, so the UI appears immediately even when `/codex/models` is slow. Interactive edits write the selected config file immediately. When you close the dialog, Pi reloads so the tool set and defaults apply without restarting the whole terminal.
|
|
201
|
+
|
|
202
|
+
## Notes
|
|
203
|
+
|
|
204
|
+
### Codex search vs model search
|
|
205
|
+
|
|
206
|
+
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.
|
|
207
|
+
|
|
208
|
+
### Account id
|
|
209
|
+
|
|
210
|
+
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.
|
|
211
|
+
|
|
212
|
+
## Troubleshooting
|
|
213
|
+
|
|
214
|
+
### `codex_search` fails with an `auth` error
|
|
215
|
+
|
|
216
|
+
Run:
|
|
217
|
+
|
|
218
|
+
```text
|
|
219
|
+
/login openai-codex
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
If Pi asks for a provider, choose `ChatGPT Plus/Pro (Codex Subscription)`. The extension picks up the refreshed credential on the next call.
|
|
223
|
+
|
|
224
|
+
### `codex_search` says the account id was not found
|
|
225
|
+
|
|
226
|
+
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.
|
|
227
|
+
|
|
228
|
+
### The model does not see `codex_search`
|
|
229
|
+
|
|
230
|
+
Check whether `enabled` is false in env, project config, or home config:
|
|
231
|
+
|
|
232
|
+
```text
|
|
233
|
+
/codex-search-settings status
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Remember that env overrides project, and project overrides home.
|
|
237
|
+
|
|
238
|
+
### Search uses the wrong model
|
|
239
|
+
|
|
240
|
+
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`.
|
|
241
|
+
|
|
242
|
+
### A different extension already registers `codex_search`
|
|
243
|
+
|
|
244
|
+
The tool names are fixed as `codex_search` and `codex_standalone_web`. Disable conflicting extensions or tools with the same names.
|
|
90
245
|
|
|
91
246
|
## Development
|
|
92
247
|
|
|
@@ -107,16 +262,9 @@ This repository follows the same release shape as `pi-provider-kimi-code`:
|
|
|
107
262
|
- `.github/workflows/release-command.yml` creates release commits and tags.
|
|
108
263
|
- `.github/workflows/release-on-tag.yml` publishes to npm with provenance and attaches `pi-codex-search.tar.gz` to the GitHub release.
|
|
109
264
|
|
|
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
265
|
## References
|
|
118
266
|
|
|
119
|
-
-
|
|
267
|
+
- Pi: [earendil-works/pi](https://github.com/earendil-works/pi)
|
|
120
268
|
|
|
121
269
|
## License
|
|
122
270
|
|