@99percentpeople/pi-codex-api 0.1.3 → 0.2.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/README.md CHANGED
@@ -1,216 +1,130 @@
1
1
  # @99percentpeople/pi-codex-api
2
2
 
3
- Expose first-party Codex subscription APIs as native Pi tools and commands.
4
- The extension reuses Pi's existing `openai-codex` OAuth login and does not need
5
- an OpenAI API key, MCP server, or separate search provider.
6
-
7
- ## Requirements
8
-
9
- - Pi authenticated with `/login` for the `openai-codex` provider
10
- - An active `openai-codex` model, or **Other providers** enabled in `/99settings`
11
- - A ChatGPT workspace and plan entitled to the requested Codex feature
12
-
13
- The extension still loads when Codex has not been configured. It does not
14
- prompt or attempt an OAuth request during installation. A tool call instead
15
- shows an actionable error directing you to `/login`; an expired login is
16
- reported the same way after Pi's refresh attempt fails.
17
-
18
- API-key authentication is intentionally rejected because these tools target the
19
- ChatGPT subscription backend rather than metered Platform API usage.
20
-
21
- ## Install
3
+ Turn your ChatGPT subscription into Pi superpowers image generation, web
4
+ search, Fast mode, and usage monitoring **no OpenAI API key required**.
5
+
6
+ ## Highlights
7
+
8
+ - **Image generation & editing** — `codex_image` creates or edits images via
9
+ your Codex subscription's `gpt-image-2`, and works from **any model**:
10
+ even with a third-party provider active (DeepSeek, Google, …), it reuses Pi's
11
+ logged-in `openai-codex` OAuth account (enable **Other providers** in
12
+ `/99settings`).
13
+ - **First-party search** `codex_search` runs web and image queries, page
14
+ navigation, PDF screenshots, finance, weather, sports, and time lookups, and
15
+ renders clean result cards instead of raw citations.
16
+ - **Fast mode** optional priority service tier for snappier responses.
17
+ - **Usage at a glance** — the status bar shows remaining Codex quota and
18
+ reset time; `/codex-usage` shows your plan, masked account, limits, credits,
19
+ and earned rate-limit reset cards.
20
+ - **Reset cards** — when you run out of messages, `/codex-redeem` redeems an
21
+ earned reset card safely: pick a card, confirm, done.
22
+
23
+ ## Quick start
22
24
 
23
25
  ```bash
24
26
  pi install npm:@99percentpeople/pi-codex-api
25
27
  ```
26
28
 
27
- During development, build the npm artifact before installing the package
28
- directory:
29
+ Requirements:
29
30
 
30
- ```bash
31
- bun run build:packages
32
- bun run --cwd extensions/codex-api build
33
- pi install ./extensions/codex-api
34
- ```
31
+ - Pi logged in with `/login` for `openai-codex`
32
+ - An active `openai-codex` model, or **Other providers** enabled in
33
+ `/99settings` to use the subscription from any model
35
34
 
36
- ## Tools
35
+ That's it — just ask *"generate an image of a neon ramen shop"* or *"search
36
+ the web for today's Rust releases"* and the model calls the tools for you.
37
+
38
+ ## Commands
37
39
 
38
- ### `codex_image`
40
+ ### `/codex-usage`
39
41
 
40
- Generates or edits images through the Codex subscription image API using
41
- `gpt-image-2`.
42
+ Shows a fresh snapshot of your subscription in one block:
42
43
 
43
44
  ```text
44
- codex_image prompt="A quiet neon-lit ramen shop at night"
45
- ```
45
+ Codex usage
46
46
 
47
- For edits, provide up to five image paths inside the current workspace:
47
+ account · Plus (user@example.com)
48
48
 
49
- ```text
50
- codex_image \
51
- prompt="Change only the sky to a warm sunset" \
52
- referenced_image_paths=["assets/photo.png"] \
53
- output_path="assets/photo-sunset.png"
49
+ codex
50
+ weekly [█████████████░░░░░░░] 65% left resets in 5d 3h
51
+ no additional credits
52
+
53
+ rate limit redeem
54
+ Full reset (available, expires 2026-08-13 02:14 UTC+8)
54
55
  ```
55
56
 
