mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(opencode): migrate OpenCode Manager to OpenCode 2 (#359)
* feat(opencode): migrate OpenCode Manager to OpenCode 2 Port the backend lifecycle, generated plugins, event aggregation, schedules, worktrees, provider credentials, MCP, config handling, the frontend chat model, and the ocm CLI to OpenCode 2. Adopt @opencode/client 2.0.15 as the single typed V2 API contract, require OpenCode 2.0.0 or newer (pinned 2.0.15), and delete every V1-only code path. * refactor(opencode): reload config in place and drop v1 compatibility shims Route config/skill/AGENTS.md changes through the OpenCode location reload API instead of a full server restart, stop auto-resuming interrupted sessions, remove the restart coordinator and v1 MCP/version shims, and pin support to OpenCode >=2.0.15 <3.0.0. Adds integration-ready retries, service-mode launch, ocm-cli repo proxy, and new frontend form/MCP helpers. * refactor(opencode): consolidate v2 migration helpers and harden install, proxy, and session flows - extract shared semver and model-ref utilities, reuse across version checks - share the OpenCode release download script across Docker, entrypoint, dev setup - unify install/upgrade failure recovery and guard externally managed OPENCODE_BIN - scope the repo proxy location rewrite and surface ocm proxy errors - rework frontend session projection, permission lookup, and cache invalidation * fix(schedules): reject unavailable agents before creating a session * feat(opencode): add ocm install, schedule agent fallback, and session move guards
This commit is contained in:
1 parent
6c2ebd764b
commit
dacde879d6
383 files changed
+29905
-46566
No files matched your search
@@ -13,19 +13,28 @@ import {
|
||||
withOpenCodeConfigLock,
|
||||
} from './opencode-config-file'
|
||||
import { opencodeServerManager } from './opencode-single-server'
|
||||
import { reloadOpenCodeConfig } from './opencode-restart'
|
||||
import type { OpenCodeClient } from './opencode/client'
|
||||
import type { SettingsService } from './settings'
|
||||
import { logger } from '../utils/logger'
|
||||
|
||||
export type OpenCodeReloadOutcome = 'reloaded' | 'restart_pending'
|
||||
|
||||
export type ApplyOpenCodeConfigResult =
|
||||
| { status: 'restart_pending'; config: OpenCodeConfigFile }
|
||||
| { status: 'applied'; config: OpenCodeConfigFile }
|
||||
| { status: 'reloaded'; config: OpenCodeConfigFile }
|
||||
| { status: 'restart_pending'; config: OpenCodeConfigFile }
|
||||
|
||||
export interface ApplyOpenCodeConfigInput {
|
||||
content: Record<string, unknown> | string
|
||||
source?: OpenCodeConfigSourceName
|
||||
expectedRevision?: string
|
||||
settingsService: SettingsService
|
||||
openCodeClient: OpenCodeClient
|
||||
}
|
||||
|
||||
const MCP_CONFIG_KEY = 'mcp'
|
||||
|
||||
export async function captureLastKnownGoodOpenCodeConfig(settingsService: SettingsService): Promise<OpenCodeConfigFile | null> {
|
||||
const previous = await readOpenCodeConfigFile()
|
||||
if (previous?.isValid) {
|
||||
@@ -66,26 +75,33 @@ export function toOpenCodeConfigApplyResponse(
|
||||
}
|
||||
}
|
||||
|
||||
function requiresOpenCodeRestart(previous: OpenCodeConfigFile | null, next: OpenCodeConfigFile): boolean {
|
||||
export async function reloadOpenCodeOrMarkRestartPending(openCodeClient: OpenCodeClient): Promise<OpenCodeReloadOutcome> {
|
||||
try {
|
||||
await reloadOpenCodeConfig(openCodeClient)
|
||||
return 'reloaded'
|
||||
} catch (error) {
|
||||
logger.warn('OpenCode configuration reload failed, marking a server restart as pending:', error)
|
||||
opencodeServerManager.markRestartPending()
|
||||
return 'restart_pending'
|
||||
}
|
||||
}
|
||||
|
||||
function listChangedTopLevelKeys(previous: Record<string, unknown>, next: Record<string, unknown>): string[] {
|
||||
const keys = new Set([...Object.keys(previous), ...Object.keys(next)])
|
||||
return [...keys].filter((key) => !isDeepStrictEqual(previous[key], next[key]))
|
||||
}
|
||||
|
||||
function requiresOpenCodeReload(previous: OpenCodeConfigFile | null, next: OpenCodeConfigFile): boolean {
|
||||
if (previous?.isValid !== next.isValid) {
|
||||
return true
|
||||
}
|
||||
|
||||
const previousContent = previous?.content ?? {}
|
||||
const keys = new Set([...Object.keys(previousContent), ...Object.keys(next.content)])
|
||||
for (const key of keys) {
|
||||
if (!isDeepStrictEqual(previousContent[key], next.content[key]) && key !== 'mcp') {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return listChangedTopLevelKeys(previous?.content ?? {}, next.content).some((key) => key !== MCP_CONFIG_KEY)
|
||||
}
|
||||
|
||||
export async function applyOpenCodeConfigUpdate(
|
||||
input: ApplyOpenCodeConfigInput,
|
||||
): Promise<ApplyOpenCodeConfigResult> {
|
||||
return withOpenCodeConfigLock(async () => {
|
||||
const { reloadRequired, config } = await withOpenCodeConfigLock(async () => {
|
||||
const { content, source, expectedRevision, settingsService } = input
|
||||
|
||||
const snapshot = await readOpenCodeConfigSnapshot()
|
||||
@@ -103,11 +119,12 @@ export async function applyOpenCodeConfigUpdate(
|
||||
}
|
||||
}
|
||||
|
||||
if (requiresOpenCodeRestart(previous, next)) {
|
||||
opencodeServerManager.markRestartPending()
|
||||
return { status: 'restart_pending', config: next }
|
||||
}
|
||||
|
||||
return { status: 'applied', config: next }
|
||||
return { reloadRequired: requiresOpenCodeReload(previous, next), config: next }
|
||||
})
|
||||
|
||||
if (!reloadRequired) {
|
||||
return { status: 'applied', config }
|
||||
}
|
||||
|
||||
return { status: await reloadOpenCodeOrMarkRestartPending(input.openCodeClient), config }
|
||||
}
|
||||
Reference in new issue
Block a user