feat: unified WS event bus, v2Hosts data model, real diff stats

Merged
SA
7mo ago
+6658-847

Summary

  • Unified WS event bus: Single /events WebSocket endpoint on host-service replacing per-workspace filesystem WS connections. Carries git:changed (auto-pushed for all workspaces) and fs:events (on-demand per client request). Client-side connection manager with reconnection and ref-counting.
  • v2Hosts/v2Clients data model: Replaced v2Devices/v2DevicePresence/v2UsersDevices with v2Hosts (machineId NOT NULL, lastSeenAt), v2Clients (machineId, userId, type: desktop/mobile/web), v2UsersHosts (owner/member). v2Workspaces.deviceId → hostId.
  • Real diff stats: Left sidebar chips show actual +N / -N from git.getStatus, triggered by git:changed events instead of polling. Multi-host routing ready (local → localhost, remote → proxy URL pattern).
  • GIT_OPTIONAL_LOCKS=0: Prevents index.lock contention between host-service git reads and user git operations.
  • Changes tab fix: Header stats now update when switching the filter dropdown (all/uncommitted/commit).
  • PR polling: Bumped to 10s (was 15s on client, 30s on host-service).

Test plan

  • Left sidebar diff stats show real data matching git diff --shortstat
  • Making code changes updates the diff stats chip (git watcher fires)
  • File tree still works (filesystem events over unified event bus)
  • Network tab shows single /events WS connection per host
  • git checkout / git commit in terminal doesn't hit index.lock errors
  • Changes tab header stats update when switching filter dropdown
  • Cloud workspaces show no diff stats chip
  • bun run lint:fix && bun run typecheck passes

Summary by cubic

Unifies host-service events behind a single /events WebSocket and completes the v2Hosts/v2Clients migration, delivering live diff stats and an event‑driven Changes tab. Reduces connections, improves multi‑host routing, and avoids git lock conflicts.

  • New Features

    • Single /events WS per host emits git:changed (auto) and fs:events (opt‑in); one shared connection with reconnection and ref‑counting.
    • Real diff stats (+N/−N) via useDiffStats and useWorkspaceEvent; dedupes by path to avoid double‑counting; Changes tab invalidates status/commits on git:changed (no polling).
    • Data model: v2Hosts, v2Clients, v2UsersHosts; workspaces now use hostId. ensureV2Host(machineId) and new ensureV2Client.
  • Bug Fixes

    • More reliable host URL resolution and multi‑host routing (local service when present, else proxy api/v2-hosts/:hostId/trpc).
    • Event bus fixes: ref‑counted watchFs/unwatchFs; 300ms per‑workspace debounce in GitWatcher; removed legacy FS event bridge in workspace-client.
    • Set GIT_OPTIONAL_LOCKS=0 to avoid index.lock contention.
    • PR polling set to 10s; small UI polish (diff‑stats pill sizing, LuFolderGit2, editor width); cleanup of stale DB enums; re‑exported FS types from @superset/workspace-fs/client.

Summary by CodeRabbit

  • New Features

    • Real-time event bus and client hooks for git and filesystem events; workspace components now subscribe to live git/fs notifications.
    • Live diff stats in the workspace sidebar (replacing mocked values).
  • Refactor

    • Platform model migrated from device→host: host-based selection, local vs remote detection, routing, and workspace metadata updated.
    • Host-focused UI: pickers, icons, and workspace forms reflect host/cloud semantics.
  • Performance

    • More responsive updates: reduced polling intervals and event-driven invalidation replacing frequent polling.