Skip to content

Conversation

Flux159
Copy link

@Flux159 Flux159 commented Oct 16, 2025

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.

Flux159 and others added 5 commits October 15, 2025 18:19
- Add Template utility for processing bash commands in ! syntax
- Support file:// URLs in agent prompts for loading external files
- Enable dynamic content generation in system prompts using same logic as commands
- Add comprehensive tests covering templating, file loading, and error handling
- Backward compatible with existing static prompts
- Extend Template utility to support both shell (!) and file (@file) templating
- Handle non-git repositories by falling back to Instance.directory when worktree is root
- Add comprehensive tests for file references, directory listings, and combined templating
- Support tilde paths (~/.file) and graceful error handling for missing files
- Enable full command-style templating capabilities in agent system prompts
- Inline file:// URL processing and templating directly in resolveSystemPrompt
- Remove unnecessary resolveAgentPrompt helper function and _internal export
- Focus tests on Template utility rather than internal implementation details
- Maintain full functionality while improving code organization
- Clean up test structure and remove code smells
- Remove file:// URL handling as it's already processed elsewhere in the pipeline
- Keep only the Template.process call for bash commands and file references
- Simplify implementation to focus on core templating functionality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant