Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM mcr.microsoft.com/devcontainers/javascript-node:5-24-bookworm

ARG BUN_VERSION=1.4.3
ARG OPENCODE1_VERSION=1.19.2
ARG OPENCODE2_VERSION=2.0.30

# Both opencode packages install an `opencode` command, so each gets its own prefix;
# oc1 and oc2 pick the right one.
RUN npm install -g bun@${BUN_VERSION} \
&& npm install -g --prefix /opt/opencode1 opencode-ai@${OPENCODE1_VERSION} \
&& npm install -g --prefix /opt/opencode2 @opencode/cli@${OPENCODE2_VERSION} \
&& npm cache clean --force

# No browser in the container: Copilot's device login prints the URL instead.
RUN printf '#!/bin/sh\necho "open in your browser: $*" >&2\n' > /usr/local/bin/xdg-open \
&& chmod +x /usr/local/bin/xdg-open

COPY bin/ /usr/local/bin/

# Logins, sessions and plugin logs of both opencode versions; a volume keeps them
# across rebuilds.
RUN mkdir -p /home/node/.oc && chown node:node /home/node/.oc
14 changes: 14 additions & 0 deletions .devcontainer/bin/oc1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# opencode 1 with this repo's plugin build (dist/index.js), isolated in ~/.oc/1.
# Run `bun run build` (or `bun run dev`) first. Plugin options go in
# ~/.oc/1/config/opencode/opencode.json.
set -euo pipefail
root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
home="$HOME/.oc/1"
export XDG_CONFIG_HOME="$home/config" XDG_DATA_HOME="$home/data" XDG_STATE_HOME="$home/state" XDG_CACHE_HOME="$home/cache"
config="$XDG_CONFIG_HOME/opencode/opencode.json"
if [ ! -f "$config" ]; then
mkdir -p "$(dirname "$config")"
printf '{\n "$schema": "https://opencode.ai/config.json",\n "plugin": [["%s/dist/index.js", {}]]\n}\n' "$root" > "$config"
fi
exec /opt/opencode1/bin/opencode "$@"
14 changes: 14 additions & 0 deletions .devcontainer/bin/oc2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# opencode 2 with this repo's plugin build (the dist directory: opencode 2 only
# loads local plugins from a directory), isolated in ~/.oc/2. Run `bun run build`
# (or `bun run dev`) first. Plugin options go in ~/.oc/2/config/opencode/opencode.json.
set -euo pipefail
root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
home="$HOME/.oc/2"
export XDG_CONFIG_HOME="$home/config" XDG_DATA_HOME="$home/data" XDG_STATE_HOME="$home/state" XDG_CACHE_HOME="$home/cache"
config="$XDG_CONFIG_HOME/opencode/opencode.json"
if [ ! -f "$config" ]; then
mkdir -p "$(dirname "$config")"
printf '{\n "$schema": "https://opencode.ai/config.json",\n "plugins": [{ "package": "%s/dist", "options": {} }]\n}\n' "$root" > "$config"
fi
exec /opt/opencode2/bin/opencode2 "$@"
10 changes: 10 additions & 0 deletions .devcontainer/bin/plugin-log
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Follow the plugin log of opencode 1 or 2 in this devcontainer: plugin-log 1|2
set -euo pipefail
case "${1:-}" in
1|2) ;;
*) echo "usage: plugin-log 1|2" >&2; exit 2 ;;
esac
log="$HOME/.oc/$1/state/opencode-copilot-auto/plugin.log"
mkdir -p "$(dirname "$log")" && touch "$log"
exec tail -n 50 -F "$log"
12 changes: 12 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "opencode-copilot-auto",
"build": { "dockerfile": "Dockerfile", "context": "." },
"remoteUser": "node",
"mounts": ["source=opencode-copilot-auto-oc,target=/home/node/.oc,type=volume"],
"postCreateCommand": "bun install && bun run build",
"customizations": {
"vscode": {
"extensions": ["oven.bun-vscode"]
}
}
}
40 changes: 40 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Only dev dependencies, actions and the devcontainer image: none of these updates
# changes the published package, so the commit prefixes (chore/ci) cut no release.
version: 2
updates:
- package-ecosystem: bun
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
commit-message:
prefix: chore
include: scope
groups:
# The plugin types and the SDK are released together; keep them in step.
opencode:
patterns: ["@opencode-ai/*", "@opencode/*"]
dev-tools:
patterns: ["*"]

- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
cooldown:
default-days: 7
commit-message:
prefix: ci
include: scope
groups:
actions:
patterns: ["*"]

- package-ecosystem: docker
directory: /.devcontainer
schedule:
interval: weekly
commit-message:
prefix: chore
include: scope
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,20 @@ jobs:
- run: bun run typecheck
- run: bun run build
- run: bun test

devcontainer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: docker build -t devcontainer .devcontainer
# Both opencode versions start and see the plugin build. The checkout belongs to
# the runner's user, so the container works on a copy as `node`.
- run: |
docker run --rm -u node -v "$PWD:/src:ro" devcontainer bash -euc '
cp -r /src ~/repo && cd ~/repo
bun install --frozen-lockfile
bun run build
oc1 --version
oc2 --version
oc2 models --standalone --print-logs --log-level info 2>&1 | grep "loading plugin"
'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
dist
.mise.toml
.mise.local.toml
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ The tier only steers the router; the chosen model runs with its normal settings.

Sign in to GitHub Copilot in opencode as usual; the plugin uses that connection.

### Updating

opencode installs a plugin package once and keeps using the cached copy: it does not
look for newer versions, not even for an unversioned name. Pin the version and bump it
to update:

```jsonc
{ "plugin": ["@klconsultancy/opencode-copilot-auto@1.0.1"] }
```

opencode installs a new version on the next start. Start the TUI for that: a
short-lived command such as `opencode run` or `opencode models` can exit before the
install finishes, and then the plugin is missing for that run.

From a local checkout (`bun install && bun run build`), use the `dist` directory for
opencode 2 (it only accepts a directory) and `dist/index.js` for opencode 1.

Expand Down Expand Up @@ -129,6 +143,27 @@ request model gpt-5.4 -> gpt-6-luna

## Development

CI and the devcontainer use bun 1.4.3.

### Devcontainer

`.devcontainer/` gives a container with bun and both opencode lines side by side,
isolated from any opencode you use day to day:

| Command | Runs | Loads the plugin from |
|---------|------|------------------------|
| `oc1` | opencode 1.19.2 | `dist/index.js` |
| `oc2` | opencode 2.0.30 | `dist/` (opencode 2 only loads a directory) |
| `plugin-log 1` / `plugin-log 2` | follows that version's plugin log | |

Each keeps its own config, login and logs under `~/.oc/1` or `~/.oc/2`, on a volume that
survives rebuilds. Sign in to Copilot once per version (`oc1 auth login`, `oc2 auth
login github-copilot`); the device login prints a URL to open on the host. Plugin options
go in `~/.oc/<1|2>/config/opencode/opencode.json`. Run `bun run dev` to rebuild `dist/` on
every change.

### Commands

```sh
bun install
bun run typecheck
Expand Down
Loading