Create sync infrastructure for the single-DB multi-app architecture:
sync.ts — Unified Sync Manager:
- One sync channel per appId (todo, calendar, contacts, etc.)
- Push: collects _pendingChanges tagged with appId → POST /sync/{appId}/push
- Pull: fetches server delta per collection → applies field-level LWW
- WebSocket: connects to /sync/{appId}/ws for real-time push notifications
- Online/offline handling with automatic reconnect
- Uses SYNC_APP_MAP from database.ts for table→appId routing
change-tracker.ts — Write tracking helper:
- trackChange(): records writes to _pendingChanges with auto-appId lookup
- trackFieldUpdate(): field-level LWW tracking for partial updates
- trackDelete(): soft-delete tracking
The _pendingChanges table now includes appId as an indexed field,
and _syncMeta uses compound key [appId+collection] for per-app cursors.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>