# Agent Instructions ## Build & development commands All tasks are run via mise: - `mise run setup` — install dependencies - `mise run build [package...]` — build all plugins (or only the named ones) into `packages/*/dist/` - `mise run dev ` — build a single package with inline sourcemaps - `mise run typecheck` — type-check all packages - `mise run test` — run all tests - `mise run lint` — lint with ESLint - `mise run lint:fix` — lint and auto-fix - `mise run format` — format with Prettier - `mise run install-local [--local-plugins] ` — build a plugin into `~/.config/opencode/plugins//`, or into `~/.config/opencode/local-plugins//` when `opencode.json(c)` configures it with `options` (or `--local-plugins` is passed) so auto-discovery doesn't shadow its options There are no npm scripts. Do not add a `"scripts"` key to any `package.json`. ## Mise task metadata When creating or updating a mise task, maintain its argument and completion metadata alongside its implementation. Use `#USAGE` directives for file tasks or `usage` for TOML tasks, with help text, repeatability, fixed `choices`, and dynamic `complete` rules where applicable. Derive completions from authoritative local metadata. Completion must not read credentials, change state, or contact live services. For wrappers whose CLI parses forwarded arguments, set `raw_args = true` (or `#MISE raw_args=true`) and keep forwarding intact. `raw` controls terminal access, not argument parsing. Tasks without arguments need only task-name completion. Validate flags with `mise __complete_word__ --shell zsh --line 'mise run TASK --'` and test representative value prefixes. Test forwarding with harmless fixtures, not operational tasks. Complete immediately after `--` or a value prefix; a standalone `--` followed by a space disables task-aware completion. ## Code style - TypeScript strict mode, ESNext target - Single quotes, semicolons, 100-char line width, 2-space indent, trailing commas - No `console.log` — ESLint enforces `no-console: error` - Avoid redundant comments, but keep brief comments that explain non-obvious context (such as why a `catch` block ignores an error) - Imports: use `import type` for type-only imports ## Code rules - Avoid negated ternary conditions (`!cond ? a : b` or `x !== y ? a : b`); flip the condition and swap the branches instead - Avoid nested ternary operators; extract a helper function or use `if`/`return` statements instead - Prefer `switch` statements over multiple `if`/`else if` branches when dispatching on a value or discriminant ## Plugin API Plugins target the OpenCode 2 plugin API (`@opencode/plugin`). See . - Server plugins live in `src/index.ts`; CLI (TUI) plugins live in `src/tui.ts`, or `src/tui.tsx` when they render JSX. `.mise/bundle.ts` compiles whichever exist, and packages export them as `.` and `./tui`. - Desktop (GUI) parts live in `src/gui.tsx` and use `@opencode/plugin/gui`, with Solid's DOM JSX (`/** @jsxImportSource solid-js */`). `.mise/bundle.ts` builds them under Node with `.mise/vite.gui.config.mjs` into `dist/gui-experimental.cjs`, because Vite fails under Bun. Packages export it as `./gui-experimental`. Only OpenCode Desktop loads GUI parts; the web UI runs only built-in ones. - `.mise/bundle.ts` also compiles `src/worker.ts` into `dist/worker.js`, next to `dist/index.js`, for work that must not block the server. Resolve it from `import.meta.url`; see `packages/session-finder/src/run.ts`. - JSX goes through OpenTUI's Solid transform. The bundle keeps `solid-js` and `@opentui/*` external, because OpenCode provides them at runtime. A package that renders JSX lists `@opentui/core`, `@opentui/solid`, and `solid-js` as peer dependencies, and sets `"jsx": "preserve"` and `"jsxImportSource": "@opentui/solid"` in its `tsconfig.json`. - Import `@opencode/plugin` and `@opencode/plugin/tui` with `import type` only, and default-export `{ id, setup } satisfies Plugin.Plugin` (or `Plugin.Definition` for TUI). `Plugin.define` is an identity function, so no runtime dependency is needed. The build marks the package as external as a safety net. - Use `exec` from `packages/_shared/` to run subprocesses. Do not rely on Bun's `$`. - Code that talks to the user's terminal (TTY escape codes, tmux) belongs in a CLI plugin, because the server can run in a separate process or on a remote host. ## Monorepo structure - Root `package.json` is private with `"workspaces": ["packages/*"]` - All devDependencies live at the root - Each package has its own `package.json` with name, version, description, and a peerDependency on `@opencode/plugin` - Each package extends `../../tsconfig.base.json` via its own `tsconfig.json` - Internal shared code lives in `packages/_shared/` without a `package.json`; it is bundled into each plugin ## Adding a new plugin 1. Copy `packages/_template/` to `packages//` and replace all `PLUGIN-NAME` placeholders 2. Add the package to `release-please-config.json` and `.release-please-manifest.json` (`"0.0.0"`) 3. Add a publish job in `.github/workflows/release.yml` 4. On the first release, npm Trusted Publishing (OIDC) cannot authenticate until the package exists on npmjs.com. Stage the initial version locally (`npm stage publish --access public --tag latest`), approve it with `npm stage approve `, and configure `pedropombeiro/opencode-plugins` (`release.yml`) as a Trusted Publisher on `https://www.npmjs.com/package//access`. ## Testing Verify by running `mise run lint`, `mise run typecheck`, `mise run build`, and `mise run test` successfully. ## Releasing Releases are fully automated via [release-please](https://github.com/googleapis/release-please) and GitHub Actions. **Do NOT manually bump versions, and do NOT merge release-please PRs unless the user explicitly asks to cut a release.** 1. Push commits to `main` using [Conventional Commits](https://www.conventionalcommits.org/) (e.g. `fix:`, `feat:`, `chore:`). 2. Release-please creates and updates separate release PRs per package as changes land on `main`. 3. Only when the user explicitly asks to release, merge the release PR with `gh pr merge --admin --squash `. Release-please opens it with `GITHUB_TOKEN`, so CI never runs on it and the required check needs an admin bypass. The merge creates a GitHub Release and stages the version on npm with `npm stage publish`. 4. Approve the staged version with two-factor authentication, on the **Staged Packages** tab on npmjs.com or with `npm stage list` and `npm stage approve `. Until then, the version isn't installable. ### OpenCode 1 maintenance The `v1` branch holds the last OpenCode 1 versions (0.x) of every plugin. Releases from `v1` publish under the npm dist-tag `opencode-v1`; releases from `main` publish under `latest`. npm rejects dist-tags that are valid semver ranges, such as `v1`. To ship an OpenCode 1 hotfix, open a PR against `v1` with a `fix:` commit, then merge the release-please PR that targets `v1`. Do not merge V2 code into `v1`.