Skip to content

feat(init): add opencode as a fifth editor target#217

Merged
rhuanbarreto merged 4 commits into
mainfrom
feat/opencode-editor-support
Apr 22, 2026
Merged

feat(init): add opencode as a fifth editor target#217
rhuanbarreto merged 4 commits into
mainfrom
feat/opencode-editor-support

Conversation

@rhuanbarreto

Copy link
Copy Markdown
Contributor

Summary

  • Wire opencode into the shared EditorTarget abstraction alongside Claude Code, Cursor, VS Code, and Copilot CLI
  • Install agent markdown at user scope (~/.config/opencode/agents/ on POSIX, %APPDATA%\opencode\agents\ on Windows) rather than into the project tree, so the proprietary agent prompts stay out of consumer repos
  • Distribute agents via an authenticated tarball download from the plugins service (mirrors the Cursor .vsix flow)
  • Extend archgate init --editor opencode and archgate plugin install --editor opencode to cover the new target

Implementation notes

  • paths.ts::opencodeAgentsDir() resolves XDG/APPDATA with the same defensive env handling as archgateHomeDir() (ARCH-009 compliant — goes through isWindows() from helpers/platform.ts)
  • plugin-install.ts::installOpencodePlugin() downloads /api/opencode, extracts via Bun.spawn(["tar", "-xzf", ...]) (ARCH-007), cleans up the staging archive in a finally
  • plugin/url.ts prints a "N/A — run authenticated install" hint for opencode instead of a marketplace URL
  • On install failure, tryInstallPlugin routes through printManualInstructions("opencode", detail) so the user sees a retry + archgate login refresh hint
  • cli/CLAUDE.md gains an "Adding a New Editor Target" checklist documenting the 7-file + 3-test wire-up surface (captured from this session — three tests failed on first run because their expected argChoices array didn't include the new entry)

Depends on

  • archgate/plugins companion PR adding the agent source files under opencode/plugins/archgate/agents/
  • Service-side endpoint GET https://plugins.archgate.dev/api/opencode returning a .tar.gz of the five archgate-*.md files (Bearer auth, same 401 behavior as /api/vscode)

Test plan

  • bun run validate — 639 pass / 0 fail, 21/21 ADR rules pass, build-check succeeds
  • bun test tests/commands/plugin tests/helpers/editor-detect.test.ts — choice-list assertions updated to include opencode
  • Dry-run once /api/opencode is live: archgate init --editor opencode --install-plugin writes the five files to opencodeAgentsDir() and does not touch the project tree
  • archgate plugin install --editor opencode re-runs the install idempotently
  • Unauthenticated flow surfaces the existing "Not logged in" error; 401 surfaces the existing archgate login refresh hint
  • Launch opencode in a test project; confirm archgate-developer is selectable as primary and @archgate-architect / @archgate-quality-manager / @archgate-adr-author / @archgate-cli-reference resolve as subagents
  • Windows: files land under %APPDATA%\opencode\agents\

Known caveat (pre-existing, not addressed here)

Architect review flagged one ARCH-012 warning: the outer registerPluginInstallCommand action body is not fully wrapped in try/catch — only the per-editor install loop is. Pre-loop loadCredentials() errors would fall through to main().catch() (exit 2) instead of logError + exit 1. Not introduced by this change; worth a follow-up.

🤖 Generated with Claude Code

Wire opencode into the shared EditorTarget abstraction. Agent files are
installed at user scope (~/.config/opencode/agents or %APPDATA%\opencode\agents)
via an authenticated tarball download from the plugins service — no files
land in the project tree, keeping the proprietary agent prompts out of
consumer repos.

- Add opencodeAgentsDir() with XDG/APPDATA resolution (ARCH-009 compliant)
- Add isOpencodeCliAvailable() and installOpencodePlugin() using Bun.spawn
  for tar extraction (ARCH-007)
- Extend EditorTarget union, EDITOR_LABELS, EDITOR_DIRS, SIGNUP_EDITORS
- Extend --editor choices in init, plugin install, and plugin url
- Plugin install aliases to the init writer (no network for repeated installs
  once the tarball has been fetched — each call re-fetches authenticated)
- Document the "add a new editor" checklist in cli/CLAUDE.md so future
  contributors hit every wire-up point up front

Depends on: plugins service endpoint /api/opencode (follow-up)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 21, 2026

Copy link
Copy Markdown

Deploying archgate-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: 820fc3f
Status: ✅  Deploy successful!
Preview URL: https://1c183c80.archgate-cli.pages.dev
Branch Preview URL: https://feat-opencode-editor-support.archgate-cli.pages.dev

View logs

rhuanbarreto and others added 3 commits April 22, 2026 09:34
- guides/opencode-integration.mdx (EN + PT-BR) documenting the user-scope
  install behaviour, the five agents, and the developer workflow
- reference/cli/init.mdx and plugin.mdx updated to list opencode in
  --editor choices and describe the tarball/user-scope install path
- astro.config.mjs sidebar entry for the new guide
- docs/public/llms-full.txt regenerated by the docs build

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
opencode locates its user-scope config via the `xdg-basedir` npm package,
which falls back to `~/.config` on every platform including Windows —
it does NOT read `%APPDATA%`. My earlier implementation guessed at the
standard Windows convention and would have written files under
`%APPDATA%\opencode\agents\` where opencode would never look for them.

- `opencodeAgentsDir()` now honors `$XDG_CONFIG_HOME` when set and falls
  back to `$HOME/.config/opencode/agents` on every platform. On Windows
  this resolves to `C:\Users\<user>\.config\opencode\agents` via
  `os.homedir()` / `$USERPROFILE`, matching what opencode actually reads.
- Drop the now-unused `isWindows` import.
- Update the opencode integration guide (EN + PT-BR) and the
  `archgate init` reference (EN + PT-BR) with the corrected path and
  an explanation of why Windows doesn't use `%APPDATA%`.
- Extend the "add a new editor" checklist in CLAUDE.md with a note to
  verify the editor's path helper in its source before writing the
  resolver — this bug was a guess-the-convention mistake.
- Regenerated llms-full.txt from the updated docs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Every other editor's install path checks `is<Editor>CliAvailable()` before
writing files or invoking the editor's plugin subcommand. The opencode path
skipped that check and would write `archgate-*.md` files into
`~/.config/opencode/agents/` even on machines that don't have opencode
installed — leaving stale files in a directory nothing reads.

- `tryInstallPlugin("opencode")` now calls `isOpencodeCliAvailable()`
  first and returns a `cli-not-found` sentinel when the binary is missing.
- `printManualInstructions("opencode", "cli-not-found")` tells the user to
  install opencode from https://opencode.ai/docs/ and re-run
  `archgate plugin install --editor opencode`. Existing failure branch
  (download/extract error) is preserved for other `detail` values.
- `archgate plugin install --editor opencode` mirrors the same guard so
  the direct install command doesn't silently write files either.
- Tests: add `isOpencodeCliAvailable` boolean smoke test (mirrors the
  existing pattern for claude/copilot/vscode).
- Docs (EN + PT-BR guide, both reference pages): document the prerequisite
  and regenerate llms-full.txt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rhuanbarreto rhuanbarreto merged commit 58f8aaa into main Apr 22, 2026
10 checks passed
@rhuanbarreto rhuanbarreto deleted the feat/opencode-editor-support branch April 22, 2026 20:21
@github-actions github-actions Bot mentioned this pull request Apr 22, 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.

1 participant