@loongphy/codex-auth 0.2.0 → 0.2.2-alpha.1

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.
Files changed (2) hide show
  1. package/README.md +91 -3
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -67,6 +67,7 @@ codex-auth list # list all accounts
67
67
  codex-auth login # run `codex login`, then add the current account
68
68
  codex-auth switch [<email>] # switch active account (interactive or partial/fragment match)
69
69
  codex-auth import <path> [--alias <alias>] # smart import: file -> single import, folder -> batch import
70
+ codex-auth import --cpa [<path>] # import CPA flat token JSON from one file or directory
70
71
  codex-auth import --purge [<path>] # rebuild registry.json from auth files for the current version
71
72
  codex-auth remove # remove accounts (interactive multi-select)
72
73
  codex-auth status # show auto-switch/service/api usage status
@@ -103,6 +104,26 @@ Batch import from a folder:
103
104
  codex-auth import /path/to/auth-exports
104
105
  ```
105
106
 
107
+ Import CPA exports directly:
108
+
109
+ ```shell
110
+ codex-auth import --cpa # scan ~/.cli-proxy-api/*.json
111
+ codex-auth import --cpa /path/to/cpa-dir
112
+ codex-auth import --cpa /path/to/cpa.json --alias personal
113
+ ```
114
+
115
+ Typical batch import output:
116
+
117
+ ```text
118
+ Scanning /path/to/auth-exports...
119
+ ✓ imported token_ryan.taylor.alpha@email.com
120
+ ✓ updated token_jane.smith.alpha@email.com
121
+ ✗ skipped token_invalid: MalformedJson
122
+ Import Summary: 1 imported, 1 updated, 1 skipped (total 3 files)
123
+ ```
124
+
125
+ `stdout` carries scanning/success/summary lines. Skipped files and warnings stay on `stderr`.
126
+
106
127
  Rebuild `registry.json` from imported auth files:
107
128
 
108
129
  ```shell
@@ -177,15 +198,82 @@ Changing thresholds updates `registry.json`; Linux/WSL and Windows pick them up
177
198
  Changing `config api` updates `registry.json` immediately; `api enable` means API-only and `api disable` means local-sessions-only.
178
199
  `codex-auth help` also shows whether auto-switching and usage API calls are currently enabled.
179
200
 
