fix: keep config references on save and apply review batch 2 fixes (OM-179)

This commit is contained in:
Chris Scott committed 2026-11-02 23:21:33 -05:00
1 parent 49bb4ebd36
commit 8a6fd56e9a
17 files changed
+524 -60

No files matched your search

+19 -5
View File
@@ -1,6 +1,7 @@
import { Info } from '@opencode/schema/config'
import { Schema } from 'effect'
import type { OpenCodeConfigValidationIssue } from '../types'
import { isRecord } from '../utils/record'
export type OpenCodeConfigValidationResult =
| { success: true }
@@ -10,6 +11,9 @@ const standardSchema = Schema.toStandardSchemaV1(Info, {
parseOptions: { errors: 'all', onExcessProperty: 'ignore' },
})
const LEGACY_SKILLS_MESSAGE =
'skills must be a list of skill paths. Replace the legacy `skills: { paths: [...] }` object with `skills: [...]`.'
function toIssuePath(path: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }> | undefined): string {
if (!path || path.length === 0) return 'root'
return path
@@ -17,9 +21,14 @@ function toIssuePath(path: ReadonlyArray<PropertyKey | { readonly key: PropertyK
.join('.')
}
function hasLegacySkillsObject(value: unknown): boolean {
return isRecord(value) && isRecord(value.skills)
}
/**
* Validates a parsed OpenCode config document against the v2 `Config.Info` schema, ignoring
* unknown keys so v1-only fields in existing files stay loadable.
* unknown keys so v1-only fields in existing files stay loadable. A legacy v1 `skills` object
* is reported with an actionable message naming the v2 list form.
*/
export function validateOpenCodeConfig(value: unknown): OpenCodeConfigValidationResult {
const result = standardSchema['~standard'].validate(value)
@@ -27,11 +36,16 @@ export function validateOpenCodeConfig(value: unknown): OpenCodeConfigValidation
throw new Error('OpenCode config validation must be synchronous')
}
if (!result.issues) return { success: true }
const legacySkillsObject = hasLegacySkillsObject(value)
return {
success: false,
issues: result.issues.map((issue) => ({
path: toIssuePath(issue.path),
message: issue.message,
})),
issues: result.issues.map((issue) => {
const path = toIssuePath(issue.path)
const isLegacySkillsIssue = legacySkillsObject && path === 'skills'
return {
path,
message: isLegacySkillsIssue ? LEGACY_SKILLS_MESSAGE : issue.message,
}
}),
}
}