@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,43 +0,0 @@
1
- import AppKit
2
-
3
- struct InventoryPath: Equatable {
4
- let display: String
5
- let space: String
6
- let appType: String
7
- let appName: String
8
- let windowTitle: String
9
-
10
- var description: String {
11
- [display, space, appType, appName, windowTitle]
12
- .map { sanitize($0) }
13
- .joined(separator: ".")
14
- }
15
-
16
- func matches(pattern: String) -> Bool {
17
- let segments = description.split(separator: ".").map(String.init)
18
- let patternSegments = pattern.lowercased().split(separator: ".").map(String.init)
19
-
20
- for (i, pat) in patternSegments.enumerated() {
21
- guard i < segments.count else { return false }
22
- if pat == "*" { continue }
23
- if !segments[i].hasPrefix(pat) { return false }
24
- }
25
- return true
26
- }
27
-
28
- static func displayName(for screen: NSScreen, isMain: Bool) -> String {
29
- if isMain { return "main" }
30
- return sanitizeStatic(screen.localizedName)
31
- }
32
-
33
- private func sanitize(_ s: String) -> String {
34
- Self.sanitizeStatic(s)
35
- }
36
-
37
- private static func sanitizeStatic(_ s: String) -> String {
38
- s.lowercased()
39
- .replacingOccurrences(of: "[\\s./\\\\]+", with: "-", options: .regularExpression)
40
- .replacingOccurrences(of: "[^a-z0-9_-]", with: "", options: .regularExpression)
41
- .trimmingCharacters(in: CharacterSet(charactersIn: "-"))
42
- }
43
- }
@@ -1,527 +0,0 @@
1
- import AppKit
2
- import CoreGraphics
3
-
4
- private enum SpotlightConfig {
5
- static let overlayAlpha: CGFloat = 0.75
6
- static let dimAlpha: CGFloat = 0.85
7
- static let spotlightRadius: CGFloat = 200
8
- static let sonarDelay: TimeInterval = 1.0
9
- static let totalDuration: TimeInterval = 2.5
10
- static let fadeInDuration: TimeInterval = 0.15
11
- static let fadeOutDuration: TimeInterval = 0.4
12
- static let accentColor = NSColor(calibratedRed: 0.4, green: 0.7, blue: 1.0, alpha: 1.0)
13
- }
14
-
15
- private struct DotMatrixConfig {
16
- var dotRadius: CGFloat = 2.2
17
- var dotSpacing: CGFloat = 6.0
18
- var arrowCols: Int = 13
19
- var arrowRows: Int = 7 // must be odd
20
-
21
- static let shared: DotMatrixConfig = {
22
- let path = NSHomeDirectory() + "/.lattices/mouse-finder.json"
23
- guard FileManager.default.fileExists(atPath: path),
24
- let data = try? Data(contentsOf: URL(fileURLWithPath: path)),
25
- let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any]
26
- else { return DotMatrixConfig() }
27
-
28
- var config = DotMatrixConfig()
29
- if let v = json["dotRadius"] as? Double { config.dotRadius = CGFloat(v) }
30
- if let v = json["dotSpacing"] as? Double { config.dotSpacing = CGFloat(v) }
31
- if let v = json["arrowCols"] as? Int { config.arrowCols = max(3, v) }
32
- if let v = json["arrowRows"] as? Int { config.arrowRows = max(3, v | 1) }
33
- return config
34
- }()
35
-
36
- func generatePattern() -> [(col: Int, row: Int)] {
37
- let center = arrowRows / 2
38
- let shaftHalf = center / 2
39
- var dots: [(Int, Int)] = []
40
-
41
- for r in 0..<arrowRows {
42
- let d = abs(r - center)
43
- if d <= shaftHalf {
44
- for c in 0...(arrowCols - 1 - d) { dots.append((c, r)) }
45
- } else {
46
- let headTip = arrowCols - 1 - d
47
- let headStart = max(0, headTip - 1)
48
- for c in headStart...headTip { dots.append((c, r)) }
49
- }
50
- }
51
- return dots
52
- }
53
- }
54
-
55
- /// Locates the mouse cursor with a spotlight + sonar pulse effect.
56
- /// Dims all screens, spotlights the cursor area, shows directional arrows on off-screens,
57
- /// then plays sonar rings on top.
58
- final class MouseFinder {
59
- static let shared = MouseFinder()
60
-
61
- private var overlayWindows: [NSWindow] = []
62
- private var sonarWindows: [NSWindow] = []
63
- private var dismissTimer: Timer?
64
- private var animationTimer: Timer?
65
- private var sonarDelayTimer: Timer?
66
- private var animationStart: CFTimeInterval = 0
67
- private let animationDuration: CFTimeInterval = 1.5
68
- private var globalEventMonitor: Any?
69
- private var localEventMonitor: Any?
70
-
71
- // MARK: - Find (highlight current position)
72
-
73
- func find() {
74
- let pos = NSEvent.mouseLocation
75
- showSpotlight(at: pos)
76
- }
77
-
78
- // MARK: - Summon (warp to center of the screen the mouse is on, or a specific point)
79
-
80
- func summon(to point: CGPoint? = nil) {
81
- let target: NSPoint
82
- if let point {
83
- target = point
84
- } else {
85
- let screen = mouseScreen()
86
- let frame = screen.frame
87
- target = NSPoint(x: frame.midX, y: frame.midY)
88
- }
89
-
90
- let primaryHeight = NSScreen.screens.first?.frame.height ?? 0
91
- let cgPoint = CGPoint(x: target.x, y: primaryHeight - target.y)
92
- CGWarpMouseCursorPosition(cgPoint)
93
- CGAssociateMouseAndMouseCursorPosition(1)
94
-
95
- showSpotlight(at: target, mode: .summon)
96
- }
97
-
98
- // MARK: - Spotlight Effect
99
-
100
- private func showSpotlight(at nsPoint: NSPoint, mode: SpotlightMode = .find) {
101
- dismiss()
102
-
103
- let screens = NSScreen.screens
104
- guard !screens.isEmpty else { return }
105
-
106
- let cursorScreen = screens.first(where: { $0.frame.contains(nsPoint) }) ?? screens[0]
107
- let otherScreens = screens.filter { $0 !== cursorScreen }
108
- let windowLevel = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.maximumWindow)))
109
-
110
- // Spotlight overlay on cursor screen
111
- let localCursor = NSPoint(
112
- x: nsPoint.x - cursorScreen.frame.origin.x,
113
- y: nsPoint.y - cursorScreen.frame.origin.y
114
- )
115
- let spotlightWindow = makeOverlayWindow(frame: cursorScreen.frame, level: windowLevel)
116
- spotlightWindow.contentView = SpotlightView(
117
- frame: NSRect(origin: .zero, size: cursorScreen.frame.size),
118
- cursorPoint: localCursor,
119
- mode: mode
120
- )
121
- overlayWindows.append(spotlightWindow)
122
-
123
- // Dim overlays with directional arrows on other screens
124
- for screen in otherScreens {
125
- let screenCenter = NSPoint(
126
- x: screen.frame.midX,
127
- y: screen.frame.midY
128
- )
129
- let angle = atan2(nsPoint.y - screenCenter.y, nsPoint.x - screenCenter.x)
130
-
131
- let dimWindow = makeOverlayWindow(frame: screen.frame, level: windowLevel)
132
- dimWindow.contentView = DimOverlayView(
133
- frame: NSRect(origin: .zero, size: screen.frame.size),
134
- cursorAngle: angle
135
- )
136
- overlayWindows.append(dimWindow)
137
- }
138
-
139
- // Fade all in
140
- for window in overlayWindows {
141
- window.alphaValue = 0
142
- window.orderFrontRegardless()
143
- NSAnimationContext.runAnimationGroup { ctx in
144
- ctx.duration = SpotlightConfig.fadeInDuration
145
- window.animator().alphaValue = 1.0
146
- }
147
- }
148
-
149
- installEventMonitors()
150
-
151
- // Start sonar after delay
152
- sonarDelayTimer = Timer.scheduledTimer(withTimeInterval: SpotlightConfig.sonarDelay, repeats: false) { [weak self] _ in
153
- self?.showSonar(at: nsPoint)
154
- }
155
-
156
- // Auto-dismiss
157
- dismissTimer = Timer.scheduledTimer(withTimeInterval: SpotlightConfig.totalDuration, repeats: false) { [weak self] _ in
158
- self?.fadeOut()
159
- }
160
- }
161
-
162
- // MARK: - Sonar Animation (plays on top of spotlight)
163
-
164
- private func showSonar(at nsPoint: NSPoint) {
165
- let screens = NSScreen.screens
166
- guard !screens.isEmpty else { return }
167
-
168
- let ringCount = 3
169
- let maxRadius: CGFloat = 120
170
- let totalSize = maxRadius * 2 + 20
171
- let sonarLevel = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.maximumWindow)) + 1)
172
-
173
- for screen in screens {
174
- let extendedBounds = screen.frame.insetBy(dx: -maxRadius, dy: -maxRadius)
175
- guard extendedBounds.contains(nsPoint) else { continue }
176
-
177
- let windowFrame = NSRect(
178
- x: nsPoint.x - totalSize / 2,
179
- y: nsPoint.y - totalSize / 2,
180
- width: totalSize,
181
- height: totalSize
182
- )
183
-
184
- let window = NSWindow(
185
- contentRect: windowFrame,
186
- styleMask: .borderless,
187
- backing: .buffered,
188
- defer: false
189
- )
190
- window.isOpaque = false
191
- window.backgroundColor = .clear
192
- window.level = sonarLevel
193
- window.hasShadow = false
194
- window.ignoresMouseEvents = true
195
- window.collectionBehavior = [.canJoinAllSpaces, .stationary]
196
-
197
- let sonarView = SonarView(
198
- frame: NSRect(origin: .zero, size: windowFrame.size),
199
- ringCount: ringCount,
200
- maxRadius: maxRadius
201
- )
202
- window.contentView = sonarView
203
-
204
- window.alphaValue = 0
205
- window.orderFrontRegardless()
206
- sonarWindows.append(window)
207
-
208
- NSAnimationContext.runAnimationGroup { ctx in
209
- ctx.duration = 0.1
210
- window.animator().alphaValue = 1.0
211
- }
212
- }
213
-
214
- animationStart = CACurrentMediaTime()
215
- let interval = 1.0 / 60.0
216
-
217
- animationTimer = Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { [weak self] timer in
218
- guard let self else { timer.invalidate(); return }
219
- let elapsed = CACurrentMediaTime() - self.animationStart
220
- let progress = CGFloat(min(elapsed / self.animationDuration, 1.0))
221
-
222
- for window in self.sonarWindows {
223
- (window.contentView as? SonarView)?.progress = progress
224
- window.contentView?.needsDisplay = true
225
- }
226
-
227
- if progress >= 1.0 {
228
- timer.invalidate()
229
- self.animationTimer = nil
230
- }
231
- }
232
- }
233
-
234
- // MARK: - Lifecycle
235
-
236
- private func fadeOut() {
237
- let allWindows = overlayWindows + sonarWindows
238
- NSAnimationContext.runAnimationGroup({ ctx in
239
- ctx.duration = SpotlightConfig.fadeOutDuration
240
- for window in allWindows {
241
- window.animator().alphaValue = 0
242
- }
243
- }, completionHandler: { [weak self] in
244
- self?.dismiss()
245
- })
246
- }
247
-
248
- func dismiss() {
249
- removeEventMonitors()
250
- animationTimer?.invalidate()
251
- animationTimer = nil
252
- dismissTimer?.invalidate()
253
- dismissTimer = nil
254
- sonarDelayTimer?.invalidate()
255
- sonarDelayTimer = nil
256
- for window in overlayWindows + sonarWindows {
257
- window.orderOut(nil)
258
- }
259
- overlayWindows.removeAll()
260
- sonarWindows.removeAll()
261
- }
262
-
263
- // MARK: - Event Monitors
264
-
265
- private func installEventMonitors() {
266
- globalEventMonitor = NSEvent.addGlobalMonitorForEvents(
267
- matching: [.leftMouseDown, .rightMouseDown, .keyDown]
268
- ) { [weak self] _ in
269
- self?.dismiss()
270
- }
271
- localEventMonitor = NSEvent.addLocalMonitorForEvents(
272
- matching: [.leftMouseDown, .rightMouseDown, .keyDown]
273
- ) { [weak self] event in
274
- self?.dismiss()
275
- return event
276
- }
277
- }
278
-
279
- private func removeEventMonitors() {
280
- if let m = globalEventMonitor { NSEvent.removeMonitor(m); globalEventMonitor = nil }
281
- if let m = localEventMonitor { NSEvent.removeMonitor(m); localEventMonitor = nil }
282
- }
283
-
284
- // MARK: - Helpers
285
-
286
- private func makeOverlayWindow(frame: NSRect, level: NSWindow.Level) -> NSWindow {
287
- let window = NSWindow(
288
- contentRect: frame,
289
- styleMask: .borderless,
290
- backing: .buffered,
291
- defer: false
292
- )
293
- window.isOpaque = false
294
- window.backgroundColor = .clear
295
- window.level = level
296
- window.hasShadow = false
297
- window.ignoresMouseEvents = true
298
- window.collectionBehavior = [.canJoinAllSpaces, .stationary]
299
- return window
300
- }
301
-
302
- private func mouseScreen() -> NSScreen {
303
- let pos = NSEvent.mouseLocation
304
- return NSScreen.screens.first(where: { $0.frame.contains(pos) }) ?? NSScreen.screens[0]
305
- }
306
- }
307
-
308
- // MARK: - Spotlight View (radial gradient cutout on cursor screen)
309
-
310
- enum SpotlightMode {
311
- case find // single arrow at screen center pointing TO the cursor
312
- case summon // four arrows around the cursor pointing INWARD ("conjured here")
313
- }
314
-
315
- private class SpotlightView: NSView {
316
- let cursorPoint: CGPoint
317
- let mode: SpotlightMode
318
- private let config = DotMatrixConfig.shared
319
- private lazy var dotPattern = config.generatePattern()
320
-
321
- init(frame: NSRect, cursorPoint: CGPoint, mode: SpotlightMode = .find) {
322
- self.cursorPoint = cursorPoint
323
- self.mode = mode
324
- super.init(frame: frame)
325
- }
326
-
327
- required init?(coder: NSCoder) { fatalError() }
328
-
329
- override func draw(_ dirtyRect: NSRect) {
330
- guard let ctx = NSGraphicsContext.current?.cgContext else { return }
331
-
332
- ctx.setFillColor(NSColor.black.withAlphaComponent(SpotlightConfig.overlayAlpha).cgColor)
333
- ctx.fill(bounds)
334
-
335
- // Punch a radial gradient hole using destinationOut blend mode
336
- ctx.setBlendMode(.destinationOut)
337
-
338
- let colorSpace = CGColorSpaceCreateDeviceRGB()
339
- let components: [CGFloat] = [
340
- 1, 1, 1, 1.0,
341
- 1, 1, 1, 0.8,
342
- 1, 1, 1, 0.0,
343
- ]
344
- let locations: [CGFloat] = [0.0, 0.3, 1.0]
345
-
346
- guard let gradient = CGGradient(
347
- colorSpace: colorSpace,
348
- colorComponents: components,
349
- locations: locations,
350
- count: 3
351
- ) else { return }
352
-
353
- ctx.drawRadialGradient(
354
- gradient,
355
- startCenter: cursorPoint,
356
- startRadius: 0,
357
- endCenter: cursorPoint,
358
- endRadius: SpotlightConfig.spotlightRadius,
359
- options: []
360
- )
361
-
362
- ctx.setBlendMode(.normal)
363
-
364
- switch mode {
365
- case .find:
366
- // Single arrow at screen center pointing toward the cursor.
367
- let center = CGPoint(x: bounds.midX, y: bounds.midY)
368
- let angle = atan2(cursorPoint.y - center.y, cursorPoint.x - center.x)
369
- drawDotMatrixArrow(in: ctx, at: center, angle: angle)
370
-
371
- case .summon:
372
- // Four arrows around the cursor, all heads pointing inward toward it —
373
- // the visual joke is that the mouse was just summoned here, so everything
374
- // is converging on the new cursor position.
375
- let arrowLen = CGFloat(config.arrowCols - 1) * config.dotSpacing
376
- let offset = arrowLen / 2 + SpotlightConfig.spotlightRadius * 0.55
377
- let placements: [(CGPoint, CGFloat)] = [
378
- (CGPoint(x: cursorPoint.x, y: cursorPoint.y + offset), -.pi / 2), // above → points down
379
- (CGPoint(x: cursorPoint.x, y: cursorPoint.y - offset), .pi / 2), // below → points up
380
- (CGPoint(x: cursorPoint.x - offset, y: cursorPoint.y), 0), // left → points right
381
- (CGPoint(x: cursorPoint.x + offset, y: cursorPoint.y), .pi), // right → points left
382
- ]
383
- for (origin, angle) in placements {
384
- drawDotMatrixArrow(in: ctx, at: origin, angle: angle)
385
- }
386
- }
387
- }
388
-
389
- private func drawDotMatrixArrow(in ctx: CGContext, at point: CGPoint, angle: CGFloat) {
390
- ctx.saveGState()
391
- ctx.translateBy(x: point.x, y: point.y)
392
- ctx.rotate(by: angle)
393
-
394
- let originX = -CGFloat(config.arrowCols - 1) * config.dotSpacing / 2
395
- let originY = -CGFloat(config.arrowRows - 1) * config.dotSpacing / 2
396
-
397
- for (col, row) in dotPattern {
398
- let x = originX + CGFloat(col) * config.dotSpacing
399
- let y = originY + CGFloat(row) * config.dotSpacing
400
-
401
- let t = CGFloat(col) / CGFloat(max(1, config.arrowCols - 1))
402
- let alpha = 0.35 + t * 0.5
403
-
404
- ctx.setFillColor(SpotlightConfig.accentColor.withAlphaComponent(alpha).cgColor)
405
- ctx.fillEllipse(in: CGRect(
406
- x: x - config.dotRadius,
407
- y: y - config.dotRadius,
408
- width: config.dotRadius * 2,
409
- height: config.dotRadius * 2
410
- ))
411
- }
412
-
413
- ctx.restoreGState()
414
- }
415
- }
416
-
417
- // MARK: - Dim Overlay View (dark fill + dot matrix arrow centered on off-screens)
418
-
419
- private class DimOverlayView: NSView {
420
- let cursorAngle: CGFloat
421
- private let config = DotMatrixConfig.shared
422
- private lazy var dotPattern = config.generatePattern()
423
-
424
- init(frame: NSRect, cursorAngle: CGFloat) {
425
- self.cursorAngle = cursorAngle
426
- super.init(frame: frame)
427
- }
428
-
429
- required init?(coder: NSCoder) { fatalError() }
430
-
431
- override func draw(_ dirtyRect: NSRect) {
432
- guard let ctx = NSGraphicsContext.current?.cgContext else { return }
433
-
434
- ctx.setFillColor(NSColor.black.withAlphaComponent(SpotlightConfig.dimAlpha).cgColor)
435
- ctx.fill(bounds)
436
-
437
- let center = CGPoint(x: bounds.midX, y: bounds.midY)
438
-
439
- ctx.saveGState()
440
- ctx.translateBy(x: center.x, y: center.y)
441
- ctx.rotate(by: cursorAngle)
442
-
443
- let originX = -CGFloat(config.arrowCols - 1) * config.dotSpacing / 2
444
- let originY = -CGFloat(config.arrowRows - 1) * config.dotSpacing / 2
445
-
446
- for (col, row) in dotPattern {
447
- let x = originX + CGFloat(col) * config.dotSpacing
448
- let y = originY + CGFloat(row) * config.dotSpacing
449
-
450
- let t = CGFloat(col) / CGFloat(max(1, config.arrowCols - 1))
451
- let alpha = 0.35 + t * 0.5
452
-
453
- ctx.setFillColor(SpotlightConfig.accentColor.withAlphaComponent(alpha).cgColor)
454
- ctx.fillEllipse(in: CGRect(
455
- x: x - config.dotRadius,
456
- y: y - config.dotRadius,
457
- width: config.dotRadius * 2,
458
- height: config.dotRadius * 2
459
- ))
460
- }
461
-
462
- ctx.restoreGState()
463
- }
464
- }
465
-
466
- // MARK: - Sonar Ring View
467
-
468
- private class SonarView: NSView {
469
- let ringCount: Int
470
- let maxRadius: CGFloat
471
- var progress: CGFloat = 0
472
-
473
- init(frame: NSRect, ringCount: Int, maxRadius: CGFloat) {
474
- self.ringCount = ringCount
475
- self.maxRadius = maxRadius
476
- super.init(frame: frame)
477
- }
478
-
479
- required init?(coder: NSCoder) { fatalError() }
480
-
481
- override func draw(_ dirtyRect: NSRect) {
482
- guard let ctx = NSGraphicsContext.current?.cgContext else { return }
483
-
484
- let center = CGPoint(x: bounds.midX, y: bounds.midY)
485
-
486
- for i in 0..<ringCount {
487
- let ringDelay = CGFloat(i) * 0.15
488
- let denom = 1.0 - ringDelay * CGFloat(ringCount - 1) / CGFloat(ringCount)
489
- let ringProgress = max(0, min(1, (progress - ringDelay) / denom))
490
-
491
- guard ringProgress > 0 else { continue }
492
-
493
- let eased = 1.0 - pow(1.0 - ringProgress, 3)
494
- let radius = maxRadius * eased
495
- let alpha = (1.0 - eased) * 0.8
496
-
497
- ctx.setStrokeColor(NSColor(calibratedRed: 0.4, green: 0.7, blue: 1.0, alpha: alpha).cgColor)
498
- ctx.setLineWidth(2.5 - CGFloat(i) * 0.5)
499
- ctx.addEllipse(in: CGRect(
500
- x: center.x - radius,
501
- y: center.y - radius,
502
- width: radius * 2,
503
- height: radius * 2
504
- ))
505
- ctx.strokePath()
506
- }
507
-
508
- let dotRadius: CGFloat = 6
509
- let dotAlpha = max(0.3, 1.0 - progress * 0.5)
510
- ctx.setFillColor(NSColor(calibratedRed: 0.4, green: 0.7, blue: 1.0, alpha: dotAlpha).cgColor)
511
- ctx.fillEllipse(in: CGRect(
512
- x: center.x - dotRadius,
513
- y: center.y - dotRadius,
514
- width: dotRadius * 2,
515
- height: dotRadius * 2
516
- ))
517
-
518
- ctx.setFillColor(NSColor(calibratedRed: 0.4, green: 0.7, blue: 1.0, alpha: dotAlpha * 0.2).cgColor)
519
- let glowRadius: CGFloat = 12
520
- ctx.fillEllipse(in: CGRect(
521
- x: center.x - glowRadius,
522
- y: center.y - glowRadius,
523
- width: glowRadius * 2,
524
- height: glowRadius * 2
525
- ))
526
- }
527
- }