201
+ ## Q&A
202
+
203
+ ### Why is my usage limit not refreshing?
204
+
205
+ If `codex-auth` is using local-only usage refresh, it reads the newest `~/.codex/sessions/**/rollout-*.jsonl` file. Recent Codex builds often write `token_count` events with `rate_limits: null`. The local files may still contain older usable usage limit data, but in practice they can lag by several hours, so local-only refresh may show a usage limit snapshot from hours ago instead of your latest state.
206
+
207
+ - Upstream Codex issue: [openai/codex#14880](https://github.com/openai/codex/issues/14880)
208
+
209
+ You can switch usage limit refresh to the usage API with:
210
+
211
+ ```shell
212
+ codex-auth config api enable
213
+ ```
214
+
215
+ Then confirm the current mode with:
216
+
217
+ ```shell
218
+ codex-auth status
219
+ ```
220
+
221
+ `status` should show `usage: api`.
222
+
223
+ Upgrade notes:
224
+
225
+ - If you are upgrading from `v0.1.x` to the latest `v0.2.x`, API usage refresh is enabled by default.
226
+ - If you previously used an early `v0.2` prerelease/test build and `status` still shows `usage: local`, run `codex-auth config api enable` once to switch to API mode.
227
+
228
+ ### How to import tokens from cli-proxy-api?
229
+
230
+ If you have token files from `~/.cli-proxy-api/token*.json`, this repository includes a helper script that can convert them into a format codex-auth can read.
231
+
232
+ The CLI can also import the flat cli-proxy-api / CPA JSON files directly:
233
+
234
+ ```shell
235
+ codex-auth import --cpa # default source: ~/.cli-proxy-api
236
+ codex-auth import --cpa /path/to/cpa-dir # scans direct child .json files
237
+ ```
238
+
239
+ Each CPA file is converted in memory to the standard auth snapshot shape before it is written into `~/.codex/accounts/`. Missing or empty `refresh_token` values are skipped as `MissingRefreshToken`.
240
+
241
+ The script is not bundled in the published npm package, so run it from a clone of this repository:
242
+
243
+ ```shell
244
+ # Convert: ~/.cli-proxy-api → /tmp/tokens
245
+ python3 scripts/convert_tokens.sh
246
+
247
+ # Or specify custom directories
248
+ python3 scripts/convert_tokens.sh <source_dir> <output_dir>
249
+ ```
250
+
251
+ Then import and switch:
252
+
253
+ ```shell
254
+ codex-auth import /tmp/tokens/
255
+ # or import the CPA files directly without a conversion step
256
+ codex-auth import --cpa
257
+ codex-auth switch
258
+ ```
259
+
260
+ Verify with:
261
+
262
+ ```shell
263
+ codex exec "say hello"
264
+ ```
265
+
266
+ > **Output format:** Each converted file contains `auth_mode`, `OPENAI_API_KEY`, `tokens` (with `id_token`, `access_token`, `refresh_token`, `account_id`), and `last_refresh`. The `refresh_token` field is required for token refresh to work.
267
+
180
268
  ## Disclaimer
181
269
 
182
270
  This project is provided as-is and use is at your own risk.
183
271
 
184
272
  **Usage Data Refresh Source:**
185
- `codex-auth` supports two sources for refreshing account usage/quota information:
273
+ `codex-auth` supports two sources for refreshing account usage/usage limit information:
186
274
 
187
- 1. **Local (default):** Scans local `~/.codex/sessions/*/rollout-*.jsonl` files. This mode is strictly local.
188
- 2. **API:** When `config api enable` is on, the tool will make direct HTTPS requests to OpenAI's endpoints using your account's access token.
275
+ 1. **API (default):** When `config api enable` is on, the tool makes direct HTTPS requests to OpenAI's endpoints using your account's access token. This is the current default mode.
276
+ 2. **Local-only:** When `config api disable` is on, the tool scans local `~/.codex/sessions/*/rollout-*.jsonl` files without making API calls. This mode is safer, but it can be less accurate because recent Codex rollout files often contain `rate_limits: null`, so the latest local usage limit data may lag by several hours.
189
277
 
190
278
  **API Call Declaration:**
191
279
  By enabling API-based usage refresh, this tool will send your ChatGPT access token to OpenAI's servers (specifically `https://chatgpt.com/backend-api/wham/usage`) to fetch current quota information. This behavior may be detected by OpenAI and could violate their terms of service, potentially leading to account suspension or other risks. The decision to use this feature and any resulting consequences are entirely yours.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loongphy/codex-auth",
3
- "version": "0.2.0",
3
+ "version": "0.2.2-alpha.1",
4
4
  "description": "CLI for switching Codex accounts",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -20,10 +20,10 @@
20
20
  "README.md"
21
21
  ],
22
22
  "optionalDependencies": {
23
- "@loongphy/codex-auth-linux-x64": "0.2.0",
24
- "@loongphy/codex-auth-darwin-x64": "0.2.0",
25
- "@loongphy/codex-auth-darwin-arm64": "0.2.0",
26
- "@loongphy/codex-auth-win32-x64": "0.2.0"
23
+ "@loongphy/codex-auth-linux-x64": "0.2.2-alpha.1",
24
+ "@loongphy/codex-auth-darwin-x64": "0.2.2-alpha.1",
25
+ "@loongphy/codex-auth-darwin-arm64": "0.2.2-alpha.1",
26
+ "@loongphy/codex-auth-win32-x64": "0.2.2-alpha.1"
27
27
  },
28
28
  "scripts": {
29
29
  "check:versions": "node scripts/npm/check-versions.mjs",