forked from mendixlabs/mxcli
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(init): add OpenCode tool support #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ Supported Tools: | |
| - continue Continue.dev with custom commands | ||
| - windsurf Windsurf (Codeium) with MDL rules | ||
| - aider Aider with project configuration | ||
| - opencode OpenCode AI agent with MDL commands and skills | ||
|
|
||
| All tools receive universal documentation in AGENTS.md and .ai-context/ | ||
| `, | ||
|
|
@@ -143,6 +144,35 @@ All tools receive universal documentation in AGENTS.md and .ai-context/ | |
| } | ||
| } | ||
|
|
||
| // Create .opencode directory for OpenCode-specific content (if OpenCode is selected) | ||
| var opencodeCommandsDir, opencodeSkillsDir string | ||
| if slices.Contains(tools, "opencode") { | ||
| opencodeDir := filepath.Join(absDir, ".opencode") | ||
| opencodeCommandsDir = filepath.Join(opencodeDir, "commands") | ||
| opencodeSkillsDir = filepath.Join(opencodeDir, "skills") | ||
|
|
||
| if err := os.MkdirAll(opencodeCommandsDir, 0755); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error creating .opencode/commands directory: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| if err := os.MkdirAll(opencodeSkillsDir, 0755); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error creating .opencode/skills directory: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Lint rules stay in .claude/lint-rules/ (read by mxcli lint). | ||
| // Ensure that directory exists even when claude tool is not selected. | ||
| if !slices.Contains(tools, "claude") { | ||
| if lintRulesDir == "" { | ||
| lintRulesDir = filepath.Join(absDir, ".claude", "lint-rules") | ||
| } | ||
| if err := os.MkdirAll(lintRulesDir, 0755); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error creating .claude/lint-rules directory: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Write universal skills to .ai-context/skills/ | ||
| skillCount := 0 | ||
| err = fs.WalkDir(skillsFS, "skills", func(path string, d fs.DirEntry, err error) error { | ||
|
|
@@ -254,6 +284,97 @@ All tools receive universal documentation in AGENTS.md and .ai-context/ | |
| fmt.Printf(" Created %d lint rule files in .claude/lint-rules/\n", lintRuleCount) | ||
| } | ||
| } | ||
|
|
||
| // OpenCode-specific: write commands, lint rules, and skills | ||
| if toolName == "opencode" && opencodeCommandsDir != "" { | ||
| cmdCount := 0 | ||
| err = fs.WalkDir(commandsFS, "commands", func(path string, d fs.DirEntry, err error) error { | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if d.IsDir() { | ||
| return nil | ||
| } | ||
| content, err := commandsFS.ReadFile(path) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| targetPath := filepath.Join(opencodeCommandsDir, d.Name()) | ||
| if err := os.WriteFile(targetPath, content, 0644); err != nil { | ||
| return err | ||
| } | ||
| cmdCount++ | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, " Error writing OpenCode commands: %v\n", err) | ||
| } else { | ||
| fmt.Printf(" Created %d command files in .opencode/commands/\n", cmdCount) | ||
| } | ||
|
|
||
| lintRuleCount := 0 | ||
| err = fs.WalkDir(lintRulesFS, "lint-rules", func(path string, d fs.DirEntry, err error) error { | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if d.IsDir() { | ||
| return nil | ||
| } | ||
| content, err := lintRulesFS.ReadFile(path) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| targetPath := filepath.Join(lintRulesDir, d.Name()) | ||
| if err := os.WriteFile(targetPath, content, 0644); err != nil { | ||
| return err | ||
| } | ||
| lintRuleCount++ | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, " Error writing lint rules: %v\n", err) | ||
| } else { | ||
| fmt.Printf(" Created %d lint rule files in .claude/lint-rules/\n", lintRuleCount) | ||
| } | ||
|
|
||
| skillCount2 := 0 | ||
| err = fs.WalkDir(skillsFS, "skills", func(path string, d fs.DirEntry, err error) error { | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if d.IsDir() { | ||
| return nil | ||
| } | ||
| // Skip README | ||
| if d.Name() == "README.md" { | ||
| return nil | ||
| } | ||
| content, err := skillsFS.ReadFile(path) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| // Derive skill name from filename (strip .md) | ||
| skillName := strings.TrimSuffix(d.Name(), ".md") | ||
| // Create per-skill subdirectory | ||
| skillDir := filepath.Join(opencodeSkillsDir, skillName) | ||
| if err := os.MkdirAll(skillDir, 0755); err != nil { | ||
| return err | ||
| } | ||
| // Wrap content with OpenCode frontmatter | ||
| wrapped := wrapSkillContent(skillName, content) | ||
| targetPath := filepath.Join(skillDir, "SKILL.md") | ||
| if err := os.WriteFile(targetPath, wrapped, 0644); err != nil { | ||
| return err | ||
| } | ||
| skillCount2++ | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, " Error writing OpenCode skills: %v\n", err) | ||
| } else { | ||
| fmt.Printf(" Created %d skill directories in .opencode/skills/\n", skillCount2) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Write universal AGENTS.md | ||
|
|
@@ -312,8 +433,8 @@ All tools receive universal documentation in AGENTS.md and .ai-context/ | |
| } | ||
| } | ||
|
|
||
| // Install VS Code extension if Claude is selected | ||
| if slices.Contains(tools, "claude") { | ||
| // Install VS Code extension if Claude or OpenCode is selected | ||
| if slices.Contains(tools, "claude") || slices.Contains(tools, "opencode") { | ||
| installVSCodeExtension(absDir) | ||
| } | ||
|
|
||
|
|
@@ -340,6 +461,32 @@ All tools receive universal documentation in AGENTS.md and .ai-context/ | |
| }, | ||
| } | ||
|
|
||
| // wrapSkillContent prepends OpenCode-compatible YAML frontmatter to a skill file. | ||
| // OpenCode requires each skill to live in its own subdirectory as SKILL.md and | ||
| // the file must start with YAML frontmatter containing name, description, and | ||
| // compatibility fields. | ||
| func wrapSkillContent(skillName string, content []byte) []byte { | ||
| description := extractSkillDescription(content) | ||
| frontmatter := fmt.Sprintf("---\nname: %s\ndescription: %s\ncompatibility: opencode\n---\n\n", skillName, description) | ||
| return append([]byte(frontmatter), content...) | ||
| } | ||
|
|
||
| // extractSkillDescription returns a one-line description for the skill by | ||
| // finding the first top-level markdown heading (# ...) and stripping a leading | ||
| // "Skill: " prefix if present. Falls back to the skill name if no heading is | ||
| // found. | ||
| func extractSkillDescription(content []byte) string { | ||
| for _, line := range strings.Split(string(content), "\n") { | ||
| line = strings.TrimSpace(line) | ||
| if strings.HasPrefix(line, "# ") { | ||
| desc := strings.TrimPrefix(line, "# ") | ||
| desc = strings.TrimPrefix(desc, "Skill: ") | ||
| return strings.TrimSpace(desc) | ||
| } | ||
| } | ||
| return "MDL skill" | ||
|
Comment on lines
+474
to
+487
|
||
| } | ||
|
|
||
| func findMprFile(dir string) string { | ||
| entries, err := os.ReadDir(dir) | ||
| if err != nil { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When both
claudeandopencodeare selected, lint rules are written once in the Claude block and again in the OpenCode block (same destinationlintRulesDir). This duplicates work and results in duplicate "Created X lint rule files" output; consider writing lint rules once when either tool requires them (outside the per-tool branches) or guarding the OpenCode lint rule walk when Claude already handled it.