feat(frontend): add simple chat mode (#190)

* loop: simple-chat-mode completed after 1 iterations

* feat(frontend): add simple chat mode for user messages and clean up redundant optimistic filtering

* refactor(frontend): consolidate status indicators and simplify simple chat mode

- Merge MiniScanner and CompactStatusIndicator into SessionStatusIndicator with size and showLabel props
- Hide step-finish cost/token display in simpleChatMode
- Update SessionCard and PromptInput to use unified SessionStatusIndicator
- Add tests for step-finish rendering in simpleChatMode
This commit is contained in:
Chris Scott authored and GitHub committed 2026-04-23 11:37:24 -04:00
1 parent b61a3c83d1
commit adf77516e5
12 files changed
+493 -221

No files matched your search

@@ -66,10 +66,12 @@ export function FileToolRender({ part, filediff, filePath, content, toolName, on
const { preferences } = useSettings()
const isReadTool = toolName === 'Read'
const isEditTool = toolName === 'Edit'
const isWriteTool = toolName === 'Write'
const hasExpandableContent = !isReadTool && (filediff || content)
const defaultExpanded = isEditTool
? (preferences?.expandDiffs ?? true)
const isFileMutatingTool = isEditTool || isWriteTool
const defaultExpanded = isFileMutatingTool
? (preferences?.expandDiffs ?? true)
: (preferences?.expandToolCalls ?? false)
const [expanded, setExpanded] = useState(defaultExpanded)
@@ -5,12 +5,17 @@ import type { MessagePart as MessagePartType } from '@/api/types'
const mocks = vi.hoisted(() => ({
useTTS: vi.fn(),
useSettings: vi.fn(),
}))
vi.mock('@/hooks/useTTS', () => ({
useTTS: mocks.useTTS,
}))
vi.mock('@/hooks/useSettings', () => ({
useSettings: mocks.useSettings,
}))
interface MockTTSReturn {
speakMessage: ReturnType<typeof vi.fn>
stop: ReturnType<typeof vi.fn>
@@ -20,6 +25,21 @@ interface MockTTSReturn {
isEnabled: boolean
}
interface MockSettingsReturn {
preferences: {
simpleChatMode: boolean
showReasoning: boolean
expandToolCalls: boolean
expandDiffs: boolean
autoScroll: boolean
theme: 'dark' | 'light' | 'system'
mode: 'plan' | 'build'
} | undefined
isLoading: boolean
updateSettings: ReturnType<typeof vi.fn>
isUpdating: boolean
}
describe('MessagePart', () => {
const mockSpeakMessage = vi.fn()
const mockStop = vi.fn()
@@ -27,6 +47,20 @@ describe('MessagePart', () => {
beforeEach(() => {
mockSpeakMessage.mockClear()
mockStop.mockClear()
mocks.useSettings.mockReturnValue({
preferences: {
simpleChatMode: false,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark' as const,
mode: 'build' as const,
},
isLoading: false,
updateSettings: vi.fn(),
isUpdating: false,
})
})
const setup = (options: {
@@ -47,6 +81,15 @@ describe('MessagePart', () => {
mocks.useTTS.mockReturnValue(mockTTS)
}
const setupSettings = (preferences: MockSettingsReturn['preferences']) => {
mocks.useSettings.mockReturnValue({
preferences,
isLoading: false,
updateSettings: vi.fn(),
isUpdating: false,
})
}
const createStepFinishPart = (messageID: string): MessagePartType => ({
type: 'step-finish',
messageID,
@@ -223,4 +266,311 @@ describe('MessagePart', () => {
expect(screen.getByRole('button')).not.toHaveClass('bg-red-500/20')
})
describe('simpleChatMode', () => {
const createToolPart = (): MessagePartType => ({
type: 'tool',
tool: 'edit',
sessionID: 'test-session',
state: {
status: 'completed',
input: { filePath: '/test/file.txt' },
time: { start: Date.now(), end: Date.now() + 100 },
},
})
const createPatchPart = (): MessagePartType => ({
type: 'patch',
hash: 'abc123',
files: ['/test/file.txt'],
sessionID: 'test-session',
})
const createReasoningPart = (): MessagePartType => ({
type: 'reasoning',
text: 'This is the reasoning text',
sessionID: 'test-session',
})
const createSnapshotPart = (): MessagePartType => ({
type: 'snapshot',
snapshot: 'snapshot-data',
sessionID: 'test-session',
})
const createAgentPart = (): MessagePartType => ({
type: 'agent',
name: 'test-agent',
sessionID: 'test-session',
})
const createStepFinishPart = (): MessagePartType => ({
type: 'step-finish',
messageID: 'test-message',
sessionID: 'test-session',
cost: 0.01,
tokens: {
input: 100,
output: 50,
cache: { read: 0, write: 0 },
},
time: {
start: Date.now(),
end: Date.now() + 100,
},
})
const createTextPart = (): MessagePartType => ({
type: 'text',
text: 'Hello, this is a text message',
sessionID: 'test-session',
})
it('renders null for tool part when simpleChatMode is true', () => {
setupSettings({
simpleChatMode: true,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createToolPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).toBeNull()
})
it('renders null for patch part when simpleChatMode is true', () => {
setupSettings({
simpleChatMode: true,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createPatchPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).toBeNull()
})
it('renders null for reasoning part when simpleChatMode is true', () => {
setupSettings({
simpleChatMode: true,
showReasoning: true,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createReasoningPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).toBeNull()
})
it('renders null for snapshot part when simpleChatMode is true', () => {
setupSettings({
simpleChatMode: true,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createSnapshotPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).toBeNull()
})
it('renders null for agent part when simpleChatMode is true', () => {
setupSettings({
simpleChatMode: true,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createAgentPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).toBeNull()
})
it('renders text part when simpleChatMode is true', () => {
setupSettings({
simpleChatMode: true,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createTextPart()
render(<MessagePart part={part} />)
expect(screen.getByText('Hello, this is a text message')).toBeInTheDocument()
})
it('renders tool part when simpleChatMode is false', () => {
setupSettings({
simpleChatMode: false,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createToolPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).not.toBeNull()
})
it('renders patch part when simpleChatMode is false', () => {
setupSettings({
simpleChatMode: false,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createPatchPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).not.toBeNull()
})
it('renders snapshot part when simpleChatMode is false', () => {
setupSettings({
simpleChatMode: false,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createSnapshotPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).not.toBeNull()
})
it('renders agent part when simpleChatMode is false', () => {
setupSettings({
simpleChatMode: false,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createAgentPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).not.toBeNull()
})
it('renders null for step-finish part when simpleChatMode is true', () => {
setupSettings({
simpleChatMode: true,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createStepFinishPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).toBeNull()
})
it('renders step-finish part when simpleChatMode is false', () => {
setupSettings({
simpleChatMode: false,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createStepFinishPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).not.toBeNull()
})
})
describe('showReasoning', () => {
const createReasoningPart = (): MessagePartType => ({
type: 'reasoning',
text: 'This is the reasoning text',
sessionID: 'test-session',
})
it('renders null for reasoning part when showReasoning is false', () => {
setupSettings({
simpleChatMode: false,
showReasoning: false,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createReasoningPart()
const { container } = render(<MessagePart part={part} />)
expect(container.firstChild).toBeNull()
})
it('renders reasoning part when showReasoning is true', () => {
setupSettings({
simpleChatMode: false,
showReasoning: true,
expandToolCalls: false,
expandDiffs: true,
autoScroll: true,
theme: 'dark',
mode: 'build',
})
const part = createReasoningPart()
render(<MessagePart part={part} />)
expect(screen.getByText('This is the reasoning text')).toBeInTheDocument()
expect(screen.getByText('Reasoning')).toBeInTheDocument()
})
})
})
+23 -12
View File
@@ -7,6 +7,7 @@ import { ToolCallPart } from './ToolCallPart'
import { RetryPart } from './RetryPart'
import { useTTS } from '@/hooks/useTTS'
import { useMobile } from '@/hooks/useMobile'
import { useSettings } from '@/hooks/useSettings'
import { CopyButton } from '@/components/ui/copy-button'
type RetryPartType = components['schemas']['RetryPart']
@@ -100,6 +101,9 @@ function TTSButton({ messageId, content, className = "" }: TTSButtonProps) {
}
export const MessagePart = memo(function MessagePart({ part, role, allParts, partIndex, onFileClick, onChildSessionClick, messageTextContent }: MessagePartProps) {
const { preferences } = useSettings()
const simpleChatMode = preferences?.simpleChatMode ?? false
const showReasoning = preferences?.showReasoning ?? false
const copyableContent = getCopyableContent(part, allParts)
const isMobile = useMobile()
@@ -113,10 +117,13 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
}
return <TextPart part={part} />
case 'patch':
if (simpleChatMode) return null
return <PatchPart part={part} onFileClick={onFileClick} />
case 'tool':
if (simpleChatMode) return null
return <ToolCallPart part={part} onFileClick={onFileClick} onChildSessionClick={onChildSessionClick} />
case 'reasoning':
if (simpleChatMode || !showReasoning) return null
return (
<details className="border border-border rounded-lg my-2">
<summary className="px-4 py-2 bg-muted hover:bg-accent cursor-pointer text-sm font-medium">
@@ -128,29 +135,33 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
</details>
)
case 'snapshot':
if (simpleChatMode) return null
return (
<div className="border border-border rounded-lg p-4 my-2 bg-card">
<div className="text-xs text-muted-foreground font-mono">Snapshot: {part.snapshot}</div>
</div>
)
case 'agent':
if (simpleChatMode) return null
return (
<div className="border border-border rounded-lg p-4 my-2 bg-card">
<div className="text-sm font-medium text-blue-600 dark:text-blue-400">Agent: {part.name}</div>
</div>
)
case 'step-finish': {
const isFree = part.cost === 0
const totalTokens = part.tokens.input + part.tokens.output + (part.tokens.cache?.read || 0)
const costText = isMobile && isFree ? null : <span>${part.cost.toFixed(4)} • {totalTokens} tokens</span>
return (
<div className="text-xs text-muted-foreground my-1 flex items-center gap-2">
{costText}
<CopyButton content={copyableContent} title="Copy step complete" />
{messageTextContent && part.messageID && <TTSButton messageId={part.messageID} content={messageTextContent} />}
</div>
)
}
case 'step-finish':
if (simpleChatMode) return null
{
const isFree = part.cost === 0
const totalTokens = part.tokens.input + part.tokens.output + (part.tokens.cache?.read || 0)
const costText = isMobile && isFree ? null : <span>${part.cost.toFixed(4)} • {totalTokens} tokens</span>
return (
<div className="text-xs text-muted-foreground my-1 flex items-center gap-2">
{costText}
<CopyButton content={copyableContent} title="Copy step complete" />
{messageTextContent && part.messageID && <TTSButton messageId={part.messageID} content={messageTextContent} />}
</div>
)
}
case 'file':
return (
<span className="inline-flex items-center gap-1 px-2 py-1 rounded bg-muted border border-border text-sm text-foreground">
@@ -7,6 +7,7 @@ import { MessageError } from './MessageError'
import type { Message, Part, MessageWithParts } from '@/api/types'
import { useSessionStatusForSession } from '@/stores/sessionStatusStore'
import { useSessionTodos } from '@/stores/sessionTodosStore'
import { useSettings } from '@/hooks/useSettings'
import type { components } from '@/api/opencode-types'
import type { Todo } from '@/components/message/SessionTodoDisplay'
import type { OpenCodeError } from '@/lib/opencode-errors'
@@ -78,6 +79,7 @@ interface MessageRowProps {
handleStartEditUserMessage: (userMessageId: string, assistantMessageId: string) => void
handleCancelEdit: () => void
model?: string
simpleChatMode: boolean
}
const MessageRow = memo(function MessageRow({
@@ -98,6 +100,7 @@ const MessageRow = memo(function MessageRow({
handleStartEditUserMessage,
handleCancelEdit,
model,
simpleChatMode,
}: MessageRowProps) {
const msg = msgWithParts.info
const parts = msgWithParts.parts
@@ -185,6 +188,12 @@ const MessageRow = memo(function MessageRow({
onClick={() => handleStartEditUserMessage(msg.id, nextAssistantMsg.id)}
isEditable={false}
/>
) : msg.role === 'user' && simpleChatMode ? (
<ClickableUserMessage
content={messageTextContent}
onClick={() => {}}
isEditable={false}
/>
) : parts.length > 0 ? (
parts.map((part: Part, partIndex: number) => (
<div key={`${msg.id}-${part.id}-${partIndex}`}>
@@ -222,6 +231,8 @@ export const MessageThread = memo(function MessageThread({
const [editingUserMessageId, setEditingUserMessageId] = useState<string | null>(null)
const [editingForAssistantId, setEditingForAssistantId] = useState<string | null>(null)
const sessionStatus = useSessionStatusForSession(sessionID)
const { preferences } = useSettings()
const simpleChatMode = preferences?.simpleChatMode ?? false
const pendingAssistantId = useMemo(() => {
if (!messages) return undefined
@@ -316,6 +327,7 @@ export const MessageThread = memo(function MessageThread({
handleStartEditUserMessage={handleStartEditUserMessage}
handleCancelEdit={handleCancelEdit}
model={model}
simpleChatMode={simpleChatMode}
/>
))}
</div>
@@ -1065,7 +1065,7 @@ return (
/>
{hasActiveStream ? (
<div className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium text-muted-foreground max-w-[120px] md:max-w-[180px]">
<SessionStatusIndicator sessionID={sessionID} />
<SessionStatusIndicator sessionID={sessionID} showLabel />
</div>
) : (
!hideSecondaryButtons && (