Skip to content

Add opencode connect adapter, single-source the onboarding picker#883

Merged
rohitg00 merged 3 commits into
mainfrom
fix/connect-dry-opencode-872
Jun 10, 2026
Merged

Add opencode connect adapter, single-source the onboarding picker#883
rohitg00 merged 3 commits into
mainfrom
fix/connect-dry-opencode-872

Conversation

@rohitg00

@rohitg00 rohitg00 commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Fixes #872.

Problem

Two hardcoded agent lists had drifted:

  • src/cli/onboarding.ts offered opencode, goose, kilo, aider, claude-desktop, windsurf, roo — but connect had no adapter for any of them, so onboarding's wire step hit resolveAdapter(name) -> null ("no adapter available, skipped"). Phantom offerings.
  • connect's ADAPTERS had antigravity, kiro, warp, continue, zed, droid, qwen that the onboarding picker never showed.

Fix

  1. opencode adapter (src/cli/connect/opencode.ts): OpenCode's MCP config is not the standard mcpServers shape, it's a top-level mcp key with command as an array plus type/enabled (documented in the README). A dedicated adapter writes that schema to ~/.config/opencode/opencode.json with the same safety as the generic adapter (preserve existing servers, backup, dry-run, already-wired, post-write verify). Registered in ADAPTERS (now 18).
  2. DRY: onboarding.buildAgentOptions() now derives from connect's ADAPTERS (single source of truth) instead of its own arrays. Glyph + native/MCP grouping stay as a local cosmetic lookup with a neutral default. The picker can no longer drift from what connect can wire.

Effect

  • opencode is now wireable and appears in both pickers.
  • Connect-only adapters (antigravity/kiro/warp/continue/zed/droid/qwen) now appear in onboarding.
  • The 7 phantom agents with no adapter no longer appear in onboarding (they could never be wired). goose/kilo/aider/claude-desktop/windsurf/roo are candidates for real adapters in a follow-up; this PR does not ship untested ones.

Tests

  • New opencode adapter tests (schema, preserve-other, idempotent, dry-run) under test/cli-connect.test.ts.
  • Updated the supported-agent-list and ADAPTERS.length assertions (17 -> 18).
  • npm run build + full suite (1412) pass.

README's OpenCode row can be updated to mention agentmemory connect opencode in a follow-up; kept this PR scoped to the bug.

Summary by CodeRabbit

  • New Features

    • Added OpenCode adapter to the connect flow with safe install (backup, verification), dry-run, and idempotency.
  • User Experience

    • Onboarding agent picker now derives options from available adapters, with glyph fallback and native-vs-MCP grouping for clearer selection.
  • Tests

    • Expanded test coverage for the new adapter and updated adapter-list expectations.
  • Documentation

    • Reference updated to include the new OpenCode adapter.

…ADAPTERS

The onboarding agent picker and the connect interactive menu maintained two separate hardcoded lists that had drifted: onboarding offered opencode/goose/kilo/aider/claude-desktop/windsurf/roo (which connect had no adapter for, so picking them hit 'no adapter available, skipped'), while connect had antigravity/kiro/warp/continue/zed/droid/qwen that onboarding never offered.

Add a real opencode adapter writing OpenCode's documented mcp schema (top-level mcp key, command as array, type/enabled), and make onboarding's buildAgentOptions derive from connect's ADAPTERS so the two can never diverge again. Connect-only adapters now appear in onboarding; opencode is now wireable; phantom agents with no adapter no longer appear. Fixes #872.
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agentmemory Ready Ready Preview, Comment Jun 10, 2026 1:10pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5464e848-ea24-42ea-82b6-5e8cd7215260

📥 Commits

Reviewing files that changed from the base of the PR and between 154ab67 and b090cfd.

📒 Files selected for processing (1)
  • plugin/skills/agentmemory-agents/REFERENCE.md
✅ Files skipped from review due to trivial changes (1)
  • plugin/skills/agentmemory-agents/REFERENCE.md

📝 Walkthrough

Walkthrough

Adds an OpenCode MCP connect adapter (detect/install with backup/dry-run), registers it in ADAPTERS, refactors onboarding to derive agent options from ADAPTERS, and extends tests and docs to include the new opencode adapter.

Changes

OpenCode Connect Adapter

Layer / File(s) Summary
OpenCode Adapter Implementation
src/cli/connect/opencode.ts
Defines config path constants, MCP entry schema and entryMatches(); exports adapter with detect() and install() supporting dry-run, force, backup, atomic write, and verification.
Adapter Registration in CLI Registry
src/cli/connect/index.ts
Imports and registers opencode in the exported ADAPTERS array so the CLI can discover and wire it.
Onboarding Agent Picker Refactor
src/cli/onboarding.ts
Replaces hardcoded agent lists with dynamic options derived from ADAPTERS, adds AGENT_GLYPH and NATIVE_AGENTS, and groups native plugins before MCP servers.
Test Coverage
test/cli-connect.test.ts
Updates dispatcher tests to include opencode (ADAPTERS length 17→18) and adds opencode adapter tests for detect, install (writes mcp.agentmemory with array command), idempotency, and dry-run behavior.
Docs / Reference
plugin/skills/agentmemory-agents/REFERENCE.md
Increments adapter count (17→18) and adds an OpenCode row describing MCP config location and installation note.

Sequence Diagram

