@indigoai-us/hq-cloud 6.16.37 → 6.16.38
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/dist/bin/sync-runner.test.js +3 -3
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/share.test.js +4 -0
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync.js +2 -2
- package/dist/cli/sync.js.map +1 -1
- package/dist/journal-area-ledger-read-boundary.test.d.ts +2 -0
- package/dist/journal-area-ledger-read-boundary.test.d.ts.map +1 -0
- package/dist/journal-area-ledger-read-boundary.test.js +386 -0
- package/dist/journal-area-ledger-read-boundary.test.js.map +1 -0
- package/dist/journal-row-store.d.ts.map +1 -1
- package/dist/journal-row-store.js +15 -5
- package/dist/journal-row-store.js.map +1 -1
- package/dist/journal-row-store.test.js +147 -0
- package/dist/journal-row-store.test.js.map +1 -1
- package/dist/journal-snapshot-memory-helpers.d.ts +3 -0
- package/dist/journal-snapshot-memory-helpers.d.ts.map +1 -1
- package/dist/journal-snapshot-memory-helpers.js +3 -3
- package/dist/journal-snapshot-memory-helpers.js.map +1 -1
- package/dist/journal.d.ts +17 -0
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +175 -19
- package/dist/journal.js.map +1 -1
- package/dist/manifest/build-manifest-resident-parity.test.d.ts +2 -0
- package/dist/manifest/build-manifest-resident-parity.test.d.ts.map +1 -0
- package/dist/manifest/build-manifest-resident-parity.test.js +68 -0
- package/dist/manifest/build-manifest-resident-parity.test.js.map +1 -0
- package/dist/manifest/build-manifest.bench.test.js +262 -2
- package/dist/manifest/build-manifest.bench.test.js.map +1 -1
- package/dist/manifest/build-manifest.d.ts +15 -0
- package/dist/manifest/build-manifest.d.ts.map +1 -1
- package/dist/manifest/build-manifest.js +39 -8
- package/dist/manifest/build-manifest.js.map +1 -1
- package/dist/manifest/build-manifest.test.js +8 -0
- package/dist/manifest/build-manifest.test.js.map +1 -1
- package/dist/outposts/command.d.ts +1 -0
- package/dist/outposts/command.d.ts.map +1 -1
- package/dist/outposts/command.js +6 -0
- package/dist/outposts/command.js.map +1 -1
- package/dist/outposts/session-host-auth.d.ts +70 -0
- package/dist/outposts/session-host-auth.d.ts.map +1 -0
- package/dist/outposts/session-host-auth.js +166 -0
- package/dist/outposts/session-host-auth.js.map +1 -0
- package/dist/outposts/session-host-auth.test.d.ts +16 -0
- package/dist/outposts/session-host-auth.test.d.ts.map +1 -0
- package/dist/outposts/session-host-auth.test.js +284 -0
- package/dist/outposts/session-host-auth.test.js.map +1 -0
- package/dist/outposts/session-host-command.d.ts +42 -0
- package/dist/outposts/session-host-command.d.ts.map +1 -0
- package/dist/outposts/session-host-command.js +223 -0
- package/dist/outposts/session-host-command.js.map +1 -0
- package/dist/outposts/session-host-command.test.d.ts +10 -0
- package/dist/outposts/session-host-command.test.d.ts.map +1 -0
- package/dist/outposts/session-host-command.test.js +98 -0
- package/dist/outposts/session-host-command.test.js.map +1 -0
- package/dist/outposts/session-host-connection.d.ts +44 -0
- package/dist/outposts/session-host-connection.d.ts.map +1 -0
- package/dist/outposts/session-host-connection.js +227 -0
- package/dist/outposts/session-host-connection.js.map +1 -0
- package/dist/outposts/session-host-connection.test.d.ts +18 -0
- package/dist/outposts/session-host-connection.test.d.ts.map +1 -0
- package/dist/outposts/session-host-connection.test.js +392 -0
- package/dist/outposts/session-host-connection.test.js.map +1 -0
- package/dist/outposts/session-host-fakes.d.ts +61 -0
- package/dist/outposts/session-host-fakes.d.ts.map +1 -0
- package/dist/outposts/session-host-fakes.js +115 -0
- package/dist/outposts/session-host-fakes.js.map +1 -0
- package/dist/outposts/session-host-ndjson.d.ts +30 -0
- package/dist/outposts/session-host-ndjson.d.ts.map +1 -0
- package/dist/outposts/session-host-ndjson.js +64 -0
- package/dist/outposts/session-host-ndjson.js.map +1 -0
- package/dist/outposts/session-host-ndjson.test.d.ts +11 -0
- package/dist/outposts/session-host-ndjson.test.d.ts.map +1 -0
- package/dist/outposts/session-host-ndjson.test.js +73 -0
- package/dist/outposts/session-host-ndjson.test.js.map +1 -0
- package/dist/outposts/session-host-protocol.d.ts +137 -0
- package/dist/outposts/session-host-protocol.d.ts.map +1 -0
- package/dist/outposts/session-host-protocol.js +244 -0
- package/dist/outposts/session-host-protocol.js.map +1 -0
- package/dist/outposts/session-host-protocol.test.d.ts +15 -0
- package/dist/outposts/session-host-protocol.test.d.ts.map +1 -0
- package/dist/outposts/session-host-protocol.test.js +0 -0
- package/dist/outposts/session-host-protocol.test.js.map +1 -0
- package/dist/outposts/session-host-server.d.ts +25 -0
- package/dist/outposts/session-host-server.d.ts.map +1 -0
- package/dist/outposts/session-host-server.js +66 -0
- package/dist/outposts/session-host-server.js.map +1 -0
- package/dist/outposts/session-host-server.test.d.ts +10 -0
- package/dist/outposts/session-host-server.test.d.ts.map +1 -0
- package/dist/outposts/session-host-server.test.js +118 -0
- package/dist/outposts/session-host-server.test.js.map +1 -0
- package/dist/outposts/session-host-sessions.d.ts +144 -0
- package/dist/outposts/session-host-sessions.d.ts.map +1 -0
- package/dist/outposts/session-host-sessions.js +336 -0
- package/dist/outposts/session-host-sessions.js.map +1 -0
- package/dist/outposts/session-host-sessions.test.d.ts +18 -0
- package/dist/outposts/session-host-sessions.test.d.ts.map +1 -0
- package/dist/outposts/session-host-sessions.test.js +439 -0
- package/dist/outposts/session-host-sessions.test.js.map +1 -0
- package/dist/sync/area-ledger-migration.d.ts.map +1 -1
- package/dist/sync/area-ledger-migration.js +13 -5
- package/dist/sync/area-ledger-migration.js.map +1 -1
- package/dist/sync/area-ledger.test.js +4 -0
- package/dist/sync/area-ledger.test.js.map +1 -1
- package/dist/watcher.test.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Newline-delimited JSON framing for the box session host.
|
|
3
|
+
*
|
|
4
|
+
* The host reads a raw TCP stream, so it cuts the lines itself. Two properties
|
|
5
|
+
* are load-bearing:
|
|
6
|
+
* - lines are cut on BYTES and decoded one whole line at a time, so a
|
|
7
|
+
* character split across two TCP chunks arrives intact;
|
|
8
|
+
* - the length cap trips as soon as the pending bytes pass it, not when a
|
|
9
|
+
* newline finally arrives. Otherwise a peer that never sends "\n" could make
|
|
10
|
+
* the host buffer without limit — and before the hello check, that peer is
|
|
11
|
+
* anyone who can reach the port.
|
|
12
|
+
*/
|
|
13
|
+
export interface LineSplitterOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Longest allowed line in bytes, not counting the newline. A function is
|
|
16
|
+
* re-read per chunk, which is how the connection holds a peer to a small cap
|
|
17
|
+
* until it has signed in and a generous one afterwards.
|
|
18
|
+
*/
|
|
19
|
+
maxLineBytes: number | (() => number);
|
|
20
|
+
onLine: (line: string) => void;
|
|
21
|
+
/** Called once, when a line passes the cap. Nothing is emitted afterwards. */
|
|
22
|
+
onOverflow: () => void;
|
|
23
|
+
}
|
|
24
|
+
export interface LineSplitter {
|
|
25
|
+
push(chunk: Buffer): void;
|
|
26
|
+
/** Flush a final line that arrived without a trailing newline. */
|
|
27
|
+
end(): void;
|
|
28
|
+
}
|
|
29
|
+
export declare function createLineSplitter(options: LineSplitterOptions): LineSplitter;
|
|
30
|
+
//# sourceMappingURL=session-host-ndjson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-host-ndjson.d.ts","sourceRoot":"","sources":["../../src/outposts/session-host-ndjson.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,YAAY,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACtC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,8EAA8E;IAC9E,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,kEAAkE;IAClE,GAAG,IAAI,IAAI,CAAC;CACb;AAKD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAgD7E"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Newline-delimited JSON framing for the box session host.
|
|
3
|
+
*
|
|
4
|
+
* The host reads a raw TCP stream, so it cuts the lines itself. Two properties
|
|
5
|
+
* are load-bearing:
|
|
6
|
+
* - lines are cut on BYTES and decoded one whole line at a time, so a
|
|
7
|
+
* character split across two TCP chunks arrives intact;
|
|
8
|
+
* - the length cap trips as soon as the pending bytes pass it, not when a
|
|
9
|
+
* newline finally arrives. Otherwise a peer that never sends "\n" could make
|
|
10
|
+
* the host buffer without limit — and before the hello check, that peer is
|
|
11
|
+
* anyone who can reach the port.
|
|
12
|
+
*/
|
|
13
|
+
const NEWLINE = 0x0a;
|
|
14
|
+
const CARRIAGE_RETURN = 0x0d;
|
|
15
|
+
export function createLineSplitter(options) {
|
|
16
|
+
const { onLine, onOverflow } = options;
|
|
17
|
+
const capOf = typeof options.maxLineBytes === "function" ? options.maxLineBytes : () => options.maxLineBytes;
|
|
18
|
+
let pending = Buffer.alloc(0);
|
|
19
|
+
let dead = false;
|
|
20
|
+
function overflow() {
|
|
21
|
+
dead = true;
|
|
22
|
+
pending = Buffer.alloc(0);
|
|
23
|
+
onOverflow();
|
|
24
|
+
}
|
|
25
|
+
function emit(line) {
|
|
26
|
+
const end = line.length > 0 && line[line.length - 1] === CARRIAGE_RETURN ? line.length - 1 : line.length;
|
|
27
|
+
if (end > capOf()) {
|
|
28
|
+
overflow();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// Blank lines are how a peer keeps a connection warm; they carry nothing.
|
|
32
|
+
if (end === 0)
|
|
33
|
+
return;
|
|
34
|
+
onLine(line.subarray(0, end).toString("utf8"));
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
push(chunk) {
|
|
38
|
+
if (dead)
|
|
39
|
+
return;
|
|
40
|
+
pending = pending.length === 0 ? chunk : Buffer.concat([pending, chunk]);
|
|
41
|
+
for (let at = pending.indexOf(NEWLINE); at >= 0; at = pending.indexOf(NEWLINE)) {
|
|
42
|
+
const line = pending.subarray(0, at);
|
|
43
|
+
pending = pending.subarray(at + 1);
|
|
44
|
+
emit(line);
|
|
45
|
+
if (dead)
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// Nothing left to cut on: a peer must not be able to grow this forever.
|
|
49
|
+
// One byte of slack covers a line that ends exactly at the cap and whose
|
|
50
|
+
// "\r\n" has not fully arrived yet.
|
|
51
|
+
if (pending.length > capOf() + 1)
|
|
52
|
+
overflow();
|
|
53
|
+
},
|
|
54
|
+
end() {
|
|
55
|
+
if (dead)
|
|
56
|
+
return;
|
|
57
|
+
const line = pending;
|
|
58
|
+
pending = Buffer.alloc(0);
|
|
59
|
+
if (line.length > 0)
|
|
60
|
+
emit(line);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=session-host-ndjson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-host-ndjson.js","sourceRoot":"","sources":["../../src/outposts/session-host-ndjson.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoBH,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B,MAAM,UAAU,kBAAkB,CAAC,OAA4B;IAC7D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,KAAK,GACT,OAAO,OAAO,CAAC,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,YAAsB,CAAC;IAC3G,IAAI,OAAO,GAAW,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtC,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AI,CAAC,IAAI,CAAC,CAAC;gBACX,IAAI,IAAI;oBAAE,OAAO;YACnB,CAAC;YACD,wEAAwE;YACxE,yEAAyE;YACzE,oCAAoC;YACpC,IAAI,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE,GAAG,CAAC;gBAAE,QAAQ,EAAE,CAAC;QAC/C,CAAC;QAED,GAAG;YACD,IAAI,IAAI;gBAAE,OAAO;YACjB,MAAM,IAAI,GAAG,OAAO,CAAC;YACrB,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC1B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;gBAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the session host's line framing.
|
|
3
|
+
*
|
|
4
|
+
* The host speaks newline-delimited JSON over a raw TCP stream, so it cuts the
|
|
5
|
+
* byte stream into lines itself. Two properties matter beyond "split on \n":
|
|
6
|
+
* a character split across two TCP chunks must arrive intact, and a peer must
|
|
7
|
+
* never be able to make the host buffer an unbounded line — the cap trips as
|
|
8
|
+
* soon as the pending bytes pass it, not when a newline finally arrives.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=session-host-ndjson.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-host-ndjson.test.d.ts","sourceRoot":"","sources":["../../src/outposts/session-host-ndjson.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the session host's line framing.
|
|
3
|
+
*
|
|
4
|
+
* The host speaks newline-delimited JSON over a raw TCP stream, so it cuts the
|
|
5
|
+
* byte stream into lines itself. Two properties matter beyond "split on \n":
|
|
6
|
+
* a character split across two TCP chunks must arrive intact, and a peer must
|
|
7
|
+
* never be able to make the host buffer an unbounded line — the cap trips as
|
|
8
|
+
* soon as the pending bytes pass it, not when a newline finally arrives.
|
|
9
|
+
*/
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
import { createLineSplitter } from "./session-host-ndjson";
|
|
12
|
+
function collect(maxLineBytes = 1024) {
|
|
13
|
+
const lines = [];
|
|
14
|
+
let overflows = 0;
|
|
15
|
+
const splitter = createLineSplitter({
|
|
16
|
+
maxLineBytes,
|
|
17
|
+
onLine: (line) => lines.push(line),
|
|
18
|
+
onOverflow: () => {
|
|
19
|
+
overflows += 1;
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
return { splitter, lines, overflows: () => overflows };
|
|
23
|
+
}
|
|
24
|
+
describe("createLineSplitter", () => {
|
|
25
|
+
it("emits one line per newline, across chunk boundaries", () => {
|
|
26
|
+
const { splitter, lines } = collect();
|
|
27
|
+
splitter.push(Buffer.from('{"a":1}\n{"b"'));
|
|
28
|
+
splitter.push(Buffer.from(':2}\n{"c":3}\n'));
|
|
29
|
+
expect(lines).toEqual(['{"a":1}', '{"b":2}', '{"c":3}']);
|
|
30
|
+
});
|
|
31
|
+
it("keeps a multi-byte character intact when a chunk splits it", () => {
|
|
32
|
+
const { splitter, lines } = collect();
|
|
33
|
+
const bytes = Buffer.from('{"t":"café 🚀"}\n', "utf8");
|
|
34
|
+
const insideE = bytes.indexOf(0xc3) + 1; // between the two bytes of "é"
|
|
35
|
+
const insideRocket = bytes.indexOf(0xf0) + 2; // inside the four bytes of "🚀"
|
|
36
|
+
splitter.push(bytes.subarray(0, insideE));
|
|
37
|
+
splitter.push(bytes.subarray(insideE, insideRocket));
|
|
38
|
+
splitter.push(bytes.subarray(insideRocket));
|
|
39
|
+
expect(lines).toEqual(['{"t":"café 🚀"}']);
|
|
40
|
+
});
|
|
41
|
+
it("drops a trailing carriage return and skips blank lines", () => {
|
|
42
|
+
const { splitter, lines } = collect();
|
|
43
|
+
splitter.push(Buffer.from('{"a":1}\r\n\n\r\n{"b":2}\n'));
|
|
44
|
+
expect(lines).toEqual(['{"a":1}', '{"b":2}']);
|
|
45
|
+
});
|
|
46
|
+
it("accepts a line of exactly the cap, counted in bytes rather than characters", () => {
|
|
47
|
+
const { splitter, lines, overflows } = collect(8);
|
|
48
|
+
splitter.push(Buffer.from("éééé\n", "utf8")); // 4 characters, 8 bytes
|
|
49
|
+
expect(lines).toEqual(["éééé"]);
|
|
50
|
+
expect(overflows()).toBe(0);
|
|
51
|
+
});
|
|
52
|
+
it("reports a line over the cap once, and emits nothing after it", () => {
|
|
53
|
+
const { splitter, lines, overflows } = collect(8);
|
|
54
|
+
splitter.push(Buffer.from("ééééé\n", "utf8")); // 10 bytes
|
|
55
|
+
splitter.push(Buffer.from('{"a":1}\n'));
|
|
56
|
+
splitter.push(Buffer.from("x".repeat(100)));
|
|
57
|
+
expect(lines).toEqual([]);
|
|
58
|
+
expect(overflows()).toBe(1);
|
|
59
|
+
});
|
|
60
|
+
it("trips the cap before any newline arrives, so a peer cannot make it buffer forever", () => {
|
|
61
|
+
const { splitter, lines, overflows } = collect(16);
|
|
62
|
+
splitter.push(Buffer.alloc(64, 0x61)); // 64 × "a", no newline yet
|
|
63
|
+
expect(overflows()).toBe(1);
|
|
64
|
+
expect(lines).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
it("flushes a final line that has no newline when the stream ends", () => {
|
|
67
|
+
const { splitter, lines } = collect();
|
|
68
|
+
splitter.push(Buffer.from('{"a":1}\n{"b":2}'));
|
|
69
|
+
splitter.end();
|
|
70
|
+
expect(lines).toEqual(['{"a":1}', '{"b":2}']);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=session-host-ndjson.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-host-ndjson.test.js","sourceRoot":"","sources":["../../src/outposts/session-host-ndjson.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,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CAAC,GAAG,EAAE,CAAC;QAEf,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The message format the HQ desktop app and the box session host speak.
|
|
3
|
+
*
|
|
4
|
+
* One JSON object per line, in both directions. The app sends hello, list,
|
|
5
|
+
* start, attach, detach, input, end and ping; the host answers with welcome,
|
|
6
|
+
* sessions, started, attached, frame, truncated, log, exited, pong and error.
|
|
7
|
+
*
|
|
8
|
+
* Everything the app sends is validated here before the host acts on it. The
|
|
9
|
+
* rule that matters most: the host builds `claude`'s argument list itself, from
|
|
10
|
+
* checked fields, so no value the app sends can turn into an extra flag. A
|
|
11
|
+
* value that starts with "-" is refused outright.
|
|
12
|
+
*/
|
|
13
|
+
import type { SessionSummary, SessionOutbound } from "./session-host-sessions.js";
|
|
14
|
+
export declare const SESSION_HOST_PROTOCOL_VERSION = 1;
|
|
15
|
+
/**
|
|
16
|
+
* The loopback port the host listens on, and the desktop app forwards to. Fixed
|
|
17
|
+
* so the Mac side needs no discovery step: it opens the Outpost port-forward to
|
|
18
|
+
* this port and dials the local end.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_SESSION_HOST_PORT = 47821;
|
|
21
|
+
/** A Cognito ID token is ~1–2 KB; this leaves generous room without inviting a flood. */
|
|
22
|
+
export declare const MAX_TOKEN_BYTES: number;
|
|
23
|
+
export type PermissionMode = "default" | "acceptEdits" | "plan" | "bypassPermissions";
|
|
24
|
+
export interface HelloMessage {
|
|
25
|
+
t: "hello";
|
|
26
|
+
v: number;
|
|
27
|
+
token: string;
|
|
28
|
+
client?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ListMessage {
|
|
31
|
+
t: "list";
|
|
32
|
+
id: string;
|
|
33
|
+
}
|
|
34
|
+
export interface StartMessage {
|
|
35
|
+
t: "start";
|
|
36
|
+
id: string;
|
|
37
|
+
permissionMode: PermissionMode;
|
|
38
|
+
cwd?: string;
|
|
39
|
+
sessionId?: string;
|
|
40
|
+
resume?: string;
|
|
41
|
+
model?: string;
|
|
42
|
+
effort?: string;
|
|
43
|
+
thinkingDisplay?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface AttachMessage {
|
|
46
|
+
t: "attach";
|
|
47
|
+
id: string;
|
|
48
|
+
session: string;
|
|
49
|
+
sinceSeq: number;
|
|
50
|
+
}
|
|
51
|
+
export interface DetachMessage {
|
|
52
|
+
t: "detach";
|
|
53
|
+
session: string;
|
|
54
|
+
}
|
|
55
|
+
export interface InputMessage {
|
|
56
|
+
t: "input";
|
|
57
|
+
session: string;
|
|
58
|
+
frame: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
export interface EndMessage {
|
|
61
|
+
t: "end";
|
|
62
|
+
session: string;
|
|
63
|
+
}
|
|
64
|
+
export interface PingMessage {
|
|
65
|
+
t: "ping";
|
|
66
|
+
id?: string;
|
|
67
|
+
}
|
|
68
|
+
export type ClientMessage = HelloMessage | ListMessage | StartMessage | AttachMessage | DetachMessage | InputMessage | EndMessage | PingMessage;
|
|
69
|
+
export type ParseFailureCode = "bad-json" | "bad-message" | "bad-request";
|
|
70
|
+
export type ParseResult = {
|
|
71
|
+
ok: true;
|
|
72
|
+
message: ClientMessage;
|
|
73
|
+
} | {
|
|
74
|
+
ok: false;
|
|
75
|
+
code: ParseFailureCode;
|
|
76
|
+
message: string;
|
|
77
|
+
id?: string;
|
|
78
|
+
};
|
|
79
|
+
export type ServerErrorCode = ParseFailureCode | "bad-hello" | "unsupported-version" | "unauthorized" | "line-too-long" | "unknown-session" | "session-exited" | "session-busy" | "too-many-sessions" | "bad-cwd" | "spawn-failed" | "shutting-down" | "internal";
|
|
80
|
+
export type ServerMessage = {
|
|
81
|
+
t: "welcome";
|
|
82
|
+
v: number;
|
|
83
|
+
host: string;
|
|
84
|
+
version: string;
|
|
85
|
+
} | {
|
|
86
|
+
t: "sessions";
|
|
87
|
+
id: string;
|
|
88
|
+
sessions: SessionSummary[];
|
|
89
|
+
} | {
|
|
90
|
+
t: "started";
|
|
91
|
+
id: string;
|
|
92
|
+
session: string;
|
|
93
|
+
claudeSessionId: string;
|
|
94
|
+
} | {
|
|
95
|
+
t: "attached";
|
|
96
|
+
id: string;
|
|
97
|
+
session: string;
|
|
98
|
+
lastSeq: number;
|
|
99
|
+
} | {
|
|
100
|
+
t: "pong";
|
|
101
|
+
id?: string;
|
|
102
|
+
} | {
|
|
103
|
+
t: "error";
|
|
104
|
+
code: ServerErrorCode;
|
|
105
|
+
message: string;
|
|
106
|
+
id?: string;
|
|
107
|
+
session?: string;
|
|
108
|
+
} | SessionOutbound;
|
|
109
|
+
/**
|
|
110
|
+
* Validate one line from the desktop app.
|
|
111
|
+
*
|
|
112
|
+
* `bad-json` means the line was not a JSON object at all — which is also how a
|
|
113
|
+
* browser's `GET / HTTP/1.1` lands here. `bad-message` is an unknown command,
|
|
114
|
+
* and `bad-request` is a known command with a field the host will not accept.
|
|
115
|
+
*/
|
|
116
|
+
export declare function parseClientMessage(line: string): ParseResult;
|
|
117
|
+
export interface ClaudeArgsSpec {
|
|
118
|
+
permissionMode: PermissionMode;
|
|
119
|
+
sessionId?: string;
|
|
120
|
+
resume?: string;
|
|
121
|
+
model?: string;
|
|
122
|
+
effort?: string;
|
|
123
|
+
thinkingDisplay?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Build `claude`'s arguments for one session.
|
|
127
|
+
*
|
|
128
|
+
* These are the desktop app's own flags for a local session (see the Mac side's
|
|
129
|
+
* `build_args`), so a box session behaves exactly like one started on the Mac:
|
|
130
|
+
* stream-json in and out, partial messages on, and tool approvals routed over
|
|
131
|
+
* stdio instead of a terminal prompt. A fresh run pins the id we minted; a
|
|
132
|
+
* resume adopts the CLI's own id — the CLI rejects both together.
|
|
133
|
+
*/
|
|
134
|
+
export declare function buildClaudeArgs(spec: ClaudeArgsSpec): string[];
|
|
135
|
+
/** One server message as a single line, newline included. */
|
|
136
|
+
export declare function encodeServerMessage(message: ServerMessage): string;
|
|
137
|
+
//# sourceMappingURL=session-host-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-host-protocol.d.ts","sourceRoot":"","sources":["../../src/outposts/session-host-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElF,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAAQ,CAAC;AAE/C,yFAAyF;AACzF,eAAO,MAAM,eAAe,QAAY,CAAC;AAoBzC,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,aAAa,GAAG,MAAM,GAAG,mBAAmB,CAAC;AAStF,MAAM,WAAW,YAAY;IAC3B,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,EAAE,OAAO,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,cAAc,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,EAAE,QAAQ,CAAC;I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244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The message format the HQ desktop app and the box session host speak.
|
|
3
|
+
*
|
|
4
|
+
* One JSON object per line, in both directions. The app sends hello, list,
|
|
5
|
+
* start, attach, detach, input, end and ping; the host answers with welcome,
|
|
6
|
+
* sessions, started, attached, frame, truncated, log, exited, pong and error.
|
|
7
|
+
*
|
|
8
|
+
* Everything the app sends is validated here before the host acts on it. The
|
|
9
|
+
* rule that matters most: the host builds `claude`'s argument list itself, from
|
|
10
|
+
* checked fields, so no value the app sends can turn into an extra flag. A
|
|
11
|
+
* value that starts with "-" is refused outright.
|
|
12
|
+
*/
|
|
13
|
+
export const SESSION_HOST_PROTOCOL_VERSION = 1;
|
|
14
|
+
/**
|
|
15
|
+
* The loopback port the host listens on, and the desktop app forwards to. Fixed
|
|
16
|
+
* so the Mac side needs no discovery step: it opens the Outpost port-forward to
|
|
17
|
+
* this port and dials the local end.
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_SESSION_HOST_PORT = 47821;
|
|
20
|
+
/** A Cognito ID token is ~1–2 KB; this leaves generous room without inviting a flood. */
|
|
21
|
+
export const MAX_TOKEN_BYTES = 16 * 1024;
|
|
22
|
+
const MAX_REQUEST_ID_CHARS = 64;
|
|
23
|
+
const MAX_SESSION_ID_CHARS = 128;
|
|
24
|
+
const MAX_CLIENT_CHARS = 200;
|
|
25
|
+
const MAX_MODEL_CHARS = 256;
|
|
26
|
+
const MAX_CWD_CHARS = 4096;
|
|
27
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
28
|
+
const PLAIN_WORD = /^[a-z]{1,20}$/;
|
|
29
|
+
/** No whitespace, no control characters, and never a leading "-". */
|
|
30
|
+
function hasControlOrSpace(value) {
|
|
31
|
+
if (/\s/.test(value))
|
|
32
|
+
return true;
|
|
33
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
34
|
+
const code = value.charCodeAt(i);
|
|
35
|
+
if (code < 0x20 || code === 0x7f)
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const PERMISSION_MODES = [
|
|
41
|
+
"default",
|
|
42
|
+
"acceptEdits",
|
|
43
|
+
"plan",
|
|
44
|
+
"bypassPermissions",
|
|
45
|
+
];
|
|
46
|
+
function isPlainObject(value) {
|
|
47
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
48
|
+
}
|
|
49
|
+
/** A value safe to hand to `claude` as one argument: no flags, no whitespace. */
|
|
50
|
+
function isArgumentSafe(value, maxChars) {
|
|
51
|
+
return (typeof value === "string" &&
|
|
52
|
+
value.length > 0 &&
|
|
53
|
+
value.length <= maxChars &&
|
|
54
|
+
!value.startsWith("-") &&
|
|
55
|
+
!hasControlOrSpace(value));
|
|
56
|
+
}
|
|
57
|
+
function isLabel(value, maxChars) {
|
|
58
|
+
return (typeof value === "string" &&
|
|
59
|
+
value.length > 0 &&
|
|
60
|
+
value.length <= maxChars &&
|
|
61
|
+
!hasControlOrSpace(value));
|
|
62
|
+
}
|
|
63
|
+
function bad(code, message, id) {
|
|
64
|
+
return id === undefined ? { ok: false, code, message } : { ok: false, code, message, id };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validate one line from the desktop app.
|
|
68
|
+
*
|
|
69
|
+
* `bad-json` means the line was not a JSON object at all — which is also how a
|
|
70
|
+
* browser's `GET / HTTP/1.1` lands here. `bad-message` is an unknown command,
|
|
71
|
+
* and `bad-request` is a known command with a field the host will not accept.
|
|
72
|
+
*/
|
|
73
|
+
export function parseClientMessage(line) {
|
|
74
|
+
let value;
|
|
75
|
+
try {
|
|
76
|
+
value = JSON.parse(line);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return bad("bad-json", "expected one JSON object per line");
|
|
80
|
+
}
|
|
81
|
+
if (!isPlainObject(value))
|
|
82
|
+
return bad("bad-json", "expected a JSON object");
|
|
83
|
+
const type = value.t;
|
|
84
|
+
if (typeof type !== "string")
|
|
85
|
+
return bad("bad-message", "missing message type");
|
|
86
|
+
const id = isLabel(value.id, MAX_REQUEST_ID_CHARS) ? value.id : undefined;
|
|
87
|
+
switch (type) {
|
|
88
|
+
case "hello": {
|
|
89
|
+
if (!Number.isInteger(value.v))
|
|
90
|
+
return bad("bad-request", "hello needs a whole version number");
|
|
91
|
+
if (typeof value.token !== "string" || value.token.length === 0) {
|
|
92
|
+
return bad("bad-request", "hello needs a sign-in token");
|
|
93
|
+
}
|
|
94
|
+
if (Buffer.byteLength(value.token, "utf8") > MAX_TOKEN_BYTES) {
|
|
95
|
+
return bad("bad-request", "that sign-in token is too large");
|
|
96
|
+
}
|
|
97
|
+
if (value.client !== undefined && !isLabel(value.client, MAX_CLIENT_CHARS)) {
|
|
98
|
+
return bad("bad-request", "client must be a short name");
|
|
99
|
+
}
|
|
100
|
+
const hello = { t: "hello", v: value.v, token: value.token };
|
|
101
|
+
if (typeof value.client === "string")
|
|
102
|
+
hello.client = value.client;
|
|
103
|
+
return { ok: true, message: hello };
|
|
104
|
+
}
|
|
105
|
+
case "list": {
|
|
106
|
+
if (id === undefined)
|
|
107
|
+
return bad("bad-request", "list needs a request id");
|
|
108
|
+
return { ok: true, message: { t: "list", id } };
|
|
109
|
+
}
|
|
110
|
+
case "start": {
|
|
111
|
+
if (id === undefined)
|
|
112
|
+
return bad("bad-request", "start needs a request id");
|
|
113
|
+
const start = { t: "start", id, permissionMode: "default" };
|
|
114
|
+
if (value.permissionMode !== undefined) {
|
|
115
|
+
if (typeof value.permissionMode !== "string" || !PERMISSION_MODES.includes(value.permissionMode)) {
|
|
116
|
+
return bad("bad-request", `permissionMode must be one of ${PERMISSION_MODES.join(", ")}`, id);
|
|
117
|
+
}
|
|
118
|
+
start.permissionMode = value.permissionMode;
|
|
119
|
+
}
|
|
120
|
+
if (value.cwd !== undefined) {
|
|
121
|
+
if (!isArgumentSafe(value.cwd, MAX_CWD_CHARS) || !value.cwd.startsWith("/")) {
|
|
122
|
+
return bad("bad-request", "cwd must be an absolute path with no spaces", id);
|
|
123
|
+
}
|
|
124
|
+
start.cwd = value.cwd;
|
|
125
|
+
}
|
|
126
|
+
if (value.sessionId !== undefined && value.resume !== undefined) {
|
|
127
|
+
return bad("bad-request", "pass sessionId or resume, not both", id);
|
|
128
|
+
}
|
|
129
|
+
if (value.sessionId !== undefined) {
|
|
130
|
+
if (typeof value.sessionId !== "string" || !UUID.test(value.sessionId)) {
|
|
131
|
+
return bad("bad-request", "sessionId must be a UUID", id);
|
|
132
|
+
}
|
|
133
|
+
start.sessionId = value.sessionId;
|
|
134
|
+
}
|
|
135
|
+
if (value.resume !== undefined) {
|
|
136
|
+
if (typeof value.resume !== "string" || !UUID.test(value.resume)) {
|
|
137
|
+
return bad("bad-request", "resume must be a UUID", id);
|
|
138
|
+
}
|
|
139
|
+
start.resume = value.resume;
|
|
140
|
+
}
|
|
141
|
+
if (value.model !== undefined) {
|
|
142
|
+
if (!isArgumentSafe(value.model, MAX_MODEL_CHARS)) {
|
|
143
|
+
return bad("bad-request", "model must be a plain model name", id);
|
|
144
|
+
}
|
|
145
|
+
start.model = value.model;
|
|
146
|
+
}
|
|
147
|
+
if (value.effort !== undefined) {
|
|
148
|
+
if (typeof value.effort !== "string" || !PLAIN_WORD.test(value.effort)) {
|
|
149
|
+
return bad("bad-request", "effort must be a lowercase word", id);
|
|
150
|
+
}
|
|
151
|
+
start.effort = value.effort;
|
|
152
|
+
}
|
|
153
|
+
if (value.thinkingDisplay !== undefined) {
|
|
154
|
+
if (typeof value.thinkingDisplay !== "string" || !PLAIN_WORD.test(value.thinkingDisplay)) {
|
|
155
|
+
return bad("bad-request", "thinkingDisplay must be a lowercase word", id);
|
|
156
|
+
}
|
|
157
|
+
start.thinkingDisplay = value.thinkingDisplay;
|
|
158
|
+
}
|
|
159
|
+
return { ok: true, message: start };
|
|
160
|
+
}
|
|
161
|
+
case "attach": {
|
|
162
|
+
if (id === undefined)
|
|
163
|
+
return bad("bad-request", "attach needs a request id");
|
|
164
|
+
if (!isLabel(value.session, MAX_SESSION_ID_CHARS)) {
|
|
165
|
+
return bad("bad-request", "attach needs a session", id);
|
|
166
|
+
}
|
|
167
|
+
let sinceSeq = 0;
|
|
168
|
+
if (value.sinceSeq !== undefined) {
|
|
169
|
+
if (!Number.isInteger(value.sinceSeq) || value.sinceSeq < 0) {
|
|
170
|
+
return bad("bad-request", "sinceSeq must be a whole number, zero or more", id);
|
|
171
|
+
}
|
|
172
|
+
sinceSeq = value.sinceSeq;
|
|
173
|
+
}
|
|
174
|
+
return { ok: true, message: { t: "attach", id, session: value.session, sinceSeq } };
|
|
175
|
+
}
|
|
176
|
+
case "detach":
|
|
177
|
+
case "end": {
|
|
178
|
+
if (!isLabel(value.session, MAX_SESSION_ID_CHARS)) {
|
|
179
|
+
return bad("bad-request", `${type} needs a session`, id);
|
|
180
|
+
}
|
|
181
|
+
return { ok: true, message: { t: type, session: value.session } };
|
|
182
|
+
}
|
|
183
|
+
case "input": {
|
|
184
|
+
if (!isLabel(value.session, MAX_SESSION_ID_CHARS)) {
|
|
185
|
+
return bad("bad-request", "input needs a session", id);
|
|
186
|
+
}
|
|
187
|
+
if (!isPlainObject(value.frame) || typeof value.frame.type !== "string") {
|
|
188
|
+
return bad("bad-request", "input needs a frame object with a type", id);
|
|
189
|
+
}
|
|
190
|
+
return { ok: true, message: { t: "input", session: value.session, frame: value.frame } };
|
|
191
|
+
}
|
|
192
|
+
case "ping": {
|
|
193
|
+
return { ok: true, message: id === undefined ? { t: "ping" } : { t: "ping", id } };
|
|
194
|
+
}
|
|
195
|
+
default:
|
|
196
|
+
return bad("bad-message", `unknown message type ${JSON.stringify(type)}`, id);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Build `claude`'s arguments for one session.
|
|
201
|
+
*
|
|
202
|
+
* These are the desktop app's own flags for a local session (see the Mac side's
|
|
203
|
+
* `build_args`), so a box session behaves exactly like one started on the Mac:
|
|
204
|
+
* stream-json in and out, partial messages on, and tool approvals routed over
|
|
205
|
+
* stdio instead of a terminal prompt. A fresh run pins the id we minted; a
|
|
206
|
+
* resume adopts the CLI's own id — the CLI rejects both together.
|
|
207
|
+
*/
|
|
208
|
+
export function buildClaudeArgs(spec) {
|
|
209
|
+
if ((spec.sessionId === undefined) === (spec.resume === undefined)) {
|
|
210
|
+
throw new Error("session host: pass exactly one of sessionId or resume");
|
|
211
|
+
}
|
|
212
|
+
const args = [
|
|
213
|
+
"--print",
|
|
214
|
+
"--input-format",
|
|
215
|
+
"stream-json",
|
|
216
|
+
"--output-format",
|
|
217
|
+
"stream-json",
|
|
218
|
+
// `--verbose` is REQUIRED alongside `--print --output-format stream-json`;
|
|
219
|
+
// without it the CLI exits with a usage error.
|
|
220
|
+
"--verbose",
|
|
221
|
+
"--include-partial-messages",
|
|
222
|
+
];
|
|
223
|
+
if (spec.thinkingDisplay !== undefined)
|
|
224
|
+
args.push("--thinking-display", spec.thinkingDisplay);
|
|
225
|
+
// `--permission-prompt-tool stdio` routes tool approvals onto the stdio
|
|
226
|
+
// channel, which is what lets the Mac answer them.
|
|
227
|
+
args.push("--permission-prompt-tool", "stdio", "--permission-mode", spec.permissionMode);
|
|
228
|
+
if (spec.permissionMode === "bypassPermissions")
|
|
229
|
+
args.push("--dangerously-skip-permissions");
|
|
230
|
+
if (spec.resume !== undefined)
|
|
231
|
+
args.push("--resume", spec.resume);
|
|
232
|
+
else
|
|
233
|
+
args.push("--session-id", spec.sessionId);
|
|
234
|
+
if (spec.model !== undefined)
|
|
235
|
+
args.push("--model", spec.model);
|
|
236
|
+
if (spec.effort !== undefined)
|
|
237
|
+
args.push("--effort", spec.effort);
|
|
238
|
+
return args;
|
|
239
|
+
}
|
|
240
|
+
/** One server message as a single line, newline included. */
|
|
241
|
+
export function encodeServerMessage(message) {
|
|
242
|
+
return `${JSON.stringify(message)}\n`;
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=session-host-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-host-protocol.js","sourceRoot":"","sources":["../../src/outposts/session-host-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAE/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAE/C,yFAAyF;AACzF,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,CAAC;AAEzC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B,MAAM,IAAI,GAAG,iEAAiE,CAAC;AAC/E,MAAM,UAAU,GAAG,eAAe,CAAC;AACnC,qEAAqE;AACrE,SAAS,iBAAiB,CAAC,KAAa;IACtC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;IAChD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAID,MAAM,gBAAgB,GAAsB;IAC1C,SAAS;IACT,aAAa;IACb,MAAM;IACN,mBAAmB;CACpB,CAAC;AA8FF,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CA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,KAAK,KAAK,SAAS;QAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/D,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;QAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAElE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,mBAAmB,CAAC,OAAsB;IACxD,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the session host's message format.
|
|
3
|
+
*
|
|
4
|
+
* The desktop app sends small JSON commands — hello, list, start, attach,
|
|
5
|
+
* detach, input, end, ping — and the host validates every one before acting.
|
|
6
|
+
* The rules that matter most:
|
|
7
|
+
* - nothing the desktop sends can turn into an extra command-line flag for
|
|
8
|
+
* `claude`: the host builds the argument list itself, and any value that
|
|
9
|
+
* starts with "-" is refused;
|
|
10
|
+
* - a session is either new (optionally with a chosen id) or a resume, never
|
|
11
|
+
* both — the CLI rejects that combination too;
|
|
12
|
+
* - anything malformed gets an error reply, never a crash.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=session-host-protocol.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-host-protocol.test.d.ts","sourceRoot":"","sources":["../../src/outposts/session-host-protocol.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
|
|
Binary file
|