7.8 KiB
7.8 KiB
BMAD-METHOD × OpenCode (SST) Integration Plan (JSON-only)
This plan delivers first-class OpenCode CLI/TUI integration for BMAD-METHOD using a project-level opencode.json/opencode.jsonc — no Markdown generation fallback. It mirrors our Codex integration goals and prioritizes file references to BMAD sources so updates flow automatically.
Objectives
- Generate/merge a project-level OpenCode config with BMAD agents and commands.
- Use file references (
{file:...}and@file) to avoid duplicating BMAD content. - Support all relevant agent/command options in OpenCode JSON.
- Be idempotent and non-destructive when a project already has
opencode.json(c). - Minimize name collisions; optionally prefix names with
bmad-.
References
- Config: https://opencode.ai/docs/config/
- Agents: https://opencode.ai/docs/agents/#configure
- Commands: https://opencode.ai/docs/commands/
High-Level Approach
- Add a new IDE target
opencodein the installer. - Detect an existing project-level
opencode.jsoncoropencode.json; if none, createopencode.jsonc. - Merge BMAD agents and commands into the config using file references to BMAD source files.
- Preserve user entries; only add or update BMAD-managed keys.
- Support expansion packs using the same mapping and relative path logic.
Path mapping (source → installed)
- Source in this repo:
bmad-core/...andexpansion-packs/.... - Installed in a user project:
.bmad-core/...and.bmad-core/expansion-packs/.... - All
opencode.json(c)references must target the installed.bmad-core/...paths and be POSIX-style,./-prefixed relative to the project root.
Mapping BMAD → OpenCode (JSON-only)
-
Agents (from
.bmad-core/agents/*.mdand expansion packs) →agententries:- Key: agent ID (optionally with prefix, e.g.,
bmad-dev). - Fields supported:
description: from BMAD YAMLwhenToUseor a generated fallback.
mode:primary|subagent(map core roles toprimary, specialists tosubagent).prompt:{file:./relative/path/to/.bmad-core/agents/{agent}.md}(or expansion path).- Optional:
model,temperature.
tools: conservative defaults{ write: true, edit: true, bash: true }(add more later as needed).permission:{ edit: allow|ask|deny, bash: allow|ask|deny|{pattern map}, webfetch: allow|ask|deny }.- Provider-specific options pass through unchanged.
- Key: agent ID (optionally with prefix, e.g.,
-
Commands (from
.bmad-core/tasks/*.md,common/tasks/*.md, and expansion tasks) →commandentries:- Key: task ID (optionally with prefix, e.g.,
bmad-test-design). - Fields supported:
template:{file:./relative/path/to/task.md}(use{file:...}consistently).description: from the task’s heading/summary or a generated fallback.
agent: optional; set explicitly where sensible (e.g.,dev,pm,qa). If omitted, OpenCode’s default applies.model: optional override per command.
- Key: task ID (optionally with prefix, e.g.,
Project Config Creation/Merge Strategy
- Detection order:
opencode.jsonc→opencode.json→ createopencode.jsonc. $schema:https://opencode.ai/config.json.- Existing project config present:
- Only add BMAD
agentandcommandentries. - Ensure
instructionsincludes the single entry:.bmad-core/core-config.yaml(append if missing). - Do not add or modify other top-level fields (e.g.,
theme,model,small_model,permission). - Idempotent: preserve user entries and comments; never remove non-BMAD entries.
- Only add BMAD
- No project config present:
- Create a minimal
opencode.jsonccontaining:$schema:https://opencode.ai/config.jsoninstructions: [ ".bmad-core/core-config.yaml" ]agent: { ...BMAD agents... }command: { ...BMAD commands... }
- Intentionally do NOT set
theme,model,small_model, orpermissionhere to avoid overriding a global configuration. - Paths must be relative to the project root.
- Create a minimal
Defaults for Tools & Permissions
- dev/build-like agents:
tools: { write: true, edit: true, bash: true },permission: { edit: "allow", bash: "ask" }. - pm/analyst/plan:
tools: { write: false, edit: false, bash: false },permission: { edit: "deny", bash: "deny" }. - qa:
tools: { write: true, edit: true, bash: false },permission: { edit: "ask", bash: "deny" }. - reviewer/read-only:
tools: { write: false, edit: false, bash: false },permission: { edit: "deny", bash: "deny" }.
Installer UX & Flow
- When
opencodeis selected:- Detect
opencode.jsoncoropencode.jsonat project root. - If config exists: add BMAD
agent/commandand ensure.bmad-core/core-config.yamlis present ininstructions(no other top-level changes). - If config does not exist: create minimal
opencode.jsoncwith$schema,instructions: [".bmad-core/core-config.yaml"],agent, andcommand. - Ask: “Prefix agent/command names with
bmad-?” (default: off). - Output a summary of added/updated/skipped entries and the config file path.
- Detect
Implementation Plan (code)
- Config entry: add
opencodetotools/installer/config/install.config.yamlwith a brief description. - Switch wiring: in
tools/installer/lib/ide-setup.js, addcase 'opencode': return this.setupOpenCode(installDir, selectedAgent, { prefix });. - Implement
setupOpenCode(installDir, selectedAgent, { prefix }):- Resolve project root, detect existing OpenCode config file.
- Parse with a JSONC-capable parser (e.g.,
jsonc-parserorcomment-json). - Build BMAD agent and command maps using existing helpers (agents/tasks from core + expansion packs).
- Apply defaults (tools/permissions) by agent category.
- Merge into
agent/commandsections (idempotent, preserve user entries). - Write back preserving comments/format when possible.
- Docs: update
docs/user-guide.mdwith an OpenCode section describing usage in JSON mode and re-run behavior. - Optional: add npm script if
package.jsonexists:"bmad:opencode": "bmad-method install -f -i opencode".
JSONC Example (minimal project-level config)
{
"$schema": "https://opencode.ai/config.json",
"instructions": [ ".bmad-core/core-config.yaml" ],
"agent": {
"dev": {
"description": "Product development / implementation agent",
"mode": "primary",
"prompt": "{file:./.bmad-core/agents/dev.md}",
"tools": { "write": true, "edit": true, "bash": true },
"permission": { "edit": "allow", "bash": "ask" }
},
"pm": {
"description": "Product management and planning agent",
"mode": "primary",
"prompt": "{file:./.bmad-core/agents/pm.md}",
"tools": { "write": false, "edit": false, "bash": false },
"permission": { "edit": "deny", "bash": "deny" }
}
},
"command": {
"review-changes": {
"description": "Review recent changes",
"agent": "dev",
"template": "{file:./.bmad-core/tasks/review-changes.md}"
},
"test-design": {
"description": "Design tests based on the test levels framework",
"agent": "qa",
"template": "{file:./.bmad-core/tasks/test-design.md}"
}
}
}
## Name collisions and BMAD-managed detection
- Collision handling (when prefix is off):
- If an unprefixed key exists and is not BMAD-managed → skip and report a collision; suggest re-run with `--prefix bmad-`.
- If a key is BMAD-managed → update it idempotently.
- BMAD-managed detection heuristics:
- Agent with `prompt` referencing `.bmad-core/agents` or `.bmad-core/expansion-packs/.../agents`.
- Command with `template` referencing `.bmad-core/tasks` or `.bmad-core/expansion-packs/.../tasks`.
## Acceptance Criteria
- Selecting `Opencode` merges BMAD agents/commands into a project’s `opencode.json(c)` or creates a new `opencode.jsonc`.
- Agents reference BMAD agent files via `prompt: {file:...}`; commands reference tasks via `template`.
- Doc updates describe how to use the integration and how it behaves on updates.