opencode-thinking-fix 2.0.0 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,16 +10,101 @@
10
10
  npm install opencode-thinking-fix
11
11
  ```
12
12
 
13
- > Fix for the `reasoning_content` 400 error that kills multi-turn conversations with DeepSeek, Kimi, GLM, MiMo, and MiniMax-M3 in OpenCode.
13
+ > Fix for reasoning being dropped from multi-turn conversations with DeepSeek, Kimi, GLM, MiMo, and MiniMax-M3.
14
+ >
15
+ > **Zero config.** Install via `Ctrl+P`, restart OpenCode, done. The plugin auto-detects reasoning models and only patches when needed.
14
16
  >
15
17
  > Docs: [OpenCode Plugins](https://opencode.ai/docs/plugins)
16
18
 
19
+ Your AI has a secret notebook.
20
+
21
+ When DeepSeek or Kimi answers you, it scribbles notes first. "Let me think... the user wants a login page... I should use React Hook Form... check the API docs..." These notes are `reasoning_content`. You never see them. But the AI needs them.
22
+
23
+ The client and its SDK throw the notebook away. Next turn, the AI reaches for it — but the request already went to the API without it. The request carries no notes, or a blank notebook. The AI doesn't crash, but it forgot everything it was thinking. That is why your AI seems dumber on turn 2. It's not dumber. It just lost its notes.
24
+
25
+ The drop happens in SDK serializers and client transforms (truthy checks, missing type members, stripped signatures), not in the providers — the providers are doing exactly what their docs say.
26
+
27
+ **Without the plugin:** "Build me a login page." → AI builds it. "Now add password reset." → AI lost its notes, conversation degrades.
28
+
29
+ **With the plugin:** "Build me a login page." → AI builds it, notes saved. "Now add password reset." → AI reads its notes: "I used React Hook Form for login, I'll extend that for password reset." → Works.
30
+
31
+ ---
32
+
33
+ ## ELI15 — what this thing actually does
34
+
35
+ Imagine you're doing homework with a friend (the AI) over text messages. Your friend is smart but **forgetful between messages**. Every time they answer, they first scribble their thinking on a **sticky note** (that's `reasoning_content`) — but you never see the note, and the note gets **thrown away** before your friend reads the next message.
36
+
37
+ So when you say "ok now change the color," your friend has no memory of *why* they picked the blue button, gets confused, and gives a worse answer (the "dumber on turn 2" feeling).
38
+
39
+ Three facts make this messy:
40
+
41
+ 1. **The sticky notes are non-standard.** Normal chat apps don't have a "thinking note" field. So the tool that carries your messages back and forth (OpenCode, Cursor, Roo, etc.) simply **doesn't know the note exists** and drops it.
42
+ 2. **The teachers (Chinese AI companies: DeepSeek, Kimi, GLM, MiMo, MiniMax) demand the note back.** Their rules say: "if you don't hand me the exact sticky note from last time, I refuse to answer."
43
+ 3. **Some teachers are picky about the note being present**, not missing. Kimi K2.7-Code accepts a present-but-empty note. Others (DeepSeek, Kimi K2.5/2.6, GLM, MiMo) accept a blank one but then they "forget" and do worse.
44
+
45
+ What this repo does about it:
46
+
47
+ - **The plugin** is a tiny note-checker that runs inside OpenCode. It looks at every message and, if a note is missing, it slips a blank note in so the teacher doesn't yell. Cheap, but the teacher still forgets (blank note = no memory).
48
+ - **The proxy** is a smarter middle-man that sits between OpenCode and the teacher. It **reads the real sticky note off each answer, remembers it, and pastes the actual writing back** into the next message. Now the teacher remembers, and your friend stays sharp. (v3 rewrote the proxy so it does this with almost zero slowdown — see below.)
49
+ - **The watchdog** is just a babysitter that restarts the proxy if it ever crashes.
50
+
51
+ Bottom line: **the proxy is what makes the AI actually remember its thinking. The plugin is a safety net. The watchdog keeps the lights on.**
52
+
53
+ ---
54
+
55
+ ## v3 proxy rewrite — performance + correctness
56
+
57
+ The proxy (`proxy/proxy.js`) was rewritten to remove the slowdown you were hitting:
58
+
59
+ - **Raw-byte streaming.** Responses are now forwarded as-is; the stream is parsed *only* to cache the note. No more re-building every token before sending it to you.
60
+ - **Lazy patching.** If OpenCode already hands the notes back correctly (newer builds do), the proxy does **nothing** — zero JSON rewriting, zero overhead.
61
+ - **Correct note placement (the big bug fix).** Earlier versions pasted every note into the *first* slot, so turn 3+ forgot everything. v3 stores each note in its own correct slot, so every turn replays *its own* thinking.
62
+ - **Keep-alive connections + upstream timeout.** Fewer TLS handshakes, no hung requests.
63
+
64
+ ## v3.1 — dialect-aware patching (intel-driven)
65
+
66
+ Provider-specific research showed the field name is **not universal** and the "echo everything" heuristic was
67
+ causing cross-provider poisoning. v3.1 fixes that:
68
+
69
+ - **Echo only the field the upstream expects.** Each route declares a `reasoningKey`:
70
+ `reasoning_content` (DeepSeek/Kimi/Moonshot/GLM/Zhipu/MiMo), `reasoning_details`
71
+ (MiniMax split mode), `reasoning` (OpenCode Go / fixed-upstream). Previously the proxy
72
+ filled all three fields, so a GLM turn stored under `reasoning` could poison a later
73
+ DeepSeek replay that expects `reasoning_content`.
74
+ - **R1 vs V4 split.** `deepseek-reasoner` (R1) must **not** receive reasoning echoed back
75
+ (400 if you do) while V4 must. R1 now routes with `reasoningKey: null`.
76
+ - **Never fabricate reasoning.** Unknown models and providers that reject echo
77
+ (Qwen, GPT, Claude, Gemini, Llama, Mistral, Cerebras-hosted GLM) default to
78
+ `reasoningKey: null` — the body is forwarded untouched.
79
+
80
+ ### "Another way" — do you even need the plugin now?
81
+
82
+ The reasoning-drop is fixed at the wire layer by the proxy, so you have three options:
83
+
84
+ | Approach | Pros | Cons |
85
+ |----------|------|------|
86
+ | **Proxy-only (recommended)** — keep a *slim* plugin that only tags sessions with `x-session-id`, let the proxy do all note-handling | Real reasoning replay, near-zero overhead, correct across all turns | One extra localhost process to run |
87
+ | **Native / disable thinking** — point at the provider's Anthropic-compatible endpoint (e.g. DeepSeek `/anthropic`) or set `thinking: disabled` | No extra process, simplest | Loses ~20–40% reasoning quality on hard coding tasks |
88
+ | **Full plugin + proxy** (old default) | Maximum safety net | Plugin's per-message transform adds overhead inside OpenCode |
89
+
90
+ **Recommendation:** run the proxy, and slim the plugin down to *just* the `x-session-id` header injection (delete its message-transform hook). That gives you real reasoning replay with the least overhead.
91
+
92
+ ## Plugin deprecation and derived sessions
93
+
94
+ As of 3.0, plugin is deprecated. Proxy derives session identity from request when `x-session-id` is absent. Formula: `sha256(authHeader || '' || modelName || firstUserMessageText)`, prefixed with `derived:` and truncated to 32 hex characters; header wins when present. Rare bounded collision: conversations sharing same first user message, model, and auth key share cache key, causing minor reasoning cross-talk that self-heals as turns diverge.
95
+
17
96
  ---
18
97
 
19
98
  ## Quick Install
20
99
 
21
100
  **This is an OpenCode plugin. Install it inside OpenCode, no terminal needed.**
22
101
 
102
+ | Method | Command | Best for |
103
+ |--------|---------|----------|
104
+ | **TUI** | `Ctrl+P` → type `install plugin` → `opencode-thinking-fix` | First-time users |
105
+ | **CLI** | `opencode plugin opencode-thinking-fix` | Scripting |
106
+ | **Manual** | Add `"plugin": ["opencode-thinking-fix"]` to `opencode.json` | Version pinning |
107
+
23
108
  ### Method 1: TUI (press `Ctrl+P` while OpenCode is running)
24
109
 
25
110
  1. Press `Ctrl+P` to open the command palette.
@@ -28,7 +113,7 @@ npm install opencode-thinking-fix
28
113
  4. Type `opencode-thinking-fix`.
29
114
  5. Press `Enter`. Restart OpenCode.
30
115
 
31
- You should see `[ThinkingFix] Plugin loaded, universal reasoning_content fix active` at startup.
116
+ Check `~/.local/share/opencode/thinking-fix.log` for `plugin_loaded`. See [Is it working?](#is-it-working).
32
117
 
33
118
  ### Method 2: CLI (shell command)
34
119
 
@@ -39,7 +124,7 @@ opencode plugin opencode-thinking-fix
39
124
  For a specific version:
40
125
 
41
126
  ```bash
