refactor(settings): redesign OpenCode settings with shared collapsible sections

- Replace bordered cards with compact flat rows and maintenance sections
- Add shared SettingsDisclosure for config, maintenance, and sandbox sections
- Auto-scroll expanded sections into view when outside the scrollport
- Make agent file editor and agent form full-height and keyboard-aware on mobile
This commit is contained in:
Chris Scott committed 2026-09-19 10:14:34 -04:00
1 parent 295d24ced7
commit 2a4fa956b4
18 files changed
+1013 -742

No files matched your search

@@ -170,7 +170,7 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent mobileFullscreen className="sm:max-w-2xl sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6">
<DialogContent mobileFullscreen keyboardAware className="sm:max-w-2xl sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6 pb-safe">
<DialogHeader className="p-4 sm:p-6 border-b flex flex-row items-center justify-between space-y-0">
<DialogTitle>{editingAgent ? 'Edit Agent' : 'Create Agent'}</DialogTitle>
</DialogHeader>
@@ -516,13 +516,13 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
</div>
<DialogFooter className="p-3 sm:p-4 border-t gap-2 pb-4">
<Button variant="outline" onClick={() => handleOpenChange(false)} className="flex-1 sm:flex-none">
<Button variant="outline" onClick={() => handleOpenChange(false)} className="h-11 flex-1 sm:h-9 sm:flex-none">
Cancel
</Button>
<Button
onClick={() => form.handleSubmit(handleSubmit)()}
disabled={!form.formState.isValid}
className="flex-1 sm:flex-none"
className="h-11 flex-1 sm:h-9 sm:flex-none"
>
{editingAgent ? 'Update' : 'Create'}
</Button>
@@ -128,28 +128,29 @@ export function AgentsMdEditor() {
</div>
</div>
<EditorFindBar
query={query}
onQueryChange={setQuery}
matchCount={matches.length}
currentMatch={hasMatches ? currentMatchIndex + 1 : 0}
onPrev={prev}
onNext={next}
inputName="agents-md-find"
placeholder="Find in AGENTS.md..."
className="rounded-t-md border-x border-t"
/>
<div className="h-[55vh] min-h-[300px] overflow-hidden rounded-b-md border border-input">
<CodeEditor
ariaLabel="AGENTS.md content"
value={content}
onChange={setContent}
highlights={matches}
activeHighlightIndex={currentMatchIndex}
disabled={isSaving}
placeholder="# Agent Instructions&#10;&#10;Add global instructions for AI agents here..."
<div className="overflow-hidden rounded-md border border-input">
<EditorFindBar
query={query}
onQueryChange={setQuery}
matchCount={matches.length}
currentMatch={hasMatches ? currentMatchIndex + 1 : 0}
onPrev={prev}
onNext={next}
inputName="agents-md-find"
placeholder="Find in AGENTS.md..."
/>
<div className="h-[60dvh] min-h-[320px] sm:h-[55vh]">
<CodeEditor
ariaLabel="AGENTS.md content"
value={content}
onChange={setContent}
highlights={matches}
activeHighlightIndex={currentMatchIndex}
disabled={isSaving}
placeholder="# Agent Instructions&#10;&#10;Add global instructions for AI agents here..."
/>
</div>
</div>
{hasChanges && (
@@ -66,43 +66,46 @@ export function DirectoryFilesList({ kind, files, titlePrefix = '' }: DirectoryF
return (
<>
{files.map((file) => (
<SettingsListRow
key={`file:${file.relativePath}`}
title={`${titlePrefix}${file.name}`}
description={`Uploaded file: ${file.relativePath}`}
badges={<Badge variant="secondary" className="shrink-0">File</Badge>}
onClick={() => setEditingFile(file)}
primaryAction={{ label: 'Edit', onClick: () => setEditingFile(file) }}
actions={[{ label: 'Delete', destructive: true, onClick: () => setDeletingFile(file) }]}
actionsLabel={`Actions for ${file.name}`}
/>
))}
{files.map((file) => {
const isNested = file.relativePath.includes('/')
return (
<SettingsListRow
key={`file:${file.relativePath}`}
title={<span title={file.relativePath}>{`${titlePrefix}${file.name}`}</span>}
description={isNested ? `Uploaded file: ${file.relativePath}` : undefined}
badges={<Badge variant="secondary" className="shrink-0">File</Badge>}
onClick={() => setEditingFile(file)}
primaryAction={{ label: 'Edit', onClick: () => setEditingFile(file) }}
actions={[{ label: 'Delete', destructive: true, onClick: () => setDeletingFile(file) }]}
actionsLabel={`Actions for ${file.name}`}
/>
)
})}
<Dialog open={!!editingFile} onOpenChange={(open) => !open && setEditingFile(null)}>
<DialogContent mobileFullscreen className="sm:max-w-2xl sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6 pb-safe">
<DialogContent mobileFullscreen keyboardAware className="sm:max-w-2xl sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6 pb-safe">
<DialogHeader className="p-4 sm:p-6 border-b">
<DialogTitle className="truncate">{editingFile?.relativePath}</DialogTitle>
<DialogTitle className="break-all pr-8">{editingFile?.relativePath}</DialogTitle>
</DialogHeader>
<div className="flex-1 overflow-y-auto p-2 sm:p-4">
<div className="flex min-h-0 flex-1 flex-col p-2 sm:p-4">
<Textarea
value={content}
onChange={(e) => setContent(e.target.value)}
disabled={isLoadingContent}
rows={18}
className="font-mono md:text-sm"
aria-label={editingFile?.relativePath ?? 'File content'}
className="h-full min-h-0 flex-1 field-sizing-fixed resize-none font-mono md:text-sm"
/>
</div>
<DialogFooter className="flex flex-row gap-2 pt-2 border-t border-border sm:justify-end pb-4 p-3">
<Button variant="outline" onClick={() => setEditingFile(null)} className="flex-1 sm:flex-none">
<Button variant="outline" onClick={() => setEditingFile(null)} className="h-11 flex-1 sm:h-9 sm:flex-none">
Cancel
</Button>
<Button
onClick={() => updateMutation.mutate()}
disabled={isLoadingContent || updateMutation.isPending}
className="flex-1 sm:flex-none"
className="h-11 flex-1 sm:h-9 sm:flex-none"
>
{updateMutation.isPending ? 'Saving...' : 'Save'}
</Button>
@@ -3,7 +3,8 @@ import { useManagerToken } from '@/hooks/useManagerToken'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Alert, AlertDescription } from '@/components/ui/alert'
import { AlertTriangle, Check, ChevronDown, Copy, Eye, EyeOff, RefreshCw } from 'lucide-react'
import { AlertTriangle, Check, Copy, Eye, EyeOff, RefreshCw } from 'lucide-react'
import { SettingsDisclosure } from './SettingsDisclosure'
interface ManagerTokenSettingsProps {
isOpen?: boolean
@@ -41,75 +42,65 @@ export function ManagerTokenSettings({ isOpen: controlledOpen, onToggle }: Manag
}
return (
<div className="rounded-lg border bg-card overflow-hidden">
<button
type="button"
onClick={handleToggle}
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors"
>
<div className="flex items-center gap-3 min-w-0">
<h3 className="text-sm font-semibold truncate">Manager Internal Token</h3>
<span className="text-xs text-muted-foreground truncate hidden sm:inline">
Bearer token for workspace plugin and API clients
</span>
<SettingsDisclosure
title="Manager Internal Token"
isOpen={isOpen}
onToggle={handleToggle}
contentClassName="space-y-3"
meta={
<span className="text-xs text-muted-foreground truncate hidden sm:inline">
Bearer token for workspace plugin and API clients
</span>
}
>
<div className="flex items-center gap-2">
<div className="relative flex-1">
<Input
id="manager-token"
type={showToken ? 'text' : 'password'}
value={isLoading ? 'Loading...' : token ?? ''}
readOnly
className="flex-1 font-mono text-xs pr-9"
autoComplete="new-password"
name="manager-token-input"
/>
<button
type="button"
onClick={() => setShowToken(!showToken)}
disabled={!token}
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
>
{showToken ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
<ChevronDown className={`h-4 w-4 transition-transform flex-shrink-0 ${isOpen ? 'rotate-90' : ''}`} />
</button>
<Button
variant="outline"
size="icon"
type="button"
onClick={handleCopy}
disabled={!token}
>
{copied ? <Check className="h-4 w-4 text-green-500" /> : <Copy className="h-4 w-4" />}
</Button>
<Button
variant={confirmRotate ? 'destructive' : 'outline'}
size="icon"
type="button"
onClick={handleRotate}
disabled={rotate.isPending || isLoading}
>
<RefreshCw className={`h-4 w-4 ${rotate.isPending ? 'animate-spin' : ''}`} />
</Button>
</div>
{isOpen && (
<div className="px-4 pb-4 pt-1 border-t border-border">
<div className="space-y-4">
<div className="flex gap-2 items-center pt-2">
<div className="relative flex-1">
<Input
id="manager-token"
type={showToken ? 'text' : 'password'}
value={isLoading ? 'Loading...' : token ?? ''}
readOnly
className="flex-1 font-mono text-xs pr-9"
autoComplete="new-password"
name="manager-token-input"
/>
<button
type="button"
onClick={() => setShowToken(!showToken)}
disabled={!token}
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
>
{showToken ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
<Button
variant="outline"
size="icon"
type="button"
onClick={handleCopy}
disabled={!token}
>
{copied ? <Check className="h-4 w-4 text-green-500" /> : <Copy className="h-4 w-4" />}
</Button>
<Button
variant={confirmRotate ? 'destructive' : 'outline'}
size="icon"
type="button"
onClick={handleRotate}
disabled={rotate.isPending || isLoading}
>
<RefreshCw className={`h-4 w-4 ${rotate.isPending ? 'animate-spin' : ''}`} />
</Button>
</div>
{confirmRotate && (
<Alert variant="destructive">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>
Rotating will invalidate the existing token. Any plugin or client using it must be updated. Click Rotate again to confirm.
</AlertDescription>
</Alert>
)}
</div>
</div>
{confirmRotate && (
<Alert variant="destructive">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>
Rotating will invalidate the existing token. Any plugin or client using it must be updated. Click Rotate again to confirm.
</AlertDescription>
</Alert>
)}
</div>
</SettingsDisclosure>
)
}
@@ -14,6 +14,7 @@ const {
mockGetOpenCodeImportStatus,
mockListManagedSkills,
mockListOpenCodeDirectoryFiles,
mockGetAgentsMd,
healthState,
} = vi.hoisted(() => ({
mockGetOpenCodeConfig: vi.fn(),
@@ -23,6 +24,7 @@ const {
mockGetOpenCodeImportStatus: vi.fn(),
mockListManagedSkills: vi.fn(),
mockListOpenCodeDirectoryFiles: vi.fn(),
mockGetAgentsMd: vi.fn(),
healthState: { data: { opencode: 'healthy', opencodeRestartPending: false } as Record<string, unknown> },
}))
@@ -43,6 +45,7 @@ vi.mock('@/api/settings', () => ({
getOpenCodeImportStatus: mockGetOpenCodeImportStatus,
listManagedSkills: mockListManagedSkills,
listOpenCodeDirectoryFiles: mockListOpenCodeDirectoryFiles,
getAgentsMd: mockGetAgentsMd,
syncOpenCodeImport: vi.fn(),
upgradeOpenCode: vi.fn(),
},
@@ -81,6 +84,7 @@ describe('OpenCodeConfigManager', () => {
healthState.data = { opencode: 'healthy', opencodeRestartPending: false }
mockGetOpenCodeConfig.mockResolvedValue(defaultConfig)
mockGetOpenCodeImportStatus.mockResolvedValue({})
mockGetAgentsMd.mockResolvedValue({ content: '# Agent Instructions' })
mockListManagedSkills.mockResolvedValue([])
mockListOpenCodeDirectoryFiles.mockImplementation((kind: 'agents' | 'commands') => {
if (kind === 'commands') return Promise.resolve([])
@@ -176,12 +180,58 @@ describe('OpenCodeConfigManager', () => {
expect(screen.queryByText('Restart OpenCode Server?')).not.toBeInTheDocument()
})
it('anchors the AGENTS.md card to the settings dialog scrollport', async () => {
it('keeps the AGENTS.md editor mounted while its disclosure toggles', async () => {
const user = userEvent.setup()
renderWithQuery(<OpenCodeConfigManager />)
const header = await screen.findByRole('button', { name: /Global Agent Instructions/i })
const card = header.parentElement
expect(card?.className).toContain('overflow-clip')
expect(card?.className).not.toContain('overflow-hidden')
expect(header).toHaveAttribute('aria-expanded', 'false')
const content = document.getElementById(header.getAttribute('aria-controls') ?? '')
expect(content).toHaveClass('hidden')
expect(await screen.findByLabelText('AGENTS.md content')).toBeInTheDocument()
const chevron = header.querySelector('.lucide-chevron-down')
expect(chevron).not.toHaveClass('rotate-180')
await user.click(header)
expect(header).toHaveAttribute('aria-expanded', 'true')
expect(content).toHaveClass('block')
expect(chevron).toHaveClass('rotate-180')
expect(chevron).not.toHaveClass('rotate-90')
expect(screen.getByLabelText('AGENTS.md content')).toBeInTheDocument()
await user.click(header)
expect(header).toHaveAttribute('aria-expanded', 'false')
expect(content).toHaveClass('hidden')
expect(screen.getByLabelText('AGENTS.md content')).toBeInTheDocument()
})
it('wires every disclosure header to a unique content id', async () => {
renderWithQuery(<OpenCodeConfigManager />)
await screen.findByText('opencode.json')
const headers = screen.getAllByRole('button').filter(
(button) => button.hasAttribute('aria-controls') && !button.hasAttribute('aria-haspopup'),
)
expect(headers).toHaveLength(7)
headers.forEach((header) => expect(header).toHaveAttribute('aria-expanded'))
const contentIds = headers.map((header) => header.getAttribute('aria-controls') ?? '')
expect(new Set(contentIds).size).toBe(7)
contentIds.forEach((id) => expect(document.getElementById(id)).toBeInTheDocument())
})
it('labels the config file actions and exposes its metadata', async () => {
renderWithQuery(<OpenCodeConfigManager />)
expect(await screen.findByText('opencode.json')).toBeInTheDocument()
const editButton = screen.getAllByRole('button', { name: 'Edit' }).find((button) => button.querySelector('.lucide-square-pen'))
expect(editButton).toBeDefined()
expect(screen.getByRole('button', { name: 'Download' })).toBeInTheDocument()
expect(screen.getByText('File location and updated time')).toBeInTheDocument()
expect(screen.getByText('/workspace/.opencode/opencode.json')).toBeInTheDocument()
expect(screen.getByText(`Updated: ${new Date(defaultConfig.updatedAt).toLocaleString()}`)).toBeInTheDocument()
})
it('keeps the editor mounted while the post-save config refresh is in flight', async () => {
@@ -316,7 +366,7 @@ describe('OpenCodeConfigManager', () => {
await waitFor(() => expect(screen.queryByText('Edit opencode.json')).not.toBeInTheDocument())
})
it('renders host import collapsed after the configuration card until expanded', async () => {
it('renders host import collapsed after the configuration file until expanded', async () => {
const user = userEvent.setup()
renderWithQuery(<OpenCodeConfigManager />)
@@ -325,8 +375,8 @@ describe('OpenCodeConfigManager', () => {
const importContent = document.getElementById(importToggle.getAttribute('aria-controls') ?? '')
expect(importContent).toHaveClass('hidden')
const configTitle = screen.getByText('OpenCode Configuration')
expect(configTitle.compareDocumentPosition(importToggle) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
const configFileName = await screen.findByText('opencode.json')
expect(configFileName.compareDocumentPosition(importToggle) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
await user.click(importToggle)
expect(importToggle).toHaveAttribute('aria-expanded', 'true')
@@ -334,7 +384,7 @@ describe('OpenCodeConfigManager', () => {
expect(await screen.findByRole('button', { name: /Import From Host/i })).toBeInTheDocument()
})
it('shows the config file path and an invalid badge when the file is invalid', async () => {
it('shows the config file name and an invalid badge when the file is invalid', async () => {
mockGetOpenCodeConfig.mockResolvedValue({
...defaultConfig,
isValid: false,
@@ -343,7 +393,8 @@ describe('OpenCodeConfigManager', () => {
renderWithQuery(<OpenCodeConfigManager />)
expect(await screen.findByText('/workspace/.opencode/opencode.json')).toBeInTheDocument()
expect(await screen.findByText('opencode.json')).toBeInTheDocument()
expect(screen.getByText('/workspace/.opencode/opencode.json')).toBeInTheDocument()
expect(screen.getByText('Invalid Config')).toBeInTheDocument()
expect(screen.getByText('model')).toBeInTheDocument()
})
@@ -2,9 +2,7 @@ import { useState, useRef, useId } from 'react'
import { cn } from '@/lib/utils'
import { Loader2, Edit, Download, RotateCcw, FileText, ChevronDown, AlertTriangle } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
import { RestartServerDialog } from './RestartServerDialog'
import { OpenCodeConfigEditor } from './OpenCodeConfigEditor'
import { CommandsEditor } from './CommandsEditor'
@@ -13,6 +11,7 @@ import { AgentsMdEditor } from './AgentsMdEditor'
import { McpManager } from './McpManager'
import { SkillsEditor } from './SkillsEditor'
import { OpenCodeModelsEditor, type ConfigProvider } from './OpenCodeModelsEditor'
import { scrollSectionIntoView } from '@/lib/settingsScroll'
import { VersionSelectDialog } from './VersionSelectDialog'
import { settingsApi } from '@/api/settings'
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
@@ -54,13 +53,30 @@ interface Agent {
[key: string]: unknown
}
const EXPANDED_SECTION_CONTENT_CLASS = 'p-2 sm:p-4'
type ConfigSectionKey = 'agentsMd' | 'commands' | 'agents' | 'skills' | 'mcp' | 'models' | 'hostImport'
const SECTION_LIST_CLASS = 'divide-y divide-border/60 border-t border-border/60'
const SECTION_HEADER_CLASS = 'flex w-full min-w-0 items-center justify-between gap-3 py-3 text-left transition-colors hover:bg-muted/40 focus-visible:outline-2 focus-visible:outline-ring focus-visible:outline-offset-2'
const SECTION_CONTENT_CLASS = 'pb-4'
const SECTION_CHEVRON_CLASS = 'h-4 w-4 shrink-0 transition-transform'
const SECTION_TITLE_CLASS = 'text-sm font-medium truncate'
const SECTION_META_CLASS = 'text-xs text-muted-foreground'
const getConfigFileName = (path: string) => path.split(/[\\/]/).filter(Boolean).pop() ?? path
export function OpenCodeConfigManager() {
const hostImportContentId = useId()
const sectionIdPrefix = useId()
const agentsMdContentId = `${sectionIdPrefix}-agents-md`
const commandsContentId = `${sectionIdPrefix}-commands`
const agentsContentId = `${sectionIdPrefix}-agents`
const skillsContentId = `${sectionIdPrefix}-skills`
const mcpContentId = `${sectionIdPrefix}-mcp`
const modelsContentId = `${sectionIdPrefix}-models`
const hostImportContentId = `${sectionIdPrefix}-host-import`
const queryClient = useQueryClient()
const { data: health } = useServerHealth()
const [expandedSections, setExpandedSections] = useState<Record<string, boolean>>({
const [expandedSections, setExpandedSections] = useState<Record<ConfigSectionKey, boolean>>({
agentsMd: false,
commands: false,
agents: false,
@@ -86,6 +102,7 @@ export function OpenCodeConfigManager() {
const skillsRef = useRef<HTMLButtonElement>(null)
const mcpRef = useRef<HTMLButtonElement>(null)
const modelsRef = useRef<HTMLButtonElement>(null)
const hostImportRef = useRef<HTMLButtonElement>(null)
const { data: config, isLoading } = useOpenCodeConfigFile()
@@ -113,13 +130,11 @@ export function OpenCodeConfigManager() {
staleTime: 30 * 1000,
})
const scrollToSection = (ref: React.RefObject<HTMLButtonElement | null>) => {
if (ref.current) {
ref.current.scrollIntoView({
behavior: 'smooth',
block: 'nearest',
inline: 'nearest'
})
const toggleSection = (section: ConfigSectionKey, ref?: React.RefObject<HTMLButtonElement | null>) => {
const isExpanding = !expandedSections[section]
setExpandedSections(prev => ({ ...prev, [section]: !prev[section] }))
if (isExpanding) {
setTimeout(() => scrollSectionIntoView(ref?.current ?? null), 0)
}
}
@@ -185,7 +200,7 @@ export function OpenCodeConfigManager() {
const canImportFromHost = Boolean(importStatus?.configSourcePath || importStatus?.stateSourcePath)
return (
<div className="space-y-6 min-w-0">
<div className="min-w-0 space-y-4">
{health?.opencodeRestartPending && (
<div className="flex flex-col gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3 sm:flex-row sm:items-center sm:justify-between">
<div className="flex items-center gap-2">
@@ -216,80 +231,69 @@ export function OpenCodeConfigManager() {
/>
{!config ? (
<Card>
<CardContent className="p-8 text-center">
<p className="text-muted-foreground">No OpenCode configuration file found. Restart the Manager to seed one.</p>
</CardContent>
</Card>
<p className="py-8 text-center text-sm text-muted-foreground">
No OpenCode configuration file found. Restart the Manager to seed one.
</p>
) : (
<>
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm sm:text-base">OpenCode Configuration</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex flex-col gap-2 sm:flex-row sm:items-center">
<div className="min-w-0">
<p className="truncate text-sm font-medium">{config.path}</p>
<p className="truncate text-sm text-muted-foreground">Updated: {new Date(config.updatedAt).toLocaleString()}</p>
</div>
{!config.isValid && (
<Badge variant="destructive">Invalid Config</Badge>
)}
<TooltipProvider delayDuration={200}>
<div className="flex items-center gap-1 sm:gap-1.5 sm:ml-auto">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="sm"
onClick={() => downloadConfig(config)}
>
<Download className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom">Download</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="sm"
onClick={() => setIsEditDialogOpen(true)}
>
<Edit className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent side="bottom">Edit</TooltipContent>
</Tooltip>
</div>
</TooltipProvider>
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div className="flex min-w-0 items-start gap-2">
<FileText className="mt-0.5 h-4 w-4 shrink-0 text-blue-500" />
<div className="min-w-0">
<p className="truncate text-sm font-medium">{getConfigFileName(config.path)}</p>
<details className="text-xs text-muted-foreground">
<summary className="cursor-pointer select-none">File location and updated time</summary>
<p className="mt-1 break-all">{config.path}</p>
<p className="mt-1">Updated: {new Date(config.updatedAt).toLocaleString()}</p>
</details>
</div>
</div>
{!config.isValid && config.validationIssues && config.validationIssues.length > 0 && (
<div className="rounded-lg border border-destructive/40 bg-destructive/5 p-4">
<p className="font-medium text-destructive">This configuration has validation issues</p>
<p className="mt-1 text-sm text-destructive/90">
OpenCode may fail to start until these fields are corrected. Open the config editor to fix the file directly.
</p>
<ul className="mt-3 list-disc space-y-1 pl-5 text-sm text-destructive/90">
{config.validationIssues.slice(0, 8).map((issue) => (
<li key={`${issue.path}-${issue.message}`}>
<span className="font-mono text-xs">{issue.path}</span>: {issue.message}
</li>
))}
</ul>
{config.validationIssues.length > 8 && (
<p className="mt-2 text-xs text-destructive/80">
Showing 8 of {config.validationIssues.length} issues. Open the config editor to review and fix the file.
</p>
)}
</div>
<div className="flex flex-wrap items-center gap-2">
{!config.isValid && (
<Badge variant="destructive">Invalid Config</Badge>
)}
</CardContent>
</Card>
<Button
variant="ghost"
size="sm"
className="h-11 sm:h-8"
onClick={() => setIsEditDialogOpen(true)}
>
<Edit className="h-3.5 w-3.5 mr-1" />
Edit
</Button>
<Button
variant="ghost"
size="sm"
className="h-11 sm:h-8"
onClick={() => downloadConfig(config)}
>
<Download className="h-3.5 w-3.5 mr-1" />
Download
</Button>
</div>
</div>
{!config.isValid && config.validationIssues && config.validationIssues.length > 0 && (
<div className="rounded-lg border border-destructive/40 bg-destructive/5 p-4">
<p className="font-medium text-destructive">This configuration has validation issues</p>
<p className="mt-1 text-sm text-destructive/90">
OpenCode may fail to start until these fields are corrected. Open the config editor to fix the file directly.
</p>
<ul className="mt-3 list-disc space-y-1 pl-5 text-sm text-destructive/90">
{config.validationIssues.slice(0, 8).map((issue) => (
<li key={`${issue.path}-${issue.message}`}>
<span className="font-mono text-xs">{issue.path}</span>: {issue.message}
</li>
))}
</ul>
{config.validationIssues.length > 8 && (
<p className="mt-2 text-xs text-destructive/80">
Showing 8 of {config.validationIssues.length} issues. Open the config editor to review and fix the file.
</p>
)}
</div>
)}
<OpenCodeConfigEditor
config={config}
@@ -303,238 +307,222 @@ export function OpenCodeConfigManager() {
</>
)}
<div className="mt-8 space-y-6">
<div className="border-t border-border pt-6">
<div className="bg-card border border-border rounded-lg overflow-clip min-w-0 mb-6">
<button
ref={agentsMdRef}
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.agentsMd ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
onClick={() => {
const isExpanding = !expandedSections.agentsMd
setExpandedSections(prev => ({ ...prev, agentsMd: isExpanding }))
if (isExpanding) {
setTimeout(() => scrollToSection(agentsMdRef), 100)
}
}}
>
<div className="flex items-center gap-3 min-w-0">
<FileText className="h-4 w-4 text-blue-500" />
<h4 className="text-sm font-medium truncate">Global Agent Instructions (AGENTS.md)</h4>
</div>
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.agentsMd ? 'rotate-90' : ''}`} />
</button>
<div className={`${expandedSections.agentsMd ? 'block' : 'hidden'} border-t border-border`}>
<div className="p-4">
<AgentsMdEditor />
</div>
</div>
<div className={cn('mt-6', SECTION_LIST_CLASS)}>
<div>
<button
ref={agentsMdRef}
type="button"
aria-expanded={expandedSections.agentsMd}
aria-controls={agentsMdContentId}
className={cn(SECTION_HEADER_CLASS, 'flex-wrap sm:flex-nowrap')}
onClick={() => toggleSection('agentsMd', agentsMdRef)}
>
<div className="flex min-w-0 items-center gap-3">
<FileText className="h-4 w-4 shrink-0 text-blue-500" />
<div className="min-w-0 text-left">
<h4 className="text-sm font-medium">Global Agent Instructions (AGENTS.md)</h4>
<p className={SECTION_META_CLASS}>Applies across OpenCode</p>
</div>
<h3 className="text-base sm:text-lg font-semibold mb-4">Configure Commands, Agents & MCP Servers</h3>
<p className="text-sm text-muted-foreground mb-6">
Add custom commands, agents, and MCP servers to your OpenCode configuration.
</p>
{config && (
<div className="space-y-6">
<div className="flex flex-col gap-4 pb-4 min-w-0">
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
<button
ref={commandsRef}
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.commands ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
onClick={() => {
const isExpanding = !expandedSections.commands
setExpandedSections(prev => ({ ...prev, commands: isExpanding }))
if (isExpanding) {
setTimeout(() => scrollToSection(commandsRef), 100)
}
}}
>
<div className="flex items-center gap-3 min-w-0">
<h4 className="text-sm font-medium truncate">Commands</h4>
<span className="text-xs text-muted-foreground">
{Object.keys((config.content.command as Record<string, Command> | undefined) ?? {}).length + directoryCommands.length} configured
</span>
</div>
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.commands ? 'rotate-90' : ''}`} />
</button>
<div className={`${expandedSections.commands ? 'block' : 'hidden'} border-t border-border`}>
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
<CommandsEditor
commands={(config.content.command as Record<string, Command> | undefined) ?? {}}
directoryCommands={directoryCommands}
onChange={(commands) => {
updateConfigContent({
...config.content,
command: commands
})
}}
/>
</div>
</div>
</div>
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
<button
ref={agentsRef}
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.agents ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
onClick={() => {
const isExpanding = !expandedSections.agents
setExpandedSections(prev => ({ ...prev, agents: isExpanding }))
if (isExpanding) {
setTimeout(() => scrollToSection(agentsRef), 100)
}
}}
>
<div className="flex items-center gap-3 min-w-0">
<h4 className="text-sm font-medium truncate">Agents</h4>
<span className="text-xs text-muted-foreground">
{Object.keys((config.content.agent as Record<string, Agent> | undefined) ?? {}).length + directoryAgents.length} configured
</span>
</div>
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.agents ? 'rotate-90' : ''}`} />
</button>
<div className={`${expandedSections.agents ? 'block' : 'hidden'} border-t border-border`}>
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
<AgentsEditor
agents={(config.content.agent as Record<string, Agent> | undefined) ?? {}}
directoryAgents={directoryAgents}
onChange={(agents) => {
updateConfigContent({
...config.content,
agent: agents
})
}}
/>
</div>
</div>
</div>
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
<button
ref={skillsRef}
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.skills ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
onClick={() => {
const isExpanding = !expandedSections.skills
setExpandedSections(prev => ({ ...prev, skills: isExpanding }))
if (isExpanding) {
setTimeout(() => scrollToSection(skillsRef), 100)
}
}}
>
<div className="flex items-center gap-3 min-w-0">
<h4 className="text-sm font-medium truncate">Skills</h4>
<span className="text-xs text-muted-foreground">
{managedSkills.length} configured
</span>
</div>
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.skills ? 'rotate-90' : ''}`} />
</button>
<div className={`${expandedSections.skills ? 'block' : 'hidden'} border-t border-border`}>
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
<SkillsEditor
managedSkills={managedSkills}
/>
</div>
</div>
</div>
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
<button
ref={mcpRef}
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.mcp ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
onClick={() => {
const isExpanding = !expandedSections.mcp
setExpandedSections(prev => ({ ...prev, mcp: isExpanding }))
if (isExpanding) {
setTimeout(() => scrollToSection(mcpRef), 100)
}
}}
>
<div className="flex items-center gap-3 min-w-0">
<h4 className="text-sm font-medium truncate">MCP Servers</h4>
<span className="text-xs text-muted-foreground">
{Object.keys((config.content.mcp as Record<string, unknown> | undefined) ?? {}).length} configured
</span>
</div>
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.mcp ? 'rotate-90' : ''}`} />
</button>
<div className={`${expandedSections.mcp ? 'block' : 'hidden'} border-t border-border`}>
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
<McpManager
config={config}
onUpdate={updateConfigContent}
/>
</div>
</div>
</div>
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
<button
ref={modelsRef}
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.models ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
onClick={() => {
const isExpanding = !expandedSections.models
setExpandedSections(prev => ({ ...prev, models: isExpanding }))
if (isExpanding) {
setTimeout(() => scrollToSection(modelsRef), 100)
}
}}
>
<div className="flex items-center gap-3 min-w-0">
<h4 className="text-sm font-medium truncate">Models</h4>
<span className="text-xs text-muted-foreground">
{(() => {
const provider = config.content.provider as Record<string, unknown> | undefined
if (!provider) return 0
return Object.values(provider).reduce<number>((acc, p) => {
const models = (p as { models?: Record<string, unknown> })?.models
return acc + (models ? Object.keys(models).length : 0)
}, 0)
})()} configured
</span>
</div>
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.models ? 'rotate-90' : ''}`} />
</button>
<div className={`${expandedSections.models ? 'block' : 'hidden'} border-t border-border`}>
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
<OpenCodeModelsEditor
providers={(config.content.provider as Record<string, ConfigProvider> | undefined) ?? {}}
onChange={(providers) => {
updateConfigContent({
...config.content,
provider: providers
})
}}
/>
</div>
</div>
</div>
</div>
</div>
)}
</div>
<div className="flex shrink-0 items-center gap-3">
<span className="text-xs font-medium text-blue-500">Edit AGENTS.md</span>
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.agentsMd && 'rotate-180')} />
</div>
</button>
<div
id={agentsMdContentId}
className={cn(SECTION_CONTENT_CLASS, expandedSections.agentsMd ? 'block' : 'hidden')}
>
<AgentsMdEditor />
</div>
</div>
<div className="bg-card border border-border rounded-lg overflow-hidden min-w-0">
<button
className={cn("w-full px-4 py-3 flex items-center justify-between transition-colors min-w-0", expandedSections.hostImport ? "bg-muted/40 hover:bg-muted/50" : "hover:bg-muted/50")}
aria-expanded={expandedSections.hostImport}
aria-controls={hostImportContentId}
onClick={() => setExpandedSections(prev => ({ ...prev, hostImport: !prev.hostImport }))}
>
<div className="flex items-center gap-3 min-w-0">
<Download className="h-4 w-4 text-blue-500" />
<h4 className="text-sm font-medium truncate">Existing OpenCode Host Import</h4>
</div>
<ChevronDown className={`h-4 w-4 transition-transform ${expandedSections.hostImport ? 'rotate-90' : ''}`} />
</button>
<div id={hostImportContentId} className={`${expandedSections.hostImport ? 'block' : 'hidden'} border-t border-border`}>
<div className={cn(EXPANDED_SECTION_CONTENT_CLASS, 'space-y-3 text-sm')}>
{config && (
<>
<div>
<button
ref={commandsRef}
type="button"
aria-expanded={expandedSections.commands}
aria-controls={commandsContentId}
className={SECTION_HEADER_CLASS}
onClick={() => toggleSection('commands', commandsRef)}
>
<div className="flex min-w-0 items-center gap-3">
<h4 className={SECTION_TITLE_CLASS}>Commands</h4>
<span className={SECTION_META_CLASS}>
{Object.keys((config.content.command as Record<string, Command> | undefined) ?? {}).length + directoryCommands.length} configured
</span>
</div>
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.commands && 'rotate-180')} />
</button>
<div
id={commandsContentId}
className={cn(SECTION_CONTENT_CLASS, expandedSections.commands ? 'block' : 'hidden')}
>
<CommandsEditor
commands={(config.content.command as Record<string, Command> | undefined) ?? {}}
directoryCommands={directoryCommands}
onChange={(commands) => {
updateConfigContent({
...config.content,
command: commands
})
}}
/>
</div>
</div>
<div>
<button
ref={agentsRef}
type="button"
aria-expanded={expandedSections.agents}
aria-controls={agentsContentId}
className={SECTION_HEADER_CLASS}
onClick={() => toggleSection('agents', agentsRef)}
>
<div className="flex min-w-0 items-center gap-3">
<h4 className={SECTION_TITLE_CLASS}>Agents</h4>
<span className={SECTION_META_CLASS}>
{Object.keys((config.content.agent as Record<string, Agent> | undefined) ?? {}).length + directoryAgents.length} configured
</span>
</div>
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.agents && 'rotate-180')} />
</button>
<div
id={agentsContentId}
className={cn(SECTION_CONTENT_CLASS, expandedSections.agents ? 'block' : 'hidden')}
>
<AgentsEditor
agents={(config.content.agent as Record<string, Agent> | undefined) ?? {}}
directoryAgents={directoryAgents}
onChange={(agents) => {
updateConfigContent({
...config.content,
agent: agents
})
}}
/>
</div>
</div>
<div>
<button
ref={skillsRef}
type="button"
aria-expanded={expandedSections.skills}
aria-controls={skillsContentId}
className={SECTION_HEADER_CLASS}
onClick={() => toggleSection('skills', skillsRef)}
>
<div className="flex min-w-0 items-center gap-3">
<h4 className={SECTION_TITLE_CLASS}>Skills</h4>
<span className={SECTION_META_CLASS}>
{managedSkills.length} configured
</span>
</div>
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.skills && 'rotate-180')} />
</button>
<div
id={skillsContentId}
className={cn(SECTION_CONTENT_CLASS, expandedSections.skills ? 'block' : 'hidden')}
>
<SkillsEditor
managedSkills={managedSkills}
/>
</div>
</div>
<div>
<button
ref={mcpRef}
type="button"
aria-expanded={expandedSections.mcp}
aria-controls={mcpContentId}
className={SECTION_HEADER_CLASS}
onClick={() => toggleSection('mcp', mcpRef)}
>
<div className="flex min-w-0 items-center gap-3">
<h4 className={SECTION_TITLE_CLASS}>MCP Servers</h4>
<span className={SECTION_META_CLASS}>
{Object.keys((config.content.mcp as Record<string, unknown> | undefined) ?? {}).length} configured
</span>
</div>
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.mcp && 'rotate-180')} />
</button>
<div
id={mcpContentId}
className={cn(SECTION_CONTENT_CLASS, expandedSections.mcp ? 'block' : 'hidden')}
>
<McpManager
config={config}
onUpdate={updateConfigContent}
/>
</div>
</div>
<div>
<button
ref={modelsRef}
type="button"
aria-expanded={expandedSections.models}
aria-controls={modelsContentId}
className={SECTION_HEADER_CLASS}
onClick={() => toggleSection('models', modelsRef)}
>
<div className="flex min-w-0 items-center gap-3">
<h4 className={SECTION_TITLE_CLASS}>Models</h4>
<span className={SECTION_META_CLASS}>
{(() => {
const provider = config.content.provider as Record<string, unknown> | undefined
if (!provider) return 0
return Object.values(provider).reduce<number>((acc, p) => {
const models = (p as { models?: Record<string, unknown> })?.models
return acc + (models ? Object.keys(models).length : 0)
}, 0)
})()} configured
</span>
</div>
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.models && 'rotate-180')} />
</button>
<div
id={modelsContentId}
className={cn(SECTION_CONTENT_CLASS, expandedSections.models ? 'block' : 'hidden')}
>
<OpenCodeModelsEditor
providers={(config.content.provider as Record<string, ConfigProvider> | undefined) ?? {}}
onChange={(providers) => {
updateConfigContent({
...config.content,
provider: providers
})
}}
/>
</div>
</div>
</>
)}
<div>
<button
ref={hostImportRef}
type="button"
aria-expanded={expandedSections.hostImport}
aria-controls={hostImportContentId}
className={SECTION_HEADER_CLASS}
onClick={() => toggleSection('hostImport', hostImportRef)}
>
<div className="flex min-w-0 items-center gap-3">
<Download className="h-4 w-4 shrink-0 text-blue-500" />
<h4 className={SECTION_TITLE_CLASS}>Existing OpenCode Host Import</h4>
</div>
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.hostImport && 'rotate-180')} />
</button>
<div
id={hostImportContentId}
className={cn(SECTION_CONTENT_CLASS, 'space-y-3 text-sm', expandedSections.hostImport ? 'block' : 'hidden')}
>
<p className="text-muted-foreground">
Import your standalone OpenCode config and session state into this workspace, then restart the server so existing chats can reconnect.
</p>
@@ -3,7 +3,8 @@ import { useOpenCodeServerAuth } from '@/hooks/useOpenCodeServerAuth'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Alert, AlertDescription } from '@/components/ui/alert'
import { AlertTriangle, CheckCircle2, ChevronDown, Eye, EyeOff, XCircle } from 'lucide-react'
import { AlertTriangle, CheckCircle2, Eye, EyeOff, XCircle } from 'lucide-react'
import { SettingsDisclosure } from './SettingsDisclosure'
interface OpenCodeServerAuthSettingsProps {
isOpen?: boolean
@@ -41,76 +42,66 @@ export function OpenCodeServerAuthSettings({ isOpen: controlledOpen, onToggle }:
}
return (
<div className="rounded-lg border bg-card overflow-hidden">
<button
type="button"
onClick={handleToggle}
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors"
>
<div className="flex items-center gap-2">
<h3 className="text-sm font-semibold">OpenCode Server Authentication</h3>
<span className="text-xs text-muted-foreground flex items-center gap-1">
{getStatusIcon()}
{getStatusText()}
</span>
</div>
<ChevronDown className={`h-4 w-4 transition-transform ${isOpen ? 'rotate-90' : ''}`} />
</button>
{isOpen && (
<div className="px-4 pb-4 pt-1 border-t border-border">
<div className="space-y-4">
{status?.source === 'none' && (
<Alert variant="destructive">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>
If you set OPENCODE_HOST=0.0.0.0 in Docker without a password, the server will refuse to start.
</AlertDescription>
</Alert>
)}
<div className="flex gap-2 items-center pt-2">
<div className="relative flex-1">
<Input
id="password"
type={showPassword ? 'text' : 'password'}
value={password}
onChange={(e) => setPasswordValue(e.target.value)}
placeholder="Enter new password"
className="pr-9"
autoComplete="new-password"
name="opencode-server-password"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
>
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
<Button
onClick={handleSave}
disabled={password.length < 8 || setPassword.isPending}
>
{setPassword.isPending ? 'Saving...' : 'Save'}
</Button>
</div>
{password.length > 0 && password.length < 8 && (
<p className="text-xs text-destructive">Password must be at least 8 characters</p>
)}
{status?.source === 'db' && (
<Button
variant="outline"
onClick={() => clearPassword.mutate()}
disabled={clearPassword.isPending}
>
{clearPassword.isPending ? 'Clearing...' : 'Clear stored password'}
</Button>
)}
</div>
</div>
<SettingsDisclosure
title="OpenCode Server Authentication"
isOpen={isOpen}
onToggle={handleToggle}
contentClassName="space-y-3"
meta={
<span className="text-xs text-muted-foreground flex items-center gap-1">
{getStatusIcon()}
{getStatusText()}
</span>
}
>
{status?.source === 'none' && (
<Alert variant="destructive">
<AlertTriangle className="h-4 w-4" />
<AlertDescription>
If you set OPENCODE_HOST=0.0.0.0 in Docker without a password, the server will refuse to start.
</AlertDescription>
</Alert>
)}
</div>
<div className="flex items-center gap-2">
<div className="relative flex-1">
<Input
id="password"
type={showPassword ? 'text' : 'password'}
value={password}
onChange={(e) => setPasswordValue(e.target.value)}
placeholder="Enter new password"
className="pr-9"
autoComplete="new-password"
name="opencode-server-password"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"
>
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
<Button
onClick={handleSave}
disabled={password.length < 8 || setPassword.isPending}
>
{setPassword.isPending ? 'Saving...' : 'Save'}
</Button>
</div>
{password.length > 0 && password.length < 8 && (
<p className="text-xs text-destructive">Password must be at least 8 characters</p>
)}
{status?.source === 'db' && (
<Button
variant="outline"
onClick={() => clearPassword.mutate()}
disabled={clearPassword.isPending}
>
{clearPassword.isPending ? 'Clearing...' : 'Clear stored password'}
</Button>
)}
</SettingsDisclosure>
)
}
@@ -41,26 +41,51 @@ function mockHealth(sandbox?: { available: boolean; enforced: boolean; reason?:
} as ReturnType<typeof useServerHealth>)
}
async function renderSandbox() {
const user = userEvent.setup()
render(<SandboxSettings />)
await user.click(screen.getByRole('button', { name: /^Sandbox/ }))
return user
}
describe('SandboxSettings', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('reflects the persisted sandbox preference', () => {
it('keeps the controls collapsed until the disclosure is expanded', async () => {
mockUseSettings()
mockHealth({ available: true, enforced: false })
const user = userEvent.setup()
render(<SandboxSettings />)
const header = screen.getByRole('button', { name: /^Sandbox/ })
expect(header).toHaveAttribute('aria-expanded', 'false')
const content = document.getElementById(header.getAttribute('aria-controls') ?? '')
expect(content).toHaveClass('hidden')
await user.click(header)
expect(header).toHaveAttribute('aria-expanded', 'true')
expect(content).toHaveClass('block')
expect(screen.getByRole('switch', { name: 'Toggle sandbox' })).toBeInTheDocument()
})
it('reflects the persisted sandbox preference', async () => {
mockUseSettings({ preferences: { sandbox: { enabled: true } } })
mockHealth({ available: true, enforced: false })
render(<SandboxSettings />)
await renderSandbox()
expect(screen.getByRole('switch', { name: 'Toggle sandbox' })).toBeChecked()
})
it('writes only the sandbox preference when toggled and shows the restart notice', async () => {
const user = userEvent.setup()
const { updateSettingsAsync } = mockUseSettings()
mockHealth({ available: true, enforced: false }, true)
render(<SandboxSettings />)
const user = await renderSandbox()
await user.click(screen.getByRole('switch', { name: 'Toggle sandbox' }))
@@ -68,22 +93,21 @@ describe('SandboxSettings', () => {
expect(screen.getByText('Restart the OpenCode server to apply sandbox changes.')).toBeInTheDocument()
})
it('disables the switch with a visible reason when microVMs are unavailable', () => {
it('disables the switch with a visible reason when microVMs are unavailable', async () => {
mockUseSettings()
mockHealth({ available: false, enforced: false, reason: 'KVM is not available on this host' })
render(<SandboxSettings />)
await renderSandbox()
expect(screen.getByRole('switch', { name: 'Toggle sandbox' })).toBeDisabled()
expect(screen.getByText('KVM is not available on this host')).toBeInTheDocument()
})
it('still allows disabling an already-enabled preference when microVMs become unavailable', async () => {
const user = userEvent.setup()
const { updateSettingsAsync } = mockUseSettings({ preferences: { sandbox: { enabled: true } } })
mockHealth({ available: false, enforced: false, reason: 'KVM is not available on this host' })
render(<SandboxSettings />)
const user = await renderSandbox()
const toggle = screen.getByRole('switch', { name: 'Toggle sandbox' })
expect(toggle).toBeChecked()
@@ -95,7 +119,7 @@ describe('SandboxSettings', () => {
expect(updateSettingsAsync).toHaveBeenCalledWith({ sandbox: { enabled: false, gitCredentials: false } })
})
it('disables the switch while sandbox availability has not been reported', () => {
it('disables the switch while sandbox availability has not been reported', async () => {
mockUseSettings()
vi.mocked(useServerHealth).mockReturnValue({
data: undefined,
@@ -106,7 +130,7 @@ describe('SandboxSettings', () => {
rollbackMutation: { mutate: vi.fn(), mutateAsync: vi.fn(), isPending: false },
} as ReturnType<typeof useServerHealth>)
render(<SandboxSettings />)
await renderSandbox()
expect(screen.getByRole('switch', { name: 'Toggle sandbox' })).toBeDisabled()
expect(screen.getByText('Checking sandbox availability...')).toBeInTheDocument()
@@ -122,11 +146,10 @@ describe('SandboxSettings', () => {
})
it('shows an error toast when saving the preference fails', async () => {
const user = userEvent.setup()
mockUseSettings({ updateSettingsAsync: vi.fn().mockRejectedValue(new Error('failed')) })
mockHealth({ available: true, enforced: false })
render(<SandboxSettings />)
const user = await renderSandbox()
await user.click(screen.getByRole('switch', { name: 'Toggle sandbox' }))
@@ -134,7 +157,6 @@ describe('SandboxSettings', () => {
})
it('shows the backend error when enabling sandboxing is rejected', async () => {
const user = userEvent.setup()
mockUseSettings({
updateSettingsAsync: vi.fn().mockRejectedValue(
new FetchError('Cannot enable sandboxing: process identity attestation is unavailable', 400),
@@ -142,7 +164,7 @@ describe('SandboxSettings', () => {
})
mockHealth({ available: true, enforced: false })
render(<SandboxSettings />)
const user = await renderSandbox()
await user.click(screen.getByRole('switch', { name: 'Toggle sandbox' }))
@@ -152,13 +174,12 @@ describe('SandboxSettings', () => {
})
it('preserves the git credential preference when the sandbox toggle changes', async () => {
const user = userEvent.setup()
const { updateSettingsAsync } = mockUseSettings({
preferences: { sandbox: { enabled: false, gitCredentials: true } },
})
mockHealth({ available: true, enforced: false })
render(<SandboxSettings />)
const user = await renderSandbox()
await user.click(screen.getByRole('switch', { name: 'Toggle sandbox' }))
@@ -166,22 +187,21 @@ describe('SandboxSettings', () => {
})
it('enables git credential forwarding without changing the sandbox preference', async () => {
const user = userEvent.setup()
const { updateSettingsAsync } = mockUseSettings({ preferences: { sandbox: { enabled: true } } })
mockHealth({ available: true, enforced: false })
render(<SandboxSettings />)
const user = await renderSandbox()
await user.click(screen.getByRole('switch', { name: 'Toggle git credentials in sandbox' }))
expect(updateSettingsAsync).toHaveBeenCalledWith({ sandbox: { enabled: true, gitCredentials: true } })
})
it('disables the git credential switch while sandboxing is off', () => {
it('disables the git credential switch while sandboxing is off', async () => {
mockUseSettings()
mockHealth({ available: true, enforced: false })
render(<SandboxSettings />)
await renderSandbox()
expect(screen.getByRole('switch', { name: 'Toggle git credentials in sandbox' })).toBeDisabled()
})
@@ -6,6 +6,7 @@ import { Badge } from '@/components/ui/badge'
import { Box, RotateCcw } from 'lucide-react'
import { showToast } from '@/lib/toast'
import { FetchError } from '@/api/fetchWrapper'
import { SettingsDisclosure } from './SettingsDisclosure'
export function SandboxSettings() {
const { preferences, updateSettingsAsync, isUpdating } = useSettings()
@@ -35,21 +36,20 @@ export function SandboxSettings() {
)
return (
<div className="rounded-lg border bg-card overflow-hidden">
<div className="p-4 space-y-3">
<div className="flex items-center justify-between gap-3">
<div className="flex items-center gap-2 min-w-0">
<Box className="h-4 w-4 shrink-0 text-muted-foreground" />
<h3 className="text-sm font-semibold truncate">Sandbox</h3>
</div>
{sandbox?.msbVersion && (
<Badge variant="outline" className="text-xs shrink-0">
msb {sandbox.msbVersion}
</Badge>
)}
</div>
<div className="flex items-center justify-between gap-3">
<SettingsDisclosure
title="Sandbox"
icon={<Box className="h-4 w-4 shrink-0 text-muted-foreground" />}
meta={
sandbox?.msbVersion ? (
<Badge variant="outline" className="text-xs shrink-0">
msb {sandbox.msbVersion}
</Badge>
) : undefined
}
contentClassName="space-y-3"
>
<div className="grid gap-x-6 gap-y-3 @min-[1000px]:grid-cols-2">
<div className="flex items-start justify-between gap-3">
<div className="min-w-0 space-y-0.5">
<p className="text-sm text-muted-foreground">
Run OpenCode agent commands inside microVMs for isolation.
@@ -70,9 +70,9 @@ export function SandboxSettings() {
/>
</div>
<div className="flex items-center justify-between gap-3 border-t pt-3">
<div className="flex items-start justify-between gap-3 border-t pt-3 @min-[1000px]:border-t-0 @min-[1000px]:pt-0">
<div className="min-w-0 space-y-0.5">
<p className="text-sm">Git credentials in sandbox</p>
<p className="text-sm font-semibold">Git credentials in sandbox</p>
<p className="text-xs text-muted-foreground">
Forward git credentials into the microVM so sandboxed git and gh commands can authenticate. A
prompt-injected agent can exfiltrate any credential you forward.
@@ -85,16 +85,16 @@ export function SandboxSettings() {
aria-label="Toggle git credentials in sandbox"
/>
</div>
{health?.opencodeRestartPending && (
<Alert>
<RotateCcw className="h-4 w-4" />
<AlertDescription>
Restart the OpenCode server to apply sandbox changes.
</AlertDescription>
</Alert>
)}
</div>
</div>
{health?.opencodeRestartPending && (
<Alert>
<RotateCcw className="h-4 w-4" />
<AlertDescription>
Restart the OpenCode server to apply sandbox changes.
</AlertDescription>
</Alert>
)}
</SettingsDisclosure>
)
}
@@ -4,10 +4,11 @@ import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Switch } from '@/components/ui/switch'
import { Alert, AlertDescription } from '@/components/ui/alert'
import { ChevronDown, Plus, Trash2, RotateCcw } from 'lucide-react'
import { Plus, Trash2, RotateCcw } from 'lucide-react'
import { Badge } from '@/components/ui/badge'
import { showToast } from '@/lib/toast'
import { BLOCKED_SERVER_ENV_KEYS, DEFAULT_SERVER_ENV_VARS } from '@/api/types/settings'
import { SettingsDisclosure } from './SettingsDisclosure'
interface EnvVar {
key: string
@@ -74,115 +75,107 @@ export function ServerEnvVarsSettings() {
}
return (
<div className="rounded-lg border bg-card overflow-hidden">
<button
type="button"
onClick={() => setIsOpen((value) => !value)}
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors"
>
<div className="flex items-center gap-2 min-w-0">
<h3 className="text-sm font-semibold truncate">Server Environment Variables</h3>
<Badge variant="outline" className="text-xs">
{enabledDefaultCount + (preferences?.serverEnvVars ?? []).length}
</Badge>
</div>
<ChevronDown className={`h-4 w-4 transition-transform ${isOpen ? 'rotate-180' : ''}`} />
</button>
{isOpen && (
<div className="px-4 pb-4 pt-1 border-t border-border space-y-3">
{needsRestart && (
<Alert>
<RotateCcw className="h-4 w-4" />
<AlertDescription>
Restart the OpenCode server to apply environment variable changes.
</AlertDescription>
</Alert>
)}
<div className="space-y-2">
<div className="rounded-md border bg-muted/20 p-3 space-y-2">
<div className="text-xs font-medium text-muted-foreground">Default variables</div>
{DEFAULT_SERVER_ENV_VARS.map((envVar) => {
const isEnabled = !disabledDefaultSet.has(envVar.key)
return (
<div key={envVar.key} className="flex items-center justify-between gap-3">
<div className="min-w-0">
<div className="font-mono text-xs truncate">{envVar.key}={envVar.value}</div>
<p className="text-xs text-muted-foreground">
Required for OpenCode workspace listing and deletion.
</p>
</div>
<Switch
checked={isEnabled}
onCheckedChange={(checked) => handleDefaultToggle(envVar.key, checked)}
aria-label={`Toggle ${envVar.key}`}
/>
</div>
)
})}
</div>
{envVars.map((envVar, index) => {
const isBlocked = blockedSet.has(envVar.key.trim())
return (
<div key={index} className="flex gap-2 items-center">
<div className="flex-1 flex gap-2">
<Input
value={envVar.key}
onChange={(event) => handleChange(index, 'key', event.target.value)}
placeholder="VARIABLE_NAME"
className={`font-mono ${isBlocked ? 'border-destructive' : ''}`}
/>
<Input
value={envVar.value}
onChange={(event) => handleChange(index, 'value', event.target.value)}
placeholder="value"
className="font-mono"
/>
</div>
<Button
type="button"
variant="ghost"
size="icon"
onClick={() => handleRemove(index)}
className="shrink-0"
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
)
})}
{blockedKeys.length > 0 && (
<p className="text-xs text-destructive">
Reserved keys cannot be overridden: {blockedKeys.join(', ')}
</p>
)}
</div>
<div className="flex gap-2 pt-1">
<Button type="button" variant="outline" size="sm" onClick={handleAdd}>
<Plus className="h-3 w-3 mr-1" />
Add variable
</Button>
<Button
type="button"
size="sm"
onClick={handleSave}
disabled={isUpdating || blockedKeys.length > 0}
>
{isUpdating ? 'Saving...' : 'Save'}
</Button>
</div>
<p className="text-xs text-muted-foreground">
Variables are injected into the OpenCode server process at startup.
Changes require a server restart.
</p>
</div>
<SettingsDisclosure
title="Server Environment Variables"
isOpen={isOpen}
onToggle={() => setIsOpen((value) => !value)}
contentClassName="space-y-3"
meta={
<Badge variant="outline" className="text-xs">
{enabledDefaultCount + (preferences?.serverEnvVars ?? []).length}
</Badge>
}
>
{needsRestart && (
<Alert>
<RotateCcw className="h-4 w-4" />
<AlertDescription>
Restart the OpenCode server to apply environment variable changes.
</AlertDescription>
</Alert>
)}
</div>
<div className="space-y-2">
<div className="rounded-md bg-muted/20 p-3 space-y-2">
<div className="text-xs font-medium text-muted-foreground">Default variables</div>
{DEFAULT_SERVER_ENV_VARS.map((envVar) => {
const isEnabled = !disabledDefaultSet.has(envVar.key)
return (
<div key={envVar.key} className="flex items-center justify-between gap-3">
<div className="min-w-0">
<div className="font-mono text-xs truncate">{envVar.key}={envVar.value}</div>
<p className="text-xs text-muted-foreground">
Required for OpenCode workspace listing and deletion.
</p>
</div>
<Switch
checked={isEnabled}
onCheckedChange={(checked) => handleDefaultToggle(envVar.key, checked)}
aria-label={`Toggle ${envVar.key}`}
/>
</div>
)
})}
</div>
{envVars.map((envVar, index) => {
const isBlocked = blockedSet.has(envVar.key.trim())
return (
<div key={index} className="flex gap-2 items-center">
<div className="flex-1 flex gap-2">
<Input
value={envVar.key}
onChange={(event) => handleChange(index, 'key', event.target.value)}
placeholder="VARIABLE_NAME"
className={`font-mono ${isBlocked ? 'border-destructive' : ''}`}
/>
<Input
value={envVar.value}
onChange={(event) => handleChange(index, 'value', event.target.value)}
placeholder="value"
className="font-mono"
/>
</div>
<Button
type="button"
variant="ghost"
size="icon"
onClick={() => handleRemove(index)}
className="shrink-0"
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
)
})}
{blockedKeys.length > 0 && (
<p className="text-xs text-destructive">
Reserved keys cannot be overridden: {blockedKeys.join(', ')}
</p>
)}
</div>
<div className="flex gap-2 pt-1">
<Button type="button" variant="outline" size="sm" onClick={handleAdd}>
<Plus className="h-3 w-3 mr-1" />
Add variable
</Button>
<Button
type="button"
size="sm"
onClick={handleSave}
disabled={isUpdating || blockedKeys.length > 0}
>
{isUpdating ? 'Saving...' : 'Save'}
</Button>
</div>
<p className="text-xs text-muted-foreground">
Variables are injected into the OpenCode server process at startup.
Changes require a server restart.
</p>
</SettingsDisclosure>
)
}
@@ -43,10 +43,11 @@ describe('ServerHealthStatus', () => {
mockActions()
})
it('keeps Update and Versions enabled', () => {
it('keeps Update, Restart, and Versions enabled', () => {
render(<ServerHealthStatus />)
expect(screen.getByRole('button', { name: /Update/i })).toBeEnabled()
expect(screen.getByRole('button', { name: /Restart/i })).toBeEnabled()
expect(screen.getByRole('button', { name: /Versions/i })).toBeEnabled()
})
@@ -62,6 +63,18 @@ describe('ServerHealthStatus', () => {
expect(performUpgrade).toHaveBeenCalled()
})
it('invokes a restart when Restart is clicked', async () => {
const user = userEvent.setup()
const requestRestart = vi.fn()
mockActions({ requestRestart })
render(<ServerHealthStatus />)
await user.click(screen.getByRole('button', { name: /Restart/i }))
expect(requestRestart).toHaveBeenCalled()
})
it('opens the version dialog when Versions is clicked', async () => {
const user = userEvent.setup()
const onOpenVersionDialog = vi.fn()
@@ -1,6 +1,4 @@
import { cn } from '@/lib/utils'
import { Button } from '@/components/ui/button'
import { Card, CardContent } from '@/components/ui/card'
import { Loader2, ArrowUpCircle, RotateCcw, History } from 'lucide-react'
import { useServerHealth } from '@/hooks/useServerHealth'
import { useOpenCodeServerActions } from '@/hooks/useOpenCodeServerActions'
@@ -25,82 +23,79 @@ export function ServerHealthStatus({ onOpenVersionDialog }: ServerHealthStatusPr
if (!health) {
return (
<Card className="bg-transparent border-transparent">
<CardContent className="p-3">
<div className="flex items-center gap-2">
<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />
<span className="text-sm text-muted-foreground">Loading server status...</span>
</div>
</CardContent>
</Card>
<div className="flex items-center gap-2">
<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />
<span className="text-sm text-muted-foreground">Loading server status...</span>
</div>
)
}
const isUnhealthy = health.opencode !== 'healthy'
return (
<Card className={cn('bg-transparent border-transparent', isUnhealthy && 'border-destructive')}>
<CardContent className="p-3">
<div className="flex flex-wrap items-center justify-between gap-3">
<div className="flex min-w-0 flex-wrap items-center gap-2">
<div className={`h-3 w-3 rounded-full ${isUnhealthy ? 'bg-destructive animate-pulse' : 'bg-green-500'}`} />
<p className="font-medium text-sm">
Server Status: {isUnhealthy ? 'Unhealthy' : 'Healthy'}
<>
<div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-3">
<div className="flex min-w-0 flex-wrap items-center gap-2">
<div className={`h-3 w-3 rounded-full ${isUnhealthy ? 'bg-destructive animate-pulse' : 'bg-green-500'}`} />
<p className="font-medium text-sm">
Server Status: {isUnhealthy ? 'Unhealthy' : 'Healthy'}
</p>
{health.error && (
<p className="text-xs text-destructive">
{health.error}
</p>
{health.error && (
<p className="text-xs text-destructive">
{health.error}
</p>
)}
{health.opencodeVersion && (
<p className="text-xs text-muted-foreground">
OpenCode v{health.opencodeVersion}
</p>
)}
{health.opencodeManagerVersion && (
<p className="text-xs text-muted-foreground">
Manager v{health.opencodeManagerVersion}
</p>
)}
</div>
<div className="flex flex-wrap gap-2">
<Button
variant="outline"
size="sm"
onClick={performUpgrade}
disabled={upgradeOpenCodeMutation.isPending}
>
{upgradeOpenCodeMutation.isPending ? (
<Loader2 className="h-3 w-3 sm:h-4 sm:w-4 mr-1 animate-spin" />
) : (
<ArrowUpCircle className="h-3 w-3 sm:h-4 sm:w-4 mr-1" />
)}
<span className="text-xs sm:text-sm">Update</span>
</Button>
<Button
variant="outline"
size="sm"
onClick={requestRestart}
disabled={restartServerMutation.isPending}
>
{restartServerMutation.isPending ? (
<Loader2 className="h-3 w-3 sm:h-4 sm:w-4 mr-1 animate-spin" />
) : (
<RotateCcw className="h-3 w-3 sm:h-4 sm:w-4 mr-1" />
)}
<span className="text-xs sm:text-sm">Restart</span>
</Button>
<Button
variant="outline"
size="sm"
onClick={onOpenVersionDialog}
>
<History className="h-3 w-3 sm:h-4 sm:w-4 mr-1" />
<span className="text-xs sm:text-sm">Versions</span>
</Button>
</div>
)}
{health.opencodeVersion && (
<p className="text-xs text-muted-foreground">
OpenCode v{health.opencodeVersion}
</p>
)}
{health.opencodeManagerVersion && (
<p className="text-xs text-muted-foreground">
Manager v{health.opencodeManagerVersion}
</p>
)}
</div>
</CardContent>
<div className="flex flex-wrap gap-2">
<Button
variant="secondary"
size="sm"
className="h-11 sm:h-8"
onClick={performUpgrade}
disabled={upgradeOpenCodeMutation.isPending}
>
{upgradeOpenCodeMutation.isPending ? (
<Loader2 className="h-3 w-3 sm:h-4 sm:w-4 animate-spin" />
) : (
<ArrowUpCircle className="h-3 w-3 sm:h-4 sm:w-4" />
)}
<span className="text-xs sm:text-sm">Update</span>
</Button>
<Button
variant="secondary"
size="sm"
className="h-11 sm:h-8"
onClick={requestRestart}
disabled={restartServerMutation.isPending}
>
{restartServerMutation.isPending ? (
<Loader2 className="h-3 w-3 sm:h-4 sm:w-4 animate-spin" />
) : (
<RotateCcw className="h-3 w-3 sm:h-4 sm:w-4" />
)}
<span className="text-xs sm:text-sm">Restart</span>
</Button>
<Button
variant="secondary"
size="sm"
className="h-11 sm:h-8"
onClick={onOpenVersionDialog}
>
<History className="h-3 w-3 sm:h-4 sm:w-4" />
<span className="text-xs sm:text-sm">Versions</span>
</Button>
</div>
</div>
<RestartServerDialog
open={confirmOpen}
onOpenChange={setConfirmOpen}
@@ -109,6 +104,6 @@ export function ServerHealthStatus({ onOpenVersionDialog }: ServerHealthStatusPr
onCancel={() => setConfirmOpen(false)}
onConfirm={confirmRestart}
/>
</Card>
</>
)
}
@@ -28,12 +28,12 @@ function OpenCodeSettings({ onOpenVersionDialog }: { onOpenVersionDialog: () =>
const toggleAuthSections = useCallback(() => setAuthSectionsOpen((open) => !open), [])
return (
<div className="space-y-6">
<div className="group/opencode-settings space-y-4" data-opencode-settings>
<ServerHealthStatus onOpenVersionDialog={onOpenVersionDialog} />
<OpenCodeConfigManager />
<section className="space-y-4 border-t border-border pt-6" aria-label="Server maintenance">
<section className="space-y-4 border-t border-border pt-4" aria-label="Server maintenance">
<h2 className="text-lg font-semibold">Server maintenance</h2>
<div className="grid grid-cols-1 items-start gap-4 @min-[1000px]:grid-cols-2">
<div className="grid grid-cols-1 items-start gap-x-6 gap-y-4 @min-[1000px]:grid-cols-2">
<OpenCodeServerAuthSettings isOpen={authSectionsOpen} onToggle={toggleAuthSections} />
<ManagerTokenSettings isOpen={authSectionsOpen} onToggle={toggleAuthSections} />
</div>
@@ -132,7 +132,7 @@ export function SettingsDialog() {
return (
<Dialog open={isOpen} modal={false} onOpenChange={(open) => !open && close()}>
<DialogContent
className="inset-0 w-full h-full max-w-none max-h-none p-0 rounded-none bg-gradient-to-br from-background via-background to-background border-border overflow-hidden !flex !flex-col !gap-0"
className="inset-0 w-full h-full max-w-none max-h-none p-0 rounded-none bg-background border-border overflow-hidden !flex !flex-col !gap-0"
fullscreen
canSwipeBack={() => mobileView !== 'menu'}
onSwipeBack={handleSettingsBack}
@@ -0,0 +1,64 @@
import { useId, useRef, useState, type ReactNode } from 'react'
import { ChevronDown } from 'lucide-react'
import { cn } from '@/lib/utils'
import { scrollSectionIntoView } from '@/lib/settingsScroll'
interface SettingsDisclosureProps {
title: string
icon?: ReactNode
meta?: ReactNode
isOpen?: boolean
onToggle?: () => void
contentClassName?: string
children: ReactNode
}
export function SettingsDisclosure({
title,
icon,
meta,
isOpen: controlledOpen,
onToggle,
contentClassName,
children,
}: SettingsDisclosureProps) {
const [uncontrolledOpen, setUncontrolledOpen] = useState(false)
const isOpen = controlledOpen ?? uncontrolledOpen
const contentId = useId()
const headerRef = useRef<HTMLButtonElement>(null)
const handleToggle = () => {
const nextOpen = !isOpen
if (onToggle) {
onToggle()
} else {
setUncontrolledOpen(nextOpen)
}
if (nextOpen) {
setTimeout(() => scrollSectionIntoView(headerRef.current), 0)
}
}
return (
<div className="border-t border-border pt-4">
<button
ref={headerRef}
type="button"
aria-expanded={isOpen}
aria-controls={contentId}
onClick={handleToggle}
className="w-full flex items-center justify-between gap-2 py-2 text-left"
>
<div className="flex items-center gap-2 min-w-0">
{icon}
<h3 className="text-sm font-semibold truncate">{title}</h3>
{meta}
</div>
<ChevronDown className={cn('h-4 w-4 shrink-0 transition-transform', isOpen && 'rotate-180')} />
</button>
<div id={contentId} className={cn('pt-2', isOpen ? 'block' : 'hidden', contentClassName)}>
{children}
</div>
</div>
)
}