@lattices/cli 0.4.14 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +5 -7
  2. package/apps/mac/Info.plist +4 -4
  3. package/apps/mac/Lattices.app/Contents/Info.plist +4 -12
  4. package/apps/mac/Lattices.app/Contents/MacOS/Lattices +0 -0
  5. package/bin/lattices-app.ts +110 -17
  6. package/bin/lattices-build +125 -0
  7. package/bin/lattices-dev +89 -16
  8. package/bin/lattices.ts +977 -16
  9. package/docs/agents.md +81 -4
  10. package/docs/ai-chat-ux-review.md +416 -0
  11. package/docs/api.md +135 -3
  12. package/docs/app.md +30 -8
  13. package/docs/config.md +4 -0
  14. package/docs/mouse-gestures.md +60 -1
  15. package/docs/proposals/LAT-004-interactive-overlay-actors.md +1 -1
  16. package/docs/proposals/LAT-005-action-runtime-product-spine.md +914 -0
  17. package/docs/proposals/LAT-006-mira-in-lattices.md +553 -0
  18. package/docs/proposals/LAT-007-unified-app-shell.md +128 -0
  19. package/docs/reference/dewey.config.ts +2 -2
  20. package/docs/release.md +171 -0
  21. package/docs/repo-structure.md +5 -5
  22. package/docs/voice.md +11 -27
  23. package/package.json +11 -10
  24. package/apps/mac/Package.swift +0 -27
  25. package/apps/mac/Sources/AppShell/App.swift +0 -26
  26. package/apps/mac/Sources/AppShell/AppActivationCoordinator.swift +0 -27
  27. package/apps/mac/Sources/AppShell/AppDelegate.swift +0 -189
  28. package/apps/mac/Sources/AppShell/AppServicesBootstrap.swift +0 -25
  29. package/apps/mac/Sources/AppShell/AppShellView.swift +0 -171
  30. package/apps/mac/Sources/AppShell/AppUpdater.swift +0 -305
  31. package/apps/mac/Sources/AppShell/CliActionLauncher.swift +0 -50
  32. package/apps/mac/Sources/AppShell/HomeDashboardView.swift +0 -133
  33. package/apps/mac/Sources/AppShell/HotkeyBootstrap.swift +0 -87
  34. package/apps/mac/Sources/AppShell/KeyRecorderView.swift +0 -210
  35. package/apps/mac/Sources/AppShell/LatticesRuntime.swift +0 -104
  36. package/apps/mac/Sources/AppShell/MainView.swift +0 -847
  37. package/apps/mac/Sources/AppShell/MainWindow.swift +0 -83
  38. package/apps/mac/Sources/AppShell/MenuBarController.swift +0 -177
  39. package/apps/mac/Sources/AppShell/OnboardingView.swift +0 -483
  40. package/apps/mac/Sources/AppShell/PermissionsAssistantView.swift +0 -366
  41. package/apps/mac/Sources/AppShell/PermissionsAssistantWindow.swift +0 -70
  42. package/apps/mac/Sources/AppShell/Preferences.swift +0 -297
  43. package/apps/mac/Sources/AppShell/SettingsView.swift +0 -3163
  44. package/apps/mac/Sources/AppShell/SettingsWindow.swift +0 -34
  45. package/apps/mac/Sources/AppShell/WorkspaceInspectorPresenter.swift +0 -13
  46. package/apps/mac/Sources/Core/Actions/HotkeyManager.swift +0 -256
  47. package/apps/mac/Sources/Core/Actions/HotkeyStore.swift +0 -399
  48. package/apps/mac/Sources/Core/Actions/IntentEngine.swift +0 -988
  49. package/apps/mac/Sources/Core/Actions/IntentSchema.swift +0 -94
  50. package/apps/mac/Sources/Core/Actions/Intents/CreateLayerIntent.swift +0 -54
  51. package/apps/mac/Sources/Core/Actions/Intents/DistributeIntent.swift +0 -56
  52. package/apps/mac/Sources/Core/Actions/Intents/FocusIntent.swift +0 -69
  53. package/apps/mac/Sources/Core/Actions/Intents/HelpIntent.swift +0 -41
  54. package/apps/mac/Sources/Core/Actions/Intents/KillIntent.swift +0 -47
  55. package/apps/mac/Sources/Core/Actions/Intents/LatticeIntent.swift +0 -53
  56. package/apps/mac/Sources/Core/Actions/Intents/LaunchIntent.swift +0 -67
  57. package/apps/mac/Sources/Core/Actions/Intents/ListSessionsIntent.swift +0 -32
  58. package/apps/mac/Sources/Core/Actions/Intents/ListWindowsIntent.swift +0 -30
  59. package/apps/mac/Sources/Core/Actions/Intents/ScanIntent.swift +0 -52
  60. package/apps/mac/Sources/Core/Actions/Intents/SearchIntent.swift +0 -190
  61. package/apps/mac/Sources/Core/Actions/Intents/SwitchLayerIntent.swift +0 -50
  62. package/apps/mac/Sources/Core/Actions/Intents/TileIntent.swift +0 -61
  63. package/apps/mac/Sources/Core/Actions/PaletteCommand.swift +0 -439
  64. package/apps/mac/Sources/Core/Actions/VoiceIntentResolver.swift +0 -713
  65. package/apps/mac/Sources/Core/Companion/CompanionActivityLog.swift +0 -70
  66. package/apps/mac/Sources/Core/Companion/CompanionKeyboardController.swift +0 -141
  67. package/apps/mac/Sources/Core/Companion/LatticesCompanionBridgeServer.swift +0 -454
  68. package/apps/mac/Sources/Core/Companion/LatticesCompanionCockpit.swift +0 -555
  69. package/apps/mac/Sources/Core/Companion/LatticesCompanionSecurityCoordinator.swift +0 -629
  70. package/apps/mac/Sources/Core/Companion/LatticesCompanionTrackpadController.swift +0 -204
  71. package/apps/mac/Sources/Core/Companion/LatticesDeckHost.swift +0 -1463
  72. package/apps/mac/Sources/Core/Daemon/DaemonProtocol.swift +0 -114
  73. package/apps/mac/Sources/Core/Daemon/DaemonServer.swift +0 -427
  74. package/apps/mac/Sources/Core/Daemon/LatticesApi.swift +0 -2965
  75. package/apps/mac/Sources/Core/Desktop/AccessibilityTextExtractor.swift +0 -111
  76. package/apps/mac/Sources/Core/Desktop/AppTypeClassifier.swift +0 -106
  77. package/apps/mac/Sources/Core/Desktop/DesktopModel.swift +0 -331
  78. package/apps/mac/Sources/Core/Desktop/DesktopModelTypes.swift +0 -73
  79. package/apps/mac/Sources/Core/Desktop/InventoryManager.swift +0 -35
  80. package/apps/mac/Sources/Core/Desktop/InventoryPath.swift +0 -43
  81. package/apps/mac/Sources/Core/Desktop/MouseFinder.swift +0 -527
  82. package/apps/mac/Sources/Core/Desktop/OcrModel.swift +0 -467
  83. package/apps/mac/Sources/Core/Desktop/OcrStore.swift +0 -329
  84. package/apps/mac/Sources/Core/Desktop/PlacementSpec.swift +0 -195
  85. package/apps/mac/Sources/Core/Desktop/SessionWindowLocator.swift +0 -139
  86. package/apps/mac/Sources/Core/Desktop/TilePickerView.swift +0 -209
  87. package/apps/mac/Sources/Core/Desktop/WindowCapture.swift +0 -33
  88. package/apps/mac/Sources/Core/Desktop/WindowDragSnapController.swift +0 -429
  89. package/apps/mac/Sources/Core/Desktop/WindowPreviewCard.swift +0 -100
  90. package/apps/mac/Sources/Core/Desktop/WindowPreviewStore.swift +0 -112
  91. package/apps/mac/Sources/Core/Desktop/WindowSelectionStore.swift +0 -76
  92. package/apps/mac/Sources/Core/Desktop/WindowTiler.swift +0 -2222
  93. package/apps/mac/Sources/Core/Input/EventTapBreaker.swift +0 -124
  94. package/apps/mac/Sources/Core/Input/EventTapThread.swift +0 -54
  95. package/apps/mac/Sources/Core/Input/InputCaptureResetCenter.swift +0 -20
  96. package/apps/mac/Sources/Core/Input/KeyboardRemapConfig.swift +0 -69
  97. package/apps/mac/Sources/Core/Input/KeyboardRemapController.swift +0 -346
  98. package/apps/mac/Sources/Core/Input/KeyboardRemapStore.swift +0 -141
  99. package/apps/mac/Sources/Core/Input/MouseGestureConfig.swift +0 -499
  100. package/apps/mac/Sources/Core/Input/MouseGestureController.swift +0 -2583
  101. package/apps/mac/Sources/Core/Input/MouseInputDeviceStore.swift +0 -98
  102. package/apps/mac/Sources/Core/Input/MouseInputEventViewer.swift +0 -272
  103. package/apps/mac/Sources/Core/Input/MouseShortcutStore.swift +0 -170
  104. package/apps/mac/Sources/Core/Input/SecureEventInputMonitor.swift +0 -39
  105. package/apps/mac/Sources/Core/Input/ShapeRecognizer.swift +0 -624
  106. package/apps/mac/Sources/Core/Input/TapBudgetMeter.swift +0 -56
  107. package/apps/mac/Sources/Core/Overlays/AppWindowShell.swift +0 -63
  108. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeState.swift +0 -1566
  109. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeView.swift +0 -1927
  110. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeWindow.swift +0 -196
  111. package/apps/mac/Sources/Core/Overlays/CommandPalette/CommandPaletteView.swift +0 -307
  112. package/apps/mac/Sources/Core/Overlays/CommandPalette/CommandPaletteWindow.swift +0 -67
  113. package/apps/mac/Sources/Core/Overlays/HUD/CheatSheetHUD.swift +0 -576
  114. package/apps/mac/Sources/Core/Overlays/HUD/HUDBottomBar.swift +0 -279
  115. package/apps/mac/Sources/Core/Overlays/HUD/HUDController.swift +0 -1158
  116. package/apps/mac/Sources/Core/Overlays/HUD/HUDLeftBar.swift +0 -849
  117. package/apps/mac/Sources/Core/Overlays/HUD/HUDMinimap.swift +0 -179
  118. package/apps/mac/Sources/Core/Overlays/HUD/HUDRightBar.swift +0 -596
  119. package/apps/mac/Sources/Core/Overlays/HUD/HUDState.swift +0 -367
  120. package/apps/mac/Sources/Core/Overlays/HUD/HUDTopBar.swift +0 -243
  121. package/apps/mac/Sources/Core/Overlays/HUD/LauncherHUD.swift +0 -334
  122. package/apps/mac/Sources/Core/Overlays/HUD/LayerBezel.swift +0 -203
  123. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchState.swift +0 -280
  124. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchView.swift +0 -422
  125. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchWindow.swift +0 -94
  126. package/apps/mac/Sources/Core/Overlays/OverlayPanelShell.swift +0 -241
  127. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapState.swift +0 -3135
  128. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapView.swift +0 -3977
  129. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapWindowController.swift +0 -119
  130. package/apps/mac/Sources/Core/Overlays/ScreenOverlayCanvasController.swift +0 -1217
  131. package/apps/mac/Sources/Core/Overlays/Voice/VoiceCommandWindow.swift +0 -1575
  132. package/apps/mac/Sources/Core/Pi/PiAuthNextStepCard.swift +0 -148
  133. package/apps/mac/Sources/Core/Pi/PiAuthPromptCard.swift +0 -90
  134. package/apps/mac/Sources/Core/Pi/PiChatDock.swift +0 -564
  135. package/apps/mac/Sources/Core/Pi/PiChatSession.swift +0 -1948
  136. package/apps/mac/Sources/Core/Pi/PiInstallCallout.swift +0 -86
  137. package/apps/mac/Sources/Core/Pi/PiProviderSetupCallout.swift +0 -99
  138. package/apps/mac/Sources/Core/Pi/PiWorkspaceView.swift +0 -510
  139. package/apps/mac/Sources/Core/System/Capability.swift +0 -79
  140. package/apps/mac/Sources/Core/System/DiagnosticLog.swift +0 -373
  141. package/apps/mac/Sources/Core/System/EventBus.swift +0 -31
  142. package/apps/mac/Sources/Core/System/PermissionChecker.swift +0 -224
  143. package/apps/mac/Sources/Core/System/ProcessModel.swift +0 -199
  144. package/apps/mac/Sources/Core/System/ProcessQuery.swift +0 -151
  145. package/apps/mac/Sources/Core/System/SystemTelemetryMonitor.swift +0 -273
  146. package/apps/mac/Sources/Core/Voice/AdvisorLearningStore.swift +0 -90
  147. package/apps/mac/Sources/Core/Voice/AgentSession.swift +0 -377
  148. package/apps/mac/Sources/Core/Voice/AudioProvider.swift +0 -555
  149. package/apps/mac/Sources/Core/Voice/HandsOffSession.swift +0 -839
  150. package/apps/mac/Sources/Core/Voice/VoiceChatView.swift +0 -192
  151. package/apps/mac/Sources/Core/Voice/VoxClient.swift +0 -454
  152. package/apps/mac/Sources/Core/Workspace/Project.swift +0 -28
  153. package/apps/mac/Sources/Core/Workspace/ProjectScanner.swift +0 -141
  154. package/apps/mac/Sources/Core/Workspace/SessionLayerStore.swift +0 -285
  155. package/apps/mac/Sources/Core/Workspace/SessionManager.swift +0 -75
  156. package/apps/mac/Sources/Core/Workspace/Terminal/Terminal.swift +0 -259
  157. package/apps/mac/Sources/Core/Workspace/Terminal/TerminalQuery.swift +0 -156
  158. package/apps/mac/Sources/Core/Workspace/Terminal/TerminalSynthesizer.swift +0 -200
  159. package/apps/mac/Sources/Core/Workspace/Tmux/TmuxModel.swift +0 -60
  160. package/apps/mac/Sources/Core/Workspace/Tmux/TmuxQuery.swift +0 -105
  161. package/apps/mac/Sources/Core/Workspace/WorkspaceManager.swift +0 -1027
  162. package/apps/mac/Sources/UI/ActionRow.swift +0 -78
  163. package/apps/mac/Sources/UI/OrphanRow.swift +0 -129
  164. package/apps/mac/Sources/UI/ProjectRow.swift +0 -368
  165. package/apps/mac/Sources/UI/TabGroupRow.swift +0 -178
  166. package/apps/mac/Sources/UI/Theme.swift +0 -164
  167. package/apps/mac/Tests/StageDragTests.swift +0 -333
  168. package/apps/mac/Tests/StageJoinTests.swift +0 -313
  169. package/apps/mac/Tests/StageManagerTests.swift +0 -280
  170. package/apps/mac/Tests/StageTileTests.swift +0 -353
  171. package/swift/Package.swift +0 -20
  172. package/swift/Sources/DeckKit/DeckAction.swift +0 -51
  173. package/swift/Sources/DeckKit/DeckBridgeSecurity.swift +0 -152
  174. package/swift/Sources/DeckKit/DeckCockpit.swift +0 -82
  175. package/swift/Sources/DeckKit/DeckHost.swift +0 -7
  176. package/swift/Sources/DeckKit/DeckManifest.swift +0 -145
  177. package/swift/Sources/DeckKit/DeckRuntimeSnapshot.swift +0 -533
  178. package/swift/Sources/DeckKit/DeckTrackpad.swift +0 -63
  179. package/swift/Sources/DeckKit/DeckValue.swift +0 -93
  180. package/swift/Sources/DeckKit/DeckVoiceError.swift +0 -88
  181. package/swift/Tests/DeckKitTests/DeckKitTests.swift +0 -286
