feat(core): hide grep and glob when full_codemode is on (#64364)

This commit is contained in:
Aiden Cline
2026-11-16 23:58:35 -06:00
committed by GitHub
Unverified
parent eaa6075572
commit bb9d4e3562
3 changed files with 114 additions and 38 deletions
+11 -3
View File
@@ -6,7 +6,10 @@ import { Effect, Schema } from "effect"
import path from "path"
import { toolFailure } from "../runtime.js"
import { ToolSearch } from "../search.js"
import { Config } from "../../config.js"
import { ConfigEntryObserver } from "../../config/plugin/entry-observer.js"
import { Environment } from "../../environment/index.js"
import { Flag } from "../../flag.js"
import { FileSystem } from "../../filesystem.js"
import { Location } from "../../location.js"
import { FileAccess } from "../../file-access.js"
@@ -52,9 +55,14 @@ export const Plugin = {
const location = yield* Location.Service
const access = yield* FileAccess.Service
const permission = yield* Permission.Service
const config = yield* Config.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 flags = yield* Flag.Service
yield* ctx.tool
.transform((editor) =>
.transform((editor) => {
if (flags.resolve(loaded.entries).full_codemode.enabled) return
editor.add({
name,
options: { codemode: false },
@@ -111,8 +119,8 @@ export const Plugin = {
: toolFailure(`Unable to find files matching ${input.pattern}`)(error),
),
),
}),
)
})
})
.pipe(Effect.orDie)
}),
}
+11 -3
View File
@@ -4,7 +4,10 @@ import type { Context } from "@opencode/plugin/effect/plugin"
import { ToolFailure } from "@opencode/ai/effect"
import { Effect, Schema } from "effect"
import path from "path"
import { Config } from "../../config.js"
import { ConfigEntryObserver } from "../../config/plugin/entry-observer.js"
import { Environment } from "../../environment/index.js"
import { Flag } from "../../flag.js"
import { FileSystem } from "../../filesystem.js"
import { Location } from "../../location.js"
import { FileAccess } from "../../file-access.js"
@@ -70,9 +73,14 @@ export const Plugin = {
const location = yield* Location.Service
const access = yield* FileAccess.Service
const permission = yield* Permission.Service
const config = yield* Config.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 flags = yield* Flag.Service
yield* ctx.tool
.transform((editor) =>
.transform((editor) => {
if (flags.resolve(loaded.entries).full_codemode.enabled) return
editor.add({
name,
options: { codemode: false },
@@ -145,8 +153,8 @@ export const Plugin = {
return new ToolFailure({ message: `Unable to grep for ${input.pattern}`, error })
}),
),
}),
)
})
})
.pipe(Effect.orDie)
}),
}
+92 -32
View File
@@ -1,12 +1,17 @@
import { describe, expect } from "bun:test"
import fs from "fs/promises"
import path from "path"
import { Effect, Layer } from "effect"
import { Context, Effect, Layer, PubSub, Stream } from "effect"
import { Document, Info, type Entry } from "@opencode/schema/config"
import { Event } from "@opencode/schema/event"
import { ConfigExperimental } from "@opencode/schema/config/experimental"
import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
import { Config } from "@opencode/core/config"
import { makeLocationNode } from "@opencode/util/effect/app-node"
import { LayerNode } from "@opencode/util/effect/layer-node"
import { Environment } from "@opencode/core/environment/index"
import { FileSystem } from "@opencode/core/filesystem"
import { Flag } from "@opencode/core/flag"
import { Location } from "@opencode/core/location"
import { FileAccess } from "@opencode/core/file-access"
import { Permission } from "@opencode/core/permission"
@@ -20,45 +25,63 @@ import { location } from "./fixture/location"
import { tmpdir, tmpdirScoped, withTempDir } from "./fixture/tmpdir"
import { it } from "./lib/effect"
import { permissionLayer } from "./lib/permission"
import { executeTool, registerToolPlugin, toolIdentity } from "./lib/tool"
import { codeModeListings, executeTool, registerToolPlugin, toolIdentity, waitForTool } from "./lib/tool"
const globToolNode = makeLocationNode({
name: "test/glob-tool-plugin",
layer: Layer.effectDiscard(registerToolPlugin(GlobTool.Plugin)),
deps: [Tool.node, Environment.node, Ripgrep.node, Location.node, FileAccess.node, Permission.node],
})
const grepToolNode = makeLocationNode({
name: "test/grep-tool-plugin",
layer: Layer.effectDiscard(registerToolPlugin(GrepTool.Plugin)),
deps: [Tool.node, Environment.node, Ripgrep.node, Location.node, FileAccess.node, Permission.node],
})
const sessionID = Session.ID.make("ses_search_tool_test")
const configUpdated = () => ({ id: Event.ID.create(), created: Date.now(), type: "config.updated" as const, data: {} })
const withTools = <A, E, R>(
directory: string,
body: (registry: Tool.Interface) => Effect.Effect<A, E, R>,
body: (registry: Tool.Interface, configure: (entries: Entry[]) => Effect.Effect<void>) => Effect.Effect<A, E, R>,
assertions?: Permission.AssertInput[],
entries: Entry[] = [],
) =>
Effect.gen(function* () {
const registry = yield* Tool.Service
return yield* body(registry)
}).pipe(
Effect.provide(
AppNodeBuilder.build(LayerNode.group([Tool.node, globToolNode, grepToolNode]), [
Location.node.replace(
Layer.succeed(Location.Service, Location.Service.of(location({ directory: AbsolutePath.make(directory) }))),
),
Permission.node.replace(
permissionLayer({
assert: (input) =>
Effect.sync(() => {
assertions?.push(input)
}),
}),
),
]),
),
)
const config = yield* Layer.build(Config.testLayer(entries))
const updates = yield* PubSub.unbounded<ReturnType<typeof configUpdated>>()
const event = { subscribe: () => Stream.fromPubSub(updates) }
const configure = (next: Entry[]) =>
Context.get(config, Config.Test)
.setEntries(next)
.pipe(Effect.andThen(PubSub.publish(updates, configUpdated())), Effect.asVoid)
const searchToolsNode = makeLocationNode({
name: "test/search-tool-plugins",
layer: Layer.effectDiscard(
Effect.all([registerToolPlugin(GlobTool.Plugin, { event }), registerToolPlugin(GrepTool.Plugin, { event })]),
),
deps: [
Config.node,
Environment.node,
FileAccess.node,
Flag.node,
Location.node,
Permission.node,
Ripgrep.node,
Tool.node,
],
})
return yield* Effect.gen(function* () {
const registry = yield* Tool.Service
return yield* body(registry, configure)
}).pipe(
Effect.provide(
AppNodeBuilder.build(LayerNode.group([Tool.node, searchToolsNode]), [
Config.node.replace(Layer.succeedContext(config)),
Location.node.replace(
Layer.succeed(Location.Service, Location.Service.of(location({ directory: AbsolutePath.make(directory) }))),
),
Permission.node.replace(
permissionLayer({
assert: (input) =>
Effect.sync(() => {
assertions?.push(input)
}),
}),
),
]),
),
)
}).pipe(Effect.scoped)
const call = (name: "glob" | "grep", input: unknown) => ({
sessionID,
@@ -66,7 +89,44 @@ const call = (name: "glob" | "grep", input: unknown) => ({
call: { type: "tool-call" as const, id: `call-${name}`, name, input },
})
const fullCodeMode = new Document({
type: "document",
info: new Info({ experimental: new ConfigExperimental.Info({ full_codemode: true }) }),
})
const exposed = (registry: Tool.Interface) =>
registry
.snapshot()
.pipe(
Effect.map((snapshot) => [
...snapshot.definitions.map((tool) => tool.name),
...(snapshot.codeModeCatalog ? codeModeListings(snapshot.codeModeCatalog).map((entry) => entry.path) : []),
]),
)
describe("search tools", () => {
it.live("are absent with full_codemode and return when it is turned off", () =>
withTempDir((tmp) =>
withTools(
tmp.path,
(registry, configure) =>
Effect.gen(function* () {
const names = yield* exposed(registry)
expect(names).not.toContain("glob")
expect(names).not.toContain("grep")
expect(yield* executeTool(registry, call("grep", { pattern: "needle" }))).toMatchObject({ status: "error" })
yield* configure([])
yield* waitForTool(registry, "grep")
yield* waitForTool(registry, "glob")
expect(yield* exposed(registry)).toEqual(expect.arrayContaining(["glob", "grep"]))
}),
undefined,
[fullCodeMode],
),
),
)
for (const name of ["glob", "grep"] as const) {
it.live(`${name} distinguishes a malformed filename glob from an empty search`, () =>
withTempDir((tmp) =>