"use client"; import { useState } from "react"; import { useTheme } from "next-themes"; import { IconCommand, IconPalette, IconServer, IconKeyboard, IconTerminal2, IconGitBranch, } from "@tabler/icons-react"; import { Badge } from "@kandev/ui/badge"; import { Card, CardContent, CardHeader, CardTitle } from "@kandev/ui/card"; import { Label } from "@kandev/ui/label"; import { Input } from "@kandev/ui/input"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue, } from "@kandev/ui/select"; import { Separator } from "@kandev/ui/separator"; import { SettingsSection } from "@/components/settings/settings-section"; import { ShellSettingsCard } from "@/components/settings/shell-settings-card"; import { KeyboardShortcutsCard } from "@/components/settings/keyboard-shortcuts-card"; import { getBackendConfig } from "@/lib/config"; import { useAppStore, useAppStoreApi } from "@/components/state-provider"; import { updateUserSettings } from "@/lib/api"; import { TERMINAL_FONT_PRESETS } from "@/lib/terminal/terminal-font"; import type { FontCategory } from "@/lib/terminal/terminal-font"; import type { Theme } from "@/lib/settings/types"; function ThemeSettingsCard() { const { theme: currentTheme, setTheme } = useTheme(); const themeValue = currentTheme ?? "system"; return ( Color Theme
); } function ChatSubmitKeyCard() { const userSettings = useAppStore((state) => state.userSettings); const setUserSettings = useAppStore((state) => state.setUserSettings); const [isSavingSubmitKey, setIsSavingSubmitKey] = useState(false); const handleChatSubmitKeyChange = async (value: "enter" | "cmd_enter") => { if (isSavingSubmitKey) return; setIsSavingSubmitKey(true); const previousValue = userSettings.chatSubmitKey; try { setUserSettings({ ...userSettings, chatSubmitKey: value }); await updateUserSettings({ workspace_id: userSettings.workspaceId || "", repository_ids: userSettings.repositoryIds || [], chat_submit_key: value, }); } catch { setUserSettings({ ...userSettings, chatSubmitKey: previousValue }); } finally { setIsSavingSubmitKey(false); } }; return ( Submit Shortcut

{userSettings.chatSubmitKey === "cmd_enter" ? "Press Cmd/Ctrl+Enter to send messages. Press Enter for newlines." : "Press Enter to send messages. Press Shift+Enter for newlines."}

); } function ChangesPanelLayoutCard() { const userSettings = useAppStore((state) => state.userSettings); const setUserSettings = useAppStore((state) => state.setUserSettings); const storeApi = useAppStoreApi(); const [isSaving, setIsSaving] = useState(false); const handleChange = async (value: "flat" | "tree") => { if (isSaving) return; setIsSaving(true); const current = storeApi.getState().userSettings; const previous = current.changesPanelLayout; try { setUserSettings({ ...current, changesPanelLayout: value }); await updateUserSettings({ workspace_id: current.workspaceId || "", repository_ids: current.repositoryIds || [], changes_panel_layout: value, }); } catch { setUserSettings({ ...storeApi.getState().userSettings, changesPanelLayout: previous }); } finally { setIsSaving(false); } }; return ( Changes Panel Layout

Display changed files as a flat list with full paths, or as a folder tree.

); } function TerminalLinksCard() { const userSettings = useAppStore((state) => state.userSettings); const setUserSettings = useAppStore((state) => state.setUserSettings); const storeApi = useAppStoreApi(); const [isSaving, setIsSaving] = useState(false); const handleChange = async (value: "new_tab" | "browser_panel") => { if (isSaving) return; setIsSaving(true); const current = storeApi.getState().userSettings; const previous = current.terminalLinkBehavior; try { setUserSettings({ ...current, terminalLinkBehavior: value }); await updateUserSettings({ workspace_id: current.workspaceId || "", repository_ids: current.repositoryIds || [], terminal_link_behavior: value, }); } catch { setUserSettings({ ...storeApi.getState().userSettings, terminalLinkBehavior: previous, }); } finally { setIsSaving(false); } }; return ( Terminal Links

Click a URL in the terminal to open it.

); } const CUSTOM_VALUE = "__custom__"; const CATEGORY_LABELS: Record = { icons: "Nerd Fonts", ligatures: "Programming", system: "System", }; const CATEGORY_BADGES: Partial> = { icons: "Icons", ligatures: "Ligatures", }; const FONT_GROUPS: Record = TERMINAL_FONT_PRESETS.reduce( (acc, p) => { (acc[p.category] ??= []).push(p); return acc; }, {} as Record, ); const FONT_CATEGORIES: FontCategory[] = ["icons", "ligatures", "system"]; function FontGroupOptions() { return FONT_CATEGORIES.map((category) => ( {CATEGORY_LABELS[category]} {CATEGORY_BADGES[category] && ( {CATEGORY_BADGES[category]} )} {(FONT_GROUPS[category] ?? []).map((preset) => ( {preset.label} ))} )); } function TerminalFontSizeCard() { const storeApi = useAppStoreApi(); const userSettings = useAppStore((state) => state.userSettings); const setUserSettings = useAppStore((state) => state.setUserSettings); const [isSaving, setIsSaving] = useState(false); const [fontSize, setFontSize] = useState(() => userSettings.terminalFontSize ?? 13); const saveFontSize = async (value: number) => { if (isSaving) return; if (value < 8 || value > 24) return; setIsSaving(true); const current = storeApi.getState().userSettings; const previous = current.terminalFontSize; try { setUserSettings({ ...current, terminalFontSize: value }); await updateUserSettings({ workspace_id: current.workspaceId || "", repository_ids: current.repositoryIds || [], terminal_font_size: value, }); } catch { setUserSettings({ ...storeApi.getState().userSettings, terminalFontSize: previous }); } finally { setIsSaving(false); } }; const handleFontSizeBlur = () => { const v = Math.min(24, Math.max(8, fontSize)); setFontSize(v); saveFontSize(v); }; return ( Terminal Font Size
setFontSize(Number(e.target.value))} onBlur={handleFontSizeBlur} onKeyDown={(e) => { if (e.key === "Enter") handleFontSizeBlur(); }} className="w-20" disabled={isSaving} data-testid="terminal-font-size-input" /> px (8-24)

Set the font size for the terminal. Default is 13px.

); } function TerminalFontCard() { const storeApi = useAppStoreApi(); const userSettings = useAppStore((state) => state.userSettings); const setUserSettings = useAppStore((state) => state.setUserSettings); const [isSaving, setIsSaving] = useState(false); const [isCustom, setIsCustom] = useState(() => { const current = userSettings.terminalFontFamily; if (!current) return false; return !TERMINAL_FONT_PRESETS.some((p) => p.value === current); }); const [customValue, setCustomValue] = useState( () => (isCustom ? userSettings.terminalFontFamily : "") ?? "", ); const saveFontFamily = async (value: string) => { if (isSaving) return; setIsSaving(true); const current = storeApi.getState().userSettings; const previous = current.terminalFontFamily; try { setUserSettings({ ...current, terminalFontFamily: value || null }); await updateUserSettings({ workspace_id: current.workspaceId || "", repository_ids: current.repositoryIds || [], terminal_font_family: value, }); } catch { setUserSettings({ ...storeApi.getState().userSettings, terminalFontFamily: previous, }); } finally { setIsSaving(false); } }; const handleSelectChange = (value: string) => { if (value === CUSTOM_VALUE) { setIsCustom(true); return; } setIsCustom(false); setCustomValue(""); saveFontFamily(value === "default" ? "" : value); }; const handleCustomBlur = () => { const trimmed = customValue.trim(); if (trimmed) saveFontFamily(trimmed); }; const selectValue = isCustom ? CUSTOM_VALUE : userSettings.terminalFontFamily || "default"; return ( Terminal Font
{isCustom && ( setCustomValue(e.target.value)} onBlur={handleCustomBlur} onKeyDown={(e) => { if (e.key === "Enter") handleCustomBlur(); }} data-testid="terminal-font-custom-input" /> )}

Choose a monospace font for the terminal. Nerd Fonts include icons for CLI tools.

); } function BackendConnectionCard() { const [backendUrl] = useState(() => getBackendConfig().apiBaseUrl); const displayBackendUrl = backendUrl.replace(/^https?:\/\//, "").replace(/\/$/, ""); return ( Backend Server URL

Backend URL is provided at runtime for SSR and WebSocket connections.

); } export function GeneralSettings() { return (

General Settings

Manage your application preferences and notifications

} title="Appearance" description="Customize how the application looks" > } title="Terminal" description="Configure terminal appearance and behavior" > } title="Chat Input" description="Configure chat input behavior" > } title="Changes Panel" description="Customize how changed files are displayed" > } title="Keyboard Shortcuts" description="Customize keyboard shortcuts for the command panel" > } title="Backend Connection" description="Configure the backend server URL" >
); }