Skip to content

Commit ac46bdc

Browse files
Honadavidgut1982
authored andcommitted
fix(core): accept deprecated reference config key (anomalyco#31659)
1 parent 9b87daf commit ac46bdc

6 files changed

Lines changed: 69 additions & 2 deletions

File tree

.opencode/opencode.jsonc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"$schema": "https://opencode.ai/config.json",
33
"provider": {},
44
"permission": {},
5-
"references": {
5+
// TODO: flip back to `references` once a release containing the v1 `reference` migration ships.
6+
// The release pipeline runs the latest published opencode against this file, which only knows `reference`.
7+
"reference": {
68
"effect": {
79
"repository": "github.com/Effect-TS/effect-smol",
810
"description": "Use for Effect v4 and effect-smol implementation details",

packages/core/src/v1/config/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export const Info = Schema.Struct({
4545
references: Schema.optional(ConfigReference.Info).annotate({
4646
description: "Named git or local directory references",
4747
}),
48+
reference: Schema.optional(ConfigReference.Info).annotate({
49+
description: "@deprecated Use 'references' field instead. Named git or local directory references",
50+
}),
4851
watcher: Schema.optional(Schema.Struct({ ignore: Schema.optional(Schema.mutable(Schema.Array(Schema.String))) })),
4952
snapshot: Schema.optional(Schema.Boolean).annotate({
5053
description:

packages/core/src/v1/config/migrate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const keys = new Set([
1212
"logLevel",
1313
"server",
1414
"command",
15+
"reference",
1516
"snapshot",
1617
"plugin",
1718
"autoshare",
@@ -62,7 +63,7 @@ export function migrate(info: typeof ConfigV1.Info.Type) {
6263
skills: info.skills && [...(info.skills.paths ?? []), ...(info.skills.urls ?? [])],
6364
commands: info.command,
6465
instructions: info.instructions,
65-
references: info.references,
66+
references: info.references ?? info.reference,
6667
plugins: info.plugin?.map((plugin) =>
6768
typeof plugin === "string" ? plugin : { package: plugin[0], options: plugin[1] },
6869
),

packages/core/test/config/config.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ describe("Config", () => {
7070
Effect.sync(() => {
7171
expect(ConfigMigrateV1.isV1({ snapshot: false })).toBe(true)
7272
expect(ConfigMigrateV1.isV1({ snapshot: false, agents: {} })).toBe(true)
73+
expect(ConfigMigrateV1.isV1({ reference: {} })).toBe(true)
7374
expect(ConfigMigrateV1.isV1({ shell: "/bin/zsh", model: "anthropic/claude" })).toBe(false)
75+
expect(ConfigMigrateV1.isV1({ references: {} })).toBe(false)
7476
}),
7577
)
7678

@@ -431,6 +433,42 @@ describe("Config", () => {
431433
),
432434
)
433435

436+
it.live("migrates the deprecated reference key into references", () =>
437+
Effect.acquireRelease(
438+
Effect.promise(() => tmpdir()),
439+
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
440+
).pipe(
441+
Effect.flatMap((tmp) =>
442+
Effect.gen(function* () {
443+
yield* Effect.promise(() =>
444+
fs.writeFile(
445+
path.join(tmp.path, "opencode.json"),
446+
JSON.stringify({
447+
reference: {
448+
local: { path: "../library" },
449+
sdk: { repository: "github.com/example/sdk", branch: "main" },
450+
shorthand: "github.com/example/docs",
451+
},
452+
}),
453+
),
454+
)
455+
456+
return yield* Effect.gen(function* () {
457+
const config = yield* Config.Service
458+
const documents = (yield* config.entries()).filter((entry) => entry.type === "document")
459+
460+
expect(documents).toHaveLength(1)
461+
expect(documents[0]?.info.references).toEqual({
462+
local: { path: "../library" },
463+
sdk: { repository: "github.com/example/sdk", branch: "main" },
464+
shorthand: "github.com/example/docs",
465+
})
466+
}).pipe(Effect.provide(testLayer(tmp.path)))
467+
}),
468+
),
469+
),
470+
)
471+
434472
it.live("migrates v1 configuration when a v1-only key is present", () =>
435473
Effect.acquireRelease(
436474
Effect.promise(() => tmpdir()),

packages/opencode/test/config/config.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,26 @@ it.instance("migrates mode field to agent field", () =>
722722
}),
723723
)
724724

725+
it.instance("accepts the deprecated reference field", () =>
726+
Effect.gen(function* () {
727+
const test = yield* TestInstance
728+
yield* writeConfigEffect(test.directory, {
729+
$schema: "https://opencode.ai/config.json",
730+
reference: {
731+
local: { path: "../library" },
732+
sdk: { repository: "github.com/example/sdk", branch: "main" },
733+
shorthand: "github.com/example/docs",
734+
},
735+
})
736+
const config = yield* Config.use.get()
737+
expect(config.reference).toEqual({
738+
local: { path: "../library" },
739+
sdk: { repository: "github.com/example/sdk", branch: "main" },
740+
shorthand: "github.com/example/docs",
741+
})
742+
}),
743+
)
744+
725745
it.instance("loads config from .opencode directory", () =>
726746
Effect.gen(function* () {
727747
const test = yield* TestInstance

packages/sdk/js/src/v2/gen/types.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,9 @@ export type Config = {
19311931
references?: {
19321932
[key: string]: string | ConfigV2ReferenceGit | ConfigV2ReferenceLocal
19331933
}
1934+
reference?: {
1935+
[key: string]: string | ConfigV2ReferenceGit | ConfigV2ReferenceLocal
1936+
}
19341937
watcher?: {
19351938
ignore?: Array<string>
19361939
}

0 commit comments

Comments
 (0)