A luxe hook runs luxe-notify, which sends one JSON line over a Unix socket to a SwiftUI menu bar app. The app shows a banner, keeps a badge count and history, and brings the terminal forward when you click a banner. Notifies on approvals (PermissionRequested), question prompts (BeforeToolUse, matched to the question tool), errors, and turns that run at least --min-seconds (default 30, timed from BeforeAgentStart to AgentEnd). The menu warns when macOS has notifications blocked for the app. The app writes status.txt beside its socket for debugging. Known limits are in README.md and PLAN.md: a crowded menu bar can hide the icon, and the first test build after a change can fail with a TestingMacros error under Command Line Tools, which make test retries once.
32 lines
1.5 KiB
Swift
32 lines
1.5 KiB
Swift
import Foundation
|
|
|
|
/// Decides whether a finished turn is worth a notification. A quick turn means you are probably
|
|
/// still at the keyboard, so notifying would just be noise.
|
|
public enum TurnTimer {
|
|
public static let defaultMinimumSeconds: TimeInterval = 30
|
|
|
|
public static func shouldNotify(startedAt: Date?, endedAt: Date, minimumSeconds: TimeInterval) -> Bool {
|
|
// No recorded start (hook not installed, or app restarted mid-turn): err toward telling the user.
|
|
guard let startedAt else { return true }
|
|
return endedAt.timeIntervalSince(startedAt) >= minimumSeconds
|
|
}
|
|
|
|
public static func startFilePath(directory: String) -> String {
|
|
(directory as NSString).appendingPathComponent("turn-start")
|
|
}
|
|
|
|
public static func recordStart(at date: Date, directory: String) throws {
|
|
try FileManager.default.createDirectory(atPath: directory, withIntermediateDirectories: true)
|
|
let text = String(date.timeIntervalSince1970)
|
|
try text.write(toFile: startFilePath(directory: directory), atomically: true, encoding: .utf8)
|
|
}
|
|
|
|
/// Returns nil when no start was recorded or the file is unreadable, never throws, so a damaged
|
|
/// file cannot stop a notification.
|
|
public static func readStart(directory: String) -> Date? {
|
|
guard let text = try? String(contentsOfFile: startFilePath(directory: directory), encoding: .utf8),
|
|
let seconds = TimeInterval(text.trimmingCharacters(in: .whitespacesAndNewlines)) else { return nil }
|
|
return Date(timeIntervalSince1970: seconds)
|
|
}
|
|
}
|