effect: move tool flags into RuntimeFlags (#27198)

This commit is contained in:
Kit Langton
2026-05-12 21:45:53 -04:00
committed by GitHub
parent c9df833d2c
commit da689d77c4
7 changed files with 88 additions and 47 deletions
+10 -11
View File
@@ -24,7 +24,6 @@ import { ProviderID, type ModelID } from "../provider/schema"
import { WebSearchTool } from "./websearch"
import { RepoCloneTool } from "./repo_clone"
import { RepoOverviewTool } from "./repo_overview"
import { Flag } from "@opencode-ai/core/flag/flag"
import * as Log from "@opencode-ai/core/util/log"
import { LspTool } from "./lsp"
import * as Truncate from "./truncate"
@@ -50,13 +49,11 @@ import { Git } from "@/git"
import { Skill } from "../skill"
import { Permission } from "@/permission"
import { Reference } from "@/reference/reference"
import { RuntimeFlags } from "@/effect/runtime-flags"
const log = Log.create({ service: "tool.registry" })
export function webSearchEnabled(
providerID: ProviderID,
flags = { exa: Flag.OPENCODE_ENABLE_EXA, parallel: Flag.OPENCODE_ENABLE_PARALLEL },
) {
export function webSearchEnabled(providerID: ProviderID, flags = { exa: false, parallel: false }) {
return providerID === ProviderID.opencode || flags.exa || flags.parallel
}
@@ -101,6 +98,7 @@ export const layer: Layer.Layer<
| Ripgrep.Service
| Format.Service
| Truncate.Service
| RuntimeFlags.Service
> = Layer.effect(
Service,
Effect.gen(function* () {
@@ -109,6 +107,7 @@ export const layer: Layer.Layer<
const agents = yield* Agent.Service
const skill = yield* Skill.Service
const truncate = yield* Truncate.Service
const flags = yield* RuntimeFlags.Service
const invalid = yield* InvalidTool
const task = yield* TaskTool
@@ -209,8 +208,7 @@ export const layer: Layer.Layer<
}
yield* config.get()
const questionEnabled =
["app", "cli", "desktop"].includes(Flag.OPENCODE_CLIENT) || Flag.OPENCODE_ENABLE_QUESTION_TOOL
const questionEnabled = ["app", "cli", "desktop"].includes(flags.client) || flags.enableQuestionTool
const tool = yield* Effect.all({
invalid: Tool.init(invalid),
@@ -248,11 +246,11 @@ export const layer: Layer.Layer<
tool.fetch,
tool.todo,
tool.search,
...(Flag.OPENCODE_EXPERIMENTAL_SCOUT ? [tool.repo_clone, tool.repo_overview] : []),
...(flags.experimentalScout ? [tool.repo_clone, tool.repo_overview] : []),
tool.skill,
tool.patch,
...(Flag.OPENCODE_EXPERIMENTAL_LSP_TOOL ? [tool.lsp] : []),
...(Flag.OPENCODE_EXPERIMENTAL_PLAN_MODE && Flag.OPENCODE_CLIENT === "cli" ? [tool.plan] : []),
...(flags.experimentalLspTool ? [tool.lsp] : []),
...(flags.experimentalPlanMode && flags.client === "cli" ? [tool.plan] : []),
],
task: tool.task,
read: tool.read,
@@ -306,7 +304,7 @@ export const layer: Layer.Layer<
const tools: Interface["tools"] = Effect.fn("ToolRegistry.tools")(function* (input) {
const filtered = (yield* all()).filter((tool) => {
if (tool.id === WebSearchTool.id) {
return webSearchEnabled(input.providerID)
return webSearchEnabled(input.providerID, { exa: flags.enableExa, parallel: flags.enableParallel })
}
const usePatch =
@@ -380,6 +378,7 @@ export const defaultLayer = Layer.suspend(() =>
Layer.provide(CrossSpawnSpawner.defaultLayer),
Layer.provide(Ripgrep.defaultLayer),
Layer.provide(Truncate.defaultLayer),
Layer.provide(RuntimeFlags.defaultLayer),
),
)