mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(config): support layered OpenCode config sources with revision-guarded saves (#358)
* feat(config): support layered OpenCode config sources with revision-guarded saves * refactor(config): harden multi-source OpenCode config handling - extract shared config-source helpers and default source name - reject shadowed removals with 409 and require sources/revision - restart the server on reload with session resume - mirror multiple host config files on import and warn on removals - skip restart for mcp-only saves - drop removedFields and CONFIG_PATCH_TIMEOUT_MS * fix(config): return null when archiving broken OpenCode config fails
This commit is contained in:
1 parent
97370a8296
commit
b5dd900efb
53 files changed
+3003
-1665
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { opencodeServerManager } from './opencode-single-server'
|
||||
import type { OpenCodeSupervisor } from './opencode-supervisor'
|
||||
import { opencodeServerManager, ConfigReloadError } from './opencode-single-server'
|
||||
import { readOpenCodeConfigFile } from './opencode-config-file'
|
||||
import type { OpenCodeOperationReason, OpenCodeSupervisor } from './opencode-supervisor'
|
||||
import type { OpenCodeRestartCoordinator } from './opencode-restart-coordinator'
|
||||
|
||||
let restartCoordinator: OpenCodeRestartCoordinator | null = null
|
||||
@@ -22,9 +23,9 @@ function restartFailureError(): Error {
|
||||
return new Error(startupError ?? 'OpenCode server restart did not complete successfully')
|
||||
}
|
||||
|
||||
async function performRestart(supervisor?: OpenCodeSupervisor): Promise<boolean> {
|
||||
async function performRestart(supervisor: OpenCodeSupervisor | undefined, reason: OpenCodeOperationReason): Promise<boolean> {
|
||||
if (supervisor) {
|
||||
return (await supervisor.restart('settings_restart')).healthy
|
||||
return (await supervisor.restart(reason)).healthy
|
||||
}
|
||||
opencodeServerManager.clearStartupError()
|
||||
await opencodeServerManager.restart()
|
||||
@@ -43,16 +44,19 @@ async function performRestart(supervisor?: OpenCodeSupervisor): Promise<boolean>
|
||||
* A full process restart drops in-flight sessions; resuming re-issues a
|
||||
* "continue" prompt once the server is healthy again.
|
||||
*/
|
||||
export async function restartOpenCode(supervisor?: OpenCodeSupervisor): Promise<{ resumedSessionIDs: string[] }> {
|
||||
export async function restartOpenCode(
|
||||
supervisor?: OpenCodeSupervisor,
|
||||
reason: OpenCodeOperationReason = 'settings_restart',
|
||||
): Promise<{ resumedSessionIDs: string[] }> {
|
||||
if (restartCoordinator) {
|
||||
const result = await restartCoordinator.runWithResume(() => performRestart(supervisor))
|
||||
const result = await restartCoordinator.runWithResume(() => performRestart(supervisor, reason))
|
||||
if (!result.healthy) {
|
||||
throw restartFailureError()
|
||||
}
|
||||
return { resumedSessionIDs: result.resumedSessionIDs }
|
||||
}
|
||||
if (supervisor) {
|
||||
const status = await supervisor.restart('settings_restart')
|
||||
const status = await supervisor.restart(reason)
|
||||
if (!status.healthy) {
|
||||
throw restartFailureError()
|
||||
}
|
||||
@@ -67,19 +71,13 @@ export async function restartOpenCode(supervisor?: OpenCodeSupervisor): Promise<
|
||||
return { resumedSessionIDs: [] }
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads OpenCode configuration via the non-disruptive API patch. This does
|
||||
* NOT drop the server process, so active sessions keep running and there is
|
||||
* nothing to resume.
|
||||
*/
|
||||
export async function reloadOpenCodeConfig(supervisor?: OpenCodeSupervisor): Promise<void> {
|
||||
if (supervisor) {
|
||||
const status = await supervisor.reloadConfig('settings_reload')
|
||||
if (!status.healthy) {
|
||||
const startupError = opencodeServerManager.getLastStartupError()
|
||||
throw new Error(startupError ?? 'OpenCode server reload did not complete successfully')
|
||||
}
|
||||
return
|
||||
export async function reloadOpenCodeConfig(supervisor?: OpenCodeSupervisor): Promise<{ resumedSessionIDs: string[] }> {
|
||||
const config = await readOpenCodeConfigFile()
|
||||
if (!config) {
|
||||
throw new ConfigReloadError('No OpenCode global configuration files found')
|
||||
}
|
||||
await opencodeServerManager.reloadConfig()
|
||||
if (!config.isValid) {
|
||||
throw new ConfigReloadError('OpenCode global configuration is invalid', config.validationIssues)
|
||||
}
|
||||
return restartOpenCode(supervisor, 'settings_reload')
|
||||
}
|
||||
Reference in new issue
Block a user