56
- If an edit target was attached or generated in the conversation and has no
57
- usable local path, the model can instead include the smallest necessary window
58
- of one to five recent conversation images with `num_last_images_to_include`.
59
- The two reference mechanisms are mutually exclusive.
60
-
61
- The model may request a validated GPT Image 2 `WIDTHxHEIGHT` size when exact
62
- dimensions are part of the task. It normally omits `quality`, inheriting the
63
- user's **Image quality** preference, and only overrides it when the user
64
- explicitly requests a draft or a quality level.
65
-
66
- New images default to `output/codex-images/<tool-call-id>.png`. Reference and
67
- output paths must stay inside the current workspace, and existing files are
68
- never overwritten. The PNG is both saved locally and returned as image
69
- content so Codex can inspect or revise it in later turns. If a network request
70
- fails before an HTTP response, the error identifies the endpoint path and any
71
- safe transport code (for example `ECONNRESET`). The extension itself never
72
- retries image generation automatically, because the server may have accepted
73
- the first request; decide whether to retry after reviewing the error.
74
-
75
- ### `codex_search`
76
-
77
- Uses the first-party Codex standalone search API. Supported command families:
78
-
79
- - web and image queries;
80
- - open, click, and find operations using returned reference IDs;
81
- - PDF page screenshots;
82
- - finance, weather, sports, and time lookups.
83
-
84
- Search mode is configurable as Auto, Cached, Indexed, or Live. In Auto, the AI
85
- requests a per-call mode: Cached for stable facts and known references, Indexed
86
- for recent documentation and announcements, and Live for same-day or real-time
87
- information. An omitted request defaults to Indexed. Selecting a fixed mode
88
- pins every call to that mode, regardless of the AI request. External content is
89
- untrusted and should never be treated as instructions.
90
-
91
- ## Parameter ownership
92
-
93
- The extension follows the current official Codex split between task intent,
94
- user policy, and internal protocol fields:
95
-
96
- | Owner | Search | Image |
97
- | --- | --- | --- |
98
- | AI per call | queries, recency, task-specific domains, navigation/lookup commands, response length, and the requested mode when Auto is enabled | prompt, local or recent-conversation references, task-specific size, explicit quality override, destination path |
99
- | User in `/99settings` | Auto or a fixed Cached/Indexed/Live policy, plus search context size | default image quality |
100
- | Extension/backend | session/model routing, caller policy and token ceiling | fixed `gpt-image-2`, automatic background, one PNG result, reference and dimension validation |
101
-
102
- Model selection, batch count, output format, input fidelity, masks, moderation,
103
- and transparent background are intentionally not advertised as AI arguments on
104
- this subscription path. In particular, GPT Image 2 does not support native
105
- transparent-background output; requesting transparency through an unsupported
106
- field would be misleading.
107
-
108
- ## Bundled skill
109
-
110
- The package also ships the Agent Skills-standard **`gpt-image-prompts`** skill
111
- under `skills/`. Pi discovers it with the package and can load it on demand to
112
- write or refine production-ready GPT Image 2 prompts for new images,
113
- reference-guided work, and precise edits. Invoke it explicitly with:
57
+ - Plan type and masked email from Codex's official usage endpoint
58
+ - Each limit window shows remaining capacity as a bar; when exhausted it reads
59
+ `limit reached` instead of `0% left`
60
+ - Earned reset cards, sorted by expiry, with local-time expiry timestamps
61
+ - The status bar mirrors this compactly: `Codex weekly 65% 5d 3h` →
62
+ `Codex weekly limit reached 5d 14h`
114
63
 
115
- ```text
116
- /skill:gpt-image-prompts
117
- ```
64
+ Usage refreshes automatically on session start and model select;
65
+ `/codex-usage` always forces a fresh read.
118
66
 
119
- The skill contains visual prompt-writing guidance only. It does not select or
120
- document tools, construct API requests, manage credentials, or prescribe file
121
- and execution workflows.
122
-
123
- ## Tool display
124
-
125
- Web and image queries render normalized source cards instead of the backend's
126
- raw citation dump. The collapsed view shows three title/domain/snippet cards;
127
- Pi's configured tool-output expansion shortcut (`Ctrl+O` by default) expands
128
- every source with its full URL. Internal reference markers,
129
- word-limit metadata, and separators are hidden. Open/click/find/PDF operations
130
- use cleaned document cards. Batched navigation renders each returned page as a
131
- separate numbered card with a short per-page preview, one shared expansion hint,
132
- and visible warning styling for unresolved references. Weather, finance,
133
- sports, and time lookups use a compact data view. This changes only the TUI display copy: the model
134
- still receives the complete original search output.
135
-
136
- Search and image parameters stream into the call row while the model constructs
137
- them; input parameters are never repeated in the result area. Both tools also
138
- stream real execution stages into the active result row while they run
139
- (authentication, request, reference loading, generation, and saving as
140
- applicable). Successful `codex_search` and `codex_image` calls also request a
141
- rate-limited background usage refresh. The Codex search and image endpoints
142
- return one final response, so result bodies appear atomically rather than as
143
- fabricated content chunks.
67
+ ### `/codex-redeem`
144
68
 
145
- ## Commands
69
+ Redeems an earned rate-limit reset card when you're out of messages:
146
70
 
147
71
  ```text
148
- /codex-usage
72
+ ──────────────────────────────────────────────
73
+ Select a reset credit to redeem (30s)
74
+
75
+ → Full reset (expires 2026-08-03)
76
+ Full reset (expires 2026-08-12)
77
+
78
+ ↑↓ navigate ↵ select esc cancel
79
+ ──────────────────────────────────────────────
80
+ ↓ pick a card
81
+ ──────────────────────────────────────────────
82
+ Redeem Full reset (expires 2026-08-12)? (30s)
83
+
84
+ → No
85
+ Yes
86
+
87
+ ↑↓ navigate ↵ select esc cancel
88
+ ──────────────────────────────────────────────
149
89
  ```
