Skip to content
Merged
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
8 changes: 4 additions & 4 deletions packages/opencode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
53 changes: 53 additions & 0 deletions packages/opencode/test/task-hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "", /<arguments>\s*auth bug with multiline\nextra context\s*<\/arguments>/);
});

test("ignores non-task tool calls", async () => {
const execution = await getTaskToolExecution(
{
Expand Down Expand Up @@ -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 ?? "", /<arguments>\s*Branch naming guidance: fix login redirect\s*<\/arguments>/);
assert.equal(output.args.prompt, execution?.prompt);
});
});

describe("expandSlashCommandPrompt", () => {
Expand Down
Loading