dsh-coding-subscription-oauth 0.5.7 → 0.6.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 (141) hide show
  1. package/CHANGELOG.md +211 -182
  2. package/CONTRIBUTING.md +120 -109
  3. package/INSTALL.md +240 -209
  4. package/LICENSE +19 -19
  5. package/NOTICE +11 -11
  6. package/README.de.md +298 -293
  7. package/README.es.md +299 -294
  8. package/README.fr.md +299 -294
  9. package/README.ja.md +299 -294
  10. package/README.ko.md +299 -294
  11. package/README.md +313 -306
  12. package/README.pt-BR.md +299 -294
  13. package/README.ru.md +299 -294
  14. package/README.zh-CN.md +311 -304
  15. package/compatibility/dsh-bom.json +43 -0
  16. package/cordis.patch.yml +13 -13
  17. package/docs/00-project-rules.md +195 -195
  18. package/docs/02-architecture.md +134 -129
  19. package/docs/02-architecture.zh-CN.md +134 -129
  20. package/lib/auth-routes.d.ts +8 -15
  21. package/lib/auth-routes.d.ts.map +1 -1
  22. package/lib/bin.js +746 -1402
  23. package/lib/bin.js.map +4 -4
  24. package/lib/capability-routes.d.ts +3 -3
  25. package/lib/capability-routes.d.ts.map +1 -1
  26. package/lib/capability-settings.d.ts +5 -4
  27. package/lib/capability-settings.d.ts.map +1 -1
  28. package/lib/client.js +27 -8
  29. package/lib/client.js.map +4 -4
  30. package/lib/compatibility.d.ts +46 -0
  31. package/lib/compatibility.d.ts.map +1 -0
  32. package/lib/dsh-host-adapter.d.ts +18 -0
  33. package/lib/dsh-host-adapter.d.ts.map +1 -0
  34. package/lib/gateway-auth.d.ts +1 -2
  35. package/lib/gateway-auth.d.ts.map +1 -1
  36. package/lib/gateway-routes.d.ts +3 -4
  37. package/lib/gateway-routes.d.ts.map +1 -1
  38. package/lib/gateway.d.ts +4 -0
  39. package/lib/gateway.d.ts.map +1 -1
  40. package/lib/ids.d.ts +3 -32
  41. package/lib/ids.d.ts.map +1 -1
  42. package/lib/imagine-routes.d.ts +2 -0
  43. package/lib/imagine-routes.d.ts.map +1 -1
  44. package/lib/index.d.ts +19 -4
  45. package/lib/index.d.ts.map +1 -1
  46. package/lib/index.js +26573 -1023
  47. package/lib/index.js.map +4 -4
  48. package/lib/invariant.js.map +1 -1
  49. package/lib/oauth-import-routes.d.ts +3 -4
  50. package/lib/oauth-import-routes.d.ts.map +1 -1
  51. package/lib/proxy.d.ts +3 -16
  52. package/lib/proxy.d.ts.map +1 -1
  53. package/lib/web-origin.d.ts +28 -4
  54. package/lib/web-origin.d.ts.map +1 -1
  55. package/lib/web-routes.d.ts.map +1 -1
  56. package/media/en/settings_accounts.png +0 -0
  57. package/media/en/settings_capabilities.png +0 -0
  58. package/media/en/settings_gateway.png +0 -0
  59. package/media/zh-CN/settings_accounts.png +0 -0
  60. package/media/zh-CN/settings_capabilities.png +0 -0
  61. package/media/zh-CN/settings_gateway.png +0 -0
  62. package/package.json +209 -172
  63. package/patches/dsh-agy@0.1.2.patch +25 -25
  64. package/scripts/release.mjs +186 -166
  65. package/scripts/smoke-deployed-routes.mjs +146 -146
  66. package/scripts/verify-deployed-catalog.mjs +87 -87
  67. package/src/adapter.ts +287 -287
  68. package/src/alias-adapter.ts +153 -153
  69. package/src/auth-routes.ts +921 -871
  70. package/src/auth.ts +67 -67
  71. package/src/bin.ts +350 -350
  72. package/src/capability-routes.ts +279 -275
  73. package/src/capability-runtime.ts +313 -313
  74. package/src/capability-settings.ts +658 -657
  75. package/src/capability-tools.ts +666 -666
  76. package/src/catalog.ts +271 -271
  77. package/src/client/GrokBuildSettings.tsx +770 -718
  78. package/src/client/api.ts +88 -88
  79. package/src/client/components/AboutTab.tsx +30 -20
  80. package/src/client/components/AccountsTab.tsx +241 -224
  81. package/src/client/components/Badge.tsx +33 -33
  82. package/src/client/components/CapabilitiesTab.tsx +265 -227
  83. package/src/client/components/CliPullPreview.tsx +116 -107
  84. package/src/client/components/CopyButton.tsx +57 -57
  85. package/src/client/components/GatewayTab.tsx +469 -364
  86. package/src/client/components/NoticeBanner.tsx +46 -46
  87. package/src/client/components/ProgressBar.tsx +53 -52
  88. package/src/client/components/ProviderCard.tsx +606 -502
  89. package/src/client/components/SettingsTabs.tsx +75 -75
  90. package/src/client/components/ToggleSwitch.tsx +71 -62
  91. package/src/client/constants.ts +224 -206
  92. package/src/client/display.ts +61 -61
  93. package/src/client/dshClientAdapter.ts +109 -0
  94. package/src/client/gatewaySnippets.ts +37 -36
  95. package/src/client/index.tsx +156 -37
  96. package/src/client/locales.ts +535 -487
  97. package/src/client/microStyles.ts +52 -33
  98. package/src/client/parsers.ts +396 -386
  99. package/src/client/styles.ts +325 -312
  100. package/src/client/types.ts +197 -185
  101. package/src/codex-http.ts +447 -447
  102. package/src/codex-images.ts +485 -485
  103. package/src/codex-model-capabilities.ts +320 -320
  104. package/src/codex-search.ts +245 -245
  105. package/src/codex-usage.ts +263 -263
  106. package/src/compatibility.ts +55 -0
  107. package/src/dsh-host-adapter.ts +171 -0
  108. package/src/gateway-anthropic-messages.ts +84 -84
  109. package/src/gateway-auth.ts +102 -100
  110. package/src/gateway-backend.ts +274 -274
  111. package/src/gateway-body.ts +49 -49
  112. package/src/gateway-config.ts +76 -76
  113. package/src/gateway-http.ts +104 -104
  114. package/src/gateway-openai-chat.ts +124 -124
  115. package/src/gateway-openai-responses.ts +53 -53
  116. package/src/gateway-parse.ts +224 -224
  117. package/src/gateway-protocol.ts +52 -52
  118. package/src/gateway-routes.ts +158 -152
  119. package/src/gateway.ts +258 -242
  120. package/src/grok-errors.ts +24 -24
  121. package/src/grok-imagine.ts +1627 -1627
  122. package/src/grok-import.ts +151 -151
  123. package/src/http-json.ts +82 -82
  124. package/src/ids.ts +59 -45
  125. package/src/imagine-routes.ts +463 -461
  126. package/src/index.ts +748 -598
  127. package/src/invariant.ts +17 -17
  128. package/src/kimi-errors.ts +26 -26
  129. package/src/media-store.ts +927 -927
  130. package/src/oauth-import-routes.ts +324 -314
  131. package/src/oauth-providers.ts +152 -152
  132. package/src/oauth-session.ts +183 -183
  133. package/src/oauth-sources.ts +1104 -1104
  134. package/src/oauth.ts +620 -620
  135. package/src/provider.ts +128 -128
  136. package/src/proxy.ts +11 -99
  137. package/src/redact.ts +72 -72
  138. package/src/session.ts +218 -218
  139. package/src/store.ts +217 -217
  140. package/src/web-origin.ts +296 -60
  141. package/src/web-routes.ts +38 -75
