Construct agent and skill files from common templates#3
Conversation
Currently this plugin is available for both copilot and claude code. Both services expect different YAML headers in the agent files. To reduce duplication, this commit introduces common templates that are then dynamically specialized for each service. It does this using jinja2 and a python script that produces the final agent and skill files under a `./out/<product>` directory. E.g. the copilot agent files live under `./out/copilot/plugin/proof-copilot/agents`.
|
Hi @klinvill I am not seeing the duplication you identified, can you reply with maybe two duplicate files? Using Jinja here seems like a good idea, but still if we can avoid the CI indirection that would be best. |
|
Sure! They're not exact duplicates, but the fstar-coder.agent.md and fstar-coder.md files differ only in the headers. Specifically, diffing those two files gives the following output: Regarding avoiding CI indirection, another option is to just manually regenerate any vendor-specialized agent and skill finals with each commit (could maybe use a git hook?). My preference is to not have any generated/output static files in the branch that people commit and merge to, and to have a separate deploy branch that is only ever written to by a CI job that is triggered any time the main branch receives new commits (this is effectively the workflow I use for my personal website). There are definitely other valid options though that avoid CI but come with their own tradeoffs (like the use of local git hooks). Note that this draft PR doesn't currently add any additional instrumentation like hooks or CI, so I'm happy to update it or feel free to fork it off yourself to experiment with if the templating is a useful start! |
@elefthei currently there's some duplication in the agent files. This is only two copies of one file so it's not too bad to manage, but I wanted to open this draft PR to surface what my previous comment (in #1) about potentially using common templates could look like. Granted, it adds a lot of extra boilerplate and a github action should be created to automatically run the python script that generates the latest output agent and skill files, then push those files to a deployment branch that the plugins can be pulled from. Any thoughts on if this is a desirable direction to go (avoiding duplication for agent files) or if it's just overkill for the current plugins?
This draft adds in a jinja template for the agent file (under
templates/agents/fstar-coder.md.j2). The template accepts a key-value dictionary of header entries and renders it as a YAML header. This draft also adds a python script (generate_plugins.py) that reads custom headers for each vendor (e.g.templates/agents/claude.headers.yaml) and injects them into a rendered agent file for that specific vendor (copilot or claude). The rendered files are saved under theout/<vendor>directory, so currently the rendered copilot agent files get saved to theout/copilot/plugins/proof-copilot/agents/directory. Having a separate output directory makes it easy to ensure that files meant for a different vendor do not end up getting installed along with the plugin (I believe claude code will currently pull thefstar-coder.agent.mdfile down as well). The skills files currently aren't specialized for either vendor so the python script currently just copies them over to the output directories.If you want to give this a try yourself, I set it up using the
uvpython package manager. Installation instructions foruvare at https://docs.astral.sh/uv/getting-started/installation/. Once it's installed, you can just runuv run python generate_plugins.pyanduvwill handle the python environment setup and installation for you.