- **Sandboxing**: If App Sandbox is enabled, ensure `com.apple.security.network.client` and hardware access entitlements are correctly set in `.entitlements` or `Info.plist`.
Resources
7Install
npx skillscat add ericsk/skstats Install via the SkillsCat registry.
SKILL.md
skStats Development & Maintenance Guide
This document provides specialized instructions and architectural context for maintaining and extending the skStats macOS system monitoring application.
🏗 Architecture Overview
The app follows a modern SwiftUI architecture with a strict separation between UI, state management, and telemetry gathering.
1. Core Components
skStatsApp.swift: Entry point usingMenuBarExtra. Manages the high-level lifecycle and defines the Menu Bar display logic.SystemMonitor.swift:SystemMonitor(MainActor ObservableObject): The single source of truth for UI state. It handles settings persistence viaUserDefaultsand coordinates update cycles.TelemetryWorker(Actor): Handles all thread-unsafe and performance-heavy system calls (IOKit, Mach host info, libproc) in a background context to prevent UI hangs.SystemStats(Struct): A thread-safe data transfer object used to pass snapshots from the worker to the monitor.
ContentView.swift: The main dashboard UI. Uses specializedDashboardSectionwrappers and SwiftUIGaugecomponents for visualization.
2. Telemetry Logic
- CPU: Uses
host_processor_infowithPROCESSOR_CPU_LOAD_INFOto calculate per-core load. - GPU: Uses
IOKit(IOAccelerator) to fetch "Device Utilization %". - Memory: Uses
host_statistics64withHOST_VM_INFO64. - Disk/Network: Calculates rates by comparing cumulative byte counts over the
updateInterval. - Processes: Uses
libproc(proc_listpidsandproc_pidinfo). CPU percentage for processes is calculated by delta snapshots over time for accuracy.
🎨 UI & Styling Standards
- Color Cues: CPU Gauges use dynamic threshold coloring:
Green: < 70% (Normal)Orange: 70% - 90% (Warning)Red: > 90% (Critical)
- Components: Prefer
Gaugefor percentage-based metrics andStatViewfor rate-based metrics (MB/s). - Aesthetics: Use
VisualEffectViewfor native macOS vibrant backgrounds. Maintain monospaced fonts for numerical data to prevent layout jitter.
🛠 Maintenance Workflows
Build & Run (Development)
xcodebuild -project skStats.xcodeproj -scheme skStats -configuration Debug -derivedDataPath build build
./build/Build/Products/Debug/skStats.app/Contents/MacOS/skStatsBuild & Run (Release)
xcodebuild -project skStats.xcodeproj -scheme skStats -configuration Release -derivedDataPath build clean build
open build/Build/Products/Release/skStats.appKey Maintenance Tasks
- Updating Constants: The
updateIntervalis configurable via UI but defaults to 3s. - Process Filtering: Top processes are limited to the top 3 by default. Adjust
prefix(3)inTelemetryWorkerto change this. - Adding New Metrics:
- Update
SystemStatsstruct. - Add fetch logic in
TelemetryWorker. - Update
SystemMonitor@Publishedproperties. - Create a new dashboard view in
ContentView.swift.
- Update
⚠️ Security & Performance
- Actor Isolation: Never call
TelemetryWorkermethods directly from the UI. Always useTaskfromSystemMonitor. - Memory Safety: Ensure all
io_object_tand Mach pointers are properly released/deallocated. - Sandboxing: If App Sandbox is enabled, ensure
com.apple.security.network.clientand hardware access entitlements are correctly set in.entitlementsorInfo.plist.