package/README.md CHANGED
@@ -1,314 +1,321 @@
1
-
2
- <!-- banner -->
3
- <div align="center">
4
-
5
- # 🔐 dsh-coding-subscription-oauth
6
-
7
- **v0.5.7** · 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
-
1
+
2
+ <!-- banner -->
3
+ <div align="center">
4
+
5
+ # 🔐 dsh-coding-subscription-oauth
6
+
7
+ **v0.6.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
16
  </div>
17
17
 
18
18
  ---
19
19
 
20
- ## Name change
21
-
22
- Published first as **`dsh-grok-build`** when it only covered Grok Build. The current name matches the full coding-subscription OAuth surface.
23
-
24
- | | Use this | Still works |
25
- |---|---|---|
26
- | npm (recommended) | Current release is `0.5.7`: `dsh plugin --profile web add dsh-coding-subscription-oauth@0.5.7` | No legacy npm package was published |
27
- | GitHub / development | [`dsh-coding-subscription-oauth`](https://github.com/lninghaha/dsh-coding-subscription-oauth) | Previous GitHub repo `dsh-grok-build` was removed |
28
- | CLI | `dsh-coding-oauth` | `dsh-grok-build` |
29
- | Cordis plugin id | `llm-grok-build-oauth` | unchanged |
30
- | Settings HTTP API | `/plugins/dsh-grok-build/*` | unchanged |
31
- | Credential files | `$DSH_HOME/.grok-build-auth.json` and the other `*-oauth-auth.json` files | unchanged |
32
-
33
- ## ✨ Features
34
-
35
- - 🧽 **Bring your own subscription** — SuperGrok, ChatGPT Plus/Pro, Kimi Code, Claude Pro/Max; no extra pay-as-you-go key.
36
- - 🔑 **Local OAuth, no key-pasting** — authorize in Settings or CLI; access/refresh tokens never enter chat, logs or HTTP status.
37
- - 🧩 **One plugin, five providers** — Grok Build (`cli-chat-proxy.grok.com`), Codex, Kimi Code, Claude Code and Google Antigravity.
38
- - 🛡️ **Secure by design** — credential files are owner-only `0600`, atomically written, cross-process locked.
39
- - ⚙️ **Dynamic catalog** — the selector lists only signed-in routes, labelled `(OAuth)`, including grok-4.6 `xhigh`.
40
- - 🌐 **Proxy-aware** — proxies only reviewed subscription domains; Kimi China stays direct by default.
41
- - 📥 **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.
42
- - 🗂️ **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.
43
- - 🎛️ **Optional capabilities, default off** — Codex search, usage/quota, image generate/edit, Fast, and Grok Imagine apply live when you turn them on.
44
- - 🔌 **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.
45
-
46
- ## Problems this plugin solves
47
-
48
- 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.
49
-
50
- | You searched / saw | What was actually broken | What this plugin does |
51
- |---|---|---|
52
- | 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 |
53
- | `本轮运行失败` **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 |
54
- | `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 |
55
- | 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 |
56
- | 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` |
57
- | 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)` |
58
- | 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 |
59
- | 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` |
60
- | 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 |
61
-
62
- 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.
63
-
64
- ## Supported providers
65
-
66
- | Provider | Route | Auth | Coexists with |
67
- |---|---|---|---|
68
- | **xAI Grok Build** | `grok-build` | SuperGrok / X Premium OAuth | `xai` |
69
- | **OpenAI Codex** | `codex-oauth` · optional `codex-oauth-fast` | ChatGPT Plus/Pro OAuth | `openai` |
70
- | **Kimi Code** | `kimi-code-oauth` | Kimi Code OAuth | `kimi-coding` |
71
- | **Claude Code** | `claude-code-oauth` | Claude Pro/Max OAuth | — |
72
- | **Google Antigravity** | `agy` | `dsh-agy` Google OAuth | — |
73
-
74
- > 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.
75
-
76
- ## 🚀 Quick start
77
-
78
- ```bash
79
- # 1. install the current npm release into the web profile
80
- dsh plugin --profile web add dsh-coding-subscription-oauth@0.5.7
81
-
82
- # 2. optional — Google Antigravity (pinned, reviewed version)
83
- dsh plugin --profile web add dsh-agy@0.1.2
20
+ > **Upgrade / 升级:** Follow the versioned steps in [`INSTALL.md`](INSTALL.md). Install into the existing `web` profile, keep profile/config/credential files, and restart one existing DSH Web process after all packages are updated. When Hub and Subscription are both used, `dsh-coding-oauth-core@0.1.0` is their shared npm dependency, not a separate DSH plugin.
84
21
 
85
- # 3. restart the resident dsh web service
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.6.0`: `dsh plugin --profile web add dsh-coding-subscription-oauth@0.6.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.
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.6.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 resident DSH Web process
90
+ # Local service-manager example only; `dsh web` is the official CLI alias for the web profile, not a systemd unit name.
86
91
  systemctl --user restart dsh-web.service
87
- ```
88
-
89
- Then open **Settings → Coding OAuth** and sign in to any provider. Done — pick your authenticated model from the selector.
90
-
91
- ## 📚 Table of contents
92
-
93
- - [Name change](#name-change)
94
- - [Features](#-features)
95
- - [Problems this plugin solves](#problems-this-plugin-solves)
96
- - [Supported providers](#supported-providers)
97
- - [Quick start](#-quick-start)
98
- - [Install](#install)
99
- - [Settings page](#settings-page)
100
- - [Optional capabilities](#optional-capabilities)
101
- - [Local API gateway](#local-api-gateway)
102
- - [CLI](#cli)
103
- - [Kimi in China](#kimi-in-china)
104
- - [Network proxy](#network-proxy)
105
- - [Resilience](#resilience)
106
- - [Credentials](#credentials)
107
- - [Architecture](#architecture)
108
- - [Technical notes](#technical-notes)
109
- - [Compliance](#compliance)
110
- - [Documentation](#documentation)
111
- - [Related](#related)
112
- - [Contributing](#contributing)
113
- - [License](#license)
114
-
115
- ## Install
116
-
117
- Requires DeepSeek Harness `0.1.0-rc.6+` and Node.js 22.19+. Full details in the [installation notes](INSTALL.md).
118
-
119
- ```bash
120
- # current npm release
121
- dsh plugin --profile web add dsh-coding-subscription-oauth@0.5.7
122
-
123
- # development / alternative: from GitHub
124
- dsh plugin --profile web add github:lninghaha/dsh-coding-subscription-oauth
125
-
126
- # local development checkout (alternative)
127
- # dsh plugin --profile web add ./dsh-coding-subscription-oauth
128
- ```
129
-
130
- Restart `dsh web` after installing. Maintainers can verify a live deployment from a source checkout (npm installs do not include these scripts):
131
-
132
- ```bash
133
- pnpm run verify:deployed # checks real /api/llm.models + OAuth state
134
- DSH_EXPECT_AGY_AUTH=signed-in pnpm run verify:deployed # if Google is signed in
135
-
136
- DSH_RESTORE_PROVIDER=openai \
137
- DSH_RESTORE_MODEL=gpt-5.6-sol \
138
- DSH_RESTORE_REASONING=max \
139
- pnpm run smoke:deployed # real Codex/Kimi tool-calls + second-turn replay
140
- ```
141
-
142
- > `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.
143
-
144
- ## Settings page
145
-
92
+ ```
93
+
94
+ Then open **Settings → Coding OAuth** and sign in to any provider. Done — pick your authenticated model from the selector.
95
+
96
+ ## 📚 Table of contents
97
+
98
+ - [Name change](#name-change)
99
+ - [Features](#-features)
100
+ - [Problems this plugin solves](#problems-this-plugin-solves)
101
+ - [Supported providers](#supported-providers)
102
+ - [Quick start](#-quick-start)
103
+ - [Install](#install)
104
+ - [Settings page](#settings-page)
105
+ - [Optional capabilities](#optional-capabilities)
106
+ - [Local API gateway](#local-api-gateway)
107
+ - [CLI](#cli)
108
+ - [Kimi in China](#kimi-in-china)
109
+ - [Network proxy](#network-proxy)
110
+ - [Resilience](#resilience)
111
+ - [Credentials](#credentials)
112
+ - [Architecture](#architecture)
113
+ - [Technical notes](#technical-notes)
114
+ - [Compliance](#compliance)
115
+ - [Documentation](#documentation)
116
+ - [Related](#related)
117
+ - [Contributing](#contributing)
118
+ - [License](#license)
119
+
120
+ ## Install
121
+
122
+ Requires DeepSeek Harness `0.1.0-rc.6+` and Node.js 22.19+. Full details in the [installation notes](INSTALL.md).
123
+
124
+ ```bash
125
+ # current npm release
126
+ dsh plugin --profile web add dsh-coding-subscription-oauth@0.6.0
127
+
128
+ # development / alternative: from GitHub
129
+ dsh plugin --profile web add github:lninghaha/dsh-coding-subscription-oauth
130
+
131
+ # local development checkout (alternative)
132
+ # dsh plugin --profile web add ./dsh-coding-subscription-oauth
133
+ ```
134
+
135
+ 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):
136
+
137
+ ```bash
138
+ pnpm run verify:deployed # checks real /api/llm.models + OAuth state
139
+ DSH_EXPECT_AGY_AUTH=signed-in pnpm run verify:deployed # if Google is signed in
140
+
141
+ DSH_RESTORE_PROVIDER=openai \
142
+ DSH_RESTORE_MODEL=gpt-5.6-sol \
143
+ DSH_RESTORE_REASONING=max \
144
+ pnpm run smoke:deployed # real Codex/Kimi tool-calls + second-turn replay
145
+ ```
146
+
147
+ > `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.
148
+
149
+ ## Settings page
150
+
146
151
  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.
147
152
 
148
- <table>
149
- <tr>
150
- <td align="center" valign="top" width="33%">
151
- <a href="media/settings_accounts.png"><img src="media/settings_accounts.png" alt="Coding OAuth Accounts tab" width="280" /></a><br />
152
- <sub>Accounts</sub>
153
- </td>
154
- <td align="center" valign="top" width="33%">
155
- <a href="media/settings_gateway.png"><img src="media/settings_gateway.png" alt="Coding OAuth Gateway tab" width="280" /></a><br />
156
- <sub>Gateway</sub>
157
- </td>
158
- <td align="center" valign="top" width="33%">
159
- <a href="media/settings_capabilities.png"><img src="media/settings_capabilities.png" alt="Coding OAuth Capabilities tab" width="280" /></a><br />
160
- <sub>Capabilities</sub>
161
- </td>
162
- </tr>
163
- </table>
164
-
165
- | Provider | Methods |
166
- |---|---|
167
- | Grok | auth code · device code · model selection |
168
- | Codex | device code (recommended on remote DSH) · browser PKCE |
169
- | Kimi | device code |
170
- | Claude | browser PKCE (remote browser can paste the full localhost redirect URL) |
171
- | Antigravity | `dsh-agy` install status + profile-local CLI commands |
172
-
173
- 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.
174
-
175
- 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.
176
-
177
- 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.
178
-
179
- ## Optional capabilities
180
-
181
- All seven switches start **off** and apply **live** (no restart): `codexSearch`, `codexImages`, `codexImageEdits`, `codexUsage`, `codexFast`, `grokImagineImage`, and `grokImagineVideo`. 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.
182
-
183
- `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.
184
-
185
- 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.
186
-
187
- 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.
188
-
189
- ## Local API gateway
190
-
191
- 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:
192
-
193
- ```yaml
194
- gateway:
195
- enabled: false
196
- bind: 127.0.0.1
197
- port: 18080
198
- ```
199
-
200
- 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`).
201
-
202
- 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.
203
-
204
- ## CLI
205
-
206
- ```bash
207
- # `dsh-grok-build` remains a command alias
208
- dsh-coding-oauth login [--pkce] | import | status | logout
209
-
210
- # newer providers
211
- dsh-coding-oauth login codex --device-auth | codex --browser | kimi | claude
212
- dsh-coding-oauth status all
213
- dsh-coding-oauth logout codex
214
-
215
- # Antigravity (install into web profile first)
216
- dsh plugin --profile web exec dsh-agy login --headless
217
- ```
218
-
219
- > `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.
220
-
221
- ## Kimi in China
222
-
223
- 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.
224
-
225
- ## Network proxy
226
-
227
- Priority: `config.proxy` → `CODING_OAUTH_PROXY` → `GROK_BUILD_PROXY` → `HTTPS_PROXY`/`HTTP_PROXY`.
228
-
229
- ```yaml
230
- - id: llm-grok-build-oauth
231
- config:
232
- proxy: http://127.0.0.1:7890
233
- proxyKimi: false
234
- ```
235
-
236
- 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`.
237
-
238
- ## Resilience
239
-
240
- 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.
241
-
242
- 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:
243
-
244
- ```yaml
245
- - id: llm-grok-build-oauth
246
- config:
247
- retryPolicy:
248
- mode: normal
249
- maxRetries: 5
250
- retryableCodes: [EMPTY_RESPONSE, RATE_LIMIT, SERVER, TIMEOUT, TRANSPORT, AUTH]
251
- backoff: { initialDelayMs: 5000, maxDelayMs: 80000, jitterRatio: 0.1 }
252
- ```
253
-
254
- ## Credentials
255
-
256
- Owner-only `0600`, atomically written, cross-process file lock:
257
-
258
- - `$DSH_HOME/.grok-build-auth.json`
259
- - `$DSH_HOME/.codex-oauth-auth.json`
260
- - `$DSH_HOME/.kimi-code-oauth-auth.json`
261
- - `$DSH_HOME/.claude-code-oauth-auth.json`
262
-
263
- 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.**
264
-
265
- ## Architecture
266
-
267
- ```mermaid
268
- flowchart LR
269
- subgraph DSH["DSH Harness"]
270
- UI[Settings / Web · Coding OAuth] --> LLM[llm route]
271
- LLM --> ALIA[Route-alias adapter]
272
- end
273
- ALIA --> PI[pi-ai native provider<br/>OAuth · refresh · stream]
274
- PI --> GROK[Grok Build]
275
- PI --> COD[Codex]
276
- PI --> KIMI[Kimi]
277
- PI --> CLAU[Claude]
278
- AGY[dsh-agy plugin] --> GAL[Google Antigravity]
279
- ```
280
-
281
- ## Technical notes
282
-
283
- - **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`.
284
- - **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`.
285
- - The Kimi access token is explicitly converted to `Authorization: Bearer` never mistakenly an Anthropic `x-api-key`.
286
- - **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.
287
- - **Grok Imagine**: official `api.x.ai` only, `XAI_API_KEY` through DSH credentials, same-origin download routes under `/plugins/dsh-grok-build/imagine/*`.
288
- - Google Antigravity is **not** reverse-engineered here; it uses a version-pinned dedicated DSH plugin.
289
-
290
- ## Compliance
291
-
292
- 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.
293
-
294
- ## Documentation
295
-
296
- | Doc | Purpose |
297
- |---|---|
298
- | [`INSTALL.md`](INSTALL.md) | Installation & usage details |
299
- | [`CHANGELOG.md`](CHANGELOG.md) | Release history |
300
- | [`docs/00-project-rules.md`](docs/00-project-rules.md) | Versioning, release loop, publish vs local-only split |
301
- | [`docs/02-architecture.md`](docs/02-architecture.md) | Internal architecture (routes, data flow, modules, API) · [中文](docs/02-architecture.zh-CN.md) |
302
- | [`CONTRIBUTING.md`](CONTRIBUTING.md) | Contribution guide |
303
-
304
- ## Related
305
-
306
- - [`dsh-agy`](https://www.npmjs.com/package/dsh-agy) — separate pinned plugin for Google Antigravity.
307
-
308
- ## Contributing
309
-
310
- 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.
311
-
312
- ## License
313
-
314
- [Apache-2.0](LICENSE) · see [NOTICE](NOTICE). Portions derived from the [dsh-xai](https://github.com/MirDie/dsh-xai) project (Apache-2.0).
153
+ 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).
154
+
155
+ <table>
156
+ <tr>
157
+ <td align="center" valign="top" width="33%">
158
+ <a href="media/en/settings_accounts.png"><img src="media/en/settings_accounts.png" alt="Coding OAuth Accounts tab" width="280" /></a><br />
159
+ <sub>Accounts</sub>
160
+ </td>
161
+ <td align="center" valign="top" width="33%">
162
+ <a href="media/en/settings_gateway.png"><img src="media/en/settings_gateway.png" alt="Coding OAuth Gateway tab" width="280" /></a><br />
163
+ <sub>Gateway</sub>
164
+ </td>
165
+ <td align="center" valign="top" width="33%">
166
+ <a href="media/en/settings_capabilities.png"><img src="media/en/settings_capabilities.png" alt="Coding OAuth Capabilities tab" width="280" /></a><br />
167
+ <sub>Capabilities</sub>
168
+ </td>
169
+ </tr>
170
+ </table>
171
+
172
+ | Provider | Methods |
173
+ |---|---|
174
+ | Grok | auth code · device code · model selection |
175
+ | Codex | device code (recommended on remote DSH) · browser PKCE |
176
+ | Kimi | device code |
177
+ | Claude | browser PKCE (remote browser can paste the full localhost redirect URL) |
178
+ | Antigravity | `dsh-agy` install status + profile-local CLI commands |
179
+
180
+ 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.
181
+
182
+ 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.
183
+
184
+ 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.
185
+
186
+ ## Optional capabilities
187
+
188
+ All seven switches start **off** and apply **live** (no restart): `codexSearch`, `codexImages`, `codexImageEdits`, `codexUsage`, `codexFast`, `grokImagineImage`, and `grokImagineVideo`. 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.
189
+
190
+ `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.
191
+
192
+ 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.
193
+
194
+ 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.
195
+
196
+ ## Local API gateway
197
+
198
+ 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:
199
+
200
+ ```yaml
201
+ gateway:
202
+ enabled: false
203
+ bind: 127.0.0.1
204
+ port: 18080
205
+ ```
206
+
207
+ 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`).
208
+
209
+ 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.
210
+
211
+ ## CLI
212
+
213
+ ```bash
214
+ # `dsh-grok-build` remains a command alias
215
+ dsh-coding-oauth login [--pkce] | import | status | logout
216
+
217
+ # newer providers
218
+ dsh-coding-oauth login codex --device-auth | codex --browser | kimi | claude
219
+ dsh-coding-oauth status all
220
+ dsh-coding-oauth logout codex
221
+
222
+ # Antigravity (install into web profile first)
223
+ dsh plugin --profile web exec dsh-agy login --headless
224
+ ```
225
+
226
+ > `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.
227
+
228
+ ## Kimi in China
229
+
230
+ 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.
231
+
232
+ ## Network proxy
233
+
234
+ Priority: `config.proxy` → `CODING_OAUTH_PROXY` → `GROK_BUILD_PROXY` → `HTTPS_PROXY`/`HTTP_PROXY`.
235
+
236
+ ```yaml
237
+ - id: llm-grok-build-oauth
238
+ config:
239
+ proxy: http://127.0.0.1:7890
240
+ proxyKimi: false
241
+ ```
242
+
243
+ 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`.
244
+
245
+ ## Resilience
246
+
247
+ 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.
248
+
249
+ 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:
250
+
251
+ ```yaml
252
+ - id: llm-grok-build-oauth
253
+ config:
254
+ retryPolicy:
255
+ mode: normal
256
+ maxRetries: 5
257
+ retryableCodes: [EMPTY_RESPONSE, RATE_LIMIT, SERVER, TIMEOUT, TRANSPORT, AUTH]
258
+ backoff: { initialDelayMs: 5000, maxDelayMs: 80000, jitterRatio: 0.1 }
259
+ ```
260
+
261
+ ## Credentials
262
+
263
+ Owner-only `0600`, atomically written, cross-process file lock:
264
+
265
+ - `$DSH_HOME/.grok-build-auth.json`
266
+ - `$DSH_HOME/.codex-oauth-auth.json`
267
+ - `$DSH_HOME/.kimi-code-oauth-auth.json`
268
+ - `$DSH_HOME/.claude-code-oauth-auth.json`
269
+
270
+ 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.**
271
+
272
+ ## Architecture
273
+
274
+ ```mermaid
275
+ flowchart LR
276
+ subgraph DSH["DSH Harness"]
277
+ UI[Settings / Web · Coding OAuth] --> LLM[llm route]
278
+ LLM --> ALIA[Route-alias adapter]
279
+ end
280
+ ALIA --> PI[pi-ai native provider<br/>OAuth · refresh · stream]
281
+ PI --> GROK[Grok Build]
282
+ PI --> COD[Codex]
283
+ PI --> KIMI[Kimi]
284
+ PI --> CLAU[Claude]
285
+ AGY[dsh-agy plugin] --> GAL[Google Antigravity]
286
+ ```
287
+
288
+ ## Technical notes
289
+
290
+ - **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`.
291
+ - **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`.
292
+ - The Kimi access token is explicitly converted to `Authorization: Bearer` never mistakenly an Anthropic `x-api-key`.
293
+ - **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.
294
+ - **Grok Imagine**: official `api.x.ai` only, `XAI_API_KEY` through DSH credentials, same-origin download routes under `/plugins/dsh-grok-build/imagine/*`.
295
+ - Google Antigravity is **not** reverse-engineered here; it uses a version-pinned dedicated DSH plugin.
296
+
297
+ ## Compliance
298
+
299
+ 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.
300
+
301
+ ## Documentation
302
+
303
+ | Doc | Purpose |
304
+ |---|---|
305
+ | [`INSTALL.md`](INSTALL.md) | Installation & usage details |
306
+ | [`CHANGELOG.md`](CHANGELOG.md) | Release history |
307
+ | [`docs/00-project-rules.md`](docs/00-project-rules.md) | Versioning, release loop, publish vs local-only split |
308
+ | [`docs/02-architecture.md`](docs/02-architecture.md) | Internal architecture (routes, data flow, modules, API) · [中文](docs/02-architecture.zh-CN.md) |
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).