mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat(worktree): worktree tabs, server env vars, and multi-directory SSE (#240)
* loop: worktree-tabs-2 completed after 4 iterations * loop: server-env-vars completed after 7 iterations * feat(worktree): add worktree tabs and server env vars settings * refactor(worktree): multi-directory SSE support and workspace chip row * feat(workspace): collapsible workspace manager and sibling filtering * feat(workspace): workspace creation endpoint, refactored workspace manager, and tests * refactor(frontend): unify workspace label and remove dead code - extract shared workspaceLabel helper into api/repos and reuse in WorkspaceManager and RepoDetail directoryLabels - remove unused useSessions hook and subscribeToDirectory subscription - drop redundant frontend workspace dedup now guaranteed by backend - align WorktreeTabs empty-state test with create-workspace button
This commit is contained in:
1 parent
60ed756a0b
commit
b9236f7f20
38 files changed
+2423
-133
No files matched your search
@@ -0,0 +1,188 @@
|
||||
import { useState, useEffect, useMemo } from 'react'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
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 { Badge } from '@/components/ui/badge'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { BLOCKED_SERVER_ENV_KEYS, DEFAULT_SERVER_ENV_VARS } from '@/api/types/settings'
|
||||
|
||||
interface EnvVar {
|
||||
key: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export function ServerEnvVarsSettings() {
|
||||
const { preferences, updateSettingsAsync, isUpdating } = useSettings()
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const [envVars, setEnvVars] = useState<EnvVar[]>([])
|
||||
const [disabledDefaultKeys, setDisabledDefaultKeys] = useState<string[]>([])
|
||||
const [needsRestart, setNeedsRestart] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
setEnvVars(preferences?.serverEnvVars ?? [])
|
||||
setDisabledDefaultKeys(preferences?.disabledDefaultServerEnvVars ?? [])
|
||||
}, [preferences?.disabledDefaultServerEnvVars, preferences?.serverEnvVars])
|
||||
|
||||
const blockedSet = useMemo(() => new Set<string>(BLOCKED_SERVER_ENV_KEYS), [])
|
||||
|
||||
const blockedKeys = useMemo(
|
||||
() => envVars
|
||||
.map((envVar) => envVar.key.trim())
|
||||
.filter((key) => key.length > 0 && blockedSet.has(key)),
|
||||
[envVars, blockedSet],
|
||||
)
|
||||
|
||||
const disabledDefaultSet = useMemo(() => new Set(disabledDefaultKeys), [disabledDefaultKeys])
|
||||
const enabledDefaultCount = DEFAULT_SERVER_ENV_VARS.filter((envVar) => !disabledDefaultSet.has(envVar.key)).length
|
||||
|
||||
const handleDefaultToggle = (key: string, enabled: boolean) => {
|
||||
setDisabledDefaultKeys((prev) => enabled
|
||||
? prev.filter((disabledKey) => disabledKey !== key)
|
||||
: [...new Set([...prev, key])])
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
setEnvVars((prev) => [...prev, { key: '', value: '' }])
|
||||
}
|
||||
|
||||
const handleRemove = (index: number) => {
|
||||
setEnvVars((prev) => prev.filter((_, i) => i !== index))
|
||||
}
|
||||
|
||||
const handleChange = (index: number, field: keyof EnvVar, value: string) => {
|
||||
setEnvVars((prev) => prev.map((envVar, i) => (i === index ? { ...envVar, [field]: value } : envVar)))
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
if (blockedKeys.length > 0) return
|
||||
|
||||
const filtered = envVars.filter((envVar) => envVar.key.trim() !== '')
|
||||
|
||||
try {
|
||||
await updateSettingsAsync({
|
||||
serverEnvVars: filtered,
|
||||
disabledDefaultServerEnvVars: disabledDefaultKeys,
|
||||
})
|
||||
setNeedsRestart(true)
|
||||
showToast.success('Environment variables saved')
|
||||
} catch {
|
||||
showToast.error('Failed to save environment variables')
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { KeyboardShortcuts } from '@/components/settings/KeyboardShortcuts'
|
||||
import { OpenCodeConfigManager } from '@/components/settings/OpenCodeConfigManager'
|
||||
import { OpenCodeServerAuthSettings } from '@/components/settings/OpenCodeServerAuthSettings'
|
||||
import { ManagerTokenSettings } from '@/components/settings/ManagerTokenSettings'
|
||||
import { ServerEnvVarsSettings } from '@/components/settings/ServerEnvVarsSettings'
|
||||
import { ServerHealthStatus } from '@/components/settings/ServerHealthStatus'
|
||||
import { ProviderSettings } from '@/components/settings/ProviderSettings'
|
||||
import { AccountSettings } from '@/components/settings/AccountSettings'
|
||||
@@ -163,6 +164,7 @@ export function SettingsDialog() {
|
||||
<OpenCodeServerAuthSettings isOpen={authSectionsOpen} onToggle={toggleAuthSections} />
|
||||
<ManagerTokenSettings isOpen={authSectionsOpen} onToggle={toggleAuthSections} />
|
||||
</div>
|
||||
<ServerEnvVarsSettings />
|
||||
<OpenCodeConfigManager hideHealthStatus />
|
||||
</div>
|
||||
</TabsContent>
|
||||
@@ -228,14 +230,15 @@ export function SettingsDialog() {
|
||||
{mobileView === 'voice' && <div key="voice"><VoiceSettings /></div>}
|
||||
{mobileView === 'git' && <div key="git"><GitSettings /></div>}
|
||||
{mobileView === 'shortcuts' && <div key="shortcuts"><KeyboardShortcuts /></div>}
|
||||
{mobileView === 'opencode' && (
|
||||
<div key="opencode" className="space-y-6">
|
||||
<ServerHealthStatus />
|
||||
<OpenCodeServerAuthSettings />
|
||||
<ManagerTokenSettings />
|
||||
<OpenCodeConfigManager hideHealthStatus />
|
||||
</div>
|
||||
)}
|
||||
{mobileView === 'opencode' && (
|
||||
<div key="opencode" className="space-y-6">
|
||||
<ServerHealthStatus />
|
||||
<OpenCodeServerAuthSettings />
|
||||
<ManagerTokenSettings />
|
||||
<ServerEnvVarsSettings />
|
||||
<OpenCodeConfigManager hideHealthStatus />
|
||||
</div>
|
||||
)}
|
||||
{mobileView === 'providers' && <div key="providers"><ProviderSettings /></div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user