diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..1097e0e --- /dev/null +++ b/.devcontainer/Dockerfile @@ -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 diff --git a/.devcontainer/bin/oc1 b/.devcontainer/bin/oc1 new file mode 100755 index 0000000..7e05d4e --- /dev/null +++ b/.devcontainer/bin/oc1 @@ -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 "$@" diff --git a/.devcontainer/bin/oc2 b/.devcontainer/bin/oc2 new file mode 100755 index 0000000..0d06cec --- /dev/null +++ b/.devcontainer/bin/oc2 @@ -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 "$@" diff --git a/.devcontainer/bin/plugin-log b/.devcontainer/bin/plugin-log new file mode 100755 index 0000000..a074270 --- /dev/null +++ b/.devcontainer/bin/plugin-log @@ -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" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..12b961a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -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"] + } + } +} diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0bd56cd --- /dev/null +++ b/.github/dependabot.yml @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24f64ba..bc406ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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" + ' diff --git a/.gitignore b/.gitignore index f06235c..2f91b00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules dist +.mise.toml +.mise.local.toml diff --git a/README.md b/README.md index fb99118..a206bfc 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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