xonecas.io
64875
Mc

mini-coder / commit ee1f347

chore: todo and plan for reasoning display handling.

xonecas2026-03-11 ee1f347b6d6299045e593c00c3e187c03298bf88 parent 11c92d3

2 files changed

TODO.md+64−51
@@ -1,60 +1,67 @@
11 # TODO
22
3-## Investigate broken api with Gemini:
3+## Bug with chat completions models (kimi 2.5 for example)
4+
5+See bellow, there is the thinking spiner before each line, this doesn't happen with other models.
46
57 ```
6-⠴ thinking2438 | text: responseBody,
7-2439 | schema: errorSchema
8-2440 | });
9-2441 | return {
10-2442 | responseHeaders,
11-2443 | value: new APICallError4({
12- ^
13-AI_APICallError: Unable to submit request because function call `default_api:replace` in the 26. content block is missing a `thought_signature`. Learn more: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/thought-signatures
14- cause: undefined,
15- url: "https://opencode.ai/zen/v1/models/gemini-3.1-pro:streamGenerateContent?alt=sse",
16- requestBodyValues: {
17- generationConfig: [Object ...],
18- contents: [
19- [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...], [Object ...]
20- ],
21- systemInstruction: [Object ...],
22- safetySettings: undefined,
23- tools: [
24- [Object ...]
25- ],
26- toolConfig: [Object ...],
27- cachedContent: undefined,
28- labels: undefined,
29-},
30- statusCode: 400,
31- responseHeaders: {
32- "cf-ray": "9da99240986c1124-ORD",
33- connection: "keep-alive",
34- "content-type": "text/event-stream",
35- date: "Wed, 11 Mar 2026 09:35:55 GMT",
36- server: "cloudflare",
37- "transfer-encoding": "chunked",
38-},
39- responseBody: "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Unable to submit request because function call `default_api:replace` in the 26. content block is missing a `thought_signature`. Learn more: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/thought-signatures\",\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n",
40- isRetryable: false,
41- data: {
42- error: [Object ...],
43-},
44- vercel.ai.error: true,
45- vercel.ai.error.AI_APICallError: true,
46-
47- at /Users/seancaetanomartin/src/mini-coder/node_modules/@ai-sdk/provider-utils/dist/index.mjs:2443:18
48- at /Users/seancaetanomartin/src/mini-coder/node_modules/@ai-sdk/provider-utils/dist/index.mjs:2286:34
49- at processTicksAndRejections (native:7:39)
50-
51-✖ API error 400
52- https://opencode.ai/zen/v1/models/gemini-3.1-pro:streamGenerateContent?alt=sse
53-✖ API error 400
54- https://opencode.ai/zen/v1/models/gemini-3.1-pro:streamGenerateContent?alt=sse
8+⠦ thinkingAdd reasoning indicator (e.g., "🤔" or "thinking") when `showReasoning` is true
9+
10+⠧ thinkingPhase 5: Update Command Context & CLI Commands
11+⠏ thinkingFiles: `src/cli/commands.ts`, `src/agent/session-runner.ts`, `src/index.ts`
12+
13+⠋ thinking1. Add `showReasoning` to `CommandContext`
14+⠹ thinking2. Add `/reasoning` command to toggle (on|off)
15+⠸ thinking3. Load/save preference from settings repo
16+⠼ thinking4. Pass setting through to `SessionRunner` and reporter
17+
18+⠦ thinkingPhase 6: Update Output Reporter & Headless Reporter
19+⠧ thinkingFiles: `src/cli/output-reporter.ts`, `src/cli/headless-reporter.ts`
20+
21+⠋ thinking1. Accept and forward `showReasoning` option
22+⠙ thinking2. Headless reporter: still consume reasoning events (for accumulation) but never render
23+
24+Phase 7: Agent Integration
25+Files: `src/agent/agent.ts`
26+
27+⠹ thinking1. Load `getShowReasoning()` preference
28+2. Pass to `CommandContext` and `SessionRunner`
29+⠸ thinking3. Update status bar calls to include reasoning flag
30+
31+⠼ thinkingPhase 8: Help & Documentation
32+Files: `src/cli/commands.ts`
33+
34+⠴ thinkingAdd `/reasoning` to help text
35+
36+────────────────────────────────────────
37+
38+⠦ thinkingFiles to Modify (in dependency order):
39+
40+⠧ thinking1. `src/session/db/settings-repo.ts` - Add new setting functions
41+⠇ thinking2. `src/llm-api/types.ts` - Add reasoning to TurnResult (if needed)
42+⠋ thinking3. `src/agent/reporter.ts` - Update StatusBarData
43+4. `src/cli/stream-render.ts` - Add showReasoning option
44+⠙ thinking5. `src/cli/status-bar.ts` - Add reasoning indicator
45+⠹ thinking6. `src/cli/output-reporter.ts` - Forward option
46+⠸ thinking7. `src/cli/headless-reporter.ts` - Handle reasoning events
47+⠼ thinking8. `src/cli/commands.ts` - Add /reasoning command
48+⠴ thinking9. `src/agent/session-runner.ts` - Accept and pass through setting
49+⠦ thinking10. `src/agent/agent.ts` - Load preference, wire up
50+⠧ thinking11. `src/index.ts` - Load preference on startup
51+⠇ thinking12. `src/session/db/index.ts` - Export new functions
52+
53+⠏ thinkingThis is a clean, incremental change that:
54+⠋ thinking· Maintains backward compatibility (defaults to showing reasoning)
55+⠙ thinking· Separates the "reasoning effort" setting from "reasoning display" setting
56+⠹ thinking· Properly accumulates reasoning text for message history
57+⠼ thinking· Works in both interactive and headless modes
58+kimi-k2.5 ✦ high mmm7tm8p ~/src/mini-coder ⎇ main ctx 37.9k/262.1k 14% ↑ 172.2k ↓ 2.3k
59+▶
5560 ```
5661
57-## Gpt 5.4 starts printing garbage:
62+---
63+
64+## Gpt 5.4 starts printing tool calls as the assistant message:
5865
5966 ```
6067 ← read src/llm-api/turn.test.ts:108+50
@@ -88,6 +95,10 @@ AI_APICallError: Unable to submit request because function call `default_api:rep
8895 error: script "dev" exited with code 130
8996 ```
9097
98+I was not able to reproduce the same behaviour with opencode using the same provider. Which points to an issue with our code.
99+
100+---
101+
91102 ## Gpt codex context window maxinng out
92103
93104 I've noticed several sessions with codex spark that error because the context got too big for the model:
@@ -112,6 +123,8 @@ error: script "dev" exited with code 1
112123
113124 The same task with GPT 5.4: `ctx 82.8k/1050.0k 8%` used on 82k in context. I know spark is a smaller context, but I'm suprised by how often we max out the 128k context.
114125
126+---
127+
115128 ## LSP Diagnostics (not very important, with tool-hooks and strong linting, this is not as necessary, but we should implement asap)
116129
117130 We should have a closed loop feedback for LSP diagnostics on edits/reads.
reasoning-display-plan.md+118−0
@@ -0,0 +1,118 @@
1+# Implementation Plan: Reasoning Display Support
2+
3+## Current State Analysis
4+
5+### What Already Exists:
6+
7+| Component | Current State |
8+|-----------|---------------|
9+| `ReasoningDeltaEvent` in `types.ts` | ✅ Event type defined |
10+| `runTurn()` in `turn.ts` | ✅ Generates `reasoning-delta` events from AI SDK streams |
11+| `renderTurn()` in `stream-render.ts` | ✅ Handles events, shows "Thinking..." header, renders dimmed text |
12+| `preferred_thinking_effort` | ✅ Controls how much reasoning the model does (separate concern) |
13+
14+### What's Missing:
15+
16+| Component | Missing |
17+|-------------|---------|
18+| User setting | No toggle to show/hide reasoning output |
19+| `accumulatedText` | Reasoning not accumulated (unlike regular text) |
20+| Message persistence | Reasoning not stored in message history |
21+| Headless reporter | Ignores reasoning events |
22+| Status bar | No indicator for reasoning display mode |
23+
24+---
25+
26+## Implementation Plan
27+
28+### Phase 1: Add Settings Infrastructure
29+**Files: `src/session/db/settings-repo.ts`**
30+
31+Add `preferred_show_reasoning` setting (boolean stored as "true"/"false" string):
32+- `getShowReasoning(): boolean` - returns true by default
33+- `setShowReasoning(show: boolean): void`
34+
35+### Phase 2: Update Reporter Interface & Types
36+**Files: `src/agent/reporter.ts`, `src/llm-api/types.ts`**
37+
38+1. Add `showReasoning?: boolean` to `StatusBarData` interface
39+2. Add `reasoningText` to `TurnResult` so reasoning can be accumulated and returned
40+
41+### Phase 3: Update Stream Rendering
42+**Files: `src/cli/stream-render.ts`**
43+
44+1. Accept `showReasoning` option in `renderTurn()`
45+2. When `showReasoning` is false: consume reasoning events but don't render them
46+3. Accumulate reasoning text into a separate buffer (not mixed with `accumulatedText`)
47+4. Return accumulated reasoning in `TurnResult`
48+
49+### Phase 4: Update Status Bar
50+**Files: `src/cli/status-bar.ts`**
51+
52+Add reasoning indicator (e.g., "🤔" or "thinking") when `showReasoning` is true
53+
54+### Phase 5: Update Command Context & CLI Commands
55+**Files: `src/cli/commands.ts`, `src/agent/session-runner.ts`, `src/index.ts`**
56+
57+1. Add `showReasoning` to `CommandContext`
58+2. Add `/reasoning` command to toggle (on|off)
59+3. Load/save preference from settings repo
60+4. Pass setting through to `SessionRunner` and reporter
61+
62+### Phase 6: Update Output Reporter & Headless Reporter
63+**Files: `src/cli/output-reporter.ts`, `src/cli/headless-reporter.ts`**
64+
65+1. Accept and forward `showReasoning` option
66+2. Headless reporter: still consume reasoning events (for accumulation) but never render
67+
68+### Phase 7: Agent Integration
69+**Files: `src/agent/agent.ts`**
70+
71+1. Load `getShowReasoning()` preference
72+2. Pass to `CommandContext` and `SessionRunner`
73+3. Update status bar calls to include reasoning flag
74+
75+### Phase 8: Help & Documentation
76+**Files: `src/cli/commands.ts`**
77+
78+Add `/reasoning` to help text
79+
80+---
81+
82+## Files to Modify (in dependency order):
83+
84+1. `src/session/db/settings-repo.ts` - Add new setting functions
85+2. `src/llm-api/types.ts` - Add reasoning to TurnResult (if needed)
86+3. `src/agent/reporter.ts` - Update StatusBarData
87+4. `src/cli/stream-render.ts` - Add showReasoning option
88+5. `src/cli/status-bar.ts` - Add reasoning indicator
89+6. `src/cli/output-reporter.ts` - Forward option
90+7. `src/cli/headless-reporter.ts` - Handle reasoning events
91+8. `src/cli/commands.ts` - Add /reasoning command
92+9. `src/agent/session-runner.ts` - Accept and pass through setting
93+10. `src/agent/agent.ts` - Load preference, wire up
94+11. `src/index.ts` - Load preference on startup
95+12. `src/session/db/index.ts` - Export new functions
96+
97+---
98+
99+## Design Decisions
100+
101+1. **Separate from thinking effort**: The existing `thinkingEffort` controls how much reasoning the model *produces*. The new `showReasoning` controls whether we *display* it. These are orthogonal concerns.
102+
103+2. **Default to true**: Users who have models with reasoning capability expect to see it. They can opt out.
104+
105+3. **Accumulate separately, don't persist**: Reasoning text should be accumulated for display purposes only. It must **NOT** be added to the message history that gets sent back to the model on subsequent turns - this would bloat the context window unnecessarily. The reasoning is ephemeral UI feedback, not part of the conversation state.
106+
107+4. **Headless mode**: Even when headless, we consume reasoning events to properly track state, but never render them (headless is non-interactive). The accumulated reasoning is discarded, not stored.
108+
109+## Additional Considerations
110+
111+### Context Window Bloat Prevention
112+
113+The reasoning output can be substantial (especially with high thinking effort). We must ensure:
114+
115+- `reasoningText` is **never** added to `coreHistory` or `session.messages`
116+- `reasoningText` is **never** returned in `TurnResult.messages` or `TurnCompleteEvent.messages`
117+- The reasoning is for UI display only and is discarded after the turn completes
118+- Abort message building (`buildAbortMessages`) should not include reasoning text