mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
fix(core): keep todo opt-in only (#64775)
This commit is contained in:
parent
88ca792e02
commit
56dc95bff5
7 changed files with 45 additions and 21 deletions
|
|
@ -182,8 +182,8 @@ const table = sqliteTable("session", {
|
|||
|
||||
- When you open a PR, decide whether the change needs a flag: new user-visible behavior, risky core changes, and anything not ready to release get one; fixes, refactors, docs and tests do not.
|
||||
- Gate risky behavior, or behavior that lands over several PRs, with a key and a description in `packages/schema/src/config/flag.ts`, and read it with `Flag.enabled("<key>")` from `@opencode/core/flag`.
|
||||
- Flags default to on in local and dev builds and off in releases; `experimental.<key>` in config and `OPENCODE_FLAGS="key,-other"` override that.
|
||||
- Say in the PR body which flag guards the change. The reserved switches `OPENCODE_FLAGS=all` and `experimental.all_flags: true` enable every flag; use `all,-<key>` or `experimental.<key>: false` to opt out within the respective source.
|
||||
- Flags default to on in local and dev builds and off in releases, except `optInOnly` flags (such as `todo`), which require an explicit `OPENCODE_FLAGS=<key>` or `experimental.<key>: true` in every build.
|
||||
- Say in the PR body which flag guards the change. The reserved switches `OPENCODE_FLAGS=all` and `experimental.all_flags: true` skip opt-in-only flags; use `all,-<key>` or `experimental.<key>: false` to opt out within the respective source.
|
||||
- Ship a feature by deleting its flag and the checks that read it.
|
||||
|
||||
## Testing
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/Fl
|
|||
|
||||
/**
|
||||
* `OPENCODE_FLAGS`, a comma-separated list such as `automations,-media_blob`; a leading `-` turns a flag off, and
|
||||
* `all` turns every flag on unless the same list opts one out, as in `all,-media_blob`.
|
||||
* `all` enables all flags except opt-in-only flags and any disabled in the same list, as in `all,-media_blob`.
|
||||
*/
|
||||
export const Overrides = Context.Reference<string | undefined>("@opencode/Flag/Overrides", {
|
||||
defaultValue: () => process.env.OPENCODE_FLAGS,
|
||||
|
|
@ -39,6 +39,7 @@ const onByDefault = (channel: string) => channel === "local" || channel === "dev
|
|||
* document that sets `experimental` (the same document every other `experimental` setting reads), then `all_flags: true`
|
||||
* from the highest-priority document that sets `all_flags`, so a global switch survives a project's own `experimental`
|
||||
* block, then on for local and dev builds. `all_flags: false` falls through rather than turning flags off.
|
||||
* Opt-in-only flags skip both wildcards and default to off on every channel.
|
||||
* A remote kill switch belongs above `OPENCODE_FLAGS` here.
|
||||
*/
|
||||
export function resolve(input: {
|
||||
|
|
@ -61,17 +62,19 @@ export function resolve(input: {
|
|||
)?.info.experimental?.all_flags === true
|
||||
const names = Object.keys(ConfigFlag.aliases) as Array<keyof typeof ConfigFlag.aliases>
|
||||
return Record.map(ConfigFlag.registry, (_, key): State => {
|
||||
const optInOnly = ConfigFlag.optInOnly.has(key)
|
||||
const old = names.find((name) => ConfigFlag.aliases[name] === key)
|
||||
const override = env.get(key) ?? (old === undefined ? undefined : env.get(old)) ?? (all ? true : undefined)
|
||||
const override =
|
||||
env.get(key) ?? (old === undefined ? undefined : env.get(old)) ?? (all && !optInOnly ? true : undefined)
|
||||
const value = experimental?.[key] ?? (old === undefined ? undefined : experimental?.[old])
|
||||
// A flag that takes settings is on when given them.
|
||||
const configured = typeof value === "object" ? true : (value ?? (allFlags ? true : undefined))
|
||||
const configured = typeof value === "object" ? true : (value ?? (allFlags && !optInOnly ? true : undefined))
|
||||
const [enabled, source]: [boolean, State["source"]] =
|
||||
override !== undefined
|
||||
? [override, "env"]
|
||||
: configured !== undefined
|
||||
? [configured, "config"]
|
||||
: [onByDefault(input.channel), "default"]
|
||||
: [!optInOnly && onByDefault(input.channel), "default"]
|
||||
return { enabled, source }
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import type { Context } from "@opencode/plugin/effect/plugin"
|
|||
import { Effect, Schema } from "effect"
|
||||
import { Config } from "../../config.js"
|
||||
import { ConfigEntryObserver } from "../../config/plugin/entry-observer.js"
|
||||
import { Flag } from "../../flag.js"
|
||||
import { Permission } from "../../permission.js"
|
||||
import DESCRIPTION from "../todowrite.txt"
|
||||
|
||||
|
|
@ -47,7 +48,8 @@ export const Plugin = {
|
|||
const permission = yield* Permission.Service
|
||||
// Internal plugins are not re-run on config changes, so reload the tool transform instead.
|
||||
const loaded = yield* ConfigEntryObserver.observe(config, ctx.event, ctx.tool.reload())
|
||||
const enabled = () => Config.latest(loaded.entries, "experimental")?.todo === true
|
||||
const flags = yield* Flag.Service
|
||||
const enabled = () => flags.resolve(loaded.entries).todo.enabled
|
||||
|
||||
yield* ctx.tool
|
||||
.transform((editor) => {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,11 @@ const document = (experimental?: ConstructorParameters<typeof ConfigExperimental
|
|||
info: new Info(experimental === undefined ? {} : { experimental: new ConfigExperimental.Info(experimental) }),
|
||||
})
|
||||
|
||||
const every = (state: Flag.State) => Record.map(ConfigFlag.registry, () => state)
|
||||
// todo is opt-in only, so the build defaults and both wildcards leave it off.
|
||||
const every = (state: Flag.State): Record<Flag.Key, Flag.State> => ({
|
||||
...Record.map(ConfigFlag.registry, () => state),
|
||||
todo: { enabled: false, source: "default" },
|
||||
})
|
||||
|
||||
describe("Flag.resolve", () => {
|
||||
test.each([
|
||||
|
|
@ -40,6 +44,21 @@ describe("Flag.resolve", () => {
|
|||
expect(Flag.resolve({ entries: [], channel })).toEqual(every({ enabled, source: "default" }))
|
||||
})
|
||||
|
||||
test("todo is opt-in only: on only when named in OPENCODE_FLAGS or experimental.todo", () => {
|
||||
expect(Flag.resolve({ entries: [], channel: "dev", overrides: "all" }).todo).toEqual({
|
||||
enabled: false,
|
||||
source: "default",
|
||||
})
|
||||
expect(Flag.resolve({ entries: [], channel: "latest", overrides: "todo" }).todo).toEqual({
|
||||
enabled: true,
|
||||
source: "env",
|
||||
})
|
||||
expect(Flag.resolve({ entries: [document({ todo: true })], channel: "latest" }).todo).toEqual({
|
||||
enabled: true,
|
||||
source: "config",
|
||||
})
|
||||
})
|
||||
|
||||
test("full_codemode defaults to on in local and dev builds, off in releases, and follows overrides and wildcards", () => {
|
||||
expect(Flag.resolve({ entries: [], channel: "local" }).full_codemode).toEqual({
|
||||
enabled: true,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { describe, expect } from "bun:test"
|
||||
import { Effect, Stream } from "effect"
|
||||
import { Config } from "@opencode/core/config"
|
||||
import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
|
||||
import { Flag } from "@opencode/core/flag"
|
||||
import { Session } from "@opencode/core/session"
|
||||
import { Tool } from "@opencode/core/tool"
|
||||
import { TodoTool } from "@opencode/core/tool/plugin/todo"
|
||||
|
|
@ -25,7 +25,7 @@ const it = testEffect(AppNodeBuilder.build(Tool.node, toolNodeReplacements()))
|
|||
const setup = (experimental: ConfigExperimental.Info | undefined) =>
|
||||
Effect.gen(function* () {
|
||||
yield* registerToolPlugin(TodoTool.Plugin, { event: { subscribe: () => Stream.never } }).pipe(
|
||||
Effect.provide(Config.testLayer([document(experimental)])),
|
||||
Effect.provide(Flag.testLayer([document(experimental)])),
|
||||
Effect.provide(permissionLayer({ assert: () => Effect.void })),
|
||||
)
|
||||
return yield* Tool.Service
|
||||
|
|
@ -39,7 +39,6 @@ describe("TodoTool", () => {
|
|||
Effect.gen(function* () {
|
||||
expect(yield* names(yield* setup(undefined))).not.toContain(TodoTool.name)
|
||||
expect(yield* names(yield* setup(new ConfigExperimental.Info({ todo: false })))).not.toContain(TodoTool.name)
|
||||
expect(yield* names(yield* setup(new ConfigExperimental.Info({ all_flags: true })))).not.toContain(TodoTool.name)
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,14 +15,13 @@ export class Info extends Schema.Class<Info>("ConfigExperimental.Info")({
|
|||
}),
|
||||
all_flags: Schema.Boolean.pipe(optional).annotate({
|
||||
description:
|
||||
"Turn every feature flag on regardless of the build channel, like OPENCODE_FLAGS=all; explicit per-flag settings still win, and false is not a kill switch.",
|
||||
"Enable all flags except opt-in-only flags on any build channel, like OPENCODE_FLAGS=all. Per-flag config settings take precedence over all_flags; false leaves the build defaults in effect.",
|
||||
}),
|
||||
todo: Schema.Boolean.pipe(optional).annotate({
|
||||
description: "Enable the experimental todowrite tool. Defaults to false.",
|
||||
}),
|
||||
...Record.map(ConfigFlag.registry, (description) =>
|
||||
...Record.map(ConfigFlag.registry, (description, key) =>
|
||||
Schema.Boolean.pipe(optional).annotate({
|
||||
description: `${description} Defaults to on in local and dev builds and off in releases.`,
|
||||
description: ConfigFlag.optInOnly.has(key)
|
||||
? description
|
||||
: `${description} Defaults to on in local and dev builds and off in releases.`,
|
||||
}),
|
||||
),
|
||||
// The flag also takes settings; an object turns it on.
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
export * as ConfigFlag from "./flag.js"
|
||||
|
||||
/** The `OPENCODE_FLAGS` entry that turns every flag on, as in `all,-media_blob`. It is not a flag key. */
|
||||
/** The `OPENCODE_FLAGS` entry that enables all flags except opt-in-only flags, as in `all,-media_blob`. */
|
||||
export const wildcard = "all"
|
||||
|
||||
/**
|
||||
* Every feature flag, by key, with what it turns on. Flags default to on in local and dev builds and off in releases;
|
||||
* `experimental.<key>` in config and `OPENCODE_FLAGS` override that, and `OPENCODE_FLAGS=all` or
|
||||
* `experimental.all_flags: true` turn every flag on. Read one with Core's `Flag.enabled("<key>")`.
|
||||
* Flags default to on in local and dev builds and off in releases, except for `optInOnly` flags, which must be
|
||||
* named explicitly in `experimental.<key>` or `OPENCODE_FLAGS`. Read a flag with Core's `Flag.enabled("<key>")`.
|
||||
*/
|
||||
export const registry = {
|
||||
todo: "Enable the experimental todowrite tool. Off by default in every build, including local and dev; opt in with OPENCODE_FLAGS=todo or experimental.todo: true.",
|
||||
media_blob: "Store new session media once in a deduplicated blob table instead of inline in every message row.",
|
||||
automations:
|
||||
"Run a prompt or Code Mode action on a timer, or on a connected MCP server's push event when mcp_events is enabled.",
|
||||
|
|
@ -23,6 +23,8 @@ export const registry = {
|
|||
} as const satisfies Record<string, string>
|
||||
export type Key = keyof typeof registry
|
||||
|
||||
export const optInOnly: ReadonlySet<Key> = new Set(["todo"])
|
||||
|
||||
/** Earlier names of a flag, still read from `experimental.<name>` and `OPENCODE_FLAGS` when the new key is unset. */
|
||||
export const aliases = {
|
||||
schedules: "automations",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue