Desktop State & Persistence
The desktop application maintains a persistent state instate.json, managed by the DesktopStateFile struct. This file tracks the onboarding progress, rollout flags, and companion preferences.
Schema & Migration
The state follows a versioned schema defined byDESKTOP_STATE_SCHEMA_VERSION apps/desktop/src-tauri/src/lib.rs#9-9. The load_or_initialize_state_file function handles the lifecycle of this file, including automatic migrations when the schema version increments apps/desktop/src-tauri/src/desktop_state.rs#250-280.
Vault-Backed Secret Storage
Sensitive runtime secrets, such as thedesktop_admin_token and desktop_browser_auth_token, are stored in the DesktopSecretStore. This store utilizes the palyra-vault crate with an EncryptedFile backend apps/desktop/src-tauri/src/desktop_state.rs#434-450.
| Secret Key | Purpose |
|---|---|
desktop_admin_token | Authenticates the Desktop Control Center against the palyrad admin API. |
desktop_browser_auth_token | Authenticates the palyra-browserd sidecar. |
Onboarding Flow
The onboarding process is a linear state machine defined byDesktopOnboardingStep. It ensures the local environment is prepared before handing off to the web dashboard.
Onboarding Steps
- Welcome: Initial landing and EULA acknowledgement.
- Environment: Preflight checks for dependencies (ports, binaries).
- State Root: Selection and validation of the runtime data directory.
- Gateway Init: Bootstrapping the
palyraddaemon. - Operator Auth: Generating and pinning the local operator identity.
- Model Provider (OpenAI): Connecting API keys or OAuth.
- Connector (Discord): Optional setup of chat platform integrations.
- Dashboard Handoff: Generating a secure token to open the Web Console.
- Completion: Finalizing the setup.
Preflight Checks
Thebuild_preflight_snapshot function performs non-blocking and blocking checks on the host system, verifying port availability (7142, 7443, 7444) and binary existence for palyrad and palyra-browserd apps/desktop/src-tauri/src/onboarding.rs#201-240.
Data Flow: Onboarding Logic
Sources: apps/desktop/src-tauri/src/onboarding.rs#78-112, apps/desktop/src-tauri/src/commands.rs#95-104, apps/desktop/src-tauri/src/desktop_state.rs#205-215.Companion UI & Polling Model
The Companion UI is a React application (apps/desktop/ui) embedded within Tauri. It provides a “lite” version of the console, focused on approvals, notifications, and local status.
The Polling Model
The UI uses theuseDesktopCompanion hook to synchronize state. Instead of complex WebSocket management for the desktop-to-daemon link, it relies on a high-frequency polling of the get_desktop_companion_snapshot Tauri command apps/desktop/ui/src/hooks/useDesktopCompanion.ts.
The snapshot includes:
- Control Center Status: Process health and logs.
- Approval Inbox: Pending tool calls requiring human-in-the-loop (HITL) consent.
- Notification Feed: Real-time alerts for runs, connections, and trust events.
- Offline Drafts: Messages queued when the daemon is unreachable.
Offline Drafts & Queueing
When thepalyrad gateway is down or unreachable, the Companion UI allows users to “draft” messages. These are stored in the DesktopCompanionState apps/desktop/src-tauri/src/desktop_state.rs#175-196. Once the gateway returns to a Healthy state, the UI prompts the user to sync these drafts apps/desktop/ui/src/App.tsx#100-104.
Companion State Management
Sources: apps/desktop/src-tauri/src/desktop_state.rs#92-120, apps/desktop/src-tauri/src/companion.rs#80-101, apps/desktop/ui/src/lib/desktopApi.ts#256-275.Dashboard Handoff
The transition from the Desktop App to the Web Console (running in a standard browser) is secured via a handoff token.- Request: The user clicks “Open Dashboard” in the Companion UI.
- Token Generation: The
ControlCenterrequests a short-lived admin session from the localpalyradinstance apps/desktop/src-tauri/src/snapshot.rs#213-230. - URL Construction: The
build_dashboard_open_urlfunction appends theadmin_tokenand acsrf_tokento the dashboard URL apps/desktop/src-tauri/src/snapshot.rs#232-250. - Launch: The desktop app invokes the system’s default browser with the authenticated URL.