feat: add OpenCode as a translator output target#30
Conversation
Add OpenCode (https://opencode.ai/) as a supported output target in the convert_to_ide_formats.py translator pipeline, closing #29. - Create OpenCodeFormat class that generates rule .md files into .opencode/skills/software-security/rules/ - Generate OpenCode-compliant SKILL.md with validated frontmatter (name, description, license, compatibility, metadata) - Validate skill names against OpenCode spec regex (^[a-z0-9]+(-[a-z0-9]+)*$, 1-64 chars) - Enforce description length limit (1-1024 chars) - Include language-to-rules mapping table in SKILL.md - Wire OpenCode into the pipeline alongside Agent Skills (core only) Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Adds OpenCode as a new output target to the rule translation pipeline so core Project CodeGuard rules can be distributed in OpenCode’s expected .opencode/skills/<skill>/ structure alongside existing IDE/agent formats.
Changes:
- Introduces
OpenCodeFormatto emit rule.mdfiles underdist/.opencode/skills/software-security/rules/. - Adds OpenCode SKILL.md generation with OpenCode-compliant frontmatter plus language-to-rules mapping injection.
- Wires OpenCode into
convert_to_ide_formats.py(core-only, alongside Agent Skills).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/formats/opencode.py |
Adds OpenCode rule-format writer plus skill-name validation and description truncation helpers. |
src/formats/__init__.py |
Exports OpenCodeFormat from the formats package. |
src/convert_to_ide_formats.py |
Integrates OpenCode into conversion flow and generates OpenCode-specific SKILL.md. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for picking this up so quickly, @santosomar . I just reviewed the diff and this is exactly what I had in mind when I filed #29. The Appreciate you and @thomas-bartlett jumping on this - excited to see OpenCode supported alongside other IDE targets. |
thomas-bartlett
left a comment
There was a problem hiding this comment.
The skills approach works well, even though the rules/ subdirectory pattern isn't explicitly documented. OpenCode's skill tool discovers bundled files in the skill directory at runtime. One caveat: file discovery is capped at 10, but the language mapping table in SKILL.md references all rules by name so the agent can still load them by path.
An alternative would be an opencode.json with remote URLs (see Custom Instructions):
- Pro: no local files needed, users always get the latest rules automatically
- Con: all 23 rules are injected into context every session, ignoring language scoping
The skills approach is the better fit to avoid polluting the context, but the current implementation can be simplified:
- Rule files are identical to Agent Skills output --
OpenCodeFormatshould inherit fromAgentSkillsFormatand only overrideget_format_name()andget_output_subpath(), no other changes needed generate_opencode_skill_md()can be removed: the dist just needsskills/copied under.opencode/with an OpenCode-compliant SKILL.md (frontmatter fields differ slightly from Agent Skills)
Happy to implement the simplified skills approach if that helps.
|
Built on @santosomar's initial implementation. Simplified
|
|
Thank you so much, @thomas-bartlett ! |
|
Please do a final review @ramraaj25 @aacarter1 |
Add OpenCode (https://opencode.ai/) as a supported output target in the convert_to_ide_formats.py translator pipeline, closing #29.
Output structure
Files changed
src/formats/opencode.pyOpenCodeFormatclass, name validation, description truncationsrc/formats/__init__.pyOpenCodeFormatsrc/convert_to_ide_formats.pygenerate_opencode_skill_md()Test plan
python src/convert_to_ide_formats.py --source core— all 23 rules convert successfully.opencode/skills/software-security/SKILL.mdhas valid OpenCode frontmatterrules/directory contains all 23 rule files with preserved frontmatterdiffshows no differences)