opencode-ahp 0.1.3 → 0.1.5
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/README.md +95 -20
- package/options.example.jsonc +20 -9
- package/package.json +1 -1
- package/src/bridge.ts +427 -33
- package/src/channels.ts +131 -18
- package/src/client-tools.ts +127 -0
- package/src/handshake.ts +2 -3
- package/src/host.ts +2231 -243
- package/src/index.ts +273 -24
- package/src/keep-alive.ts +3 -3
- package/src/options.ts +12 -7
- package/src/seq.ts +4 -5
- package/src/state.ts +52 -5
- package/src/transport.ts +15 -8
package/README.md
CHANGED
|
@@ -2,13 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
OpenCode v2 plugin that hosts the **Agent Host Protocol (AHP) 1.0.0**
|
|
4
4
|
in-process so opencode is a native agent in the **VS Code Agents window** —
|
|
5
|
-
on this machine and
|
|
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).
|
|
5
|
+
on this machine and on other machines over the local LAN.
|
|
12
6
|
|
|
13
7
|
## What you get
|
|
14
8
|
|
|
@@ -27,11 +21,45 @@ In the Agents window, an `opencode` host with:
|
|
|
27
21
|
(started → ready → confirmed → complete), and usage totals.
|
|
28
22
|
- **Permissions** — opencode's `permission.asked` becomes an in-window
|
|
29
23
|
approval prompt; approve runs the tool, deny blocks it.
|
|
24
|
+
- **Client tools** — a client can register its own tools per session
|
|
25
|
+
(`createSession` or `session/activeClientSet`): the model calls them
|
|
26
|
+
directly, the host delegates execution to the owning client
|
|
27
|
+
(`toolClientExecution` request — the session stays in progress while the
|
|
28
|
+
client runs), and the client's result flows back into the turn, including
|
|
29
|
+
`requiresResultConfirmation` approval. Client tools bypass opencode's
|
|
30
|
+
permission prompt; only the client that provided the tool may execute it
|
|
31
|
+
or confirm its result.
|
|
32
|
+
- **Multi-chat** — a session can host additional chats (AHP `createChat`,
|
|
33
|
+
gated on the advertised `multipleChats` capability): each chat runs
|
|
34
|
+
against its own opencode backend session with fully isolated turns, and
|
|
35
|
+
`disposeChat` removes a chat without touching the session. The chats
|
|
36
|
+
appear in the session's catalog (default chat first); each chat carries
|
|
37
|
+
its own changesets. Fork/side-chat creation is not supported (opencode
|
|
38
|
+
exposes no fork to plugins). Peer-chat backends appear in opencode's own
|
|
39
|
+
UI as ordinary sessions — they are real opencode sessions underneath.
|
|
40
|
+
**Survives restarts:** the host stamps small binding markers into the
|
|
41
|
+
opencode sessions' metadata at create, so after a location reload each
|
|
42
|
+
chat re-attaches at its original URI (and a client-chosen session
|
|
43
|
+
channel resurfaces under its original name); re-attached chat titles are
|
|
44
|
+
re-derived (`Chat 2`, …) while session titles and messages persist.
|
|
30
45
|
- **Steering + queue** — a message sent mid-turn steers the active turn or
|
|
31
46
|
queues for the next one (AHP `pendingMessageSet`).
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
47
|
+
- **Changesets** — per-session diff channels (uncommitted, session, and
|
|
48
|
+
per-turn) backed by the location's git state: live `file://` refs,
|
|
49
|
+
`git show HEAD:` before-refs, and in-memory turn snapshots; the
|
|
50
|
+
`discard-changes` operation restores a file. Requires the location
|
|
51
|
+
directory to be a git repository (otherwise the changesets are empty);
|
|
52
|
+
opt out with `capabilities.changesets: false`.
|
|
53
|
+
- **Terminals** — read-only `ahp-terminal:` channels rendered from
|
|
54
|
+
`shell`-tool executions (`isPty: false`, completed-command output with
|
|
55
|
+
exit codes): while a turn runs a foreground shell command, the terminal
|
|
56
|
+
appears in the root catalog, streams
|
|
57
|
+
`data` → `commandFinished` → `exited` to subscribers, and leaves the
|
|
58
|
+
catalog at turn end (the channel state stays subscribable until the
|
|
59
|
+
chat/session is removed). The terminals are renderings, not pty —
|
|
60
|
+
`createTerminal`/`disposeTerminal` and client `terminal/*` actions get
|
|
61
|
+
clean read-only errors. Opt out with
|
|
62
|
+
`capabilities.terminals: false`.
|
|
35
63
|
|
|
36
64
|
## Requirements
|
|
37
65
|
|
|
@@ -84,18 +112,18 @@ sibling of `src/index.ts` (checkouts only — copy
|
|
|
84
112
|
| `path` | `"/ahp"` | WS path — VS Code's URL carries it verbatim |
|
|
85
113
|
| `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
114
|
| `allowedOrigins` | `"*"` | `"*"` or an exact list, e.g. `["vscode://vscode"]`. The token is still always required regardless |
|
|
87
|
-
| `tls` | `null` | `{ keyPath, certPath }` — native TLS → `wss://` (
|
|
88
|
-
| `healthPath` | `"/healthz"` |
|
|
115
|
+
| `tls` | `null` | `{ keyPath, certPath }` — native TLS termination → `wss://` (off-LAN transports, D3). PEM **file paths**; the port becomes TLS-only (plain-HTTP requests to it fail) and the health endpoint is then HTTPS: `curl -k https://…:8765/healthz`. A missing/unreadable file disables the AHP listener — the opencode server keeps running |
|
|
116
|
+
| `healthPath` | `"/healthz"` | Health endpoint (no auth): `curl …:8765/healthz` → `ok` (over the same TLS termination when `tls` is set) |
|
|
89
117
|
| `keepAlive` | `true` | Keep the opencode location loaded against its idle timeout (`experimental.location_idle_timeout`, default 60 min) by periodically touching an internal anchor session — with this on, **no `location_idle_timeout` config entry is needed**. The anchor (`opencode-ahp (keep-alive)`) is a real opencode session: it shows in the TUI session list but is hidden from AHP clients (opencode's plugin surface cannot archive it) |
|
|
90
118
|
| `keepAliveIntervalMinutes` | `10` | Minutes between keep-alive touches; keep well below the effective idle timeout |
|
|
91
119
|
| `replayWindow` | `1000` | Per-channel actions kept for reconnect replay; older gaps → fresh snapshot |
|
|
92
|
-
| `capabilities` | `{ changesets:
|
|
120
|
+
| `capabilities` | `{ changesets: true, terminals: true, automations: false }` | Host-side switches — never advertise what we don't implement (in AHP 1.0.0 none of these is a wire field; discovery is the state's optionality). Set `changesets` to `false` to disable the diff channels (the session/chat snapshots then carry no changeset catalogues and changeset URIs resolve to nothing); set `terminals` to `false` to disable the synthetic shell-command terminal channels (no `root/terminals` list, `shell` calls open no `ahp-terminal:` channels) |
|
|
93
121
|
|
|
94
|
-
## Remote access (local LAN
|
|
122
|
+
## Remote access (local LAN)
|
|
95
123
|
|
|
96
|
-
|
|
124
|
+
The LAN transport is plain `ws://` + token (the token in the URL is
|
|
97
125
|
cleartext — LAN only, by design). Off-LAN options (Tailscale, a dev-tunnel
|
|
98
|
-
port forward, any `wss://` proxy) are
|
|
126
|
+
port forward, any `wss://` proxy) are operational; the host accepts any
|
|
99
127
|
`ws(s)://` URL whose path and token match.
|
|
100
128
|
|
|
101
129
|
### Host side
|
|
@@ -142,8 +170,9 @@ port forward, any `wss://` proxy) are post-MVP; the host accepts any
|
|
|
142
170
|
needs an upstream auto-boot option.)
|
|
143
171
|
4. Verify: `curl -s http://<host-lan-ip>:<port>/healthz` → `ok`.
|
|
144
172
|
|
|
145
|
-
Full two-machine walkthrough:
|
|
146
|
-
|
|
173
|
+
Full two-machine walkthrough (and the complete testing strategy: unit,
|
|
174
|
+
static, live verification, two-machine, conformance):
|
|
175
|
+
[`docs/testing.md`](docs/testing.md).
|
|
147
176
|
|
|
148
177
|
### Client side (each PC)
|
|
149
178
|
|
|
@@ -165,6 +194,33 @@ Note: the Agents window's built-in **SSH** and **Dev tunnels** flows run
|
|
|
165
194
|
For a third-party host, only raw network reachability of the `ws(s)://`
|
|
166
195
|
URL matters.
|
|
167
196
|
|
|
197
|
+
### Off-LAN: native `wss://`
|
|
198
|
+
|
|
199
|
+
When plain LAN `ws://` doesn't fit (host on another network, or
|
|
200
|
+
token-in-URL on a shared network you don't want), set `tls` and the same
|
|
201
|
+
listener serves `wss://` — native termination in `Bun.serve`, no proxy in
|
|
202
|
+
the middle:
|
|
203
|
+
|
|
204
|
+
```jsonc
|
|
205
|
+
"options": {
|
|
206
|
+
"host": "0.0.0.0",
|
|
207
|
+
"token": "change-me-to-a-long-random-string",
|
|
208
|
+
"tls": {
|
|
209
|
+
"keyPath": "/path/tls-key.pem",
|
|
210
|
+
"certPath": "/path/tls-cert.pem"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The client URL becomes `wss://<host>:8767/ahp?token=<token>` and the
|
|
216
|
+
token/Origin policy is unchanged. The certificate must be trusted by the
|
|
217
|
+
client machine for the URL's hostname: VS Code expects a real chain
|
|
218
|
+
(mkcert on a dev network, or any CA the client trusts); self-signed
|
|
219
|
+
certs only work for script-based checks
|
|
220
|
+
(`NODE_TLS_REJECT_UNAUTHORIZED=0`). With `tls` set the port is
|
|
221
|
+
**TLS-only** — plain-HTTP requests to it fail, and the health check
|
|
222
|
+
becomes `curl -k https://<host>:<port>/healthz` → `ok`.
|
|
223
|
+
|
|
168
224
|
## Development
|
|
169
225
|
|
|
170
226
|
```sh
|
|
@@ -178,8 +234,20 @@ Dependency-free live probes (Node ≥ 20 global WebSocket):
|
|
|
178
234
|
|
|
179
235
|
```sh
|
|
180
236
|
node scripts/ahp-client.mjs --token <token> [--base http://127.0.0.1:8765]
|
|
181
|
-
#
|
|
182
|
-
node scripts/ahp-
|
|
237
|
+
# end-to-end: createSession → agent-picker snapshot → full turn lifecycle
|
|
238
|
+
node scripts/ahp-turn-lifecycle.mjs --token <token> --base http://127.0.0.1:8765 --provider opencode
|
|
239
|
+
# changesets end-to-end: edit → diffs → discard, plus mid-turn reconnect/replay
|
|
240
|
+
node scripts/ahp-changesets.mjs --token <token> --base http://127.0.0.1:8765
|
|
241
|
+
# client-provided tools (ping tool, failed result, confirmation cycle)
|
|
242
|
+
node scripts/ahp-client-tools.mjs --token <token> --base http://127.0.0.1:8765
|
|
243
|
+
# multi-chat (createChat/disposeChat, per-chat backends, no ghost sessions)
|
|
244
|
+
node scripts/ahp-multi-chat.mjs --token <token> --base http://127.0.0.1:8765
|
|
245
|
+
# multi-chat durability: leave the peer chat + backend alive, reload the
|
|
246
|
+
# location, then recheck the re-attachment (chat at its original URI)
|
|
247
|
+
node scripts/ahp-multi-chat.mjs --token <token> --base http://127.0.0.1:8765 --leave-peer
|
|
248
|
+
node scripts/ahp-multi-chat.mjs --token <token> --base http://127.0.0.1:8765 --recheck <sessionChannel> <peerChatURI>
|
|
249
|
+
# the same probes over native wss:// (self-signed test cert):
|
|
250
|
+
NODE_TLS_REJECT_UNAUTHORIZED=0 node scripts/ahp-changesets.mjs --token <token> --base https://127.0.0.1:8765
|
|
183
251
|
```
|
|
184
252
|
|
|
185
253
|
## Publishing
|
|
@@ -193,6 +261,13 @@ settings* → *Trusted publishers* → this workflow).
|
|
|
193
261
|
Installed copies don't auto-update: `opencode plugin update opencode-ahp`
|
|
194
262
|
- `opencode service restart`.
|
|
195
263
|
|
|
264
|
+
## Documentation
|
|
265
|
+
|
|
266
|
+
- [`docs/design.md`](docs/design.md) — architecture and wire-contract findings.
|
|
267
|
+
- [`docs/futures.md`](docs/futures.md) — candidate future work
|
|
268
|
+
- [`docs/testing.md`](docs/testing.md) — the testing strategy: unit, live
|
|
269
|
+
verification, two-machine, and conformance.
|
|
270
|
+
|
|
196
271
|
## License
|
|
197
272
|
|
|
198
273
|
MIT — see [LICENSE](LICENSE).
|
package/options.example.jsonc
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
// Documented option set for opencode-ahp
|
|
2
|
+
// Documented option set for opencode-ahp.
|
|
3
3
|
//
|
|
4
4
|
// How to use: copy this file to `options.jsonc` next to src/index.ts when
|
|
5
5
|
// running from a checkout, or — the usual case — put the values you want
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
// WS listen port.
|
|
13
13
|
// "port": 8765,
|
|
14
14
|
|
|
15
|
-
// Bind address. Binding a non-loopback address REQUIRES a token (
|
|
16
|
-
// listener refuses to start without one
|
|
15
|
+
// Bind address. Binding a non-loopback address REQUIRES a token (R4:
|
|
16
|
+
// the listener refuses to start without one).
|
|
17
17
|
// "host": "127.0.0.1",
|
|
18
18
|
|
|
19
19
|
// WS path — VS Code's remoteAgentHosts URL carries it verbatim.
|
|
@@ -25,11 +25,13 @@
|
|
|
25
25
|
// "token": "…",
|
|
26
26
|
|
|
27
27
|
// Origin allowlist: "*" (default) or an exact list, e.g.
|
|
28
|
-
// ["vscode://vscode"]. The token is always required regardless
|
|
28
|
+
// ["vscode://vscode"]. The token is always required regardless.
|
|
29
29
|
// "allowedOrigins": "*",
|
|
30
30
|
|
|
31
|
-
// Native TLS via Bun.serve → wss:// (
|
|
32
|
-
//
|
|
31
|
+
// Native TLS termination via Bun.serve → wss:// (off-LAN transports,
|
|
32
|
+
// D3). Paths to the PEM key and certificate files; with this set the
|
|
33
|
+
// port is TLS-only (health endpoint → `curl -k https://…/healthz`).
|
|
34
|
+
// The cert must be trusted by client machines for the URL hostname.
|
|
33
35
|
// "tls": { "keyPath": "/path/key.pem", "certPath": "/path/cert.pem" },
|
|
34
36
|
|
|
35
37
|
// Plain-HTTP health endpoint (no auth).
|
|
@@ -37,7 +39,7 @@
|
|
|
37
39
|
|
|
38
40
|
// Keep the opencode location loaded against the idle timeout
|
|
39
41
|
// (experimental.location_idle_timeout, default 60 min) by touching an
|
|
40
|
-
// internal anchor session periodically
|
|
42
|
+
// internal anchor session periodically. On, the
|
|
41
43
|
// location_idle_timeout config entry is not needed. The anchor shows in
|
|
42
44
|
// the TUI session list as "opencode-ahp (keep-alive)"; AHP clients never
|
|
43
45
|
// see it.
|
|
@@ -50,7 +52,16 @@
|
|
|
50
52
|
// Global actions kept for reconnect replay; older gaps → fresh snapshot.
|
|
51
53
|
// "replayWindow": 1000,
|
|
52
54
|
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
+
// Host-side capability switches — never advertise what we don't
|
|
56
|
+
// implement (in AHP 1.0.0 none of these is a wire field; discovery is
|
|
57
|
+
// the state's optionality).
|
|
58
|
+
// Default: { "changesets": true, "terminals": true, "automations": false }.
|
|
59
|
+
// "changesets": false disables the diff channels (no changeset
|
|
60
|
+
// catalogues in the session/chat snapshots; changeset URIs resolve to
|
|
61
|
+
// nothing). Changesets require the location directory to be a git
|
|
62
|
+
// repository.
|
|
63
|
+
// "terminals": false disables the synthetic shell-command terminal
|
|
64
|
+
// channels (shell-tool calls open no ahp-terminal: channels and the
|
|
65
|
+
// root state carries no terminals list).
|
|
55
66
|
// "capabilities": { "changesets": false, "terminals": false, "automations": false }
|
|
56
67
|
}
|
package/package.json
CHANGED