@bitkyc08/opencodex 2.12.0 → 2.13.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 +1 -1
- package/gui/dist/assets/index-BHldBl6_.js +76 -0
- package/gui/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/adapters/anthropic-output-schema.ts +137 -0
- package/src/adapters/anthropic.ts +15 -0
- package/src/adapters/google-antigravity-replay.ts +269 -5
- package/src/adapters/openai-chat.ts +25 -18
- package/src/adapters/openai-responses.ts +63 -17
- package/src/bridge.ts +11 -5
- package/src/claude/inbound.ts +24 -3
- package/src/cli/account-api.ts +2 -0
- package/src/cli/account-extended.ts +262 -1
- package/src/cli/account.ts +3 -1
- package/src/cli/dispatch.ts +532 -0
- package/src/cli/doctor.ts +26 -21
- package/src/cli/help.ts +9 -278
- package/src/cli/index.ts +45 -506
- package/src/cli/lab.ts +171 -65
- package/src/cli/registry.ts +384 -0
- package/src/cli/root.ts +86 -0
- package/src/cli/status.ts +9 -2
- package/src/cli/v2.ts +37 -2
- package/src/codex/account-label.ts +14 -1
- package/src/codex/account-store.ts +12 -1
- package/src/codex/admission.ts +2 -1
- package/src/codex/auth-api.ts +3 -2
- package/src/codex/catalog/metadata.ts +6 -4
- package/src/codex/catalog/parsing.ts +31 -7
- package/src/codex/catalog/provider-fetch.ts +2 -1
- package/src/codex/catalog/sync.ts +65 -11
- package/src/codex/features.ts +437 -31
- package/src/codex/history-job.ts +6 -11
- package/src/codex/history-provider.ts +10 -9
- package/src/codex/inject.ts +14 -1
- package/src/codex/native-profile-startup.ts +49 -3
- package/src/codex/native-residue.ts +14 -2
- package/src/codex/paths.ts +75 -1
- package/src/codex/reset-credit-recovery.ts +1044 -0
- package/src/codex/shim.ts +876 -16
- package/src/codex/sync.ts +27 -2
- package/src/config.ts +148 -10
- package/src/generated/compatibility-version.json +2572 -0
- package/src/images/loop.ts +1 -1
- package/src/lab/artifacts/sanitize.ts +3 -3
- package/src/lab/automation/budgets.ts +78 -0
- package/src/lab/automation/config-persistence.ts +256 -0
- package/src/lab/automation/constants.ts +39 -0
- package/src/lab/automation/cooldown.ts +103 -0
- package/src/lab/automation/dispatch.ts +211 -0
- package/src/lab/automation/index.ts +13 -0
- package/src/lab/automation/orchestrator.ts +480 -0
- package/src/lab/automation/persistence.ts +512 -0
- package/src/lab/automation/planner.ts +371 -0
- package/src/lab/automation/policy.ts +136 -0
- package/src/lab/automation/queue.ts +191 -0
- package/src/lab/automation/recovery.ts +24 -0
- package/src/lab/automation/route-context.ts +21 -0
- package/src/lab/automation/run-key.ts +44 -0
- package/src/lab/automation/runs-query.ts +34 -0
- package/src/lab/automation/types.ts +160 -0
- package/src/lab/conformance/types.ts +23 -0
- package/src/lab/events/types.ts +2 -1
- package/src/lab/events/validate.ts +2 -1
- package/src/lab/fabric/constants.ts +40 -0
- package/src/lab/fabric/executor.ts +492 -0
- package/src/lab/fabric/index.ts +80 -0
- package/src/lab/fabric/manifest.ts +222 -0
- package/src/lab/fabric/observe.ts +454 -0
- package/src/lab/fabric/patch.ts +79 -0
- package/src/lab/fabric/producer-child.ts +139 -0
- package/src/lab/fabric/producer-isolate.ts +276 -0
- package/src/lab/fabric/producer-protocol.ts +61 -0
- package/src/lab/fabric/scratch.ts +439 -0
- package/src/lab/fabric/subject.ts +106 -0
- package/src/lab/fabric/types.ts +134 -0
- package/src/lab/fabric/verifier.ts +98 -0
- package/src/lab/index.ts +2 -0
- package/src/lab/ledger/store.ts +173 -0
- package/src/lab/live/executor.ts +29 -4
- package/src/lab/live/transport.ts +3 -1
- package/src/lab/observe/from-conformance.ts +12 -57
- package/src/lab/observe/from-live.ts +9 -1
- package/src/lab/paths.ts +74 -9
- package/src/lab/projection/schema.ts +14 -1
- package/src/lab/projection/verdicts.ts +89 -53
- package/src/lab/projection/verification.ts +83 -3
- package/src/lab/query/catalog.ts +34 -5
- package/src/lab/query/freshness.ts +53 -0
- package/src/lab/query/index.ts +11 -0
- package/src/lab/query/latest-observation.ts +59 -0
- package/src/lab/query/passive-production.ts +159 -0
- package/src/lab/subject/installation-salt.ts +24 -4
- package/src/lab/subject/protocol-subject.ts +80 -0
- package/src/lab/subject/route-subject.ts +2 -1
- package/src/lib/fabric-task-execution-authority.ts +7 -0
- package/src/lib/fabric-task-host.ts +29 -0
- package/src/lib/lab-live-route-production.ts +130 -0
- package/src/lib/local-management-capability.ts +100 -0
- package/src/lib/server-resource-ownership.ts +71 -0
- package/src/lib/windows-elevation.ts +8 -1
- package/src/lib/windows-user-principal.ts +62 -2
- package/src/lib/winsw.ts +8 -2
- package/src/oauth/account-import/google-antigravity-adapter.ts +74 -0
- package/src/oauth/account-import/index.ts +15 -0
- package/src/oauth/account-import/parser.ts +83 -0
- package/src/oauth/account-import/registry.ts +18 -0
- package/src/oauth/account-import/service.ts +75 -0
- package/src/oauth/account-import/types.ts +91 -0
- package/src/oauth/anthropic.ts +12 -1
- package/src/oauth/callback-server.ts +8 -2
- package/src/oauth/chatgpt.ts +12 -1
- package/src/oauth/google-antigravity.ts +27 -0
- package/src/oauth/health.ts +12 -48
- package/src/oauth/index.ts +122 -0
- package/src/oauth/kimi.ts +16 -2
- package/src/oauth/nous.ts +749 -0
- package/src/oauth/store.ts +56 -3
- package/src/providers/codex-capacity.ts +1 -0
- package/src/providers/registry.ts +161 -16
- package/src/responses/custom-tool-compat.ts +182 -0
- package/src/responses/parser.ts +22 -0
- package/src/responses/reasoning-replay-cache.ts +168 -11
- package/src/responses/schema.ts +1 -1
- package/src/router.ts +5 -20
- package/src/routing/capability.ts +9 -3
- package/src/routing/compatibility/assemble.ts +159 -0
- package/src/routing/compatibility/behavior.ts +224 -0
- package/src/routing/compatibility/catalog.ts +99 -0
- package/src/routing/compatibility/endpoint.ts +52 -0
- package/src/routing/compatibility/policy.ts +181 -0
- package/src/routing/compatibility/reader.ts +110 -0
- package/src/routing/compatibility/subject.ts +191 -0
- package/src/routing/compatibility/types.ts +64 -0
- package/src/routing/compatibility/version.ts +104 -0
- package/src/routing/evaluator.ts +27 -32
- package/src/routing/profile.ts +118 -4
- package/src/routing/trace.ts +82 -28
- package/src/server/auth-cors.ts +7 -0
- package/src/server/background-lifecycle.ts +20 -7
- package/src/server/chat-completions.ts +2 -2
- package/src/server/claude-messages.ts +6 -3
- package/src/server/direct-local-http.ts +343 -0
- package/src/server/index.ts +80 -18
- package/src/server/lifecycle.ts +12 -4
- package/src/server/local-management-read-client.ts +90 -0
- package/src/server/management/agent-settings-routes.ts +27 -3
- package/src/server/management/lab-automation-routes.ts +206 -0
- package/src/server/management/lab-routes.ts +13 -0
- package/src/server/management/logs-usage-routes.ts +1 -0
- package/src/server/management/oauth-account-routes.ts +57 -1
- package/src/server/management/provider-routes.ts +16 -0
- package/src/server/management/routing-profile-routes.ts +12 -24
- package/src/server/management-api.ts +2 -0
- package/src/server/management-auth.ts +68 -3
- package/src/server/proxy-liveness.ts +3 -2
- package/src/server/request-decompress.ts +9 -3
- package/src/server/request-log.ts +53 -4
- package/src/server/responses/collaboration.ts +93 -17
- package/src/server/responses/compact.ts +3 -0
- package/src/server/responses/core.ts +202 -15
- package/src/server/responses/policy-fallback.ts +1 -0
- package/src/server/responses-custom-tool-repair.ts +280 -0
- package/src/server/responses-terminal-repair.ts +342 -0
- package/src/server/startup-action-control.ts +8 -1
- package/src/service.ts +278 -12
- package/src/types.ts +49 -3
- package/src/usage/expected-prices.ts +30 -0
- package/src/usage/log.ts +30 -4
- package/src/usage/summary.ts +153 -2
- package/src/web-search/loop.ts +1 -1
- package/gui/dist/assets/index-Cw1_mxO8.js +0 -70
- package/src/cli/internal-dispatch.ts +0 -20
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
export interface CliCommandEntry {
|
|
2
|
+
name: string;
|
|
3
|
+
aliases?: string[];
|
|
4
|
+
usage: string;
|
|
5
|
+
summary: string;
|
|
6
|
+
details?: string[];
|
|
7
|
+
hidden?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const CLI_COMMANDS: CliCommandEntry[] = [
|
|
11
|
+
{
|
|
12
|
+
name: "init",
|
|
13
|
+
aliases: ["setup"],
|
|
14
|
+
usage: "ocx init",
|
|
15
|
+
summary: "Interactive setup for providers and Codex config injection.",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "setup",
|
|
19
|
+
aliases: [],
|
|
20
|
+
usage: "ocx setup",
|
|
21
|
+
summary: "Interactive setup for providers and Codex config injection (alias of init).",
|
|
22
|
+
},
|
|
23
|
+
{ name: "start", usage: "ocx start [--port <port>]", summary: "Start the proxy server and sync models to Codex." },
|
|
24
|
+
{ name: "stop", usage: "ocx stop", summary: "Stop the proxy and restore native Codex config." },
|
|
25
|
+
{
|
|
26
|
+
name: "restore",
|
|
27
|
+
aliases: ["eject"],
|
|
28
|
+
usage: "ocx restore [back]",
|
|
29
|
+
summary: "Restore native Codex config without stopping the proxy; `restore back` re-points codex at the running proxy.",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "eject",
|
|
33
|
+
aliases: [],
|
|
34
|
+
usage: "ocx eject [back]",
|
|
35
|
+
summary: "Restore native Codex config without stopping the proxy; `eject back` re-points codex at the running proxy.",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "recover-history",
|
|
39
|
+
usage: "ocx recover-history --legacy-openai",
|
|
40
|
+
summary: "Explicitly recover pre-backup syncResumeHistory rows.",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "uninstall",
|
|
44
|
+
aliases: ["remove"],
|
|
45
|
+
usage: "ocx uninstall",
|
|
46
|
+
summary: "Remove service/shim/config and restore native Codex.",
|
|
47
|
+
details: [
|
|
48
|
+
"Alias: ocx remove",
|
|
49
|
+
"Config cleanup requires ownership metadata created by a fresh install; legacy or shared directories are left in place.",
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "remove",
|
|
54
|
+
aliases: [],
|
|
55
|
+
usage: "ocx remove",
|
|
56
|
+
summary: "Remove service/shim/config and restore native Codex.",
|
|
57
|
+
details: [
|
|
58
|
+
"Alias of: ocx uninstall",
|
|
59
|
+
"Config cleanup requires ownership metadata created by a fresh install; legacy or shared directories are left in place.",
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "service",
|
|
64
|
+
usage: "ocx service [install|start|stop|status|uninstall|remove]",
|
|
65
|
+
summary: "Run as a background service.",
|
|
66
|
+
details: [
|
|
67
|
+
"With no subcommand, installs/updates and starts the background service.",
|
|
68
|
+
"Use `ocx service status` to see diagnostics and log paths.",
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "codex-shim",
|
|
73
|
+
usage: "ocx codex-shim <install|status|uninstall|remove>",
|
|
74
|
+
summary: "Auto-start the proxy when `codex` launches.",
|
|
75
|
+
details: ["Use `remove` as an alias for `uninstall`."],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "tray",
|
|
79
|
+
usage: "ocx tray <install|start|stop|status|uninstall|remove> [--json] [--no-start]",
|
|
80
|
+
summary: "Install and control the Windows status tray icon.",
|
|
81
|
+
details: [
|
|
82
|
+
"The tray starts at Windows login and provides one-click proxy controls.",
|
|
83
|
+
"Tray start/stop controls the icon only; use its menu to start or stop the proxy.",
|
|
84
|
+
"--no-start (install only) installs the tray without launching it immediately.",
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
{ name: "ensure", usage: "ocx ensure", summary: "Ensure the proxy is running and Codex config/cache are current." },
|
|
88
|
+
{
|
|
89
|
+
name: "sync",
|
|
90
|
+
usage: "ocx sync [--restart-codex]",
|
|
91
|
+
summary: "Fetch provider models and inject them into Codex config.",
|
|
92
|
+
details: [
|
|
93
|
+
"After writing the catalog, warns if long-lived Codex app-server processes are still running.",
|
|
94
|
+
"--restart-codex sends SIGTERM only to matching app-server / code-mode-host processes (may interrupt active turns).",
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: "sync-cache",
|
|
99
|
+
usage: "ocx sync-cache [--restart-codex]",
|
|
100
|
+
summary: "Refresh Codex's model cache from the active catalog.",
|
|
101
|
+
details: [
|
|
102
|
+
"Warns when Codex app-server processes still hold an in-memory model list.",
|
|
103
|
+
"--restart-codex sends SIGTERM only to matching app-server / code-mode-host processes (may interrupt active turns).",
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{ name: "status", usage: "ocx status", summary: "Check proxy server status." },
|
|
107
|
+
{
|
|
108
|
+
name: "doctor",
|
|
109
|
+
usage: "ocx doctor",
|
|
110
|
+
summary: "Diagnose environment/network issues (paths, WSL /mnt, proxy env, ChatGPT reachability).",
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "debug",
|
|
114
|
+
usage: "ocx debug <provider|usage|injection|claude> <on|off|status|reset|logs [-f]>",
|
|
115
|
+
summary: "Show or toggle runtime provider, usage, injection, and Claude debug capture.",
|
|
116
|
+
details: [
|
|
117
|
+
"Provider: ocx debug provider on | off | status | reset | logs [-f]",
|
|
118
|
+
"Usage JSONL: ocx debug usage on | off | status | reset | logs [-f]",
|
|
119
|
+
"Env default: OCX_DEBUG=1 (legacy OCX_DEBUG_FRAMES still works)",
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
{ name: "login", usage: "ocx login <provider>", summary: "OAuth or API-key login for a provider." },
|
|
123
|
+
{ name: "logout", usage: "ocx logout <provider>", summary: "Remove a stored provider login." },
|
|
124
|
+
{ name: "gui", usage: "ocx gui", summary: "Open the opencodex dashboard." },
|
|
125
|
+
{
|
|
126
|
+
name: "update",
|
|
127
|
+
usage: "ocx update [--tag latest|preview]",
|
|
128
|
+
summary: "Update opencodex. Preview installs stay on the preview tag unless overridden.",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: "provider",
|
|
132
|
+
usage: "ocx provider <list|add|edit|test|remove|show|set-default|selected|quota|presets|account-mode>",
|
|
133
|
+
summary: "Non-interactive provider management.",
|
|
134
|
+
details: [
|
|
135
|
+
"Subcommands: list, add/edit/test/remove/show, set-default, selected, quota, presets, account-mode",
|
|
136
|
+
"Registry providers are auto-configured by name. Custom providers need --adapter and --base-url.",
|
|
137
|
+
"Run `ocx provider --help` for full usage and examples.",
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "account",
|
|
142
|
+
usage: "ocx account <list|current|use|refresh|auto-switch|priority|login|reauth|code|cancel|remove|add-key|reset-credits|main> ...",
|
|
143
|
+
summary: "List and switch provider accounts and API-key pools (GUI parity).",
|
|
144
|
+
details: [
|
|
145
|
+
"list [provider] Codex account pool, OAuth accounts and API keys (identifiers shown masked as the API returns them).",
|
|
146
|
+
"current <provider> Show the active account or key.",
|
|
147
|
+
"use <provider> <id> Switch the active credential; 'main' selects the Codex App login.",
|
|
148
|
+
"refresh <provider> Force-refresh Codex or provider quota reports.",
|
|
149
|
+
"auto-switch <provider> <on|off|status|threshold N> Control the Codex pool threshold.",
|
|
150
|
+
"priority <provider> <id|main> [first|earlier|normal|later|last|-100..100|reset] Selection order; omit the value to read it.",
|
|
151
|
+
"remove <provider> <id> --yes Remove a stored account or key after an existence check.",
|
|
152
|
+
"add-key <provider> [--label <label>] Add a key read only from piped stdin.",
|
|
153
|
+
"login/reauth/code/cancel Run browser or manual-code auth from a headless shell.",
|
|
154
|
+
"reset-credits <id|main> [--consume --yes] Inspect or consume Codex reset credits.",
|
|
155
|
+
"main <subcommand> Manage the physical native Codex login separately from Pool routing.",
|
|
156
|
+
"Switching the active account takes effect immediately; running threads move on their next request, and in-flight requests keep the account they captured.",
|
|
157
|
+
"A selection-order change applies from the next unbound request and never moves a bound thread.",
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: "models",
|
|
162
|
+
aliases: ["model"],
|
|
163
|
+
usage: "ocx models <list|live|add|edit|remove|enable|disable|provider|selected|context|shadow> ...",
|
|
164
|
+
summary: "List models and manage custom (manually registered) models.",
|
|
165
|
+
details: [
|
|
166
|
+
"List available models from static config with no subcommand (liveModels may add more at runtime).",
|
|
167
|
+
"add: register a model the provider catalog does not advertise yet.",
|
|
168
|
+
" --display-name <name> Human label (no slashes).",
|
|
169
|
+
" --context-window <tokens> e.g. 200000.",
|
|
170
|
+
" --modalities text,image Comma-separated (text|image|audio).",
|
|
171
|
+
"remove: delete a custom model by UUID or <provider>/<modelId>.",
|
|
172
|
+
"list-custom: show all custom models.",
|
|
173
|
+
"Changes apply immediately to a running proxy (catalog sync).",
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "model",
|
|
178
|
+
aliases: [],
|
|
179
|
+
usage: "ocx model <subcommand>",
|
|
180
|
+
summary: "Alias of ocx models.",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: "combo",
|
|
184
|
+
usage: "ocx combo <list|show|set|remove> ...",
|
|
185
|
+
summary: "Manage combo failover and round-robin virtual models.",
|
|
186
|
+
details: ["Alias hierarchy: ocx route combo ...", "Use --targets provider/model[:weight],provider/model[:weight]."],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "route",
|
|
190
|
+
usage: "ocx route combo <list|show|set|remove> ...",
|
|
191
|
+
summary: "Manage routing features; combo is currently the supported routing resource.",
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "agent",
|
|
195
|
+
usage: "ocx agent <status|injection|effort|subagents|fallback|sidecar> ...",
|
|
196
|
+
summary: "Manage headless multi-agent, roster, effort, injection, and sidecar settings.",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
name: "observe",
|
|
200
|
+
usage: "ocx observe <logs|usage|storage|memory|debug|claude-inbound|injection> ...",
|
|
201
|
+
summary: "Inspect proxy requests, usage, storage, memory, and debug data.",
|
|
202
|
+
},
|
|
203
|
+
{ name: "logs", usage: "ocx logs [filters] [--follow] [--json|--jsonl]", summary: "Alias of ocx observe logs." },
|
|
204
|
+
{
|
|
205
|
+
name: "usage",
|
|
206
|
+
usage: "ocx usage [--range <7d|30d|all>] [--surface <all|codex|claude|grok>] [--json]",
|
|
207
|
+
summary: "Alias of ocx observe usage.",
|
|
208
|
+
},
|
|
209
|
+
{ name: "storage", usage: "ocx storage [--json]", summary: "Alias of ocx observe storage." },
|
|
210
|
+
{ name: "memory", usage: "ocx memory [--json]", summary: "Alias of ocx observe memory." },
|
|
211
|
+
{
|
|
212
|
+
name: "access",
|
|
213
|
+
usage: "ocx access <key|endpoints|models|test> ...",
|
|
214
|
+
summary: "Manage OpenCodex admission API keys and inspect external endpoints.",
|
|
215
|
+
},
|
|
216
|
+
{ name: "api-key", usage: "ocx api-key <list|create|remove> ...", summary: "Alias of ocx access key." },
|
|
217
|
+
{
|
|
218
|
+
name: "export",
|
|
219
|
+
usage: "ocx export --client <opencode|pi|omp|hermes|openclaw|kimi|gajae> [--json] [--out <path>] [--force]",
|
|
220
|
+
summary: "Print a client config (opencode, Pi, OMP, Hermes, OpenClaw, Kimi Code, Gajae Code) wired to the running proxy.",
|
|
221
|
+
details: [
|
|
222
|
+
"--json prints the generated document as JSON on stdout; use --out for the client's native format.",
|
|
223
|
+
"--out <path> writes the native config there and refuses to replace an existing file without --force.",
|
|
224
|
+
"The config never contains a real key; it carries a documented env reference or a non-secret loopback placeholder.",
|
|
225
|
+
"The destination path is printed for merging by hand — ocx never writes your real client config.",
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: "grok",
|
|
230
|
+
usage: "ocx grok <status|exclude|include|set|clear|apply> ...",
|
|
231
|
+
summary: "Manage and apply the Grok Build model fence.",
|
|
232
|
+
},
|
|
233
|
+
{ name: "integration", usage: "ocx integration <claude|grok|client> ...", summary: "Manage supported client integrations." },
|
|
234
|
+
{
|
|
235
|
+
name: "system",
|
|
236
|
+
usage: "ocx system <status|settings|startup|diagnostics|sync|update> ...",
|
|
237
|
+
summary: "Manage headless runtime settings, startup, sync, diagnostics, and updates.",
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: "config",
|
|
241
|
+
usage: "ocx config <show|get|set|unset|validate|export|import> ...",
|
|
242
|
+
summary: "Inspect and safely modify validated OpenCodex configuration.",
|
|
243
|
+
details: ["Secrets are masked by show/get. Import requires --yes and validates before writing."],
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
name: "claude",
|
|
247
|
+
usage: "ocx claude [claude args...]",
|
|
248
|
+
summary: "Launch Claude Code wired to the proxy (env injection + gateway model discovery).",
|
|
249
|
+
details: [
|
|
250
|
+
"Ensures the proxy is running, then execs `claude` with ANTHROPIC_BASE_URL/ANTHROPIC_AUTH_TOKEN,",
|
|
251
|
+
"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 and model slots from config.claudeCode.",
|
|
252
|
+
"Routed models appear in the native /model picker with stable claude-opus-4-8-2026MMDD slot aliases (Claude Code >= 2.1.129).",
|
|
253
|
+
"Older versions: pick models via ANTHROPIC_MODEL or /model <id> directly (any string passes through).",
|
|
254
|
+
"User-exported ANTHROPIC_* variables always take precedence.",
|
|
255
|
+
"",
|
|
256
|
+
"Claude Desktop profile:",
|
|
257
|
+
" ocx claude desktop [apply] Save and apply the four-family profile",
|
|
258
|
+
" ocx claude desktop show [--json] Show routes, families, and defaults",
|
|
259
|
+
" ocx claude desktop move <route> <family> [--default]",
|
|
260
|
+
" ocx claude desktop default <family> <route|none>",
|
|
261
|
+
" ocx claude desktop export <path|-> Export versioned JSON (`-` = stdout)",
|
|
262
|
+
" ocx claude desktop import <path> [--apply] Validate and import JSON",
|
|
263
|
+
"Families: opus, fable, sonnet, haiku. New routes start in opus.",
|
|
264
|
+
"`none` is valid only when that family is empty.",
|
|
265
|
+
"Legacy apply flags remain supported: --static, --hybrid, --discovery-only.",
|
|
266
|
+
"",
|
|
267
|
+
"Claude Code settings: ocx claude config <status|set> ...",
|
|
268
|
+
],
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: "opencode",
|
|
272
|
+
usage: "ocx opencode [opencode args...]",
|
|
273
|
+
summary: "Launch opencode wired to the proxy (runtime provider config).",
|
|
274
|
+
details: [
|
|
275
|
+
"Ensures the proxy is running, then execs `opencode` with the generated `provider.opencodex`",
|
|
276
|
+
"block injected through OpenCode's inline runtime layer (`OPENCODE_CONFIG_CONTENT`). Any",
|
|
277
|
+
"existing inline config in the environment is preserved and only `provider.opencodex` is",
|
|
278
|
+
"overwritten for this launch.",
|
|
279
|
+
"Global/project opencode.json may be read to warn about an existing provider.opencodex",
|
|
280
|
+
"override; on-disk files are never modified.",
|
|
281
|
+
"Routed models appear in the model picker as opencodex/<provider>/<model>.",
|
|
282
|
+
"Stop using `ocx opencode` and plain `opencode` behaves exactly as before.",
|
|
283
|
+
],
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
name: "restart",
|
|
287
|
+
usage: "ocx restart",
|
|
288
|
+
summary: "Stop the proxy and restart it (background). Equivalent to stop + ensure.",
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
name: "v2",
|
|
292
|
+
usage: "ocx v2 <status|on|off|mode <v1|default|v2>|threads <n>>",
|
|
293
|
+
summary: "Toggle the Codex multi_agent_v2 feature (multi-agent surface).",
|
|
294
|
+
details: [
|
|
295
|
+
"status Show flag, multi-agent mode, and thread limit.",
|
|
296
|
+
"on | off Enable/disable multi_agent_v2 (catalog resyncs).",
|
|
297
|
+
"mode <v1|default|v2> Force all models to one surface, or respect upstream pins.",
|
|
298
|
+
"threads <n> Set max_concurrent_threads_per_session (integer >= 1).",
|
|
299
|
+
"Flips preserve the active thread limit while moving between v1/v2 modes.",
|
|
300
|
+
],
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
name: "health",
|
|
304
|
+
usage: "ocx health [--json]",
|
|
305
|
+
summary: "Check proxy health. Exits 0 if healthy, 1 otherwise.",
|
|
306
|
+
details: ["Use --json for structured output: {ok, pid, port}."],
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
name: "ready",
|
|
310
|
+
usage: "ocx ready [--json] [--wait [--timeout <seconds>]]",
|
|
311
|
+
summary: "Check post-sync readiness. Exits 0 only when ready.",
|
|
312
|
+
details: [
|
|
313
|
+
"Exact unauthenticated GET /readyz returns HTTP 200 when ready, or 503 with Retry-After: 1 for pending or failed.",
|
|
314
|
+
"Its sanitized HTTP identity is {service, version, uptime, pid, port, status}; /healthz is separate liveness, not readiness.",
|
|
315
|
+
"Default is a single identity-checked /readyz probe; old proxies without /readyz fail closed as unreachable.",
|
|
316
|
+
"--wait polls until ready or timeout, but exits immediately on terminal failed (default 45s, max 300s).",
|
|
317
|
+
"--timeout requires --wait and accepts a positive integer (1..300).",
|
|
318
|
+
"--json emits {ready, status, pid, port}; status is one of ready|pending|failed|unreachable.",
|
|
319
|
+
"Invalid or unknown arguments exit 64. Not-ready, pending, failed, timeout, and unreachable exit 1.",
|
|
320
|
+
],
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
name: "lab",
|
|
324
|
+
usage: "ocx lab <status|verdicts|subjects|subject|observations|events|event|artifacts|artifact|catalog> [options] [--json]",
|
|
325
|
+
summary: "Read-only Compatibility Lab projection inspection (local SQLite; no daemon).",
|
|
326
|
+
details: [
|
|
327
|
+
"status Projection availability, schema versions, and row counts.",
|
|
328
|
+
"verdicts Paginated derived compatibility verdicts with filters.",
|
|
329
|
+
"subjects List subjects; subject <id> returns one typed subject.",
|
|
330
|
+
"observations Paginated observation rows from the projection.",
|
|
331
|
+
"events Event history; event <id> returns one safe typed event.",
|
|
332
|
+
"artifacts Artifact metadata only (no content download).",
|
|
333
|
+
"catalog Packaged protocol/live scenario catalog metadata.",
|
|
334
|
+
"Reads never rebuild the projection, trigger probes, or require the proxy.",
|
|
335
|
+
],
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
name: "__refresh-version",
|
|
339
|
+
hidden: true,
|
|
340
|
+
usage: "ocx __refresh-version [preview|latest]",
|
|
341
|
+
summary: "Hidden detached helper: refresh the cached latest version.",
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
name: "__tray-start",
|
|
345
|
+
hidden: true,
|
|
346
|
+
usage: "ocx __tray-start",
|
|
347
|
+
summary: "Hidden internal: start the tray proxy.",
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
name: "__tray-restart",
|
|
351
|
+
hidden: true,
|
|
352
|
+
usage: "ocx __tray-restart",
|
|
353
|
+
summary: "Hidden internal: restart the tray proxy.",
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
name: "__startup-health",
|
|
357
|
+
hidden: true,
|
|
358
|
+
usage: "ocx __startup-health",
|
|
359
|
+
summary: "Hidden internal: print startup health JSON.",
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
name: "__tray-host",
|
|
363
|
+
hidden: true,
|
|
364
|
+
usage: "ocx __tray-host",
|
|
365
|
+
summary: "Hidden internal: run the Windows tray host.",
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
name: "__gui-update-worker",
|
|
369
|
+
hidden: true,
|
|
370
|
+
usage: "ocx __gui-update-worker <jobId> [channel] [restart]",
|
|
371
|
+
summary: "Hidden internal: run the GUI update worker.",
|
|
372
|
+
},
|
|
373
|
+
];
|
|
374
|
+
|
|
375
|
+
export function findCommand(name: string): CliCommandEntry | undefined {
|
|
376
|
+
// Exact-name wins so alias-name entries (setup/eject/remove/model) keep their
|
|
377
|
+
// own help text; the canonical entry is the fallback for alias lookups.
|
|
378
|
+
return CLI_COMMANDS.find(entry => entry.name === name)
|
|
379
|
+
?? CLI_COMMANDS.find(entry => entry.aliases?.includes(name));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function commandNames(): string[] {
|
|
383
|
+
return CLI_COMMANDS.map(entry => entry.name);
|
|
384
|
+
}
|
package/src/cli/root.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI head: version/help early exits, `ocx ready` pre-parse, and the bounded
|
|
3
|
+
* Codex-shim auto-restore preflight, in that order (Phase 1 of the CLI
|
|
4
|
+
* deepening — moved out of src/cli/index.ts).
|
|
5
|
+
*
|
|
6
|
+
* `parseCliHead` is pure (no I/O, no process access) so the ordering and the
|
|
7
|
+
* single-parse contract are unit-testable without a subprocess. `runCli` owns
|
|
8
|
+
* the exit paths and the shim preflight, then returns the dispatchable head
|
|
9
|
+
* for the command switch in src/cli/index.ts.
|
|
10
|
+
*/
|
|
11
|
+
import { hasHelpFlag, printSubcommandUsage, printUsage, printVersion } from "./help";
|
|
12
|
+
import { parseReadyArgs, type ReadyArgs } from "./ready";
|
|
13
|
+
import { maybeAutoRestoreCodexShim } from "./codex-shim-autorestore";
|
|
14
|
+
|
|
15
|
+
export interface CliHead {
|
|
16
|
+
kind: "version" | "help" | "ready" | "command";
|
|
17
|
+
command: string | undefined;
|
|
18
|
+
args: string[];
|
|
19
|
+
/** For kind "help": the subcommand whose usage should print, if any. */
|
|
20
|
+
helpTarget?: string;
|
|
21
|
+
/** Present only for `ready`; undefined when the ready args failed to parse. */
|
|
22
|
+
readyArgs?: ReadyArgs;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parseCliHead(argv: string[]): CliHead {
|
|
26
|
+
const command = argv[0];
|
|
27
|
+
const args = argv;
|
|
28
|
+
if (command === "--version" || command === "-v" || command === "version") {
|
|
29
|
+
return { kind: "version", command, args };
|
|
30
|
+
}
|
|
31
|
+
if (command === undefined || command === "help" || command === "--help" || command === "-h") {
|
|
32
|
+
// `ocx help <sub>` carries the subcommand; bare/flag help prints the full usage.
|
|
33
|
+
return {
|
|
34
|
+
kind: "help",
|
|
35
|
+
command,
|
|
36
|
+
args,
|
|
37
|
+
...(command === "help" && args[1] ? { helpTarget: args[1] } : {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (command !== "help" && hasHelpFlag(args.slice(1))) {
|
|
41
|
+
// `ocx <cmd> --help|-h|help` prints that command's usage, not the full list.
|
|
42
|
+
return { kind: "help", command, args, helpTarget: command };
|
|
43
|
+
}
|
|
44
|
+
// P1: pre-parse `ocx ready` and reject invalid arguments with exit 64 BEFORE
|
|
45
|
+
// maybeAutoRestoreCodexShim (or any discovery/probe/filesystem-capable global
|
|
46
|
+
// preflight) runs. `ready --help` / `help ready` already exited above, so this
|
|
47
|
+
// only sees ready args without a help flag. Valid args are stashed so the
|
|
48
|
+
// switch dispatch can call runReady without a second parse.
|
|
49
|
+
if (command === "ready") {
|
|
50
|
+
const parsed = parseReadyArgs(args.slice(1));
|
|
51
|
+
if (!parsed.ok) return { kind: "ready", command, args, readyArgs: undefined };
|
|
52
|
+
return { kind: "ready", command, args, readyArgs: parsed.args };
|
|
53
|
+
}
|
|
54
|
+
return { kind: "command", command, args };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function runCli(argv: string[]): Promise<CliHead> {
|
|
58
|
+
const head = parseCliHead(argv);
|
|
59
|
+
switch (head.kind) {
|
|
60
|
+
case "version":
|
|
61
|
+
printVersion();
|
|
62
|
+
process.exit(0);
|
|
63
|
+
case "help": {
|
|
64
|
+
if (head.helpTarget) printSubcommandUsage(head.helpTarget);
|
|
65
|
+
else printUsage();
|
|
66
|
+
process.exit(0);
|
|
67
|
+
}
|
|
68
|
+
case "ready": {
|
|
69
|
+
// Fail-closed impossible-state guard: parseCliHead already ran the
|
|
70
|
+
// pre-parse before any shim/preflight side effect, so reaching here
|
|
71
|
+
// without readyArgs means dispatch diverged. Refuse with code 64 and
|
|
72
|
+
// perform NO I/O (no discovery/probe).
|
|
73
|
+
if (!head.readyArgs) {
|
|
74
|
+
console.error("Usage: ocx ready [--json] [--wait [--timeout <seconds>]]");
|
|
75
|
+
console.error(" --timeout requires --wait; <seconds> must be a positive integer (1..300).");
|
|
76
|
+
console.error(" Default wait timeout is 45 seconds.");
|
|
77
|
+
process.exit(64);
|
|
78
|
+
}
|
|
79
|
+
maybeAutoRestoreCodexShim(head.command, head.args);
|
|
80
|
+
return head;
|
|
81
|
+
}
|
|
82
|
+
case "command":
|
|
83
|
+
maybeAutoRestoreCodexShim(head.command, head.args);
|
|
84
|
+
return head;
|
|
85
|
+
}
|
|
86
|
+
}
|
package/src/cli/status.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { durableBunRuntime } from "../lib/bun-runtime";
|
|
|
2
2
|
import { codexAutoStartEnabled, getConfigPath, getPidPath, readConfigDiagnostics, readPid, readRuntimePort, type RuntimePortState } from "../config";
|
|
3
3
|
import { diagnoseCodexBundledPlugins, type CodexPluginsDiagnostic } from "../codex/plugins-doctor";
|
|
4
4
|
import { findLiveProxy, isOpencodexHealthz, probeHostname } from "../server/proxy-liveness";
|
|
5
|
+
import { directLocalHttpFetch } from "../server/direct-local-http";
|
|
5
6
|
import type { OcxConfig } from "../types";
|
|
6
7
|
import { diagnoseService, serviceLogPath } from "../service";
|
|
7
8
|
import { collectStartupHealth, type StartupHealth } from "../codex/autostart-health";
|
|
@@ -110,12 +111,18 @@ export function resolveStatusPid(
|
|
|
110
111
|
return live ? live.pid : pidFile;
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
export function proxyHealthFailureReason(error: unknown, signal: AbortSignal): "timed out" | "unreachable" {
|
|
115
|
+
return signal.aborted || (error instanceof Error && error.name === "AbortError")
|
|
116
|
+
? "timed out"
|
|
117
|
+
: "unreachable";
|
|
118
|
+
}
|
|
119
|
+
|
|
113
120
|
async function checkProxyHealth(target: ListenTarget): Promise<HealthCheck> {
|
|
114
121
|
const url = target.healthUrl;
|
|
115
122
|
const controller = new AbortController();
|
|
116
123
|
const timer = setTimeout(() => controller.abort(), 800);
|
|
117
124
|
try {
|
|
118
|
-
const response = await
|
|
125
|
+
const response = await directLocalHttpFetch(url, { signal: controller.signal });
|
|
119
126
|
if (!response.ok) {
|
|
120
127
|
const message = `returned HTTP ${response.status}`;
|
|
121
128
|
return { ok: false, url, message, label: `${url} ${message}` };
|
|
@@ -130,7 +137,7 @@ async function checkProxyHealth(target: ListenTarget): Promise<HealthCheck> {
|
|
|
130
137
|
const message = `ok${version}${uptime}`;
|
|
131
138
|
return { ok: true, url, message, label: `${url} ${message}` };
|
|
132
139
|
} catch (error) {
|
|
133
|
-
const reason = error
|
|
140
|
+
const reason = proxyHealthFailureReason(error, controller.signal);
|
|
134
141
|
return { ok: false, url, message: reason, label: `${url} ${reason}` };
|
|
135
142
|
} finally {
|
|
136
143
|
clearTimeout(timer);
|
package/src/cli/v2.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { execFileSync } from "node:child_process";
|
|
14
14
|
import { dirname } from "node:path";
|
|
15
|
-
import { activeCodexConfigPath, getAgentsEnabled, getAgentsMaxDepth, getLogicalMaxThreads, getSubagentDeveloperInstructions, hasAgentsMaxThreads, isMultiAgentV2Enabled, transitionMultiAgentV2 } from "../codex/features";
|
|
15
|
+
import { activeCodexConfigPath, getAgentsEnabled, getAgentsMaxDepth, getLogicalMaxThreads, getMultiAgentModeHintText, getSubagentDeveloperInstructions, hasAgentsMaxThreads, isMultiAgentV2Enabled, setMultiAgentModeHintText, transitionMultiAgentV2 } from "../codex/features";
|
|
16
16
|
|
|
17
17
|
import { commandInvocation, type SpawnInvocation } from "../lib/win-exec";
|
|
18
18
|
import { loadConfig, saveConfig } from "../config";
|
|
@@ -121,11 +121,46 @@ export async function cmdV2(args: string[], deps: V2CliDeps = {}, findPort?: ()
|
|
|
121
121
|
log.log(`agents.max_depth: ${maxDepth ?? "(unset — upstream default 1)"}${v2Active ? " (V1-only — ignored while multi_agent_v2 is enabled)" : ""}`);
|
|
122
122
|
const instructions = getSubagentDeveloperInstructions();
|
|
123
123
|
log.log(`subagent_developer_instructions: ${instructions === null ? "(unset — children inherit)" : instructions === "" ? '"" (clears inherited instructions)' : JSON.stringify(instructions)}`);
|
|
124
|
+
const modeHint = getMultiAgentModeHintText();
|
|
125
|
+
log.log(`multi_agent_mode_hint_text: ${modeHint === null ? "(unset — effort-derived policy: ultra=proactive, else explicit)" : JSON.stringify(modeHint)}`);
|
|
124
126
|
if (isEnabled() && hasMaxThreads()) {
|
|
125
127
|
log.log("WARNING: [agents] max_threads is set — codex refuses to start while multi_agent_v2 is enabled. Remove it from config.toml (concurrency lives in features.multi_agent_v2.max_concurrent_threads_per_session).");
|
|
126
128
|
}
|
|
127
129
|
return 0;
|
|
128
130
|
}
|
|
131
|
+
if (verb === "mode-hint") {
|
|
132
|
+
const value = args[1];
|
|
133
|
+
if (value === undefined) {
|
|
134
|
+
log.error("v2 mode-hint: pass the hint text, or --clear to unset it.");
|
|
135
|
+
return 1;
|
|
136
|
+
}
|
|
137
|
+
if (value === "--clear") {
|
|
138
|
+
const result = setMultiAgentModeHintText(null);
|
|
139
|
+
if (!result.ok) {
|
|
140
|
+
log.error(`v2 mode-hint: ${result.error}`);
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
log.log(result.changed
|
|
144
|
+
? "multi_agent_mode_hint_text cleared — effort-derived policy resumes (new sessions)."
|
|
145
|
+
: "multi_agent_mode_hint_text already unset — nothing to do.");
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
// `--clear` is the only reserved token; hints are otherwise arbitrary
|
|
149
|
+
// nonblank text and may legitimately begin with a hyphen.
|
|
150
|
+
if (value.trim().length === 0) {
|
|
151
|
+
log.error("v2 mode-hint: pass the hint text, or --clear to unset it.");
|
|
152
|
+
return 1;
|
|
153
|
+
}
|
|
154
|
+
const result = setMultiAgentModeHintText(value);
|
|
155
|
+
if (!result.ok) {
|
|
156
|
+
log.error(`v2 mode-hint: ${result.error}`);
|
|
157
|
+
return 1;
|
|
158
|
+
}
|
|
159
|
+
log.log(result.changed
|
|
160
|
+
? `multi_agent_mode_hint_text set (new sessions).`
|
|
161
|
+
: "multi_agent_mode_hint_text already set — nothing to do.");
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
129
164
|
if (verb === "threads") {
|
|
130
165
|
const value = Number((args[1] ?? "").trim());
|
|
131
166
|
if (!Number.isInteger(value) || value < 1) {
|
|
@@ -170,7 +205,7 @@ export async function cmdV2(args: string[], deps: V2CliDeps = {}, findPort?: ()
|
|
|
170
205
|
return 0;
|
|
171
206
|
}
|
|
172
207
|
if (verb !== "on" && verb !== "off") {
|
|
173
|
-
log.error(`v2: unknown verb '${verb}' (expected status|on|off|mode <v1|default|v2>|threads <n>)`);
|
|
208
|
+
log.error(`v2: unknown verb '${verb}' (expected status|on|off|mode <v1|default|v2>|threads <n>|mode-hint <text|--clear>)`);
|
|
174
209
|
return 1;
|
|
175
210
|
}
|
|
176
211
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
-
import type { CodexAccount } from "../types";
|
|
2
|
+
import type { CodexAccount, OcxConfig } from "../types";
|
|
3
|
+
import type { CodexAuthContext } from "./auth-context";
|
|
4
|
+
import { MAIN_CODEX_ACCOUNT_ID } from "./main-account";
|
|
3
5
|
|
|
4
6
|
export const CODEX_ACCOUNT_LOG_LABEL_RE = /^p[a-f0-9]{6}$/;
|
|
5
7
|
|
|
@@ -22,6 +24,17 @@ export function codexAccountLogLabel(account: CodexAccount): string {
|
|
|
22
24
|
: fallbackCodexAccountLogLabel(account.id);
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
/** Effective durable label for a resolved Codex Pool account. */
|
|
28
|
+
export function codexAuthContextLogLabel(
|
|
29
|
+
authCtx: CodexAuthContext,
|
|
30
|
+
config: Pick<OcxConfig, "codexAccounts">,
|
|
31
|
+
): "main" | `p${string}` | undefined {
|
|
32
|
+
if (authCtx.kind !== "pool" && authCtx.kind !== "main-pool") return undefined;
|
|
33
|
+
if (authCtx.accountId === MAIN_CODEX_ACCOUNT_ID) return "main";
|
|
34
|
+
const account = (config.codexAccounts ?? []).find(candidate => candidate.id === authCtx.accountId);
|
|
35
|
+
return account ? codexAccountLogLabel(account) as `p${string}` : undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
25
38
|
export function withCodexAccountLogLabel(
|
|
26
39
|
account: Omit<CodexAccount, "logLabel"> & Partial<Pick<CodexAccount, "logLabel">>,
|
|
27
40
|
existingAccounts: readonly CodexAccount[],
|
|
@@ -491,11 +491,22 @@ export async function getValidCodexToken(id: string): Promise<CodexTokenResult>
|
|
|
491
491
|
throw new TokenRefreshError(reason, `Codex token refresh failed (${reason}); reauthenticate the account.`);
|
|
492
492
|
}
|
|
493
493
|
const data = (await res.json()) as { access_token: string; refresh_token?: string; expires_in: number };
|
|
494
|
+
// Guard against a missing/non-finite/negative expires_in (malformed upstream
|
|
495
|
+
// response): a NaN expiry would never compare as expired, and a negative
|
|
496
|
+
// duration would stamp an already-past expiry — both block refresh semantics.
|
|
497
|
+
const expiresIn =
|
|
498
|
+
typeof data.expires_in === "number" && Number.isFinite(data.expires_in) && data.expires_in >= 0
|
|
499
|
+
? data.expires_in
|
|
500
|
+
: 3600;
|
|
501
|
+
// The computed timestamp itself must stay finite: Number.MAX_VALUE passes
|
|
502
|
+
// Number.isFinite but overflows to Infinity once multiplied by 1000.
|
|
503
|
+
const expiresAt = Date.now() + expiresIn * 1000;
|
|
504
|
+
const safeExpiresAt = Number.isFinite(expiresAt) ? expiresAt : Date.now() + 3600 * 1000;
|
|
494
505
|
|
|
495
506
|
const updated: CodexAccountCredentials = {
|
|
496
507
|
accessToken: data.access_token,
|
|
497
508
|
refreshToken: data.refresh_token ?? lockedCred.refreshToken,
|
|
498
|
-
expiresAt:
|
|
509
|
+
expiresAt: safeExpiresAt,
|
|
499
510
|
chatgptAccountId: lockedCred.chatgptAccountId,
|
|
500
511
|
};
|
|
501
512
|
if (!saveCodexAccountCredentialIfGeneration(id, startGeneration, updated)) {
|
package/src/codex/admission.ts
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
CODEX_PROFILE_PATH,
|
|
34
34
|
DEFAULT_CATALOG_PATH,
|
|
35
35
|
getCodexHome,
|
|
36
|
+
resolveCodexStateDbPath,
|
|
36
37
|
} from "./paths";
|
|
37
38
|
|
|
38
39
|
export type CodexAdmission =
|
|
@@ -162,7 +163,7 @@ export function admitCodexWrite(deps: AdmissionDeps = {}): CodexAdmission {
|
|
|
162
163
|
const config = diagnostics.config;
|
|
163
164
|
const opencodexHome = getConfigDir();
|
|
164
165
|
const integrationRecord = join(opencodexHome, "integrations", "codex.json");
|
|
165
|
-
const historyDb =
|
|
166
|
+
const historyDb = resolveCodexStateDbPath({ codexHome });
|
|
166
167
|
|
|
167
168
|
const canonicalTargets = {
|
|
168
169
|
codexHome,
|
package/src/codex/auth-api.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
saveConfigPreservingClaudeCode,
|
|
6
6
|
withConfigMutationLockSync,
|
|
7
7
|
} from "../config";
|
|
8
|
-
import { withCodexAccountLogLabel } from "./account-label";
|
|
8
|
+
import { codexAccountLogLabel, withCodexAccountLogLabel } from "./account-label";
|
|
9
9
|
import {
|
|
10
10
|
getCodexAccountCredential,
|
|
11
11
|
getValidCodexToken,
|
|
@@ -239,7 +239,7 @@ function poolAccountDto(
|
|
|
239
239
|
email: maskEmail(account.email) ?? account.email,
|
|
240
240
|
...(account.alias !== undefined ? { alias: account.alias } : {}),
|
|
241
241
|
...(plan !== undefined ? { plan } : {}),
|
|
242
|
-
|
|
242
|
+
logLabel: codexAccountLogLabel(account),
|
|
243
243
|
isMain: false,
|
|
244
244
|
paused,
|
|
245
245
|
priority,
|
|
@@ -1228,6 +1228,7 @@ export async function listCodexAuthAccountsSnapshot(
|
|
|
1228
1228
|
id: MAIN_CODEX_ACCOUNT_ID,
|
|
1229
1229
|
email: maskEmail(mainInfo.email) ?? "Codex App login",
|
|
1230
1230
|
plan: mainInfo.plan,
|
|
1231
|
+
logLabel: "main",
|
|
1231
1232
|
isMain: true,
|
|
1232
1233
|
paused: isCodexAccountPaused(runtimeConfig, MAIN_CODEX_ACCOUNT_ID),
|
|
1233
1234
|
priority: getCodexAccountPriority(runtimeConfig, MAIN_CODEX_ACCOUNT_ID),
|