42
- opencode plugin opencode-thinking-fix@2.0.0
127
+ opencode plugin opencode-thinking-fix@3.1.4
43
128
  ```
44
129
 
45
130
  Restart OpenCode after installing.
@@ -56,21 +141,22 @@ Config file location:
56
141
  - **Linux/macOS:** `~/.config/opencode/opencode.json` (global) or `.opencode/opencode.json` (project)
57
142
  - **Windows:** `%APPDATA%/OpenCode/opencode.json` (global) or `.opencode/opencode.json` (project)
58
143
 
59
- Restart OpenCode after adding. You should see `[ThinkingFix] Plugin loaded` at startup.
144
+ Restart OpenCode after adding. Check `~/.local/share/opencode/thinking-fix.log` for `plugin_loaded`. See [Is it working?](#is-it-working).
60
145
 
61
146
  See also: [OpenCode plugin docs](https://opencode.ai/docs/plugins)
62
147
 
148
+ > **On Windows?** See [Windows notes](#windows-notes) for PowerShell commands, NSSM service setup, and config paths.
149
+
63
150
  ---
64
151
 
65
152
  - [What problem this fixes](#what-problem-this-fixes)
66
- - [Option 1: Plugin (stops the crashes)](#option-1-plugin-stops-the-crashes)
153
+ - [Option 1: Plugin (safety net)](#option-1-plugin-safety-net)
67
154
  - [Option 2: Proxy (replays real reasoning)](#option-2-proxy-replays-real-reasoning)
68
155
  - [Option 3: Watchdog (auto-recovery)](#option-3-watchdog-auto-recovery)
69
156
  - [How they work together](#how-they-work-together)
70
157
  - [Affected models](#affected-models)
71
158
  - [Model routing](#model-routing)
72
159
  - [Is it working?](#is-it-working)
73
- - [Running tests](#running-tests)
74
160
  - [This bug is everywhere](#this-bug-is-everywhere)
75
161
  - [Files in this repo](#files-in-this-repo)
76
162
 
@@ -78,13 +164,13 @@ See also: [OpenCode plugin docs](https://opencode.ai/docs/plugins)
78
164
 
79
165
  ## What problem this fixes
80
166
 
81
- You ask DeepSeek a question. It picks a tool, calls it, works fine. Then you ask a follow-up and you get this:
167
+ You ask DeepSeek a question. It picks a tool, calls it, works fine. Then you ask a follow-up — and the AI has lost the reasoning it produced on every earlier turn.
82
168
 
83
- ```
84
- HTTP 400: The reasoning_content in the thinking mode must be passed back to the API
85
- ```
169
+ The client/SDK dropped the field before it reached the API — the providers are doing exactly what their docs say. The drop happens in SDK serializers and client transforms.
86
170
 
87
- DeepSeek V4 (and Kimi K2.7, GLM 5.x, MiMo V2.5) require that `reasoning_content` from every prior assistant turn gets included in subsequent API requests. The [docs](https://api-docs.deepseek.com/guides/thinking_mode) say it clearly: if you do not pass back `reasoning_content` correctly, the API returns a 400 error. All five providers confirm this in their official documentation:
171
+ > **Deprecated:** the historical symptom of this drop — `HTTP 400: The reasoning_content in the thinking mode must be passed back to the API` — is **resolved** by this fix. This repo is about the drop itself, not the error it used to cause.
172
+
173
+ DeepSeek V4 (and Kimi K2.7, GLM 5.x, MiMo V2.5) require that `reasoning_content` from every prior assistant turn gets included in subsequent API requests. The [docs](https://api-docs.deepseek.com/guides/thinking_mode) say it clearly: if you do not pass back `reasoning_content` correctly, the API rejects the request. All five providers confirm this in their official documentation:
88
174
 
89
175
  - **DeepSeek**: "[The reasoning_content will be ignored by the API](https://api-docs.deepseek.com/guides/thinking_mode)", but the conversation history must contain the field.
90
176
  - **Z.AI / GLM**: "[Key: return reasoning_content to keep the reasoning coherent](https://docs.z.ai/en/api/thinking)."
@@ -92,13 +178,12 @@ DeepSeek V4 (and Kimi K2.7, GLM 5.x, MiMo V2.5) require that `reasoning_content`
92
178
  - **MiniMax**: "[The complete model response must be append to the conversation history](https://platform.minimaxi.com/document/ChatCompletion%20v2)."
93
179
  - **Xiaomi MiMo**: "[Any assistant message with tool calls... must preserve its full reasoning_content field, otherwise the API will return a 400 error](https://dev.mi.com/doc/llm-api). Affected frameworks include TRAE, Cursor, Roo Code, Codex, GitHub Copilot CLI, Zed, AutoGen."
94
180
 
95
- OpenCode's provider layer drops this field. Three upstream PRs ([#24250](https://github.com/anomalyco/opencode/pull/24250), [#24428](https://github.com/anomalyco/opencode/pull/24428), [#24895](https://github.com/anomalyco/opencode/pull/24895)) tried to fix it. None merged. The field is non-standard per OpenAI, so both OpenCode and the AI SDK ignore it.
96
-
97
- This repo fixes it. Three layers, pick what you need.
181
+ The field is non-standard per OpenAI, so SDKs and clients ignore it — the drop is
182
+ systemic, not a single tool's bug. This repo fixes it. Three layers, pick what you need.
98
183
 
99
184
  ---
100
185
 
101
- ## Option 1: plugin (stops the crashes)
186
+ ## Option 1: plugin (safety net)
102
187
 
103
188
  ### Install via npm (recommended)
104
189
 
@@ -119,7 +204,7 @@ It also handles `reasoning` for the OpenCode Go provider, and patches empty `con
119
204
 
