Skip to content

Commit eb0ac62

Browse files
authored
Show basher summary prompt in TUI (#640)
1 parent 3c626e9 commit eb0ac62

5 files changed

Lines changed: 129 additions & 4 deletions

File tree

cli/src/components/blocks/agent-branch-wrapper.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ToolBlockGroup } from './tool-block-group'
1717
import { useTheme } from '../../hooks/use-theme'
1818
import { useChatStore } from '../../state/chat-store'
1919
import { isTextBlock } from '../../types/chat'
20+
import { getAgentDisplayPrompt } from '../../utils/agent-display'
2021
import { getAgentStatusInfo } from '../../utils/agent-helpers'
2122
import {
2223
processBlocks,
@@ -64,9 +65,10 @@ function getCollapsedPreview(
6465
}
6566
}
6667

67-
// Default preview: use initialPrompt or first line of text content
68-
if (agentBlock.initialPrompt) {
69-
return sanitizePreview(agentBlock.initialPrompt)
68+
// Default preview: use the displayed prompt or first line of text content.
69+
const displayPrompt = getAgentDisplayPrompt(agentBlock)
70+
if (displayPrompt) {
71+
return sanitizePreview(displayPrompt)
7072
}
7173

7274
const textContent =
@@ -413,6 +415,7 @@ export const AgentBranchWrapper = memo(
413415

414416
// Compute collapsed preview text
415417
const preview = getCollapsedPreview(agentBlock, isStreaming, isCollapsed)
418+
const displayPrompt = getAgentDisplayPrompt(agentBlock)
416419

417420
const effectiveStatus = isStreaming ? 'running' : agentBlock.status
418421
const {
@@ -429,7 +432,7 @@ export const AgentBranchWrapper = memo(
429432
<box key={keyPrefix} style={{ flexDirection: 'column', gap: 0 }}>
430433
<AgentBranchItem
431434
name={agentBlock.agentName}
432-
prompt={agentBlock.initialPrompt}
435+
prompt={displayPrompt}
433436
agentId={agentBlock.agentId}
434437
isCollapsed={isCollapsed}
435438
isStreaming={isStreaming}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { describe, expect, test } from 'bun:test'
2+
3+
import { getAgentDisplayPrompt } from '../agent-display'
4+
5+
import type { AgentContentBlock } from '../../types/chat'
6+
7+
const createAgentBlock = (
8+
overrides: Partial<AgentContentBlock>,
9+
): AgentContentBlock => ({
10+
type: 'agent',
11+
agentId: 'agent-1',
12+
agentName: 'Basher',
13+
agentType: 'basher',
14+
content: '',
15+
status: 'running',
16+
blocks: [],
17+
initialPrompt: '',
18+
...overrides,
19+
})
20+
21+
describe('getAgentDisplayPrompt', () => {
22+
test('uses initial prompt when present', () => {
23+
const block = createAgentBlock({
24+
initialPrompt: 'Run tests',
25+
params: {
26+
what_to_summarize: 'Summarize failures',
27+
},
28+
})
29+
30+
expect(getAgentDisplayPrompt(block)).toBe('Run tests')
31+
})
32+
33+
test('uses basher what_to_summarize when prompt is omitted', () => {
34+
const block = createAgentBlock({
35+
params: {
36+
command: 'bun test',
37+
what_to_summarize: 'Summarize failing tests only',
38+
},
39+
})
40+
41+
expect(getAgentDisplayPrompt(block)).toBe('Summarize failing tests only')
42+
})
43+
44+
test('normalizes scoped and versioned basher agent ids', () => {
45+
const block = createAgentBlock({
46+
agentType: 'codebuff/basher@1.0.0',
47+
params: {
48+
what_to_summarize: 'Summarize command output',
49+
},
50+
})
51+
52+
expect(getAgentDisplayPrompt(block)).toBe('Summarize command output')
53+
})
54+
55+
test('ignores non-basher what_to_summarize params', () => {
56+
const block = createAgentBlock({
57+
agentName: 'code-searcher',
58+
agentType: 'code-searcher',
59+
params: {
60+
what_to_summarize: 'This is not a basher prompt',
61+
},
62+
})
63+
64+
expect(getAgentDisplayPrompt(block)).toBeUndefined()
65+
})
66+
})

cli/src/utils/__tests__/sdk-event-handlers.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,40 @@ describe('sdk-event-handlers', () => {
295295
expect(getStreamingAgents().size).toBe(0)
296296
})
297297

298+
test('preserves spawn_agents params on placeholder agent blocks', () => {
299+
const { ctx, getMessages, getStreamingAgents } = createTestContext()
300+
const handleEvent = createEventHandler(ctx)
301+
302+
handleEvent({
303+
type: 'tool_call',
304+
toolCallId: 'tool-1',
305+
toolName: 'spawn_agents',
306+
input: {
307+
agents: [
308+
{
309+
agent_type: 'basher',
310+
params: {
311+
command: 'git status --short',
312+
what_to_summarize: 'Report whether the worktree is clean',
313+
},
314+
},
315+
],
316+
},
317+
agentId: 'main-agent',
318+
parentAgentId: undefined,
319+
} as any)
320+
321+
const agentBlock = (getMessages()[0].blocks ?? [])[0] as AgentContentBlock
322+
expect(agentBlock.agentId).toBe('tool-1-0')
323+
expect(agentBlock.agentType).toBe('basher')
324+
expect(agentBlock.initialPrompt).toBe('')
325+
expect(agentBlock.params).toEqual({
326+
command: 'git status --short',
327+
what_to_summarize: 'Report whether the worktree is clean',
328+
})
329+
expect(getStreamingAgents().has('tool-1-0')).toBe(true)
330+
})
331+
298332
test('handles spawn_agents tool results and clears streaming agents', () => {
299333
const { ctx, getMessages, getStreamingAgents } = createTestContext()
300334
ctx.message.updater.addBlock(

cli/src/utils/agent-display.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { getAgentBaseName } from './message-block-helpers'
2+
3+
import type { AgentContentBlock } from '../types/chat'
4+
5+
export function getAgentDisplayPrompt(
6+
agentBlock: AgentContentBlock,
7+
): string | undefined {
8+
const initialPrompt = agentBlock.initialPrompt?.trim()
9+
if (initialPrompt) {
10+
return initialPrompt
11+
}
12+
13+
if (getAgentBaseName(agentBlock.agentType) !== 'basher') {
14+
return undefined
15+
}
16+
17+
const whatToSummarize = agentBlock.params?.what_to_summarize
18+
return typeof whatToSummarize === 'string' && whatToSummarize.trim()
19+
? whatToSummarize.trim()
20+
: undefined
21+
}

cli/src/utils/sdk-event-handlers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ const handleSpawnAgentsToolCall = (
285285
agentId: `${event.toolCallId}-${originalIndex}`,
286286
agentType: agent.agent_type || '',
287287
prompt: agent.prompt,
288+
params: agent.params,
288289
spawnToolCallId: event.toolCallId,
289290
spawnIndex: originalIndex,
290291
parentAgentType,

0 commit comments

Comments
 (0)