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

@ -14,15 +14,41 @@ export const mergeToolShelfInto = (target: Msg, source: Msg): Msg => ({
tools: [...(target.tools ?? []), ...(source.tools ?? [])]
})
const isBarrierMessage = (msg: Msg | undefined) => {
if (!msg) {
return true
}
// Assistant text, user input, intro/panel rows all terminate the shelf.
if (msg.kind === 'intro' || msg.kind === 'panel' || msg.kind === 'diff') {
return true
}
if (msg.role && msg.role !== 'system') {
return true
}
if (msg.text) {
return true
}
return false
}
const isToolCarryingTrail = (msg: Msg | undefined) =>
Boolean(msg?.kind === 'trail' && !msg.text && msg.tools?.length)
export const appendToolShelfMessage = (prev: readonly Msg[], msg: Msg): Msg[] => {
if (!isToolShelfMessage(msg)) {
return [...prev, msg]
}
let fallbackHolder: number | null = null
for (let index = prev.length - 1; index >= 0; index--) {
const candidate = prev[index]
if (canHoldToolShelf(candidate)) {
if (isToolCarryingTrail(candidate)) {
const next = [...prev]
next[index] = mergeToolShelfInto(candidate!, msg)
@ -30,10 +56,22 @@ export const appendToolShelfMessage = (prev: readonly Msg[], msg: Msg): Msg[] =>
return next
}
if (candidate?.kind !== 'trail' || candidate.text) {
if (fallbackHolder === null && canHoldToolShelf(candidate)) {
fallbackHolder = index
}
if (isBarrierMessage(candidate)) {
break
}
}
if (fallbackHolder !== null) {
const next = [...prev]
next[fallbackHolder] = mergeToolShelfInto(prev[fallbackHolder]!, msg)
return next
}
return [...prev, msg]
}