120
205
  No config file changes. No build step. OpenCode compiles `.ts` plugins when it starts.
121
206
 
122
- **The catch:** the plugin fills in empty strings, not your model's actual prior thinking. DeepSeek, Kimi K2.5/K2.6, GLM, and MiMo accept empty strings fine, your conversation works but the model does not see its earlier reasoning. Kimi K2.7 Code rejects empty strings entirely, it needs the real text.
207
+ **The catch:** the plugin fills in empty strings, not your model's actual prior thinking. DeepSeek, Kimi K2.5/K2.6, GLM, and MiMo accept empty strings fine, your conversation works but the model does not see its earlier reasoning. Kimi K2.7 Code requires the field to be present; present-but-empty is accepted.
123
208
 
124
209
  ---
125
210
 
@@ -138,7 +223,7 @@ The proxy runs on **two ports**:
138
223
  | **3457** | Direct providers (DeepSeek, Kimi, GLM, MiMo, GPT, Claude, Qwen, Gemini, etc.) | `PORT=3457` |
139
224
  | **3458** | OpenCode Go provider | `PORT=3458` `UPSTREAM_URL=https://opencode.ai/zen/go/v1` |
140
225
 
141
- Port 3457 auto-routes based on model name using the built-in route table. Port 3458 is a fixed-upstream proxy specifically for the OpenCode Go provider, which uses `delta.reasoning` (not `reasoning_content`) in its SSE streams. Both are handled by the same `proxy.js` binary, just different environment variables.
226
+ Port 3457 auto-routes based on model name using the built-in route table. Port 3458 is a fixed-upstream proxy specifically for the OpenCode Go provider. It handles the provider's supported chat and Anthropic message dialects, while passing unsupported response formats through unchanged. Both are handled by the same `proxy.js` binary, just different environment variables.
142
227
 
