Skip to content
Open
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
1 change: 1 addition & 0 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ export namespace Config {
.array(z.string())
.optional()
.describe("Tools that should only be available to primary agents."),
subagent_tools: z.array(z.string()).optional().describe("Tools that should only be available to subagents."),
continue_loop_on_deny: z.boolean().optional().describe("Continue the agent loop when a tool call is denied"),
mcp_timeout: z
.number()
Expand Down
8 changes: 8 additions & 0 deletions packages/opencode/src/tool/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,21 @@ export namespace ToolRegistry {

export async function tools(providerID: string, agent?: Agent.Info) {
const tools = await all()
const config = await Config.get()
const primaryTools = new Set(config.experimental?.primary_tools ?? [])
const subagentTools = new Set(config.experimental?.subagent_tools ?? [])

const result = await Promise.all(
tools
.filter((t) => {
// Enable websearch/codesearch for zen users OR via enable flag
if (t.id === "codesearch" || t.id === "websearch") {
return providerID === "opencode" || Flag.OPENCODE_ENABLE_EXA
}

if (agent?.mode === "subagent" && primaryTools.has(t.id)) return false
if (agent?.mode === "primary" && subagentTools.has(t.id)) return false

return true
})
.map(async (t) => {
Expand Down
6 changes: 0 additions & 6 deletions packages/opencode/src/tool/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ export const TaskTool = Tool.define("task", async (ctx) => {
pattern: "*",
action: "deny",
},
...(config.experimental?.primary_tools?.map((t) => ({
pattern: "*",
action: "allow" as const,
permission: t,
})) ?? []),
],
})
})
Expand Down Expand Up @@ -147,7 +142,6 @@ export const TaskTool = Tool.define("task", async (ctx) => {
todowrite: false,
todoread: false,
task: false,
...Object.fromEntries((config.experimental?.primary_tools ?? []).map((t) => [t, false])),
},
parts: promptParts,
})
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/js/src/v2/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,10 @@ export type Config = {
* Tools that should only be available to primary agents.
*/
primary_tools?: Array<string>
/**
* Tools that should only be available to subagents.
*/
subagent_tools?: Array<string>
/**
* Continue the agent loop when a tool call is denied
*/
Expand Down