xonecas.io
62159
Sy

symb / commit 7eaa823

fix: token count + context size corrected

xonecas2026-02-15 7eaa82392201fc473c05d580f74eccf24233f858 parent bf5a0de

5 files changed

internal/tui/conv.go+2−2
@@ -119,10 +119,10 @@ func formatTokens(n int) string {
119119 }
120120
121121 // makeSeparator builds a right-aligned timestamp/token separator line.
122-func (m Model) makeSeparator(dur string, ts string, tokIn, tokOut, totalTok int) string {
122+func (m Model) makeSeparator(dur string, ts string, tokIn, tokOut, totalTok, ctxTok int) string {
123123 var label string
124124 if tokIn > 0 || tokOut > 0 {
125- label = fmt.Sprintf("%s %s %sin/%sout (%s)", dur, ts, formatTokens(tokIn), formatTokens(tokOut), formatTokens(totalTok))
125+ label = fmt.Sprintf("%s %s ↓%s ↑%s Σ%s ◫%s", dur, ts, formatTokens(tokIn), formatTokens(tokOut), formatTokens(totalTok), formatTokens(ctxTok))
126126 } else {
127127 label = dur + " " + ts
128128 }
internal/tui/messages.go+12−9
@@ -33,10 +33,11 @@ type llmToolResultMsg struct {
3333 }
3434
3535 type llmDoneMsg struct {
36- duration time.Duration
37- timestamp string
38- inputTokens int
39- outputTokens int
36+ duration time.Duration
37+ timestamp string
38+ inputTokens int
39+ outputTokens int
40+ contextTokens int
4041 }
4142
4243 type llmUsageMsg struct {
@@ -171,7 +172,7 @@ func (m Model) processLLM() tea.Cmd {
171172 }
172173
173174 start := time.Now()
174- var turnIn, turnOut int
175+ var turnIn, turnOut, contextIn int
175176 err := llm.ProcessTurn(ctx, llm.ProcessTurnOptions{
176177 Provider: prov,
177178 Proxy: proxy,
@@ -190,6 +191,7 @@ func (m Model) processLLM() tea.Cmd {
190191 OnUsage: func(inputTokens, outputTokens int) {
191192 turnIn += inputTokens
192193 turnOut += outputTokens
194+ contextIn = inputTokens
193195 ch <- llmUsageMsg{inputTokens: inputTokens, outputTokens: outputTokens}
194196 },
195197 OnMessage: func(msg provider.Message) {
@@ -222,10 +224,11 @@ func (m Model) processLLM() tea.Cmd {
222224 return
223225 }
224226 ch <- llmDoneMsg{
225- duration: time.Since(start),
226- timestamp: start.Format("15:04"),
227- inputTokens: turnIn,
228- outputTokens: turnOut,
227+ duration: time.Since(start),
228+ timestamp: start.Format("15:04"),
229+ inputTokens: turnIn,
230+ outputTokens: turnOut,
231+ contextTokens: contextIn,
229232 }
230233 }()
231234 return nil
internal/tui/mouse.go+2−0
@@ -152,6 +152,8 @@ func (m *Model) handleConvMouse(msg tea.MouseMsg, x, y int) tea.Cmd {
152152 func (m *Model) handleConvMotion(x, y, totalLines int) {
153153 if m.convDragging && m.convSel != nil && totalLines > 0 {
154154 m.convSel.active = m.convPosFromScreen(x, y, totalLines)
155+ } else if !m.convDragging && m.convSel != nil {
156+ m.convSel = nil
155157 }
156158 if totalLines > 0 {
157159 lineIdx := m.visibleStartLine() + (y - m.layout.conv.Min.Y)
internal/tui/tui.go+1−0
@@ -223,6 +223,7 @@ type Model struct {
223223 // Token usage tracking
224224 turnInputTokens int // accumulated input tokens for current turn
225225 turnOutputTokens int // accumulated output tokens for current turn
226+ turnContextTokens int // context size (last API call's input tokens)
226227 totalInputTokens int // session-wide total input tokens
227228 totalOutputTokens int // session-wide total output tokens
228229
internal/tui/update.go+4−2
@@ -252,11 +252,12 @@ func (m *Model) handleUserMsg(msg llmUserMsg) Model {
252252
253253 m.appendText(highlightMarkdown(msg.content, m.styles.Text)...)
254254 m.appendText("")
255- sep := m.makeSeparator("0s", now.Format("15:04:05"), 0, 0, 0)
255+ sep := m.makeSeparator("0s", now.Format("15:04:05"), 0, 0, 0, 0)
256256 wasBottom := m.appendText(sep)
257257 m.appendText("")
258258 m.turnInputTokens = 0
259259 m.turnOutputTokens = 0
260+ m.turnContextTokens = 0
260261 if wasBottom {
261262 m.scrollOffset = 0
262263 }
@@ -331,8 +332,9 @@ func (m Model) handleLLMBatch(batch llmBatchMsg) (tea.Model, tea.Cmd) {
331332 m.lastNetError = ""
332333 m.demoteOldUndo()
333334 m.appendText("")
335+ m.turnContextTokens = msg.contextTokens
334336 sep := m.makeSeparator(msg.duration.Round(time.Second).String(), msg.timestamp,
335- msg.inputTokens, msg.outputTokens, m.totalInputTokens+m.totalOutputTokens)
337+ msg.inputTokens, msg.outputTokens, m.totalInputTokens+m.totalOutputTokens, m.turnContextTokens)
336338 m.appendConv(m.makeUndoEntry(sep)...)
337339 m.trimOldTurns()
338340 return m, nil