143
228
  ```bash
144
229
  # Linux / macOS / Windows (Node.js required)
@@ -150,6 +235,44 @@ PORT=3458 UPSTREAM_URL=https://opencode.ai/zen/go/v1 node proxy/proxy.js
150
235
 
151
236
  > **Windows PowerShell:** use `$env:PORT=3457; node proxy/proxy.js` (PowerShell) or `set PORT=3457 && node proxy/proxy.js` (CMD).
152
237
 
238
+ ### OpenCode Go setup (explicit and credentials-safe)
239
+
240
+ The npm package intentionally does **not** run a `postinstall` script. It never
241
+ reads `auth.json`, edits your OpenCode configuration, starts a process, or
242
+ enables a service without your explicit action.
243
+
244
+ 1. In OpenCode, run `/connect` and select **OpenCode Go**. Keep the credential
245
+ in OpenCode's own local auth store; never paste it into this repository,
246
+ `opencode.json`, a shell script, or a public issue.
247
+ 2. Install the package and start its Go proxy manually:
248
+
249
+ ```bash
250
+ npm install opencode-thinking-fix
251
+ PORT=3458 UPSTREAM_URL=https://opencode.ai/zen/go/v1 \
252
+ node node_modules/opencode-thinking-fix/proxy/proxy.js
253
+ ```
254
+
255
+ 3. Point only the OpenCode Go provider at the local proxy. The `baseURL` must
256
+ be under `provider.<id>.options`:
257
+
258
+ ```json
259
+ {
260
+ "$schema": "https://opencode.ai/config.json",
261
+ "provider": {
262
+ "opencode-go": {
263
+ "options": {
264
+ "baseURL": "http://127.0.0.1:3458/v1"
265
+ }
266
+ }
267
+ }
268
+ }
269
+ ```
270
+
271
+ The proxy forwards the authorization header supplied by OpenCode to the
272
+ configured upstream and does not persist the credential. Stop the proxy when
273
+ it is not needed. The systemd and watchdog options below are deliberately
274
+ opt-in alternatives for operators who want automatic restarts.
275
+
153
276
  ### Install as systemd services (auto-start at boot)
154
277
 
155
278
  ```bash
