From 3dc79ab657eb9ad8369bb4b52da2b9aa0cc1279b Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Mon, 9 Nov 2026 23:06:18 -0600 Subject: [PATCH] fix(core): put Console event watches behind the console_watches flag (#63036) --- packages/client/src/promise/generated/types.ts | 1 + packages/core/src/plugin/provider/opencode.ts | 9 +++++++-- .../plugin/provider-opencode-watches.test.ts | 18 ++++++++++++++++-- packages/protocol/openapi.json | 3 +++ packages/schema/src/config/flag.ts | 2 ++ 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/client/src/promise/generated/types.ts b/packages/client/src/promise/generated/types.ts index 45c7dcc720e..a34feed23e8 100644 --- a/packages/client/src/promise/generated/types.ts +++ b/packages/client/src/promise/generated/types.ts @@ -2552,6 +2552,7 @@ export type ConfigEntry = schedules?: boolean artifacts?: boolean codemode_vm?: boolean + console_watches?: boolean part_rows?: boolean image_generate?: boolean | { model?: string | { providerID: string; model: string; variant?: string } } subagent_depth?: number diff --git a/packages/core/src/plugin/provider/opencode.ts b/packages/core/src/plugin/provider/opencode.ts index a4d4c0c652f..159ece15cd7 100644 --- a/packages/core/src/plugin/provider/opencode.ts +++ b/packages/core/src/plugin/provider/opencode.ts @@ -20,6 +20,7 @@ import { ConfigProviderPlugin } from "../../config/plugin/provider.js" import { SkillFile } from "../../config/plugin/skill-file.js" import { ConsoleAccess } from "../../console-access.js" import { Credential } from "../../credential.js" +import { Flag } from "../../flag.js" import { InstructionDiscovery } from "../../instruction-discovery.js" import { Integration } from "../../integration.js" import { IntegrationConnection } from "../../integration/connection.js" @@ -179,6 +180,7 @@ export const OpencodePlugin = define< | HttpClient.HttpClient | Bus.Service | Config.Service + | Flag.Service | InstructionDiscovery.Service | SharedCache.Service | Skill.Service @@ -192,6 +194,7 @@ export const OpencodePlugin = define< // and whether it evaluates the policies it is being sent. const http = HttpClient.mapRequest(client, HttpClientRequest.setHeader("User-Agent", App.useragent(ctx.app))) const config = yield* Config.Service + const flags = yield* Flag.Service const discovery = yield* InstructionDiscovery.Service const skills = yield* Skill.Service const cache = yield* SharedCache.Service @@ -331,9 +334,11 @@ export const OpencodePlugin = define< // content. const allowed = document !== undefined && (!config.integration || isDeepStrictEqual(integrated, document)) yield* syncInstructionsAndSkills(next, allowed) - yield* syncWatches(allowed && next.remote?.watches === true ? next.connection : undefined) + const watching = allowed && next.remote?.watches === true && (yield* flags.enabled("console_watches")) + yield* syncWatches(watching ? next.connection : undefined) }) - // Watching starts when the Console's config says the workspace has event watches, and stops when it no longer does. + // Watching starts when the console_watches flag is on and the Console's config says the workspace has event watches, + // and stops when either no longer holds. const syncWatches = Effect.fnUntraced( function* (connection: ActiveConnection) { const credential = connection && (yield* ctx.integration.connection.resolve(connection)) diff --git a/packages/core/test/plugin/provider-opencode-watches.test.ts b/packages/core/test/plugin/provider-opencode-watches.test.ts index 4c3dbcf011e..bdfd437ec4e 100644 --- a/packages/core/test/plugin/provider-opencode-watches.test.ts +++ b/packages/core/test/plugin/provider-opencode-watches.test.ts @@ -1,8 +1,9 @@ import { describe, expect } from "bun:test" import type { Plugin as PluginContext } from "@opencode/plugin/effect" -import { Effect } from "effect" +import { Effect, Layer } from "effect" import { TestClock } from "effect/testing" import { Credential } from "@opencode/core/credential" +import { Flag } from "@opencode/core/flag" import { Integration } from "@opencode/core/integration" import { Plugin } from "@opencode/core/plugin" import { PluginHooks } from "@opencode/core/plugin/hooks" @@ -18,7 +19,9 @@ import { eventually, waitUntil } from "../lib/eventually" import { testEffect } from "../lib/effect" import { PluginTestLayer } from "./fixture" -const it = testEffect(PluginTestLayer) +const withFlags = (overrides: string) => testEffect(PluginTestLayer.pipe(Layer.provide(Layer.succeed(Flag.Overrides, overrides)))) +const it = withFlags("console_watches") +const released = withFlags("-console_watches") type Synthetic = Parameters[0] type WatchEvent = ReturnType @@ -267,6 +270,17 @@ describe("OpencodePlugin event watches", () => { ), ) + released.effect("stays dormant without the console_watches flag, even when the Console advertises event watches", () => + withConsole({}, (console) => + Effect.gen(function* () { + yield* start(console) + yield* Effect.promise(() => Bun.sleep(100)) + expect(yield* watchTools).toEqual([]) + expect(console.state.opens).toBe(0) + }), + ), + ) + it.effect("registers the console_watch tools while watches are on", () => withConsole({}, (console) => Effect.gen(function* () { diff --git a/packages/protocol/openapi.json b/packages/protocol/openapi.json index 63554969d4f..116829325d3 100644 --- a/packages/protocol/openapi.json +++ b/packages/protocol/openapi.json @@ -16666,6 +16666,9 @@ "codemode_vm": { "type": "boolean" }, + "console_watches": { + "type": "boolean" + }, "part_rows": { "type": "boolean" }, diff --git a/packages/schema/src/config/flag.ts b/packages/schema/src/config/flag.ts index 633618464fb..dc296f9c660 100644 --- a/packages/schema/src/config/flag.ts +++ b/packages/schema/src/config/flag.ts @@ -16,5 +16,7 @@ export const registry = { schedules: "Enable experimental scheduled tasks that wake a session with a prompt.", artifacts: "Enable experimental artifacts backed by pluggable providers.", codemode_vm: "Run the Code Mode execute tool on the experimental bytecode VM instead of the legacy interpreter.", + console_watches: + "Watch Slack threads, GitHub pull requests, issues, commits and Actions runs, and the workspace's MCP servers' events through OpenCode Console, and wake sessions when they change.", } as const satisfies Record export type Key = keyof typeof registry