fix(frontend): keep transcript display settings working with the plain log layout

This commit is contained in:
Chris Scott committed 2026-10-21 22:26:33 -04:00
1 parent 8004496f10
commit d8495df811
8 files changed
+198 -16

No files matched your search

@@ -69,7 +69,7 @@ function FileToolRender({ part, filediff, filePath, content, toolName, onFileCli
const hasExpandableContent = !isReadTool && (filediff || content)
const isFileLink = Boolean(onFileClick) && !isRemoteServer
const defaultExpanded = hasDiff
const defaultExpanded = hasDiff || toolName === 'Write'
? (preferences?.expandDiffs ?? true)
: (preferences?.expandToolCalls ?? false)
const [detailsOpen, setDetailsOpen] = useToolDetailsState(defaultExpanded)
@@ -648,6 +648,51 @@ describe('MessagePart', () => {
expect(screen.getByText('/test/file.txt')).toBeInTheDocument()
})
it('expands a write tool preview when expand diffs is enabled', () => {
setupSettings({
simpleChatMode: false,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
})
renderWithProviders(
<MessagePart
part={toolPart('write', {
status: 'completed',
input: { path: '/test/file.txt', content: 'written preview line' },
content: [{ type: 'text', text: 'Wrote file successfully' }],
metadata: {},
})}
/>,
)
expect(screen.getByText('written preview line')).toBeInTheDocument()
})
it('collapses a write tool preview when only expand tool calls is enabled', () => {
setupSettings({
simpleChatMode: false,
showReasoning: false,
expandToolCalls: true,
expandDiffs: false,
})
renderWithProviders(
<MessagePart
part={toolPart('write', {
status: 'completed',
input: { path: '/test/file.txt', content: 'written preview line' },
content: [{ type: 'text', text: 'Wrote file successfully' }],
metadata: {},
})}
/>,
)
expect(screen.getByText('/test/file.txt')).toBeInTheDocument()
expect(screen.queryByText('written preview line')).toBeNull()
})
it('makes legacy filePath read, write, and filediff edit calls clickable', () => {
const onFileClick = vi.fn()
const legacy = (name: string, metadata: Record<string, unknown>) =>
@@ -684,6 +684,26 @@ describe('MessageThread', () => {
expect(screen.queryByText(/File Changes/)).not.toBeInTheDocument()
})
it('omits the agent name from the assistant footer in simple chat mode', () => {
const messages = [assistantMessage('2', [textPart('Updated files')], { agent: 'build' })]
setupSettings({ simpleChatMode: true, showReasoning: false })
const simple = render(
<MessageThread sessionID="test-session" messages={messages} pending={[]} />,
)
expect(screen.queryByText('Build')).not.toBeInTheDocument()
expect(screen.getByText('test-model')).toBeInTheDocument()
simple.unmount()
setupSettings({ simpleChatMode: false, showReasoning: false })
render(<MessageThread sessionID="test-session" messages={messages} pending={[]} />)
expect(screen.getByText('Build')).toBeInTheDocument()
expect(screen.getByText('test-model')).toBeInTheDocument()
})
it('shows the empty state when there are no messages or pending prompts', () => {
setupSettings({ simpleChatMode: false, showReasoning: false })
@@ -558,10 +558,14 @@ const MessageRow = memo(function MessageRow({
</div>
<div className="mt-3 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground">
<span style={getAgentStyleVars(message.agent)} className="font-medium text-[var(--agent-color)]">
{message.agent.charAt(0).toUpperCase() + message.agent.slice(1)}
</span>
<span aria-hidden="true">·</span>
{!simpleChatMode && (
<>
<span style={getAgentStyleVars(message.agent)} className="font-medium text-[var(--agent-color)]">
{message.agent.charAt(0).toUpperCase() + message.agent.slice(1)}
</span>
<span aria-hidden="true">·</span>
</>
)}
<span className="text-foreground">{message.model.id}</span>
{message.time.completed !== undefined ? (
<>
@@ -1,4 +1,4 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { MemoryRouter } from 'react-router-dom'
@@ -701,6 +701,66 @@ describe('ToolCallPart shell preview', () => {
})
})
describe('ToolCallPart shell details scrolling', () => {
const originalScrollIntoView = Element.prototype.scrollIntoView
const scrollIntoView = vi.fn()
beforeEach(() => {
vi.clearAllMocks()
mocks.useSettings.mockReturnValue({
preferences: { expandToolCalls: false },
isLoading: false,
updateSettings: vi.fn(),
isUpdating: false,
})
mocks.useToolCallPermission.mockReturnValue(null)
Element.prototype.scrollIntoView = scrollIntoView
})
afterEach(() => {
Element.prototype.scrollIntoView = originalScrollIntoView
})
const completedShell = (): SessionMessageAssistantTool => ({
type: 'tool',
id: 'call_scroll',
name: 'shell',
time: { created: 1, ran: 2, completed: 3 },
state: {
status: 'completed',
input: { command: 'seq 25' },
content: [{ type: 'text', text: 'line 24\nline 25' }],
metadata: {},
},
})
it('does not scroll when the shell details open from the preference', () => {
mocks.useSettings.mockReturnValue({
preferences: { expandToolCalls: true },
isLoading: false,
updateSettings: vi.fn(),
isUpdating: false,
})
renderWithProviders(<ToolCallPart part={completedShell()} messageID="msg_1" />)
expect(screen.getByText('Command:')).toBeInTheDocument()
expect(scrollIntoView).not.toHaveBeenCalled()
})
it('scrolls once when the user opens the shell details', () => {
renderWithProviders(<ToolCallPart part={completedShell()} messageID="msg_1" />)
expect(screen.queryByText('Command:')).not.toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'Show shell details' }))
expect(screen.getByText('Command:')).toBeInTheDocument()
expect(scrollIntoView).toHaveBeenCalledTimes(1)
expect(scrollIntoView).toHaveBeenCalledWith({ behavior: 'smooth', block: 'nearest' })
})
})
describe('ToolCallPart show artifact action', () => {
beforeEach(() => {
vi.clearAllMocks()
@@ -102,6 +102,7 @@ export const ToolCallPart = memo(function ToolCallPart({ part, messageID, direct
const pendingPermission = useToolCallPermission(part.id, messageID)
const isWaitingPermission = part.state.status === 'running' && pendingPermission !== null
const outputRef = useRef<HTMLDivElement>(null)
const userOpenedDetailsRef = useRef(false)
const input = toolInput(part)
const openWalkthrough = readOpenWalkthroughCall(part)
const rawCommand = part.name === 'shell' && typeof input?.command === 'string'
@@ -123,10 +124,10 @@ export const ToolCallPart = memo(function ToolCallPart({ part, messageID, direct
const [detailsOpen, setDetailsOpen] = useToolDetailsState(preferences?.expandToolCalls ?? false)
useEffect(() => {
if (part.name !== 'shell' || !detailsOpen || !userOpenedDetailsRef.current) return
userOpenedDetailsRef.current = false
if (isMobile) return
if (part.name === 'shell' && detailsOpen && outputRef.current) {
outputRef.current.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
}
outputRef.current?.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
}, [detailsOpen, isMobile, part.name])
const getStatusColor = () => {
@@ -380,7 +381,11 @@ export const ToolCallPart = memo(function ToolCallPart({ part, messageID, direct
<ShellPreview
command={displayCommand ?? ''}
output={output}
onClick={() => setDetailsOpen(!detailsOpen)}
onClick={() => {
const nextOpen = !detailsOpen
if (nextOpen) userOpenedDetailsRef.current = true
setDetailsOpen(nextOpen)
}}
status={
<span className="flex shrink-0 items-center gap-1.5 text-xs text-muted-foreground">
<span className={getStatusColor()}>{getStatusIcon()}</span>
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen } from '@testing-library/react'
import { fireEvent, render, screen } from '@testing-library/react'
import { ShellPreview, ToolDetails, useToolDetailsState } from './ToolDetails'
const mocks = vi.hoisted(() => ({
@@ -18,8 +18,15 @@ const Details = ({ open, onOpenChange }: { open: boolean; onOpenChange: (open: b
)
function StateProbe({ defaultOpen }: { defaultOpen: boolean }) {
const [open] = useToolDetailsState(defaultOpen)
return <span>{open ? 'open' : 'closed'}</span>
const [open, setOpen] = useToolDetailsState(defaultOpen)
return (
<>
<span>{open ? 'open' : 'closed'}</span>
<button type="button" onClick={() => setOpen(false)}>
close details
</button>
</>
)
}
describe('ToolDetails', () => {
@@ -92,6 +99,47 @@ describe('useToolDetailsState', () => {
expect(screen.getByText('closed')).toBeInTheDocument()
})
it('follows a default that turns open after mount on desktop', () => {
mocks.useMobile.mockReturnValue(false)
const { rerender } = render(<StateProbe defaultOpen={false} />)
expect(screen.getByText('closed')).toBeInTheDocument()
rerender(<StateProbe defaultOpen />)
expect(screen.getByText('open')).toBeInTheDocument()
})
it('keeps the user choice when a later default differs', () => {
mocks.useMobile.mockReturnValue(false)
const { rerender } = render(<StateProbe defaultOpen />)
expect(screen.getByText('open')).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'close details' }))
expect(screen.getByText('closed')).toBeInTheDocument()
rerender(<StateProbe defaultOpen />)
expect(screen.getByText('closed')).toBeInTheDocument()
})
it('closes when the viewport shrinks to mobile after opening on desktop', () => {
mocks.useMobile.mockReturnValue(false)
const { rerender } = render(<StateProbe defaultOpen />)
expect(screen.getByText('open')).toBeInTheDocument()
mocks.useMobile.mockReturnValue(true)
rerender(<StateProbe defaultOpen />)
expect(screen.getByText('closed')).toBeInTheDocument()
})
})
describe('ShellPreview', () => {
@@ -8,11 +8,11 @@ import { TRANSCRIPT_DETAIL_CLASS } from './transcriptStyles'
const SHELL_PREVIEW_LINES = 10
const MOBILE_SHELL_PREVIEW_LINES = 4
/** Tool-detail disclosure state that stays closed on mobile unless the user opens it. */
/** Tool-detail disclosure state that follows the preference until the user toggles it and never auto-opens on mobile. */
export function useToolDetailsState(defaultOpen: boolean): [boolean, (open: boolean) => void] {
const isMobile = useMobile()
const [open, setOpen] = useState(() => defaultOpen && !isMobile)
return [open, setOpen]
const [userOpen, setUserOpen] = useState<boolean | null>(null)
return [userOpen ?? (defaultOpen && !isMobile), setUserOpen]
}
/** Renders tool detail content inline on desktop and in a fullscreen dialog on mobile. */