@@ -167,10 +290,14 @@ Then point OpenCode at it, in your `opencode.json`:
167
290
  {
168
291
  "provider": {
169
292
  "deepseek-v4-pro": {
170
- "baseURL": "http://127.0.0.1:3457/v1"
293
+ "options": {
294
+ "baseURL": "http://127.0.0.1:3457/v1"
295
+ }
171
296
  },
172
297
  "opencode-go": {
173
- "baseURL": "http://127.0.0.1:3458/v1"
298
+ "options": {
299
+ "baseURL": "http://127.0.0.1:3458/v1"
300
+ }
174
301
  }
175
302
  }
176
303
  }
@@ -206,7 +333,7 @@ OpenCode → [plugin patches missing reasoning_content/reasoning]
206
333
  → API
207
334
  ```
208
335
 
209
- The plugin is the safety net. If the proxy goes down, the plugin still injects empty strings so you do not get 400s. If the proxy is up, its cached text takes priority because the plugin sees the field is already filled in. Either way, your conversation does not break.
336
+ The plugin is the safety net. If the proxy goes down, the plugin still injects empty strings so reasoning is never missing from the request. If the proxy is up, its cached text takes priority because the plugin sees the field is already filled in. Either way, your conversation keeps its thinking.
210
337
 
211
338
  ---
212
339
 
@@ -214,28 +341,29 @@ The plugin is the safety net. If the proxy goes down, the plugin still injects e
214
341
 
215
342
  | Model | Plugin helps | Proxy helps | What it needs |
216
343
  |---|---|---|---|
217
- | DeepSeek V4 Pro / Flash | Yes | Nice to have | Accepts `""` |
344
+ | DeepSeek V4 Pro / Flash | Yes | Nice to have | Accepts `""` (tool-call turns need real text) |
218
345
  | Kimi K2.5 / K2.6 | Yes | Nice to have | Accepts `""` |
219
- | **Kimi K2.7 Code** | **Not enough alone** | **Required** | Needs real text |
346
+ | **Kimi K2.7 Code** | **Not enough alone** | **Required** | Field must be *present*; real text keeps it coherent |
220
347
  | GLM-5.x / Zhipu | Yes | Nice to have | Accepts `""` |
221
- | MiMo V2.5 / MiniMax | Yes | Nice to have | Accepts `""` (default mode embeds `<think>` in `content`) |
348
+ | MiMo V2.5 | Yes | Nice to have | `reasoning_content` on `api.xiaomimimo.com/v1` |
222
349
  | **MiniMax-M3** | Yes | **Recommended** | `reasoning_details[]` array; ~40% quality loss if stripped. Proxy injects `reasoning_split:true` to keep thinking separate from content. |
223
- | OpenCode Go | Yes | Required | Uses `reasoning` field |
350
+ | OpenCode Go | Yes | Recommended for chat/message routes | Chat uses `reasoning`; Anthropic messages are handled; unsupported response formats pass through |
224
351
  | Qwen, GPT, Claude, Gemini, Llama, Mistral | No | No | No reasoning_content |
225
352
 
226
353
  ---
227
354
 
228
355
  ## Model routing (proxy port 3457)
229
356
 
230
- The proxy auto-routes by model name prefix. All 15 supported prefixes:
357
+ The proxy auto-routes by model name prefix. All routes:
231
358
 
232
359
  | Prefix | Upstream | Reasoning |
233
360
  |---|---|---|
234
- | `deepseek-v4-pro` | `https://api.deepseek.com` | Yes |
235
- | `deepseek` | `https://api.deepseek.com` | Yes |
236
- | `kimi`, `moonshot` | `https://api.moonshot.ai/v1` | Yes |
237
- | `glm`, `zhipu` | `https://open.bigmodel.cn/api/paas/v4` | Yes |
238
- | `minimax`, `mimo` | `https://api.minimax.io/v1` | Yes |
361
+ | `deepseek-v4-pro`, `deepseek-v4-flash`, `deepseek-chat` | `https://api.deepseek.com` | Yes (`reasoning_content`) |
362
+ | `deepseek-reasoner` | `https://api.deepseek.com` | **No — must NOT echo** (R1 contract) |
363
+ | `kimi`, `moonshot` | `https://api.moonshot.ai/v1` | Yes (`reasoning_content`) |
364
+ | `glm`, `zhipu` | `https://open.bigmodel.cn/api/paas/v4` | Yes (`reasoning_content`) |
365
+ | `minimax` | `https://api.minimax.io/v1` | Yes (`reasoning_details`, `reasoning_split:true`) |
366
+ | `mimo` | `https://api.xiaomimimo.com/v1` | Yes (`reasoning_content`) |
239
367
  | `gpt`, `o1` | `https://api.openai.com` | No |
