Skip to content

Commit 8b7f473

Browse files
EvgeniyEvgeniy
authored andcommitted
fix: concatenate system prompt instead of push to preserve agent prompts
When using custom OpenCode agents (defined in ~/.config/opencode/agents/), output.system.push() creates a second element in the system[] array. OpenCode maps each element to a separate {role: 'system'} message, and providers only respect the last one — which drops the agent prompt. Fix: concatenate DCP prompt to system[0] instead of pushing a new element. Tested: isolated A/B test confirmed push() breaks agent prompt, concatenation preserves it.
1 parent 11e3774 commit 8b7f473

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

lib/hooks.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ export function createSystemPromptHandler(
9292
return
9393
}
9494

95-
output.system.push(renderSystemPrompt(flags))
95+
// Concatenate to system[0] instead of push() to avoid creating
96+
// multiple {role: "system"} messages. OpenCode maps each system[]
97+
// element to a separate system message, and providers typically
98+
// only respect the last one — which drops the agent prompt.
99+
if (output.system.length > 0) {
100+
output.system[0] += "\n\n" + renderSystemPrompt(flags)
101+
} else {
102+
output.system.push(renderSystemPrompt(flags))
103+
}
96104
}
97105
}
98106

0 commit comments

Comments
 (0)