dsh-coding-subscription-oauth 0.7.0 → 0.8.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +312 -296
  2. package/CONTRIBUTING.md +138 -138
  3. package/INSTALL.md +267 -261
  4. package/LICENSE +19 -19
  5. package/NOTICE +11 -11
  6. package/README.de.md +309 -303
  7. package/README.es.md +310 -304
  8. package/README.fr.md +310 -304
  9. package/README.ja.md +310 -304
  10. package/README.ko.md +310 -304
  11. package/README.md +327 -321
  12. package/README.pt-BR.md +310 -304
  13. package/README.ru.md +310 -304
  14. package/README.zh-CN.md +325 -319
  15. package/compatibility/dsh-bom.json +36 -36
  16. package/cordis.patch.yml +13 -13
  17. package/docs/00-project-rules.md +213 -213
  18. package/docs/02-architecture.md +143 -142
  19. package/docs/02-architecture.zh-CN.md +143 -142
  20. package/lib/adapter.d.ts.map +1 -1
  21. package/lib/bin.js +13 -6
  22. package/lib/bin.js.map +3 -3
  23. package/lib/client.js +3 -3
  24. package/lib/client.js.map +4 -4
  25. package/lib/gateway-auth.d.ts +1 -0
  26. package/lib/gateway-auth.d.ts.map +1 -1
  27. package/lib/gateway-config.d.ts +4 -0
  28. package/lib/gateway-config.d.ts.map +1 -1
  29. package/lib/gateway-http.d.ts +5 -0
  30. package/lib/gateway-http.d.ts.map +1 -1
  31. package/lib/gateway-opencode-go.d.ts +22 -0
  32. package/lib/gateway-opencode-go.d.ts.map +1 -0
  33. package/lib/gateway.d.ts +2 -0
  34. package/lib/gateway.d.ts.map +1 -1
  35. package/lib/index.js +278 -63
  36. package/lib/index.js.map +4 -4
  37. package/lib/invariant.js.map +1 -1
  38. package/package.json +229 -226
  39. package/patches/dsh-agy@0.1.2.patch +25 -25
  40. package/scripts/release.mjs +187 -187
  41. package/scripts/smoke-deployed-routes.mjs +146 -146
  42. package/scripts/verify-adapter-host.mjs +70 -0
  43. package/scripts/verify-deployed-catalog.mjs +87 -87
