diff --git a/apps/web/app/demo/messages/page.tsx b/apps/web/app/demo/messages/page.tsx new file mode 100644 index 0000000000..299cf7daef --- /dev/null +++ b/apps/web/app/demo/messages/page.tsx @@ -0,0 +1,576 @@ +'use client'; + +import type { Message } from '@/lib/types/http'; +import { MessageRenderer } from '@/components/task/chat/message-renderer'; + +const dummyMessages: Message[] = [ + // Task description + { + id: 'task-description', + session_id: 'demo', + task_id: 'demo-task', + content: '[TASK DESCRIPTION - AMBER BANNER] Implement a new feature to handle user authentication with OAuth 2.0', + author_type: 'user', + type: 'message', + created_at: '2024-01-20T10:00:00Z', + }, + + // User message - short + { + id: 'user-1', + session_id: 'demo', + task_id: 'demo-task', + content: '[USER MESSAGE - SHORT] Can you help me with this?', + author_type: 'user', + type: 'message', + created_at: '2024-01-20T10:01:00Z', + }, + + // User message - long + { + id: 'user-2', + session_id: 'demo', + task_id: 'demo-task', + content: '[USER MESSAGE - LONG] I need to implement a complex feature that involves multiple components. The requirements are:\n1. User authentication\n2. Role-based access control\n3. Session management\n4. Token refresh mechanism\n\nCan you help me design this system?', + author_type: 'user', + type: 'message', + created_at: '2024-01-20T10:02:00Z', + }, + + // Agent message - plain text + { + id: 'agent-1', + session_id: 'demo', + task_id: 'demo-task', + content: '[AGENT MESSAGE - PLAIN TEXT] This is a simple paragraph with no markdown formatting. Just plain text content.', + author_type: 'agent', + type: 'message', + created_at: '2024-01-20T10:03:00Z', + }, + + // Agent message - with markdown + { + id: 'agent-2', + session_id: 'demo', + task_id: 'demo-task', + content: `**[MARKDOWN DEMO]** Here's a message showing all markdown elements: + +## Heading 2 (h2 element) + +This is a **paragraph (p element)** with some **bold text (strong element)** to test styling. + +### Heading 3 (h3 element) + +**Ordered List (ol element):** + +1. First item (li element in ol) +2. Second item with **bold text** +3. Third item with inline code: \`const example = true\` +4. Fourth item (li element) + +**Unordered List (ul element):** + +- Bullet point one (li element in ul) +- Bullet point two +- Bullet point with \`inline code\` (code element) +- Another bullet point + +**Inline code examples (code element, inline):** +- Variable: \`const token = jwt.sign(payload)\` +- Function call: \`getUserData(userId)\` +- Path: \`/src/auth/config.ts\` + +**Code block example (code element, block):** + +\`\`\`typescript +// This is a code block (pre > code) +interface AuthConfig { + clientId: string; + clientSecret: string; + redirectUri: string; +} + +function authenticate(config: AuthConfig) { + return jwt.sign(config); +} +\`\`\` + +**Another code block (JavaScript):** + +\`\`\`javascript +// Testing syntax highlighting +const data = { name: "test", value: 123 }; +console.log(data); +\`\`\``, + author_type: 'agent', + type: 'message', + created_at: '2024-01-20T10:04:00Z', + }, + + // Thinking message + { + id: 'thinking-1', + session_id: 'demo', + task_id: 'demo-task', + type: 'thinking', + content: '', + author_type: 'agent', + created_at: '2024-01-20T10:05:00Z', + metadata: { + thinking: '[THINKING MESSAGE] This shows the agent\'s internal reasoning process. I need to check the current authentication implementation before suggesting changes. Let me search for existing auth files and understand the current architecture.', + }, + }, + + // Tool call - Read (complete) + { + id: 'tool-1', + session_id: 'demo', + task_id: 'demo-task', + type: 'tool_call', + content: 'Read file', + author_type: 'agent', + created_at: '2024-01-20T10:06:00Z', + metadata: { + tool_call_id: 'tool-1', + tool_name: 'Read', + title: '[TOOL - READ - COMPLETE ✓] Read src/auth/config.ts', + status: 'complete', + args: { + file_path: '/Users/demo/project/src/auth/config.ts', + line_count: 50, + }, + result: 'File content loaded successfully (50 lines)', + }, + }, + + // Tool call - Bash (running) + { + id: 'tool-2', + session_id: 'demo', + task_id: 'demo-task', + type: 'tool_call', + content: 'Run command', + author_type: 'agent', + created_at: '2024-01-20T10:07:00Z', + metadata: { + tool_call_id: 'tool-2', + tool_name: 'Bash', + title: '[TOOL - BASH - RUNNING ⏳] npm test', + status: 'running', + args: { + command: 'npm test -- --coverage', + description: 'Run tests with coverage', + timeout: 30000, + }, + }, + }, + + // Tool call - Edit (error) + { + id: 'tool-3', + session_id: 'demo', + task_id: 'demo-task', + type: 'tool_call', + content: 'Edit file', + author_type: 'agent', + created_at: '2024-01-20T10:08:00Z', + metadata: { + tool_call_id: 'tool-3', + tool_name: 'Edit', + title: '[TOOL - EDIT - ERROR ✗] Edit src/components/Login.tsx', + status: 'error', + args: { + file_path: '/Users/demo/project/src/components/Login.tsx', + old_string: 'const handleLogin = () => {', + new_string: 'const handleLogin = async () => {', + }, + result: 'Error: old_string not found in file. Make sure the old_string exactly matches the content in the file.', + }, + }, + + // Tool call - Edit with complex metadata (complete) + { + id: 'tool-3b', + session_id: 'demo', + task_id: 'demo-task', + type: 'tool_call', + content: 'Auggie Read `drizzle.config.ts`', + author_type: 'agent', + created_at: '2024-01-20T10:08:30Z', + metadata: { + tool_call_id: 'toolu_vrtx_01W75yrLi1WLgLCz8P3D8jjh', + tool_name: 'edit', + title: 'Edit drizzle.config.ts', + status: 'complete', + args: { + kind: 'edit', + locations: [ + { + path: '/Users/cfl/.kandev/worktrees/1_c28de20d/drizzle.config.ts', + }, + ], + path: '/Users/cfl/.kandev/worktrees/1_c28de20d/drizzle.config.ts', + raw_input: { + command: 'str_replace', + instruction_reminder: 'ALWAYS BREAK DOWN EDITS INTO SMALLER CHUNKS OF AT MOST 150 LINES EACH.', + new_str_1: 'export default defineConfig({\n schema: "./src/main/lib/db/schema/index.ts",\n dialect: "sqlite",\n})', + old_str_1: 'export default defineConfig({\n schema: "./src/main/lib/db/schema/index.ts",\n out: "./drizzle",\n dialect: "sqlite",\n})', + old_str_end_line_number_1: 7, + old_str_start_line_number_1: 3, + path: 'drizzle.config.ts', + }, + }, + }, + }, + + // Tool call - Search (pending, with permission) + { + id: 'tool-4', + session_id: 'demo', + task_id: 'demo-task', + type: 'tool_call', + content: 'Search files', + author_type: 'agent', + created_at: '2024-01-20T10:09:00Z', + metadata: { + tool_call_id: 'tool-4', + tool_name: 'Grep', + title: '[TOOL - GREP - PENDING 🔒] Search for "authentication" in codebase', + status: 'pending', + args: { + pattern: 'authentication', + path: '/Users/demo/project/src', + output_mode: 'files_with_matches', + }, + }, + }, + + // Permission request (for tool-4) + { + id: 'permission-1', + session_id: 'demo', + task_id: 'demo-task', + type: 'permission_request', + content: '[PERMISSION REQUEST] Approve/Reject action', + author_type: 'user', + created_at: '2024-01-20T10:09:01Z', + metadata: { + pending_id: 'perm-1', + tool_call_id: 'tool-4', + action_type: 'file_search', + action_details: { + path: '/Users/demo/project/src', + command: 'grep -r "authentication"', + }, + options: [ + { option_id: 'allow-1', name: 'Allow Once', kind: 'allow_once' }, + { option_id: 'allow-2', name: 'Allow Always', kind: 'allow_always' }, + { option_id: 'reject-1', name: 'Reject', kind: 'reject_once' }, + ], + status: 'pending', + }, + }, + + // Status message - simple (separator style) + { + id: 'status-0', + session_id: 'demo', + task_id: 'demo-task', + type: 'status', + content: 'Agent initialized', + author_type: 'agent', + created_at: '2024-01-20T10:09:30Z', + }, + + // Status message - success + { + id: 'status-1', + session_id: 'demo', + task_id: 'demo-task', + type: 'status', + content: '[STATUS MESSAGE - SUCCESS ✓] Tests passed successfully! All 42 tests completed.', + author_type: 'agent', + created_at: '2024-01-20T10:10:00Z', + metadata: { + level: 'success', + }, + }, + + // Status message - error + { + id: 'status-2', + session_id: 'demo', + task_id: 'demo-task', + type: 'error', + content: '[STATUS MESSAGE - ERROR ✗] Build failed: TypeScript compilation error in auth.ts:45', + author_type: 'agent', + created_at: '2024-01-20T10:11:00Z', + metadata: { + level: 'error', + }, + }, + + // Todo message + { + id: 'todo-1', + session_id: 'demo', + task_id: 'demo-task', + type: 'todo', + content: '[TODO MESSAGE] Task list', + author_type: 'agent', + created_at: '2024-01-20T10:12:00Z', + metadata: { + todos: [ + { id: '1', text: '[TODO ITEM - COMPLETED] Set up OAuth provider', completed: true }, + { id: '2', text: '[TODO ITEM - PENDING] Implement token validation middleware', completed: false }, + { id: '3', text: '[TODO ITEM - PENDING] Add refresh token endpoint', completed: false }, + { id: '4', text: '[TODO ITEM - PENDING] Write integration tests', completed: false }, + ], + }, + }, + + // Script execution message - running + { + id: 'script-1', + session_id: 'demo', + task_id: 'demo-task', + type: 'script_execution', + content: '[SCRIPT EXECUTION MESSAGE - RUNNING] Setting up environment...\nInstalling dependencies...', + author_type: 'agent', + created_at: '2024-01-20T10:13:00Z', + metadata: { + script_type: 'setup', + command: './scripts/setup-env.sh', + status: 'running', + }, + }, + + // Script execution message - completed + { + id: 'script-2', + session_id: 'demo', + task_id: 'demo-task', + type: 'script_execution', + content: '[SCRIPT EXECUTION MESSAGE - COMPLETED] Build successful!\nAll tests passed.\nDeployment ready.', + author_type: 'agent', + created_at: '2024-01-20T10:14:00Z', + metadata: { + script_type: 'cleanup', + command: 'npm run build', + status: 'exited', + exit_code: 0, + started_at: '2024-01-20T10:13:00Z', + completed_at: '2024-01-20T10:14:00Z', + }, + }, + + // Agent message - mixed content + { + id: 'agent-3', + session_id: 'demo', + task_id: 'demo-task', + content: `**[MIXED CONTENT DEMO]** Testing nested and mixed elements: + +#### Heading 4 (h4 element) + +Regular paragraph with inline elements: \`code\`, **bold**, and more text. + +**Nested list structure:** + +1. **First level item** (ol > li with strong) + - Nested bullet (this should indent) + - Another nested item +2. Second level item with \`inline code\` +3. Third item + +**Technical details:** + +- File path: \`/src/components/Auth.tsx\` +- Function: \`authenticateUser(credentials)\` +- Status: **Active** (strong element) + +\`\`\`bash +# Code block with bash syntax +npm install +npm run dev +\`\`\` + +Final paragraph (p element) to wrap up.`, + author_type: 'agent', + type: 'message', + created_at: '2024-01-20T10:14:00Z', + }, + + // Agent message with rich blocks - thinking + { + id: 'agent-rich-1', + session_id: 'demo', + task_id: 'demo-task', + content: `**[RICH BLOCK - THINKING]** Here's my analysis of the authentication system.`, + author_type: 'agent', + type: 'message', + created_at: '2024-01-20T10:15:00Z', + metadata: { + thinking: 'I need to carefully consider the security implications here. The current implementation uses JWT tokens, but we should add refresh token rotation to prevent token theft. We also need to implement proper CSRF protection for the authentication endpoints.', + }, + }, + + // Agent message with rich blocks - todos + { + id: 'agent-rich-2', + session_id: 'demo', + task_id: 'demo-task', + content: `**[RICH BLOCK - TODOS]** Here are the next steps we need to take.`, + author_type: 'agent', + type: 'message', + created_at: '2024-01-20T10:16:00Z', + metadata: { + todos: [ + { text: 'Update the authentication middleware', done: true }, + { text: 'Add unit tests for token validation', done: false }, + { text: 'Implement rate limiting on login endpoint', done: false }, + 'Update documentation for new OAuth flow', + ], + }, + }, + + // Agent message with rich blocks - diff payload (structured) + { + id: 'agent-rich-3', + session_id: 'demo', + task_id: 'demo-task', + content: `**[RICH BLOCK - DIFF PAYLOAD]** I've made the following changes to the authentication config:`, + author_type: 'agent', + type: 'message', + created_at: '2024-01-20T10:17:00Z', + metadata: { + diff: { + oldFile: { fileName: 'src/auth/config.ts', fileLang: 'typescript' }, + newFile: { fileName: 'src/auth/config.ts', fileLang: 'typescript' }, + hunks: [ + `diff --git a/src/auth/config.ts b/src/auth/config.ts +index 1234567..abcdefg 100644 +--- a/src/auth/config.ts ++++ b/src/auth/config.ts +@@ -1,7 +1,10 @@ + export const authConfig = { + clientId: process.env.OAUTH_CLIENT_ID, +- clientSecret: process.env.OAUTH_CLIENT_SECRET, ++ clientSecret: process.env.OAUTH_CLIENT_SECRET || '', + redirectUri: process.env.OAUTH_REDIRECT_URI, ++ tokenExpiry: '1h', ++ refreshTokenExpiry: '7d', ++ enableCsrf: true, + }; + + export function validateToken(token: string) {`, + ], + }, + }, + }, + + // Agent message with rich blocks - diff string (plain text) + { + id: 'agent-rich-4', + session_id: 'demo', + task_id: 'demo-task', + content: `**[RICH BLOCK - DIFF STRING]** Here's the diff for the middleware changes:`, + author_type: 'agent', + type: 'message', + created_at: '2024-01-20T10:18:00Z', + metadata: { + diff: `--- a/src/middleware/auth.ts ++++ b/src/middleware/auth.ts +@@ -12,6 +12,11 @@ export async function authMiddleware(req: Request, res: Response, next: NextFun + const token = req.headers.authorization?.split(' ')[1]; + + if (!token) { +- return res.status(401).json({ error: 'No token provided' }); ++ return res.status(401).json({ ++ error: 'No token provided', ++ code: 'AUTH_TOKEN_MISSING', ++ timestamp: new Date().toISOString() ++ }); + } + + try {`, + }, + }, + + // Agent message with multiple rich blocks + { + id: 'agent-rich-5', + session_id: 'demo', + task_id: 'demo-task', + content: `**[RICH BLOCK - ALL TYPES]** Here's my complete analysis with all the changes:`, + author_type: 'agent', + type: 'message', + created_at: '2024-01-20T10:19:00Z', + metadata: { + thinking: 'After reviewing the code, I found several areas that need improvement. The error handling is inconsistent and we need better type safety.', + todos: [ + { text: 'Add TypeScript strict mode', done: true }, + { text: 'Implement error boundaries', done: false }, + { text: 'Add logging middleware', done: false }, + ], + diff: { + oldFile: { fileName: 'src/types/auth.ts', fileLang: 'typescript' }, + newFile: { fileName: 'src/types/auth.ts', fileLang: 'typescript' }, + hunks: [ + `diff --git a/src/types/auth.ts b/src/types/auth.ts +index 9876543..fedcba9 100644 +--- a/src/types/auth.ts ++++ b/src/types/auth.ts +@@ -1,4 +1,12 @@ +-export type AuthToken = string; ++export interface AuthToken { ++ value: string; ++ expiresAt: Date; ++ type: 'access' | 'refresh'; ++} + +-export type User = { ++export interface User { + id: string; + email: string; ++ role: 'admin' | 'user'; ++ createdAt: Date; ++}`, + ], + }, + }, + }, +]; + +export default function MessagesDemoPage() { + const permissionsByToolCallId = new Map(); + const permMsg = dummyMessages.find(m => m.id === 'permission-1'); + if (permMsg) { + permissionsByToolCallId.set('tool-4', permMsg); + } + + return ( +
+
+
+

Message Types Demo

+

+ All message types rendered for styling and testing +

+
+ +
+ {dummyMessages.map((message) => ( + + ))} +
+
+
+ ); +} diff --git a/apps/web/components/task/chat/messages/chat-message.tsx b/apps/web/components/task/chat/messages/chat-message.tsx index 228ed066a4..de79610850 100644 --- a/apps/web/components/task/chat/messages/chat-message.tsx +++ b/apps/web/components/task/chat/messages/chat-message.tsx @@ -1,12 +1,14 @@ 'use client'; -import { useMemo } from 'react'; import ReactMarkdown from 'react-markdown'; import remarkBreaks from 'remark-breaks'; import remarkGfm from 'remark-gfm'; +import { IconRobot } from '@tabler/icons-react'; import { cn } from '@/lib/utils'; import type { Message } from '@/lib/types/http'; import { RichBlocks } from '@/components/task/chat/messages/rich-blocks'; +import { InlineCode } from '@/components/task/chat/messages/inline-code'; +import { CodeBlock } from '@/components/task/chat/messages/code-block'; type ChatMessageProps = { comment: Message; @@ -15,39 +17,47 @@ type ChatMessageProps = { showRichBlocks?: boolean; }; -function formatMessageTime(dateString: string): string { - if (!dateString) return ''; - try { - const date = new Date(dateString); - if (isNaN(date.getTime())) return ''; - return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); - } catch { - return ''; - } -} - export function ChatMessage({ comment, label, className, showRichBlocks }: ChatMessageProps) { const isUser = comment.author_type === 'user'; - const formattedTime = useMemo(() => formatMessageTime(comment.created_at), [comment.created_at]); + const isTaskDescription = label === 'Task'; - return ( -
-
-

- {label} - {comment.requests_input ? ( - - Needs input - - ) : null} -

- {formattedTime && ( - {formattedTime} - )} -
- {isUser ? ( + // Keep the old card-based layout for task descriptions (amber banner) + if (isTaskDescription) { + return ( +
+
+

+ {comment.requests_input ? ( + + Needs input + + ) : null} +

+

{comment.content || '(empty)'}

- ) : ( +
+ ); + } + + // User message: right-aligned bubble + if (isUser) { + return ( +
+
+
+

{comment.content || '(empty)'}

+
+
+
+ ); + } + + // Agent message: icon on left, no card background + return ( +
+ + {/* Content */} +
- {children} - - ); + return {children}; } - // Code blocks (triple backticks) - return ( - - {children} - - ); + + // Code blocks (triple backticks) - with syntax highlighting and copy button + return {children}; }, ol: ({ children, ...props }) => ( -
    +
      {children}
    ), ul: ({ children, ...props }) => ( -
      +
        {children}
      ), li: ({ children, ...props }) => ( -
    • +
    • {children}
    • ), p: ({ children, ...props }) => ( -

      +

      + {children} +

      + ), + h1: ({ children, ...props }) => ( +

      + {children} +

      + ), + h2: ({ children, ...props }) => ( +

      + {children} +

      + ), + h3: ({ children, ...props }) => ( +

      + {children} +

      + ), + h4: ({ children, ...props }) => ( +

      + {children} +

      + ), + h5: ({ children, ...props }) => ( +

      {children}

      ), @@ -148,7 +125,7 @@ export function ChatMessage({ comment, label, className, showRichBlocks }: ChatM {showRichBlocks ? : null}
- )} +
); } diff --git a/apps/web/components/task/chat/messages/code-block.tsx b/apps/web/components/task/chat/messages/code-block.tsx new file mode 100644 index 0000000000..4b1571ace4 --- /dev/null +++ b/apps/web/components/task/chat/messages/code-block.tsx @@ -0,0 +1,148 @@ +'use client'; + +import { useState } from 'react'; +import { useTheme } from 'next-themes'; +import CodeMirror from '@uiw/react-codemirror'; +import { javascript } from '@codemirror/lang-javascript'; +import { python } from '@codemirror/lang-python'; +import { go } from '@codemirror/lang-go'; +import { rust } from '@codemirror/lang-rust'; +import { java } from '@codemirror/lang-java'; +import { cpp } from '@codemirror/lang-cpp'; +import { css } from '@codemirror/lang-css'; +import { html } from '@codemirror/lang-html'; +import { json } from '@codemirror/lang-json'; +import { markdown } from '@codemirror/lang-markdown'; +import { yaml } from '@codemirror/lang-yaml'; +import { vscodeDark, vscodeLight } from '@uiw/codemirror-theme-vscode'; +import { EditorView } from '@codemirror/view'; +import { IconCheck, IconCopy } from '@tabler/icons-react'; +import type { Extension } from '@codemirror/state'; +import { cn } from '@/lib/utils'; + +type CodeBlockProps = { + children: React.ReactNode; + className?: string; +}; + +const getLanguageExtension = (language?: string): Extension | undefined => { + if (!language) return undefined; + + const lang = language.replace('language-', '').toLowerCase(); + + switch (lang) { + case 'javascript': + case 'js': + return javascript(); + case 'jsx': + return javascript({ jsx: true }); + case 'typescript': + case 'ts': + return javascript({ typescript: true }); + case 'tsx': + return javascript({ jsx: true, typescript: true }); + case 'python': + case 'py': + return python(); + case 'go': + case 'golang': + return go(); + case 'rust': + case 'rs': + return rust(); + case 'java': + return java(); + case 'cpp': + case 'c++': + case 'c': + return cpp(); + case 'css': + case 'scss': + case 'less': + return css(); + case 'html': + case 'htm': + return html(); + case 'json': + return json(); + case 'markdown': + case 'md': + return markdown(); + case 'yaml': + case 'yml': + return yaml(); + case 'bash': + case 'sh': + case 'shell': + // Bash doesn't have a specific extension, fallback to basic + return undefined; + default: + return undefined; + } +}; + +export function CodeBlock({ children, className }: CodeBlockProps) { + const [copied, setCopied] = useState(false); + const { theme, systemTheme } = useTheme(); + const effectiveTheme = theme === 'system' ? systemTheme : theme; + + const code = String(children).replace(/\n$/, ''); + const language = className?.replace('language-', '') || ''; + const languageExtension = getLanguageExtension(className); + + // Custom padding theme + const paddingTheme = EditorView.theme({ + '&': { + padding: '2px 2px', + }, + }); + + const handleCopy = async () => { + try { + await navigator.clipboard.writeText(code); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + } catch (err) { + console.error('Failed to copy:', err); + } + }; + + return ( +
+ {/* Copy button */} + + + {/* Code editor */} + +
+ ); +} diff --git a/apps/web/components/task/chat/messages/inline-code.tsx b/apps/web/components/task/chat/messages/inline-code.tsx new file mode 100644 index 0000000000..b8794dcc2e --- /dev/null +++ b/apps/web/components/task/chat/messages/inline-code.tsx @@ -0,0 +1,57 @@ +'use client'; + +import { useState } from 'react'; +import { cn } from '@/lib/utils'; + +type InlineCodeProps = { + children: React.ReactNode; +}; + +export function InlineCode({ children }: InlineCodeProps) { + const [showTooltip, setShowTooltip] = useState(false); + const [tooltipText, setTooltipText] = useState('Copy to clipboard'); + + const handleClick = async () => { + const text = String(children); + try { + await navigator.clipboard.writeText(text); + setTooltipText('Copied!'); + setShowTooltip(true); + + setTimeout(() => { + setShowTooltip(false); + setTimeout(() => setTooltipText('Copy to clipboard'), 200); + }, 1500); + } catch (err) { + console.error('Failed to copy:', err); + } + }; + + return ( + + + {children} + + + {/* Tooltip */} + + {tooltipText} + + + + ); +} diff --git a/apps/web/components/task/chat/messages/permission-action-row.tsx b/apps/web/components/task/chat/messages/permission-action-row.tsx index 92bdda7936..02b6493b98 100644 --- a/apps/web/components/task/chat/messages/permission-action-row.tsx +++ b/apps/web/components/task/chat/messages/permission-action-row.tsx @@ -15,26 +15,26 @@ export function PermissionActionRow({ isResponding = false, }: PermissionActionRowProps) { return ( -
+
Approve this action? + {isExpanded && comment.content && ( +
+
+                  {comment.content}
+                
+
+ )} +
- {comment.content && ( -
-            {comment.content}
-          
- )}
); } @@ -45,90 +74,106 @@ export function ScriptExecutionMessage({ comment }: { comment: Message }) { const StatusIcon = isRunning ? IconLoader2 : isSuccess - ? IconCheck - : IconX; + ? IconCheck + : IconX; const statusText = isRunning ? 'Running...' : isSuccess - ? 'Completed' - : 'Failed'; + ? 'Completed' + : 'Failed'; const statusColor = isRunning ? 'text-blue-500' : isSuccess - ? 'text-green-500' - : 'text-red-500'; + ? 'text-green-500' + : 'text-red-500'; - const borderColor = isRunning - ? 'border-blue-500/40' - : isSuccess - ? 'border-green-500/40' - : 'border-red-500/40'; - - const bgColor = isRunning - ? 'bg-blue-500/5' - : isSuccess - ? 'bg-green-500/5' - : 'bg-red-500/5'; + const hasDetails = comment.content || error || exit_code !== undefined; return ( -
- {/* Header */} -
-
+
+ {/* Icon + Summary Row */} +
+ {/* Icon */} +
- - {isSetup ? 'Setup Script' : 'Cleanup Script'} - -
- - {statusText} +
+ + {/* Content */} +
+
+
-
-
- {/* Command */} -
- $ {command} -
+ {/* Expanded Details */} + {isExpanded && hasDetails && ( +
+ {/* Output */} + {comment.content && comment.content.trim() !== '' && ( +
+
+ Output +
+
+                    {comment.content}
+                  
+
+ )} - {/* Output */} - {comment.content && comment.content.trim() !== '' && ( -
-
- Output -
-
-            {comment.content}
-          
-
- )} + {/* Error message */} + {error && ( +
+
+ Error +
+
+ {error} +
+
+ )} - {/* Error message */} - {error && ( -
- {error} -
- )} - - {/* Footer with exit code */} - {!isRunning && exit_code !== undefined && ( -
- Exit code: {exit_code} - {metadata.started_at && metadata.completed_at && ( - - Duration: {calculateDuration(metadata.started_at, metadata.completed_at)} - + {/* Footer with exit code */} + {!isRunning && exit_code !== undefined && ( +
+ Exit code: {exit_code} + {metadata.started_at && metadata.completed_at && ( + + Duration: {calculateDuration(metadata.started_at, metadata.completed_at)} + + )} +
+ )} +
)}
- )} +
); } diff --git a/apps/web/components/task/chat/messages/status-message.tsx b/apps/web/components/task/chat/messages/status-message.tsx index a867fd349b..17ad5a5e47 100644 --- a/apps/web/components/task/chat/messages/status-message.tsx +++ b/apps/web/components/task/chat/messages/status-message.tsx @@ -33,30 +33,31 @@ export function StatusMessage({ comment }: { comment: Message }) { if (isSimpleStatus) { return ( -
-
- - {message} -
+
+
+ {message} +
); } - // Cancelled turn gets a special compact warning style + // Cancelled turn gets a special separator style if (metadata?.cancelled) { return ( -
-
+
+
+
{message}
+
); } const Icon = isError ? IconAlertTriangle : isWarning ? IconAlertTriangle : IconInfoCircle; const iconClass = isError ? 'text-red-500' : isWarning ? 'text-amber-500' : 'text-muted-foreground'; - const label = isError ? 'Error' : isWarning ? 'Warning' : 'Status'; + const textClass = isError ? 'text-red-600 dark:text-red-400' : isWarning ? 'text-amber-600 dark:text-amber-400' : 'text-muted-foreground'; // Format error details for display const formatErrorDetails = () => { @@ -86,68 +87,71 @@ export function StatusMessage({ comment }: { comment: Message }) { const errorDetails = hasErrorDetails ? formatErrorDetails() : []; return ( -
-
- - {label} -
-
{message || 'An error occurred'}
+
+ {/* Icon + Content Row */} +
+ {/* Icon */} +
+ +
- {/* Expandable error details */} - {hasErrorDetails && errorDetails.length > 0 && ( -
- + {/* Content */} +
+
+ {message || 'An error occurred'} +
- {isExpanded && ( -
- {errorDetails.map((detail, index) => ( -
-
- {detail.label} -
-
-                    {detail.value}
-                  
+ {/* Expandable error details */} + {hasErrorDetails && errorDetails.length > 0 && ( +
+ + + {isExpanded && ( +
+ {errorDetails.map((detail, index) => ( +
+
+ {detail.label} +
+
+                        {detail.value}
+                      
+
+ ))}
- ))} + )} +
+ )} + + {/* Progress bar */} + {progress !== null && ( +
+
+ {statusLine ?? 'Progress'} + {Math.round(progress)}% +
+
+
+
)}
- )} - - {progress !== null && ( -
-
- {statusLine ?? 'Progress'} - {Math.round(progress)}% -
-
-
-
-
- )} +
); } diff --git a/apps/web/components/task/chat/messages/thinking-message.tsx b/apps/web/components/task/chat/messages/thinking-message.tsx index dbc8abb40e..d06db3d8d5 100644 --- a/apps/web/components/task/chat/messages/thinking-message.tsx +++ b/apps/web/components/task/chat/messages/thinking-message.tsx @@ -1,20 +1,54 @@ 'use client'; -import { IconBrain } from '@tabler/icons-react'; +import { useState } from 'react'; +import { IconBrain, IconChevronDown, IconChevronRight } from '@tabler/icons-react'; +import { cn } from '@/lib/utils'; import type { Message } from '@/lib/types/http'; import type { RichMetadata } from '@/components/task/chat/types'; export function ThinkingMessage({ comment }: { comment: Message }) { + const [isExpanded, setIsExpanded] = useState(false); const metadata = comment.metadata as RichMetadata | undefined; const text = metadata?.thinking ?? comment.content; + if (!text) return null; + return ( -
-
- - Thinking +
+ {/* Icon + Summary Row */} +
+ {/* Icon */} +
+ +
+ + {/* Content */} +
+
+ +
+ + {/* Expanded Content */} + {isExpanded && ( +
+
{text}
+
+ )} +
-
{text}
); } diff --git a/apps/web/components/task/chat/messages/todo-message.tsx b/apps/web/components/task/chat/messages/todo-message.tsx index ee5cdd7d7e..7ca1805baf 100644 --- a/apps/web/components/task/chat/messages/todo-message.tsx +++ b/apps/web/components/task/chat/messages/todo-message.tsx @@ -20,7 +20,7 @@ export function TodoMessage({ comment }: { comment: Message }) { const progress = Math.round((completed / todoItems.length) * 100); return ( -
+
Todos diff --git a/apps/web/components/task/chat/messages/tool-call-message.tsx b/apps/web/components/task/chat/messages/tool-call-message.tsx index 0f37117726..4d0c7da51a 100644 --- a/apps/web/components/task/chat/messages/tool-call-message.tsx +++ b/apps/web/components/task/chat/messages/tool-call-message.tsx @@ -1,6 +1,6 @@ 'use client'; -import { useCallback, useState } from 'react'; +import { useCallback, useEffect, useState } from 'react'; import { IconCheck, IconChevronDown, @@ -87,8 +87,6 @@ type ToolCallMessageProps = { }; export function ToolCallMessage({ comment, permissionMessage }: ToolCallMessageProps) { - const [isExpanded, setIsExpanded] = useState(false); - const [isResponding, setIsResponding] = useState(false); const metadata = comment.metadata as ToolCallMetadata | undefined; const permissionMetadata = permissionMessage?.metadata as PermissionRequestMetadata | undefined; @@ -103,6 +101,31 @@ export function ToolCallMessage({ comment, permissionMessage }: ToolCallMessageP const permissionStatus = permissionMetadata?.status; const isPermissionPending = hasPermission && permissionStatus !== 'approved' && permissionStatus !== 'rejected'; + // Initialize isExpanded based on status - auto-expand if running + const [isExpanded, setIsExpanded] = useState(() => { + return status === 'running'; + }); + const [isManuallyToggled, setIsManuallyToggled] = useState(false); + const [isResponding, setIsResponding] = useState(false); + + // Auto-collapse when complete (unless manually overridden) + useEffect(() => { + // Permission requests always stay expanded + if (isPermissionPending) { + setIsExpanded(true); + return; + } + + // Only auto-collapse if user hasn't manually toggled + if (!isManuallyToggled) { + if (status === 'running') { + setIsExpanded(true); + } else if (status === 'complete' || status === 'error') { + setIsExpanded(false); + } + } + }, [status, isManuallyToggled, isPermissionPending]); + const handleRespond = useCallback( async (optionId: string, cancelled: boolean = false) => { if (!permissionMetadata || !permissionMessage) return; @@ -150,10 +173,6 @@ export function ToolCallMessage({ comment, permissionMessage }: ToolCallMessageP } }, [permissionMetadata, handleRespond]); - const toolIcon = getToolIcon(toolName, cn( - 'h-4 w-4 flex-shrink-0', - isPermissionPending ? 'text-amber-600 dark:text-amber-400' : 'text-amber-600 dark:text-amber-400' - )); const hasDetails = args && Object.keys(args).length > 0; let filePath: string | undefined; @@ -168,75 +187,99 @@ export function ToolCallMessage({ comment, permissionMessage }: ToolCallMessageP } } + const isSuccess = status === 'complete' && !permissionStatus; + return ( -
- +
+ {/* Icon + Summary Row */} +
+ {/* Icon */} +
+ {getToolIcon(toolName, cn( + 'h-4 w-4', + isPermissionPending ? 'text-amber-600 dark:text-amber-400' : 'text-muted-foreground' + ))} +
- {isExpanded && hasDetails && ( -
- {args && Object.entries(args).map(([key, value]) => { - const strValue = typeof value === 'string' ? value : JSON.stringify(value, null, 2); - const isLongValue = strValue.length > 100 || strValue.includes('\n'); + {/* Content */} +
+
+ + {filePath && ( + + {filePath} + + )} +
- return ( -
- {key}: - {isLongValue ? ( -
-                    {strValue}
+          {/* Expanded Details */}
+          {isExpanded && hasDetails && (
+            
+ {args && Object.entries(args).map(([key, value]) => { + const strValue = typeof value === 'string' ? value : JSON.stringify(value, null, 2); + const isLongValue = strValue.length > 100 || strValue.includes('\n'); + + return ( +
+ {key}: + {isLongValue ? ( +
+                        {strValue}
+                      
+ ) : ( + {strValue} + )} +
+ ); + })} + {result && ( +
+ Result: +
+                    {result}
                   
- ) : ( - {strValue} - )} -
- ); - })} - {result && ( -
- Result: -
-                {result}
-              
+
+ )} +
+ )} + + {/* Inline permission approval UI */} + {isPermissionPending && ( +
+
)}
- )} - - {/* Inline permission approval UI */} - {isPermissionPending && ( - - )} +
); } diff --git a/apps/web/components/task/chat/virtualized-message-list.tsx b/apps/web/components/task/chat/virtualized-message-list.tsx index 2fa221ed26..40d7d0aa15 100644 --- a/apps/web/components/task/chat/virtualized-message-list.tsx +++ b/apps/web/components/task/chat/virtualized-message-list.tsx @@ -100,7 +100,7 @@ export function VirtualizedMessageList({ return ( {isLoadingMore && hasMore && (
@@ -133,7 +133,7 @@ export function VirtualizedMessageList({ className="absolute left-0 top-0 w-full" style={{ transform: `translateY(${virtualRow.start}px)` }} > -
+
+
No changes detected
)} @@ -354,7 +354,7 @@ const TaskFilesPanel = memo(function TaskFilesPanel({ onSelectDiff, onOpenFile } {activeSessionId ? ( ) : ( -
+
No task selected
)}