feat: stream files as binary frames over WebSocket (#659)

Replace base64-in-JSON file transfers with binary WebSocket frames to
unblock the JS thread when assistant markdown messages contain images.
Receive cost (JSON.parse over multi-MB base64) and persist cost (base64
re-encode to disk) both removed.

- Split daemon-client `exploreFileSystem` into `listDirectory` + `readFile`;
  `readFile` returns `{ bytes, mime, size, modifiedAt }`. Encoding stays
  private to the seam.
- New `packages/server/src/shared/binary-frames/` module hosts terminal
  frames (moved from `terminal-stream-protocol.ts`) and new file-transfer
  opcodes (`FileBegin` / `FileChunk` / `FileEnd`) with request-id correlation.
- Add optional `acceptBinary` to `FileExplorerRequestSchema`. New daemons
  emit binary frames when set; legacy JSON path remains for old clients.
  Compat fallback lives only inside `readFile`.
- New `persistAttachmentFromBytes` writes bytes directly: native via
  `expo-file-system` `File.write(Uint8Array)`, web via Blob -> IndexedDB,
  desktop via new `write_attachment_bytes` IPC. `persistAttachmentFromBase64`
  removed.
This commit is contained in:
Mohamed Boudra
2026-05-02 14:02:27 +08:00
committed by GitHub
parent b6c43088fb
commit bb889dae99
44 changed files with 1630 additions and 436 deletions
+36 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, test } from "vitest";
import { SessionOutboundMessageSchema } from "./messages.js";
import { FileExplorerRequestSchema, SessionOutboundMessageSchema } from "./messages.js";
function workspaceDescriptor(overrides: Record<string, unknown> = {}) {
return {
@@ -126,3 +126,38 @@ describe("workspace descriptor message compatibility", () => {
});
});
});
describe("file explorer request compatibility", () => {
test("acceptBinary is optional for old clients and accepted for new clients", () => {
expect(
FileExplorerRequestSchema.parse({
type: "file_explorer_request",
cwd: "/repo/app",
path: "image.png",
mode: "file",
requestId: "req-old",
}),
).toEqual({
type: "file_explorer_request",
cwd: "/repo/app",
path: "image.png",
mode: "file",
requestId: "req-old",
});
expect(
FileExplorerRequestSchema.parse({
type: "file_explorer_request",
cwd: "/repo/app",
path: "image.png",
mode: "file",
requestId: "req-new",
acceptBinary: true,
}),
).toMatchObject({
type: "file_explorer_request",
requestId: "req-new",
acceptBinary: true,
});
});
});