/** Wire protocol shared by the EditorRoom Durable Object, the gitfor-fs VS Code extension and agent clients. */ export const EDITOR_WS_PROTOCOL = "gitfor-editor.v1"; /** Binary frames start with a varUint message type, as in y-websocket. */ export const MESSAGE_SYNC = 0; export const MESSAGE_AWARENESS = 1; /** Close codes: clients stop on 4401, reconnect read-only on 4403, reconnect normally on 4408. */ export const CLOSE_REVOKED = 4401; export const CLOSE_DOWNGRADED = 4403; export const CLOSE_REAUTH = 4408; /** Y.Map holding per-path metadata; Y.Text contents live under `file:`. */ export const FILES_MAP = "files"; export const TEXT_PREFIX = "file:"; export type FileKind = "text" | "binary" | "lfs" | "too-large" | "symlink" | "gitlink"; /** * - `seeded`: loaded from the branch head. * - `created`: new in this session. * - `deleted`: staged for deletion. * - `missing`: requested but absent at head. * - `conflict`: changed upstream while edited here. */ export type FileState = "seeded" | "created" | "deleted" | "missing" | "conflict"; export type FileMeta = { state: FileState; kind: FileKind; size: number }; export type ChangeStatus = "A" | "M" | "D"; /** JSON text frames from client to room. */ export type ClientControl = | { type: "open"; path: string } | { type: "create"; path: string } | { type: "delete"; path: string } | { type: "resolve"; path: string } | { type: "ping" }; /** JSON text frames from room to clients. */ export type RoomControl = | { type: "welcome"; head: string; branch: string; writable: boolean; user: string; clientLimit: number } | { type: "status"; head: string; changes: Array<{ path: string; status: ChangeStatus }>; conflicts: string[] } | { type: "committed"; sha: string; branch: string; pullUrl: string | null; by: string } | { type: "error"; message: string; path?: string } | { type: "pong" }; export function textKey(path: string): string { return `${TEXT_PREFIX}${path}`; }