hivecode-mcp 0.12.1 → 0.12.4

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/hive-mux-proto.js CHANGED
@@ -1,58 +1,58 @@
1
- // hive-mux-proto.js -- the wire format for ONE socket per participant, shared by relay and client.
2
- //
3
- // WHY: Hivecode opened one WebSocket per FILE. A participant held 1 + min(files, 128) sockets,
4
- // so an agent in a 1000-file repository saw only 128 files on disk, and a relay's connection cap
5
- // divided by 129 per person. The mux carries every file doc of one room over one socket.
6
- //
7
- // The design rule that makes it safe: the relay does not grow a second enforcement path. Each
8
- // OPEN runs the SAME per-doc admission a per-file upgrade runs (token scope for that path, the
9
- // per-room ceiling, the committer limit), and the accepted channel is wrapped in a VirtualConn
10
- // that looks exactly like a ws connection to installUsageLimits, makeReadOnly, installWriteGate
11
- // and setupWSConnection. The bytes inside a MSG frame are the same y-protocols message a
12
- // per-file socket would carry.
13
- //
14
- // Frames are binary, lib0-encoded:
15
- // client -> relay OPEN [0, id, docName] open this file doc as channel `id`
16
- // CLOSE [1, id] the client is done with it
17
- // MSG [2, id, ...payload] a y-protocols message for that doc
18
- // relay -> client MSG [2, id, ...payload]
19
- // OPENED [3, id] admitted; the relay's sync step 1 follows
20
- // REFUSED [4, id, code, reason] not admitted -- the HTTP status a per-file
21
- // upgrade would have answered, and why
22
- // CLOSED [5, id, reason] the relay closed that channel
23
- // BEAT [6, 0] liveness, so a dead socket is noticed
24
- // Channel ids are chosen by the client and are only meaningful on the socket that opened them.
25
- import * as encoding from 'lib0/encoding'
26
- import * as decoding from 'lib0/decoding'
27
-
28
- export const MUX_PREFIX = '_hive_mux/'
29
- export const MUX_VERSION = 1
30
- export const F = Object.freeze({ OPEN: 0, CLOSE: 1, MSG: 2, OPENED: 3, REFUSED: 4, CLOSED: 5, BEAT: 6 })
31
-
32
- export function encodeFrame(kind, id, a, b) {
33
- const e = encoding.createEncoder()
34
- encoding.writeVarUint(e, kind)
35
- encoding.writeVarUint(e, id >>> 0)
36
- if (kind === F.OPEN) encoding.writeVarString(e, String(a))
37
- else if (kind === F.MSG) encoding.writeUint8Array(e, a instanceof Uint8Array ? a : new Uint8Array(a))
38
- else if (kind === F.REFUSED) { encoding.writeVarUint(e, a >>> 0); encoding.writeVarString(e, String(b || '')) }
39
- else if (kind === F.CLOSED) encoding.writeVarString(e, String(a || ''))
40
- return encoding.toUint8Array(e)
41
- }
42
-
43
- /** Decode one frame. Throws on garbage, which the caller treats as a protocol violation. */
44
- export function decodeFrame(buf) {
45
- const u8 = buf instanceof Uint8Array ? buf : new Uint8Array(buf)
46
- const d = decoding.createDecoder(u8)
47
- const kind = decoding.readVarUint(d)
48
- const id = decoding.readVarUint(d)
49
- if (kind === F.OPEN) return { kind, id, docName: decoding.readVarString(d) }
50
- if (kind === F.MSG) return { kind, id, payload: u8.subarray(d.pos) }
51
- if (kind === F.REFUSED) return { kind, id, code: decoding.readVarUint(d), reason: decoding.readVarString(d) }
52
- if (kind === F.CLOSED) return { kind, id, reason: decoding.readVarString(d) }
53
- if (kind === F.CLOSE || kind === F.OPENED || kind === F.BEAT) return { kind, id }
54
- throw new Error(`unknown mux frame kind ${kind}`)
55
- }
56
-
57
- /** The mux upgrade path for a base room, as the relay parses it (pathname minus the slash). */
58
- export function muxPath(room) { return MUX_PREFIX + encodeURIComponent(room) }
1
+ // hive-mux-proto.js -- the wire format for ONE socket per participant, shared by relay and client.
2
+ //
3
+ // WHY: Hivecode opened one WebSocket per FILE. A participant held 1 + min(files, 128) sockets,
4
+ // so an agent in a 1000-file repository saw only 128 files on disk, and a relay's connection cap
5
+ // divided by 129 per person. The mux carries every file doc of one room over one socket.
6
+ //
7
+ // The design rule that makes it safe: the relay does not grow a second enforcement path. Each
8
+ // OPEN runs the SAME per-doc admission a per-file upgrade runs (token scope for that path, the
9
+ // per-room ceiling, the committer limit), and the accepted channel is wrapped in a VirtualConn
10
+ // that looks exactly like a ws connection to installUsageLimits, makeReadOnly, installWriteGate
11
+ // and setupWSConnection. The bytes inside a MSG frame are the same y-protocols message a
12
+ // per-file socket would carry.
13
+ //
14
+ // Frames are binary, lib0-encoded:
15
+ // client -> relay OPEN [0, id, docName] open this file doc as channel `id`
16
+ // CLOSE [1, id] the client is done with it
17
+ // MSG [2, id, ...payload] a y-protocols message for that doc
18
+ // relay -> client MSG [2, id, ...payload]
19
+ // OPENED [3, id] admitted; the relay's sync step 1 follows
20
+ // REFUSED [4, id, code, reason] not admitted -- the HTTP status a per-file
21
+ // upgrade would have answered, and why
22
+ // CLOSED [5, id, reason] the relay closed that channel
23
+ // BEAT [6, 0] liveness, so a dead socket is noticed
24
+ // Channel ids are chosen by the client and are only meaningful on the socket that opened them.
25
+ import * as encoding from 'lib0/encoding'
26
+ import * as decoding from 'lib0/decoding'
27
+
28
+ export const MUX_PREFIX = '_hive_mux/'
29
+ export const MUX_VERSION = 1
30
+ export const F = Object.freeze({ OPEN: 0, CLOSE: 1, MSG: 2, OPENED: 3, REFUSED: 4, CLOSED: 5, BEAT: 6 })
31
+
32
+ export function encodeFrame(kind, id, a, b) {
33
+ const e = encoding.createEncoder()
34
+ encoding.writeVarUint(e, kind)
35
+ encoding.writeVarUint(e, id >>> 0)
36
+ if (kind === F.OPEN) encoding.writeVarString(e, String(a))
37
+ else if (kind === F.MSG) encoding.writeUint8Array(e, a instanceof Uint8Array ? a : new Uint8Array(a))
38
+ else if (kind === F.REFUSED) { encoding.writeVarUint(e, a >>> 0); encoding.writeVarString(e, String(b || '')) }
39
+ else if (kind === F.CLOSED) encoding.writeVarString(e, String(a || ''))
40
+ return encoding.toUint8Array(e)
41
+ }
42
+
43
+ /** Decode one frame. Throws on garbage, which the caller treats as a protocol violation. */
44
+ export function decodeFrame(buf) {
45
+ const u8 = buf instanceof Uint8Array ? buf : new Uint8Array(buf)
46
+ const d = decoding.createDecoder(u8)
47
+ const kind = decoding.readVarUint(d)
48
+ const id = decoding.readVarUint(d)
49
+ if (kind === F.OPEN) return { kind, id, docName: decoding.readVarString(d) }
50
+ if (kind === F.MSG) return { kind, id, payload: u8.subarray(d.pos) }
51
+ if (kind === F.REFUSED) return { kind, id, code: decoding.readVarUint(d), reason: decoding.readVarString(d) }
52
+ if (kind === F.CLOSED) return { kind, id, reason: decoding.readVarString(d) }
53
+ if (kind === F.CLOSE || kind === F.OPENED || kind === F.BEAT) return { kind, id }
54
+ throw new Error(`unknown mux frame kind ${kind}`)
55
+ }
56
+
57
+ /** The mux upgrade path for a base room, as the relay parses it (pathname minus the slash). */
58
+ export function muxPath(room) { return MUX_PREFIX + encodeURIComponent(room) }