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 +176 -50
- package/index.ts +353 -104
- package/package.json +3 -2
- package/src/codex.ts +50 -6
- package/src/command.ts +343 -0
- package/src/config.ts +214 -0
package/README.md
CHANGED
|
@@ -3,90 +3,223 @@
|
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
"
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
/
|
|
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
|
-
|
|
138
|
+
Settings are merged from three layers, highest precedence first:
|
|
43
139
|
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
146
|
+
Full schema, all fields optional:
|
|
49
147
|
|
|
50
148
|
```json
|
|
51
149
|
{
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
160
|
+
`enabled: false` skips tool registration entirely. The model will not see `codex_search` at all.
|
|
62
161
|
|
|
63
|
-
|
|
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
|
-
|
|
164
|
+
Environment variable equivalents:
|
|
68
165
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
176
|
+
`PI_CODEX_WEB_SEARCH_ENABLED` accepts `true` / `false` (case-insensitive). Any other value fails config loading.
|
|
74
177
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
-
|
|
245
|
+
- Pi: [earendil-works/pi](https://github.com/earendil-works/pi)
|
|
120
246
|
|
|
121
247
|
## License
|
|
122
248
|
|