fix(tui): inline todo in transcript, group across thinking

This commit is contained in:
Brooklyn Nicholson 2026-04-26 16:09:28 -05:00
parent 4943ea2a7c
commit 319c1c1691
6 changed files with 104 additions and 30 deletions

View file

@ -1,5 +1,7 @@
import { describe, expect, it } from 'vitest'
import type { Msg } from '../types.js'
import { appendToolShelfMessage, canHoldToolShelf, isTodoDone, mergeToolShelfInto } from './liveProgress.js'
describe('isTodoDone', () => {
@ -54,6 +56,52 @@ describe('appendToolShelfMessage', () => {
expect(merged).toEqual([{ kind: 'trail', role: 'system', text: '', thinking: 'plan', tools: ['one ✓', 'two ✓'] }])
})
it('merges through intervening thinking-only rows back into the nearest holder', () => {
const prev: Msg[] = [
{ kind: 'trail', role: 'system', text: '', thinking: 'plan', tools: ['one ✓'] },
{ kind: 'trail', role: 'system', text: '', thinking: 'more plan' }
]
const merged = appendToolShelfMessage(prev, {
kind: 'trail',
role: 'system',
text: '',
tools: ['two ✓']
})
expect(merged).toHaveLength(2)
expect(merged[0]).toEqual({
kind: 'trail',
role: 'system',
text: '',
thinking: 'plan',
tools: ['one ✓', 'two ✓']
})
expect(merged[1]).toEqual({ kind: 'trail', role: 'system', text: '', thinking: 'more plan' })
})
it('collapses a chronological thinking/tool/thinking/tool stream into one shelf', () => {
const events: Msg[] = [
{ kind: 'trail', role: 'system', text: '', thinking: 'plan' },
{ kind: 'trail', role: 'system', text: '', tools: ['one ✓'] },
{ kind: 'trail', role: 'system', text: '', thinking: 'more plan' },
{ kind: 'trail', role: 'system', text: '', tools: ['two ✓'] },
{ kind: 'trail', role: 'system', text: '', tools: ['three ✓'] }
]
const reduced = events.reduce<Msg[]>((acc, msg) => appendToolShelfMessage(acc, msg), [])
expect(reduced).toHaveLength(2)
expect(reduced[0]).toEqual({
kind: 'trail',
role: 'system',
text: '',
thinking: 'plan',
tools: ['one ✓', 'two ✓', 'three ✓']
})
expect(reduced[1]).toEqual({ kind: 'trail', role: 'system', text: '', thinking: 'more plan' })
})
it('starts a new shelf across assistant text boundaries', () => {
const merged = appendToolShelfMessage(
[{ kind: 'trail', role: 'system', text: '', tools: ['one ✓'] }, { role: 'assistant', text: 'done' }],