import Foundation public enum CallbackEvent: String, CaseIterable, Codable, Sendable { case windowOpened = "exec-on-window-opened" case windowClosed = "exec-on-window-closed" case focusChanged = "exec-on-focus-changed" case layoutChanged = "exec-on-layout-changed" case spaceChanged = "exec-on-space-changed" } public enum CallbackConfigurationError: Error, Equatable, Sendable { case invalidArguments(CallbackEvent) } public struct CallbackConfiguration: Equatable, Sendable { public var commands: [CallbackEvent: [String]] public init(commands: [CallbackEvent: [String]] = [:]) { self.commands = commands } public func validate() throws { for (event, arguments) in commands { guard Self.valid(arguments) else { throw CallbackConfigurationError.invalidArguments(event) } } } static func valid(_ arguments: [String]) -> Bool { if arguments.isEmpty { return true } return arguments.count <= 64 && arguments[0].hasPrefix("/") && arguments.allSatisfy { $0.utf8.count <= 4096 && !$0.contains("\0") } && arguments.reduce(0) { $0 + $1.utf8.count } <= 16_384 } }