summaryrefslogtreecommitdiff
path: root/docs/README.opencode.md
diff options
context:
space:
mode:
authorGoldJohnKing <GoldJohnKing@live.cn>2026-08-07 20:16:01 +0800
committerGoldJohnKing <GoldJohnKing@live.cn>2026-08-07 20:18:03 +0800
commit2ee628174705a5db2dcd1bf2eeafe295a8fb48b7 (patch)
tree593a5c9d38ed331aeb724f6eb84784f1a40e5047 /docs/README.opencode.md
parentc367f804bbf136a8a2814252c94dd286ed1c9a67 (diff)
feat(opencode): add V2 (opencode2) plugin compatibility
Add dual V1/V2 support to the OpenCode plugin. The same source file now works on both OpenCode V1 (opencode) and V2 (opencode2) without version detection at runtime. V2 changes: - Add default export { id, server, setup } for V2 PluginSupervisor - setup() registers skills via ctx.skill.transform() (V2 native API) - setup() injects bootstrap via ctx.session.hook('context') (V2 equivalent of V1's experimental.chat.messages.transform) - config hook guards against V2 array-format skills to avoid conflicts Both APIs confirmed active at runtime via diagnostics in the V2 beta. No external dependencies added — pure JavaScript throughout. Docs updated with V2 install instructions, OPENCODE_CONFIG_DIR side-by-side setup, and accurate How It Works section for both versions.
Diffstat (limited to 'docs/README.opencode.md')
-rw-r--r--docs/README.opencode.md106
1 files changed, 95 insertions, 11 deletions
diff --git a/docs/README.opencode.md b/docs/README.opencode.md
index 11da854..ab5810f 100644
--- a/docs/README.opencode.md
+++ b/docs/README.opencode.md
@@ -4,6 +4,11 @@ Complete guide for using Superpowers with [OpenCode.ai](https://opencode.ai).
## Installation
+Installation differs between OpenCode V1 (`opencode`) and V2 (`opencode2`).
+Install Superpowers separately for each version if you use both.
+
+### OpenCode V1 (`opencode`)
+
Add superpowers to the `plugin` array in your `opencode.json` (global or project-level):
```json
@@ -17,10 +22,62 @@ registers all skills.
Verify by asking: "Tell me about your superpowers"
-OpenCode uses its own plugin install. If you also use Claude Code, Codex, or
-another harness, install Superpowers separately for each one.
+### OpenCode V2 (`opencode2`)
+
+V2 does not support `git+https://` plugin installation. Use a local clone with
+a path reference instead.
-### Migrating from the old symlink-based install
+1. Clone the repository:
+
+```bash
+git clone https://github.com/obra/superpowers.git ~/superpowers
+```
+
+2. Add the plugin using the `plugin` field (singular) with an absolute path:
+
+```jsonc
+{
+ "$schema": "https://opencode.ai/config.json",
+ "plugin": [
+ "/home/your-username/superpowers/.opencode/plugins/superpowers.js"
+ ]
+}
+```
+
+> **Note:** V2 does not expand `~` in local plugin paths. Use an absolute path
+> or a relative path (`./` or `../`) resolved from the config file directory.
+
+3. Restart and verify:
+
+```bash
+opencode2 service restart
+```
+
+Ask: "Tell me about your superpowers"
+
+### Running V1 and V2 Side by Side
+
+V1 (`opencode`) and V2 (`opencode2`) share the same default config directory
+(`~/.config/opencode/`). Since V2 normalizes V1's `plugin` field into its own
+loading pipeline, putting a `git+https://` spec (which V2 cannot install) in
+the shared config causes V2 to silently fail loading it.
+
+To use different plugin sources for each version, point V2 at a separate
+config directory via the `OPENCODE_CONFIG_DIR` environment variable:
+
+```bash
+# In ~/.bashrc (or equivalent shell config)
+export OPENCODE_CONFIG_DIR="$HOME/.config/opencode2"
+```
+
+Then maintain two config files:
+
+- `~/.config/opencode/opencode.json` — V1 config, using `git+https://` sources
+- `~/.config/opencode2/opencode.json` — V2 config, using local path sources
+
+Both versions can now run independently without interfering with each other.
+
+### Migrating from the old symlink-based install (V1)
If you previously installed superpowers using `git clone` and symlinks, remove the old setup:
@@ -82,6 +139,8 @@ Create project-specific skills in `.opencode/skills/` within your project.
## Updating
+### V1 (`opencode`)
+
OpenCode installs Superpowers through a git-backed package spec. Some OpenCode
and Bun versions pin that resolved git dependency in a lockfile or cache, so a
restart may not pick up the newest Superpowers commit. If updates do not appear,
@@ -95,12 +154,23 @@ To pin a specific version, use a branch or tag:
}
```
+### V2 (`opencode2`)
+
+```bash
+cd ~/superpowers && git pull
+opencode2 service restart
+```
+
## How It Works
The plugin does two things:
-1. **Injects bootstrap context** via the `experimental.chat.messages.transform` hook, adding superpowers awareness to every conversation.
-2. **Registers the skills directory** via the `config` hook, so OpenCode discovers all superpowers skills without symlinks or manual config.
+1. **Registers the skills directory** so OpenCode discovers all superpowers skills without symlinks or manual config.
+ - **V1:** via the `config` hook, injecting into `config.skills.paths`
+ - **V2:** via the `setup()` function using `ctx.skill.transform()` (V2 native API, confirmed active at runtime)
+2. **Injects bootstrap context** into the first user message of each conversation, adding superpowers awareness.
+ - **V1:** via `experimental.chat.messages.transform` hook
+ - **V2:** via `ctx.session.hook("context")` — the V2 equivalent (confirmed active at runtime)
### Tool Mapping
@@ -121,9 +191,22 @@ Skills speak in actions rather than naming any one runtime's tools. On OpenCode
### Plugin not loading
-1. Check OpenCode logs: `opencode run --print-logs "hello" 2>&1 | grep -i superpowers`
-2. Verify the plugin line in your `opencode.json` is correct
-3. Make sure you're running a recent version of OpenCode
+**V1:** Check OpenCode logs:
+
+```
+opencode run --print-logs "hello" 2>&1 | grep -i superpowers
+```
+
+**V2:** Check the server log:
+
+```
+opencode2 service status
+```
+
+Then inspect `~/.local/share/opencode/log/opencode.log`, filtering for `role=server`.
+
+Also verify the plugin path in your `opencode.json` is correct and that you're
+running a recent version of OpenCode.
### Windows install issues
@@ -153,11 +236,12 @@ Then use the installed package path in `opencode.json`:
### Bootstrap not appearing
-1. Check OpenCode version supports `experimental.chat.messages.transform` hook
-2. Restart OpenCode after config changes
+- **V1:** Check OpenCode version supports `experimental.chat.messages.transform` hook. Restart OpenCode after config changes.
+- **V2:** The plugin uses `ctx.session.hook("context")` for bootstrap injection. Verify the plugin loaded via `opencode2 api get /api/plugin`. Restart with `opencode2 service restart` after config changes.
## Getting Help
- Report issues: https://github.com/obra/superpowers/issues
- Main documentation: https://github.com/obra/superpowers
-- OpenCode docs: https://opencode.ai/docs/
+- OpenCode V2 docs: https://opencode.ai/v2/docs/
+- OpenCode V1 docs: https://opencode.ai/docs/