fix(core): put Console event watches behind the console_watches flag (#63036)

This commit is contained in:
Aiden Cline
2026-11-09 23:06:18 -06:00
committed by GitHub
Unverified
parent c3eadb976a
commit 3dc79ab657
5 changed files with 29 additions and 4 deletions
+1
View File
@@ -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
@@ -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))
@@ -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<PluginContext.Context["session"]["synthetic"]>[0]
type WatchEvent = ReturnType<typeof watchEvent>
@@ -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* () {
+3
View File
@@ -16666,6 +16666,9 @@
"codemode_vm": {
"type": "boolean"
},
"console_watches": {
"type": "boolean"
},
"part_rows": {
"type": "boolean"
},
+2
View File
@@ -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<string, string>
export type Key = keyof typeof registry