@lattices/cli 0.4.14 → 0.5.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 (180) hide show
  1. package/README.md +5 -7
  2. package/apps/mac/Info.plist +2 -2
  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/reference/dewey.config.ts +2 -2
  19. package/docs/release.md +171 -0
  20. package/docs/repo-structure.md +4 -5
  21. package/docs/voice.md +11 -27
  22. package/package.json +9 -10
  23. package/apps/mac/Package.swift +0 -27
  24. package/apps/mac/Sources/AppShell/App.swift +0 -26
  25. package/apps/mac/Sources/AppShell/AppActivationCoordinator.swift +0 -27
  26. package/apps/mac/Sources/AppShell/AppDelegate.swift +0 -189
  27. package/apps/mac/Sources/AppShell/AppServicesBootstrap.swift +0 -25
  28. package/apps/mac/Sources/AppShell/AppShellView.swift +0 -171
  29. package/apps/mac/Sources/AppShell/AppUpdater.swift +0 -305
  30. package/apps/mac/Sources/AppShell/CliActionLauncher.swift +0 -50
  31. package/apps/mac/Sources/AppShell/HomeDashboardView.swift +0 -133
  32. package/apps/mac/Sources/AppShell/HotkeyBootstrap.swift +0 -87
  33. package/apps/mac/Sources/AppShell/KeyRecorderView.swift +0 -210
  34. package/apps/mac/Sources/AppShell/LatticesRuntime.swift +0 -104
  35. package/apps/mac/Sources/AppShell/MainView.swift +0 -847
  36. package/apps/mac/Sources/AppShell/MainWindow.swift +0 -83
  37. package/apps/mac/Sources/AppShell/MenuBarController.swift +0 -177
  38. package/apps/mac/Sources/AppShell/OnboardingView.swift +0 -483
  39. package/apps/mac/Sources/AppShell/PermissionsAssistantView.swift +0 -366
  40. package/apps/mac/Sources/AppShell/PermissionsAssistantWindow.swift +0 -70
  41. package/apps/mac/Sources/AppShell/Preferences.swift +0 -297
  42. package/apps/mac/Sources/AppShell/SettingsView.swift +0 -3163
  43. package/apps/mac/Sources/AppShell/SettingsWindow.swift +0 -34
  44. package/apps/mac/Sources/AppShell/WorkspaceInspectorPresenter.swift +0 -13
  45. package/apps/mac/Sources/Core/Actions/HotkeyManager.swift +0 -256
  46. package/apps/mac/Sources/Core/Actions/HotkeyStore.swift +0 -399
  47. package/apps/mac/Sources/Core/Actions/IntentEngine.swift +0 -988
  48. package/apps/mac/Sources/Core/Actions/IntentSchema.swift +0 -94
  49. package/apps/mac/Sources/Core/Actions/Intents/CreateLayerIntent.swift +0 -54
  50. package/apps/mac/Sources/Core/Actions/Intents/DistributeIntent.swift +0 -56
  51. package/apps/mac/Sources/Core/Actions/Intents/FocusIntent.swift +0 -69
  52. package/apps/mac/Sources/Core/Actions/Intents/HelpIntent.swift +0 -41
  53. package/apps/mac/Sources/Core/Actions/Intents/KillIntent.swift +0 -47
  54. package/apps/mac/Sources/Core/Actions/Intents/LatticeIntent.swift +0 -53
  55. package/apps/mac/Sources/Core/Actions/Intents/LaunchIntent.swift +0 -67
  56. package/apps/mac/Sources/Core/Actions/Intents/ListSessionsIntent.swift +0 -32
  57. package/apps/mac/Sources/Core/Actions/Intents/ListWindowsIntent.swift +0 -30
  58. package/apps/mac/Sources/Core/Actions/Intents/ScanIntent.swift +0 -52
  59. package/apps/mac/Sources/Core/Actions/Intents/SearchIntent.swift +0 -190
  60. package/apps/mac/Sources/Core/Actions/Intents/SwitchLayerIntent.swift +0 -50
  61. package/apps/mac/Sources/Core/Actions/Intents/TileIntent.swift +0 -61
  62. package/apps/mac/Sources/Core/Actions/PaletteCommand.swift +0 -439
  63. package/apps/mac/Sources/Core/Actions/VoiceIntentResolver.swift +0 -713
  64. package/apps/mac/Sources/Core/Companion/CompanionActivityLog.swift +0 -70
  65. package/apps/mac/Sources/Core/Companion/CompanionKeyboardController.swift +0 -141
  66. package/apps/mac/Sources/Core/Companion/LatticesCompanionBridgeServer.swift +0 -454
  67. package/apps/mac/Sources/Core/Companion/LatticesCompanionCockpit.swift +0 -555
  68. package/apps/mac/Sources/Core/Companion/LatticesCompanionSecurityCoordinator.swift +0 -629
  69. package/apps/mac/Sources/Core/Companion/LatticesCompanionTrackpadController.swift +0 -204
  70. package/apps/mac/Sources/Core/Companion/LatticesDeckHost.swift +0 -1463
  71. package/apps/mac/Sources/Core/Daemon/DaemonProtocol.swift +0 -114
  72. package/apps/mac/Sources/Core/Daemon/DaemonServer.swift +0 -427
  73. package/apps/mac/Sources/Core/Daemon/LatticesApi.swift +0 -2965
  74. package/apps/mac/Sources/Core/Desktop/AccessibilityTextExtractor.swift +0 -111
  75. package/apps/mac/Sources/Core/Desktop/AppTypeClassifier.swift +0 -106
  76. package/apps/mac/Sources/Core/Desktop/DesktopModel.swift +0 -331
  77. package/apps/mac/Sources/Core/Desktop/DesktopModelTypes.swift +0 -73
  78. package/apps/mac/Sources/Core/Desktop/InventoryManager.swift +0 -35
  79. package/apps/mac/Sources/Core/Desktop/InventoryPath.swift +0 -43
  80. package/apps/mac/Sources/Core/Desktop/MouseFinder.swift +0 -527
  81. package/apps/mac/Sources/Core/Desktop/OcrModel.swift +0 -467
  82. package/apps/mac/Sources/Core/Desktop/OcrStore.swift +0 -329
  83. package/apps/mac/Sources/Core/Desktop/PlacementSpec.swift +0 -195
  84. package/apps/mac/Sources/Core/Desktop/SessionWindowLocator.swift +0 -139
  85. package/apps/mac/Sources/Core/Desktop/TilePickerView.swift +0 -209
  86. package/apps/mac/Sources/Core/Desktop/WindowCapture.swift +0 -33
  87. package/apps/mac/Sources/Core/Desktop/WindowDragSnapController.swift +0 -429
  88. package/apps/mac/Sources/Core/Desktop/WindowPreviewCard.swift +0 -100
  89. package/apps/mac/Sources/Core/Desktop/WindowPreviewStore.swift +0 -112
  90. package/apps/mac/Sources/Core/Desktop/WindowSelectionStore.swift +0 -76
  91. package/apps/mac/Sources/Core/Desktop/WindowTiler.swift +0 -2222
  92. package/apps/mac/Sources/Core/Input/EventTapBreaker.swift +0 -124
  93. package/apps/mac/Sources/Core/Input/EventTapThread.swift +0 -54
  94. package/apps/mac/Sources/Core/Input/InputCaptureResetCenter.swift +0 -20
  95. package/apps/mac/Sources/Core/Input/KeyboardRemapConfig.swift +0 -69
  96. package/apps/mac/Sources/Core/Input/KeyboardRemapController.swift +0 -346
  97. package/apps/mac/Sources/Core/Input/KeyboardRemapStore.swift +0 -141
  98. package/apps/mac/Sources/Core/Input/MouseGestureConfig.swift +0 -499
  99. package/apps/mac/Sources/Core/Input/MouseGestureController.swift +0 -2583
  100. package/apps/mac/Sources/Core/Input/MouseInputDeviceStore.swift +0 -98
  101. package/apps/mac/Sources/Core/Input/MouseInputEventViewer.swift +0 -272
  102. package/apps/mac/Sources/Core/Input/MouseShortcutStore.swift +0 -170
  103. package/apps/mac/Sources/Core/Input/SecureEventInputMonitor.swift +0 -39
  104. package/apps/mac/Sources/Core/Input/ShapeRecognizer.swift +0 -624
  105. package/apps/mac/Sources/Core/Input/TapBudgetMeter.swift +0 -56
  106. package/apps/mac/Sources/Core/Overlays/AppWindowShell.swift +0 -63
  107. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeState.swift +0 -1566
  108. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeView.swift +0 -1927
  109. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeWindow.swift +0 -196
  110. package/apps/mac/Sources/Core/Overlays/CommandPalette/CommandPaletteView.swift +0 -307
  111. package/apps/mac/Sources/Core/Overlays/CommandPalette/CommandPaletteWindow.swift +0 -67
  112. package/apps/mac/Sources/Core/Overlays/HUD/CheatSheetHUD.swift +0 -576
  113. package/apps/mac/Sources/Core/Overlays/HUD/HUDBottomBar.swift +0 -279
  114. package/apps/mac/Sources/Core/Overlays/HUD/HUDController.swift +0 -1158
  115. package/apps/mac/Sources/Core/Overlays/HUD/HUDLeftBar.swift +0 -849
  116. package/apps/mac/Sources/Core/Overlays/HUD/HUDMinimap.swift +0 -179
  117. package/apps/mac/Sources/Core/Overlays/HUD/HUDRightBar.swift +0 -596
  118. package/apps/mac/Sources/Core/Overlays/HUD/HUDState.swift +0 -367
  119. package/apps/mac/Sources/Core/Overlays/HUD/HUDTopBar.swift +0 -243
  120. package/apps/mac/Sources/Core/Overlays/HUD/LauncherHUD.swift +0 -334
  121. package/apps/mac/Sources/Core/Overlays/HUD/LayerBezel.swift +0 -203
  122. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchState.swift +0 -280
  123. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchView.swift +0 -422
  124. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchWindow.swift +0 -94
  125. package/apps/mac/Sources/Core/Overlays/OverlayPanelShell.swift +0 -241
  126. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapState.swift +0 -3135
  127. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapView.swift +0 -3977
  128. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapWindowController.swift +0 -119
  129. package/apps/mac/Sources/Core/Overlays/ScreenOverlayCanvasController.swift +0 -1217
  130. package/apps/mac/Sources/Core/Overlays/Voice/VoiceCommandWindow.swift +0 -1575
  131. package/apps/mac/Sources/Core/Pi/PiAuthNextStepCard.swift +0 -148
  132. package/apps/mac/Sources/Core/Pi/PiAuthPromptCard.swift +0 -90
  133. package/apps/mac/Sources/Core/Pi/PiChatDock.swift +0 -564
  134. package/apps/mac/Sources/Core/Pi/PiChatSession.swift +0 -1948
  135. package/apps/mac/Sources/Core/Pi/PiInstallCallout.swift +0 -86
  136. package/apps/mac/Sources/Core/Pi/PiProviderSetupCallout.swift +0 -99
  137. package/apps/mac/Sources/Core/Pi/PiWorkspaceView.swift +0 -510
  138. package/apps/mac/Sources/Core/System/Capability.swift +0 -79
  139. package/apps/mac/Sources/Core/System/DiagnosticLog.swift +0 -373
  140. package/apps/mac/Sources/Core/System/EventBus.swift +0 -31
  141. package/apps/mac/Sources/Core/System/PermissionChecker.swift +0 -224
  142. package/apps/mac/Sources/Core/System/ProcessModel.swift +0 -199
  143. package/apps/mac/Sources/Core/System/ProcessQuery.swift +0 -151
  144. package/apps/mac/Sources/Core/System/SystemTelemetryMonitor.swift +0 -273
  145. package/apps/mac/Sources/Core/Voice/AdvisorLearningStore.swift +0 -90
  146. package/apps/mac/Sources/Core/Voice/AgentSession.swift +0 -377
  147. package/apps/mac/Sources/Core/Voice/AudioProvider.swift +0 -555
  148. package/apps/mac/Sources/Core/Voice/HandsOffSession.swift +0 -839
  149. package/apps/mac/Sources/Core/Voice/VoiceChatView.swift +0 -192
  150. package/apps/mac/Sources/Core/Voice/VoxClient.swift +0 -454
  151. package/apps/mac/Sources/Core/Workspace/Project.swift +0 -28
  152. package/apps/mac/Sources/Core/Workspace/ProjectScanner.swift +0 -141
  153. package/apps/mac/Sources/Core/Workspace/SessionLayerStore.swift +0 -285
  154. package/apps/mac/Sources/Core/Workspace/SessionManager.swift +0 -75
  155. package/apps/mac/Sources/Core/Workspace/Terminal/Terminal.swift +0 -259
  156. package/apps/mac/Sources/Core/Workspace/Terminal/TerminalQuery.swift +0 -156
  157. package/apps/mac/Sources/Core/Workspace/Terminal/TerminalSynthesizer.swift +0 -200
  158. package/apps/mac/Sources/Core/Workspace/Tmux/TmuxModel.swift +0 -60
  159. package/apps/mac/Sources/Core/Workspace/Tmux/TmuxQuery.swift +0 -105
  160. package/apps/mac/Sources/Core/Workspace/WorkspaceManager.swift +0 -1027
  161. package/apps/mac/Sources/UI/ActionRow.swift +0 -78
  162. package/apps/mac/Sources/UI/OrphanRow.swift +0 -129
  163. package/apps/mac/Sources/UI/ProjectRow.swift +0 -368
  164. package/apps/mac/Sources/UI/TabGroupRow.swift +0 -178
  165. package/apps/mac/Sources/UI/Theme.swift +0 -164
  166. package/apps/mac/Tests/StageDragTests.swift +0 -333
  167. package/apps/mac/Tests/StageJoinTests.swift +0 -313
  168. package/apps/mac/Tests/StageManagerTests.swift +0 -280
  169. package/apps/mac/Tests/StageTileTests.swift +0 -353
  170. package/swift/Package.swift +0 -20
  171. package/swift/Sources/DeckKit/DeckAction.swift +0 -51
  172. package/swift/Sources/DeckKit/DeckBridgeSecurity.swift +0 -152
  173. package/swift/Sources/DeckKit/DeckCockpit.swift +0 -82
  174. package/swift/Sources/DeckKit/DeckHost.swift +0 -7
  175. package/swift/Sources/DeckKit/DeckManifest.swift +0 -145
  176. package/swift/Sources/DeckKit/DeckRuntimeSnapshot.swift +0 -533
  177. package/swift/Sources/DeckKit/DeckTrackpad.swift +0 -63
  178. package/swift/Sources/DeckKit/DeckValue.swift +0 -93
  179. package/swift/Sources/DeckKit/DeckVoiceError.swift +0 -88
  180. package/swift/Tests/DeckKitTests/DeckKitTests.swift +0 -286