240
368
  | `claude`, `anthropic` | `https://api.anthropic.com` | No |
241
369
  | `qwen` | `https://dashscope-intl.aliyuncs.com/compatible-mode/v1` | No |
@@ -249,56 +377,44 @@ Unknown models fall back to `https://api.deepseek.com` with reasoning disabled.
249
377
 
250
378
  ## Is it working?
251
379
 
252
- Turn 1 will not show anything, there is no history to patch yet. That is normal.
380
+ The plugin writes a structured JSON log: `~/.local/share/opencode/thinking-fix.log`.
253
381
 
254
- Turn 2+, check the console:
382
+ 628 unique sessions. 12,551 inspect events (the hook fires twice per message by design — first pass patches, second confirms clean). 297 reasoning model sessions patched, 331 non-reasoning correctly skipped. Zero false patches.
255
383
 
256
- **Plugin working:**
257
- ```
258
- [ThinkingFix] patched 3 field(s) across 11 message(s)
259
- ```
384
+ Before and after, from a real session:
260
385
 
261
- **Proxy working:**
262
386
  ```
263
- [Cache] session abcdefgh: stored reasoning turn 0 (1842 chars)
264
- [Cache] session abcdefgh: replayed reasoning for turn 0 (1842 chars)
387
+ Before: reasoning dropped on every turn → AI forgets its thinking
388
+ After: 34 fields patched across a 104-message session → reasoning replays correctly
265
389
  ```
