opencode-ahp 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +188 -2
- package/options.example.jsonc +44 -0
- package/package.json +50 -4
- package/src/bridge.ts +722 -0
- package/src/channels.ts +109 -0
- package/src/handshake.ts +124 -0
- package/src/host.ts +1795 -0
- package/src/index.ts +361 -0
- package/src/options.ts +229 -0
- package/src/seq.ts +87 -0
- package/src/state.ts +81 -0
- package/src/transport.ts +270 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Matt Zinkevicius
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,189 @@
|
|
|
1
|
-
#
|
|
1
|
+
# opencode-ahp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OpenCode v2 plugin that hosts the **Agent Host Protocol (AHP) 1.0.0**
|
|
4
|
+
in-process so opencode is a native agent in the **VS Code Agents window** —
|
|
5
|
+
on this machine and (MVP scope) on other machines over the local LAN.
|
|
6
|
+
|
|
7
|
+
> **Status: Phase 1 — MVP complete.** Sessions, model + agent pickers,
|
|
8
|
+
> streaming, tool calls, permission prompts, steering/queue, and usage are
|
|
9
|
+
> live-verified over the LAN with VS Code 1.145.2 (real Agents window ↔
|
|
10
|
+
> host). The full plan and wire findings live in
|
|
11
|
+
> [`plan.md`](plan.md).
|
|
12
|
+
|
|
13
|
+
## What you get
|
|
14
|
+
|
|
15
|
+
In the Agents window, an `opencode` host with:
|
|
16
|
+
|
|
17
|
+
- **Sessions** — new sessions (AHP `createSession`), a live session list
|
|
18
|
+
(opencode titles/statuses), and chat state across reconnects (snapshot +
|
|
19
|
+
replay).
|
|
20
|
+
- **Model picker** — the real opencode catalog: every provider/model the
|
|
21
|
+
opencode server exposes, including llama.cpp servers registered by sync
|
|
22
|
+
plugins.
|
|
23
|
+
- **Agent picker** — opencode's user-invocable agents (Build, Plan, and
|
|
24
|
+
anything user-defined) appear as AHP custom agents; subagent-mode agents
|
|
25
|
+
are hidden from the picker.
|
|
26
|
+
- **Chat** — streaming text + reasoning, the full tool-call lifecycle
|
|
27
|
+
(started → ready → confirmed → complete), and usage totals.
|
|
28
|
+
- **Permissions** — opencode's `permission.asked` becomes an in-window
|
|
29
|
+
approval prompt; approve runs the tool, deny blocks it.
|
|
30
|
+
- **Steering + queue** — a message sent mid-turn steers the active turn or
|
|
31
|
+
queues for the next one (AHP `pendingMessageSet`).
|
|
32
|
+
|
|
33
|
+
Not yet (Phase 2+): changesets/file diffs, native `wss://` TLS, cancelling
|
|
34
|
+
a queued message, the `always` permission reply.
|
|
35
|
+
|
|
36
|
+
## Requirements
|
|
37
|
+
|
|
38
|
+
- **opencode v2** (≥ 2.2.6 verified). The plugin runs *inside* the opencode
|
|
39
|
+
server — no extra process; it only opens one extra port.
|
|
40
|
+
- **VS Code ≥ 1.144** (1.145.2 verified) for the Agents window and
|
|
41
|
+
`Agents: Add Remote Agent Host…`. VS Code ships the AHP client — nothing
|
|
42
|
+
is installed on the client machine.
|
|
43
|
+
- Node + pnpm (via [mise](https://mise.jdx.dev)) for **development only**.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
The plugin loads from an explicit `plugins` entry — never from a discovery
|
|
48
|
+
path (which would double-load it).
|
|
49
|
+
|
|
50
|
+
**Published (npm):**
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
opencode plugin add opencode-ahp
|
|
54
|
+
# or from git:
|
|
55
|
+
opencode plugin add github:mattzink/opencode-ahp
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Dev (local checkout):**
|
|
59
|
+
|
|
60
|
+
```jsonc
|
|
61
|
+
// ~/.config/opencode/opencode.jsonc
|
|
62
|
+
{
|
|
63
|
+
"plugins": [{
|
|
64
|
+
"package": "/path/to/opencode-ahp",
|
|
65
|
+
"options": { /* see Options below */ }
|
|
66
|
+
}]
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Restart the opencode service afterwards (`opencode service restart`). The
|
|
71
|
+
AHP listener starts when the location for the configured directory boots.
|
|
72
|
+
|
|
73
|
+
## Options
|
|
74
|
+
|
|
75
|
+
Per-key resolution: the config entry's `options` ▸ an `options.jsonc`
|
|
76
|
+
sibling of `src/index.ts` (checkouts only — copy
|
|
77
|
+
[`options.example.jsonc`](options.example.jsonc)) ▸ built-in defaults.
|
|
78
|
+
|
|
79
|
+
| Key | Default | Description |
|
|
80
|
+
| --- | --- | --- |
|
|
81
|
+
| `enabled` | `true` | Master switch; `false` → no listener, the plugin is fully inert |
|
|
82
|
+
| `port` | `8765` | WS listen port |
|
|
83
|
+
| `host` | `"127.0.0.1"` | Bind address; a **non-loopback bind requires an explicit `token`** (the listener refuses to start otherwise) |
|
|
84
|
+
| `path` | `"/ahp"` | WS path — VS Code's URL carries it verbatim |
|
|
85
|
+
| `token` | auto | Omit → generated on first start, persisted in opencode's plugin storage, printed once to the service log. Accepted via the `?token=` query param and `Authorization: Bearer <token>`. **Always enforced**, loopback or not |
|
|
86
|
+
| `allowedOrigins` | `"*"` | `"*"` or an exact list, e.g. `["vscode://vscode"]`. The token is still always required regardless |
|
|
87
|
+
| `tls` | `null` | `{ keyPath, certPath }` — native TLS → `wss://` (post-MVP; only needed for off-LAN transports) |
|
|
88
|
+
| `healthPath` | `"/healthz"` | Plain-HTTP health endpoint (no auth): `curl …:8765/healthz` → `ok` |
|
|
89
|
+
| `replayWindow` | `1000` | Per-channel actions kept for reconnect replay; older gaps → fresh snapshot |
|
|
90
|
+
| `capabilities` | `{ changesets: false, terminals: false, automations: false }` | Advertised in `initialize` — never advertise what we don't implement |
|
|
91
|
+
|
|
92
|
+
## Remote access (local LAN — MVP)
|
|
93
|
+
|
|
94
|
+
MVP transport is plain `ws://` + token on the LAN (the token in the URL is
|
|
95
|
+
cleartext — LAN only, by design). Off-LAN options (Tailscale, a dev-tunnel
|
|
96
|
+
port forward, any `wss://` proxy) are post-MVP; the host accepts any
|
|
97
|
+
`ws(s)://` URL whose path and token match.
|
|
98
|
+
|
|
99
|
+
### Host side
|
|
100
|
+
|
|
101
|
+
1. Serve the project on all interfaces: `opencode service set hostname
|
|
102
|
+
0.0.0.0` + restart, or a dedicated
|
|
103
|
+
`opencode serve --hostname 0.0.0.0 --port <port>`.
|
|
104
|
+
2. Configure the plugin (project or global `opencode.jsonc`):
|
|
105
|
+
|
|
106
|
+
```jsonc
|
|
107
|
+
{
|
|
108
|
+
// Required: opencode v2 unloads idle locations after 60 minutes, and
|
|
109
|
+
// AHP WebSocket connections do NOT count as location activity —
|
|
110
|
+
// without this the listener silently stops overnight.
|
|
111
|
+
"experimental": { "location_idle_timeout": false },
|
|
112
|
+
"plugins": [{
|
|
113
|
+
"package": "opencode-ahp",
|
|
114
|
+
"options": {
|
|
115
|
+
"host": "0.0.0.0",
|
|
116
|
+
"token": "change-me-to-a-long-random-string"
|
|
117
|
+
// "allowedOrigins": "vscode://vscode" // tighten once it works
|
|
118
|
+
}
|
|
119
|
+
}]
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
3. **Boot the location once** — the AHP listener exists only while the
|
|
124
|
+
location is up. Open the project once (run the `opencode` TUI in it, or
|
|
125
|
+
open it in an IDE), or headless:
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
curl -g -u opencode:<server-password> \
|
|
129
|
+
'http://127.0.0.1:<port>/api/location?location[directory]=<project-dir>'
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
With `location_idle_timeout: false` the listener then stays up
|
|
133
|
+
indefinitely.
|
|
134
|
+
4. Verify: `curl -s http://<host-lan-ip>:<port>/healthz` → `ok`.
|
|
135
|
+
|
|
136
|
+
Full two-machine walkthrough:
|
|
137
|
+
[`docs/lan-test-runbook.md`](docs/lan-test-runbook.md).
|
|
138
|
+
|
|
139
|
+
### Client side (each PC)
|
|
140
|
+
|
|
141
|
+
Command Palette → **`Agents: Add Remote Agent Host…`** → paste:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
ws://<host-lan-ip>:8765/ahp?token=<token>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Or persist it in `settings.json` — with Settings Sync on, that one line
|
|
148
|
+
propagates to every PC:
|
|
149
|
+
|
|
150
|
+
```jsonc
|
|
151
|
+
"chat.remoteAgentHosts": [{ "name": "opencode", "address": "ws://…:8765/ahp?token=…" }]
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Note: the Agents window's built-in **SSH** and **Dev tunnels** flows run
|
|
155
|
+
*VS Code's bundled* agent host — they are **not** a path to this plugin.
|
|
156
|
+
For a third-party host, only raw network reachability of the `ws(s)://`
|
|
157
|
+
URL matters.
|
|
158
|
+
|
|
159
|
+
## Development
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
mise install # node + pnpm per mise.toml / package.json
|
|
163
|
+
pnpm install
|
|
164
|
+
pnpm typecheck
|
|
165
|
+
pnpm test # pure modules + a captured turn replayed through the real AHP reducers
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Dependency-free live probes (Node ≥ 20 global WebSocket):
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
node scripts/ahp-client.mjs --token <token> [--base http://127.0.0.1:8765]
|
|
172
|
+
# Phase 1 end-to-end: createSession → agent-picker snapshot → full turn lifecycle
|
|
173
|
+
node scripts/ahp-phase1.mjs --token <token> --base http://127.0.0.1:8765 --provider opencode
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Publishing
|
|
177
|
+
|
|
178
|
+
House pattern: push to `main` → CI (`typecheck` + `test`) → the publish
|
|
179
|
+
workflow computes the version as `<major>.<minor>.<run-number>` and
|
|
180
|
+
`npm publish`es via **npm trusted publishing (OIDC)** — no npm token or
|
|
181
|
+
repo secret is stored (one-time setup: npmjs.com → package → *Package
|
|
182
|
+
settings* → *Trusted publishers* → this workflow).
|
|
183
|
+
|
|
184
|
+
Installed copies don't auto-update: `opencode plugin update opencode-ahp`
|
|
185
|
+
+ `opencode service restart`.
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Documented option set for opencode-ahp (plan §8.2).
|
|
3
|
+
//
|
|
4
|
+
// How to use: copy this file to `options.jsonc` next to src/index.ts when
|
|
5
|
+
// running from a checkout, or — the usual case — put the values you want
|
|
6
|
+
// in the plugin entry's `options` object in opencode.jsonc (that takes
|
|
7
|
+
// precedence per key). npm installs ship no sibling options file.
|
|
8
|
+
|
|
9
|
+
// Master switch; false → no listener, the plugin is fully inert.
|
|
10
|
+
// "enabled": true,
|
|
11
|
+
|
|
12
|
+
// WS listen port.
|
|
13
|
+
// "port": 8765,
|
|
14
|
+
|
|
15
|
+
// Bind address. Binding a non-loopback address REQUIRES a token (the
|
|
16
|
+
// listener refuses to start without one — plan R4).
|
|
17
|
+
// "host": "127.0.0.1",
|
|
18
|
+
|
|
19
|
+
// WS path — VS Code's remoteAgentHosts URL carries it verbatim.
|
|
20
|
+
// "path": "/ahp",
|
|
21
|
+
|
|
22
|
+
// Auth token. Omit to auto-generate one on first start (persisted in
|
|
23
|
+
// opencode's plugin storage, printed once to the service log). Accepted
|
|
24
|
+
// via the `?token=` query param and `Authorization: Bearer <token>`.
|
|
25
|
+
// "token": "…",
|
|
26
|
+
|
|
27
|
+
// Origin allowlist: "*" (default) or an exact list, e.g.
|
|
28
|
+
// ["vscode://vscode"]. The token is always required regardless (R5).
|
|
29
|
+
// "allowedOrigins": "*",
|
|
30
|
+
|
|
31
|
+
// Native TLS via Bun.serve → wss:// (post-MVP; only needed for off-LAN
|
|
32
|
+
// transports, D3). Paths to a key and a cert file.
|
|
33
|
+
// "tls": { "keyPath": "/path/key.pem", "certPath": "/path/cert.pem" },
|
|
34
|
+
|
|
35
|
+
// Plain-HTTP health endpoint (no auth).
|
|
36
|
+
// "healthPath": "/healthz",
|
|
37
|
+
|
|
38
|
+
// Global actions kept for reconnect replay; older gaps → fresh snapshot.
|
|
39
|
+
// "replayWindow": 1000,
|
|
40
|
+
|
|
41
|
+
// What initialize advertises — never advertise what we don't implement.
|
|
42
|
+
// changesets flips to true in Phase 2 (D2).
|
|
43
|
+
// "capabilities": { "changesets": false, "terminals": false, "automations": false }
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-ahp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "OpenCode V2 plugin: hosts Agent Host Protocol (AHP) 1.0.0 in-process so opencode is a native agent in the VS Code Agents window",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"!src/test",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"options.example.jsonc"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/mattzink/opencode-ahp.git"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/mattzink/opencode-ahp#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/mattzink/opencode-ahp/issues"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"opencode",
|
|
26
|
+
"opencode-plugin",
|
|
27
|
+
"plugin",
|
|
28
|
+
"agent-host-protocol",
|
|
29
|
+
"ahp",
|
|
30
|
+
"vscode",
|
|
31
|
+
"agents"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=20"
|
|
35
|
+
},
|
|
36
|
+
"packageManager": "pnpm@12.4.2",
|
|
37
|
+
"scripts": {
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"prepublishOnly": "pnpm typecheck && pnpm test"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@microsoft/agent-host-protocol": "1.0.0",
|
|
44
|
+
"@opencode/plugin": "^2.2.6"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^26.6.3",
|
|
48
|
+
"typescript": "^7.0.2",
|
|
49
|
+
"vitest": "^5.0.3"
|
|
50
|
+
},
|
|
51
|
+
"license": "MIT"
|
|
52
|
+
}
|