Skip to content

Commit 2b7ee66

Browse files
committed
feat: inherit variant from parent session in subagent tasks
1 parent 4abf804 commit 2b7ee66

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

packages/opencode/src/tool/task.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export const TaskTool = Tool.define("task", async (ctx) => {
108108
providerID: msg.info.providerID,
109109
}
110110

111+
// Inherit variant from parent user message when subagent has no explicit variant
112+
const parentUser = await MessageV2.get({ sessionID: ctx.sessionID, messageID: msg.info.parentID })
113+
const variant = !agent.variant && parentUser.info.role === "user" ? parentUser.info.variant : undefined
114+
111115
ctx.metadata({
112116
title: params.description,
113117
metadata: {
@@ -133,6 +137,7 @@ export const TaskTool = Tool.define("task", async (ctx) => {
133137
providerID: model.providerID,
134138
},
135139
agent: agent.name,
140+
variant,
136141
tools: {
137142
todowrite: false,
138143
todoread: false,

packages/opencode/test/session/prompt-variant.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,31 @@ describe("session.prompt agent variant", () => {
5757
},
5858
})
5959
})
60+
61+
test("explicit variant input takes effect without agent variant config", async () => {
62+
await using tmp = await tmpdir({
63+
git: true,
64+
config: {},
65+
})
66+
67+
await Instance.provide({
68+
directory: tmp.path,
69+
fn: async () => {
70+
const session = await Session.create({})
71+
72+
// Simulates what task.ts does: passing parent's variant as explicit input
73+
const msg = await SessionPrompt.prompt({
74+
sessionID: session.id,
75+
agent: "general",
76+
variant: "high",
77+
noReply: true,
78+
parts: [{ type: "text", text: "hello" }],
79+
})
80+
if (msg.info.role !== "user") throw new Error("expected user message")
81+
expect(msg.info.variant).toBe("high")
82+
83+
await Session.remove(session.id)
84+
},
85+
})
86+
})
6087
})

0 commit comments

Comments
 (0)