// // ThermalMonitor.swift // Poche // // Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // import Foundation import Observation /// Watches thermal state so we slow down before the system throttles us /// (CLAUDE.md §9). Battery and heat are the scarcest budgets of a local /// chat app. @MainActor @Observable final class ThermalMonitor { private(set) var state: ProcessInfo.ThermalState = ProcessInfo.processInfo.thermalState // App-lifetime object (owned by AgentSession): the observation is never // removed, so no deinit — Swift 6 deinits cannot touch isolated state. private var observer: (any NSObjectProtocol)? var shouldPauseInference: Bool { state == .critical } init() { observer = NotificationCenter.default.addObserver( forName: ProcessInfo.thermalStateDidChangeNotification, object: nil, queue: .main ) { [weak self] _ in // Delivered on the main queue; re-read from ProcessInfo because // the Notification object is not Sendable and carries nothing. MainActor.assumeIsolated { self?.state = ProcessInfo.processInfo.thermalState } } } }