Cosmo Docs
Desktop App

SyncManager

Cloud sync via pull/push and SSE change feed

packages/desktop/src/main/sync-manager.ts orchestrates two-way synchronisation between local disk and the Cosmo cloud backend for onboarding data and memory files.

Sync Targets

Local FileCloud EndpointDirection
users/{userId}.jsonPUT/GET /api/v1/sync/profileBoth
onboarding/{orgId}.jsonPUT/GET /api/v1/sync/org-onboardingBoth
memory/user-{userId}.mdPUT/GET /api/v1/sync/memory/userBoth
memory/org-{orgId}.mdPUT/GET /api/v1/sync/memory/orgBoth

Startup Pull

pull() is called once when the app starts (after auth is confirmed). It fetches all four targets from the cloud and writes them to disk, overwriting any stale local data. This ensures the desktop always starts with the latest cloud state.

Sync metadata is tracked in userData/cosmo-data/.cosmo-sync-meta.json (last-synced timestamps per target).

Push Methods

Push methods are called by OnboardingManager whenever local data changes. They are fire-and-forget (exceptions are caught and logged).

MethodEndpoint
pushUserProfile(data)PUT /api/v1/sync/profile
pushOrgOnboarding(data)PUT /api/v1/sync/org-onboarding
pushUserMemory(content)PUT /api/v1/sync/memory/user
pushOrgMemory(content)PUT /api/v1/sync/memory/org

SSE Change Feed

startListening() connects to GET /api/v1/sync/changes — a Server-Sent Events stream. The server sends a heartbeat event every 30 seconds to keep the connection alive.

When a file-changed event arrives, handleRemoteChange(event) determines which local target changed and re-pulls only that file from the cloud.

When a remote change event arrives, main/index.ts forwards it to the renderer via webContents.send('sync:remote-change', event) so the UI can refresh affected data.

SyncClient

packages/desktop/src/main/sync-client.ts is a thin HTTP wrapper used by SyncManager and the IPC handlers. It wraps fetch with Bearer token auth and X-Org-Id header injection.

Endpoints Covered

SyncClient only wraps the sync/memory and onboarding endpoints. Other API calls (tasks, workspaces, billing, etc.) are made directly in main/index.ts IPC handlers.

MethodPathPurpose
PUT/sync/profileStore user profile
GET/sync/profileRetrieve user profile
PUT/sync/org-onboardingStore org onboarding
GET/sync/org-onboardingRetrieve org onboarding
PUT/sync/memory/userStore user memory
GET/sync/memory/userRetrieve user memory
PUT/sync/memory/orgStore org memory
GET/sync/memory/orgRetrieve org memory
GET/sync/changesSSE change feed
POST/tasks/seedSeed onboarding tasks
GET/tasksList tasks
POST/tasksCreate task
PATCH/tasks/:idUpdate task
POST/tasks/reprioritizeAI reprioritization
POST/auth/seed-onboardingSeed sample org data
GET/workspacesList workspaces