266
390
 
267
- If nothing shows up, either it is a non-reasoning model (correct) or the plugin did not load (check for `[ThinkingFix] Plugin loaded` at startup).
268
-
269
- Quick proxy health check:
391
+ Here is a live excerpt from that session:
270
392
 
271
- ```bash
272
- curl http://127.0.0.1:3457/health
273
- # → {"ok":true,"uptime":42}
274
- curl http://127.0.0.1:3458/health
275
- # → {"ok":true,"uptime":42}
393
+ ```json
394
+ {"ts":"2026-06-25T01:41:50.572Z","event":"inspect","isReasoningModel":true,
395
+ "totalMessages":104,"patchedFields":34,"turns":[
396
+ {"index":1,"fields":["text","reasoning"]},
397
+ {"index":5,"fields":["text"]},
398
+ {"index":9,"fields":["text"]},
399
+ {"index":42,"fields":["reasoning"]}
400
+ ]}
276
401
  ```
277
402
 
278
- Proxy logs:
403
+ **No output?** Either you are on a non-reasoning model (correct, no patching needed) or the plugin did not load. Check:
279
404
 
280
405
  ```bash
281
- journalctl --user -u reasoning-cache.service -f
282
- journalctl --user -u reasoning-cache-go.service -f
406
+ grep plugin_loaded ~/.local/share/opencode/thinking-fix.log
283
407
  ```
284
408
 
285
- ---
286
-
287
- ## Running tests
409
+ Proxy health:
288
410
 
289
411
  ```bash
290
- npm test
291
- # or directly:
292
- node tests/test-plugin.js
293
- node tests/test-proxy.js
412
+ curl http://127.0.0.1:3457/health # → {"ok":true,"uptime":1225}
413
+ curl http://127.0.0.1:3458/health # → {"ok":true,"uptime":1225}
414
+ journalctl --user -u reasoning-cache.service -f
415
+ journalctl --user -u reasoning-cache-go.service -f
294
416
  ```
295
417
 
296
- The plugin tests cover 12 cases: native reasoning model detection, OpenCode Go `reasoning` field detection, non-reasoning model passthrough, mixed messages, multiple assistant turns, already-complete messages, wrapper format (`{ info: Message }`), empty `reasoning_content`, empty arrays, tool_calls with reasoning and without, and null/undefined wrappers.
297
-
298
- The proxy tests cover 15 cases: route resolution for all model prefixes, `patchRequestBody` injection from cache for both `reasoning_content` and `reasoning`, no-cache fallback to empty strings, user message isolation, multi-turn caching, and SSE stream parsing for `delta.reasoning_content`, `delta.reasoning`, content-triggered flush, and `finish_reason` flush.
299
-
300
- ---
301
-
302
418
  ## This bug is everywhere
303
419
 
304
420
  OpenCode is not the only tool that drops `reasoning_content`. Here is a partial list of places this same bug shows up:
@@ -329,10 +445,8 @@ OpenCode is not the only tool that drops `reasoning_content`. Here is a partial
329
445
  plugins/
330
446
  opencode-thinking-fix-universal.ts # self-detection plugin (92 lines)
331
447
  proxy/
332
- proxy.js # reasoning cache proxy (422 lines, 1 dep)
333
- tests/
334
- test-plugin.js # plugin unit tests (228 lines, 12 cases)
335
- test-proxy.js # proxy unit tests (359 lines, 15 cases)
448
+ core.js # pure logic: routes, cache, patching, parser (138 lines)
449
+ proxy.js # HTTP server + side effects (266 lines, 1 dep)
336
450
  watchdog/
337
451
  watchdog.sh # auto-recovery watchdog (64 lines)
338
452
  systemd/
@@ -341,6 +455,16 @@ systemd/
341
455
  reasoning-proxy-watchdog.service # watchdog systemd unit
342
456
  ```
