Skip to content

Commit b7181b2

Browse files
committed
Add auth split and App-controlled Fast lifecycle
1 parent 2a3532d commit b7181b2

17 files changed

Lines changed: 5216 additions & 259 deletions

File tree

.codex-plugin/plugin.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "codex-fast-proxy",
33
"version": "0.1.0",
4-
"description": "Codex App Fast/Priority proxy for third-party OpenAI-compatible Responses API providers.",
4+
"description": "Codex App proxy for third-party OpenAI-compatible Responses API providers with Fast/Priority controls.",
55
"author": {
66
"name": "gaoguobin",
77
"url": "https://github.com/gaoguobin"
@@ -24,8 +24,8 @@
2424
"skills": "./skills/",
2525
"interface": {
2626
"displayName": "Codex Fast Proxy",
27-
"shortDescription": "Fast/Priority proxy for Codex App with third-party APIs.",
28-
"longDescription": "Manage a local, safety-bounded proxy and Agent Skill so Codex App users on third-party OpenAI-compatible API providers can enable, verify, benchmark, update, and uninstall the Fast/Priority path.",
27+
"shortDescription": "Third-party API proxy for Codex App with Fast/Priority controls.",
28+
"longDescription": "Manage a local, safety-bounded proxy and Agent Skill so Codex App users on third-party OpenAI-compatible API providers can preserve the App Fast toggle, optionally force global Fast/Priority, split upstream auth for ChatGPT login, verify traffic, benchmark, update, and uninstall.",
2929
"developerName": "gaoguobin",
3030
"category": "Developer Tools",
3131
"capabilities": [

.codex/INSTALL.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,44 @@ Do not claim the skill is available before the restart.
7575
After restarting Codex App or opening a new CLI process, the user can ask:
7676

7777
- `启用 Codex Fast proxy`
78-
- `让 Codex App 使用 Fast`
78+
- `启用 Codex Fast proxy 的 ChatGPT 登录兼容模式`
79+
- `全局开启 Codex Fast proxy 的 Fast 注入`
7980
- `查看 Codex Fast proxy 状态`
8081
- `停止 Codex Fast proxy`
8182

83+
Default enable uses `--service-tier-policy auto`. In ChatGPT-login or unclear states this respects
84+
Codex App/CLI Fast UI choices; in API-key mode it may inject the priority tier when Codex omits
85+
`service_tier`, because the App Fast UI may not be available. Use
86+
`--service-tier-policy inject_missing` only when the user explicitly asks for global Fast injection,
87+
and `--service-tier-policy preserve` only when they explicitly want no proxy-side Fast injection. If
88+
the user wants ChatGPT login compatibility for plugins/GitHub/Apps/connectors while model requests
89+
still use a third-party provider, configure an upstream key environment variable with
90+
`--upstream-api-key-env <ENV_NAME>`; do not ask the user to paste API keys into chat and do not edit
91+
`auth.json` unless they explicitly request recovery. This auth override applies only to provider API
92+
requests that already go through the local proxy; it must not intercept or modify ChatGPT
93+
plugin/GitHub/App connector traffic. In override mode, the proxy replaces provider `Authorization`
94+
and drops unexpected `Cookie` headers before forwarding upstream.
95+
96+
If Codex currently works through a third-party provider and the user wants to prepare for ChatGPT
97+
login, run `python -m codex_fast_proxy prepare-chatgpt-login` first as a dry run. Report the
98+
non-secret JSON fields, then ask before running `python -m codex_fast_proxy prepare-chatgpt-login
99+
--target-env <ENV_NAME> --apply`. The apply step writes the provider key through the Windows user
100+
environment API, does not print the key, does not change proxy settings, and does not edit
101+
`auth.json`. After apply, run `python -m codex_fast_proxy set-upstream --upstream-api-key-env
102+
<ENV_NAME>` so the manager verifies `POST /v1/responses` with `stream=true` before saving the auth
103+
split. Tell the user to restart Codex App or open a new CLI process after any user environment
104+
variable change.
105+
106+
Before first enable or model-path setting changes, `install --start` verifies the candidate upstream
107+
and auth source by sending one Codex-style `POST /v1/responses` request with `stream=true`. This is
108+
real provider traffic and can consume a small amount of quota. If verification fails, do not retry
109+
with `--no-verify` unless the user explicitly accepts that the next Codex session may be unable to
110+
reach the model.
111+
112+
Enable also writes the Codex hook feature flags and a trusted hook state entry. Treat
113+
`startup_hook: true` as installed, enabled, and trusted; if `startup_hook_trust` reports `modified`
114+
or `untrusted`, rerun enable/update instead of assuming `~/.codex/hooks.json` is enough.
115+
82116
## Existing install
83117

84118
If the repository already exists, fetch and follow:

.codex/SET_UPSTREAM.md

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Do not edit the active provider `base_url` in `~/.codex/config.toml` directly wh
77
enabled. That field should keep pointing to the local proxy. API keys, model, reasoning, and other
88
Codex settings can still be edited in `config.toml` as usual.
99

10-
If the user did not provide the new upstream URL, ask for it. Do not guess provider URLs.
10+
If the user only wants to change Fast policy or ChatGPT-login upstream auth, a new upstream URL is
11+
not required. If they want to change provider URL and did not provide the new upstream URL, ask for
12+
it. Do not guess provider URLs.
1113

1214
If the Codex environment uses sandbox or approval controls, request approval/escalation because this
1315
flow may write under `%USERPROFILE%\.codex`, edit `%USERPROFILE%\.codex\hooks.json`, restart the
@@ -28,12 +30,98 @@ $resultJson
2830
python -m codex_fast_proxy status
2931
```
3032

33+
`set-upstream` verifies the candidate route before writing settings by sending one side-path
34+
Codex-style `POST /v1/responses` request with `stream=true` to the candidate upstream and auth
35+
source. This is real provider traffic and can consume a small amount of quota. If verification
36+
fails, do not retry with `--no-verify` unless the user explicitly accepts that the next Codex session
37+
may be unable to reach the model.
38+
39+
If the user asks to verify first without changing local state, run:
40+
41+
```powershell
42+
python -m codex_fast_proxy verify-upstream --upstream-base '<UPSTREAM_BASE_URL>'
43+
```
44+
45+
Report the JSON result and stop. `verify-upstream` must not write settings, edit Codex config,
46+
install hooks, or restart the proxy.
47+
48+
For ChatGPT login compatibility without changing the upstream URL, ask for the environment variable
49+
name that already contains the third-party provider API key. Do not ask the user to paste the key
50+
value into chat. This affects only provider API requests that already go through the local proxy; it
51+
must not intercept ChatGPT plugin/GitHub/App connector traffic. In override mode, the proxy replaces
52+
provider `Authorization` and drops unexpected `Cookie` headers before forwarding upstream.
53+
54+
If the user does not already have a provider key environment variable, run a dry run first:
55+
56+
```powershell
57+
python -m codex_fast_proxy prepare-chatgpt-login
58+
```
59+
60+
Report only the non-secret JSON fields. If the dry run found the current working provider key in
61+
`auth.json` or the environment, ask before applying:
62+
63+
```powershell
64+
python -m codex_fast_proxy prepare-chatgpt-login --target-env '<ENV_NAME>' --apply
65+
```
66+
67+
The apply step writes a Windows user environment variable through the manager, does not print the
68+
key, and does not change proxy settings. After it succeeds, continue with `set-upstream` so the
69+
manager verifies a streaming `/v1/responses` request before saving the auth override.
70+
71+
```powershell
72+
$statusJson = python -m codex_fast_proxy status
73+
$status = $statusJson | ConvertFrom-Json
74+
if ($status.config_matches -ne $true) {
75+
$statusJson
76+
throw 'Codex config no longer points to the recorded local proxy. Review ~/.codex/config.toml before changing upstream auth.'
77+
}
78+
79+
$resultJson = python -m codex_fast_proxy set-upstream --upstream-api-key-env '<ENV_NAME>'
80+
$resultJson
81+
python -m codex_fast_proxy status
82+
```
83+
84+
To clear a previously configured upstream auth environment override and return to preserving Codex's
85+
original provider `Authorization` header, run:
86+
87+
```powershell
88+
python -m codex_fast_proxy set-upstream --clear-upstream-api-key-env
89+
python -m codex_fast_proxy status
90+
```
91+
92+
For explicit global Fast injection without changing the upstream URL, confirm that the user accepts
93+
that Codex App's Fast UI toggle will no longer control requests whose `service_tier` is missing, then
94+
run:
95+
96+
```powershell
97+
python -m codex_fast_proxy set-upstream --service-tier-policy inject_missing
98+
python -m codex_fast_proxy status
99+
```
100+
101+
To return to UI-controlled Fast behavior, run:
102+
103+
```powershell
104+
python -m codex_fast_proxy set-upstream --service-tier-policy preserve
105+
python -m codex_fast_proxy status
106+
```
107+
108+
For the default automatic behavior, where API-key mode can use global priority but ChatGPT-login or
109+
unclear states preserve the App/CLI choice, run:
110+
111+
```powershell
112+
python -m codex_fast_proxy set-upstream --service-tier-policy auto
113+
python -m codex_fast_proxy status
114+
```
115+
31116
Report the set-upstream JSON and the final status JSON. The key fields are `provider`, `base_url`,
32-
`previous_upstream_base`, `upstream_base`, `config_matches`, `restart_required`, and `start_result`.
117+
`previous_upstream_base`, `upstream_base`, `service_tier_policy`, `upstream_auth`, `config_matches`,
118+
`verification`, `restart_required`, and `start_result`.
33119

34120
Do not use `--restart` unless the user explicitly accepts that restarting the proxy can interrupt
35121
current proxy-backed Codex sessions. If `restart_required=true`, tell the user to restart Codex App,
36122
open a new CLI process, or run `python -m codex_fast_proxy start` later to apply the new upstream.
37123

38-
If the user also changed API key environment variables, model, reasoning, or other Codex config, tell
39-
them to restart Codex App or open a new CLI process so Codex reloads those settings.
124+
If the user changed API key environment variables, model, reasoning, or other Codex config, tell
125+
them to restart Codex App or open a new CLI process so Codex reloads those settings. The proxy can
126+
read Windows user environment variables directly when possible, but already-running Codex processes
127+
still may need a restart to reload their own config and environment.

.codex/UNINSTALL.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ if (-not $deferred) {
6868

6969
Report the uninstall JSON result when available.
7070

71+
If the uninstall JSON includes `direct_upstream_auth_warning`, report it before telling the user to
72+
restart Codex. This means Codex config has been restored to the direct third-party upstream, but the
73+
current Codex auth state still looks like ChatGPT account login. Direct upstream mode no longer has
74+
the proxy auth override, so model requests may send ChatGPT auth to the third-party provider and
75+
fail with 401. Tell the user to switch Codex App back to API-key/third-party provider auth before
76+
restarting, or keep the proxy enabled if they want ChatGPT-login UI with a third-party provider.
77+
7178
When cleanup completed without `restart_required_before_cleanup=true`, explicitly tell the user:
7279

7380
```text
@@ -79,3 +86,9 @@ If the block printed `restart_required_before_cleanup=true`, explicitly tell the
7986
```text
8087
配置已恢复直连,代理暂时保留运行以避免打断当前进程;请重启 Codex App 并回到这个对话,或新开 CLI 实例后再次执行卸载完成清理。
8188
```
89+
90+
If `direct_upstream_auth_warning` is present, add this before the restart instruction:
91+
92+
```text
93+
注意:当前检测到 ChatGPT 登录态。卸载恢复直连后不再经过 proxy 的 upstream auth override;如果继续保持 ChatGPT 登录,第三方 provider 可能收到 ChatGPT token 并返回 401。请先退出 ChatGPT 登录并切回第三方/API-key 认证,或暂时不要卸载、继续保留 proxy。
94+
```

.codex/UPDATE.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Fetch and follow instructions from https://raw.githubusercontent.com/gaoguobin/c
1010

1111
## Update steps
1212

13+
If the user only asks to check whether an update is available, run this read-only command and stop:
14+
15+
```powershell
16+
python -m codex_fast_proxy check-update
17+
```
18+
19+
Report the JSON, including `relation`, `update_available`, `local_changes`, and `next_action`. If
20+
`relation=local_ahead`, do not report it as an available update. Do not pull, install, restart the
21+
proxy, edit Codex config, or write proxy state unless the user then explicitly asks to update.
22+
1323
If the Codex environment uses sandbox or approval controls, request approval/escalation for the update block because it fetches from GitHub, installs a Python package, may write under `%USERPROFILE%\.codex`, may write `%USERPROFILE%\.codex\hooks.json`, and may create a junction under `%USERPROFILE%\.agents`.
1424

1525
If any command fails because of network, permissions, sandbox write limits, or junction creation, do not try unrelated workarounds. Ask for approval and rerun the same intended update step.
@@ -50,4 +60,41 @@ status JSON as the current state. If the skill was newly linked or changed, expl
5060
请重启 Codex App 并回到这个对话,或新开 CLI 实例,让它重新扫描 ~/.agents/skills;然后再说“启用 Codex Fast proxy”。
5161
```
5262

53-
If `install --start` ran during update, it refreshes `~/.codex/hooks.json` and enables Codex `SessionStart` autostart for future App/CLI starts. It also compares the running proxy runtime with the installed code; if the proxy is healthy but stale, it restarts the proxy before returning. Use the final `status` output to report `runtime_matches` and `needs_restart`. If `status.needs_restart` is still `true`, tell the user to restart Codex App or open a new CLI process; the `SessionStart` hook will retry the stale runtime restart when config still points to the local proxy. Codex may fire `SessionStart` for each new or resumed session; `autostart --quiet` does not log normal no-op checks.
63+
If `install --start` ran during update, it refreshes `~/.codex/hooks.json` and enables Codex `SessionStart` autostart for future App/CLI starts. It also compares the running proxy runtime with the installed code; if the proxy is healthy but stale, explicit `install --start`/`start` may restart the proxy before returning. Use the final `status` output to report `runtime_matches` and `needs_restart`. If `status.needs_restart` is still `true`, tell the user to restart Codex App, open a new CLI process after the old proxy is gone, or run `python -m codex_fast_proxy start` when it is safe to refresh runtime code. Codex may fire `SessionStart` for each new or resumed session; `autostart --quiet` does not restart an already healthy proxy just because runtime code is stale, and it does not log normal no-op checks.
64+
65+
Current Codex builds may require trusted user hooks. After update, `startup_hook: true` means the
66+
hook exists, is enabled, and its current command hash is trusted. If `startup_hook_trust` reports
67+
`modified` or `untrusted`, rerun `python -m codex_fast_proxy install --start` before asking the user
68+
to rely on autostart.
69+
70+
Current behavior after update:
71+
72+
- New installs default to `auto`: ChatGPT-login or unclear states preserve Codex App/CLI Fast UI
73+
choices, while API-key mode can use global priority when Codex omits `service_tier`.
74+
- Existing `service_tier_policy` and `upstream_api_key_env` settings are preserved during
75+
`install --start`.
76+
- Older installs that never recorded `service_tier_policy` and do not have `upstream_api_key_env`
77+
are treated as `inject_missing` to keep their previous global Fast behavior. Missing policy plus
78+
`upstream_api_key_env` is treated as App-controlled `preserve`, because that shape belongs to the
79+
ChatGPT-login auth split path. If the user explicitly wants auto behavior, run:
80+
81+
```powershell
82+
python -m codex_fast_proxy set-upstream --service-tier-policy auto
83+
```
84+
85+
Do not pass `--restart` unless the user accepts interrupting current proxy-backed Codex sessions.
86+
87+
- For ChatGPT login compatibility after update, first prepare the provider key env without printing
88+
the key, then configure only the upstream API key environment variable name:
89+
90+
```powershell
91+
python -m codex_fast_proxy prepare-chatgpt-login
92+
python -m codex_fast_proxy prepare-chatgpt-login --target-env PACKY_API_KEY --apply
93+
python -m codex_fast_proxy set-upstream --upstream-api-key-env PACKY_API_KEY
94+
```
95+
96+
The first command is a dry run. Run the `--apply` command only after the user approves writing a
97+
Windows user environment variable. Do not pass `--restart` unless the user accepts interrupting
98+
current proxy-backed Codex sessions.
99+
100+
Never print API key values, `auth.json` contents, ChatGPT tokens, cookies, request bodies, or prompts.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ __pycache__/
66
build/
77
dist/
88
.pytest_cache/
9+
.claude/

0 commit comments

Comments
 (0)