fix(core): expose code mode tools directly when execute is denied (#59315)

This commit is contained in:
Aiden Cline
2026-10-26 10:48:31 -05:00
committed by GitHub
Unverified
parent 1434464f7e
commit b2526211ec
4 changed files with 38 additions and 6 deletions
+2 -2
View File
@@ -92,8 +92,8 @@ export const layer = Layer.effect(
const visible = instructions
.flatMap((item) => {
const owned = tools.filter((tool) => tool.server === item.server)
const codemode = owned[0]?.codemode !== false
if (codemode && !canExecute) return []
// Without execute, Code Mode server tools are exposed directly.
const codemode = canExecute && owned[0]?.codemode !== false
if (
!owned.some(
(tool) =>
+5 -2
View File
@@ -255,10 +255,13 @@ const layer = Layer.effect(
if (whollyDisabled(tool.options?.permission ?? name, rules)) continue
active.set(name, tool)
}
const direct = new Map(Array.from(active).filter(([, tool]) => tool.options?.codemode === false))
const codeModeEnabled = !whollyDisabled("execute", rules)
// Without Code Mode its tools would be unreachable, so expose them as direct tools instead.
const direct = codeModeEnabled
? new Map(Array.from(active).filter(([, tool]) => tool.options?.codemode === false))
: active
const codeModeTools = new Map(Array.from(active).filter(([, tool]) => tool.options?.codemode !== false))
const names = Array.from(codeModeTools.keys()).join("\0")
const codeModeEnabled = !whollyDisabled("execute", rules)
// Discovery is immutable for a registry revision and visible tool set. Keep executors
// fresh, but share the inventory, whose prepared runtime and much larger rendered catalog
// are cached by identity, and the execute tool's definition across steps.
+10 -2
View File
@@ -65,14 +65,22 @@ describe("McpInstructions", () => {
),
)
it.effect("omits instructions when the agent cannot use execute", () =>
it.effect("lists Code Mode servers as direct tools when the agent cannot use execute", () =>
Effect.gen(function* () {
const service = yield* McpInstructions.Service
const generation = yield* service
.load([{ action: "execute", resource: "*", effect: "deny" }])
.pipe(Effect.flatMap(readInitial))
expect(generation.text).toBe("")
expect(generation.text).toBe(
[
"<mcp_instructions>",
' <server name="alpha">',
" Alpha instructions",
" </server>",
"</mcp_instructions>",
].join("\n"),
)
}).pipe(
Effect.provide(
layer(
+21
View File
@@ -707,6 +707,27 @@ describe("Tool", () => {
}),
)
it.effect("exposes Code Mode tools directly when execute is denied", () =>
Effect.gen(function* () {
const service = yield* Tool.Service
yield* transform(service, { lookup: make() }, { namespace: "mcp" })
yield* transform(service, { bash: make() }, { codemode: false })
const denyExecute: Permission.Ruleset = [{ action: "execute", resource: "*", effect: "deny" }]
const snapshot = yield* service.snapshot(denyExecute)
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["bash", "mcp_lookup"])
expect(snapshot.codeModeCatalog).toBeUndefined()
expect((yield* snapshot.execute(call("mcp_lookup"))).output).toEqual({ text: "mcp_lookup" })
const hidden = yield* service.snapshot([
...denyExecute,
{ action: "mcp_lookup", resource: "*", effect: "deny" },
])
expect(hidden.definitions.map((tool) => tool.name)).toEqual(["bash"])
expect(yield* hidden.execute(call("mcp_lookup")).pipe(Effect.flip)).toBeInstanceOf(Tool.Error)
}),
)
it.effect("filters disabled tools with edit aliases and ordered wildcard precedence", () =>
Effect.gen(function* () {
const service = yield* Tool.Service