3.3 KiB
apps/desktop/
Responsibility
OpenPets desktop companion application. Tray-first Electron app providing animated desktop pets that react to coding agent events. Manages pet installations, agent integrations (Claude Code, OpenCode), and local IPC for CLI communication.
Design
- Tray-First UX: No main window; all interaction via tray menu or task windows (pet-manager, agent-setup, settings, onboarding)
- Single Instance: Uses
app.requestSingleInstanceLock()with second-instance focusing - Security Model:
- Sandboxed renderers with contextIsolation
- Preload scripts expose limited APIs via
contextBridge - CSP:
default-src 'none', inline styles only - Mock keychain to prevent OS credential prompts
- State Management: File-based JSON state with atomic writes (temp + rename)
- Pet Architecture:
- Default pet (always visible when enabled)
- Agent pets (lease-based, appear on explicit agent requests)
- Built-in fallback pet (bundled spritesheet)
- Lease Manager: 15s TTL leases for agent pet routing with heartbeat renewal
Flow
Startup: main.ts → installAppLifecycle() → initializeAppState() → createAppTray() → startLocalIpcServer() → optionally showDefaultPet()/openTaskWindow("onboarding")
Pet Display: IPC Request → local-ipc.ts → LeaseManager.acquire() → agent-pet-controller.ts → pet-window.ts → HTML/CSS spritesheet animation
Installation: Catalog fetch → ZIP download → yauzl extraction → validation → state update → tray refresh
Agent Setup: UI → agent-setup.ts → Claude/OpenCode CLI detection → MCP config modification → hooks installation → memory file management
Integration Points
- Workspace Packages:
@open-pets/claude(MCP/hooks),@open-pets/opencode(global setup),@open-pets/cli(bundled commands) - External Services:
https://openpets.dev/pets/catalog.v2.json(pet catalog)https://zip.openpets.dev/pets/{id}.zip(pet downloads)- GitHub API (release checks)
- System Integration:
- Claude Code:
~/.claude/CLAUDE.md,~/.claude/settings.json,claude mcpcommands - OpenCode:
~/.opencode/config.json - Codex:
~/.codex/pets/(local pet development) - IPC: Discovery file at platform-specific path, Unix socket/Windows named pipe
- Claude Code:
- Build:
electron-builderwith ASAR, cross-platform (macOS/Windows/Linux)
Key Files
main.ts: Entry point, lifecycle coordinationtray.ts: System tray icon and menuwindows.ts: Task window management (pet-manager, agent-setup, settings, onboarding)local-ipc.ts: TCP/Unix socket server for CLI communicationlease-manager.ts: Pet routing lease lifecyclepet-window.ts: Pet rendering (transparent frameless windows, CSS sprite animation)default-pet-controller.ts/agent-pet-controller.ts: Pet visibility/state managementapp-state.ts: Persistent state management (JSON file)agent-setup.ts: Claude/OpenCode integration logicpet-installation.ts: Catalog ZIP download and extractioncodex-pets.ts: Local Codex pet importcatalog.ts: Remote catalog fetching with fixture fallbackpreload.cjs/pet-preload.cjs: Renderer preload scripts (contextBridge APIs)electron-builder.yml: Packaging configurationscripts/release-local.mjs: macOS-local release automation with GitHub draft creation