Skip to content

Commit a2c07ba

Browse files
authored
feat(core): enable opencode api in dev by default (#66924)
1 parent 86de9fe commit a2c07ba

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎packages/core/test/flag.test.ts‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ const document = (experimental?: ConstructorParameters<typeof ConfigExperimental
3030
info: new Info(experimental === undefined ? {} : { experimental: new ConfigExperimental.Info(experimental) }),
3131
})
3232

33-
// todo and opencode_api are opt-in only, so the build defaults and both wildcards leave them off.
34-
const every = (state: Flag.State): Record<Flag.Key, Flag.State> => ({
33+
// todo is opt-in only, so the build defaults and both wildcards leave it off.
34+
const every = (state: Flag.State, opencode_api: Flag.State = { enabled: false, source: "default" }): Record<Flag.Key, Flag.State> => ({
3535
...Record.map(ConfigFlag.registry, () => state),
3636
todo: { enabled: false, source: "default" },
37-
opencode_api: { enabled: false, source: "default" },
37+
opencode_api,
3838
})
3939

4040
describe("Flag.resolve", () => {
@@ -44,7 +44,9 @@ describe("Flag.resolve", () => {
4444
["latest", false],
4545
["unknown", false],
4646
] as const)("applies %s build defaults", (channel, enabled) => {
47-
expect(Flag.resolve({ entries: [], channel })).toEqual(every({ enabled, source: "default" }))
47+
expect(Flag.resolve({ entries: [], channel })).toEqual(
48+
every({ enabled, source: "default" }, { enabled, source: "default" }),
49+
)
4850
})
4951

5052
test.each(["todo"] as const)("%s is opt-in only: on only when named in OPENCODE_FLAGS or experimental.%s", (key) => {
@@ -62,14 +64,17 @@ describe("Flag.resolve", () => {
6264
})
6365
})
6466

65-
test("opencode_api turns on only by name, and only in local and dev builds", () => {
67+
test("opencode_api defaults to on in local and dev builds and stays unavailable in releases", () => {
6668
const resolve = (channel: string, overrides?: string, experimental?: { opencode_api?: boolean }) =>
6769
Flag.resolve({ entries: experimental ? [document(experimental)] : [], channel, overrides }).opencode_api
68-
expect(resolve("dev", "all")).toEqual({ enabled: false, source: "default" })
69-
expect(resolve("local", "opencode_api")).toEqual({ enabled: true, source: "env" })
70-
expect(resolve("dev", undefined, { opencode_api: true })).toEqual({ enabled: true, source: "config" })
70+
expect(resolve("local")).toEqual({ enabled: true, source: "default" })
71+
expect(resolve("dev")).toEqual({ enabled: true, source: "default" })
72+
expect(resolve("dev", "all")).toEqual({ enabled: true, source: "env" })
73+
expect(resolve("dev", "-opencode_api")).toEqual({ enabled: false, source: "env" })
74+
expect(resolve("dev", undefined, { opencode_api: false })).toEqual({ enabled: false, source: "config" })
7175
for (const channel of ["beta", "latest", "my-branch", "unknown"])
72-
expect([resolve(channel, "opencode_api"), resolve(channel, undefined, { opencode_api: true })]).toEqual([
76+
expect([resolve(channel), resolve(channel, "opencode_api"), resolve(channel, undefined, { opencode_api: true })]).toEqual([
77+
{ enabled: false, source: "default" },
7378
{ enabled: false, source: "default" },
7479
{ enabled: false, source: "default" },
7580
])
@@ -165,7 +170,7 @@ describe("Flag.resolve", () => {
165170

166171
test("experimental.all_flags: false is not a kill switch, and all_flags in OPENCODE_FLAGS does nothing", () => {
167172
expect(Flag.resolve({ entries: [document({ all_flags: false })], channel: "dev" })).toEqual(
168-
every({ enabled: true, source: "default" }),
173+
every({ enabled: true, source: "default" }, { enabled: true, source: "default" }),
169174
)
170175
expect(Flag.resolve({ entries: [], channel: "latest", overrides: "all_flags" })).toEqual(
171176
Flag.resolve({ entries: [], channel: "latest" }),

‎packages/schema/src/config/flag.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const registry = {
2323
project_overlay:
2424
"Load a personal config dir for each project from ~/.config/opencode/project/<project-id>/, read like an extra .opencode dir that ranks above the repo's own, and let home memory keep the skills it builds for the user there.",
2525
opencode_api:
26-
'Let Code Mode scripts call the OpenCode HTTP API with fetch("opencode:///api/..."), in-process and already signed in, with no permission checks. Only in local and dev builds, and off there until you opt in with OPENCODE_FLAGS=opencode_api or experimental.opencode_api: true.',
26+
'Let Code Mode scripts call the OpenCode HTTP API with fetch("opencode:///api/..."), in-process and already signed in, with calls checked as the equivalent opencode api shell command. On by default in local and dev builds and unavailable in releases.',
2727
mcp_skills:
2828
"Load skills from MCP servers that offer them (the io.modelcontextprotocol/skills extension), named <server>:<skill>. A server that offers skills no longer has its instructions included.",
2929
compaction_jobs:
@@ -38,7 +38,7 @@ export type Key = keyof typeof registry
3838
/** Flags the server reports to clients at `GET /api/experimental/flag`, so they can adapt their UI. */
3939
export const ui: readonly Key[] = ["full_codemode"]
4040

41-
export const optInOnly: ReadonlySet<Key> = new Set(["todo", "opencode_api"])
41+
export const optInOnly: ReadonlySet<Key> = new Set(["todo"])
4242

4343
/** Flags that stay off outside local and dev builds, whatever `OPENCODE_FLAGS` or config say. */
4444
export const localOnly: ReadonlySet<Key> = new Set(["opencode_api"])

0 commit comments

Comments
 (0)