Skip to content

Commit e1b8418

Browse files
committed
docs(opencode): document the supported plugin install flow
1 parent 8fbfba0 commit e1b8418

6 files changed

Lines changed: 82 additions & 38 deletions

File tree

ARCHITECTURE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ graph LR
4242
E2E --> Core
4343
```
4444

45-
`packages/opencode/package.json:32-45` declares two `oc-plugin` entry points: `server` (the fetch interceptor / OAuth / quota controller) and `tui` (the OpenTUI sidebar)the host loads them as separate plugin registrations. The Pi package's `pi.extensions` field (`packages/pi/package.json:34-38`) is the analogue. The core package has no peer dependencies on any host runtime; it only depends on Node built-ins and `@openauthjs/openauth`.
45+
`packages/opencode/package.json` exposes two `exports` subpaths that the host installer reads: `exports["."]` (the fetch interceptor / OAuth / quota controller) and `exports["./tui"]` (the OpenTUI sidebar). The host's `opencode plugin` installer writes a server entry to `opencode.json` and a TUI entry to `tui.json`; the host loads the two registrations independently. The Pi package's `pi.extensions` field (`packages/pi/package.json:34-38`) is the analogue. The core package has no peer dependencies on any host runtime; it only depends on Node built-ins and `@openauthjs/openauth`.
4646

4747
### Process topology at runtime
4848

@@ -206,7 +206,7 @@ The `RetryState` at `packages/opencode/src/plugin/fetch/retry-state.ts` and `War
206206

207207
### Two halves of the contract
208208

209-
The OpenTUI plugin is declared in `packages/opencode/package.json:32-45` as `"oc-plugin": ["server", "tui"]`. The host loads the TUI entry point separately; the entry dispatches to either the precompiled Solid bundle or the raw `tui.tsx` based on the host runtime module's availability (`packages/opencode/src/tui/entry.mjs:30-66`).
209+
The OpenTUI plugin is wired through the package's `exports["./tui"]` subpath (`packages/opencode/package.json`). The host's `opencode plugin` installer reads that subpath and writes the registration into `tui.json`; the host loads the TUI entry point separately from the server entry, and the entry dispatches to either the precompiled Solid bundle or the raw `tui.tsx` based on the host runtime module's availability (`packages/opencode/src/tui/entry.mjs:30-66`).
210210

211211
The two halves share a small amount of code through `packages/opencode/src/tui-compiled/` (the precompiled mirror) and the slim contract modules:
212212

README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,55 @@ The shipped headers, project IDs, and OAuth client identifiers match the publicl
2222

2323
| Host | Package version | Host requirement | Install path |
2424
| --- | --- | --- | --- |
25-
| OpenCode (server + TUI) | `2.0.0` | `@opencode-ai/plugin >=1.17.13 <2` · `@opentui/core`, `@opentui/keymap`, `@opentui/solid` all `^0.4.5` | `plugin` array (server) + `oc-plugin` field (`["server","tui"]`) |
25+
| OpenCode (server + TUI) | `2.0.0` | `@opencode-ai/plugin >=1.17.13 <2` · `@opentui/core`, `@opentui/keymap`, `@opentui/solid` all `^0.4.5` | `opencode plugin @cortexkit/opencode-antigravity-auth@latest` (writes the server entry to `opencode.json` and the TUI entry to `tui.json`) |
2626
| Pi coding agent | `2.0.0` | `@earendil-works/pi-ai`, `@earendil-works/pi-coding-agent`, `@earendil-works/pi-tui` (peer) | `pi install npm:@cortexkit/pi-antigravity-auth` then `/login google-antigravity` |
2727
| Standalone CLI | shipped inside the OpenCode package as the `antigravity-auth` bin | Node 20+ | `npx @cortexkit/opencode-antigravity-auth` |
2828
| Node libraries (harness builders) | `2.0.0` core | Node 20+ | `npm install @cortexkit/antigravity-auth-core` |
2929

30-
The OpenCode package's `oc-plugin` field publishes two subpaths:
30+
The OpenCode package exposes two `exports` subpaths the host installer reads:
3131

