Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/core/src/tool/plugin/websearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import type { SessionHooks } from "@opencode/plugin/effect/session"
import { ToolFailure } from "@opencode/ai/effect"
import { Effect, Schema, Semaphore } from "effect"
import { HttpClientError } from "effect/http"
import { Config } from "../../config.js"
import { ConfigEntryObserver } from "../../config/plugin/entry-observer.js"
import { Flag } from "../../flag.js"
import { Form } from "../../form.js"
import { Permission } from "../../permission.js"
import { WebSearch } from "../../websearch.js"
Expand Down Expand Up @@ -39,12 +42,15 @@ export const Plugin = {
const permission = yield* Permission.Service
const forms = yield* Form.Service
const websearch = yield* WebSearch.Service
const config = yield* Config.Service
const loaded = yield* ConfigEntryObserver.observe(config, ctx.event, ctx.tool.reload())
const flags = yield* Flag.Service

yield* ctx.tool
.transform((editor) =>
editor.add({
name,
options: { codemode: false },
options: { codemode: flags.resolve(loaded.entries).full_codemode.enabled },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this is true, websearch isn't one of the direct definitions anymore, so the hook below (delete event.tools[name] when disabled or there are no providers) does nothing. event.tools only holds execute. I checked with Flag.Overrides = "full_codemode": after websearch.select(false) the hook leaves the tools unchanged, and the next snapshot's Code Mode catalog still lists tools.websearch(...). So after a user picks "Disable web search", or when policy removes every provider, the model is still offered a tool that always fails. That's the case the hook's comment says to avoid. The tool needs a way to be dropped from the Code Mode inventory in that state, for example by removing or re-adding the registration on ctx.tool.reload() when the provider or disabled state changes, or by filtering it in Tool.snapshot.

description,
input: Input,
output: Output,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/test/tool-websearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { describe, expect } from "bun:test"
import { Context, Effect, Layer } from "effect"
import type { HttpClientError } from "effect/http"
import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
import { Config } from "@opencode/core/config"
import { Flag } from "@opencode/core/flag"
import { LayerNode } from "@opencode/util/effect/layer-node"
import { Permission } from "@opencode/core/permission"
import { KV } from "@opencode/core/kv"
Expand Down Expand Up @@ -38,7 +40,7 @@ const webSearchToolNode = makeLocationNode({
})
}),
),
deps: [Tool.node, Permission.node, WebSearch.node, Form.node],
deps: [Tool.node, Permission.node, WebSearch.node, Form.node, Config.node, Flag.node],
})

const sessionID = Session.ID.make("ses_websearch_test")
Expand Down
Loading