Host the CloudSync runtime in the GPUI shell and activate it from the GPUI session
Summary
Problem: ANLG-320 Phase 6. After #7541 (GPUI sign-in) and #7542 (shell-neutral DesktopDbRuntime), the GPUI shell still opened the SQLite file with a plain Db::connect_local_read_write and had no CloudSync at all: no runtime, no credential exchange, no recovery-key setup, and the E2EE glue (load_e2ee_recovery_key, open_shared_workspace_keyrings, recovery-key create/inspect/import, the bodies of the configure_cloudsync_token / configure_e2ee_replica commands) lived only inside tauri-plugin-db command handlers.
Fix: Stacked on #7542 and merging #7541's branch (both are needed; the diff shown here therefore includes #7541's auth commits until it lands).
desktop-db-runtime::cloudsync_config: the command bodies move here behindE2eeSecretReader/E2eeSecretWritertraits (secret access is the only shell-specific piece):
Tauri commands become aimpl<S: QueryEventSink> DesktopDbRuntime<S> { pub async fn configure_cloudsync_token_with_keys(&self, secrets: &dyn E2eeSecretReader, ...) -> Result<CloudsyncTokenConfigurationResult, String>; pub async fn configure_e2ee_replica_with_keys(&self, secrets: &dyn E2eeSecretReader, ...) -> Result<..., String>; } pub fn create_e2ee_recovery_code() -> Result<String, String>; pub fn inspect_e2ee_recovery_key(code: &str) -> Result<String /* key_id */, String>; pub async fn import_e2ee_recovery_key(secrets: &dyn E2eeSecretWriter, account_user_id: &str, code: &str) -> Result<(), String>;TauriE2eeSecrets(AppHandle)adapter overtauri_plugin_store2plus calls into these; command signatures andplugins/db/js/permissionsare unchanged.- GPUI
Store::opennow opens throughopen_app_db(Some(path))(CloudSync-capable open +prepare_schema, creating the database like Tauri does instead of bailing when it's missing) and ownsArc<DesktopDbRuntime<GpuiQueryEventSink>>, runningensure_app_schema/finish_startuplike the plugin'sbootstrap_app_database— minus the legacy JSON import, which still needs an AppHandle-free port. - New
apps/desktop-gpui/src/cloudsync.rs, a Rust port of the core ofapps/desktop/src/auth/cloudsync*.ts:POST /sync/token(404 →/sync/replica/credentials) with the same headers (X-Anarlog-E2EE-Key-Id, member public key,x-anarlog-cloudsync-transports: replica,x-device-fingerprint, sanitized device name), untagged Legacy/E2ee/Replica response, the same status →CredentialBlockmapping (404/501unavailable, 401reauth_required, 403device_limit/not_entitled, other → retry), post-exchange key-id and account mismatch checks, generation-guarded activation, refresh atexpiresAtwith the web constants (2 min lead / 1 min retry / 1 s floor), suspend on sign-out. Key id / member public key come from the stored recovery key exactly asget_e2ee_identity_statusderives them. Activation runs on startup, afterDeepLink::AuthCallback, and after sign-out. - Device enrollment (port of
enrollCurrentDevice): when no recovery key is stored, GPUI loads/creates the device enrollment key (get_or_create_e2ee_device_identity/import_e2ee_device_enrollmentmoved intocloudsync_config, Tauri commands become thin wrappers), POSTs/sync/e2ee/device-enrollments, mapse2ee_enrollment_requires_existing_key→setup_required, 403 →device_limit/not_entitled, 401 →reauth_required, polls every 5 s whileapproval_pending, and on a sealed package imports the recovery key and best-effort acks/consumebefore the credential exchange. - Local-library account switching (parity with #7637): the credential exchange checks
local_library_connectionsfor the current account and goes straight to/sync/replica/credentialswhen the library has been connected (no/sync/tokenattempt); when activation blocks withidentity_mismatch, the signed-in settings section offers "Connect library", which reads thecloudsync_workspace_bindingworkspace id, callsDesktopDbRuntime::connect_local_library(added on #7542 from main's runtime) and re-activates. - Recovery-key setup (port of
settings/general/e2ee-setup.tsx): when the block issetup_requiredthe signed-in settings section offers "Create a recovery key" (shows the code read-only with Copy and "I saved it") or "Use an existing key"; both paths run inspect →PUT /sync/e2ee/identity(same 409 / mismatch messages as the web) → import → re-activate. Settings also show a one-line sync status.
Deliberately not in this PR: recovery-key download-to-file and clipboard auto-clear, teardown-wait and pre-emptive suspend logic, device-limit toast, activity deferral, a GPUI cloud_sync_enabled toggle (none exists yet; the setting is read with the web default), legacy import.
Verification
cargo test --locked -p desktop-db-runtime(85) + clippy-D warnings;cargo test --locked -p tauri-plugin-db(69)git diff --exit-code plugins/db/js plugins/db/permissionsclean/home/ubuntu/gpui-cargo.sh test --locked -p desktop-gpui(467, includes new tests for credential-variant parsing, 403 block mapping, device-name sanitising, refresh delay, recovery-key inspect/import) and clippy--all-targets --no-deps -- -D warningscargo test --locked -p desktop-gpui cloudsync::(12, incl. mock-server tests that the replica endpoint is used directly for a connected local library and token-first with 404 fallback otherwise)- rustfmt/dprint on changed files,
git diff --check - Not exercised against a live API/sync server from this VM.
Link to Devin session: https://app.devin.ai/sessions/f83ed73d85c648fcbdbd041cd4f15720
Open in Devin Desktop: https://app.devin.ai/desktop/session/f83ed73d85c648fcbdbd041cd4f15720?variant=devin
Requested by: @ComputelessComputer