32-
- `oc-plugin: "server"` — the default `@opencode-ai/plugin` entry; OpenCode loads it via the `plugin` array.
33-
- `oc-plugin: "tui"`exports the TUI sidebar through the `"./tui"` subpath. OpenCode 1.17.13+ resolves this automatically; legacy hosts declare it explicitly through the package's `oc-plugin` declaration in `package.json` (`["server","tui"]`). The precompiled JSX tree ships under `dist/src/tui-compiled/` and is regenerated by `bun run build:tui`; the host's loader also accepts the raw `src/tui.tsx` source path for development installs.
32+
- `exports["."]` — the bundled `dist/index.js` server root; `opencode plugin` writes this entry into `opencode.json`'s `plugin` array.
33+
- `exports["./tui"]``src/tui/entry.mjs`, the OpenTUI sidebar loader; `opencode plugin` writes this entry into `tui.json` so the TUI process picks it up on the next host start. The precompiled JSX tree ships under `dist/src/tui-compiled/` and is regenerated by `bun run build:tui`; the host's loader also accepts the raw `src/tui.tsx` source path for development installs.
3434

35-
Both core and opencode packages are dual-target: the OpenCode package bundles a CommonJS-free ESM artifact via `esbuild`, while the core package ships `tsc`-emitted ESM. Runtime requirements match the `engines.node` field (`>=20`).
35+
The host enforces the minimum OpenCode version through the package's `engines.opencode` field (`>=1.17.13 <2`); `opencode plugin` refuses to install a plugin that asks for an unsupported range. Both core and opencode packages are dual-target: the OpenCode package bundles a CommonJS-free ESM artifact via `esbuild`, while the core package ships `tsc`-emitted ESM. Runtime requirements match the `engines.node` field (`>=20`).
3636

3737
## Installation matrix
3838

3939
### OpenCode (npm — the only end-user install path)
4040

41-
Edit `~/.config/opencode/opencode.json` (or the path `OPENCODE_CONFIG_DIR` points at):
41+
The supported installer writes both registrations in one step:
42+
43+
```bash
44+
opencode plugin @cortexkit/opencode-antigravity-auth@latest
45+
```
46+
47+
What this does:
48+
49+
- Reads the package's `exports["."]` (the server root) and writes it into `~/.config/opencode/opencode.json` under the `plugin` array — that is the `auth.loader` and `fetch` interceptor the host calls on every model dispatch.
50+
- Reads the package's `exports["./tui"]` (the OpenTUI sidebar loader) and writes it into `~/.config/opencode/tui.json` so the TUI process picks the sidebar up on the next host start.
51+
- Refuses to install when the host's OpenCode version falls outside the package's `engines.opencode` range (`>=1.17.13 <2`).
52+
53+
#### Manual config (hand-edited configs)
54+
55+
If you cannot use `opencode plugin`, write both files by hand. The server entry lives in `opencode.json`:
4256

4357
```jsonc
58+
// ~/.config/opencode/opencode.json
4459
{
4560
"plugin": ["@cortexkit/opencode-antigravity-auth@latest"]
4661
}
4762
```
4863

49-
The plugin field is the **server** subpath. The TUI sidebar is loaded automatically through the `oc-plugin` declaration in the npm package; no extra config is required on a 1.17.13+ host. On older hosts, explicitly add the `./tui` exports subpath through the host plugin loader.
64+
The TUI entry lives in a separate `tui.json` file under the same config dir:
65+
66+
```jsonc
67+
// ~/.config/opencode/tui.json
68+
{
69+
"plugins": ["@cortexkit/opencode-antigravity-auth"]
70+
}
71+
```
72+
73+
The two files are independent — the host reads the server registration from `opencode.json` and the TUI registration from `tui.json`. Dropping one side disables that half of the plugin without touching the other.
5074

5175
### OpenCode from this checkout (contributors)
5276

STRUCTURE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Every production file has a corresponding `*.test.ts` sibling. The dense transfo
9999

100100
## `packages/opencode` inventory
101101

102-
`@cortexkit/opencode-antigravity-auth`. Has two `oc-plugin` entry points (`server`, `tui`) declared in `package.json:32-45`. Production layout:
102+
`@cortexkit/opencode-antigravity-auth`. Exposes two `exports` subpaths (`"."` and `"./tui"`) and pins the supported host range through `engines.opencode` (`>=1.17.13 <2`); the host installer (`opencode plugin`) reads the subpaths and writes a server entry to `opencode.json` and a TUI entry to `tui.json`. Production layout:
103103