150
90
 
151
- Fast mode is controlled only through **Codex API Fast mode** in
152
- `/99settings`. It sends `service_tier: "priority"` on Codex Responses requests
153
- and can reduce latency while consuming included limits faster. The extension fetches
154
- subscription usage directly from Codex's official ChatGPT WHAM endpoint when a
155
- session starts or a Codex model is selected; `/codex-usage` forces a fresh
156
- read, so no model request is required first. Automatic post-response refreshes
157
- are limited to once per minute.
158
-
159
- Pi does not currently publish an OAuth-account-change event or expose its
160
- credential store to extensions. As a temporary compatibility layer, this
161
- extension watches Pi's agent-directory `auth.json`. A short debounce reloads
162
- the public model registry and compares the resolved Codex Account ID. After
163
- `/login` replaces the account, the old snapshot is removed, the status changes
164
- to `Codex syncing…`, and a forced account-scoped refresh starts. `/logout`
165
- clears the status. In-flight requests are revision-guarded, so an old account
166
- cannot overwrite the newly active account. The watcher is closed on session
167
- teardown and never accesses Pi's private authentication runtime.
168
-
169
- `/codex-usage` groups every metered limit under a simple `Codex usage` heading.
170
- Each server-provided window (for example 5h, daily, or weekly) uses a fixed
171
- 20-cell bar whose filled portion represents remaining capacity, followed only
172
- by `% left` and its reset time. Additional credit availability stays under the
173
- same limit group. Inactive zero-value placeholder windows are hidden. Response
174
- headers remain supported as a fallback.
91
+ - Multiple cards show a picker (earliest expiry first); a single card skips to
92
+ confirmation
93
+ - **No is the default**, so a stray Enter never consumes anything
94
+ - Redemptions are idempotent: a retry after a network failure can never consume
95
+ a second card
96
+ - Without dialog UI, it falls back to a two-step confirm flow
175
97
 
176
98
  ## Settings
177
99
 
178
- Use the shared menu:
100
+ Configure under **Codex API** in `/99settings`:
179
101
 
180
- ```text
181
- /99settings
182
- ```
102
+ - **Other providers** — let any model (DeepSeek, Google, …) use the logged-in
103
+ Codex subscription
104
+ - **Fast mode** — priority service tier (lower latency, faster limit use)
105
+ - **Search** — auto routing (Cached / Indexed / Live per call) or a fixed mode,
106
+ plus context size
107
+ - **Image quality** — default GPT Image 2 quality
108
+ - **Usage status** — show or hide the Codex quota line in the status bar
183
109
 
184
- The **Codex API** section controls:
110
+ Settings live in `~/.pi/agent/99extensions.json` under the `codex-api`
111
+ namespace.
185
112
 
186
- - **Other providers** — off by default. When enabled, a non-Codex model may
187
- call `codex_image` and `codex_search`; the extension resolves only the
188
- separately logged-in `openai-codex` OAuth account. It never sends the active
189
- model provider's credentials to ChatGPT.
190
- - **Fast mode** — enables or disables the priority service tier;
191
- - Auto search routing, or a fixed Cached, Indexed, or Live policy;
192
- - search context size;
193
- - default GPT Image 2 quality (`Auto`, `Low`, `Medium`, or `High`);
194
- - subscription usage status visibility.
113
+ ## How it works
195
114
 
196
- Configuration is stored under the `codex-api` namespace in:
115
+ - Reuses Pi's existing `openai-codex` OAuth — no API key, no MCP server, no
116
+ separate search provider
117
+ - Tokens are fetched per call from Pi's model registry, never stored in
118
+ settings or tool results
119
+ - Images and search requests go to OpenAI's Codex backend and follow your
120
+ ChatGPT workspace's policies
121
+ - The extension also ships the **`gpt-image-prompts`** skill for crafting
122
+ production-grade image prompts — invoke it with `/skill:gpt-image-prompts`
197
123
 
198
- ```text
199
- ~/.pi/agent/99extensions.json
200
- ```
124
+ ## Development
201
125
 
202
- ## Authentication and privacy
203
-
204
- The extension asks Pi's model registry for a refreshed OAuth token at tool-call
205
- time. It sends the same bearer token and `ChatGPT-Account-ID` used by Pi's
206
- `openai-codex` adapter. With **Other providers** enabled, it resolves that
207
- Codex model specifically rather than using the active model's credentials.
208
- Tokens are never copied into extension settings or tool results. The extracted
209
- ChatGPT account ID is used only as an in-memory Usage-state key and is never
210
- persisted or displayed. The watcher reacts only to the `auth.json` filename;
211
- credential parsing and resolution remain inside Pi's public model registry.
212
-
213
- Image prompts, reference images, search commands, and search context are sent
214
- to OpenAI's Codex backend and are subject to the active ChatGPT workspace's
215
- policies. Feature availability and request formats may change as Codex rolls
216
- out backend updates.
126
+ ```bash
127
+ bun run build:packages
128
+ bun run --cwd extensions/codex-api build
129
+ pi install ./extensions/codex-api
130
+ ```