docs: refine Phase 2 — chat templates + reasoning parser + collapsible TUI thoughts section

This commit is contained in:
2026-06-10 01:10:15 +03:30
parent 9903c7b12b
commit f57b42fd6e

26
plan.md
View File

@@ -136,19 +136,37 @@ CREATE TABLE context_state (
---
## Phase 2 — Prompt Templating & Format Fix
## Phase 2 — Prompt Templating & Reasoning-Aware TUI
**Goal:** Fix model output. Swap raw prompt text for a configurable chat template so the model only returns the assistant response, not reasoning meta-text.
**Goal:** Fix model output with proper chat templates. Parse reasoning/thoughts from the response and render them beautifully in the TUI — dimmed, collapsible, like OpenCode.
### Chat Template Engine
- [ ] `internal/llama/template.go` — chat template formatter:
- ChatML: `<|im_start|>system\n...<|im_end|>\n<|im_start|>user\n...<|im_end|>\n<|im_start|>assistant\n`
- Llama 3 instruct: `<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n...<|eot_id|>`
- DeepSeek R1: with `...` support
- Configurable via env `CHAT_TEMPLATE=chatml` (default)
- [ ] Refactor `companion/promptbuilder.go` to output structured segments (system context, personality, relationship, conversation history, user message)
- [ ] Let template.go wrap those segments in the chosen format
- [ ] Strip system prompt of raw formatting headers — let template handle structure
- [ ] Add `stop` tokens per template (`<|im_end|>`, `<|eot_id|>`)
- [ ] **Test:** "hi" produces just "Hello!" not paragraphs of self-correction
- [ ] **Test:** "hi" produces just the response, no meta-text
### Reasoning Parser
- [ ] `internal/agent/reasoning.go` — parse `...`, `...`, or custom tags from model output
- [ ] Split response into `Reasoning` (thoughts) and `Content` (final answer)
- [ ] Store both separately in the `messages` table
- [ ] Feed only `Content` back into context window (reasoning is discarded after display)
### TUI Enhancement
- [ ] Render reasoning in a collapsible section:
- Header: "💭 (or `...`) with reasoning snippet
- On click/expand: show full reasoning in dimmed/italic style (`lipgloss.Color("#6B7280")`)
- [ ] Render final answer in normal assistant style (green/bold)
- [ ] Reasoning hidden by default, toggle with a keybinding (e.g., `tab`)
- [ ] **Test:** Send a prompt that triggers reasoning, verify collapsible display
---