104104
```
105105
packages/opencode/
@@ -343,7 +343,7 @@ Project-wide tsconfig used by `bun run typecheck` (root script `typecheck`) for
343343
| `@cortexkit/opencode-antigravity-auth` (`server` — fallback) | `packages/opencode/src/plugin-entry.test.ts` | test entry | Verifies the public barrel exports the two stable plugin names. |
344344
| `@cortexkit/pi-antigravity-auth` | `packages/pi/src/index.ts` | `default function` | Pi extension. Resolves as `pi.extensions: ['./dist/index.js']` per `packages/pi/package.json:34-38`. |
345345

346-
The `oc-plugin` manifest at `packages/opencode/package.json:32-45` declares the `server` and `tui` entry points and the `exports` map declares both `.` (the bundled server root) and `./tui` (the loader). The host resolves them as separate plugin registrations.
346+
The `exports` map at `packages/opencode/package.json` declares both `.` (the bundled server root) and `./tui` (the OpenTUI loader). The host's `opencode plugin` installer reads the subpaths and writes a server entry to `opencode.json` plus a TUI entry to `tui.json`; the host then resolves them as two independent plugin registrations.
347347

348348
## Generated and ignored artifacts
349349

packages/opencode/README.md

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,49 @@ This package is part of the `@cortexkit/antigravity-auth@2.0.0` monorepo. See th
3232
| `@opentui/core`, `@opentui/keymap`, `@opentui/solid` (peer) | `^0.4.5` each |
3333
| Node | `>=20` |
3434

35-
The package declares both `oc-plugin` subpaths in its `package.json`:
35+
The package pins the supported host range through `engines.opencode` (`>=1.17.13 <2`); `opencode plugin` refuses to install a plugin that asks for an unsupported range.
3636

37-
```jsonc
38-
{
39-
"oc-plugin": ["server", "tui"]
40-
}
41-
```
37+
The package exposes two `exports` subpaths the host installer reads:
4238

43-
OpenCode 1.17.13+ resolves the **server** subpath through the `plugin` array and the **tui** subpath through `oc-plugin` automatically. Legacy hosts can declare the `./tui` exports subpath explicitly through their own plugin loader.
39+
- `exports["."]` — the bundled `dist/index.js` server root. `opencode plugin` writes this entry into `opencode.json`'s `plugin` array.
40+
- `exports["./tui"]``src/tui/entry.mjs`, the OpenTUI sidebar loader. `opencode plugin` writes this entry into `tui.json` so the TUI process picks it up on the next host start.
4441

4542
## Installation
4643

4744
### End-user (npm) — the supported path
4845

49-
Add to `~/.config/opencode/opencode.json`:
46+
The supported installer writes both registrations in one step:
5047

51-
```json
48+
```bash
49+
opencode plugin @cortexkit/opencode-antigravity-auth@latest
50+
```
51+
52+
What this does:
53+
54+
- Reads the package's `exports["."]` and writes it into `~/.config/opencode/opencode.json` under the `plugin` array — the `auth.loader` and `fetch` interceptor the host calls on every model dispatch.
55+
- Reads the package's `exports["./tui"]` and writes it into `~/.config/opencode/tui.json` so the TUI process picks the sidebar up on the next host start.
56+
- Refuses to install when the host's OpenCode version falls outside the package's `engines.opencode` range.
57+
58+
#### Manual config (hand-edited configs)
59+
60+
If you cannot use `opencode plugin`, write both files by hand:
61+
62+
```jsonc
63+
// ~/.config/opencode/opencode.json
5264
{
5365
"plugin": ["@cortexkit/opencode-antigravity-auth@latest"]
5466
}
5567
```
5668

69+
```jsonc
70+
// ~/.config/opencode/tui.json
71+
{
72+
"plugins": ["@cortexkit/opencode-antigravity-auth"]
73+
}
74+
```
75+
76+
The two files are independent — the server registration is read from `opencode.json` and the TUI registration from `tui.json`.
77+
5778
Then start OpenCode and run `opencode auth login`, pick **Antigravity (Google OAuth)** in the menu (or `/antigravity-account add`). Verify with `npx -y @cortexkit/opencode-antigravity-auth quota`.
5879

