palyrad) and the browser daemon (palyra-browserd), providing a guided onboarding experience for new users and sophisticated profile isolation for advanced users.
Desktop Onboarding State Machine
Onboarding is managed via a state machine defined by theDesktopOnboardingStep enum apps/desktop/src-tauri/src/desktop_state.rs#205-215. The ControlCenter tracks the current step and any failures in the DesktopStateFile apps/desktop/src-tauri/src/desktop_state.rs#217-233.
Onboarding Steps
| Step | Purpose |
|---|---|
Welcome | Initial greeting and risk acknowledgment. |
Environment | Verification of binary paths and system requirements. |
StateRoot | Selection of the directory for data persistence (Journal, Vault, etc.). |
GatewayInit | Bootstrapping the palyrad configuration and initial start. |
OperatorAuthBootstrap | Generating the desktop_admin_token and setting up mTLS. |
OpenAiConnect | OAuth or API Key configuration for the primary LLM provider. |
DiscordConnect | (Optional) Setting up the Discord connector for remote access. |
DashboardHandoff | Transitioning the user to the full Web Console. |
Completion | Finalizing the setup and marking the profile as active. |
Profile Isolation & Management
Palyra supports multiple isolated profiles, allowing users to switch between different environments (e.g., “local-dev”, “production-admin”). Profiles are managed through theDesktopProfileCatalog apps/desktop/src-tauri/src/profile_registry.rs#135-141.
DesktopStateFile Persistence
TheDesktopStateFile is the primary persistence mechanism for the Desktop app, stored in the state.json file within the Desktop state root apps/desktop/src-tauri/src/supervisor.rs#211-212. It tracks:
- Active Profile: The currently selected profile name apps/desktop/src-tauri/src/desktop_state.rs#223.
- Onboarding Progress: The last completed step and any failure history apps/desktop/src-tauri/src/desktop_state.rs#218-220.
- Companion State: UI preferences like active section, session ID, and recent notifications apps/desktop/src-tauri/src/desktop_state.rs#92-103.
Profile Switching Logic
When a profile is switched viaswitch_desktop_companion_profile apps/desktop/src-tauri/src/companion.rs#245-263, the following flow occurs:
- The
ControlCenterstops all running services (palyrad,browserd). - The
active_profile_nameis updated inDesktopStateFile. - The
runtime_rootis re-resolved based on the new profile’s configuration. - Secrets are re-loaded from the new profile’s Vault.
- Services are restarted using the new profile’s environment.
Secret Migration to Vault
Historically, the Desktop app stored administrative tokens in plain text withinstate.json. Modern versions migrate these to the palyra-vault apps/desktop/src-tauri/src/desktop_state.rs#259-284.
Migration Process
The functionmigrate_legacy_runtime_secrets_from_state_file apps/desktop/src-tauri/src/desktop_state.rs#320-357 performs the following:
- Checks if
legacy_admin_tokenorlegacy_browser_auth_tokenexist in theDesktopStateFile. - Initializes a
Vaultusing theDesktopSecretStorebackend apps/desktop/src-tauri/src/desktop_state.rs#260-265. - Writes the tokens to the Vault under the
VaultScope::Runtimeapps/desktop/src-tauri/src/desktop_state.rs#343-352. - Clears the legacy fields from the state file and increments the
schema_version.
Offline Drafts
The Desktop Companion Shell allows users to compose messages even when the daemon is offline or unreachable. These are managed asDesktopCompanionOfflineDraft objects apps/desktop/src-tauri/src/desktop_state.rs#62-68.
Draft Lifecycle
- Queueing: If a message fails to send and
queue_on_failureis true,queue_offline_draftis called apps/desktop/src-tauri/src/desktop_state.rs#175-196. - Persistence: Drafts are stored in the
notificationsarray withinDesktopCompanionStateapps/desktop/src-tauri/src/desktop_state.rs#101. - Removal: Once a draft is successfully sent or manually deleted,
remove_offline_draftpurges it by ID apps/desktop/src-tauri/src/desktop_state.rs#198-200.
Technical Diagrams
Onboarding Data Flow
This diagram illustrates how theControlCenter orchestrates the onboarding process and persists state.
Sources: apps/desktop/src-tauri/src/commands.rs#84-93, apps/desktop/src-tauri/src/supervisor.rs#205-226, apps/desktop/src-tauri/src/desktop_state.rs#217-233
Profile Registry & Resolution
This diagram shows the relationship between profile definitions and the active runtime environment. Sources: apps/desktop/src-tauri/src/profile_registry.rs#135-141, apps/desktop/src-tauri/src/supervisor.rs#410-440, crates/palyra-cli/src/app/mod.rs#82-89Key Implementation Details
DesktopStateFile Schema
TheDesktopStateFile versioning is tracked by DESKTOP_STATE_SCHEMA_VERSION apps/desktop/src-tauri/src/lib.rs#9. It contains the DesktopOnboardingState apps/desktop/src-tauri/src/desktop_state.rs#217-233 and the DesktopCompanionState apps/desktop/src-tauri/src/desktop_state.rs#92-103.
Runtime Secret Keys
The following keys are used for storing secrets in the Vault:desktop_admin_token: Used for administrative access topalyradapps/desktop/src-tauri/src/lib.rs#11.desktop_browser_auth_token: Used for authentication withpalyra-browserdapps/desktop/src-tauri/src/lib.rs#12.