diff --git a/packages/core/src/schedule/check.ts b/packages/core/src/schedule/check.ts index 816422d13de..010262d2f4b 100644 --- a/packages/core/src/schedule/check.ts +++ b/packages/core/src/schedule/check.ts @@ -29,6 +29,8 @@ const CODE_LIMITS: CodeMode.ExecutionLimits = { } const FORBIDDEN_CODE_TOOLS = new Set([ + // Shell conditions approve the parsed commands; a code condition would approve any command it runs. + "shell", "opencode.schedule_create", "opencode.schedule_pause", "opencode.schedule_resume", diff --git a/packages/core/src/tool/plugin/shell.ts b/packages/core/src/tool/plugin/shell.ts index 0fa456f60a6..d4f8db5598f 100644 --- a/packages/core/src/tool/plugin/shell.ts +++ b/packages/core/src/tool/plugin/shell.ts @@ -7,7 +7,10 @@ import type { ShellCreateBefore } from "@opencode/plugin/effect/shell" import type { Shell as ShellSchema } from "@opencode/schema/shell" import type { Tool } from "@opencode/schema/tool" import { Clock, Deferred, Effect, Fiber, Option, Schema, Struct } from "effect" +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 { Job } from "../../job.js" import { FileAccess } from "../../file-access.js" import { Permission } from "../../permission.js" @@ -280,6 +283,11 @@ export const Plugin = { const shellSelect = yield* ShellSelect.Service const compatibleShell = shellSelect.resolve({ priority: "compat" }) 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 + const fullCodeMode = () => flags.resolve(loaded.entries).full_codemode.enabled const prepare = Effect.fn("ShellTool.prepare")(function* (invocation: ShellCreateBefore, context: Tool.Context) { const target = yield* access.resolve({ path: invocation.cwd, kind: "directory" }) @@ -346,7 +354,8 @@ export const Plugin = { .transform((editor) => editor.add({ name, - options: { codemode: false }, + // With full_codemode, shell is called as `tools.shell` inside `execute` instead of as a direct tool. + options: { codemode: fullCodeMode() }, description: description(), input: Input, output: StructuredOutput, diff --git a/packages/core/test/tool-shell.test.ts b/packages/core/test/tool-shell.test.ts index 881dc514e00..2518b6bf3f4 100644 --- a/packages/core/test/tool-shell.test.ts +++ b/packages/core/test/tool-shell.test.ts @@ -52,7 +52,7 @@ import { offlineModels } from "./fixture/models" import { testEffect } from "./lib/effect" import { permissionLayer } from "./lib/permission" import { Expected } from "./lib/session-message" -import { toolIdentity, executeTool, registerToolPlugin, toolDefinitions } from "./lib/tool" +import { codeModeListings, toolIdentity, executeTool, registerToolPlugin, toolDefinitions } from "./lib/tool" const sessionID = Session.ID.make("ses_shell_tool_test") const sessionModel = Model.Ref.make({ id: Model.ID.make("test"), providerID: Provider.ID.make("test") }) @@ -870,34 +870,38 @@ describe("ShellTool ordinary shell syntax", () => { }) describe("ShellTool", () => { - it.live("returns both parallel CodeMode shell results", () => + it.live("moves shell into Code Mode with full_codemode and returns both parallel results", () => withTempDir((tmp) => { reset() - return withSession(tmp.path, (registry) => - Effect.gen(function* () { - yield* registry.transform((editor) => - editor.update("shell", (tool) => { - tool.options = { ...tool.options, codemode: true } + return Effect.promise(() => + Bun.write(path.join(tmp.path, "opencode.json"), JSON.stringify({ experimental: { full_codemode: true } })), + ).pipe( + Effect.andThen( + withSession(tmp.path, (registry) => + Effect.gen(function* () { + const snapshot = yield* registry.snapshot() + expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["execute"]) + expect(codeModeListings(snapshot.codeModeCatalog!).map((entry) => entry.path)).toEqual(["shell"]) + const command = isWindows ? helloCommand : `${helloCommand}; sleep 0.1` + const inputs = ["one", "two"].map((text) => JSON.stringify({ command: command.replace("hello", text) })) + const result = yield* executeTool(registry, { + sessionID, + ...toolIdentity, + call: { + type: "tool-call", + id: "call-parallel-shells", + name: "execute", + input: { code: `return await Promise.all([tools.shell(${inputs[0]}), tools.shell(${inputs[1]})])` }, + }, + }).pipe(Effect.timeout("3 seconds")) + expect(result.status).toBe("completed") + expect(JSON.parse(result.output.output)).toEqual([ + { output: "one", exitCode: 0, wallTimeSeconds: expect.any(Number) }, + { output: "two", exitCode: 0, wallTimeSeconds: expect.any(Number) }, + ]) }), - ) - const command = isWindows ? helloCommand : `${helloCommand}; sleep 0.1` - const inputs = ["one", "two"].map((text) => JSON.stringify({ command: command.replace("hello", text) })) - const result = yield* executeTool(registry, { - sessionID, - ...toolIdentity, - call: { - type: "tool-call", - id: "call-parallel-shells", - name: "execute", - input: { code: `return await Promise.all([tools.shell(${inputs[0]}), tools.shell(${inputs[1]})])` }, - }, - }).pipe(Effect.timeout("3 seconds")) - expect(result.status).toBe("completed") - expect(JSON.parse(result.output.output)).toEqual([ - { output: "one", exitCode: 0, wallTimeSeconds: expect.any(Number) }, - { output: "two", exitCode: 0, wallTimeSeconds: expect.any(Number) }, - ]) - }), + ), + ), ) }), ) @@ -1241,6 +1245,7 @@ describe("ShellTool", () => { }), ), deps: [ + Config.node, Environment.node, FileAccess.node, Flag.node,