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/src/transport.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* AHP transport
|
|
2
|
+
* AHP transport.
|
|
3
3
|
*
|
|
4
4
|
* Two layers:
|
|
5
5
|
*
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* policy, path routing, loopback check. Unit-tested without a runtime.
|
|
8
8
|
* 2. **A thin listener** behind the `Listener` interface. The reference
|
|
9
9
|
* implementation uses `Bun.serve` (opencode v2 is Bun-based, so the
|
|
10
|
-
* in-process plugin runtime has it
|
|
11
|
-
*
|
|
10
|
+
* in-process plugin runtime has it). If the plugin context ever
|
|
11
|
+
* forbids raw listeners, a `ws`-
|
|
12
12
|
* package implementation drops in here with no changes to the
|
|
13
13
|
* protocol layer.
|
|
14
14
|
*
|
|
@@ -71,7 +71,7 @@ export function tokenValid(expected: string, presented: string | null): boolean
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* Origin policy
|
|
74
|
+
* Origin policy. The token is the only credential; this only
|
|
75
75
|
* filters *which* browser origins may attempt a connection. A null Origin
|
|
76
76
|
* (non-browser clients: VS Code's own connection, CLI clients) always
|
|
77
77
|
* passes — browser-origin filtering is the real attack surface.
|
|
@@ -104,7 +104,14 @@ export interface ListenerOptions {
|
|
|
104
104
|
/** When null, a non-loopback bind refuses to start (R4). */
|
|
105
105
|
token: string | null;
|
|
106
106
|
allowedOrigins: string[] | "*";
|
|
107
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Native TLS termination → `wss://` (off-LAN transports, D3). The PEM
|
|
109
|
+
* **contents** of the key and certificate — not paths: `Bun.serve`'s
|
|
110
|
+
* `tls.key`/`tls.cert` take contents (string/Buffer/BunFile), and the
|
|
111
|
+
* plugin entry reads the files (the transport stays filesystem-free so
|
|
112
|
+
* its unit tests never touch the disk).
|
|
113
|
+
*/
|
|
114
|
+
tls?: { key: string; cert: string } | null;
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
/** Transport-local connection identity. */
|
|
@@ -176,7 +183,7 @@ const textDecoder = new TextDecoder();
|
|
|
176
183
|
/**
|
|
177
184
|
* Start the AHP listener. Throws before binding when a non-loopback
|
|
178
185
|
* address is given without a token (R4) or when the runtime lacks
|
|
179
|
-
* `Bun.serve` (
|
|
186
|
+
* `Bun.serve` (the fallback implementation would be added here).
|
|
180
187
|
*/
|
|
181
188
|
export function createListener(opts: ListenerOptions, callbacks: TransportCallbacks): Listener {
|
|
182
189
|
if (!isLoopback(opts.host) && !opts.token) {
|
|
@@ -187,7 +194,7 @@ export function createListener(opts: ListenerOptions, callbacks: TransportCallba
|
|
|
187
194
|
const bun = bunOf();
|
|
188
195
|
if (!bun) {
|
|
189
196
|
throw new Error(
|
|
190
|
-
"Bun.serve is not available in this runtime
|
|
197
|
+
"Bun.serve is not available in this runtime; expected inside the " +
|
|
191
198
|
"Bun-based opencode v2 server — a `ws`-package fallback would go here",
|
|
192
199
|
);
|
|
193
200
|
}
|
|
@@ -198,7 +205,7 @@ export function createListener(opts: ListenerOptions, callbacks: TransportCallba
|
|
|
198
205
|
const server = bun.serve({
|
|
199
206
|
hostname: opts.host,
|
|
200
207
|
port: opts.port,
|
|
201
|
-
...(opts.tls ? { tls: { key: opts.tls.
|
|
208
|
+
...(opts.tls ? { tls: { key: opts.tls.key, cert: opts.tls.cert } } : {}),
|
|
202
209
|
fetch(req, srv) {
|
|
203
210
|
const url = new URL(req.url);
|
|
204
211
|
switch (routePath(url, { ahp: opts.path, health: opts.healthPath })) {
|