Skip to content

Commit 5d37e58

Browse files
authored
fix(task): respect agent task permission for nested sub-agents (#8111)
1 parent 20088a8 commit 5d37e58

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/opencode/src/tool/task.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export const TaskTool = Tool.define("task", async (ctx) => {
5656

5757
const agent = await Agent.get(params.subagent_type)
5858
if (!agent) throw new Error(`Unknown agent type: ${params.subagent_type} is not a valid agent type`)
59+
60+
const hasTaskPermission = agent.permission.some((rule) => rule.permission === "task")
61+
5962
const session = await iife(async () => {
6063
if (params.session_id) {
6164
const found = await Session.get(params.session_id).catch(() => {})
@@ -76,11 +79,15 @@ export const TaskTool = Tool.define("task", async (ctx) => {
7679
pattern: "*",
7780
action: "deny",
7881
},
79-
{
80-
permission: "task",
81-
pattern: "*",
82-
action: "deny",
83-
},
82+
...(hasTaskPermission
83+
? []
84+
: [
85+
{
86+
permission: "task" as const,
87+
pattern: "*" as const,
88+
action: "deny" as const,
89+
},
90+
]),
8491
...(config.experimental?.primary_tools?.map((t) => ({
8592
pattern: "*",
8693
action: "allow" as const,
@@ -146,7 +153,7 @@ export const TaskTool = Tool.define("task", async (ctx) => {
146153
tools: {
147154
todowrite: false,
148155
todoread: false,
149-
task: false,
156+
...(hasTaskPermission ? {} : { task: false }),
150157
...Object.fromEntries((config.experimental?.primary_tools ?? []).map((t) => [t, false])),
151158
},
152159
parts: promptParts,

0 commit comments

Comments
 (0)