@@ -1,100 +0,0 @@
1
- import AppKit
2
- import SwiftUI
3
-
4
- struct WindowPreviewCardStyle {
5
- var containerCornerRadius: CGFloat = 10
6
- var imageCornerRadius: CGFloat = 8
7
- var imagePadding: CGFloat = 8
8
- var background: Color = Palette.surface.opacity(0.8)
9
- var border: Color = Palette.border
10
- }
11
-
12
- struct WindowPreviewCard<Overlay: View>: View {
13
- let image: NSImage?
14
- let isLoading: Bool
15
- let appName: String
16
- var loadingTitle: String = "Capturing preview"
17
- var unavailableTitle: String = "Preview unavailable"
18
- var style: WindowPreviewCardStyle = WindowPreviewCardStyle()
19
- var holdingPreviousPreview: Bool = false
20
- @ViewBuilder let overlay: () -> Overlay
21
-
22
- var body: some View {
23
- ZStack {
24
- RoundedRectangle(cornerRadius: style.containerCornerRadius)
25
- .fill(style.background)
26
- .overlay(
27
- RoundedRectangle(cornerRadius: style.containerCornerRadius)
28
- .strokeBorder(style.border, lineWidth: 0.5)
29
- )
30
-
31
- if let image {
32
- Image(nsImage: image)
33
- .resizable()
34
- .aspectRatio(contentMode: .fit)
35
- .clipShape(RoundedRectangle(cornerRadius: style.imageCornerRadius))
36
- .padding(style.imagePadding)
37
- .opacity(holdingPreviousPreview ? 0.88 : 1)
38
- } else if isLoading {
39
- WindowPreviewPlaceholder(
40
- icon: "photo",
41
- title: loadingTitle,
42
- subtitle: appName
43
- )
44
- } else {
45
- WindowPreviewPlaceholder(
46
- icon: "eye.slash",
47
- title: unavailableTitle,
48
- subtitle: appName
49
- )
50
- }
51
-
52
- overlay()
53
- }
54
- }
55
- }
56
-
57
- extension WindowPreviewCard where Overlay == EmptyView {
58
- init(
59
- image: NSImage?,
60
- isLoading: Bool,
61
- appName: String,
62
- loadingTitle: String = "Capturing preview",
63
- unavailableTitle: String = "Preview unavailable",
64
- style: WindowPreviewCardStyle = WindowPreviewCardStyle(),
65
- holdingPreviousPreview: Bool = false
66
- ) {
67
- self.init(
68
- image: image,
69
- isLoading: isLoading,
70
- appName: appName,
71
- loadingTitle: loadingTitle,
72
- unavailableTitle: unavailableTitle,
73
- style: style,
74
- holdingPreviousPreview: holdingPreviousPreview,
75
- overlay: { EmptyView() }
76
- )
77
- }
78
- }
79
-
80
- private struct WindowPreviewPlaceholder: View {
81
- let icon: String
82
- let title: String
83
- let subtitle: String
84
-
85
- var body: some View {
86
- VStack(spacing: 8) {
87
- Image(systemName: icon)
88
- .font(.system(size: 18, weight: .medium))
89
- .foregroundColor(Palette.textMuted.opacity(0.7))
90
- Text(title)
91
- .font(Typo.monoBold(10))
92
- .foregroundColor(Palette.textMuted)
93
- Text(subtitle)
94
- .font(Typo.mono(9))
95
- .foregroundColor(Palette.textDim)
96
- .lineLimit(1)
97
- }
98
- .padding(16)
99
- }
100
- }
@@ -1,112 +0,0 @@
1
- import AppKit
2
- import SwiftUI
3
-
4
- final class WindowPreviewStore: ObservableObject {
5
- static let shared = WindowPreviewStore()
6
-
7
- @Published private var images: [UInt32: NSImage] = [:]
8
- @Published private var loading: Set<UInt32> = []
9
-
10
- private var lastAttemptAt: [UInt32: Date] = [:]
11
- private var accessOrder: [UInt32] = []
12
- private let maxCached = 15
13
- private let queue = DispatchQueue(label: "com.arach.lattices.window-preview", qos: .userInitiated)
14
- private let previewMaxSize = NSSize(width: 360, height: 190)
15
-
16
- func image(for wid: UInt32) -> NSImage? {
17
- if images[wid] != nil {
18
- touchLRU(wid)
19
- }
20
- return images[wid]
21
- }
22
-
23
- func hasSettled(_ wid: UInt32) -> Bool {
24
- images[wid] != nil || (lastAttemptAt[wid] != nil && !loading.contains(wid))
25
- }
26
-
27
- func isLoading(_ wid: UInt32) -> Bool {
28
- loading.contains(wid)
29
- }
30
-
31
- func prewarm(windows: [WindowEntry], limit: Int = 4) {
32
- for window in windows.prefix(limit) {
33
- load(window: window)
34
- }
35
- }
36
-
37
- func load(window: WindowEntry) {
38
- if images[window.wid] != nil || loading.contains(window.wid) {
39
- return
40
- }
41
-
42
- let now = Date()
43
- if let lastAttemptAt = lastAttemptAt[window.wid], now.timeIntervalSince(lastAttemptAt) < 1.0 {
44
- return
45
- }
46
- lastAttemptAt[window.wid] = now
47
-
48
- loading.insert(window.wid)
49
- let wid = window.wid
50
- let frame = window.frame
51
- let startedAt = Date()
52
-
53
- queue.async { [weak self] in
54
- guard let self else { return }
55
-
56
- let cgImage = WindowCapture.image(
57
- listOption: .optionIncludingWindow,
58
- windowID: CGWindowID(wid),
59
- imageOption: [.boundsIgnoreFraming, .nominalResolution]
60
- )
61
-
62
- let image = cgImage.map {
63
- NSImage(
64
- cgImage: $0,
65
- size: self.previewSize(for: frame)
66
- )
67
- }
68
-
69
- DispatchQueue.main.async {
70
- self.loading.remove(wid)
71
- let elapsedMs = Int(Date().timeIntervalSince(startedAt) * 1000)
72
- if let image {
73
- self.images[wid] = image
74
- self.touchLRU(wid)
75
- self.evictIfNeeded()
76
- if elapsedMs >= 80 {
77
- DiagnosticLog.shared.info("HUDPreview: captured wid=\(wid) in \(elapsedMs)ms")
78
- }
79
- } else {
80
- DiagnosticLog.shared.info("HUDPreview: capture unavailable wid=\(wid) after \(elapsedMs)ms")
81
- }
82
- }
83
- }
84
- }
85
-
86
- private func touchLRU(_ wid: UInt32) {
87
- accessOrder.removeAll { $0 == wid }
88
- accessOrder.append(wid)
89
- }
90
-
91
- private func evictIfNeeded() {
92
- while images.count > maxCached, let oldest = accessOrder.first {
93
- accessOrder.removeFirst()
94
- images.removeValue(forKey: oldest)
95
- lastAttemptAt.removeValue(forKey: oldest)
96
- }
97
- }
98
-
99
- private func previewSize(for frame: WindowFrame) -> NSSize {
100
- let width = max(CGFloat(frame.w), CGFloat(1))
101
- let height = max(CGFloat(frame.h), CGFloat(1))
102
- let scale = min(
103
- previewMaxSize.width / width,
104
- previewMaxSize.height / height,
105
- CGFloat(1)
106
- )
107
- return NSSize(
108
- width: max(CGFloat(1), width * scale),
109
- height: max(CGFloat(1), height * scale)
110
- )
111
- }
112
- }
@@ -1,76 +0,0 @@
1
- import Combine
2
- import Foundation
3
-
4
- struct SelectedWindowSummary: Identifiable, Equatable {
5
- let wid: UInt32
6
- let app: String
7
- let title: String
8
- let latticesSession: String?
9
-
10
- var id: UInt32 { wid }
11
-
12
- var displayTitle: String {
13
- if !title.isEmpty { return title }
14
- if let latticesSession, !latticesSession.isEmpty { return latticesSession }
15
- return app
16
- }
17
- }
18
-
19
- final class WindowSelectionStore: ObservableObject {
20
- static let shared = WindowSelectionStore()
21
-
22
- @Published private(set) var windows: [SelectedWindowSummary] = []
23
- @Published private(set) var source: String?
24
- @Published private(set) var updatedAt: Date?
25
-
26
- private init() {}
27
-
28
- var isActive: Bool { !windows.isEmpty }
29
- var windowIds: [UInt32] { windows.map(\.wid) }
30
- var count: Int { windows.count }
31
- var sourceLabel: String? {
32
- switch source {
33
- case "desktop-inventory": return "window selector"
34
- case "screen-map": return "screen map"
35
- case let value?: return value
36
- case nil: return nil
37
- }
38
- }
39
-
40
- func setSelection(_ windows: [SelectedWindowSummary], source: String) {
41
- let unique = Array(
42
- Dictionary(uniqueKeysWithValues: windows.map { ($0.wid, $0) }).values
43
- ).sorted { lhs, rhs in
44
- if lhs.app == rhs.app { return lhs.wid < rhs.wid }
45
- return lhs.app.localizedCaseInsensitiveCompare(rhs.app) == .orderedAscending
46
- }
47
-
48
- DispatchQueue.main.async {
49
- self.windows = unique
50
- self.source = source
51
- self.updatedAt = Date()
52
- }
53
- }
54
-
55
- func clear(source: String? = nil) {
56
- DispatchQueue.main.async {
57
- if let source, let current = self.source, current != source {
58
- return
59
- }
60
- self.windows = []
61
- self.source = source ?? self.source
62
- self.updatedAt = Date()
63
- }
64
- }
65
-
66
- func summary(maxItems: Int = 3) -> String {
67
- guard !windows.isEmpty else { return "No selection" }
68
- let titles = windows.prefix(maxItems).map { item in
69
- item.app == item.displayTitle ? item.app : "\(item.app): \(item.displayTitle)"
70
- }
71
- if windows.count > maxItems {
72
- return titles.joined(separator: " • ") + " +\(windows.count - maxItems)"
73
- }
74
- return titles.joined(separator: " • ")
75
- }
76
- }