fix(tui): merge tools into contextual shelves

This commit is contained in:
Brooklyn Nicholson 2026-04-26 16:00:38 -05:00
parent 4d3e3a738d
commit 4943ea2a7c
2 changed files with 25 additions and 3 deletions

View file

@ -6,9 +6,14 @@ export const isTodoDone = (todos: readonly TodoItem[]) =>
export const isToolShelfMessage = (msg: Msg | undefined) =>
Boolean(msg?.kind === 'trail' && !msg.text && !msg.thinking?.trim() && msg.tools?.length)
const canHoldToolShelf = (msg: Msg | undefined) =>
export const canHoldToolShelf = (msg: Msg | undefined) =>
Boolean(msg?.kind === 'trail' && !msg.text && (msg.thinking?.trim() || msg.tools?.length))
export const mergeToolShelfInto = (target: Msg, source: Msg): Msg => ({
...target,
tools: [...(target.tools ?? []), ...(source.tools ?? [])]
})
export const appendToolShelfMessage = (prev: readonly Msg[], msg: Msg): Msg[] => {
if (!isToolShelfMessage(msg)) {
return [...prev, msg]
@ -20,7 +25,7 @@ export const appendToolShelfMessage = (prev: readonly Msg[], msg: Msg): Msg[] =>
if (canHoldToolShelf(candidate)) {
const next = [...prev]
next[index] = { ...candidate!, tools: [...(candidate!.tools ?? []), ...(msg.tools ?? [])] }
next[index] = mergeToolShelfInto(candidate!, msg)
return next
}