From 94eb30bb963c4de756e8ec88bd8c433b0fceb8dd Mon Sep 17 00:00:00 2001 From: "M. Adel Alhashemi" Date: Tue, 13 Jan 2026 05:07:15 +0300 Subject: [PATCH] fix(task): respect agent task permission for nested sub-agents The permission rework in #6319 removed the ability to override the default task tool restriction via agent frontmatter. This fix checks if the agent has any task permission rule defined. If so, we don't add our default deny - letting the agent's permission take effect. If not specified, the default deny behavior is preserved. --- packages/opencode/src/tool/task.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/opencode/src/tool/task.ts b/packages/opencode/src/tool/task.ts index 53b501ba91a..170d4448088 100644 --- a/packages/opencode/src/tool/task.ts +++ b/packages/opencode/src/tool/task.ts @@ -56,6 +56,9 @@ export const TaskTool = Tool.define("task", async (ctx) => { const agent = await Agent.get(params.subagent_type) if (!agent) throw new Error(`Unknown agent type: ${params.subagent_type} is not a valid agent type`) + + const hasTaskPermission = agent.permission.some((rule) => rule.permission === "task") + const session = await iife(async () => { if (params.session_id) { const found = await Session.get(params.session_id).catch(() => {}) @@ -76,11 +79,15 @@ export const TaskTool = Tool.define("task", async (ctx) => { pattern: "*", action: "deny", }, - { - permission: "task", - pattern: "*", - action: "deny", - }, + ...(hasTaskPermission + ? [] + : [ + { + permission: "task" as const, + pattern: "*" as const, + action: "deny" as const, + }, + ]), ...(config.experimental?.primary_tools?.map((t) => ({ pattern: "*", action: "allow" as const, @@ -146,7 +153,7 @@ export const TaskTool = Tool.define("task", async (ctx) => { tools: { todowrite: false, todoread: false, - task: false, + ...(hasTaskPermission ? {} : { task: false }), ...Object.fromEntries((config.experimental?.primary_tools ?? []).map((t) => [t, false])), }, parts: promptParts,