Add luxe Notifier: macOS menu bar app that tells you when luxe needs you

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.
This commit is contained in:
2026-10-24 22:41:42 -04:00
commit ced6a44ed0
30 changed files with 1314 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
import Foundation
import NotifierCore
// A hook must never block or fail luxe: always exit 0, print nothing on stdout, report on stderr.
func warn(_ message: String) {
FileHandle.standardError.write(Data("luxe-notify: \(message)\n".utf8))
}
struct Options {
var hookPoint = ""
var socketPath = NotifySocket.defaultPath()
var minimumSeconds = TurnTimer.defaultMinimumSeconds
/// Flags may appear anywhere; the first bare word is the hook point.
static func parse(_ arguments: [String]) -> Options? {
var options = Options()
var index = 0
var sawHookPoint = false
while index < arguments.count {
let argument = arguments[index]
switch argument {
case "--min-seconds":
guard index + 1 < arguments.count, let value = TimeInterval(arguments[index + 1]) else {
warn("--min-seconds needs a number")
return nil
}
options.minimumSeconds = value
index += 1
case "--socket":
guard index + 1 < arguments.count else { warn("--socket needs a path"); return nil }
options.socketPath = arguments[index + 1]
index += 1
default:
if !sawHookPoint { options.hookPoint = argument; sawHookPoint = true }
}
index += 1
}
return sawHookPoint ? options : nil
}
}
func isTurnStart(_ hookPoint: String) -> Bool {
hookPoint.lowercased().replacingOccurrences(of: "_", with: "") == "beforeagentstart"
}
func isTurnEnd(_ hookPoint: String) -> Bool {
hookPoint.lowercased().replacingOccurrences(of: "_", with: "") == "agentend"
}
guard let options = Options.parse(Array(CommandLine.arguments.dropFirst())) else {
warn("usage: luxe-notify <HookPoint> [--min-seconds N] [--socket PATH] (event JSON on stdin)")
exit(0)
}
let input = FileHandle.standardInput.readDataToEndOfFile()
let appDirectory = (NotifySocket.defaultPath() as NSString).deletingLastPathComponent
do {
if isTurnStart(options.hookPoint) {
try TurnTimer.recordStart(at: Date(), directory: appDirectory)
exit(0)
}
if isTurnEnd(options.hookPoint) {
let started = TurnTimer.readStart(directory: appDirectory)
guard TurnTimer.shouldNotify(startedAt: started, endedAt: Date(), minimumSeconds: options.minimumSeconds) else { exit(0) }
}
var event = try HookEventParser.parse(input, hookPoint: options.hookPoint, cwd: FileManager.default.currentDirectoryPath)
event.terminalBundleID = TerminalLocator.bundleID(from: ProcessInfo.processInfo.environment)
try NotifyClient.send(event, to: options.socketPath)
} catch {
warn("\(error)")
}
exit(0)