Add full OpenCode support: adapter, runner, import#29
Add full OpenCode support: adapter, runner, import#29robinhuse wants to merge 1 commit intoopen-gitagent:mainfrom
Conversation
- Export adapter (src/adapters/opencode.ts): generates .opencode/instructions.md and opencode.json with provider/model config from agent.yaml - Runner (src/runners/opencode.ts): creates temp workspace with instructions + config, launches `opencode` CLI in interactive or single-shot mode - Import (src/commands/import.ts): reads .opencode/instructions.md + opencode.json, produces agent.yaml, SOUL.md, and RULES.md - Git runner auto-detection: detects .opencode/ or opencode.json and routes to the opencode adapter - Wired into export, run, and import commands with updated help text and README Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Updated review (reposted to remove emoji formatting from the previous comment): Review -- OpenCode Adapter PRThanks for the contribution @robinhuse! Solid structure overall -- you followed the adapter pattern well and the PR description is thorough. A few things to address before merge: 1. [blocker] No issue opened firstPer CONTRIBUTING.md:
No issue exists for the OpenCode adapter. Please open one (even retroactively) so we have a place to track the design decisions. 2. [blocker] Instructions path is wrong -- OpenCode uses AGENTS.md, not .opencode/instructions.mdPer OpenCode docs (Rules), custom instructions go in AGENTS.md at the project root (or ~/.config/opencode/AGENTS.md globally). The .opencode/ directory is used for commands, not instructions. Alternatively, opencode.json supports an { "instructions": ["docs/agent-rules.md"] }The adapter should export AGENTS.md instead of .opencode/instructions.md. The importer should also read AGENTS.md instead of .opencode/instructions.md. 3. [blocker] opencode.json config structure is wrongThe current adapter outputs: { "provider": "anthropic", "model": "claude-opus-4-6" }But OpenCode expects:
{
"model": "anthropic/claude-opus-4-6",
"provider": {
"anthropic": {
"npm": "@ai-sdk/anthropic"
}
}
}The 4. [blocker] Runner CLI invocation is likely wrongOpenCode uses subcommands. Single-shot mode is: opencode run --prompt "Your prompt here"Not 5. [warning] process.exit() before finally cleanupIn src/runners/opencode.ts,
6. [warning] buildComplianceSection is copy-pasted from copilot.tsThe entire ~60-line buildComplianceSection function is duplicated verbatim. This should be extracted to a shared utility (e.g., src/utils/compliance.ts or src/adapters/shared.ts) and imported by both adapters. Per the contributing guide, we prefer focused PRs -- but since this is a direct copy, extracting it now avoids tech debt. 7. [warning] Branch namingCONTRIBUTING.md suggests: 8. [warning] Lossy mapping not documentedFrom CONTRIBUTING.md:
The PR description lists what's supported but doesn't call out what's lost or what needs manual setup (e.g., API keys, OpenCode installation). A short "Limitations" section in the PR body would help. SummaryThe main blockers are #2, #3, and #4 -- the file paths and config format don't match OpenCode's actual spec, and the runner CLI invocation needs the |
Summary
src/adapters/opencode.ts): Generates.opencode/instructions.mdandopencode.jsonwith provider/model inference fromagent.yaml. Supports all gitagent features: SOUL, RULES, DUTIES, skills, tools, knowledge, compliance, and memory.src/runners/opencode.ts): Creates a temp workspace with instructions + config, launchesopencodeCLI. Supports both interactive mode and single-shot mode (-p). Cleans up on exit.src/commands/import.ts): Reads.opencode/instructions.md+opencode.jsonfrom an existing OpenCode project and producesagent.yaml,SOUL.md, andRULES.md.src/runners/git.ts): Detects.opencode/directory oropencode.jsonand auto-routes to the opencode adapter.Files changed (8 files, +434 lines)
src/adapters/opencode.tssrc/runners/opencode.tssrc/commands/import.tsopencodeimport formatsrc/commands/export.tsopencodeexport formatsrc/commands/run.tsopencodeadapter casesrc/runners/git.tssrc/adapters/index.tsREADME.mdTest plan
npm run build— clean compile, no errorsnpm test— no regressionsgitagent export -f opencodetested against all 5 example agents (minimal, standard, full, gitagent-helper, lyzr-agent)gitagent run -a opencode -d examples/standard -p "Hello"— creates workspace, shows correct error when opencode CLI not installedgitagent import --from opencode <dir>— round-trip tested: export design-agent → import produces valid agent.yaml + SOUL.md + RULES.mdgitagent validateandgitagent validate --compliancestill pass on all examples🤖 Generated with Claude Code