mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Add global AGENTS.md editor and expose dev server ports 5100-5103
This commit is contained in:
1 parent
af9f645f30
commit
433c2da50d
9 files changed
+317
-6
No files matched your search
@@ -0,0 +1,133 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Loader2, Save, RotateCcw } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import { showToast } from '@/lib/toast'
|
||||
|
||||
export function AgentsMdEditor() {
|
||||
const queryClient = useQueryClient()
|
||||
const [content, setContent] = useState('')
|
||||
const [hasChanges, setHasChanges] = useState(false)
|
||||
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: ['agents-md'],
|
||||
queryFn: () => settingsApi.getAgentsMd(),
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (data?.content !== undefined) {
|
||||
setContent(data.content)
|
||||
setHasChanges(false)
|
||||
}
|
||||
}, [data?.content])
|
||||
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: (newContent: string) => settingsApi.updateAgentsMd(newContent),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['agents-md'] })
|
||||
setHasChanges(false)
|
||||
showToast.success('AGENTS.md saved successfully')
|
||||
},
|
||||
onError: () => {
|
||||
showToast.error('Failed to save AGENTS.md')
|
||||
},
|
||||
})
|
||||
|
||||
const resetToDefaultMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
const { content: defaultContent } = await settingsApi.getDefaultAgentsMd()
|
||||
await settingsApi.updateAgentsMd(defaultContent)
|
||||
return defaultContent
|
||||
},
|
||||
onSuccess: (defaultContent) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['agents-md'] })
|
||||
setContent(defaultContent)
|
||||
setHasChanges(false)
|
||||
showToast.success('AGENTS.md reset to default')
|
||||
},
|
||||
onError: () => {
|
||||
showToast.error('Failed to reset AGENTS.md')
|
||||
},
|
||||
})
|
||||
|
||||
const handleContentChange = (value: string) => {
|
||||
setContent(value)
|
||||
setHasChanges(value !== data?.content)
|
||||
}
|
||||
|
||||
const handleSave = () => {
|
||||
updateMutation.mutate(content)
|
||||
}
|
||||
|
||||
const handleResetToDefault = () => {
|
||||
resetToDefaultMutation.mutate()
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="text-center py-8 text-red-500">
|
||||
Failed to load AGENTS.md
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Global instructions for AI agents. This file is merged with repository-specific AGENTS.md files.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleResetToDefault}
|
||||
disabled={updateMutation.isPending || resetToDefaultMutation.isPending}
|
||||
>
|
||||
{resetToDefaultMutation.isPending ? (
|
||||
<Loader2 className="h-4 w-4 mr-1 animate-spin" />
|
||||
) : (
|
||||
<RotateCcw className="h-4 w-4 mr-1" />
|
||||
)}
|
||||
Reset to Default
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={handleSave}
|
||||
disabled={!hasChanges || updateMutation.isPending || resetToDefaultMutation.isPending}
|
||||
>
|
||||
{updateMutation.isPending ? (
|
||||
<Loader2 className="h-4 w-4 mr-1 animate-spin" />
|
||||
) : (
|
||||
<Save className="h-4 w-4 mr-1" />
|
||||
)}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Textarea
|
||||
value={content}
|
||||
onChange={(e) => handleContentChange(e.target.value)}
|
||||
className="font-mono text-sm min-h-[300px] resize-y"
|
||||
placeholder="# Agent Instructions Add global instructions for AI agents here..."
|
||||
/>
|
||||
|
||||
{hasChanges && (
|
||||
<p className="text-xs text-amber-500">You have unsaved changes</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { Loader2, Plus, Trash2, Edit, Star, StarOff, Download, RotateCcw } from 'lucide-react'
|
||||
import { Loader2, Plus, Trash2, Edit, Star, StarOff, Download, RotateCcw, FileText } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Label } from '@/components/ui/label'
|
||||
@@ -10,6 +10,7 @@ import { CreateConfigDialog } from './CreateConfigDialog'
|
||||
import { OpenCodeConfigEditor } from './OpenCodeConfigEditor'
|
||||
import { CommandsEditor } from './CommandsEditor'
|
||||
import { AgentsEditor } from './AgentsEditor'
|
||||
import { AgentsMdEditor } from './AgentsMdEditor'
|
||||
import { McpManager } from './McpManager'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
@@ -53,6 +54,7 @@ export function OpenCodeConfigManager() {
|
||||
const [editingConfig, setEditingConfig] = useState<OpenCodeConfig | null>(null)
|
||||
const [selectedConfig, setSelectedConfig] = useState<OpenCodeConfig | null>(null)
|
||||
const [expandedSections, setExpandedSections] = useState<Record<string, boolean>>({
|
||||
agentsMd: false,
|
||||
commands: false,
|
||||
agents: false,
|
||||
mcp: false,
|
||||
@@ -61,6 +63,7 @@ export function OpenCodeConfigManager() {
|
||||
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false)
|
||||
const [deleteConfirmConfig, setDeleteConfirmConfig] = useState<OpenCodeConfig | null>(null)
|
||||
|
||||
const agentsMdRef = useRef<HTMLButtonElement>(null)
|
||||
const commandsRef = useRef<HTMLButtonElement>(null)
|
||||
const agentsRef = useRef<HTMLButtonElement>(null)
|
||||
const mcpRef = useRef<HTMLButtonElement>(null)
|
||||
@@ -360,9 +363,34 @@ export function OpenCodeConfigManager() {
|
||||
isUpdating={isUpdating}
|
||||
/>
|
||||
|
||||
{/* Commands, Agents, and MCP Section */}
|
||||
{/* Global AGENTS.md Section */}
|
||||
<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-hidden min-w-0 mb-6">
|
||||
<button
|
||||
ref={agentsMdRef}
|
||||
className="w-full px-4 py-3 flex items-center justify-between hover:bg-muted/50 transition-colors min-w-0"
|
||||
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>
|
||||
<Edit 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>
|
||||
|
||||
<h3 className="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 configurations. Select a configuration below to edit its settings.
|
||||
|
||||
Reference in new issue
Block a user