Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/__tests__/smoke-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ async function runSmokeTests() {
results.push({ name: route.name, status: 'PASS', details, consoleErrors, loadTimeMs: elapsed });
} catch (err: unknown) {
const elapsed = Date.now() - start;
results.push({ name: route.name, status: 'FAIL', details: err instanceof Error ? err.message : String(err), consoleErrors, loadTimeMs: elapsed });
const message = err instanceof Error ? err.message : String(err);
results.push({ name: route.name, status: 'FAIL', details: message, consoleErrors, loadTimeMs: elapsed });
}
await page.close();
}
Expand Down
3 changes: 1 addition & 2 deletions src/__tests__/unit/db-shutdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 4. Data persists across close/reopen cycles
*/

import { describe, it, before, afterEach } from 'node:test';
import { describe, it, afterEach } from 'node:test';
import assert from 'node:assert/strict';
import path from 'path';
import os from 'os';
Expand All @@ -23,7 +23,6 @@ process.env.CLAUDE_GUI_DATA_DIR = tmpDir;
// Use require to avoid top-level await issues with CJS output
/* eslint-disable @typescript-eslint/no-require-imports */
const { getDb, closeDb, createSession, getSession } = require('../../lib/db') as typeof import('../../lib/db');

describe('closeDb', () => {
afterEach(() => {
// Ensure DB is closed after each test
Expand Down
1 change: 1 addition & 0 deletions src/app/api/settings/app/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getSetting, setSetting } from '@/lib/db';
const ALLOWED_KEYS = [
'anthropic_auth_token',
'anthropic_base_url',
'locale',
'dangerously_skip_permissions',
];

Expand Down
20 changes: 11 additions & 9 deletions src/app/chat/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { HugeiconsIcon } from "@hugeicons/react";
import { Loading02Icon, PencilEdit01Icon } from "@hugeicons/core-free-icons";
import { Input } from '@/components/ui/input';
import { usePanel } from '@/hooks/usePanel';
import { useTranslation } from '@/hooks/useTranslation';

interface ChatSessionPageProps {
params: Promise<{ id: string }>;
Expand All @@ -27,11 +28,12 @@ export default function ChatSessionPage({ params }: ChatSessionPageProps) {
const [editTitle, setEditTitle] = useState('');
const titleInputRef = useRef<HTMLInputElement>(null);
const { setWorkingDirectory, setSessionId, setSessionTitle: setPanelSessionTitle, setPanelOpen } = usePanel();
const { t } = useTranslation();

const handleStartEditTitle = useCallback(() => {
setEditTitle(sessionTitle || 'New Conversation');
setEditTitle(sessionTitle || t('chatSession.newConversation'));
setIsEditingTitle(true);
}, [sessionTitle]);
}, [sessionTitle, t]);

const handleSaveTitle = useCallback(async () => {
const trimmed = editTitle.trim();
Expand Down Expand Up @@ -84,7 +86,7 @@ export default function ChatSessionPage({ params }: ChatSessionPageProps) {
}
setSessionId(id);
setPanelOpen(true);
const title = data.session.title || 'New Conversation';
const title = data.session.title || t('chatSession.newConversation');
setSessionTitle(title);
setPanelSessionTitle(title);
setSessionModel(data.session.model || '');
Expand All @@ -97,7 +99,7 @@ export default function ChatSessionPage({ params }: ChatSessionPageProps) {
}

loadSession();
}, [id, setWorkingDirectory, setSessionId, setPanelSessionTitle, setPanelOpen]);
}, [id, setWorkingDirectory, setSessionId, setPanelSessionTitle, setPanelOpen, t]);

useEffect(() => {
// Reset state when switching sessions
Expand All @@ -114,7 +116,7 @@ export default function ChatSessionPage({ params }: ChatSessionPageProps) {
if (cancelled) return;
if (!res.ok) {
if (res.status === 404) {
setError('Session not found');
setError(t('chatSession.sessionNotFound'));
return;
}
throw new Error('Failed to load messages');
Expand All @@ -123,9 +125,9 @@ export default function ChatSessionPage({ params }: ChatSessionPageProps) {
if (cancelled) return;
setMessages(data.messages);
setHasMore(data.hasMore ?? false);
} catch (err) {
} catch {
if (cancelled) return;
setError(err instanceof Error ? err.message : 'Failed to load messages');
setError(t('chatSession.failedToLoad'));
} finally {
if (!cancelled) setLoading(false);
}
Expand All @@ -134,7 +136,7 @@ export default function ChatSessionPage({ params }: ChatSessionPageProps) {
loadMessages();

return () => { cancelled = true; };
}, [id]);
}, [id, t]);

if (loading) {
return (
Expand All @@ -150,7 +152,7 @@ export default function ChatSessionPage({ params }: ChatSessionPageProps) {
<div className="text-center space-y-2">
<p className="text-destructive font-medium">{error}</p>
<Link href="/chat" className="text-sm text-muted-foreground hover:underline">
Start a new chat
{t('chatSession.startNewChat')}
</Link>
</div>
</div>
Expand Down
56 changes: 41 additions & 15 deletions src/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type { Message, SSEEvent, SessionResponse, TokenUsage, PermissionRequestE
import { MessageList } from '@/components/chat/MessageList';
import { MessageInput } from '@/components/chat/MessageInput';
import { usePanel } from '@/hooks/usePanel';
import { useTranslation } from '@/hooks/useTranslation';
import { buildHelpContent } from '@/lib/help-content';

interface ToolUseInfo {
id: string;
Expand All @@ -18,16 +20,25 @@ interface ToolResultInfo {
content: string;
}

type UserFacingError = Error & { userMessage?: string };

function makeUserFacingError(userMessage: string, technicalMessage?: string): UserFacingError {
const error = new Error(technicalMessage || userMessage) as UserFacingError;
error.userMessage = userMessage;
return error;
}

export default function NewChatPage() {
const router = useRouter();
const { setWorkingDirectory, setPanelOpen, setPendingApprovalSessionId } = usePanel();
const { setPendingApprovalSessionId } = usePanel();
const { t } = useTranslation();
const [messages, setMessages] = useState<Message[]>([]);
const [streamingContent, setStreamingContent] = useState('');
const [isStreaming, setIsStreaming] = useState(false);
const [toolUses, setToolUses] = useState<ToolUseInfo[]>([]);
const [toolResults, setToolResults] = useState<ToolResultInfo[]>([]);
const [statusText, setStatusText] = useState<string | undefined>();
const [workingDir, setWorkingDir] = useState('');
const workingDir = '';
const [mode, setMode] = useState('code');
const [currentModel, setCurrentModel] = useState('sonnet');
const [pendingPermission, setPendingPermission] = useState<PermissionRequestEvent | null>(null);
Expand Down Expand Up @@ -84,7 +95,7 @@ export default function NewChatPage() {
id: 'hint-' + Date.now(),
session_id: '',
role: 'assistant',
content: '**Please select a project directory first.** Use the folder picker in the toolbar below to choose a working directory before sending a message.',
content: `**${t('input.selectProjectFolder')}**`,
created_at: new Date().toISOString(),
token_usage: null,
};
Expand Down Expand Up @@ -119,7 +130,13 @@ export default function NewChatPage() {

if (!createRes.ok) {
const errBody = await createRes.json().catch(() => ({}));
throw new Error(errBody.error || `Failed to create session (${createRes.status})`);
const technicalMessage = typeof errBody.error === 'string'
? errBody.error
: `Failed to create session (${createRes.status})`;
throw makeUserFacingError(
t('chat.failedToCreateSession', { status: createRes.status }),
technicalMessage,
);
}

const { session }: SessionResponse = await createRes.json();
Expand Down Expand Up @@ -148,8 +165,11 @@ export default function NewChatPage() {
});

if (!response.ok) {
const err = await response.json();
throw new Error(err.error || 'Failed to send message');
const err = await response.json().catch(() => ({}));
const technicalMessage = typeof err.error === 'string'
? err.error
: `Failed to send message (${response.status})`;
throw makeUserFacingError(t('chat.failedToSend'), technicalMessage);
}

const reader = response.body?.getReader();
Expand Down Expand Up @@ -203,7 +223,7 @@ export default function NewChatPage() {
try {
const parsed = JSON.parse(event.data);
if (parsed._progress) {
setStatusText(`Running ${parsed.tool_name}... (${Math.round(parsed.elapsed_time_seconds)}s)`);
setStatusText(t('chat.running', { tool: parsed.tool_name, seconds: Math.round(parsed.elapsed_time_seconds) }));
break;
}
} catch {
Expand All @@ -219,7 +239,7 @@ export default function NewChatPage() {
try {
const statusData = JSON.parse(event.data);
if (statusData.session_id) {
setStatusText(`Connected (${statusData.model || 'claude'})`);
setStatusText(t('chat.connected', { model: statusData.model || 'claude' }));
setTimeout(() => setStatusText(undefined), 2000);
} else if (statusData.notification) {
setStatusText(statusData.message || statusData.title || undefined);
Expand Down Expand Up @@ -251,7 +271,7 @@ export default function NewChatPage() {
break;
}
case 'error': {
accumulated += '\n\n**Error:** ' + event.data;
accumulated += '\n\n**' + t('chat.error') + ':** ' + event.data;
setStreamingContent(accumulated);
break;
}
Expand Down Expand Up @@ -286,12 +306,18 @@ export default function NewChatPage() {
router.push(`/chat/${sessionId}`);
}
} else {
const errMsg = error instanceof Error ? error.message : 'Unknown error';
const errMsg =
typeof error === 'object' &&
error !== null &&
'userMessage' in error &&
typeof (error as UserFacingError).userMessage === 'string'
? (error as UserFacingError).userMessage!
: t('chat.failedToSend');
const errorMessage: Message = {
id: 'temp-error-' + Date.now(),
session_id: '',
role: 'assistant',
content: `**Error:** ${errMsg}`,
content: `**${t('chat.error')}:** ${errMsg}`,
created_at: new Date().toISOString(),
token_usage: null,
};
Expand All @@ -310,7 +336,7 @@ export default function NewChatPage() {
abortControllerRef.current = null;
}
},
[isStreaming, router, workingDir, mode, currentModel, setPendingApprovalSessionId]
[isStreaming, router, workingDir, mode, currentModel, setPendingApprovalSessionId, t]
);

const handleCommand = useCallback((command: string) => {
Expand All @@ -320,7 +346,7 @@ export default function NewChatPage() {
id: 'cmd-' + Date.now(),
session_id: '',
role: 'assistant',
content: `## Available Commands\n\n- **/help** - Show this help message\n- **/clear** - Clear conversation history\n- **/compact** - Compress conversation context\n- **/cost** - Show token usage statistics\n- **/doctor** - Check system health\n- **/init** - Initialize CLAUDE.md\n- **/review** - Start code review\n- **/terminal-setup** - Configure terminal\n\n**Tips:**\n- Type \`@\` to mention files\n- Use Shift+Enter for new line\n- Select a project folder to enable file operations`,
content: buildHelpContent(t),
created_at: new Date().toISOString(),
token_usage: null,
};
Expand All @@ -335,7 +361,7 @@ export default function NewChatPage() {
id: 'cmd-' + Date.now(),
session_id: '',
role: 'assistant',
content: `## Token Usage\n\nToken usage tracking is available after sending messages. Check the token count displayed at the bottom of each assistant response.`,
content: `${t('chat.tokenUsageTitle')}\n\n${t('chat.noTokenUsage')}`,
created_at: new Date().toISOString(),
token_usage: null,
};
Expand All @@ -345,7 +371,7 @@ export default function NewChatPage() {
default:
sendFirstMessage(command);
}
}, [sendFirstMessage]);
}, [sendFirstMessage, t]);

return (
<div className="flex h-full min-h-0 flex-col">
Expand Down
8 changes: 5 additions & 3 deletions src/app/extensions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Suspense, useState } from "react";
import { useSearchParams } from "next/navigation";
import { useTranslation } from "@/hooks/useTranslation";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { HugeiconsIcon } from "@hugeicons/react";
import { Loading02Icon } from "@hugeicons/core-free-icons";
Expand All @@ -28,15 +29,16 @@ function ExtensionsPageInner() {
const searchParams = useSearchParams();
const initialTab = (searchParams.get("tab") as ExtTab) || "skills";
const [tab, setTab] = useState<ExtTab>(initialTab);
const { t } = useTranslation();

return (
<div className="flex h-full flex-col">
<div className="px-6 pt-4 pb-0">
<h1 className="text-xl font-semibold mb-3">Extensions</h1>
<h1 className="text-xl font-semibold mb-3">{t('extensions.title')}</h1>
<Tabs value={tab} onValueChange={(v) => setTab(v as ExtTab)}>
<TabsList>
<TabsTrigger value="skills">Skills</TabsTrigger>
<TabsTrigger value="mcp">MCP Servers</TabsTrigger>
<TabsTrigger value="skills">{t('extensions.skills')}</TabsTrigger>
<TabsTrigger value="mcp">{t('extensions.mcpServers')}</TabsTrigger>
</TabsList>
</Tabs>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import { ThemeProvider } from "@/components/layout/ThemeProvider";
import { I18nProvider } from "@/components/layout/I18nProvider";
import { AppShell } from "@/components/layout/AppShell";

const geistSans = Geist({
Expand Down Expand Up @@ -30,7 +31,9 @@ export default function RootLayout({
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
<ThemeProvider>
<AppShell>{children}</AppShell>
<I18nProvider>
<AppShell>{children}</AppShell>
</I18nProvider>
</ThemeProvider>
</body>
</html>
Expand Down
27 changes: 16 additions & 11 deletions src/components/ai-elements/tool-actions-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from "@hugeicons/core-free-icons";
import { ChevronRightIcon } from 'lucide-react';
import { cn } from '@/lib/utils';
import { useTranslation } from '@/hooks/useTranslation';

// ---------------------------------------------------------------------------
// Types
Expand Down Expand Up @@ -194,15 +195,14 @@ function getRunningDescription(tools: ToolAction[]): string {
export function ToolActionsGroup({
tools,
isStreaming = false,
streamingToolOutput: _streamingToolOutput,
}: ToolActionsGroupProps) {
const hasRunningTool = tools.some((t) => t.result === undefined);
const { t } = useTranslation();

// Track whether user has manually toggled and their chosen state
const [userExpandedState, setUserExpandedState] = useState<boolean | null>(null);

// Derived: if user has toggled, use their choice; otherwise auto-expand based on streaming state
const expanded = userExpandedState !== null ? userExpandedState : (hasRunningTool || isStreaming);
const autoExpanded = hasRunningTool || isStreaming;
const [userToggled, setUserToggled] = useState(false);
const [manualExpanded, setManualExpanded] = useState(false);
const expanded = userToggled ? manualExpanded : autoExpanded;

if (tools.length === 0) return null;

Expand All @@ -211,15 +211,20 @@ export function ToolActionsGroup({
const runningDesc = getRunningDescription(tools);

const handleToggle = () => {
setUserExpandedState((prev) => prev !== null ? !prev : !expanded);
if (!userToggled) {
setUserToggled(true);
setManualExpanded(!autoExpanded);
return;
}

setManualExpanded((prev) => !prev);
};

// Build summary text parts
const summaryParts: string[] = [];
if (runningCount > 0) summaryParts.push(`${runningCount} running`);
if (doneCount > 0) summaryParts.push(`${doneCount} completed`);
if (runningCount === 0 && isStreaming) summaryParts.push('generating response');
if (summaryParts.length === 0) summaryParts.push(`${tools.length} actions`);
if (runningCount > 0) summaryParts.push(`${runningCount} ${t('toolActions.running')}`);
if (doneCount > 0) summaryParts.push(`${doneCount} ${t('toolActions.completed')}`);
if (summaryParts.length === 0) summaryParts.push(`${tools.length} ${t('toolActions.actions')}`);

return (
<div className="w-[min(100%,48rem)]">
Expand Down
Loading