diff --git a/packages/opencode/index.ts b/packages/opencode/index.ts index a7772c7..2a2076f 100644 --- a/packages/opencode/index.ts +++ b/packages/opencode/index.ts @@ -155,10 +155,10 @@ export async function getTaskToolExecution( let expandedCommand: CommandExecution | undefined; try { - expandedCommand = command - ? await expandSlashCommandPrompt(projectRoot, command, logger) - : prompt - ? await expandSlashCommandPrompt(projectRoot, prompt, logger) + expandedCommand = prompt + ? await expandSlashCommandPrompt(projectRoot, prompt, logger) + : command + ? await expandSlashCommandPrompt(projectRoot, command, logger) : undefined; } catch (error) { if (logger) { diff --git a/packages/opencode/test/task-hook.test.ts b/packages/opencode/test/task-hook.test.ts index 4e14c40..273ec77 100644 --- a/packages/opencode/test/task-hook.test.ts +++ b/packages/opencode/test/task-hook.test.ts @@ -38,6 +38,31 @@ describe("getTaskToolExecution", () => { assert.equal(output.args.prompt, execution?.prompt); }); + test("prefers the raw prompt over summarized command metadata", async () => { + const output = { + args: { + prompt: "/review auth bug with multiline\nextra context", + description: "Run review command", + subagent_type: "reviewer", + command: "@reviewer /review auth bug", + }, + }; + + const execution = await getTaskToolExecution( + { + tool: "task", + sessionID: "session-1", + callID: "call-1", + }, + output, + process.cwd(), + ); + + assert.equal(execution?.command_name, "review"); + assert.equal(execution?.command_arguments, "auth bug with multiline\nextra context"); + assert.match(execution?.prompt ?? "", /\s*auth bug with multiline\nextra context\s*<\/arguments>/); + }); + test("ignores non-task tool calls", async () => { const execution = await getTaskToolExecution( { @@ -101,6 +126,34 @@ describe("getTaskToolExecution", () => { subagent_type: undefined, }); }); + + test("falls back to command metadata when prompt is missing", async () => { + const output = { + args: { + prompt: undefined, + command: "/branch Branch naming guidance: fix login redirect", + description: "Create feature branch", + subagent_type: "worker", + }, + }; + + const execution = await getTaskToolExecution( + { + tool: "task", + sessionID: "session-1", + callID: "call-1", + }, + output, + process.cwd(), + ); + + assert.equal(execution?.command, "/branch Branch naming guidance: fix login redirect"); + assert.equal(execution?.command_name, "branch"); + assert.equal(execution?.command_arguments, "Branch naming guidance: fix login redirect"); + assert.match(execution?.prompt ?? "", /## Goal/); + assert.match(execution?.prompt ?? "", /\s*Branch naming guidance: fix login redirect\s*<\/arguments>/); + assert.equal(output.args.prompt, execution?.prompt); + }); }); describe("expandSlashCommandPrompt", () => {