Skip to content

Commit 0314cb8

Browse files
committed
Keep tool call branches collapsed
1 parent cb2c732 commit 0314cb8

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

cli/src/components/branch-item.tsx

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ interface BranchItemProps {
3232
statusColor?: string
3333
statusIndicator?: string
3434
theme: ChatTheme
35-
onToggle: () => void
35+
onToggle?: () => void
3636
showBorder?: boolean
37+
toggleEnabled?: boolean
38+
titleSuffix?: string
3739
}
3840

3941
export const BranchItem = ({
@@ -52,6 +54,8 @@ export const BranchItem = ({
5254
theme,
5355
onToggle,
5456
showBorder = true,
57+
toggleEnabled = true,
58+
titleSuffix,
5559
}: BranchItemProps) => {
5660
const resolveFg = (
5761
color?: string | null,
@@ -80,9 +84,8 @@ export const BranchItem = ({
8084
? theme.statusAccent
8185
: theme.chromeText ?? toggleFrameColor
8286
const toggleLabelColor = theme.chromeText ?? toggleFrameColor
83-
const toggleLabel = `${
84-
branchChar ? `${branchChar} ` : ''
85-
}${isCollapsed ? '▸' : '▾'} `
87+
const toggleIndicator = toggleEnabled ? (isCollapsed ? '▸ ' : '▾ ') : ''
88+
const toggleLabel = `${branchChar}${toggleIndicator}`
8689
const collapseButtonFrame = theme.agentToggleExpandedBg
8790
const collapseButtonText = collapseButtonFrame
8891
const toggleFrameFg = resolveFg(toggleFrameColor, fallbackTextColor)
@@ -247,7 +250,7 @@ export const BranchItem = ({
247250
paddingBottom: isCollapsed ? 0 : 1,
248251
width: '100%',
249252
}}
250-
onMouseDown={onToggle}
253+
onMouseDown={toggleEnabled && onToggle ? onToggle : undefined}
251254
>
252255
<text style={{ wrapMode: 'none' }}>
253256
<span {...(toggleIconFg ? { fg: toggleIconFg } : undefined)}>
@@ -259,6 +262,14 @@ export const BranchItem = ({
259262
>
260263
{name}
261264
</span>
265+
{titleSuffix ? (
266+
<span
267+
{...(toggleLabelFg ? { fg: toggleLabelFg } : undefined)}
268+
attributes={TextAttributes.BOLD}
269+
>
270+
{` ${titleSuffix}`}
271+
</span>
272+
) : null}
262273
{statusText ? (
263274
<span
264275
fg={statusColor ?? theme.agentResponseCount}
@@ -331,22 +342,24 @@ export const BranchItem = ({
331342
</box>
332343
)}
333344
{renderExpandedContent(content)}
334-
<box
335-
style={{
336-
alignSelf: 'flex-end',
337-
marginTop: content ? 0 : 1,
338-
paddingRight: showBorder ? 1 : 0,
339-
paddingBottom: 0,
340-
marginBottom: 0,
341-
}}
342-
>
343-
<RaisedPill
344-
segments={[{ text: 'Collapse', fg: collapseButtonText }]}
345-
frameColor={collapseButtonFrame}
346-
textColor={collapseButtonText}
347-
onPress={onToggle}
348-
/>
349-
</box>
345+
{toggleEnabled && onToggle && (
346+
<box
347+
style={{
348+
alignSelf: 'flex-end',
349+
marginTop: content ? 0 : 1,
350+
paddingRight: showBorder ? 1 : 0,
351+
paddingBottom: 0,
352+
marginBottom: 0,
353+
}}
354+
>
355+
<RaisedPill
356+
segments={[{ text: 'Collapse', fg: collapseButtonText }]}
357+
frameColor={collapseButtonFrame}
358+
textColor={collapseButtonText}
359+
onPress={onToggle}
360+
/>
361+
</box>
362+
)}
350363
</box>
351364
)}
352365
</box>

cli/src/components/message-block.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const MessageBlock = ({
8686
const ancestorPrefix = ancestorBranchStates
8787
.map((ancestorIsLast) => (ancestorIsLast ? ' ' : '│ '))
8888
.join('')
89-
return `${ancestorPrefix}${isLastBranch ? '└ ' : '├ '}`
89+
return `${ancestorPrefix}${isLastBranch ? '└ ' : '├ '}`
9090
}
9191

9292
const renderContentWithMarkdown = (
@@ -161,7 +161,7 @@ export const MessageBlock = ({
161161
}
162162

163163
const displayInfo = getToolDisplayInfo(toolBlock.toolName)
164-
const isCollapsed = collapsedAgents.has(toolBlock.toolCallId)
164+
const isCollapsed = true
165165
const isStreaming = streamingAgents.has(toolBlock.toolCallId)
166166

167167
const inputContent = `\`\`\`json\n${JSON.stringify(toolBlock.input, null, 2)}\n\`\`\``
@@ -183,12 +183,11 @@ export const MessageBlock = ({
183183
: null
184184

185185
const branchChar = computeBranchChar(ancestorBranchStates, isLastBranch)
186-
const indentPrefix = branchChar.replace(/[]\s*$/, '')
186+
const indentPrefix = branchChar.replace(/[]\s*$/, '')
187187
const previewBasePrefix =
188188
indentPrefix.length > 0 ? `${indentPrefix}│ ` : ' │ '
189-
const toggleLabel = `${branchChar ? `${branchChar} ` : ''}${isCollapsed ? '▸' : '▾'} `
190189
const branchIndentWidth = stringWidth(branchChar)
191-
const headerPrefixWidth = stringWidth(toggleLabel)
190+
const headerPrefixWidth = stringWidth(branchChar)
192191
const previewBaseWidth = stringWidth(previewBasePrefix)
193192
const alignmentPadding = Math.max(0, headerPrefixWidth - previewBaseWidth)
194193
const paddedPreviewPrefix = `${previewBasePrefix}${' '.repeat(alignmentPadding)}`
@@ -223,7 +222,7 @@ export const MessageBlock = ({
223222
toolRenderConfig.collapsedPreview ??
224223
getToolFinishedPreview(toolBlock, commandPreview, lastLine)
225224
const finishedPreview =
226-
!isStreaming && isCollapsed ? formatPreview(collapsedPreviewBase) : ''
225+
!isStreaming ? formatPreview(collapsedPreviewBase) : ''
227226
const agentMarkdownOptions = getAgentMarkdownOptions(indentLevel)
228227
const displayContent = renderContentWithMarkdown(
229228
fullContent,
@@ -265,9 +264,7 @@ export const MessageBlock = ({
265264
</box>
266265
) : renderableDisplayContent
267266

268-
const headerName = toolRenderConfig.path
269-
? `${displayInfo.name}${toolRenderConfig.path}`
270-
: displayInfo.name
267+
const headerName = displayInfo.name
271268

272269
return (
273270
<box
@@ -284,8 +281,9 @@ export const MessageBlock = ({
284281
streamingPreview={streamingPreview}
285282
finishedPreview={finishedPreview}
286283
theme={theme}
287-
onToggle={() => onToggleCollapsed(toolBlock.toolCallId)}
288284
showBorder={false}
285+
toggleEnabled={false}
286+
titleSuffix={toolRenderConfig.path}
289287
/>
290288
</box>
291289
)

0 commit comments

Comments
 (0)