Purpose and Scope
The Desktop Companion acts as a bridge between the low-level Rust daemons (palyrad, palyra-browserd) and the high-level operator experience. Its primary responsibilities include:
- Process Supervision: Ensuring the availability of the core gateway and browser services.
- Operator Shell: Providing a session-aware chat interface and approval inbox without requiring a full browser tab.
- Local Node Management: Supervising the enrollment and runtime of the local
palyra nodehost. - Secure Handoff: Facilitating the transition from the local desktop context to the full Web Dashboard using a secure token-based flow.
System Context Diagram
The following diagram illustrates how the Desktop Companion (Tauri) orchestrates the local environment. “Desktop Companion Architecture” Sources: apps/desktop/src-tauri/src/supervisor.rs#212-234, apps/desktop/src-tauri/src/lib.rs#44-47, apps/desktop/ui/src/App.tsx#60-64Process Supervisor and Lifecycle Management
The core of the desktop application is theControlCenter, which manages ManagedService instances for the gateway, browser daemon, and node host. It handles binary path resolution, port binding, and automated restarts with exponential backoff.
- Service Management: Defines
ServiceKind(Gateway, Browserd, NodeHost) and tracks their liveness via PIDs and health checks. - Log Aggregation: Captures
stdoutandstderrfrom sidecars, streaming them into a boundedLogLinebuffer for diagnostic visibility. - State Persistence: Manages
DesktopStateFile, which tracks onboarding progress, rollout flags, and user preferences across app restarts.
Supervisor Code Entity Mapping
“Supervisor Code Entities” Sources: apps/desktop/src-tauri/src/supervisor.rs#37-41, apps/desktop/src-tauri/src/supervisor.rs#108-118, apps/desktop/src-tauri/src/supervisor.rs#212-234, apps/desktop/src-tauri/src/desktop_state.rs#215-227Desktop Companion Shell and Onboarding
The UI layer is a React-based SPA hosted within Tauri. It provides a “Companion Shell” that allows operators to interact with the system without leaving their native desktop environment.- Companion Shell: Features a session-aware chat interface, an approvals inbox for security decisions, and a notification system for system events.
- Onboarding Flow: A multi-step wizard (
DesktopOnboardingStep) that guides the user through environment setup, sidecar initialization, and initial provider authentication (e.g., OpenAI, Discord). - Offline Support: Implements
DesktopCompanionOfflineDraftto allow users to compose messages even when the local gateway is temporarily unreachable. - Dashboard Handoff: Provides a secure mechanism to open the full Web Dashboard in a standard browser, passing the necessary authentication context (
admin_tokenandcsrf_token).
UI and Command Mapping
| Feature | Tauri Command | UI Component / Hook |
|---|---|---|
| Snapshot Polling | get_desktop_companion_snapshot | useDesktopCompanion |
| Lifecycle Control | start_palyra, stop_palyra | LifecycleActionBar |
| Chat Interaction | send_companion_chat_message | App.tsx (sendBusy state) |
| Approvals | decide_companion_approval | App.tsx (approvalBusy state) |
| Handoff | open_desktop_companion_handoff | openDashboard helper |
Configuration and Secrets
The desktop app manages its own set of runtime secrets and configuration overrides to ensure the sidecars operate in a secure, isolated environment.- State Root: Users can override the default runtime directory during onboarding, which is then persisted in the state file.
- Runtime Secrets: The app generates and stores unique tokens like
DESKTOP_SECRET_KEY_ADMIN_TOKENandDESKTOP_SECRET_KEY_BROWSER_AUTH_TOKENto secure the communication between the UI, the supervisor, and the sidecars. - Rollout Flags: Feature flags like
voice_capture_enabledandoffline_drafts_enabledare managed viaDesktopCompanionRolloutStateto safely introduce experimental features.