fix(tui): bound diff rendering work

This commit is contained in:
kingwl
2026-07-31 12:58:30 +08:00
parent 51beb34f97
commit 81ff2894ca
14 changed files with 246 additions and 45 deletions
+24 -3
View File
@@ -269,13 +269,32 @@ const ADVANCED_CARD_TOOLS: Record<string, ToolDefinition> = {
edit: visualTool(
'edit',
() => ({ card: 'diff', title: 'Edit src/view.ts', diffs: [{ path: 'src/view.ts', oldText: 'old line', newText: 'new line' }] }),
// The real edit/write tools produce exactly one diff whose path the title
// already names, so the card omits the redundant per-file header.
// The fixed tool header never names a path, so the hunk retains its path.
(): ToolResultView => ({
card: 'diff',
diffs: [{ path: 'src/view.ts', oldText: 'old line\nkeep', newText: 'new line\nkeep' }],
}),
),
large_edit: visualTool(
'large_edit',
() => ({
card: 'diff',
title: 'Edit src/large.ts',
diffs: [{
path: 'src/large.ts',
oldText: 'old one\nold two\nold three',
newText: 'new one\nnew two\nnew three',
}],
}),
(): ToolResultView => ({
card: 'diff',
diffs: [{
path: 'src/large.ts',
oldText: 'old one\nold two\nold three',
newText: 'new one\nnew two\nnew three',
}],
}),
),
subagent: visualTool('subagent', args => ({
card: 'generic',
title: 'Delegate renderer audit',
@@ -585,7 +604,7 @@ describe('TUI terminal-state snapshots', () => {
it('pins terminal, diff, subagent, task, skill, collapsed, and expanded cards', async () => {
const harness = await setupSnapshot({
tools: ADVANCED_CARD_TOOLS,
config: { maxToolOutputLines: 3 },
config: { maxToolOutputLines: 3, maxDiffEditLength: 2 },
}, { columns: 100, rows: 40 })
const calls = [
{ id: 'advanced-1', name: 'bash', arguments: { command: 'pnpm run test:coverage' } },
@@ -593,6 +612,7 @@ describe('TUI terminal-state snapshots', () => {
{ id: 'advanced-3', name: 'subagent', arguments: { prompt: 'Review renderer ownership and report only gaps.' } },
{ id: 'advanced-4', name: 'task_output', arguments: { task_id: 'subagent-7', wait: true } },
{ id: 'advanced-5', name: 'skill', arguments: { name: 'dsh-code-review' } },
{ id: 'advanced-6', name: 'large_edit', arguments: { file_path: 'src/large.ts' } },
]
await renderAfter(harness, () => {
appendToolCalls(harness.session, calls)
@@ -601,6 +621,7 @@ describe('TUI terminal-state snapshots', () => {
appendToolResult(harness.session, 'advanced-3', [{ type: 'text', text: 'The renderer has explicit lifecycle ownership.' }])
appendToolResult(harness.session, 'advanced-4', [{ type: 'text', text: 'audit complete\n[status: completed]' }])
appendToolResult(harness.session, 'advanced-5', [{ type: 'text', text: 'Loaded review instructions.' }])
appendToolResult(harness.session, 'advanced-6', [{ type: 'text', text: 'large edit complete' }])
})
await checkpoint('advanced-cards-collapsed', harness.terminal, { includeScrollback: true })