section 6: Phase 6: Config.Info validation owner and v2 config types in

This commit is contained in:
Chris Scott committed 2026-11-02 10:23:14 -05:00
1 parent 66b5d1ac06
commit 48ca38c4e3
16 files changed
+232 -79

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
import { Info } from '@opencode/schema/config'
import { Schema } from 'effect'
export interface OpenCodeConfigValidationIssue {
path: string
message: string
}
export type OpenCodeConfigValidationResult =
| { success: true }
| { success: false; issues: OpenCodeConfigValidationIssue[] }
const standardSchema = Schema.toStandardSchemaV1(Info, {
parseOptions: { errors: 'all', onExcessProperty: 'ignore' },
})
function toIssuePath(path: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }> | undefined): string {
if (!path || path.length === 0) return 'root'
return path
.map((segment) => String(typeof segment === 'object' ? segment.key : segment))
.join('.')
}
/**
* Validates a parsed OpenCode config document against the v2 `Config.Info` schema, ignoring
* unknown keys so v1-only fields in existing files stay loadable.
*/
export function validateOpenCodeConfig(value: unknown): OpenCodeConfigValidationResult {
const result = standardSchema['~standard'].validate(value)
if (result instanceof Promise) {
throw new Error('OpenCode config validation must be synchronous')
}
if (!result.issues) return { success: true }
return {
success: false,
issues: result.issues.map((issue) => ({
path: toIssuePath(issue.path),
message: issue.message,
})),
}
}
+13
View File
@@ -0,0 +1,13 @@
import type { ConfigEntry } from '@opencode/client'
export type OpenCodeConfigInfo = Extract<ConfigEntry, { type: 'document' }>['info']
export type OpenCodeAgentConfig = NonNullable<OpenCodeConfigInfo['agents']>[string]
export type OpenCodeCommandConfig = NonNullable<OpenCodeConfigInfo['commands']>[string]
export type OpenCodeProviderConfig = NonNullable<OpenCodeConfigInfo['providers']>[string]
export type OpenCodeProviderModelConfig = NonNullable<OpenCodeProviderConfig['models']>[string]
export type OpenCodePermissionRule = NonNullable<OpenCodeConfigInfo['permissions']>[number]
+10
View File
@@ -22,6 +22,7 @@ export type {
ModelInfo,
ModelRef,
PermissionRequest,
PermissionReply,
PromptAgentAttachment,
PromptFileAttachment,
PromptMention,
@@ -51,6 +52,15 @@ export { ClientError, isIntegrationNotFoundError, isMcpServerNotFoundError, isSe
export { assistantText, sessionIDFromEvent, toolContentText } from './content'
export type {
OpenCodeAgentConfig,
OpenCodeCommandConfig,
OpenCodeConfigInfo,
OpenCodePermissionRule,
OpenCodeProviderConfig,
OpenCodeProviderModelConfig,
} from './config'
export {
GOAL_CHANGED_EVENT_TYPE,
GOAL_COMMAND_NAME,
+3 -4
View File
@@ -1,11 +1,10 @@
import type { ConfigEntry, McpServer } from '@opencode/client'
import type { McpServer } from '@opencode/client'
import type { OpenCodeConfigInfo } from './config'
import { isRecord } from '../utils/record'
export const MCP_OAUTH_CALLBACK_PATH = '/api/mcp-oauth-proxy/callback'
type ConfigDocumentInfo = Extract<ConfigEntry, { type: 'document' }>['info']
type McpConfig = NonNullable<ConfigDocumentInfo['mcp']>
type McpConfig = NonNullable<OpenCodeConfigInfo['mcp']>
export type McpServerConfig = NonNullable<McpConfig['servers']>[string]
+2 -1
View File
@@ -1,6 +1,7 @@
import type { ConfigEntry, ModelRef } from '@opencode/client'
import type { OpenCodeConfigInfo } from './config'
type ConfigDocumentModel = Extract<ConfigEntry, { type: 'document' }>['info']['model']
type ConfigDocumentModel = OpenCodeConfigInfo['model']
export function parseOpenCodeModelRef(model: string): ModelRef | undefined {
const providerEnd = model.indexOf('/')