@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,196 +0,0 @@
1
- import AppKit
2
- import SwiftUI
3
-
4
- /// NSPanel subclass that accepts key events and first-click mouse events.
5
- /// Overrides sendEvent to ensure the panel is key before processing clicks,
6
- /// which is required for SwiftUI gesture/button handling in .nonactivatingPanel panels.
7
- private class CommandModePanel: NSPanel {
8
- override var canBecomeKey: Bool { true }
9
- override var canBecomeMain: Bool { true }
10
- override var acceptsMouseMovedEvents: Bool {
11
- get { true }
12
- set { super.acceptsMouseMovedEvents = newValue }
13
- }
14
-
15
- override func sendEvent(_ event: NSEvent) {
16
- // Non-activating panels can silently lose key status. Re-assert key
17
- // and app activation before every mouse-down so SwiftUI Buttons/gestures
18
- // fire reliably — including the very first click after the panel appears.
19
- if event.type == .leftMouseDown || event.type == .rightMouseDown {
20
- if !NSApp.isActive {
21
- NSApp.activate(ignoringOtherApps: true)
22
- }
23
- if !isKeyWindow { makeKey() }
24
- }
25
- super.sendEvent(event)
26
- }
27
- }
28
-
29
- /// NSHostingView subclass that accepts first-click events in non-activating panels
30
- private class FirstClickHostingView<Content: View>: NSHostingView<Content> {
31
- override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
32
- override var focusRingType: NSFocusRingType { get { .none } set {} }
33
- }
34
-
35
- final class CommandModeWindow {
36
- static let shared = CommandModeWindow()
37
-
38
- private var panel: NSPanel?
39
- private var isOpen = false
40
-
41
- /// Exposed for event monitor filtering (only handle clicks in this window)
42
- var panelWindow: NSWindow? { panel }
43
-
44
- var isVisible: Bool { isOpen }
45
-
46
- func toggle(launchMode: CommandModeLaunchMode = .normal) {
47
- if isOpen {
48
- if launchMode == .normal {
49
- dismiss()
50
- } else {
51
- show(launchMode: launchMode)
52
- }
53
- } else {
54
- show(launchMode: launchMode)
55
- }
56
- }
57
-
58
- func show(launchMode: CommandModeLaunchMode = .normal) {
59
- // Always rebuild for fresh state
60
- dismiss()
61
- isOpen = true
62
-
63
- // Dismiss palette if visible
64
- if CommandPaletteWindow.shared.isVisible {
65
- CommandPaletteWindow.shared.dismiss()
66
- }
67
-
68
- let state = CommandModeState(launchMode: launchMode)
69
- state.onDismiss = { [weak self] in
70
- self?.dismiss()
71
- }
72
- state.onPanelResize = { [weak self] width, height in
73
- self?.animateResize(width: width, height: height)
74
- }
75
- state.enter()
76
-
77
- // Compute initial size from state phase
78
- let initialWidth: CGFloat
79
- let initialHeight: CGFloat
80
- if state.phase == .desktopInventory {
81
- let displayCount = max(1, state.desktopSnapshot?.displays.count ?? 1)
82
- let columnWidth: CGFloat = 480
83
- initialWidth = CGFloat(displayCount) * columnWidth + CGFloat(displayCount - 1) + 32
84
- initialHeight = 640
85
- } else {
86
- initialWidth = 580; initialHeight = 360
87
- }
88
-
89
- let view = CommandModeView(state: state)
90
- .preferredColorScheme(.dark)
91
-
92
- let hosting = FirstClickHostingView(rootView: view)
93
- hosting.translatesAutoresizingMaskIntoConstraints = false
94
-
95
- let panel = CommandModePanel(
96
- contentRect: NSRect(x: 0, y: 0, width: initialWidth, height: initialHeight),
97
- styleMask: [.nonactivatingPanel],
98
- backing: .buffered,
99
- defer: false
100
- )
101
-
102
- panel.isOpaque = false
103
- panel.backgroundColor = .clear
104
- panel.hasShadow = true
105
- panel.level = .floating
106
- panel.isMovableByWindowBackground = true
107
- panel.hidesOnDeactivate = true
108
- panel.becomesKeyOnlyIfNeeded = false
109
- panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
110
- panel.isReleasedWhenClosed = false
111
-
112
- let cornerRadius: CGFloat = 14
113
-
114
- let effectView = NSVisualEffectView()
115
- effectView.blendingMode = .behindWindow
116
- effectView.material = .popover
117
- effectView.state = .active
118
- effectView.wantsLayer = true
119
- effectView.maskImage = Self.maskImage(cornerRadius: cornerRadius)
120
-
121
- panel.contentView = effectView
122
-
123
- effectView.addSubview(hosting)
124
- NSLayoutConstraint.activate([
125
- hosting.leadingAnchor.constraint(equalTo: effectView.leadingAnchor),
126
- hosting.trailingAnchor.constraint(equalTo: effectView.trailingAnchor),
127
- hosting.topAnchor.constraint(equalTo: effectView.topAnchor),
128
- hosting.bottomAnchor.constraint(equalTo: effectView.bottomAnchor),
129
- ])
130
-
131
- // Center horizontally, slightly above vertical center
132
- if let screen = NSScreen.main {
133
- let screenFrame = screen.visibleFrame
134
- let clampedWidth = min(initialWidth, screenFrame.width * 0.92)
135
- let clampedHeight = min(initialHeight, screenFrame.height * 0.85)
136
- let x = screenFrame.midX - clampedWidth / 2
137
- let y = screenFrame.midY - clampedHeight / 2 + (screenFrame.height * 0.08)
138
- panel.setFrameOrigin(NSPoint(x: x, y: y))
139
- }
140
-
141
- self.panel = panel
142
-
143
- panel.makeKeyAndOrderFront(nil)
144
- NSApp.activate(ignoringOtherApps: true)
145
- AppDelegate.updateActivationPolicy()
146
- }
147
-
148
- private func animateResize(width: CGFloat, height: CGFloat) {
149
- guard let panel = panel, let screen = panel.screen ?? NSScreen.main else { return }
150
-
151
- let screenFrame = screen.visibleFrame
152
- // Clamp to screen bounds with margin
153
- let newWidth = min(width, screenFrame.width * 0.92)
154
- let newHeight = min(height, screenFrame.height * 0.85)
155
-
156
- let newX = screenFrame.midX - newWidth / 2
157
- let newY = screenFrame.midY - newHeight / 2 + (screenFrame.height * 0.08)
158
-
159
- let newFrame = NSRect(x: newX, y: newY, width: newWidth, height: newHeight)
160
-
161
- NSAnimationContext.runAnimationGroup { ctx in
162
- ctx.duration = 0.25
163
- ctx.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
164
- panel.animator().setFrame(newFrame, display: true)
165
- }
166
- }
167
-
168
- func dismiss() {
169
- isOpen = false
170
- panel?.orderOut(nil)
171
- panel = nil
172
- AppDelegate.updateActivationPolicy()
173
- }
174
-
175
- /// Stretchable mask image for rounded corners
176
- private static func maskImage(cornerRadius: CGFloat) -> NSImage {
177
- let edgeLength = 2.0 * cornerRadius + 1.0
178
- let maskImage = NSImage(
179
- size: NSSize(width: edgeLength, height: edgeLength),
180
- flipped: false
181
- ) { rect in
182
- let path = NSBezierPath(roundedRect: rect, xRadius: cornerRadius, yRadius: cornerRadius)
183
- NSColor.black.set()
184
- path.fill()
185
- return true
186
- }
187
- maskImage.capInsets = NSEdgeInsets(
188
- top: cornerRadius,
189
- left: cornerRadius,
190
- bottom: cornerRadius,
191
- right: cornerRadius
192
- )
193
- maskImage.resizingMode = .stretch
194
- return maskImage
195
- }
196
- }
@@ -1,307 +0,0 @@
1
- import SwiftUI
2
- import AppKit
3
-
4
- struct CommandPaletteView: View {
5
- let commands: [PaletteCommand]
6
- let onDismiss: () -> Void
7
-
8
- @State private var query = ""
9
- @State private var selectedIndex = 0
10
- @State private var eventMonitor: Any?
11
- @FocusState private var isSearchFocused: Bool
12
-
13
- private var filtered: [PaletteCommand] {
14
- if query.isEmpty { return commands }
15
- return commands
16
- .map { ($0, $0.matchScore(query: query)) }
17
- .filter { $0.1 > 0 }
18
- .sorted { $0.1 > $1.1 }
19
- .map(\.0)
20
- }
21
-
22
- /// Group commands by category (only used when query is empty)
23
- private var grouped: [(PaletteCommand.Category, [PaletteCommand])] {
24
- let items = filtered
25
- var result: [(PaletteCommand.Category, [PaletteCommand])] = []
26
- for cat in PaletteCommand.Category.allCases {
27
- let group = items.filter { $0.category == cat }
28
- if !group.isEmpty {
29
- result.append((cat, group))
30
- }
31
- }
32
- return result
33
- }
34
-
35
- var body: some View {
36
- VStack(spacing: 0) {
37
- // Search field
38
- searchField
39
-
40
- Rectangle()
41
- .fill(Palette.border)
42
- .frame(height: 0.5)
43
-
44
- // Results
45
- ScrollViewReader { proxy in
46
- ScrollView {
47
- if query.isEmpty {
48
- groupedList
49
- } else {
50
- flatList
51
- }
52
- }
53
- .onChange(of: selectedIndex) { idx in
54
- let items = filtered
55
- if idx >= 0 && idx < items.count {
56
- proxy.scrollTo(items[idx].id, anchor: .center)
57
- }
58
- }
59
- }
60
- .frame(minHeight: 280, maxHeight: 360)
61
-
62
- Rectangle()
63
- .fill(Palette.border)
64
- .frame(height: 0.5)
65
-
66
- // Footer hints
67
- footer
68
- }
69
- .frame(width: 540)
70
- .background(Palette.bg)
71
- .clipShape(RoundedRectangle(cornerRadius: 14, style: .continuous))
72
- .overlay(
73
- RoundedRectangle(cornerRadius: 14, style: .continuous)
74
- .strokeBorder(Palette.borderLit, lineWidth: 0.5)
75
- )
76
- .onAppear {
77
- installKeyHandler()
78
- // Delay focus slightly to ensure the panel is key
79
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
80
- isSearchFocused = true
81
- }
82
- }
83
- .onDisappear { removeKeyHandler() }
84
- }
85
-
86
- // MARK: - Search Field
87
-
88
- private var searchField: some View {
89
- HStack(spacing: 10) {
90
- Image(systemName: "magnifyingglass")
91
- .foregroundColor(Palette.textMuted)
92
- .font(.system(size: 14))
93
-
94
- TextField("Search commands...", text: $query)
95
- .textFieldStyle(.plain)
96
- .font(Typo.body(14))
97
- .foregroundColor(Palette.text)
98
- .focused($isSearchFocused)
99
- .onChange(of: query) { _ in selectedIndex = 0 }
100
- }
101
- .padding(.horizontal, 16)
102
- .padding(.vertical, 12)
103
- }
104
-
105
- // MARK: - Grouped List (empty query)
106
-
107
- private var groupedList: some View {
108
- LazyVStack(alignment: .leading, spacing: 0) {
109
- ForEach(grouped, id: \.0) { category, items in
110
- sectionHeader(category)
111
- ForEach(items) { cmd in
112
- let idx = flatIndex(of: cmd)
113
- commandRow(cmd, isSelected: idx == selectedIndex)
114
- .id(cmd.id)
115
- .onTapGesture { executeCommand(cmd) }
116
- }
117
- }
118
- }
119
- .padding(.vertical, 6)
120
- }
121
-
122
- // MARK: - Flat List (with query)
123
-
124
- private var flatList: some View {
125
- LazyVStack(alignment: .leading, spacing: 0) {
126
- ForEach(Array(filtered.enumerated()), id: \.element.id) { idx, cmd in
127
- commandRow(cmd, isSelected: idx == selectedIndex)
128
- .id(cmd.id)
129
- .onTapGesture { executeCommand(cmd) }
130
- }
131
- }
132
- .padding(.vertical, 6)
133
- }
134
-
135
- // MARK: - Section Header
136
-
137
- private func sectionHeader(_ category: PaletteCommand.Category) -> some View {
138
- HStack(spacing: 5) {
139
- Image(systemName: category.icon)
140
- .font(.system(size: 9))
141
- Text(category.rawValue.uppercased())
142
- .font(Typo.mono(9))
143
- }
144
- .foregroundColor(Palette.textMuted)
145
- .padding(.horizontal, 16)
146
- .padding(.top, 10)
147
- .padding(.bottom, 4)
148
- }
149
-
150
- // MARK: - Command Row
151
-
152
- private func commandRow(_ cmd: PaletteCommand, isSelected: Bool) -> some View {
153
- HStack(spacing: 10) {
154
- Image(systemName: cmd.icon)
155
- .font(.system(size: 12))
156
- .foregroundColor(isSelected ? Palette.text : Palette.textDim)
157
- .frame(width: 20)
158
-
159
- VStack(alignment: .leading, spacing: 1) {
160
- HStack(spacing: 6) {
161
- Text(cmd.title)
162
- .font(Typo.body(13))
163
- .foregroundColor(isSelected ? Palette.text : Palette.text.opacity(0.85))
164
- .lineLimit(1)
165
-
166
- if let badge = cmd.badge {
167
- Text(badge)
168
- .font(Typo.mono(9))
169
- .foregroundColor(Palette.running)
170
- .padding(.horizontal, 5)
171
- .padding(.vertical, 1)
172
- .background(
173
- RoundedRectangle(cornerRadius: 3)
174
- .fill(Palette.running.opacity(0.12))
175
- )
176
- }
177
- }
178
-
179
- Text(cmd.subtitle)
180
- .font(Typo.caption(10))
181
- .foregroundColor(Palette.textMuted)
182
- .lineLimit(1)
183
- }
184
-
185
- Spacer()
186
- }
187
- .padding(.horizontal, 14)
188
- .padding(.vertical, 7)
189
- .background(
190
- RoundedRectangle(cornerRadius: 5)
191
- .fill(isSelected ? Palette.surface : Color.clear)
192
- )
193
- .padding(.horizontal, 6)
194
- .contentShape(Rectangle())
195
- }
196
-
197
- // MARK: - Footer
198
-
199
- private var footer: some View {
200
- HStack(spacing: 14) {
201
- footerHint(keys: ["\u{2191}\u{2193}"], label: "navigate")
202
- footerHint(keys: ["\u{21A9}"], label: "select")
203
- footerHint(keys: ["esc"], label: "close")
204
- Spacer()
205
- Text("\(filtered.count) command\(filtered.count == 1 ? "" : "s")")
206
- .font(Typo.mono(9))
207
- .foregroundColor(Palette.textMuted)
208
- }
209
- .padding(.horizontal, 16)
210
- .padding(.vertical, 8)
211
- .background(Palette.surface.opacity(0.4))
212
- }
213
-
214
- private func footerHint(keys: [String], label: String) -> some View {
215
- HStack(spacing: 4) {
216
- ForEach(keys, id: \.self) { key in
217
- Text(key)
218
- .font(Typo.mono(9))
219
- .foregroundColor(Palette.text)
220
- .padding(.horizontal, 4)
221
- .padding(.vertical, 2)
222
- .background(
223
- RoundedRectangle(cornerRadius: 3)
224
- .fill(Palette.surface)
225
- .overlay(
226
- RoundedRectangle(cornerRadius: 3)
227
- .strokeBorder(Palette.border, lineWidth: 0.5)
228
- )
229
- )
230
- }
231
- Text(label)
232
- .font(Typo.mono(9))
233
- .foregroundColor(Palette.textMuted)
234
- }
235
- }
236
-
237
- // MARK: - Keyboard Navigation
238
-
239
- private func installKeyHandler() {
240
- eventMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { event in
241
- let isSearchActive = isSearchFocused
242
-
243
- switch Int(event.keyCode) {
244
- case 125: // Down arrow
245
- moveDown()
246
- return nil
247
- case 126: // Up arrow
248
- moveUp()
249
- return nil
250
- case 38 where !isSearchActive: // j (vim down) — only when not typing
251
- moveDown()
252
- return nil
253
- case 40 where !isSearchActive: // k (vim up) — only when not typing
254
- moveUp()
255
- return nil
256
- case 36: // Return
257
- let items = filtered
258
- if selectedIndex >= 0 && selectedIndex < items.count {
259
- executeCommand(items[selectedIndex])
260
- }
261
- return nil
262
- case 53: // Escape
263
- onDismiss()
264
- return nil
265
- default:
266
- return event
267
- }
268
- }
269
- }
270
-
271
- private func moveDown() {
272
- let count = filtered.count
273
- if count > 0 {
274
- selectedIndex = min(selectedIndex + 1, count - 1)
275
- }
276
- }
277
-
278
- private func moveUp() {
279
- selectedIndex = max(selectedIndex - 1, 0)
280
- }
281
-
282
- private func removeKeyHandler() {
283
- if let monitor = eventMonitor {
284
- NSEvent.removeMonitor(monitor)
285
- eventMonitor = nil
286
- }
287
- }
288
-
289
- // MARK: - Execution
290
-
291
- private func executeCommand(_ cmd: PaletteCommand) {
292
- let action = cmd.action
293
- onDismiss()
294
- // Small delay to let the palette dismiss before executing
295
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
296
- action()
297
- }
298
- }
299
-
300
- // MARK: - Helpers
301
-
302
- /// Get flat index of a command across all groups (for selection tracking)
303
- private func flatIndex(of cmd: PaletteCommand) -> Int {
304
- let items = filtered
305
- return items.firstIndex(where: { $0.id == cmd.id }) ?? -1
306
- }
307
- }
@@ -1,67 +0,0 @@
1
- import AppKit
2
- import SwiftUI
3
-
4
- final class CommandPaletteWindow {
5
- static let shared = CommandPaletteWindow()
6
-
7
- private var panel: NSPanel?
8
- private var scanner: ProjectScanner?
9
-
10
- func configure(scanner: ProjectScanner) {
11
- self.scanner = scanner
12
- }
13
-
14
- var isVisible: Bool { panel?.isVisible ?? false }
15
-
16
- func toggle() {
17
- if let p = panel, p.isVisible {
18
- dismiss()
19
- } else {
20
- show()
21
- }
22
- }
23
-
24
- func show() {
25
- // Always rebuild for fresh command state
26
- dismiss()
27
-
28
- guard let scanner = scanner else { return }
29
-
30
- // Ensure projects are up to date (full scan if list is empty,
31
- // e.g. palette opened via hotkey before main popover appeared)
32
- if scanner.projects.isEmpty {
33
- scanner.scan()
34
- } else {
35
- scanner.refreshStatus()
36
- }
37
-
38
- let commands = CommandBuilder.build(scanner: scanner)
39
- let view = CommandPaletteView(commands: commands) { [weak self] in
40
- self?.dismiss()
41
- }
42
- .preferredColorScheme(.dark)
43
-
44
- let panel = OverlayPanelShell.makePanel(
45
- config: .init(
46
- size: NSSize(width: 540, height: 440),
47
- styleMask: [.nonactivatingPanel],
48
- background: .material(.popover),
49
- cornerRadius: 14,
50
- hidesOnDeactivate: true,
51
- isMovableByWindowBackground: true
52
- ),
53
- rootView: view
54
- )
55
- OverlayPanelShell.position(panel, placement: .centered(yOffsetRatio: 0.1))
56
- OverlayPanelShell.present(panel)
57
-
58
- self.panel = panel
59
- AppDelegate.updateActivationPolicy()
60
- }
61
-
62
- func dismiss() {
63
- panel?.orderOut(nil)
64
- panel = nil
65
- AppDelegate.updateActivationPolicy()
66
- }
67
- }