mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
feat: directory files upload system, deferred restart model, cache invalidation consolidation, and misc improvements (#281)
* feat: show variant label on model picker and add folder upload for agents/commands
- Replace three-dot variant menu trigger with selected variant label
- Add POST /api/settings/opencode-directory-files/install endpoint
- Upload agents/commands markdown folders into .config/opencode/{agents,commands}/
- Reload OpenCode server after upload so files are picked up
* fix: revalidate branch/git caches when mobile sheet opens and on vcs.branch.updated SSE
- add shared invalidateRepoGitCaches() helper for consistent invalidation
- revalidate repo list when mobile repo quick-switch sheet opens
- revalidate current repo when mobile More drawer opens
- revalidate repo/git caches when Source Control dialog opens
- handle vcs.branch.updated SSE event with optimistic cache update
- use helper in branch create/switch mutations in useGit and BranchesTab
* style: make variant selector look more like a button with chevron and compact sizing
* refactor: consolidate settings editors, add folder upload support, and clean up unused code
* refactor: consolidate settings editors, add folder upload support, and clean up unused code
* feat: add opencode-directory-files listing service and consolidate settings editors
* fix: distinguish scroll from tap in suggestion popups on touch devices
* refactor: consolidate settings editors and add DirectoryFilesList component
* refactor: target repo status cache updates only to affected batch entries
* refactor: streamline settings, git hooks, and query invalidation logic
This commit is contained in:
1 parent
e53b4fd32c
commit
617962f2dd
48 files changed
+1522
-293
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Loader2, Plus, Trash2, Edit, Download, RotateCcw, FileText, ArrowUpCircle, History, ChevronDown } from 'lucide-react'
|
||||
import { Loader2, Plus, Trash2, Edit, Download, RotateCcw, FileText, ArrowUpCircle, History, ChevronDown, AlertTriangle } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Label } from '@/components/ui/label'
|
||||
@@ -58,6 +58,8 @@ interface OpenCodeConfigManagerProps {
|
||||
hideHealthStatus?: boolean
|
||||
}
|
||||
|
||||
const EXPANDED_SECTION_CONTENT_CLASS = 'p-2 sm:p-4'
|
||||
|
||||
export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConfigManagerProps) {
|
||||
const queryClient = useQueryClient()
|
||||
const { data: health } = useServerHealth()
|
||||
@@ -100,11 +102,23 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
staleTime: 30 * 1000,
|
||||
})
|
||||
|
||||
const { data: directoryCommands = [] } = useQuery({
|
||||
queryKey: ['opencode-directory-files', 'commands'],
|
||||
queryFn: () => settingsApi.listOpenCodeDirectoryFiles('commands'),
|
||||
staleTime: 30 * 1000,
|
||||
})
|
||||
|
||||
const { data: directoryAgents = [] } = useQuery({
|
||||
queryKey: ['opencode-directory-files', 'agents'],
|
||||
queryFn: () => settingsApi.listOpenCodeDirectoryFiles('agents'),
|
||||
staleTime: 30 * 1000,
|
||||
})
|
||||
|
||||
const scrollToSection = (ref: React.RefObject<HTMLButtonElement | null>) => {
|
||||
if (ref.current) {
|
||||
ref.current.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'start',
|
||||
block: 'nearest',
|
||||
inline: 'nearest'
|
||||
})
|
||||
}
|
||||
@@ -238,7 +252,6 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
const previousConfig = configs.find(c => c.name === configName)
|
||||
const previousContent = previousConfig?.content
|
||||
const previousSelectedConfig = selectedConfig
|
||||
const shouldPromptRestart = Boolean(previousConfig?.isDefault)
|
||||
const now = Date.now()
|
||||
|
||||
setConfigs(prev => prev.map(config =>
|
||||
@@ -247,15 +260,14 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
if (selectedConfig && selectedConfig.name === configName) {
|
||||
setSelectedConfig({ ...selectedConfig, content: newContent, updatedAt: now })
|
||||
}
|
||||
if (shouldPromptRestart) {
|
||||
setIsRestartPromptOpen(true)
|
||||
}
|
||||
|
||||
try {
|
||||
setIsUpdating(true)
|
||||
const result = await settingsApi.updateOpenCodeConfig(configName, { content: newContent })
|
||||
if (result.removedFields && result.removedFields.length > 0) {
|
||||
showToast.info(`Configuration updated after removing invalid fields: ${result.removedFields.join(', ')}`)
|
||||
} else if (result.restartRequired) {
|
||||
showToast.success('Configuration saved. Restart the server to apply changes.')
|
||||
} else {
|
||||
showToast.success('Configuration updated')
|
||||
}
|
||||
@@ -267,9 +279,6 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
if (previousSelectedConfig && previousSelectedConfig.name === configName) {
|
||||
setSelectedConfig(previousSelectedConfig)
|
||||
}
|
||||
if (shouldPromptRestart) {
|
||||
setIsRestartPromptOpen(false)
|
||||
}
|
||||
console.error('Failed to update config:', error)
|
||||
showToast.error(getApiErrorMessage(error, 'Failed to update config'))
|
||||
} finally {
|
||||
@@ -413,7 +422,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
const activeConfig = configs.find((c) => c.name === activeConfigName) ?? null
|
||||
|
||||
return (
|
||||
<div className="space-y-6 overflow-y-auto">
|
||||
<div className="space-y-6 min-w-0">
|
||||
{!hideHealthStatus && health && (
|
||||
<Card className={cn('bg-transparent border-transparent', isUnhealthy && 'border-destructive')}>
|
||||
<CardContent className="p-3">
|
||||
@@ -500,6 +509,30 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{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">
|
||||
<AlertTriangle className="h-4 w-4 shrink-0 text-amber-500" />
|
||||
<p className="text-sm">
|
||||
Configuration changes are saved but require a server restart to take effect.
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => setIsRestartPromptOpen(true)}
|
||||
disabled={restartServerMutation.isPending}
|
||||
className="shrink-0"
|
||||
>
|
||||
{restartServerMutation.isPending ? (
|
||||
<Loader2 className="h-3 w-3 mr-1 animate-spin" />
|
||||
) : (
|
||||
<RotateCcw className="h-3 w-3 mr-1" />
|
||||
)}
|
||||
Restart Now
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||
@@ -745,10 +778,10 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
if (!editingConfig) return
|
||||
showToast.loading('Saving configuration...', { id: 'edit-config' })
|
||||
try {
|
||||
await settingsApi.updateOpenCodeConfig(editingConfig.name, { content: rawContent })
|
||||
const result = await settingsApi.updateOpenCodeConfig(editingConfig.name, { content: rawContent })
|
||||
await fetchConfigs()
|
||||
const successMsg = editingConfig.isDefault
|
||||
? 'Configuration saved and server reloaded'
|
||||
const successMsg = result.restartRequired
|
||||
? 'Configuration saved. Restart the server to apply changes.'
|
||||
: 'Configuration saved'
|
||||
showToast.success(successMsg, { id: 'edit-config' })
|
||||
invalidateConfigCaches(queryClient)
|
||||
@@ -817,7 +850,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-4 pb-20 min-w-0">
|
||||
<div className="flex flex-col gap-4 pb-4 min-w-0">
|
||||
{selectedConfig ? (
|
||||
<>
|
||||
{!selectedConfig.isValid && selectedConfig.validationIssues && selectedConfig.validationIssues.length > 0 && (
|
||||
@@ -856,15 +889,16 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<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((selectedConfig.content?.command as Record<string, Command> | undefined) ?? {}).length} configured
|
||||
{Object.keys((selectedConfig.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="p-2 sm:max-h-[50vh] sm:overflow-y-auto sm:p-4">
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<CommandsEditor
|
||||
commands={(selectedConfig.content?.command as Record<string, Command> | undefined) ?? {}}
|
||||
directoryCommands={directoryCommands}
|
||||
onChange={(commands) => {
|
||||
const updatedContent = {
|
||||
...selectedConfig.content,
|
||||
@@ -893,15 +927,16 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<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((selectedConfig.content?.agent as Record<string, Agent> | undefined) ?? {}).length} configured
|
||||
{Object.keys((selectedConfig.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="p-2 sm:max-h-[50vh] sm:overflow-y-auto sm:p-4">
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<AgentsEditor
|
||||
agents={(selectedConfig.content?.agent as Record<string, Agent> | undefined) ?? {}}
|
||||
directoryAgents={directoryAgents}
|
||||
onChange={(agents) => {
|
||||
const updatedContent = {
|
||||
...selectedConfig.content,
|
||||
@@ -935,7 +970,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<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="p-2 sm:max-h-[50vh] sm:overflow-y-auto sm:p-4">
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<SkillsEditor
|
||||
managedSkills={managedSkills}
|
||||
/>
|
||||
@@ -965,7 +1000,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<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="p-2 sm:max-h-[50vh] sm:overflow-y-auto sm:p-4">
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<McpManager
|
||||
config={selectedConfig}
|
||||
onUpdate={(content) => updateConfigContent(selectedConfig.name, content)}
|
||||
@@ -1004,7 +1039,7 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<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="p-2 sm:max-h-[50vh] sm:overflow-y-auto sm:p-4">
|
||||
<div className={EXPANDED_SECTION_CONTENT_CLASS}>
|
||||
<OpenCodeModelsEditor
|
||||
providers={(selectedConfig.content?.provider as Record<string, ConfigProvider> | undefined) ?? {}}
|
||||
onChange={(providers) => {
|
||||
@@ -1045,7 +1080,6 @@ export function OpenCodeConfigManager({ hideHealthStatus = false }: OpenCodeConf
|
||||
<RestartServerDialog
|
||||
open={isRestartPromptOpen}
|
||||
onOpenChange={setIsRestartPromptOpen}
|
||||
isSaving={isUpdating && !restartServerMutation.isPending}
|
||||
isRestarting={restartServerMutation.isPending}
|
||||
onCancel={() => setIsRestartPromptOpen(false)}
|
||||
onConfirm={async () => {
|
||||
|
||||
Reference in new issue
Block a user