fix(tui): keep todo pinned outside transcript

This commit is contained in:
Brooklyn Nicholson
2026-04-26 15:33:01 -05:00
parent 3271ffbd80
commit cf8439263a
6 changed files with 45 additions and 5 deletions

View File

@@ -4,6 +4,6 @@ import { liveTailOrder } from './liveLayout.js'
describe('liveTailOrder', () => {
it('keeps todo before transcript and assistant live output', () => {
expect(liveTailOrder()).toEqual(['todo', 'history', 'assistant'])
expect(liveTailOrder()).toEqual(['todo', 'scroll-history', 'assistant'])
})
})

View File

@@ -1 +1 @@
export const liveTailOrder = () => ['todo', 'history', 'assistant'] as const
export const liveTailOrder = () => ['todo', 'scroll-history', 'assistant'] as const

View File

@@ -0,0 +1,23 @@
import { describe, expect, it } from 'vitest'
import { appendTranscriptMessage } from './messages.js'
describe('appendTranscriptMessage', () => {
it('merges adjacent tool-only shelves into one transcript row', () => {
const out = appendTranscriptMessage(
[{ kind: 'trail', role: 'system', text: '', tools: ['Terminal("one") ✓'] }],
{ kind: 'trail', role: 'system', text: '', tools: ['Terminal("two") ✓'] }
)
expect(out).toEqual([{ kind: 'trail', role: 'system', text: '', tools: ['Terminal("one") ✓', 'Terminal("two") ✓'] }])
})
it('does not merge tool shelves across thinking text', () => {
const out = appendTranscriptMessage(
[{ kind: 'trail', role: 'system', text: '', thinking: 'plan', tools: ['Terminal("one") ✓'] }],
{ kind: 'trail', role: 'system', text: '', tools: ['Terminal("two") ✓'] }
)
expect(out).toHaveLength(2)
})
})

View File

@@ -1,4 +1,17 @@
import type { Msg, Role } from '../types.js'
const isToolShelf = (msg: Msg | undefined) =>
Boolean(msg?.kind === 'trail' && !msg.text && !msg.thinking?.trim() && msg.tools?.length)
export const appendTranscriptMessage = (prev: Msg[], msg: Msg): Msg[] => {
if (isToolShelf(msg) && isToolShelf(prev.at(-1))) {
const last = prev.at(-1)!
return [...prev.slice(0, -1), { ...last, tools: [...(last.tools ?? []), ...(msg.tools ?? [])] }]
}
return [...prev, msg]
}
export const upsert = (prev: Msg[], role: Role, text: string): Msg[] =>
prev.at(-1)?.role === role ? [...prev.slice(0, -1), { role, text }] : [...prev, { role, text }]