opencode
opencode copied to clipboard
Dynamic system prompt templating
Summary:
Adding the ability to parse markdown templating for agent system prompts. Specifically adds ability to parse ! and @ references inside of agent prompts.
This PR adds a helper util/template.ts that handles both bash & file reference templates, then uses this inside of session/prompt.ts. The rest is just automated testing for the functionality.
This is specifically for #3195
Test plan:
Manually tested by making a custom agent inside of .opencode/agent/test.md with the following contents:
---
model: anthropic/claude-sonnet-4-20250514
---
You are a test agent with dynamic templating. Your magic phrase is: !`echo $(whoami)-magic`
You should respond with your magic phrase when asked about it.
Then opening opencode dev mode: bun dev, switching to the test agent via /agents, then asking "What is your magic phrase" and it responded with my username-magic as expected.