@@ -1,98 +0,0 @@
1
- import Foundation
2
- import IOKit.hid
3
-
4
- struct MouseInputDeviceInfo: Identifiable, Equatable {
5
- var id: String
6
- var vendorId: Int?
7
- var productId: Int?
8
- var locationId: Int?
9
- var product: String?
10
- var manufacturer: String?
11
- var transport: String?
12
-
13
- var summary: String {
14
- var parts: [String] = []
15
- if let product, !product.isEmpty {
16
- parts.append(product)
17
- }
18
- if let manufacturer, !manufacturer.isEmpty, parts.isEmpty {
19
- parts.append(manufacturer)
20
- }
21
- if let vendorId { parts.append("vid:\(vendorId)") }
22
- if let productId { parts.append("pid:\(productId)") }
23
- if let locationId { parts.append("loc:\(locationId)") }
24
- if let transport, !transport.isEmpty { parts.append(transport) }
25
- return parts.isEmpty ? "Unknown pointer device" : parts.joined(separator: " | ")
26
- }
27
- }
28
-
29
- final class MouseInputDeviceStore: ObservableObject {
30
- static let shared = MouseInputDeviceStore()
31
-
32
- @Published private(set) var devices: [MouseInputDeviceInfo] = []
33
-
34
- private init() {
35
- refresh()
36
- }
37
-
38
- func refresh() {
39
- let manager = IOHIDManagerCreate(kCFAllocatorDefault, IOOptionBits(kIOHIDOptionsTypeNone))
40
- let matches: [[String: Any]] = [
41
- [
42
- kIOHIDDeviceUsagePageKey as String: kHIDPage_GenericDesktop,
43
- kIOHIDDeviceUsageKey as String: kHIDUsage_GD_Mouse,
44
- ],
45
- [
46
- kIOHIDDeviceUsagePageKey as String: kHIDPage_GenericDesktop,
47
- kIOHIDDeviceUsageKey as String: kHIDUsage_GD_Pointer,
48
- ],
49
- ]
50
- IOHIDManagerSetDeviceMatchingMultiple(manager, matches as CFArray)
51
- IOHIDManagerOpen(manager, IOOptionBits(kIOHIDOptionsTypeNone))
52
-
53
- let resolved: [MouseInputDeviceInfo]
54
- if let rawDevices = IOHIDManagerCopyDevices(manager) as? Set<IOHIDDevice> {
55
- resolved = rawDevices.compactMap(Self.deviceInfo(for:))
56
- .sorted { $0.summary.localizedCaseInsensitiveCompare($1.summary) == .orderedAscending }
57
- } else {
58
- resolved = []
59
- }
60
-
61
- DispatchQueue.main.async {
62
- self.devices = resolved
63
- }
64
- }
65
-
66
- private static func deviceInfo(for device: IOHIDDevice) -> MouseInputDeviceInfo? {
67
- let vendorId = integerProperty(kIOHIDVendorIDKey as CFString, from: device)
68
- let productId = integerProperty(kIOHIDProductIDKey as CFString, from: device)
69
- let locationId = integerProperty(kIOHIDLocationIDKey as CFString, from: device)
70
- let product = stringProperty(kIOHIDProductKey as CFString, from: device)
71
- let manufacturer = stringProperty(kIOHIDManufacturerKey as CFString, from: device)
72
- let transport = stringProperty(kIOHIDTransportKey as CFString, from: device)
73
-
74
- let vendorToken = vendorId.map(String.init) ?? "vid"
75
- let productToken = productId.map(String.init) ?? "pid"
76
- let locationToken = locationId.map(String.init) ?? "loc"
77
- let id = [product ?? "mouse", vendorToken, productToken, locationToken].joined(separator: ":")
78
-
79
- return MouseInputDeviceInfo(
80
- id: id,
81
- vendorId: vendorId,
82
- productId: productId,
83
- locationId: locationId,
84
- product: product,
85
- manufacturer: manufacturer,
86
- transport: transport
87
- )
88
- }
89
-
90
- private static func integerProperty(_ key: CFString, from device: IOHIDDevice) -> Int? {
91
- guard let value = IOHIDDeviceGetProperty(device, key) else { return nil }
92
- return (value as? NSNumber)?.intValue
93
- }
94
-
95
- private static func stringProperty(_ key: CFString, from device: IOHIDDevice) -> String? {
96
- IOHIDDeviceGetProperty(device, key) as? String
97
- }
98
- }
@@ -1,272 +0,0 @@
1
- import AppKit
2
- import SwiftUI
3
-
4
- final class MouseInputEventViewer: ObservableObject {
5
- static let shared = MouseInputEventViewer()
6
-
7
- struct Entry: Identifiable {
8
- let id = UUID()
9
- let timestamp: Date
10
- let phase: String
11
- let appName: String
12
- let bundleId: String
13
- let buttonNumber: Int
14
- let triggerCandidate: String
15
- let deltaText: String
16
- let modifiersText: String
17
- let deviceText: String
18
- let matchText: String
19
- let note: String
20
- }
21
-
22
- @Published private(set) var entries: [Entry] = []
23
- @Published private(set) var isCaptureActive = false
24
-
25
- private let maxEntries = 120
26
- private var window: NSWindow?
27
- private var closeObserver: Any?
28
-
29
- private init() {}
30
-
31
- func show() {
32
- if let window {
33
- isCaptureActive = true
34
- window.makeKeyAndOrderFront(nil)
35
- NSApp.activate(ignoringOtherApps: true)
36
- return
37
- }
38
-
39
- let view = MouseInputEventViewerView()
40
- let window = AppWindowShell.makeWindow(
41
- config: .init(
42
- title: "Mouse Shortcut Event Viewer",
43
- initialSize: NSSize(width: 980, height: 620),
44
- minSize: NSSize(width: 840, height: 460),
45
- maxSize: NSSize(width: 1500, height: 1000)
46
- ),
47
- rootView: view
48
- )
49
- AppWindowShell.positionCentered(window)
50
- AppWindowShell.present(window)
51
-
52
- closeObserver = NotificationCenter.default.addObserver(
53
- forName: NSWindow.willCloseNotification,
54
- object: window,
55
- queue: .main
56
- ) { [weak self] _ in
57
- self?.teardownWindow()
58
- }
59
-
60
- self.window = window
61
- isCaptureActive = true
62
- DiagnosticLog.shared.info("Mouse shortcuts event viewer opened")
63
- }
64
-
65
- func dismiss() {
66
- window?.close()
67
- teardownWindow()
68
- }
69
-
70
- func clear() {
71
- entries.removeAll()
72
- }
73
-
74
- func record(_ observedEvent: MouseShortcutObservedEvent) {
75
- let entry = Entry(
76
- timestamp: observedEvent.timestamp,
77
- phase: observedEvent.phase,
78
- appName: observedEvent.frontmostAppName ?? "Unknown App",
79
- bundleId: observedEvent.frontmostBundleId ?? "unknown.bundle",
80
- buttonNumber: observedEvent.buttonNumber,
81
- triggerCandidate: observedEvent.candidateTrigger ?? "--",
82
- deltaText: "\(Int(observedEvent.delta.x)), \(Int(observedEvent.delta.y))",
83
- modifiersText: Self.modifierLabels(for: observedEvent.modifiers).joined(separator: "+").ifEmpty("--"),
84
- deviceText: observedEvent.device?.summary ?? "Unresolved device",
85
- matchText: observedEvent.matchedRuleSummary ?? (observedEvent.willFire ? "Would fire" : "No match"),
86
- note: observedEvent.note ?? ""
87
- )
88
-
89
- DispatchQueue.main.async {
90
- self.entries.append(entry)
91
- if self.entries.count > self.maxEntries {
92
- self.entries.removeFirst(self.entries.count - self.maxEntries)
93
- }
94
- }
95
- }
96
-
97
- private func teardownWindow() {
98
- if let closeObserver {
99
- NotificationCenter.default.removeObserver(closeObserver)
100
- self.closeObserver = nil
101
- }
102
- window = nil
103
- isCaptureActive = false
104
- }
105
-
106
- private static func modifierLabels(for flags: NSEvent.ModifierFlags) -> [String] {
107
- var labels: [String] = []
108
- if flags.contains(.control) { labels.append("Ctrl") }
109
- if flags.contains(.option) { labels.append("Option") }
110
- if flags.contains(.shift) { labels.append("Shift") }
111
- if flags.contains(.command) { labels.append("Cmd") }
112
- return labels
113
- }
114
- }
115
-
116
- private struct MouseInputEventViewerView: View {
117
- @ObservedObject private var viewer = MouseInputEventViewer.shared
118
- @ObservedObject private var devices = MouseInputDeviceStore.shared
119
-
120
- private static let timestampFormatter: DateFormatter = {
121
- let formatter = DateFormatter()
122
- formatter.dateFormat = "HH:mm:ss.SSS"
123
- return formatter
124
- }()
125
-
126
- var body: some View {
127
- VStack(spacing: 0) {
128
- header
129
- Divider()
130
- .overlay(Color.white.opacity(0.08))
131
- ScrollView {
132
- LazyVStack(alignment: .leading, spacing: 8) {
133
- if devices.devices.isEmpty {
134
- deviceStrip(text: "Devices: none detected")
135
- } else {
136
- deviceStrip(text: "Devices: " + devices.devices.map(\.summary).joined(separator: " | "))
137
- }
138
-
139
- ForEach(viewer.entries) { entry in
140
- entryRow(entry)
141
- }
142
- }
143
- .padding(14)
144
- }
145
- .background(Color.black.opacity(0.16))
146
- }
147
- }
148
-
149
- private var header: some View {
150
- HStack(spacing: 12) {
151
- VStack(alignment: .leading, spacing: 4) {
152
- Text("Mouse Shortcut Event Viewer")
153
- .font(.system(size: 14, weight: .semibold, design: .monospaced))
154
- .foregroundColor(.white.opacity(0.95))
155
- Text("Watching extra mouse buttons and drag candidates for configurable shortcuts.")
156
- .font(.system(size: 11))
157
- .foregroundColor(.white.opacity(0.6))
158
- }
159
-
160
- Spacer()
161
-
162
- Button("Copy") {
163
- let text = viewer.entries.map { entry in
164
- [
165
- Self.timestampFormatter.string(from: entry.timestamp),
166
- entry.phase,
167
- entry.appName,
168
- entry.bundleId,
169
- "button=\(entry.buttonNumber)",
170
- "candidate=\(entry.triggerCandidate)",
171
- "delta=\(entry.deltaText)",
172
- "mods=\(entry.modifiersText)",
173
- "device=\(entry.deviceText)",
174
- "match=\(entry.matchText)",
175
- entry.note,
176
- ].filter { !$0.isEmpty }.joined(separator: " | ")
177
- }.joined(separator: "\n")
178
- NSPasteboard.general.clearContents()
179
- NSPasteboard.general.setString(text, forType: .string)
180
- }
181
- .buttonStyle(.plain)
182
- .foregroundColor(.white.opacity(0.72))
183
-
184
- Button("Clear") {
185
- viewer.clear()
186
- }
187
- .buttonStyle(.plain)
188
- .foregroundColor(.white.opacity(0.72))
189
- }
190
- .padding(.horizontal, 16)
191
- .padding(.vertical, 12)
192
- .background(Color.white.opacity(0.04))
193
- }
194
-
195
- private func deviceStrip(text: String) -> some View {
196
- Text(text)
197
- .font(.system(size: 10, weight: .medium, design: .monospaced))
198
- .foregroundColor(.white.opacity(0.6))
199
- .padding(.horizontal, 10)
200
- .padding(.vertical, 8)
201
- .frame(maxWidth: .infinity, alignment: .leading)
202
- .background(
203
- RoundedRectangle(cornerRadius: 10)
204
- .fill(Color.white.opacity(0.04))
205
- )
206
- }
207
-
208
- private func entryRow(_ entry: MouseInputEventViewer.Entry) -> some View {
209
- VStack(alignment: .leading, spacing: 6) {
210
- HStack(alignment: .firstTextBaseline, spacing: 10) {
211
- Text(Self.timestampFormatter.string(from: entry.timestamp))
212
- .font(.system(size: 11, weight: .medium, design: .monospaced))
213
- .foregroundColor(.white.opacity(0.82))
214
-
215
- Text(entry.phase.uppercased())
216
- .font(.system(size: 10, weight: .bold, design: .monospaced))
217
- .foregroundColor(Color(red: 0.62, green: 0.84, blue: 1.0))
218
-
219
- Text(entry.triggerCandidate)
220
- .font(.system(size: 11, weight: .semibold, design: .monospaced))
221
- .foregroundColor(.white.opacity(0.94))
222
-
223
- Spacer()
224
-
225
- Text(entry.matchText)
226
- .font(.system(size: 10, weight: .medium, design: .monospaced))
227
- .foregroundColor(.white.opacity(0.68))
228
- }
229
-
230
- HStack(spacing: 14) {
231
- metadataPill("App", "\(entry.appName) (\(entry.bundleId))")
232
- metadataPill("Button", "\(entry.buttonNumber)")
233
- metadataPill("Delta", entry.deltaText)
234
- metadataPill("Mods", entry.modifiersText)
235
- }
236
-
237
- HStack(spacing: 14) {
238
- metadataPill("Device", entry.deviceText)
239
- if !entry.note.isEmpty {
240
- metadataPill("Note", entry.note)
241
- }
242
- }
243
- }
244
- .padding(12)
245
- .frame(maxWidth: .infinity, alignment: .leading)
246
- .background(
247
- RoundedRectangle(cornerRadius: 12)
248
- .fill(Color.white.opacity(0.04))
249
- .overlay(
250
- RoundedRectangle(cornerRadius: 12)
251
- .stroke(Color.white.opacity(0.06), lineWidth: 0.5)
252
- )
253
- )
254
- }
255
-
256
- private func metadataPill(_ label: String, _ value: String) -> some View {
257
- HStack(spacing: 6) {
258
- Text(label.uppercased())
259
- .font(.system(size: 9, weight: .bold, design: .monospaced))
260
- .foregroundColor(.white.opacity(0.42))
261
- Text(value)
262
- .font(.system(size: 10, weight: .medium, design: .monospaced))
263
- .foregroundColor(.white.opacity(0.82))
264
- }
265
- }
266
- }
267
-
268
- private extension String {
269
- func ifEmpty(_ replacement: String) -> String {
270
- isEmpty ? replacement : self
271
- }
272
- }
@@ -1,170 +0,0 @@
1
- import AppKit
2
- import Combine
3
- import Foundation
4
-
5
- final class MouseShortcutStore: ObservableObject {
6
- static let shared = MouseShortcutStore()
7
-
8
- /// Drives SwiftUI bindings; mutations always happen on main.
9
- @Published private(set) var config: MouseShortcutConfig
10
-
11
- let configURL: URL
12
-
13
- /// Lock-protected mirror of `config` for tap-thread reads. The mouse event
14
- /// tap fires on a non-main thread (EventTapThread) and reads
15
- /// `watchedButtonNumbers` to compute the consume-vs-pass verdict; mutating
16
- /// `config` (a struct) on main while reading from the tap thread is a
17
- /// torn-read race. All tap-thread accessors read this snapshot under
18
- /// `stateLock`.
19
- private let stateLock = NSLock()
20
- private var snapshot: MouseShortcutConfig
21
- private var lastLoadedModifiedDate: Date?
22
-
23
- private init() {
24
- let dir = FileManager.default.homeDirectoryForCurrentUser
25
- .appendingPathComponent(".lattices")
26
- try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
27
- self.configURL = dir.appendingPathComponent("mouse-shortcuts.json")
28
- self.config = .defaults
29
- self.snapshot = .defaults
30
- ensureConfigFile()
31
- reload()
32
- }
33
-
34
- var tuning: MouseShortcutTuning {
35
- stateLock.lock(); defer { stateLock.unlock() }
36
- return snapshot.tuning
37
- }
38
-
39
- var enabledRules: [MouseShortcutRule] {
40
- stateLock.lock(); defer { stateLock.unlock() }
41
- return snapshot.rules.filter(\.enabled)
42
- }
43
-
44
- var watchedButtonNumbers: Set<Int64> {
45
- stateLock.lock(); defer { stateLock.unlock() }
46
- return Set(snapshot.rules.filter(\.enabled).map { Int64($0.trigger.button.rawButtonNumber) })
47
- }
48
-
49
- func hasEnabledRule(button: MouseShortcutButton, kind: MouseShortcutTriggerKind) -> Bool {
50
- stateLock.lock(); defer { stateLock.unlock() }
51
- return snapshot.rules.contains { rule in
52
- rule.enabled
53
- && rule.trigger.button == button
54
- && rule.trigger.kind == kind
55
- }
56
- }
57
-
58
- var summaryLines: [String] {
59
- stateLock.lock(); defer { stateLock.unlock() }
60
- return snapshot.rules.filter(\.enabled).map { "\($0.trigger.triggerName) -> \($0.action.type.rawValue)" }
61
- }
62
-
63
- func visualHint(for button: MouseShortcutButton) -> MouseShortcutVisualDefinition? {
64
- stateLock.lock(); defer { stateLock.unlock() }
65
- return snapshot.rules.filter(\.enabled).first { $0.trigger.button == button && $0.visual != nil }?.visual
66
- }
67
-
68
- func ensureConfigFile() {
69
- guard !FileManager.default.fileExists(atPath: configURL.path) else { return }
70
- write(config: .defaults)
71
- }
72
-
73
- func reload() {
74
- let newDate = modifiedDate()
75
- let newConfig: MouseShortcutConfig
76
- if let data = FileManager.default.contents(atPath: configURL.path) {
77
- do {
78
- newConfig = try JSONDecoder().decode(MouseShortcutConfig.self, from: data)
79
- } catch {
80
- DiagnosticLog.shared.error("MouseShortcutStore: failed to decode mouse-shortcuts.json - \(error.localizedDescription)")
81
- newConfig = .defaults
82
- }
83
- } else {
84
- newConfig = .defaults
85
- }
86
- stateLock.lock()
87
- snapshot = newConfig
88
- lastLoadedModifiedDate = newDate
89
- stateLock.unlock()
90
- // @Published mutation must happen on main.
91
- if Thread.isMainThread {
92
- config = newConfig
93
- } else {
94
- DispatchQueue.main.async { [weak self] in
95
- self?.config = newConfig
96
- }
97
- }
98
- }
99
-
100
- func reloadIfNeeded() {
101
- // Called from the mouse event-tap thread (and from main paths). The
102
- // stat is cheap and thread-safe; we claim the new mtime up-front so
103
- // concurrent calls don't queue duplicate reloads while one is in
104
- // flight (if reload fails to decode, we'll retry on the next mtime
105
- // change).
106
- let currentModifiedDate = modifiedDate()
107
- stateLock.lock()
108
- let needsReload = currentModifiedDate != lastLoadedModifiedDate
109
- if needsReload {
110
- lastLoadedModifiedDate = currentModifiedDate
111
- }
112
- stateLock.unlock()
113
- guard needsReload else { return }
114
- reload()
115
- }
116
-
117
- func restoreDefaults() {
118
- write(config: .defaults)
119
- reload()
120
- DiagnosticLog.shared.info("Mouse shortcuts restored to defaults")
121
- }
122
-
123
- func openConfiguration() {
124
- ensureConfigFile()
125
- NSWorkspace.shared.open(configURL)
126
- }
127
-
128
- func match(for event: MouseShortcutTriggerEvent) -> MouseShortcutMatchResult? {
129
- stateLock.lock()
130
- let rules = snapshot.rules.filter(\.enabled)
131
- stateLock.unlock()
132
- for rule in rules {
133
- guard rule.trigger.kind == event.kind,
134
- rule.trigger.button == event.button,
135
- rule.device.matches(event.device) else {
136
- continue
137
- }
138
- switch event.kind {
139
- case .drag:
140
- guard rule.trigger.direction == event.direction else { continue }
141
- case .shape:
142
- guard rule.trigger.shape == event.shape else { continue }
143
- case .click:
144
- break
145
- }
146
-
147
- return MouseShortcutMatchResult(
148
- rule: rule,
149
- action: rule.action,
150
- triggerName: rule.trigger.triggerName
151
- )
152
- }
153
-
154
- return nil
155
- }
156
-
157
- private func write(config: MouseShortcutConfig) {
158
- let encoder = JSONEncoder()
159
- encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
160
- guard let data = try? encoder.encode(config) else { return }
161
- try? data.write(to: configURL, options: .atomic)
162
- let newDate = modifiedDate()
163
- stateLock.lock(); lastLoadedModifiedDate = newDate; stateLock.unlock()
164
- }
165
-
166
- private func modifiedDate() -> Date? {
167
- let attrs = try? FileManager.default.attributesOfItem(atPath: configURL.path)
168
- return attrs?[.modificationDate] as? Date
169
- }
170
- }
@@ -1,39 +0,0 @@
1
- import Carbon
2
- import Foundation
3
-
4
- final class SecureEventInputMonitor {
5
- static let shared = SecureEventInputMonitor()
6
-
7
- private var timer: Timer?
8
- private var lastEnabled = IsSecureEventInputEnabled()
9
-
10
- private init() {}
11
-
12
- func start() {
13
- dispatchPrecondition(condition: .onQueue(.main))
14
- guard timer == nil else { return }
15
-
16
- lastEnabled = IsSecureEventInputEnabled()
17
- let timer = Timer(timeInterval: 0.25, repeats: true) { [weak self] _ in
18
- self?.poll()
19
- }
20
- self.timer = timer
21
- RunLoop.main.add(timer, forMode: .common)
22
- }
23
-
24
- func stop() {
25
- dispatchPrecondition(condition: .onQueue(.main))
26
- timer?.invalidate()
27
- timer = nil
28
- }
29
-
30
- private func poll() {
31
- let enabled = IsSecureEventInputEnabled()
32
- guard enabled != lastEnabled else { return }
33
-
34
- lastEnabled = enabled
35
- let reason = enabled ? "Secure Event Input enabled" : "Secure Event Input disabled"
36
- DiagnosticLog.shared.warn("InputCapture: \(reason)")
37
- InputCaptureResetCenter.reset(reason: reason)
38
- }
39
- }