5980
### Contributor (Bun)
@@ -80,7 +101,7 @@ A precompiled JSX tree ships under `dist/src/tui-compiled/` and is regenerated b
80101
import { authorizeAntigravity, exchangeAntigravity } from "@cortexkit/antigravity-auth-core"
81102
```
82103

83-
- **`@opencode-ai/plugin` peer dependency** moved from `^0.15.30` to `^1.17.13`. Hosts on 1.17.13+ get the automatic `oc-plugin: tui` discovery for free.
104+
- **`@opencode-ai/plugin` peer dependency** moved from `^0.15.30` to `^1.17.13`. Hosts on 1.17.13+ get the TUI registration through `opencode plugin` (the host reads `exports["./tui"]` and writes it into `tui.json`).
84105
- **New peer dependencies** (`@opentui/core`, `@opentui/keymap`, `@opentui/solid` at `^0.4.5`) — required by the sidebar.
85106
- No account-storage changes: the on-disk format is unchanged from the v1.4+ storage schema (`AccountStorageV4`).
86107
- Missing accounts now return **HTTP 401 `UNAUTHENTICATED`** from the fetch interceptor instead of a synthetic 200 with assistant text.

packages/opencode/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727
"claude"
2828
],
2929
"engines": {
30-
"node": ">=20.0.0"
30+
"node": ">=20.0.0",
31+
"opencode": ">=1.17.13 <2"
3132
},
32-
"oc-plugin": [
33-
"server",
34-
"tui"
35-
],
3633
"exports": {
3734
".": {
3835
"import": "./dist/index.js",

packages/opencode/scripts/smoke-tui-pack-install.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* directory through `bun add ./pack.tgz` (so the package export map is
44
* actually exercised), and assert the tarball + install shape:
55
*
6-
* - `package.json` exposes `oc-plugin: ["server", "tui"]`.
7-
* - `package.json` exports `./tui` pointing at `src/tui/entry.mjs`.
6+
* - `package.json` `engines.opencode` pins the host-version range
7+
* that `opencode plugin` enforces.
8+
* - `package.json` exports `./tui` pointing at `src/tui/entry.mjs`
9+
* (the host installer reads this subpath when wiring the TUI
10+
* registration into `tui.json`).
811
* - The compiled tree lands at `src/tui-compiled/tui.tsx` (where the
912
* host entry module expects it after a successful virtual runtime
1013
* probe).
@@ -13,7 +16,7 @@
1316
* real package export map (`import('@cortexkit/opencode-antigravity-auth/tui')`).
1417
*
1518
* Runs only via `bun run smoke:tui`. Use this on every package change
16-
* that touches `package.json` `exports`, `files`, or `oc-plugin` — a
19+
* that touches `package.json` `exports`, `files`, or `engines` — a
1720
* broken pack is a broken ship.
1821
*/
1922

@@ -30,9 +33,9 @@ const CORE_ROOT = resolve(REPO_ROOT, 'packages/core')
3033
interface PackageJson {
3134
name: string
3235
version: string
36+
engines?: Record<string, string>
3337
exports?: Record<string, unknown>
3438
files?: string[]
35-
'oc-plugin'?: string[]
3639
}
3740

3841
async function run(): Promise<void> {
@@ -61,17 +64,16 @@ async function run(): Promise<void> {
6164
const pkgRaw = readFileSync(join(PACKAGE_ROOT, 'package.json'), 'utf-8')
6265
const pkg = JSON.parse(pkgRaw) as PackageJson
6366

64-
// 1) `oc-plugin` must list `tui`.
65-
const ocPlugin = pkg['oc-plugin']
66-
if (!Array.isArray(ocPlugin) || ocPlugin.length === 0) {
67-
throw new Error('package.json is missing oc-plugin metadata')
68-
}
69-
if (!ocPlugin.includes('tui')) {
70-
throw new Error('package.json oc-plugin does not list "tui"')
67+
// 1) `engines.opencode` must pin the host-version range that
68+
// `opencode plugin` enforces at install time.
69+
const opencodeEngine = pkg.engines?.opencode
70+
if (typeof opencodeEngine !== 'string' || opencodeEngine.length === 0) {
71+
throw new Error('package.json is missing engines.opencode metadata')
7172
}
7273

7374
// 2) `./tui` must be exposed in the exports map and point at
74-
// `tui/entry.mjs`.
75+
// `tui/entry.mjs` — the host installer reads this subpath to
76+
// wire the TUI registration into `tui.json`.
7577
const tuiExport = pkg.exports?.['./tui']
7678
if (!tuiExport || typeof tuiExport !== 'object') {
7779
throw new Error('package.json exports must include "./tui" entry')

0 commit comments

Comments
 (0)