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
@@ -46,7 +46,6 @@ export const DEFAULTS = {
|
||||
PROCESS_START_WAIT_MS: 2000,
|
||||
PROCESS_VERIFY_WAIT_MS: 1000,
|
||||
HEALTH_CHECK_TIMEOUT_MS: 30000,
|
||||
CONFIG_PATCH_TIMEOUT_MS: 15000,
|
||||
},
|
||||
|
||||
FILE_LIMITS: {
|
||||
@@ -101,6 +100,9 @@ export const GIT_PROVIDERS = {
|
||||
BITBUCKET: 'bitbucket.org',
|
||||
} as const
|
||||
|
||||
export const OPENCODE_CONFIG_SOURCE_NAMES = ['config.json', 'opencode.json', 'opencode.jsonc'] as const
|
||||
export type OpenCodeConfigSourceName = (typeof OPENCODE_CONFIG_SOURCE_NAMES)[number]
|
||||
|
||||
export type Config = typeof DEFAULTS
|
||||
export type AllowedMimeType = (typeof ALLOWED_MIME_TYPES)[number]
|
||||
export type GitProvider = (typeof GIT_PROVIDERS)[keyof typeof GIT_PROVIDERS]
|
||||
@@ -103,7 +103,6 @@ export const ENV = {
|
||||
PROCESS_START_WAIT_MS: getEnvNumber('PROCESS_START_WAIT_MS', DEFAULTS.TIMEOUTS.PROCESS_START_WAIT_MS),
|
||||
PROCESS_VERIFY_WAIT_MS: getEnvNumber('PROCESS_VERIFY_WAIT_MS', DEFAULTS.TIMEOUTS.PROCESS_VERIFY_WAIT_MS),
|
||||
HEALTH_CHECK_TIMEOUT_MS: getEnvNumber('HEALTH_CHECK_TIMEOUT_MS', DEFAULTS.TIMEOUTS.HEALTH_CHECK_TIMEOUT_MS),
|
||||
CONFIG_PATCH_TIMEOUT_MS: getEnvNumber('CONFIG_PATCH_TIMEOUT_MS', DEFAULTS.TIMEOUTS.CONFIG_PATCH_TIMEOUT_MS),
|
||||
},
|
||||
|
||||
FILE_LIMITS: {
|
||||
@@ -160,6 +159,7 @@ export const getForgeWorktreesPath = () => path.join(getOpenCodeDataPath(), 'for
|
||||
export const getOpenCodeTmpHome = () => path.join(ENV.WORKSPACE.BASE_PATH, '.opencode', 'tmp')
|
||||
export const getOpenCodeAgentTmpPath = () => path.join(getOpenCodeTmpHome(), 'opencode')
|
||||
export const getConfigPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CONFIG_DIR)
|
||||
export { OPENCODE_CONFIG_SOURCE_NAMES } from './defaults'
|
||||
export const getOpenCodeConfigFilePath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CONFIG_DIR, 'opencode.json')
|
||||
export const getAgentsMdPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CONFIG_DIR, 'AGENTS.md')
|
||||
export const getAuthPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.AUTH_FILE)
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './defaults'
|
||||
export * from './opencode-config-sources'
|
||||
export * from './client'
|
||||
@@ -0,0 +1,17 @@
|
||||
import { OPENCODE_CONFIG_SOURCE_NAMES, type OpenCodeConfigSourceName } from './defaults'
|
||||
|
||||
export const DEFAULT_OPENCODE_CONFIG_SOURCE_NAME: OpenCodeConfigSourceName = 'opencode.jsonc'
|
||||
|
||||
export function isOpenCodeConfigSourceName(value: string): value is OpenCodeConfigSourceName {
|
||||
return (OPENCODE_CONFIG_SOURCE_NAMES as readonly string[]).includes(value)
|
||||
}
|
||||
|
||||
export function selectPreferredOpenCodeConfigSourceName(
|
||||
names: readonly OpenCodeConfigSourceName[],
|
||||
): OpenCodeConfigSourceName | null {
|
||||
const present = new Set(names)
|
||||
for (const name of [...OPENCODE_CONFIG_SOURCE_NAMES].reverse()) {
|
||||
if (present.has(name)) return name
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { NotificationPreferencesSchema, DEFAULT_NOTIFICATION_PREFERENCES } from "./notifications";
|
||||
import { OPENCODE_CONFIG_SOURCE_NAMES } from "../config/defaults";
|
||||
|
||||
export const CustomCommandSchema = z.object({
|
||||
name: z.string(),
|
||||
@@ -362,6 +363,18 @@ export const OpenCodeConfigValidationIssueSchema = z.object({
|
||||
message: z.string(),
|
||||
});
|
||||
|
||||
export const OpenCodeConfigSourceNameSchema = z.enum(OPENCODE_CONFIG_SOURCE_NAMES);
|
||||
|
||||
export const OpenCodeConfigSourceFileSchema = z.object({
|
||||
name: OpenCodeConfigSourceNameSchema,
|
||||
path: z.string(),
|
||||
rawContent: z.string(),
|
||||
content: z.record(z.string(), z.unknown()),
|
||||
isValid: z.boolean(),
|
||||
validationIssues: z.array(OpenCodeConfigValidationIssueSchema).optional(),
|
||||
updatedAt: z.number(),
|
||||
});
|
||||
|
||||
export const OpenCodeConfigFileSchema = z.object({
|
||||
path: z.string(),
|
||||
content: z.record(z.string(), z.unknown()),
|
||||
@@ -369,8 +382,12 @@ export const OpenCodeConfigFileSchema = z.object({
|
||||
isValid: z.boolean(),
|
||||
validationIssues: z.array(OpenCodeConfigValidationIssueSchema).optional(),
|
||||
updatedAt: z.number(),
|
||||
sources: z.array(OpenCodeConfigSourceFileSchema),
|
||||
revision: z.string(),
|
||||
});
|
||||
|
||||
export const UpdateOpenCodeConfigRequestSchema = z.object({
|
||||
content: z.union([OpenCodeConfigSchema, z.string()]),
|
||||
content: z.union([z.record(z.string(), z.unknown()), z.string()]),
|
||||
source: OpenCodeConfigSourceNameSchema.optional(),
|
||||
expectedRevision: z.string().optional(),
|
||||
});
|
||||
@@ -22,7 +22,6 @@ export interface ApiErrorResponse {
|
||||
detail?: string
|
||||
details?: unknown
|
||||
validationIssues?: Array<{ path: string; message: string }>
|
||||
removedFields?: string[]
|
||||
}
|
||||
|
||||
export class FetchError extends Error {
|
||||
@@ -31,7 +30,6 @@ export class FetchError extends Error {
|
||||
detail?: string
|
||||
details?: unknown
|
||||
validationIssues?: Array<{ path: string; message: string }>
|
||||
removedFields?: string[]
|
||||
|
||||
constructor(
|
||||
message: string,
|
||||
@@ -41,7 +39,6 @@ export class FetchError extends Error {
|
||||
options?: {
|
||||
details?: unknown
|
||||
validationIssues?: Array<{ path: string; message: string }>
|
||||
removedFields?: string[]
|
||||
}
|
||||
) {
|
||||
super(message)
|
||||
@@ -51,6 +48,5 @@ export class FetchError extends Error {
|
||||
this.detail = detail
|
||||
this.details = options?.details
|
||||
this.validationIssues = options?.validationIssues
|
||||
this.removedFields = options?.removedFields
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
CustomCommandSchema,
|
||||
OpenCodeConfigSchema,
|
||||
OpenCodeConfigFileSchema,
|
||||
OpenCodeConfigSourceFileSchema,
|
||||
OpenCodeConfigValidationIssueSchema,
|
||||
UpdateOpenCodeConfigRequestSchema,
|
||||
ServerEnvVarSchema,
|
||||
@@ -59,6 +60,8 @@ export type UpdateSettingsRequest = z.infer<typeof UpdateSettingsRequestSchema>
|
||||
export type CustomCommand = z.infer<typeof CustomCommandSchema>
|
||||
export type ServerEnvVar = z.infer<typeof ServerEnvVarSchema>
|
||||
export type OpenCodeConfigFile = z.infer<typeof OpenCodeConfigFileSchema>
|
||||
export type { OpenCodeConfigSourceName } from '../config/defaults'
|
||||
export type OpenCodeConfigSourceFile = z.infer<typeof OpenCodeConfigSourceFileSchema>
|
||||
export type OpenCodeConfigValidationIssue = z.infer<typeof OpenCodeConfigValidationIssueSchema>
|
||||
export type OpenCodeConfigInput = z.infer<typeof OpenCodeConfigSchema>
|
||||
export type UpdateOpenCodeConfigRequest = z.infer<typeof UpdateOpenCodeConfigRequestSchema>
|
||||
|
||||
Reference in new issue
Block a user