mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Bump version to 0.8.21 (#99)
* Add timeout handling and recovery for OpenCode upgrade/install operations - Extract DEFAULT_AGENTS_MD to constants file - Add 90s timeout for opencode upgrade/install commands - Implement server recovery when upgrade/install fails - Update frontend error handling for recovery status - Add settings route tests * Add centralized query cache invalidation utility * Bump version to 0.8.21
This commit is contained in:
1 parent
3661f0a271
commit
a02f7a2e98
14 files changed
+1100
-126
No files matched your search
@@ -0,0 +1,56 @@
|
||||
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
|
||||
|
||||
### Node.js Packages
|
||||
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
|
||||
|
||||
### Python Packages
|
||||
Always create a virtual environment in the repository directory before installing packages:
|
||||
|
||||
1. Create virtual environment in repo:
|
||||
\`cd \`<repo_path>\`
|
||||
\`uv venv .venv\`
|
||||
|
||||
2. Activate the virtual environment:
|
||||
\`source .venv/bin/activate\` # or \`uv pip sync\` for project-based workflows
|
||||
|
||||
3. Install packages into activated environment:
|
||||
\`uv pip install \`<package>\`
|
||||
\`uv pip install -r requirements.txt\`
|
||||
|
||||
4. Run Python commands:
|
||||
\`python script.py\` # Uses activated .venv
|
||||
|
||||
Alternative: Use \`uv run python script.py\` to skip explicit activation
|
||||
|
||||
**Important:**
|
||||
- Always create .venv in the repository directory (not workspace root)
|
||||
- Activate the environment before running pip operations
|
||||
- uv is pre-installed in the container and provides faster package installation
|
||||
- .venv directories created in repos will persist but can be removed safely
|
||||
|
||||
## General Guidelines
|
||||
|
||||
- This file is merged with any AGENTS.md files in individual repositories
|
||||
- Repository-specific instructions take precedence for their respective codebases
|
||||
`
|
||||
+2
-57
@@ -60,66 +60,11 @@ const db = initializeDatabase(DB_PATH)
|
||||
const auth = createAuth(db)
|
||||
const requireAuth = createAuthMiddleware(auth)
|
||||
|
||||
import { DEFAULT_AGENTS_MD } from './constants'
|
||||
|
||||
let ipcServer: IPCServer | undefined
|
||||
const gitAuthService = new GitAuthService()
|
||||
|
||||
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
|
||||
|
||||
### Node.js Packages
|
||||
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
|
||||
|
||||
### Python Packages
|
||||
Always create a virtual environment in the repository directory before installing packages:
|
||||
|
||||
1. Create virtual environment in repo:
|
||||
\`cd \`<repo_path>\`
|
||||
\`uv venv .venv\`
|
||||
|
||||
2. Activate the virtual environment:
|
||||
\`source .venv/bin/activate\` # or \`uv pip sync\` for project-based workflows
|
||||
|
||||
3. Install packages into activated environment:
|
||||
\`uv pip install \`<package>\`
|
||||
\`uv pip install -r requirements.txt\`
|
||||
|
||||
4. Run Python commands:
|
||||
\`python script.py\` # Uses activated .venv
|
||||
|
||||
Alternative: Use \`uv run python script.py\` to skip explicit activation
|
||||
|
||||
**Important:**
|
||||
- Always create .venv in the repository directory (not workspace root)
|
||||
- Activate the environment before running pip operations
|
||||
- uv is pre-installed in the container and provides faster package installation
|
||||
- .venv directories created in repos will persist but can be removed safely
|
||||
|
||||
## General Guidelines
|
||||
|
||||
- This file is merged with any AGENTS.md files in individual repositories
|
||||
- Repository-specific instructions take precedence for their respective codebases
|
||||
`
|
||||
|
||||
async function ensureDefaultConfigExists(): Promise<void> {
|
||||
const settingsService = new SettingsService(db)
|
||||
const workspaceConfigPath = getOpenCodeConfigFilePath()
|
||||
|
||||
+126
-32
@@ -12,7 +12,7 @@ import {
|
||||
} from '../types/settings'
|
||||
import { logger } from '../utils/logger'
|
||||
import { opencodeServerManager } from '../services/opencode-single-server'
|
||||
import { DEFAULT_AGENTS_MD } from '../index'
|
||||
import { DEFAULT_AGENTS_MD } from '../constants'
|
||||
|
||||
function compareVersions(v1: string, v2: string): number {
|
||||
const parts1 = v1.split('.').map(s => Number(s))
|
||||
@@ -27,6 +27,22 @@ function compareVersions(v1: string, v2: string): number {
|
||||
return 0
|
||||
}
|
||||
|
||||
function execWithTimeout(command: string, timeoutMs: number): { output: string; timedOut: boolean } {
|
||||
try {
|
||||
const output = execSync(command, {
|
||||
encoding: 'utf8',
|
||||
timeout: timeoutMs,
|
||||
killSignal: 'SIGKILL'
|
||||
})
|
||||
return { output, timedOut: false }
|
||||
} catch (error) {
|
||||
if (error && typeof error === 'object' && 'status' in error && (error as { status: number }).status === null) {
|
||||
return { output: '', timedOut: true }
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const UpdateSettingsSchema = z.object({
|
||||
preferences: UserPreferencesSchema.partial(),
|
||||
})
|
||||
@@ -376,20 +392,20 @@ export function createSettingsRoutes(db: Database) {
|
||||
})
|
||||
|
||||
app.post('/opencode-upgrade', async (c) => {
|
||||
const oldVersion = opencodeServerManager.getVersion()
|
||||
logger.info(`Current OpenCode version: ${oldVersion}`)
|
||||
|
||||
try {
|
||||
logger.info('OpenCode upgrade requested')
|
||||
|
||||
const oldVersion = opencodeServerManager.getVersion()
|
||||
logger.info(`Current OpenCode version: ${oldVersion}`)
|
||||
|
||||
logger.info('Running opencode upgrade...')
|
||||
const upgradeOutput = execSync('opencode upgrade 2>&1', { encoding: 'utf8' })
|
||||
logger.info('Running opencode upgrade with 90s timeout...')
|
||||
const { output: upgradeOutput, timedOut } = execWithTimeout('opencode upgrade 2>&1', 90000)
|
||||
logger.info(`Upgrade output: ${upgradeOutput}`)
|
||||
|
||||
await new Promise(r => setTimeout(r, 2000))
|
||||
if (timedOut) {
|
||||
logger.warn('OpenCode upgrade timed out after 90 seconds')
|
||||
throw new Error('Upgrade command timed out after 90 seconds')
|
||||
}
|
||||
|
||||
const newVersion = opencodeServerManager.getVersion() || await opencodeServerManager.fetchVersion()
|
||||
|
||||
logger.info(`New OpenCode version: ${newVersion}`)
|
||||
|
||||
const upgraded = oldVersion && newVersion && compareVersions(newVersion, oldVersion) > 0
|
||||
@@ -419,16 +435,58 @@ export function createSettingsRoutes(db: Database) {
|
||||
success: true,
|
||||
message: 'OpenCode is already up to date',
|
||||
oldVersion,
|
||||
newVersion: oldVersion,
|
||||
newVersion,
|
||||
upgraded: false
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Failed to upgrade OpenCode:', error)
|
||||
return c.json({
|
||||
error: 'Failed to upgrade OpenCode',
|
||||
details: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500)
|
||||
logger.warn('Attempting to recover OpenCode server...')
|
||||
|
||||
let recovered = false
|
||||
let recoveryMessage = ''
|
||||
|
||||
opencodeServerManager.clearStartupError()
|
||||
try {
|
||||
await opencodeServerManager.restart()
|
||||
logger.warn('OpenCode server restarted after upgrade failure')
|
||||
recovered = true
|
||||
recoveryMessage = 'Server recovered'
|
||||
} catch (recoveryError) {
|
||||
logger.error('Failed to recover OpenCode server:', recoveryError)
|
||||
recovered = false
|
||||
recoveryMessage = recoveryError instanceof Error ? recoveryError.message : 'Unknown error'
|
||||
}
|
||||
|
||||
let currentVersion: string | null | undefined = oldVersion
|
||||
try {
|
||||
currentVersion = opencodeServerManager.getVersion() || oldVersion
|
||||
} catch (versionError) {
|
||||
logger.error('Failed to get version after recovery:', versionError)
|
||||
currentVersion = oldVersion
|
||||
}
|
||||
|
||||
return c.json(
|
||||
recovered ? {
|
||||
success: false,
|
||||
error: 'Upgrade failed but server recovered',
|
||||
details: error instanceof Error ? error.message : 'Unknown error',
|
||||
oldVersion,
|
||||
newVersion: currentVersion,
|
||||
upgraded: false,
|
||||
recovered: true,
|
||||
recoveryMessage
|
||||
} : {
|
||||
error: 'Failed to upgrade OpenCode and could not recover',
|
||||
details: error instanceof Error ? error.message : 'Unknown error',
|
||||
oldVersion,
|
||||
newVersion: currentVersion,
|
||||
upgraded: false,
|
||||
recovered: false,
|
||||
recoveryMessage
|
||||
},
|
||||
recovered ? 400 : 500
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -479,30 +537,32 @@ export function createSettingsRoutes(db: Database) {
|
||||
})
|
||||
|
||||
app.post('/opencode-install-version', async (c) => {
|
||||
const oldVersion = opencodeServerManager.getVersion()
|
||||
logger.info(`Current OpenCode version: ${oldVersion}`)
|
||||
|
||||
try {
|
||||
const body = await c.req.json()
|
||||
const { version } = z.object({ version: z.string().min(1) }).parse(body)
|
||||
|
||||
|
||||
logger.info(`Installing OpenCode version: ${version}`)
|
||||
|
||||
const oldVersion = opencodeServerManager.getVersion()
|
||||
logger.info(`Current OpenCode version: ${oldVersion}`)
|
||||
|
||||
const versionArg = version.startsWith('v') ? version : `v${version}`
|
||||
logger.info(`Running opencode upgrade ${versionArg}...`)
|
||||
|
||||
const upgradeOutput = execSync(`opencode upgrade ${versionArg} 2>&1`, { encoding: 'utf8' })
|
||||
logger.info(`Running opencode upgrade ${versionArg} with 90s timeout...`)
|
||||
|
||||
const { output: upgradeOutput, timedOut } = execWithTimeout(`opencode upgrade ${versionArg} 2>&1`, 90000)
|
||||
logger.info(`Upgrade output: ${upgradeOutput}`)
|
||||
|
||||
await new Promise(r => setTimeout(r, 2000))
|
||||
|
||||
|
||||
if (timedOut) {
|
||||
logger.warn('OpenCode version install timed out after 90 seconds')
|
||||
throw new Error('Version install command timed out after 90 seconds')
|
||||
}
|
||||
|
||||
const newVersion = await opencodeServerManager.fetchVersion()
|
||||
logger.info(`New OpenCode version: ${newVersion}`)
|
||||
|
||||
|
||||
opencodeServerManager.clearStartupError()
|
||||
await opencodeServerManager.restart()
|
||||
logger.info('OpenCode server restarted after version change')
|
||||
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
message: `OpenCode ${oldVersion ? `changed from v${oldVersion} to` : 'installed as'} v${newVersion}`,
|
||||
@@ -511,10 +571,44 @@ export function createSettingsRoutes(db: Database) {
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Failed to install OpenCode version:', error)
|
||||
return c.json({
|
||||
error: 'Failed to install OpenCode version',
|
||||
details: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500)
|
||||
logger.warn('Attempting to recover OpenCode server...')
|
||||
|
||||
let recovered = false
|
||||
let recoveryMessage = ''
|
||||
|
||||
opencodeServerManager.clearStartupError()
|
||||
try {
|
||||
await opencodeServerManager.restart()
|
||||
logger.warn('OpenCode server restarted after install failure')
|
||||
recovered = true
|
||||
recoveryMessage = 'Server recovered'
|
||||
} catch (recoveryError) {
|
||||
logger.error('Failed to recover OpenCode server:', recoveryError)
|
||||
recovered = false
|
||||
recoveryMessage = recoveryError instanceof Error ? recoveryError.message : 'Unknown error'
|
||||
}
|
||||
|
||||
const currentVersion = opencodeServerManager.getVersion() || oldVersion
|
||||
|
||||
return c.json(
|
||||
recovered ? {
|
||||
success: false,
|
||||
error: 'Version install failed but server recovered',
|
||||
details: error instanceof Error ? error.message : 'Unknown error',
|
||||
oldVersion,
|
||||
newVersion: currentVersion,
|
||||
recovered: true,
|
||||
recoveryMessage
|
||||
} : {
|
||||
error: 'Failed to install OpenCode version and could not recover',
|
||||
details: error instanceof Error ? error.message : 'Unknown error',
|
||||
oldVersion,
|
||||
newVersion: currentVersion,
|
||||
recovered: false,
|
||||
recoveryMessage
|
||||
},
|
||||
recovered ? 400 : 500
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user