mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
* 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
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { DEFAULT_OPENCODE_CONFIG_SOURCE_NAME, isOpenCodeConfigSourceName } from '@opencode-manager/shared'
|
|
import type { OpenCodeConfigFile, OpenCodeConfigSourceFile, OpenCodeConfigSourceName } from '@/api/types/settings'
|
|
|
|
function sourceNameFromPath(path: string): OpenCodeConfigSourceName {
|
|
const fileName = path.split(/[\\/]/).filter(Boolean).pop() ?? ''
|
|
return isOpenCodeConfigSourceName(fileName) ? fileName : DEFAULT_OPENCODE_CONFIG_SOURCE_NAME
|
|
}
|
|
|
|
export function makeOpenCodeConfigSource(
|
|
overrides: Partial<OpenCodeConfigSourceFile> = {},
|
|
): OpenCodeConfigSourceFile {
|
|
return {
|
|
name: 'opencode.json',
|
|
path: '/workspace/.config/opencode/opencode.json',
|
|
rawContent: '{}',
|
|
content: {},
|
|
isValid: true,
|
|
updatedAt: 1,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeOpenCodeConfigFile(overrides: Partial<OpenCodeConfigFile> = {}): OpenCodeConfigFile {
|
|
const base: OpenCodeConfigFile = {
|
|
path: '/workspace/.config/opencode/opencode.json',
|
|
content: {},
|
|
rawContent: '{}',
|
|
isValid: true,
|
|
updatedAt: 1,
|
|
revision: 'rev-1',
|
|
sources: [],
|
|
}
|
|
const merged = { ...base, ...overrides }
|
|
return {
|
|
...merged,
|
|
sources: overrides.sources ?? [makeOpenCodeConfigSource({
|
|
name: sourceNameFromPath(merged.path),
|
|
path: merged.path,
|
|
rawContent: merged.rawContent,
|
|
content: merged.content,
|
|
isValid: merged.isValid,
|
|
validationIssues: merged.validationIssues,
|
|
updatedAt: merged.updatedAt,
|
|
})],
|
|
}
|
|
}
|