diff --git a/frontend/src/components/file-browser/FileOperations.tsx b/frontend/src/components/file-browser/FileOperations.tsx
index 1b5028dc..109af2f9 100644
--- a/frontend/src/components/file-browser/FileOperations.tsx
+++ b/frontend/src/components/file-browser/FileOperations.tsx
@@ -44,7 +44,7 @@ export const FileOperations = memo(function FileOperations({ onUpload, onCreate
@@ -103,4 +103,4 @@ export const FileOperations = memo(function FileOperations({ onUpload, onCreate
)
-})
\ No newline at end of file
+})
diff --git a/frontend/src/components/message/MessagePart.tsx b/frontend/src/components/message/MessagePart.tsx
index a08cf424..b7d6873e 100644
--- a/frontend/src/components/message/MessagePart.tsx
+++ b/frontend/src/components/message/MessagePart.tsx
@@ -1,3 +1,4 @@
+import { memo } from 'react'
import type { components } from '@/api/opencode-types'
import { Copy } from 'lucide-react'
import { TextPart } from './TextPart'
@@ -33,8 +34,6 @@ function getCopyableContent(part: Part, allParts?: Part[]): string {
return part.snapshot || ''
case 'agent':
return `Agent: ${part.name}`
- case 'step-start':
- return 'Starting step...'
case 'step-finish':
if (allParts) {
return allParts
@@ -77,7 +76,7 @@ function CopyButton({ content, title, className = "" }: { content: string; title
-export function MessagePart({ part, role, allParts, partIndex, onFileClick }: MessagePartProps) {
+export const MessagePart = memo(function MessagePart({ part, role, allParts, partIndex, onFileClick }: MessagePartProps) {
const copyableContent = getCopyableContent(part, allParts)
switch (part.type) {
@@ -116,16 +115,10 @@ export function MessagePart({ part, role, allParts, partIndex, onFileClick }: Me
Agent: {part.name}
)
- case 'step-start':
- return (
-
- → Starting step...
-
- )
case 'step-finish':
return (
- ✓ Step complete • ${part.cost.toFixed(4)} • {part.tokens.input + part.tokens.output} tokens
+ ${part.cost.toFixed(4)} • {part.tokens.input + part.tokens.output} tokens
)
@@ -137,10 +130,6 @@ export function MessagePart({ part, role, allParts, partIndex, onFileClick }: Me
)
default:
- return (
-
- )
+ return
}
-}
+})
diff --git a/frontend/src/components/message/MessageThread.tsx b/frontend/src/components/message/MessageThread.tsx
index fea22ce1..392b890a 100644
--- a/frontend/src/components/message/MessageThread.tsx
+++ b/frontend/src/components/message/MessageThread.tsx
@@ -1,4 +1,4 @@
-import { memo, useRef, useEffect } from 'react'
+import { memo, useRef, useEffect, useCallback } from 'react'
import { useMessages } from '@/hooks/useOpenCode'
import { useSettings } from '@/hooks/useSettings'
import { MessagePart } from './MessagePart'
@@ -10,6 +10,7 @@ interface MessageThreadProps {
directory?: string
onFileClick?: (filePath: string, lineNumber?: number) => void
containerRef?: React.RefObject
+ onScrollStateChange?: (isScrolledUp: boolean) => void
}
const isMessageStreaming = (msg: MessageWithParts): boolean => {
@@ -22,23 +23,68 @@ const isMessageThinking = (msg: MessageWithParts): boolean => {
return msg.parts.length === 0 && isMessageStreaming(msg)
}
-export const MessageThread = memo(function MessageThread({ opcodeUrl, sessionID, directory, onFileClick, containerRef }: MessageThreadProps) {
+const SCROLL_THRESHOLD = 150
+const SCROLL_DEBOUNCE_MS = 50
+
+export const MessageThread = memo(function MessageThread({ opcodeUrl, sessionID, directory, onFileClick, containerRef, onScrollStateChange }: MessageThreadProps) {
const { data: messages, isLoading, error } = useMessages(opcodeUrl, sessionID, directory)
const { preferences } = useSettings()
const lastMessageCountRef = useRef(0)
- const userJustSentMessageRef = useRef(false)
+ const userScrolledUpRef = useRef(false)
const hasInitialScrolledRef = useRef(false)
+ const scrollRAFRef = useRef(null)
+ const lastScrollTimeRef = useRef(0)
+
+ const scrollToBottom = useCallback((force = false) => {
+ if (!containerRef?.current) return
+
+ const now = Date.now()
+ if (!force && now - lastScrollTimeRef.current < SCROLL_DEBOUNCE_MS) {
+ return
+ }
+ lastScrollTimeRef.current = now
+
+ if (scrollRAFRef.current) {
+ cancelAnimationFrame(scrollRAFRef.current)
+ }
+
+ scrollRAFRef.current = requestAnimationFrame(() => {
+ if (containerRef?.current) {
+ containerRef.current.scrollTop = containerRef.current.scrollHeight
+ userScrolledUpRef.current = false
+ onScrollStateChange?.(false)
+ }
+ scrollRAFRef.current = null
+ })
+ }, [containerRef, onScrollStateChange])
+
+ useEffect(() => {
+ if (!containerRef?.current) return
+
+ const container = containerRef.current
+
+ const handleScroll = () => {
+ const distanceFromBottom = container.scrollHeight - container.scrollTop - container.clientHeight
+ const isScrolledUp = distanceFromBottom > SCROLL_THRESHOLD
+ if (userScrolledUpRef.current !== isScrolledUp) {
+ userScrolledUpRef.current = isScrolledUp
+ onScrollStateChange?.(isScrolledUp)
+ }
+ }
+
+ container.addEventListener('scroll', handleScroll, { passive: true })
+ return () => container.removeEventListener('scroll', handleScroll)
+ }, [containerRef, onScrollStateChange])
useEffect(() => {
if (!containerRef?.current || !messages) return
- const container = containerRef.current
const currentMessageCount = messages.length
const previousMessageCount = lastMessageCountRef.current
if (!hasInitialScrolledRef.current && currentMessageCount > 0) {
hasInitialScrolledRef.current = true
- container.scrollTop = container.scrollHeight
+ scrollToBottom(true)
lastMessageCountRef.current = currentMessageCount
return
}
@@ -50,28 +96,25 @@ export const MessageThread = memo(function MessageThread({ opcodeUrl, sessionID,
const isUserMessage = lastMessage?.info.role === 'user'
if (messageAdded && isUserMessage) {
- userJustSentMessageRef.current = true
- container.scrollTop = container.scrollHeight
+ userScrolledUpRef.current = false
+ scrollToBottom(true)
return
}
if (!preferences?.autoScroll) return
- const isNearBottom =
- container.scrollHeight - container.scrollTop - container.clientHeight < 100
-
- if (userJustSentMessageRef.current || isNearBottom) {
- container.scrollTop = container.scrollHeight
+ if (!userScrolledUpRef.current) {
+ scrollToBottom()
}
+ }, [messages, preferences?.autoScroll, containerRef, scrollToBottom])
- if (
- lastMessage?.info.role === 'assistant' &&
- 'completed' in lastMessage.info.time &&
- lastMessage.info.time.completed
- ) {
- userJustSentMessageRef.current = false
+ useEffect(() => {
+ return () => {
+ if (scrollRAFRef.current) {
+ cancelAnimationFrame(scrollRAFRef.current)
+ }
}
- }, [messages, preferences?.autoScroll, containerRef])
+ }, [])
if (isLoading) {
return (
@@ -98,7 +141,7 @@ export const MessageThread = memo(function MessageThread({ opcodeUrl, sessionID,
}
return (
-
+
{messages.map((msg) => {
const streaming = isMessageStreaming(msg)
const thinking = isMessageThinking(msg)
@@ -109,7 +152,7 @@ export const MessageThread = memo(function MessageThread({ opcodeUrl, sessionID,
className="flex flex-col"
>
void
onShowSessionsDialog?: () => void
onShowModelsDialog?: () => void
onShowHelpDialog?: () => void
@@ -35,7 +39,9 @@ export function PromptInput({
opcodeUrl,
directory,
sessionID,
- disabled,
+ disabled,
+ showScrollButton,
+ onScrollToBottom,
onShowSessionsDialog,
onShowModelsDialog,
onShowHelpDialog
@@ -79,12 +85,14 @@ export function PromptInput({
)
const isStandalone = useStandalone()
+ const { addUserBashCommand } = useUserBash()
const handleSubmit = () => {
if (!prompt.trim() || disabled) return
if (isBashMode) {
const command = prompt.startsWith('!') ? prompt.slice(1) : prompt
+ addUserBashCommand(command)
sendShell.mutate({
sessionID,
command,
@@ -418,7 +426,7 @@ export function PromptInput({
return (
-
+
-
-
+
+
+
- {isBashMode && (
-
- BASH MODE
-
- )}
- {modelName && (
-
- )}
-
+
+ {showScrollButton && (
+
+ )}
+
+
{
+ try {
+ await navigator.clipboard.writeText(content)
+ } catch (error) {
+ console.error('Failed to copy content:', error)
+ }
+ }
+
+ if (!content.trim()) {
+ return null
+ }
+
+ return (
+
+ )
+}
type ToolPart = components['schemas']['ToolPart']
@@ -52,9 +78,21 @@ function ClickableJson({ json, onFileClick }: { json: unknown; onFileClick?: (fi
export function ToolCallPart({ part, onFileClick }: ToolCallPartProps) {
const { preferences } = useSettings()
- const defaultExpanded = preferences?.expandToolCalls ?? false
+ const { userBashCommands } = useUserBash()
+ const outputRef = useRef(null)
+ const isUserBashCommand = part.tool === 'bash' &&
+ part.state.status === 'completed' &&
+ typeof part.state.input?.command === 'string' &&
+ userBashCommands.has(part.state.input.command)
+ const defaultExpanded = isUserBashCommand || (preferences?.expandToolCalls ?? false)
const [expanded, setExpanded] = useState(defaultExpanded)
+ useEffect(() => {
+ if (part.tool === 'bash' && expanded && outputRef.current) {
+ outputRef.current.scrollIntoView({ behavior: 'smooth', block: 'start' })
+ }
+ }, [expanded, part.tool])
+
const getStatusColor = () => {
switch (part.state.status) {
case 'completed':
@@ -110,6 +148,30 @@ export function ToolCallPart({ part, onFileClick }: ToolCallPartProps) {
const previewText = getPreviewText()
const isFileTool = ['read', 'write', 'edit'].includes(part.tool)
+ if (isUserBashCommand) {
+ const command = part.state.input.command as string
+ const output = part.state.status === 'completed' ? part.state.output : ''
+ return (
+
+
+ ✓
+ $
+ {command}
+ {part.state.status === 'completed' && part.state.time && (
+
+ {((part.state.time.end - part.state.time.start) / 1000).toFixed(2)}s
+
+ )}
+
+
navigator.clipboard.writeText(output)}
+ title="Click to copy output">
+ {output}
+
+
+ )
+ }
+
return (