From f57b42fd6e34c4e179cfa303e777c98916299746 Mon Sep 17 00:00:00 2001 From: db123-ai Date: Wed, 10 Jun 2026 01:10:15 +0330 Subject: [PATCH] =?UTF-8?q?docs:=20refine=20Phase=202=20=E2=80=94=20chat?= =?UTF-8?q?=20templates=20+=20reasoning=20parser=20+=20collapsible=20TUI?= =?UTF-8?q?=20thoughts=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plan.md | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/plan.md b/plan.md index d69d670..8a44a23 100644 --- a/plan.md +++ b/plan.md @@ -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 ---