343
457
 
458
+ ## Release highlights
459
+
460
+ - **v3.1.4:** proxy-owned structured JSONL logging with session identifiers truncated in logs.
461
+ - **v3.1.3:** Anthropic-wire dialect detection for OpenCode Go routes.
462
+ - **v3.1.2:** bounded cache/session memory, raw-stream preservation, hop-by-hop header removal, and safer parser failure handling.
463
+ - **v3.1.1:** corrected MiMo routing, non-streaming reasoning caching, and fixed partial-turn patching.
464
+ - **v3.1:** provider-aware reasoning fields, including the DeepSeek R1 no-echo route and safe passthrough for unknown models.
465
+
466
+ ---
467
+
344
468
  ## Tested on
345
469
 
346
470
  | Platform | Plugin | Proxy | Watchdog | Systemd |
package/package.json CHANGED
@@ -1,25 +1,54 @@
1
1
  {
2
2
  "name": "opencode-thinking-fix",
3
- "version": "2.0.0",
3
+ "version": "3.1.4",
4
4
  "description": "Fix reasoning_content 400 errors for DeepSeek/Kimi/GLM/MiMo/MiniMax in OpenCode",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "oc-plugin": ["server"],
7
+ "oc-plugin": [
8
+ "server"
9
+ ],
8
10
  "author": "tbosancheros39",
9
11
  "keywords": [
10
12
  "opencode",
13
+ "opencode-plugin",
14
+ "opencode-cli",
11
15
  "deepseek",
16
+ "deepseek-v4",
12
17
  "kimi",
18
+ "moonshot",
13
19
  "glm",
20
+ "zhipu",
14
21
  "mimo",
15
22
  "minimax",
16
- "reasoning",
23
+ "xiaomi-mimo",
24
+ "reasoning-content",
17
25
  "reasoning_content",
18
- "plugin"
26
+ "thinking-mode",
27
+ "tool-calls",
28
+ "multi-turn",
29
+ "400-error",
30
+ "http-400",
31
+ "proxy",
32
+ "plugin",
33
+ "cursor",
34
+ "cline",
35
+ "aider",
36
+ "roo-code",
37
+ "continue-dev",
38
+ "vscode",
39
+ "copilot",
40
+ "ai-coding",
41
+ "llm",
42
+ "chat-completion",
43
+ "openai-compatible",
44
+ "chinese-llm",
45
+ "agent",
46
+ "mcp",
47
+ "api-fix"
19
48
  ],
20
49
  "repository": {
21
50
  "type": "git",
22
- "url": "https://github.com/tbosancheros39/opencode-thinking-fix"
51
+ "url": "git+https://github.com/tbosancheros39/opencode-thinking-fix.git"
23
52
  },
24
53
  "bugs": {
25
54
  "url": "https://github.com/tbosancheros39/opencode-thinking-fix/issues"
@@ -32,20 +61,15 @@
32
61
  },
33
62
  "files": [
34
63
  "plugins/opencode-thinking-fix-universal.ts",
64
+ "proxy/core.js",
35
65
  "proxy/proxy.js",
36
66
  "systemd/reasoning-cache.service",
37
67
  "systemd/reasoning-cache-go.service",
38
68
  "systemd/reasoning-proxy-watchdog.service",
39
69
  "watchdog/watchdog.sh",
40
- "tests/test-plugin.js",
41
- "tests/test-proxy.js",
42
70
  "README.md",
43
- "CHANGELOG.md",
44
71
  "LICENSE.md"
45
72
  ],
46
- "scripts": {
47
- "test": "node tests/test-plugin.js && node tests/test-proxy.js"
48
- },
49
73
  "dependencies": {
50
74
  "eventsource-parser": "^3.1.0"
51
75
  },
@@ -61,6 +85,7 @@
61
85
  "node": ">=18"
62
86
  },
63
87
  "devDependencies": {
88
+ "@types/node": "^18.19.130",
64
89
  "typescript": "^6.0.3"
65
90
  }
66
91
  }