mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +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
+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
|
||||
}
|
||||
Reference in new issue
Block a user