How liyexin156-code/cyberpet works
1. App type and runtime
CyberPet is a macOS accessory app, not a normal document or web app. It runs as a menu-bar/background-style desktop pet with no Dock icon (LSUIElement = true), built in Swift 5.9 on macOS 14+, using SwiftUI, AppKit window controllers, SpriteKit-style animation playback, and SwiftData persistence.
2. Process entry and app bootstrap
The runtime starts in Sources/PetTaskBuddy/main.swift, then hands off to AppDelegate.swift. From there the app wires together the pet window, main panel UI, persistence, scheduling, localization, and any background/login-item behavior. This is the top-level composition boundary for the whole system.
3. Core pet runtime
The pet itself is centered around PetScene.swift, PetWindowController.swift, and ManifestAnimationPlayer.swift. These pieces render the pixel dog, choose and play animations, and keep the pet visible in a transparent desktop window. AnimationManifest.swift and the sprite assets under Assets/pet define what animations exist and how they are sequenced.
4. Pet state and behavior engine
PetStateEngine.swift, PetStateRecord.swift, PetAutonomousBehavior.swift, PixelTheme.swift, and LayoutConstants.swift form the pet’s behavior/state layer. This is where mood, fullness, idle/sleep/run/walk/sniff/pee-like behaviors, and reactive transitions are decided. The engine is the main decision boundary between UI animation and higher-level app state.
5. Task and schedule subsystem
Daily task tracking is modeled by DailyTask.swift, Goal.swift, ScheduleItem.swift, and coordinated by ScheduleCoordinator.swift. This subsystem is responsible for completion tracking, task timing, and the rules that connect tasks to pet reactions and reminders. It is the “productivity” half of the app, distinct from the pet animation layer.
6. Thought bubble and task UI
MainPanelWindowController.swift and ThoughtBubbleWindowController.swift provide the user-facing panels around the pet. The thought bubble is a separate near-pet UI surface for tasks/status, while the main panel likely acts as a broader control or list view. ThoughtBubbleHitRegionTests in the test suite suggests this UI has explicit click/interaction geometry separate from the pet sprite window.
7. Persistence and local storage
Persistent state is handled by PersistenceController.swift with SwiftData as the storage layer. This likely stores tasks, pet state snapshots, and schedule-related records so the pet and task list survive relaunches. TaskPersistenceSmokeTest.swift and PetStateSmokeTest.swift indicate persistence is a first-class boundary, not incidental UI state.
8. Reminders, notifications, and background timing
ReminderService.swift manages reminder scheduling/notification behavior, while ReminderSecondsSmokeTest.swift and ScheduleSmokeTest.swift show the timing logic is important enough to validate independently. This subsystem bridges persisted tasks/schedules to time-based user alerts and pet reactions.
9. Localization and user customization
LocalizationManager.swift handles Chinese/English switching, which affects menus, labels, and probably task text rendered in the UI. README.md notes right-click language switching, so localization is an app-wide service rather than a narrow UI detail.
10. Identity, startup, and packaging
LoginItemService.swift supports launch-at-login behavior, while Packaging/com.liyexin.PetTaskBuddy.launchagent.plist and Packaging/Info.plist define bundle/runtime metadata. Tools/package-app.sh assembles the distributable app bundle, and dist/CyberPet.zip is an unsigned beta package. These files define how the app is installed and launched on macOS.
11. AI integration boundary
AITaskService.swift and AITaskSmokeTest.swift indicate an optional AI-backed task feature. KeychainService.swift suggests credentials or tokens are stored securely, so AI is isolated behind a service boundary rather than embedded in the UI or pet engine. This subsystem is likely optional and should be drawn separately from core pet behavior.
12. Testing and validation layers
The Tests/PetTaskBuddyTests suite covers animation assets, localization sources, walk/run/side-lie behavior sources, thought bubble hit regions, and task reward toggles. In addition, the Sources/...SmokeTest.swift files expose executable smoke-test modes via the app binary itself. That means the repo has both unit tests and “run the app in test mode” validation paths.
13. Useful architectural diagram boundaries
A good diagram should separate:
- UI surfaces: pet window, main panel, thought bubble
- Pet engine: state, behavior, animation selection
- Task/schedule domain: tasks, goals, reminders, schedules
- Persistence: SwiftData/local storage
- Platform services: login item, keychain, notifications
- Assets/config: sprite manifest, packaging metadata, localization
These boundaries reflect how the code is organized and where data flows cross subsystem lines.
Main entry points: AppDelegate.swift AppDelegate · ScheduleCoordinator.swift Schedule Coordinator · PetTaskBuddyTests Unit Tests · PetScene.swift Pet Scene
Components 27
Bootstrap
Process entry and top-level app composition
- main.swift · Process entry for the macOS accessory app
Sources/PetTaskBuddy/main.swift - AppDelegate · Wires together windows, services, persistence, scheduling, and startup behavior
Sources/PetTaskBuddy/AppDelegate.swift
Pet Runtime
Rendering, animation selection, and pet behavior
- Pet Window · Transparent desktop pet window controller
Sources/PetTaskBuddy/PetWindowController.swift - Pet Scene · Renders the pet and drives animation playback in the window
Sources/PetTaskBuddy/PetScene.swift - Animation Player · Selects and plays manifest-defined sprite animations
Sources/PetTaskBuddy/ManifestAnimationPlayer.swift - State Engine · Decides pet mood, idle, movement, and reactive transitions
Sources/PetTaskBuddy/PetStateEngine.swift - Autonomous Behavior · Encodes autonomous pet actions and transitions
Sources/PetTaskBuddy/PetAutonomousBehavior.swift - State Record · Persistent record of pet state snapshots
Sources/PetTaskBuddy/PetStateRecord.swift - Pixel Theme · Theme and presentation values for the pixel pet
Sources/PetTaskBuddy/PixelTheme.swift - Layout Constants · Shared geometry and spacing constants
Sources/PetTaskBuddy/LayoutConstants.swift
UI Surfaces
Pet-adjacent windows and control panels
- Main Panel · Broader control or list panel around the pet
Sources/PetTaskBuddy/MainPanelWindowController.swift - Thought Bubble · Near-pet task and status bubble UI
Sources/PetTaskBuddy/ThoughtBubbleWindowController.swift
Task Domain
Daily tasks, goals, schedules, and reminders
- Daily Task · Core task item tracked by the app
Sources/PetTaskBuddy/DailyTask.swift - Goal · Goal-level task structure or grouping
Sources/PetTaskBuddy/Goal.swift - Schedule Item · Time-based task or reminder entry
Sources/PetTaskBuddy/ScheduleItem.swift - Schedule Coordinator · Coordinates task timing, completion, and reactions
Sources/PetTaskBuddy/ScheduleCoordinator.swift
Platform Services
Persistence, login, localization, keychain, and AI boundaries
- Reminder Service · Schedules reminders and notification timing
Sources/PetTaskBuddy/ReminderService.swift - Persistence · SwiftData-backed local storage boundary
Sources/PetTaskBuddy/PersistenceController.swift - Localization · Language selection and localized text resolution
Sources/PetTaskBuddy/LocalizationManager.swift - Login Item · Launch-at-login integration for the app
Sources/PetTaskBuddy/LoginItemService.swift - Keychain · Secure storage for credentials or tokens
Sources/PetTaskBuddy/KeychainService.swift - AI Task · Optional AI-backed task feature boundary
Sources/PetTaskBuddy/AITaskService.swift
Assets and Packaging
Animation manifest and macOS bundle metadata
- Animation Manifest · Defines available pet animations and sequencing
Assets/pet/manifest.json - Info.plist · macOS bundle and runtime metadata
Packaging/Info.plist - LaunchAgent plist · Login/background launch configuration
Packaging/com.liyexin.PetTaskBuddy.launchagent.plist
Validation
Executable smoke tests and unit tests
- Smoke Tests · Executable smoke-test entry points in the app binary
- Unit Tests · Focused tests for assets, localization, UI geometry, and behavior sources
Tests/PetTaskBuddyTests
Connections 40
- main.swift → AppDelegate: boots · Entry point hands off to app composition
- AppDelegate → Pet Window: creates · Initializes the pet window controller
- AppDelegate → Main Panel: creates · Initializes the main control panel
- AppDelegate → Thought Bubble: creates · Initializes the thought bubble UI
- AppDelegate → Persistence: loads · Wires persistent app state
- AppDelegate → Schedule Coordinator: starts · Starts task and schedule coordination
- AppDelegate → Reminder Service: wires · Connects reminders into startup flow
- AppDelegate → Localization: configures · Sets up app language behavior
- AppDelegate → Login Item: configures · Sets up launch-at-login behavior
- AppDelegate → AI Task: attaches · Optionally enables AI-backed task features
- Pet Window → Pet Scene: hosts · Displays the animated pet scene
- Pet Scene → Animation Player: plays · Uses animation playback to drive sprite motion
- Animation Player → Animation Manifest: reads · Loads available animation definitions
- Pet Scene → State Engine: queries · Uses state decisions to choose behavior
- State Engine → Autonomous Behavior: applies · Uses autonomous behavior policy
- State Engine → State Record: persists · Produces and consumes pet state snapshots
- State Engine → Pixel Theme: styles · Feeds visual theme decisions
- Pet Scene → Layout Constants: uses · Applies shared layout geometry
- Main Panel → Daily Task: shows · Surfaces task data to the user
- Thought Bubble → Schedule Coordinator: reflects · Shows near-pet schedule and status context
- Schedule Coordinator → Daily Task: organizes · Coordinates task tracking
- Schedule Coordinator → Goal: groups · Relates tasks to goals
- Schedule Coordinator → Schedule Item: plans · Works with timed schedule entries
- Schedule Coordinator → Reminder Service: triggers · Turns schedules into reminders
- Daily Task → Persistence: stores · Task records are persisted locally
- State Record → Persistence: stores · Pet state snapshots are persisted locally
- Localization → Main Panel: labels · Localizes UI text and menu strings
- Localization → Thought Bubble: labels · Localizes task bubble content
- Keychain → AI Task: secures · Holds credentials used by AI features
- Info.plist → AppDelegate: describes · Defines bundle/runtime metadata for the app
- LaunchAgent plist → Login Item: supports · Background launch configuration backing login behavior
- Smoke Tests → AI Task: covers · Executable smoke validation for AI task flow
- Smoke Tests → Persistence: covers · Executable smoke validation for storage flow
- Smoke Tests → Schedule Coordinator: covers · Executable smoke validation for scheduling flow
- Smoke Tests → State Record: covers · Executable smoke validation for pet state persistence
- Unit Tests → Animation Player: tests · Validates animation selection and asset behavior
- Unit Tests → Localization: tests · Validates language source behavior
- Unit Tests → Thought Bubble: tests · Validates hit regions and interaction geometry
- Unit Tests → Autonomous Behavior: tests · Validates autonomous behavior sources
- Unit Tests → Daily Task: tests · Validates task reward behavior