Skip to content

fix: restore OpenCode IDE handler with agent switch functionality#1555

Closed
adittanu wants to merge 2 commits intobmad-code-org:mainfrom
adittanu:main
Closed

fix: restore OpenCode IDE handler with agent switch functionality#1555
adittanu wants to merge 2 commits intobmad-code-org:mainfrom
adittanu:main

Conversation

@adittanu
Copy link
Copy Markdown

@adittanu adittanu commented Feb 6, 2026

Problem

OpenCode IDE handler was missing in v6.0.0-Beta.6, causing:

  • OpenCode not showing as preferred tool (no ⭐ indicator)
  • Agent switch functionality not working for OpenCode users
  • OpenCode integration not exporting BMAD agents, workflows, tasks, and tools

Solution

  • Restore opencode.js handler for OpenCode IDE integration
  • Register opencode.js in IdeManager custom files list (manager.js)

Changes

  • Added: tools/cli/installers/lib/ide/opencode.js
  • Modified: tools/cli/installers/lib/ide/manager.js (added 'opencode.js' to customFiles array)

Testing

After this fix, OpenCode now:

  • Appears with ⭐ indicator in tool selection
  • Properly exports agents to .opencode/agent/
  • Exports workflows, tasks, and tools to .opencode/command/
  • Agent switch functionality works as expected

Related

Fixes missing OpenCode integration that was present in v6.0.0-alpha.23

- Add missing opencode.js handler for OpenCode IDE integration
- Register opencode.js in IdeManager custom files list
- Restores agent switch functionality for OpenCode that was lost in v6.0.0-Beta.6
- OpenCode now properly exports agents, workflows, tasks, and tools to .opencode/ directory
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

Introduces a new OpenCode IDE setup handler integrated into the IDE manager's custom installer loading process. The OpenCodeSetup class manages installation of BMAD agents, workflows, and commands into an OpenCode project structure with cleanup and file organization capabilities.

Changes

Cohort / File(s) Summary
IDE Manager Configuration
tools/cli/installers/lib/ide/manager.js
Extended dynamic custom installer file loading to include opencode.js alongside existing codex.js, kilo.js, and kiro-cli.js.
OpenCode IDE Handler
tools/cli/installers/lib/ide/opencode.js
New OpenCodeSetup class extending BaseIdeSetup that handles creation of agents, workflows, and flat task/tool commands in .opencode directories, includes YAML frontmatter parsing, file cleanup routines, and custom agent launcher installation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #1549: Updates platform-codes.yaml to route agents to .opencode/agent directory, aligning with the new OpenCodeSetup agent installation logic.

Suggested reviewers

  • bmadcode
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: restoring the OpenCode IDE handler and enabling agent switch functionality. It is specific and directly related to the changeset.
Description check ✅ Passed The description clearly outlines the problem, solution, specific changes made, testing outcomes, and related context. It is directly related to the changeset and provides meaningful information.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In `@tools/cli/installers/lib/ide/opencode.js`:
- Around line 228-244: The YAML frontmatter is built via raw string
interpolation into launcherContent using agentName and metadata.title which can
break when those values contain quotes or YAML-special characters; replace this
manual construction by calling this.stringifyFrontmatter() (or yaml.dump once
fixed) to produce escaped frontmatter, or at minimum sanitize/escape agentName
and metadata.title before interpolation; update the code that produces
launcherContent to use the safe serializer (or escaped values) and reference the
same symbols (launcherContent, agentName, metadata.title,
this.stringifyFrontmatter, yaml.dump) so the frontmatter is always valid.
- Around line 163-174: The stringifyFrontmatter function calls yaml.dump (and
passes js-yaml options) which doesn't exist on the yaml v2 package; replace
yaml.dump(...) with yaml.stringify(...) and adjust the options to the yaml v2
API (remove js-yaml-only options like noRefs and sortKeys and use supported keys
such as indent and any v2 equivalents for line width), then keep the trimEnd()
and the frontmatter wrapper `---\n${yamlText}\n---` intact so the function
returns the same formatted YAML string.
- Around line 145-161: The parseFrontmatter method returns inconsistent keys:
when no frontmatter is matched it returns { data: {}, body } but when matched it
returns { frontmatter, body }, causing callers (e.g., createAgentContent) that
destructure { frontmatter } to get undefined; update the no-match return to use
the same key name (return { frontmatter: {}, body: content }), and ensure the
local variable used for parsed YAML is named/returned as frontmatter (keep
frontmatter = yaml.parse(...) || {} and return { frontmatter, body }) so all
callers and the base class see a consistent frontmatter property.
- Around line 80-86: The summary returned from setup() currently includes
success, agents, workflows and workflowCounts but omits the task/tool counts
that were logged earlier; update the return object in the setup() function to
include the task and tool count variables (e.g., taskCount and toolCount or
taskCounts/toolCounts as used where they are logged) so consumers receive those
counts alongside workflowCounts, agents, and workflows.
🧹 Nitpick comments (1)
tools/cli/installers/lib/ide/manager.js (1)

11-11: Stale comment — opencode.js not listed.

The inline documentation still lists only codex.js, kilo.js, kiro-cli.js. Consider updating it to include opencode.js so it stays in sync with the actual customFiles array on line 64.

- Fix parseFrontmatter to return consistent {frontmatter} key (was {data})
- Replace yaml.dump with yaml.stringify for yaml v2 compatibility
- Add tasks and tools to setup() return value
- Use stringifyFrontmatter for safe YAML generation in launcher
- Update manager.js comment to include opencode.js
@dracic
Copy link
Copy Markdown
Contributor

dracic commented Feb 10, 2026

Template based OpenCode setup implemented in #1556

@dracic dracic closed this Feb 10, 2026
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.

2 participants