@factory/collaboration
Realtime collaboration bridge for AI Software Factory
(docs/architecture/realtime-architecture.md §1–5; Phase 7, TASK-0091…0095).
Plain TypeScript classes — no React. apps/web (the canvas) wires the provider
to the Tiptap editor via y-prosemirror; apps/realtime is the server side of
the same frame protocol.
What's inside
| Module (subpath export) | Role |
|---|---|
. (index) |
Public surface: codec, provider, offline, awareness, outbox, lww |
./codec |
Block tree ↔ Yjs codec — blocksToYDoc / yDocToBlocks, minimal-op diff, round-trip + two-codecs-agree property tests |
./mapping |
yXml node mapping derived from @factory/shared's BLOCK_CONTENT_SCHEMAS (the structural gate for new block types) |
./provider |
WebSocket client provider — TASK-0091 R3 frame protocol: hello / sync.request / sync.state / binary 0x01-update + 0x02-awareness frames, close codes 4000–4010, token refresh on 4001, < 3 s reconnect budget |
./offline |
Offline persistence — y-indexeddb v9, 1 s autosave, doc name factory:{workspaceId}:{pageId} |
./awareness |
Presence/awareness store — deterministic colors from @factory/shared/presence, stale-cursor validity, 60 s client prune |
./outbox |
Non-editor mutation outbox — per-resource FIFO, Idempotency-Key, 1 s→30 s backoff, 4xx failed list, 24 h GC, 500-item cap |
./lww |
Last-writer-wins reconciliation helper for non-collaborative fields |
Dependencies
@factory/shared, yjs, y-indexeddb, y-prosemirror, zod.
Tests
pnpm --dir packages/collaboration test # vitest
pnpm --dir packages/collaboration typecheck