package/README.md CHANGED
@@ -1,321 +1,327 @@
1
-
2
- <!-- banner -->
3
- <div align="center">
4
-
5
- # 🔐 dsh-coding-subscription-oauth
6
-
7
- **v0.7.0** · formerly `dsh-grok-build`
8
-
9
- **Coding-subscription OAuth for [DeepSeek Harness](https://github.com/deepseek-ai/dsh).** Use SuperGrok / X Premium (Grok Build), ChatGPT Plus/Pro (Codex), Kimi Code, Claude Pro/Max and Google Antigravity inside DSH — without a second API-key bill and **without pasting any token into chat.**
10
-
11
- [![License](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)
12
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
13
-
14
- *[English](README.md) · [中文版](README.zh-CN.md) · [日本語](README.ja.md) · [한국어](README.ko.md) · [Português (BR)](README.pt-BR.md) · [Español](README.es.md) · [Français](README.fr.md) · [Deutsch](README.de.md) · [Русский](README.ru.md)*
15
-
16
- </div>
17
-
18
- ---
19
-
20
- > **Upgrade / 升级:** Follow the versioned steps in [`INSTALL.md`](INSTALL.md). Current main pins the shared dispatcher runtime on `dsh-coding-oauth-core@0.1.2` and `undici@7.29.0`, and restricts gateway key reveal/rotate to loopback access; no configuration, credential, data, or route migration is required. Grok Imagine retains its explicit pinned dispatcher. Releases from `0.6.2` onward include the strict Cordis injection startup fix and DSH `0.1.1-rc.2` support; keep profile/config/credential files and restart one existing DSH Web process only after updating.
21
-
22
- ---
23
-
24
- ## Name change
25
-
26
- Published first as **`dsh-grok-build`** when it only covered Grok Build. The current name matches the full coding-subscription OAuth surface.
27
-
28
- | | Use this | Still works |
29
- |---|---|---|
30
- | npm (recommended) | Current release is `0.7.0`: `dsh plugin --profile web add dsh-coding-subscription-oauth@0.7.0` | No legacy npm package was published |
31
- | GitHub / development | [`dsh-coding-subscription-oauth`](https://github.com/lninghaha/dsh-coding-subscription-oauth) | Previous GitHub repo `dsh-grok-build` was removed |
32
- | CLI | `dsh-coding-oauth` | `dsh-grok-build` |
33
- | Cordis plugin id | `llm-grok-build-oauth` | unchanged |
34
- | Settings HTTP API | `/plugins/dsh-grok-build/*` | unchanged |
35
- | Credential files | `$DSH_HOME/.grok-build-auth.json` and the other `*-oauth-auth.json` files | unchanged |
36
-
37
- ## ✨ Features
38
-
39
- - 🧽 **Bring your own subscription** — SuperGrok, ChatGPT Plus/Pro, Kimi Code, Claude Pro/Max; no extra pay-as-you-go key.
40
- - 🔑 **Local OAuth, no key-pasting** — authorize in Settings or CLI; access/refresh tokens never enter chat, logs or HTTP status.
41
- - 🧩 **One plugin, five providers** — Grok Build (`cli-chat-proxy.grok.com`), Codex, Kimi Code, Claude Code and Google Antigravity.
42
- - 🛡️ **Secure by design** — credential files are owner-only `0600`, atomically written, cross-process locked.
43
- - ⚙️ **Dynamic catalog** — the selector lists only signed-in routes, labelled `(OAuth)`, including grok-4.6 `xhigh`.
44
- - 🌐 **Proxy-aware** — proxies only reviewed subscription domains; Kimi China stays direct by default.
45
- - 📥 **Manual CLI Pull** — Settings discovers allowlisted official Grok/Codex/Kimi/Claude CLI OAuth files read-only; you pull a one-way copy after preview and overwrite confirmation.
46
- - 🗂️ **Tabbed Settings** — Accounts, Gateway, Capabilities, and About; remote hosts prefer device-code sign-in with quieter CLI-missing tips; signed-in cards stay collapsed until expanded.
47
- - 🎛️ **Optional capabilities, default off** — Codex search, usage/quota, image generate/edit, Fast, and Grok Imagine apply live when you turn them on. An additional default-off switch lets non-Codex model routes call Codex image tools while preserving Codex sign-in, session, and attachment-ownership checks.
48
- - 🔌 **Opt-in local API gateway** — default-off loopback OpenAI/Anthropic-compatible server for your own tools, with copyable base URLs and Bearer key; never a public relay.
49
-
50
- ## Problems this plugin solves
51
-
52
- These are the searches and DSH errors that usually lead here. If one of them is your tab title, you are in the right repo.
53
-
54
- | You searched / saw | What was actually broken | What this plugin does |
55
- |---|---|---|
56
- | SuperGrok / X Premium in DSH, “Grok Build vs `api.x.ai`” | The built-in `xai` route is the **pay-as-you-go API**. Coding-plan inference is `cli-chat-proxy.grok.com` | Dedicated `grok-build` route + official CLI fingerprint headers (`X-XAI-Token-Auth`, `x-grok-client-identifier`, `x-grok-client-version`) so you do not get a silent 403 |
57
- | `本轮运行失败` **API key is invalid** / `AUTH` mid-turn | The GUI maps **every** `AUTH` code to that banner. Often the OAuth access token just expired (Kimi ~15 min) | Refresh **5 minutes** before expiry; on a 401, invalidate the stored token and **retry the step** after refresh |
58
- | `INVALID_REPLAY_STATE` on the second Codex / Kimi turn | Replay state still carried the native pi-ai provider id after the Harness route alias | Keep the Harness route id in replay state and heal older poisoned messages |
59
- | grok-4.6 **xhigh** / Extra High Effort missing | Live `GET /v1/models-v2` already returns `reasoning_efforts` including `xhigh`; cloning the grok-4.5 template hides it (pi-ai treats absent `xhigh` as unsupported) | Parse live `reasoning_efforts` into `thinkingLevelMap`. grok-4.6 gets `xhigh`; grok-4.5 stays low/medium/high |
60
- | Kimi Code 401, or requests going out as Anthropic `x-api-key` | The OAuth token was attached as an Anthropic key | Wire **only** `Authorization: Bearer` on `api.kimi.com/coding` |
61
- | Unsigned-in Grok / Codex / Claude still in the model picker | Every registered route was listed | Unauthenticated routes expose **no models**; signed-in names show `(OAuth)` |
62
- | Device login on a **remote / headless** DSH | Browser PKCE cannot reach `localhost` | Device-code for Grok, Codex and Kimi; Claude accepts a pasted localhost redirect URL |
63
- | Proxy works for Grok/Codex but breaks Kimi in China | One global `HTTPS_PROXY` | Allowlisted proxy; Kimi stays **direct** unless `proxyKimi: true`. `auth.kimi.com` `api.moonshot.cn` |
64
- | ChatGPT Plus / Claude Pro in DSH without another API bill | Separate OpenAI / Anthropic API keys | Local OAuth on `codex-oauth` / `claude-code-oauth`, coexist with existing `openai` / `kimi-coding` API-key routes |
65
-
66
- Grok Build device login, live `/v1/models-v2` and Responses streaming are verified on real deployments. Codex / Kimi / Claude reuse `@earendil-works/pi-ai` native OAuth instead of re-implementing vendor flows.
67
-
68
- ## Supported providers
69
-
70
- | Provider | Route | Auth | Coexists with |
71
- |---|---|---|---|
72
- | **xAI Grok Build** | `grok-build` | SuperGrok / X Premium OAuth | `xai` |
73
- | **OpenAI Codex** | `codex-oauth` · optional `codex-oauth-fast` | ChatGPT Plus/Pro OAuth | `openai` |
74
- | **Kimi Code** | `kimi-code-oauth` | Kimi Code OAuth | `kimi-coding` |
75
- | **Claude Code** | `claude-code-oauth` | Claude Pro/Max OAuth | |
76
- | **Google Antigravity** | `agy` | `dsh-agy` Google OAuth | |
77
-
78
- > Grok Build's device login, dynamic `/v1/models-v2` catalog and Responses streaming are verified on real deployments. Codex/Kimi/Claude reuse the provider-native OAuth/refresh from `@earendil-works/pi-ai` instead of re-implementing vendor flows.
79
-
80
- ## 🚀 Quick start
81
-
82
- ```bash
83
- # 1. install the current npm release into the web profile
84
- dsh plugin --profile web add dsh-coding-subscription-oauth@0.7.0
85
-
86
- # 2. optional Google Antigravity (pinned, reviewed version)
87
- dsh plugin --profile web add dsh-agy@0.1.2
88
-
89
- # 3. restart the existing DSH Web process with its configured process manager
90
- # `dsh web` is the official CLI alias for the web profile, not a service-unit name.
91
- ```
92
-
93
- Then open **Settings → Coding OAuth** and sign in to any provider. Done — pick your authenticated model from the selector.
94
-
95
- ## 📚 Table of contents
96
-
97
- - [Name change](#name-change)
98
- - [Features](#-features)
99
- - [Problems this plugin solves](#problems-this-plugin-solves)
100
- - [Supported providers](#supported-providers)
101
- - [Quick start](#-quick-start)
102
- - [Install](#install)
103
- - [Settings page](#settings-page)
104
- - [Optional capabilities](#optional-capabilities)
105
- - [Local API gateway](#local-api-gateway)
106
- - [CLI](#cli)
107
- - [Kimi in China](#kimi-in-china)
108
- - [Network proxy](#network-proxy)
109
- - [Resilience](#resilience)
110
- - [Credentials](#credentials)
111
- - [Architecture](#architecture)
112
- - [Technical notes](#technical-notes)
113
- - [Compliance](#compliance)
114
- - [Documentation](#documentation)
115
- - [Related](#related)
116
- - [Contributing](#contributing)
117
- - [License](#license)
118
-
119
- ## Install
120
-
121
- Requires DeepSeek Harness `0.1.1-rc.2` (verified BOM) and Node.js 22.19+. Unverified candidates such as `0.1.5-rc.1` are recorded in `compatibility/dsh-bom.json` only — see [INSTALL.md](INSTALL.md).
122
-
123
- ```bash
124
- # current npm release
125
- dsh plugin --profile web add dsh-coding-subscription-oauth@0.7.0
126
-
127
- # development / alternative: from GitHub
128
- dsh plugin --profile web add github:lninghaha/dsh-coding-subscription-oauth
129
-
130
- # local development checkout (alternative)
131
- # dsh plugin --profile web add ./dsh-coding-subscription-oauth
132
- ```
133
-
134
- Restart the existing DSH Web process after installing. Maintainers can verify a live deployment from a source checkout (npm installs do not include these scripts):
135
-
136
- ```bash
137
- pnpm run verify:deployed # checks real /api/llm.models + OAuth state
138
- DSH_EXPECT_AGY_AUTH=signed-in pnpm run verify:deployed # if Google is signed in
139
-
140
- DSH_RESTORE_PROVIDER=openai \
141
- DSH_RESTORE_MODEL=gpt-5.6-sol \
142
- DSH_RESTORE_REASONING=max \
143
- pnpm run smoke:deployed # real Codex/Kimi tool-calls + second-turn replay
144
- ```
145
-
146
- > `smoke:deployed` creates temporary sessions, exercises Codex and Kimi tool-calls plus a second user turn (regression coverage for `INVALID_REPLAY_STATE`), restores the declared default model, then archives the sessions.
147
-
148
- ## Settings page
149
-
150
- Open **Settings → Coding OAuth**. The page uses segmented tabs — **Accounts**, **Gateway**, **Capabilities**, and **About** — with live status hints, semantic badges, and skeleton loading states. On a remote (non-loopback) host, Accounts prefers device-code sign-in and collapses noisy CLI-missing hints into one tip. Signed-in provider cards collapse to a compact summary; expand one for model search/filter, quota progress bars, or CLI Pull controls. Gateway adds quick-setup snippets (cURL / Python / IDE), and Capabilities uses toggle switches with dependency-aware disabled states plus Imagine status.
151
-
152
- DSH Web remains loopback-only. Remote Settings must travel through an SSH tunnel or an owner-authenticated HTTPS reverse proxy. The plugin prefers a DSH-native `ownerRequestPolicy`; its fallback requires the real trusted TCP peer, exact HTTPS Origin/Host, same-origin Fetch Metadata, a proxy-injected owner proof, and an independent mutation CSRF proof. Forwarded headers never grant access, and incomplete policy fails closed. See [INSTALL.md](INSTALL.md#安全访问远程-settings).
153
-
154
- <table>
155
- <tr>
156
- <td align="center" valign="top" width="33%">
157
- <a href="media/en/settings_accounts.png"><img src="media/en/settings_accounts.png" alt="Coding OAuth Accounts tab" width="280" /></a><br />
158
- <sub>Accounts</sub>
159
- </td>
160
- <td align="center" valign="top" width="33%">
161
- <a href="media/en/settings_gateway.png"><img src="media/en/settings_gateway.png" alt="Coding OAuth Gateway tab" width="280" /></a><br />
162
- <sub>Gateway</sub>
163
- </td>
164
- <td align="center" valign="top" width="33%">
165
- <a href="media/en/settings_capabilities.png"><img src="media/en/settings_capabilities.png" alt="Coding OAuth Capabilities tab" width="280" /></a><br />
166
- <sub>Capabilities</sub>
167
- </td>
168
- </tr>
169
- </table>
170
-
171
- | Provider | Methods |
172
- |---|---|
173
- | Grok | auth code · device code · model selection |
174
- | Codex | device code (recommended on remote DSH) · browser PKCE |
175
- | Kimi | device code |
176
- | Claude | browser PKCE (remote browser can paste the full localhost redirect URL) |
177
- | Antigravity | `dsh-agy` install status + profile-local CLI commands |
178
-
179
- Use device code when the DSH host is remote. Browser/PKCE sign-in opens the provider URL; if the localhost callback cannot reach this DSH host, paste either the returned authorization code or the complete redirect URL into the waiting Settings card.
180
-
181
- Settings also **discovers** allowlisted official Grok / Codex / Kimi / Claude CLI OAuth files (read-only). Synchronization is an explicit one-way **Pull** not auto-import: discover preview → conflict/fingerprint check → confirm overwrite. Official CLI files are never written. Reads refuse symlinks, non-regular files, non-owner files, group/other access, and oversized documents (`O_NOFOLLOW`). Preview tickets are one-use, expire in five minutes, and are capped at 32.
182
-
183
- The selector only lists routes that completed authentication; unauthenticated providers return an empty list. Provider names carry `(OAuth)`, and the catalog refreshes via `llm/adapters-updated` after sign-in/out.
184
-
185
- ## Optional capabilities
186
-
187
- All eight switches start **off** and apply **live** (no restart): `codexSearch`, `codexImages`, `codexImageEdits`, `codexImagesAnyModel`, `codexUsage`, `codexFast`, `grokImagineImage`, and `grokImagineVideo`. `codexImagesAnyModel` only relaxes the calling-model route gate; it still requires signed-in Codex, `codexImages` (and the edits flag for edit), and keeps session attachment ownership and edit authorization. Numeric controls are `searchResults` (1–20, default 5), `imageCount` (1–4, default 1), and `videoArtifactTtlMs` (1 hour–7 days, default 7 days; the UI shows 1–168 hours). Lowering video retention shortens and cleans existing artifacts immediately; raising it affects only artifacts created afterward. Administrators may provide secret-free composition defaults under plugin config `capabilities`; live user settings in the `coding-subscription-oauth` settings section override that base, and omitting it keeps every switch off.
188
-
189
- `codex-oauth-fast` is advertised only after a **fresh live catalog** lists at least one `priority`-eligible model. Those requests send `service_tier: priority` plus a routing hint. The UI says **Fast requested** and never guarantees latency or that upstream will honor the request.
190
-
191
- Codex search, usage, and images are **opt-in** private `chatgpt.com/backend-api` endpoints. Image generation uses the fixed model `gpt-image-2`. Image edit accepts only current-session top-level attachment ids that this session already owns.
192
-
193
- Grok Imagine calls official `https://api.x.ai` with `grok-imagine-image-2.0` and `grok-imagine-video-1.5`. It uses a **separate** DSH credential reference `XAI_API_KEY` — never Grok OAuth and never a process-env fallback. Generated outputs are fetched under MIME / size / time / redirect / DNS controls from frozen hosts `imgen.x.ai`, `videogen.x.ai`, and `vidgen.x.ai`, stored privately (256 MiB hard caps for one object and aggregate unique bytes, seven days), and served only on same-origin loopback routes.
194
-
195
- ## Local API gateway
196
-
197
- Default **off**. When enabled it starts an isolated `node:http` server (not the DSH web port) on `127.0.0.1:18080` and reuses the same signed-in OAuth sessions:
198
-
199
- ```yaml
200
- gateway:
201
- enabled: false
202
- bind: 127.0.0.1
203
- port: 18080
204
- ```
205
-
206
- Endpoints: `GET /healthz`, `GET /v1/models`, `POST /v1/chat/completions`, `POST /v1/responses`, `POST /v1/messages`. A Bearer key is stored at `$DSH_HOME/.coding-oauth-gateway.json` (`0600`).
207
-
208
- On the **Gateway** tab, copy the OpenAI base URL (for example, `http://127.0.0.1:18080/v1`), the Anthropic base URL, or the current Bearer key without rotating it. Key reveal is loopback-only and is never persisted to browser storage. Key rotation requires confirmation. Edit the listen port with **Apply** or fill it with **Random** (`18100`–`18999`); the selected port is persisted in the owner-only gateway document, and a running listener rebinds to it. Bind remains YAML-only; a non-loopback bind requires a key. This is not a remote relay.
209
-
210
- ## CLI
211
-
212
- ```bash
213
- # `dsh-grok-build` remains a command alias
214
- dsh-coding-oauth login [--pkce] | import | status | logout
215
-
216
- # newer providers
217
- dsh-coding-oauth login codex --device-auth | codex --browser | kimi | claude
218
- dsh-coding-oauth status all
219
- dsh-coding-oauth logout codex
220
-
221
- # Antigravity (install into web profile first)
222
- dsh plugin --profile web exec dsh-agy login --headless
223
- ```
224
-
225
- > `dsh-agy` CLI edits the account pool outside the DSH process, so it can't emit an in-process catalog event — close and reopen the model selector after signing in/out.
226
-
227
- ## Kimi in China
228
-
229
- Kimi Code subscription OAuth uses `https://auth.kimi.com`; inference uses `https://api.kimi.com/coding`. `https://api.moonshot.cn/v1` is the pay-as-you-go **Moonshot Open Platform** API-key channel — there is no switchable "China OAuth endpoint". This plugin uses a separate `kimi-code-oauth` route and doesn't affect an existing `kimi-coding` API-key config.
230
-
231
- ## Network proxy
232
-
233
- Priority: `config.proxy` `CODING_OAUTH_PROXY` → `GROK_BUILD_PROXY` → `HTTPS_PROXY`/`HTTP_PROXY`.
234
-
235
- ```yaml
236
- - id: llm-grok-build-oauth
237
- config:
238
- proxy: http://127.0.0.1:7890
239
- proxyKimi: false
240
- ```
241
-
242
- Only reviewed subscription domains are proxied (xAI/Grok, OpenAI Codex, Claude/Anthropic, Google Antigravity); all other DSH traffic keeps its original dispatcher. Kimi stays direct by default and only uses the proxy when `proxyKimi: true`.
243
-
244
- ## Resilience
245
-
246
- OAuth access tokens refresh proactively **five minutes** before their stored expiry (pi-ai 0.84+), so a request never rides a token into its final seconds. If an upstream still rejects a locally-valid token with 401/403 — server-side revocation or clock skew — the plugin backdates the stored credential and the retried step refreshes before reuse, recovering transparently instead of failing the turn.
247
-
248
- Request retries use the harness retry policy: transient failures (`RATE_LIMIT`/`SERVER`/`TIMEOUT`/`TRANSPORT`/`EMPTY_RESPONSE`) **and `AUTH`** retry with exponential backoff (default 5 retries, 5 s → 10 s → 20 s → 40 s → 80 s, ~155 s stacked, 10% jitter). xAI “at capacity / high demand / priority processing” finish messages are remapped to `RATE_LIMIT` so they enter this policy (pi-ai would otherwise label them `PI_AI_ERROR` when upstream `error.code` is null). Quota exhaustion and a dead refresh token are **not** retried — they fail fast with the real message and a sign-in prompt. Override per deployment:
249
-
250
- ```yaml
251
- - id: llm-grok-build-oauth
252
- config:
253
- retryPolicy:
254
- mode: normal
255
- maxRetries: 5
256
- retryableCodes: [EMPTY_RESPONSE, RATE_LIMIT, SERVER, TIMEOUT, TRANSPORT, AUTH]
257
- backoff: { initialDelayMs: 5000, maxDelayMs: 80000, jitterRatio: 0.1 }
258
- ```
259
-
260
- ## Credentials
261
-
262
- Owner-only `0600`, atomically written, cross-process file lock:
263
-
264
- - `$DSH_HOME/.grok-build-auth.json`
265
- - `$DSH_HOME/.codex-oauth-auth.json`
266
- - `$DSH_HOME/.kimi-code-oauth-auth.json`
267
- - `$DSH_HOME/.claude-code-oauth-auth.json`
268
-
269
- Selection caches live in the matching `*-models.json` files. Grok Imagine uses a separate DSH credential named `XAI_API_KEY` (not the Grok OAuth file). **No HTTP status, log or UI may ever return a token.**
270
-
271
- ## Architecture
272
-
273
- ```mermaid
274
- flowchart LR
275
- subgraph DSH["DSH Harness"]
276
- UI[Settings / Web · Coding OAuth] --> LLM[llm route]
277
- LLM --> ALIA[Route-alias adapter]
278
- end
279
- ALIA --> PI[pi-ai native provider<br/>OAuth · refresh · stream]
280
- PI --> GROK[Grok Build]
281
- PI --> COD[Codex]
282
- PI --> KIMI[Kimi]
283
- PI --> CLAU[Claude]
284
- AGY[dsh-agy plugin] --> GAL[Google Antigravity]
285
- ```
286
-
287
- ## Technical notes
288
-
289
- - **Grok Build**: Responses API on `cli-chat-proxy.grok.com/v1` (not `api.x.ai`), CLI fingerprint headers, live `/v1/models-v2` including grok-4.6 `reasoning.effort: xhigh`.
290
- - **Codex/Kimi/Claude**: pi-ai native providers handle OAuth and refresh; the route-alias adapter maps them to native ids so multi-turn replay does not throw `INVALID_REPLAY_STATE`.
291
- - The Kimi access token is explicitly converted to `Authorization: Bearer` — never mistakenly an Anthropic `x-api-key`.
292
- - **Codex Fast / private endpoints**: `codex-oauth-fast` is opt-in and fail-closed on a stale catalog; search, usage and `gpt-image-2` images stay off until enabled.
293
- - **Grok Imagine**: official `api.x.ai` only, `XAI_API_KEY` through DSH credentials, same-origin download routes under `/plugins/dsh-grok-build/imagine/*`.
294
- - Google Antigravity is **not** reverse-engineered here; it uses a version-pinned dedicated DSH plugin.
295
-
296
- ## Compliance
297
-
298
- Using coding subscriptions through a third-party harness may sit in a gray area of each vendor's terms and can trigger quota, regional or account-risk controls. **Use only your own accounts**; this project does not support bulk accounts, quota resale, remote relay, paywall bypass or client impersonation. For commercial use, prefer the vendors' official API-key channels.
299
-
300
- ## Documentation
301
-
302
- | Doc | Purpose |
303
- |---|---|
304
- | [`INSTALL.md`](INSTALL.md) | Installation & usage details |
305
- | [`CHANGELOG.md`](CHANGELOG.md) | Release history |
306
- | [`docs/00-project-rules.md`](docs/00-project-rules.md) | Versioning, release loop, publish vs local-only split |
307
- | [`docs/02-architecture.md`](docs/02-architecture.md) | Internal architecture (routes, data flow, modules, API) · [中文](docs/02-architecture.zh-CN.md) |
308
- | [`docs/03-dsh-alpha-smoke.md`](docs/03-dsh-alpha-smoke.md) | Isolated smoke on unverified DSH candidates (`0.1.2-alpha.*`, `0.1.5-rc.1`) |
309
- | [`CONTRIBUTING.md`](CONTRIBUTING.md) | Contribution guide |
310
-
311
- ## Related
312
-
313
- - [`dsh-agy`](https://www.npmjs.com/package/dsh-agy) separate pinned plugin for Google Antigravity.
314
-
315
- ## Contributing
316
-
317
- Contributions of all kinds are welcome — features, docs, translations, bug reports. See **[CONTRIBUTING](CONTRIBUTING.md)** for the flow, commit conventions and the release loop. If your language isn't listed, PR a README translation and we'll add it to the table above.
318
-
319
- ## License
320
-
321
- [Apache-2.0](LICENSE) · see [NOTICE](NOTICE). Portions derived from the [dsh-xai](https://github.com/MirDie/dsh-xai) project (Apache-2.0).
1
+
2
+ <!-- banner -->
3
+ <div align="center">
4
+
5
+ # 🔐 dsh-coding-subscription-oauth
6
+
7
+ **v0.8.0** · formerly `dsh-grok-build`
8
+
9
+ **Coding-subscription OAuth for [DeepSeek Harness](https://github.com/deepseek-ai/dsh).** Use SuperGrok / X Premium (Grok Build), ChatGPT Plus/Pro (Codex), Kimi Code, Claude Pro/Max and Google Antigravity inside DSH — without a second API-key bill and **without pasting any token into chat.**
10
+
11
+ [![License](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)
12
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
13
+
14
+ *[English](README.md) · [中文版](README.zh-CN.md) · [日本語](README.ja.md) · [한국어](README.ko.md) · [Português (BR)](README.pt-BR.md) · [Español](README.es.md) · [Français](README.fr.md) · [Deutsch](README.de.md) · [Русский](README.ru.md)*
15
+
16
+ </div>
17
+
18
+ ---
19
+
20
+ > **Upgrade / 升级:** Follow the versioned steps in [`INSTALL.md`](INSTALL.md). `0.8.0` adds opt-in OpenCode Go compatibility (sticky `x-opencode-session` on the local gateway). Current main pins the shared dispatcher runtime on `dsh-coding-oauth-core@0.1.2` and `undici@7.29.0`, and restricts gateway key reveal/rotate to loopback access; no configuration, credential, data, or route migration is required. Grok Imagine retains its explicit pinned dispatcher. Releases from `0.6.2` onward include the strict Cordis injection startup fix and DSH `0.1.1-rc.2` support; keep profile/config/credential files and restart one existing DSH Web process only after updating.
21
+
22
+ ---
23
+
24
+ ## Name change
25
+
26
+ Published first as **`dsh-grok-build`** when it only covered Grok Build. The current name matches the full coding-subscription OAuth surface.
27
+
28
+ | | Use this | Still works |
29
+ |---|---|---|
30
+ | npm (recommended) | Current release is `0.8.0`: `dsh plugin --profile web add dsh-coding-subscription-oauth@0.8.0` | No legacy npm package was published |
31
+ | GitHub / development | [`dsh-coding-subscription-oauth`](https://github.com/lninghaha/dsh-coding-subscription-oauth) | Previous GitHub repo `dsh-grok-build` was removed |
32
+ | CLI | `dsh-coding-oauth` | `dsh-grok-build` |
33
+ | Cordis plugin id | `llm-grok-build-oauth` | unchanged |
34
+ | Settings HTTP API | `/plugins/dsh-grok-build/*` | unchanged |
35
+ | Credential files | `$DSH_HOME/.grok-build-auth.json` and the other `*-oauth-auth.json` files | unchanged |
36
+
37
+ ## ✨ Features
38
+
39
+ - 🧽 **Bring your own subscription** — SuperGrok, ChatGPT Plus/Pro, Kimi Code, Claude Pro/Max; no extra pay-as-you-go key.
40
+ - 🔑 **Local OAuth, no key-pasting** — authorize in Settings or CLI; access/refresh tokens never enter chat, logs or HTTP status.
41
+ - 🧩 **One plugin, five providers** — Grok Build (`cli-chat-proxy.grok.com`), Codex, Kimi Code, Claude Code and Google Antigravity.
42
+ - 🛡️ **Secure by design** — credential files are owner-only `0600`, atomically written, cross-process locked.
43
+ - ⚙️ **Dynamic catalog** — the selector lists only signed-in routes, labelled `(OAuth)`, including grok-4.6 `xhigh`.
44
+ - 🌐 **Proxy-aware** — proxies only reviewed subscription domains; Kimi China stays direct by default.
45
+ - 📥 **Manual CLI Pull** — Settings discovers allowlisted official Grok/Codex/Kimi/Claude CLI OAuth files read-only; you pull a one-way copy after preview and overwrite confirmation.
46
+ - 🗂️ **Tabbed Settings** — Accounts, Gateway, Capabilities, and About; remote hosts prefer device-code sign-in with quieter CLI-missing tips; signed-in cards stay collapsed until expanded.
47
+ - 🎛️ **Optional capabilities, default off** — Codex search, usage/quota, image generate/edit, Fast, and Grok Imagine apply live when you turn them on. An additional default-off switch lets non-Codex model routes call Codex image tools while preserving Codex sign-in, session, and attachment-ownership checks.
48
+ - 🔌 **Opt-in local API gateway** — default-off loopback OpenAI/Anthropic-compatible server for your own tools, with copyable base URLs and Bearer key; never a public relay.
49
+ - 🤝 **Opt-in OpenCode Go compatibility** — gateway can proxy chat completions to OpenCode Go and inject sticky `x-opencode-session` (avoids `MissingSessionID` when clients omit session affinity); default off.
50
+
51
+ ## Problems this plugin solves
52
+
53
+ These are the searches and DSH errors that usually lead here. If one of them is your tab title, you are in the right repo.
54
+
55
+ | You searched / saw | What was actually broken | What this plugin does |
56
+ |---|---|---|
57
+ | SuperGrok / X Premium in DSH, “Grok Build vs `api.x.ai`” | The built-in `xai` route is the **pay-as-you-go API**. Coding-plan inference is `cli-chat-proxy.grok.com` | Dedicated `grok-build` route + official CLI fingerprint headers (`X-XAI-Token-Auth`, `x-grok-client-identifier`, `x-grok-client-version`) so you do not get a silent 403 |
58
+ | `本轮运行失败` **API key is invalid** / `AUTH` mid-turn | The GUI maps **every** `AUTH` code to that banner. Often the OAuth access token just expired (Kimi ~15 min) | Refresh **5 minutes** before expiry; on a 401, invalidate the stored token and **retry the step** after refresh |
59
+ | `INVALID_REPLAY_STATE` on the second Codex / Kimi turn | Replay state still carried the native pi-ai provider id after the Harness route alias | Keep the Harness route id in replay state and heal older poisoned messages |
60
+ | grok-4.6 **xhigh** / Extra High Effort missing | Live `GET /v1/models-v2` already returns `reasoning_efforts` including `xhigh`; cloning the grok-4.5 template hides it (pi-ai treats absent `xhigh` as unsupported) | Parse live `reasoning_efforts` into `thinkingLevelMap`. grok-4.6 gets `xhigh`; grok-4.5 stays low/medium/high |
61
+ | Kimi Code 401, or requests going out as Anthropic `x-api-key` | The OAuth token was attached as an Anthropic key | Wire **only** `Authorization: Bearer` on `api.kimi.com/coding` |
62
+ | Unsigned-in Grok / Codex / Claude still in the model picker | Every registered route was listed | Unauthenticated routes expose **no models**; signed-in names show `(OAuth)` |
63
+ | Device login on a **remote / headless** DSH | Browser PKCE cannot reach `localhost` | Device-code for Grok, Codex and Kimi; Claude accepts a pasted localhost redirect URL |
64
+ | Proxy works for Grok/Codex but breaks Kimi in China | One global `HTTPS_PROXY` | Allowlisted proxy; Kimi stays **direct** unless `proxyKimi: true`. `auth.kimi.com` `api.moonshot.cn` |
65
+ | ChatGPT Plus / Claude Pro in DSH without another API bill | Separate OpenAI / Anthropic API keys | Local OAuth on `codex-oauth` / `claude-code-oauth`, coexist with existing `openai` / `kimi-coding` API-key routes |
66
+ | OpenCode Go chat fails with `MissingSessionID` / missing `x-opencode-session` | Clients do not send sticky session headers | Opt-in gateway OpenCode Go proxy injects sticky `x-opencode-session` |
67
+
68
+ Grok Build device login, live `/v1/models-v2` and Responses streaming are verified on real deployments. Codex / Kimi / Claude reuse `@earendil-works/pi-ai` native OAuth instead of re-implementing vendor flows.
69
+
70
+ ## Supported providers
71
+
72
+ | Provider | Route | Auth | Coexists with |
73
+ |---|---|---|---|
74
+ | **xAI Grok Build** | `grok-build` | SuperGrok / X Premium OAuth | `xai` |
75
+ | **OpenAI Codex** | `codex-oauth` · optional `codex-oauth-fast` | ChatGPT Plus/Pro OAuth | `openai` |
76
+ | **Kimi Code** | `kimi-code-oauth` | Kimi Code OAuth | `kimi-coding` |
77
+ | **Claude Code** | `claude-code-oauth` | Claude Pro/Max OAuth | — |
78
+ | **Google Antigravity** | `agy` | `dsh-agy` Google OAuth | |
79
+
80
+ > Grok Build's device login, dynamic `/v1/models-v2` catalog and Responses streaming are verified on real deployments. Codex/Kimi/Claude reuse the provider-native OAuth/refresh from `@earendil-works/pi-ai` instead of re-implementing vendor flows.
81
+
82
+ ## 🚀 Quick start
83
+
84
+ ```bash
85
+ # 1. install the current npm release into the web profile
86
+ dsh plugin --profile web add dsh-coding-subscription-oauth@0.8.0
87
+
88
+ # 2. optional — Google Antigravity (pinned, reviewed version)
89
+ dsh plugin --profile web add dsh-agy@0.1.2
90
+
91
+ # 3. restart the existing DSH Web process with its configured process manager
92
+ # `dsh web` is the official CLI alias for the web profile, not a service-unit name.
93
+ ```
94
+
95
+ Then open **Settings Coding OAuth** and sign in to any provider. Done — pick your authenticated model from the selector.
96
+
97
+ ## 📚 Table of contents
98
+
99
+ - [Name change](#name-change)
100
+ - [Features](#-features)
101
+ - [Problems this plugin solves](#problems-this-plugin-solves)
102
+ - [Supported providers](#supported-providers)
103
+ - [Quick start](#-quick-start)
104
+ - [Install](#install)
105
+ - [Settings page](#settings-page)
106
+ - [Optional capabilities](#optional-capabilities)
107
+ - [Local API gateway](#local-api-gateway)
108
+ - [CLI](#cli)
109
+ - [Kimi in China](#kimi-in-china)
110
+ - [Network proxy](#network-proxy)
111
+ - [Resilience](#resilience)
112
+ - [Credentials](#credentials)
113
+ - [Architecture](#architecture)
114
+ - [Technical notes](#technical-notes)
115
+ - [Compliance](#compliance)
116
+ - [Documentation](#documentation)
117
+ - [Related](#related)
118
+ - [Contributing](#contributing)
119
+ - [License](#license)
120
+
121
+ ## Install
122
+
123
+ Requires DeepSeek Harness `0.1.1-rc.2` (verified BOM) and Node.js 22.19+. Unverified candidates such as `0.1.5-rc.1` are recorded in `compatibility/dsh-bom.json` only — see [INSTALL.md](INSTALL.md). OAuth profiles initialize an empty `modelErrors` map so candidate hosts do not crash on model resolution (`#38`).
124
+
125
+ ```bash
126
+ # current npm release
127
+ dsh plugin --profile web add dsh-coding-subscription-oauth@0.8.0
128
+
129
+ # development / alternative: from GitHub
130
+ dsh plugin --profile web add github:lninghaha/dsh-coding-subscription-oauth
131
+
132
+ # local development checkout (alternative)
133
+ # dsh plugin --profile web add ./dsh-coding-subscription-oauth
134
+ ```
135
+
136
+ Restart the existing DSH Web process after installing. Maintainers can verify a live deployment from a source checkout (npm installs do not include these scripts):
137
+
138
+ ```bash
139
+ pnpm run verify:deployed # checks real /api/llm.models + OAuth state
140
+ DSH_EXPECT_AGY_AUTH=signed-in pnpm run verify:deployed # if Google is signed in
141
+
142
+ DSH_RESTORE_PROVIDER=openai \
143
+ DSH_RESTORE_MODEL=gpt-5.6-sol \
144
+ DSH_RESTORE_REASONING=max \
145
+ pnpm run smoke:deployed # real Codex/Kimi tool-calls + second-turn replay
146
+ ```
147
+
148
+ > `smoke:deployed` creates temporary sessions, exercises Codex and Kimi tool-calls plus a second user turn (regression coverage for `INVALID_REPLAY_STATE`), restores the declared default model, then archives the sessions.
149
+
150
+ ## Settings page
151
+
152
+ Open **Settings Coding OAuth**. The page uses segmented tabs **Accounts**, **Gateway**, **Capabilities**, and **About** with live status hints, semantic badges, and skeleton loading states. On a remote (non-loopback) host, Accounts prefers device-code sign-in and collapses noisy CLI-missing hints into one tip. Signed-in provider cards collapse to a compact summary; expand one for model search/filter, quota progress bars, or CLI Pull controls. Gateway adds quick-setup snippets (cURL / Python / IDE), and Capabilities uses toggle switches with dependency-aware disabled states plus Imagine status.
153
+
154
+ DSH Web remains loopback-only. Remote Settings must travel through an SSH tunnel or an owner-authenticated HTTPS reverse proxy. The plugin prefers a DSH-native `ownerRequestPolicy`; its fallback requires the real trusted TCP peer, exact HTTPS Origin/Host, same-origin Fetch Metadata, a proxy-injected owner proof, and an independent mutation CSRF proof. Forwarded headers never grant access, and incomplete policy fails closed. See [INSTALL.md](INSTALL.md#安全访问远程-settings).
155
+
156
+ <table>
157
+ <tr>
158
+ <td align="center" valign="top" width="33%">
159
+ <a href="media/en/settings_accounts.png"><img src="media/en/settings_accounts.png" alt="Coding OAuth Accounts tab" width="280" /></a><br />
160
+ <sub>Accounts</sub>
161
+ </td>
162
+ <td align="center" valign="top" width="33%">
163
+ <a href="media/en/settings_gateway.png"><img src="media/en/settings_gateway.png" alt="Coding OAuth Gateway tab" width="280" /></a><br />
164
+ <sub>Gateway</sub>
165
+ </td>
166
+ <td align="center" valign="top" width="33%">
167
+ <a href="media/en/settings_capabilities.png"><img src="media/en/settings_capabilities.png" alt="Coding OAuth Capabilities tab" width="280" /></a><br />
168
+ <sub>Capabilities</sub>
169
+ </td>
170
+ </tr>
171
+ </table>
172
+
173
+ | Provider | Methods |
174
+ |---|---|
175
+ | Grok | auth code · device code · model selection |
176
+ | Codex | device code (recommended on remote DSH) · browser PKCE |
177
+ | Kimi | device code |
178
+ | Claude | browser PKCE (remote browser can paste the full localhost redirect URL) |
179
+ | Antigravity | `dsh-agy` install status + profile-local CLI commands |
180
+
181
+ Use device code when the DSH host is remote. Browser/PKCE sign-in opens the provider URL; if the localhost callback cannot reach this DSH host, paste either the returned authorization code or the complete redirect URL into the waiting Settings card.
182
+
183
+ Settings also **discovers** allowlisted official Grok / Codex / Kimi / Claude CLI OAuth files (read-only). Synchronization is an explicit one-way **Pull** — not auto-import: discover → preview → conflict/fingerprint check → confirm overwrite. Official CLI files are never written. Reads refuse symlinks, non-regular files, non-owner files, group/other access, and oversized documents (`O_NOFOLLOW`). Preview tickets are one-use, expire in five minutes, and are capped at 32.
184
+
185
+ The selector only lists routes that completed authentication; unauthenticated providers return an empty list. Provider names carry `(OAuth)`, and the catalog refreshes via `llm/adapters-updated` after sign-in/out.
186
+
187
+ ## Optional capabilities
188
+
189
+ All eight switches start **off** and apply **live** (no restart): `codexSearch`, `codexImages`, `codexImageEdits`, `codexImagesAnyModel`, `codexUsage`, `codexFast`, `grokImagineImage`, and `grokImagineVideo`. `codexImagesAnyModel` only relaxes the calling-model route gate; it still requires signed-in Codex, `codexImages` (and the edits flag for edit), and keeps session attachment ownership and edit authorization. Numeric controls are `searchResults` (1–20, default 5), `imageCount` (1–4, default 1), and `videoArtifactTtlMs` (1 hour–7 days, default 7 days; the UI shows 1–168 hours). Lowering video retention shortens and cleans existing artifacts immediately; raising it affects only artifacts created afterward. Administrators may provide secret-free composition defaults under plugin config `capabilities`; live user settings in the `coding-subscription-oauth` settings section override that base, and omitting it keeps every switch off.
190
+
191
+ `codex-oauth-fast` is advertised only after a **fresh live catalog** lists at least one `priority`-eligible model. Those requests send `service_tier: priority` plus a routing hint. The UI says **Fast requested** and never guarantees latency or that upstream will honor the request.
192
+
193
+ Codex search, usage, and images are **opt-in** private `chatgpt.com/backend-api` endpoints. Image generation uses the fixed model `gpt-image-2`. Image edit accepts only current-session top-level attachment ids that this session already owns.
194
+
195
+ Grok Imagine calls official `https://api.x.ai` with `grok-imagine-image-2.0` and `grok-imagine-video-1.5`. It uses a **separate** DSH credential reference `XAI_API_KEY` — never Grok OAuth and never a process-env fallback. Generated outputs are fetched under MIME / size / time / redirect / DNS controls from frozen hosts `imgen.x.ai`, `videogen.x.ai`, and `vidgen.x.ai`, stored privately (256 MiB hard caps for one object and aggregate unique bytes, seven days), and served only on same-origin loopback routes.
196
+
197
+ ## Local API gateway
198
+
199
+ Default **off**. When enabled it starts an isolated `node:http` server (not the DSH web port) on `127.0.0.1:18080` and reuses the same signed-in OAuth sessions:
200
+
201
+ ```yaml
202
+ gateway:
203
+ enabled: false
204
+ bind: 127.0.0.1
205
+ port: 18080
206
+ opencodeGo:
207
+ enabled: false
208
+ ```
209
+
210
+ Endpoints: `GET /healthz`, `GET /v1/models`, `POST /v1/chat/completions`, `POST /v1/responses`, `POST /v1/messages`. A Bearer key is stored at `$DSH_HOME/.coding-oauth-gateway.json` (`0600`).
211
+
212
+ Optional **OpenCode Go** compatibility (`gateway.opencodeGo.enabled`, default off) can also be toggled on the Gateway tab. When on, `POST /v1/chat/completions` is forwarded to pinned `https://opencode.ai/zen/go/v1/chat/completions` with a sticky `x-opencode-session` so tools that omit OpenCode session affinity (and would otherwise see `MissingSessionID`) keep working through this loopback gateway. Session id preference: `x-deepseek-harness-session-id` → `x-opencode-session` → `x-session-id` → body `session_id` → generated UUID. Set the gateway Bearer key to your OpenCode API key for that mode; the toggle does not require a restart.
213
+
214
+ On the **Gateway** tab, copy the OpenAI base URL (for example, `http://127.0.0.1:18080/v1`), the Anthropic base URL, or the current Bearer key without rotating it. Key reveal is loopback-only and is never persisted to browser storage. Key rotation requires confirmation. Edit the listen port with **Apply** or fill it with **Random** (`18100`–`18999`); the selected port is persisted in the owner-only gateway document, and a running listener rebinds to it. Bind remains YAML-only; a non-loopback bind requires a key. This is not a remote relay.
215
+
216
+ ## CLI
217
+
218
+ ```bash
219
+ # `dsh-grok-build` remains a command alias
220
+ dsh-coding-oauth login [--pkce] | import | status | logout
221
+
222
+ # newer providers
223
+ dsh-coding-oauth login codex --device-auth | codex --browser | kimi | claude
224
+ dsh-coding-oauth status all
225
+ dsh-coding-oauth logout codex
226
+
227
+ # Antigravity (install into web profile first)
228
+ dsh plugin --profile web exec dsh-agy login --headless
229
+ ```
230
+
231
+ > `dsh-agy` CLI edits the account pool outside the DSH process, so it can't emit an in-process catalog event — close and reopen the model selector after signing in/out.
232
+
233
+ ## Kimi in China
234
+
235
+ Kimi Code subscription OAuth uses `https://auth.kimi.com`; inference uses `https://api.kimi.com/coding`. `https://api.moonshot.cn/v1` is the pay-as-you-go **Moonshot Open Platform** API-key channel — there is no switchable "China OAuth endpoint". This plugin uses a separate `kimi-code-oauth` route and doesn't affect an existing `kimi-coding` API-key config.
236
+
237
+ ## Network proxy
238
+
239
+ Priority: `config.proxy` → `CODING_OAUTH_PROXY` → `GROK_BUILD_PROXY` → `HTTPS_PROXY`/`HTTP_PROXY`.
240
+
241
+ ```yaml
242
+ - id: llm-grok-build-oauth
243
+ config:
244
+ proxy: http://127.0.0.1:7890
245
+ proxyKimi: false
246
+ ```
247
+
248
+ Only reviewed subscription domains are proxied (xAI/Grok, OpenAI Codex, Claude/Anthropic, Google Antigravity); all other DSH traffic keeps its original dispatcher. Kimi stays direct by default and only uses the proxy when `proxyKimi: true`.
249
+
250
+ ## Resilience
251
+
252
+ OAuth access tokens refresh proactively **five minutes** before their stored expiry (pi-ai 0.84+), so a request never rides a token into its final seconds. If an upstream still rejects a locally-valid token with 401/403 — server-side revocation or clock skew — the plugin backdates the stored credential and the retried step refreshes before reuse, recovering transparently instead of failing the turn.
253
+
254
+ Request retries use the harness retry policy: transient failures (`RATE_LIMIT`/`SERVER`/`TIMEOUT`/`TRANSPORT`/`EMPTY_RESPONSE`) **and `AUTH`** retry with exponential backoff (default 5 retries, 5 s → 10 s → 20 s → 40 s → 80 s, ~155 s stacked, 10% jitter). xAI “at capacity / high demand / priority processing” finish messages are remapped to `RATE_LIMIT` so they enter this policy (pi-ai would otherwise label them `PI_AI_ERROR` when upstream `error.code` is null). Quota exhaustion and a dead refresh token are **not** retried — they fail fast with the real message and a sign-in prompt. Override per deployment:
255
+
256
+ ```yaml
257
+ - id: llm-grok-build-oauth
258
+ config:
259
+ retryPolicy:
260
+ mode: normal
261
+ maxRetries: 5
262
+ retryableCodes: [EMPTY_RESPONSE, RATE_LIMIT, SERVER, TIMEOUT, TRANSPORT, AUTH]
263
+ backoff: { initialDelayMs: 5000, maxDelayMs: 80000, jitterRatio: 0.1 }
264
+ ```
265
+
266
+ ## Credentials
267
+
268
+ Owner-only `0600`, atomically written, cross-process file lock:
269
+
270
+ - `$DSH_HOME/.grok-build-auth.json`
271
+ - `$DSH_HOME/.codex-oauth-auth.json`
272
+ - `$DSH_HOME/.kimi-code-oauth-auth.json`
273
+ - `$DSH_HOME/.claude-code-oauth-auth.json`
274
+
275
+ Selection caches live in the matching `*-models.json` files. Grok Imagine uses a separate DSH credential named `XAI_API_KEY` (not the Grok OAuth file). **No HTTP status, log or UI may ever return a token.**
276
+
277
+ ## Architecture
278
+
279
+ ```mermaid
280
+ flowchart LR
281
+ subgraph DSH["DSH Harness"]
282
+ UI[Settings / Web · Coding OAuth] --> LLM[llm route]
283
+ LLM --> ALIA[Route-alias adapter]
284
+ end
285
+ ALIA --> PI[pi-ai native provider<br/>OAuth · refresh · stream]
286
+ PI --> GROK[Grok Build]
287
+ PI --> COD[Codex]
288
+ PI --> KIMI[Kimi]
289
+ PI --> CLAU[Claude]
290
+ AGY[dsh-agy plugin] --> GAL[Google Antigravity]
291
+ ```
292
+
293
+ ## Technical notes
294
+
295
+ - **Grok Build**: Responses API on `cli-chat-proxy.grok.com/v1` (not `api.x.ai`), CLI fingerprint headers, live `/v1/models-v2` including grok-4.6 `reasoning.effort: xhigh`.
296
+ - **Codex/Kimi/Claude**: pi-ai native providers handle OAuth and refresh; the route-alias adapter maps them to native ids so multi-turn replay does not throw `INVALID_REPLAY_STATE`.
297
+ - The Kimi access token is explicitly converted to `Authorization: Bearer` — never mistakenly an Anthropic `x-api-key`.
298
+ - **Codex Fast / private endpoints**: `codex-oauth-fast` is opt-in and fail-closed on a stale catalog; search, usage and `gpt-image-2` images stay off until enabled.
299
+ - **Grok Imagine**: official `api.x.ai` only, `XAI_API_KEY` through DSH credentials, same-origin download routes under `/plugins/dsh-grok-build/imagine/*`.
300
+ - Google Antigravity is **not** reverse-engineered here; it uses a version-pinned dedicated DSH plugin.
301
+
302
+ ## Compliance
303
+
304
+ Using coding subscriptions through a third-party harness may sit in a gray area of each vendor's terms and can trigger quota, regional or account-risk controls. **Use only your own accounts**; this project does not support bulk accounts, quota resale, remote relay, paywall bypass or client impersonation. For commercial use, prefer the vendors' official API-key channels.
305
+
306
+ ## Documentation
307
+
308
+ | Doc | Purpose |
309
+ |---|---|
310
+ | [`INSTALL.md`](INSTALL.md) | Installation & usage details |
311
+ | [`CHANGELOG.md`](CHANGELOG.md) | Release history |
312
+ | [`docs/00-project-rules.md`](docs/00-project-rules.md) | Versioning, release loop, publish vs local-only split |
313
+ | [`docs/02-architecture.md`](docs/02-architecture.md) | Internal architecture (routes, data flow, modules, API) · [中文](docs/02-architecture.zh-CN.md) |
314
+ | [`docs/03-dsh-alpha-smoke.md`](docs/03-dsh-alpha-smoke.md) | Isolated smoke on unverified DSH candidates (`0.1.2-alpha.*`, `0.1.5-rc.1`) |
315
+ | [`CONTRIBUTING.md`](CONTRIBUTING.md) | Contribution guide |
316
+
317
+ ## Related
318
+
319
+ - [`dsh-agy`](https://www.npmjs.com/package/dsh-agy) — separate pinned plugin for Google Antigravity.
320
+
321
+ ## Contributing
322
+
323
+ Contributions of all kinds are welcome — features, docs, translations, bug reports. See **[CONTRIBUTING](CONTRIBUTING.md)** for the flow, commit conventions and the release loop. If your language isn't listed, PR a README translation and we'll add it to the table above.
324
+
325
+ ## License
326
+
327
+ [Apache-2.0](LICENSE) · see [NOTICE](NOTICE). Portions derived from the [dsh-xai](https://github.com/MirDie/dsh-xai) project (Apache-2.0).