sequenceDiagram
  participant CLI as agentmemory CLI
  participant Adapter as OpenCode Adapter
  participant FS as Filesystem
  participant Config as opencode.json
  
  CLI->>Adapter: detect()
  Adapter->>FS: check config directory exists
  FS-->>Adapter: exists? boolean
  Adapter-->>CLI: boolean result
  
  CLI->>Adapter: install(opts)
  Adapter->>FS: read opencode.json (if exists)
  FS-->>Config: existing config or {}
  Adapter->>Adapter: entryMatches(`@agentmemory/mcp`)
  alt entry already exists and not force
    Adapter-->>CLI: already-wired
  else write required
    Adapter->>FS: create backup (if exists)
    Adapter->>FS: ensure parent directories
    Adapter->>FS: atomic write mcp.agentmemory entry
    Adapter->>FS: read back and verify entry
    FS-->>Adapter: verification result
    alt verification succeeded
      Adapter-->>CLI: installed (include backupPath)
    else verification failed
      Adapter-->>CLI: skipped
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 I hopped through configs, quiet and keen,
Backed up files, and left no scene unclean,
I checked for shims and wrote with care,
Dry-runs safe, idempotent where,
ADAPTERS grew — now OpenCode is seen.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding the opencode connect adapter and refactoring the onboarding picker to use ADAPTERS as a single source of truth.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/connect-dry-opencode-872

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/cli/onboarding.ts (1)

87-87: 💤 Low value

Remove WHAT comment; let the code structure speak.

This comment explains what the code does rather than why. As per coding guidelines, WHAT comments should be replaced with clear code structure.

♻️ Suggested refactor to remove the comment
-  // Native plugins first, then MCP-only, each keeping ADAPTERS order.
   return [
     ...options.filter((o) => o.hint === "native plugin"),
     ...options.filter((o) => o.hint === "MCP server"),
   ];

The two-group filtering pattern is self-documenting: native plugins are filtered first, then MCP servers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/onboarding.ts` at line 87, Remove the redundant "Native plugins
first, then MCP-only, each keeping ADAPTERS order." comment and rely on the
existing code structure and naming (the two-group filtering logic that processes
native plugins then MCP-only plugins and the ADAPTERS ordering) to be
self-explanatory; simply delete that single-line WHAT comment in onboarding.ts
near the filtering/grouping logic so the code reads without explanatory WHAT
commentary.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli/connect/opencode.ts`:
- Around line 57-59: The current construction of mcp spreads next["mcp"] without
verifying it's an object, which can break if next["mcp"] is a non-object; add a
runtime type guard before spreading by checking that next["mcp"] is a plain
object (e.g., typeof next["mcp"] === "object" && next["mcp"] !== null &&
!Array.isArray(next["mcp"])), and only then cast/spread it into const mcp:
Record<string, McpEntry> = { ...(next["mcp"] as Record<string, McpEntry>) };
otherwise use an empty object fallback so mcp is always a safe Record<string,
McpEntry>.
- Around line 27-31: Replace the shell-style expansions inside the environment
object with OpenCode's supported {env:VAR} form: change AGENTMEMORY_URL,
AGENTMEMORY_SECRET, and AGENTMEMORY_TOOLS values to "{env:AGENTMEMORY_URL}",
"{env:AGENTMEMORY_SECRET}", and "{env:AGENTMEMORY_TOOLS}" respectively in the
environment object in opencode.ts; because OpenCode will yield an empty string
when a var is unset, also ensure the code that reads these (or the place that
builds this config) applies the intended defaults (use "http://localhost:3111"
for AGENTMEMORY_URL and "all" for AGENTMEMORY_TOOLS, and empty string or secure
handling for AGENTMEMORY_SECRET) so consumers get the fallback values when env
vars are not provided.

---

Nitpick comments:
In `@src/cli/onboarding.ts`:
- Line 87: Remove the redundant "Native plugins first, then MCP-only, each
keeping ADAPTERS order." comment and rely on the existing code structure and
naming (the two-group filtering logic that processes native plugins then
MCP-only plugins and the ADAPTERS ordering) to be self-explanatory; simply
delete that single-line WHAT comment in onboarding.ts near the
filtering/grouping logic so the code reads without explanatory WHAT commentary.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: add5028b-22a4-421b-9758-fc2b7b4186b6

📥 Commits

Reviewing files that changed from the base of the PR and between a688e50 and fcd5472.

📒 Files selected for processing (4)
  • src/cli/connect/index.ts
  • src/cli/connect/opencode.ts
  • src/cli/onboarding.ts
  • test/cli-connect.test.ts

Comment thread src/cli/connect/opencode.ts Outdated
Comment thread src/cli/connect/opencode.ts Outdated
…nv block

Guard the mcp spread against a non-object value in an existing opencode.json, and remove the environment block whose shell-style ${VAR:-default} values OpenCode does not expand (writing them literally would clobber a user's real shell AGENTMEMORY_URL). The stdio child inherits the shell env and the shim defaults unset vars. Also drop a redundant inline comment in onboarding.
Adding the opencode adapter changed ADAPTERS (17 -> 18); regenerate the auto-derived agents table so npm run skills:check passes in CI.
@rohitg00 rohitg00 merged commit c2d836d into main Jun 10, 2026
7 checks passed
@rohitg00 rohitg00 deleted the fix/connect-dry-opencode-872 branch June 10, 2026 13:15
@mintlify

mintlify Bot commented Jun 10, 2026

Copy link
Copy Markdown

Docs PR opened: https://github.com/mintlify-community/docs-agentmemory-abc2951c/pull/1

Documented the new OpenCode connect adapter on the Connect Agents and Other MCP Agents pages, including its non-standard config schema.

@HaleTom

HaleTom commented Jun 10, 2026

Copy link
Copy Markdown

Thanks! I see that you've added lines for opencode in particular.

But I wonder if the root cause remains for some of the other 18 adapters (only 7 are listed in the NATIVE_ADAPTERS list)

@rohitg00

Copy link
Copy Markdown
Owner Author

Thanks @HaleTom , Please check this #887

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.

Many agents missing from agentmemory connect interactive menu

2 participants