mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +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
+1
-1
@@ -76,7 +76,7 @@ RUN chmod +x /docker-entrypoint.sh
|
||||
RUN mkdir -p /workspace /app/data && \
|
||||
chown -R node:node /workspace /app/data
|
||||
|
||||
EXPOSE 5003
|
||||
EXPOSE 5003 5100 5101 5102 5103
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
|
||||
CMD curl -f http://localhost:5003/api/health || exit 1
|
||||
|
||||
@@ -125,6 +125,49 @@ docker-compose restart
|
||||
docker exec -it opencode-manager sh
|
||||
```
|
||||
|
||||
### Dev Server Ports
|
||||
|
||||
The Docker container exposes ports `5100-5103` for running dev servers inside your repositories. Configure your project's dev server to use one of these ports and access it directly from your browser.
|
||||
|
||||
**Example usage:**
|
||||
```bash
|
||||
# Vite (vite.config.ts)
|
||||
server: { port: 5100, host: '0.0.0.0' }
|
||||
|
||||
# Next.js
|
||||
next dev -p 5100 -H 0.0.0.0
|
||||
|
||||
# Express/Node
|
||||
app.listen(5100, '0.0.0.0')
|
||||
```
|
||||
|
||||
Access your dev server at `http://localhost:5100` (or your Docker host IP).
|
||||
|
||||
To customize the exposed ports, edit `docker-compose.yml`:
|
||||
```yaml
|
||||
ports:
|
||||
- "5003:5003" # OpenCode Manager
|
||||
- "5100:5100" # Dev server 1
|
||||
- "5101:5101" # Dev server 2
|
||||
- "5102:5102" # Dev server 3
|
||||
- "5103:5103" # Dev server 4
|
||||
```
|
||||
|
||||
### Global Agent Instructions (AGENTS.md)
|
||||
|
||||
OpenCode Manager creates a default `AGENTS.md` file in the workspace config directory (`/workspace/.config/opencode/AGENTS.md`). This file provides global instructions to AI agents working within the container.
|
||||
|
||||
**Default instructions include:**
|
||||
- Reserved ports (5003 for OpenCode Manager, 5551 for OpenCode server)
|
||||
- Available dev server ports (5100-5103)
|
||||
- Guidelines for binding to `0.0.0.0` for Docker accessibility
|
||||
|
||||
**Editing AGENTS.md:**
|
||||
- Via UI: Settings > OpenCode > Global Agent Instructions
|
||||
- Via file: Edit `/workspace/.config/opencode/AGENTS.md` directly
|
||||
|
||||
This file is merged with any repository-specific `AGENTS.md` files, with repository instructions taking precedence for their respective codebases.
|
||||
|
||||
### Option 2: Local Development
|
||||
|
||||
```bash
|
||||
|
||||
+44
-1
@@ -10,7 +10,7 @@ import { createTTSRoutes, cleanupExpiredCache } from './routes/tts'
|
||||
import { createFileRoutes } from './routes/files'
|
||||
import { createProvidersRoutes } from './routes/providers'
|
||||
import { createOAuthRoutes } from './routes/oauth'
|
||||
import { ensureDirectoryExists, writeFileContent } from './services/file-operations'
|
||||
import { ensureDirectoryExists, writeFileContent, fileExists } from './services/file-operations'
|
||||
import { SettingsService } from './services/settings'
|
||||
import { opencodeServerManager } from './services/opencode-single-server'
|
||||
import { cleanupOrphanedDirectories } from './services/repo'
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
getReposPath,
|
||||
getConfigPath,
|
||||
getOpenCodeConfigFilePath,
|
||||
getAgentsMdPath,
|
||||
getDatabasePath,
|
||||
ENV
|
||||
} from '@opencode-manager/shared'
|
||||
@@ -38,6 +39,37 @@ app.use('/*', cors({
|
||||
|
||||
const db = initializeDatabase(DB_PATH)
|
||||
|
||||
export const DEFAULT_AGENTS_MD = `# OpenCode Manager - Global Agent Instructions
|
||||
|
||||
## Critical System Constraints
|
||||
|
||||
- **DO NOT** use ports 5003 or 5551 - these are reserved for OpenCode Manager
|
||||
- **DO NOT** kill or stop processes on ports 5003 or 5551
|
||||
- **DO NOT** modify files in the \`.config/opencode\` directory unless explicitly requested
|
||||
|
||||
## Dev Server Ports
|
||||
|
||||
When starting dev servers, use the pre-allocated ports 5100-5103:
|
||||
- Port 5100: Primary dev server (frontend)
|
||||
- Port 5101: Secondary dev server (API/backend)
|
||||
- Port 5102: Additional service
|
||||
- Port 5103: Additional service
|
||||
|
||||
Always bind to \`0.0.0.0\` to allow external access from the Docker host.
|
||||
|
||||
## Package Management
|
||||
|
||||
Prefer **pnpm** or **bun** over npm for installing dependencies to save disk space:
|
||||
- Use \`pnpm install\` instead of \`npm install\`
|
||||
- Use \`bun install\` as an alternative
|
||||
- Both are pre-installed in the container
|
||||
|
||||
## General Guidelines
|
||||
|
||||
- This file is merged with any AGENTS.md files in individual repositories
|
||||
- Repository-specific instructions take precedence for their respective codebases
|
||||
`
|
||||
|
||||
const DEFAULT_OPENCODE_CONFIG = {
|
||||
$schema: 'https://opencode.ai/config.json',
|
||||
theme: 'opencode',
|
||||
@@ -122,6 +154,16 @@ async function syncDefaultConfigToDisk(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureDefaultAgentsMdExists(): Promise<void> {
|
||||
const agentsMdPath = getAgentsMdPath()
|
||||
const exists = await fileExists(agentsMdPath)
|
||||
|
||||
if (!exists) {
|
||||
await writeFileContent(agentsMdPath, DEFAULT_AGENTS_MD)
|
||||
logger.info(`Created default AGENTS.md at: ${agentsMdPath}`)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await ensureDirectoryExists(getWorkspacePath())
|
||||
await ensureDirectoryExists(getReposPath())
|
||||
@@ -135,6 +177,7 @@ try {
|
||||
|
||||
await ensureDefaultConfigExists()
|
||||
await syncDefaultConfigToDisk()
|
||||
await ensureDefaultAgentsMdExists()
|
||||
|
||||
opencodeServerManager.setDatabase(db)
|
||||
await opencodeServerManager.start()
|
||||
|
||||
@@ -2,15 +2,16 @@ import { Hono } from 'hono'
|
||||
import { z } from 'zod'
|
||||
import type { Database } from 'bun:sqlite'
|
||||
import { SettingsService } from '../services/settings'
|
||||
import { writeFileContent } from '../services/file-operations'
|
||||
import { writeFileContent, readFileContent, fileExists } from '../services/file-operations'
|
||||
import { patchOpenCodeConfig } from '../services/proxy'
|
||||
import { getOpenCodeConfigFilePath } from '@opencode-manager/shared'
|
||||
import { getOpenCodeConfigFilePath, getAgentsMdPath } from '@opencode-manager/shared'
|
||||
import {
|
||||
UserPreferencesSchema,
|
||||
OpenCodeConfigSchema,
|
||||
} from '../types/settings'
|
||||
import { logger } from '../utils/logger'
|
||||
import { opencodeServerManager } from '../services/opencode-single-server'
|
||||
import { DEFAULT_AGENTS_MD } from '../index'
|
||||
|
||||
const UpdateSettingsSchema = z.object({
|
||||
preferences: UserPreferencesSchema.partial(),
|
||||
@@ -326,5 +327,48 @@ export function createSettingsRoutes(db: Database) {
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/agents-md', async (c) => {
|
||||
try {
|
||||
const agentsMdPath = getAgentsMdPath()
|
||||
const exists = await fileExists(agentsMdPath)
|
||||
|
||||
if (!exists) {
|
||||
return c.json({ content: '' })
|
||||
}
|
||||
|
||||
const content = await readFileContent(agentsMdPath)
|
||||
return c.json({ content })
|
||||
} catch (error) {
|
||||
logger.error('Failed to get AGENTS.md:', error)
|
||||
return c.json({ error: 'Failed to get AGENTS.md' }, 500)
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/agents-md/default', async (c) => {
|
||||
return c.json({ content: DEFAULT_AGENTS_MD })
|
||||
})
|
||||
|
||||
app.put('/agents-md', async (c) => {
|
||||
try {
|
||||
const body = await c.req.json()
|
||||
const { content } = z.object({ content: z.string() }).parse(body)
|
||||
|
||||
const agentsMdPath = getAgentsMdPath()
|
||||
await writeFileContent(agentsMdPath, content)
|
||||
logger.info(`Updated AGENTS.md at: ${agentsMdPath}`)
|
||||
|
||||
await opencodeServerManager.restart()
|
||||
logger.info('Restarted OpenCode server after AGENTS.md update')
|
||||
|
||||
return c.json({ success: true })
|
||||
} catch (error) {
|
||||
logger.error('Failed to update AGENTS.md:', error)
|
||||
if (error instanceof z.ZodError) {
|
||||
return c.json({ error: 'Invalid request data', details: error.issues }, 400)
|
||||
}
|
||||
return c.json({ error: 'Failed to update AGENTS.md' }, 500)
|
||||
}
|
||||
})
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -6,6 +6,10 @@ services:
|
||||
container_name: opencode-manager
|
||||
ports:
|
||||
- "5003:5003"
|
||||
- "5100:5100"
|
||||
- "5101:5101"
|
||||
- "5102:5102"
|
||||
- "5103:5103"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- HOST=0.0.0.0
|
||||
|
||||
@@ -102,4 +102,19 @@ export const settingsApi = {
|
||||
const { data } = await axios.post(`${API_BASE_URL}/api/settings/opencode-restart`)
|
||||
return data
|
||||
},
|
||||
|
||||
getAgentsMd: async (): Promise<{ content: string }> => {
|
||||
const { data } = await axios.get(`${API_BASE_URL}/api/settings/agents-md`)
|
||||
return data
|
||||
},
|
||||
|
||||
getDefaultAgentsMd: async (): Promise<{ content: string }> => {
|
||||
const { data } = await axios.get(`${API_BASE_URL}/api/settings/agents-md/default`)
|
||||
return data
|
||||
},
|
||||
|
||||
updateAgentsMd: async (content: string): Promise<{ success: boolean }> => {
|
||||
const { data } = await axios.put(`${API_BASE_URL}/api/settings/agents-md`, { content })
|
||||
return data
|
||||
},
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -83,6 +83,7 @@ export const getWorkspacePath = () => ENV.WORKSPACE.BASE_PATH
|
||||
export const getReposPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.REPOS_DIR)
|
||||
export const getConfigPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CONFIG_DIR)
|
||||
export const getOpenCodeConfigFilePath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CONFIG_DIR, 'opencode.json')
|
||||
export const getAgentsMdPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CONFIG_DIR, 'AGENTS.md')
|
||||
export const getAuthPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.AUTH_FILE)
|
||||
export const getDatabasePath = () => ENV.DATABASE.PATH
|
||||
|
||||
|
||||
Reference in new issue
Block a user