Skip to content

Add full OpenCode support: adapter, runner, import#29

Open
robinhuse wants to merge 1 commit intoopen-gitagent:mainfrom
robinhuse:feat/opencode-full
Open

Add full OpenCode support: adapter, runner, import#29
robinhuse wants to merge 1 commit intoopen-gitagent:mainfrom
robinhuse:feat/opencode-full

Conversation

@robinhuse
Copy link

Summary

  • Export adapter (src/adapters/opencode.ts): Generates .opencode/instructions.md and opencode.json with provider/model inference from agent.yaml. Supports all gitagent features: SOUL, RULES, DUTIES, skills, tools, knowledge, compliance, and memory.
  • Runner (src/runners/opencode.ts): Creates a temp workspace with instructions + config, launches opencode CLI. Supports both interactive mode and single-shot mode (-p). Cleans up on exit.
  • Importer (src/commands/import.ts): Reads .opencode/instructions.md + opencode.json from an existing OpenCode project and produces agent.yaml, SOUL.md, and RULES.md.
  • Git auto-detection (src/runners/git.ts): Detects .opencode/ directory or opencode.json and auto-routes to the opencode adapter.
  • Updated CLI help text, adapter tables, and README.

Files changed (8 files, +434 lines)

File Change
src/adapters/opencode.ts New — export adapter
src/runners/opencode.ts New — runtime runner
src/commands/import.ts Added opencode import format
src/commands/export.ts Added opencode export format
src/commands/run.ts Added opencode adapter case
src/runners/git.ts Added opencode auto-detection + dispatch
src/adapters/index.ts Re-exported opencode adapter
README.md Updated adapter + import tables

Test plan

  • npm run build — clean compile, no errors
  • npm test — no regressions
  • gitagent export -f opencode tested against all 5 example agents (minimal, standard, full, gitagent-helper, lyzr-agent)
  • All 8 existing export formats still produce correct output
  • gitagent run -a opencode -d examples/standard -p "Hello" — creates workspace, shows correct error when opencode CLI not installed
  • gitagent import --from opencode <dir> — round-trip tested: export design-agent → import produces valid agent.yaml + SOUL.md + RULES.md
  • gitagent validate and gitagent validate --compliance still pass on all examples

🤖 Generated with Claude Code

- 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>
shreyas-lyzr

This comment was marked as outdated.

@shreyas-lyzr
Copy link
Contributor

Updated review (reposted to remove emoji formatting from the previous comment):

Review -- OpenCode Adapter PR

Thanks 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 first

Per CONTRIBUTING.md:

For new features, please open an issue first so we can discuss the approach together.

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.md

Per 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 field with file paths/globs:

{ "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 wrong

The current adapter outputs:

{ "provider": "anthropic", "model": "claude-opus-4-6" }

But OpenCode expects:

  • model in provider_id/model_id format: "anthropic/claude-opus-4-6"
  • provider as an object with provider configs, not a string:
{
  "model": "anthropic/claude-opus-4-6",
  "provider": {
    "anthropic": {
      "npm": "@ai-sdk/anthropic"
    }
  }
}

The inferProvider() function output needs to feed into both the model prefix and the provider object key. See OpenCode config docs.

4. [blocker] Runner CLI invocation is likely wrong

OpenCode uses subcommands. Single-shot mode is:

opencode run --prompt "Your prompt here"

Not opencode --prompt "...". The runner currently spawns opencode with ['--prompt', prompt] -- it should be ['run', '--prompt', prompt] for single-shot mode, or just opencode with no args for interactive.

5. [warning] process.exit() before finally cleanup

In src/runners/opencode.ts, process.exit(result.status ?? 0) is called inside the try block. process.exit() terminates immediately -- the finally block that cleans up the temp directory will never execute. Either:

  • Move cleanup before process.exit(), or
  • Use a process exit handler: process.on('exit', () => rmSync(...))

6. [warning] buildComplianceSection is copy-pasted from copilot.ts

The 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 naming

CONTRIBUTING.md suggests: adapter/langgraph, fix/..., spec/... patterns. The branch is feat/opencode-full -- adapter/opencode would be more consistent. Minor, not blocking.

8. [warning] Lossy mapping not documented

From CONTRIBUTING.md:

Please document it clearly: What gitagent fields map to your framework? What gets dropped? What requires manual setup?

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.


Summary

The 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 run subcommand. Everything else is cleanup. Happy to re-review once those are addressed!

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