Harden terminal streaming and worktree setup flow

This commit is contained in:
Mohamed Boudra
2026-02-15 19:05:27 +07:00
parent 75dc802a3a
commit 0103b4da96
21 changed files with 1297 additions and 98 deletions
@@ -3,6 +3,7 @@ import {
BinaryMuxChannel,
TerminalBinaryFlags,
TerminalBinaryMessageType,
asUint8Array,
decodeBinaryMuxFrame,
encodeBinaryMuxFrame,
} from "./binary-mux.js";
@@ -40,4 +41,10 @@ describe("binary mux frame codec", () => {
const tampered = encoded.slice(0, encoded.byteLength - 1);
expect(decodeBinaryMuxFrame(tampered)).toBeNull();
});
it("converts UTF-8 string payloads to bytes", () => {
const bytes = asUint8Array("hello");
expect(bytes).not.toBeNull();
expect(Array.from(bytes ?? [])).toEqual(Array.from(new TextEncoder().encode("hello")));
});
});
+13
View File
@@ -37,6 +37,19 @@ export interface BinaryMuxFrame {
}
export function asUint8Array(data: unknown): Uint8Array | null {
if (typeof data === "string") {
if (typeof TextEncoder !== "undefined") {
return new TextEncoder().encode(data);
}
if (typeof Buffer !== "undefined") {
return new Uint8Array(Buffer.from(data, "utf8"));
}
const out = new Uint8Array(data.length);
for (let i = 0; i < data.length; i += 1) {
out[i] = data.charCodeAt(i) & 0xff;
}
return out;
}
if (data instanceof Uint8Array) {
return data;
}