@lattices/cli 0.4.1 → 0.4.5

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 (71) hide show
  1. package/README.md +3 -0
  2. package/app/Info.plist +2 -2
  3. package/app/Lattices.app/Contents/Info.plist +2 -2
  4. package/app/Lattices.app/Contents/MacOS/Lattices +0 -0
  5. package/app/Package.swift +6 -0
  6. package/app/Sources/ActionRow.swift +43 -26
  7. package/app/Sources/App.swift +10 -0
  8. package/app/Sources/AppDelegate.swift +91 -30
  9. package/app/Sources/AppShellView.swift +2 -0
  10. package/app/Sources/AppTypeClassifier.swift +36 -0
  11. package/app/Sources/AppUpdater.swift +92 -0
  12. package/app/Sources/CheatSheetHUD.swift +1 -0
  13. package/app/Sources/CliActionLauncher.swift +50 -0
  14. package/app/Sources/CommandModeView.swift +4 -24
  15. package/app/Sources/CompanionActivityLog.swift +70 -0
  16. package/app/Sources/CompanionKeyboardController.swift +141 -0
  17. package/app/Sources/DesktopModel.swift +4 -0
  18. package/app/Sources/HandsOffSession.swift +53 -16
  19. package/app/Sources/HomeDashboardView.swift +18 -10
  20. package/app/Sources/HotkeyStore.swift +8 -5
  21. package/app/Sources/IntentEngine.swift +7 -1
  22. package/app/Sources/LatticesApi.swift +125 -4
  23. package/app/Sources/LatticesCompanionBridgeServer.swift +438 -0
  24. package/app/Sources/LatticesCompanionCockpit.swift +555 -0
  25. package/app/Sources/LatticesCompanionSecurityCoordinator.swift +594 -0
  26. package/app/Sources/LatticesCompanionTrackpadController.swift +204 -0
  27. package/app/Sources/LatticesDeckHost.swift +1463 -0
  28. package/app/Sources/LatticesRuntime.swift +61 -0
  29. package/app/Sources/MainView.swift +398 -186
  30. package/app/Sources/MouseFinder.swift +335 -30
  31. package/app/Sources/MouseGestureConfig.swift +364 -0
  32. package/app/Sources/MouseGestureController.swift +1203 -0
  33. package/app/Sources/MouseInputDeviceStore.swift +98 -0
  34. package/app/Sources/MouseInputEventViewer.swift +272 -0
  35. package/app/Sources/MouseShortcutStore.swift +107 -0
  36. package/app/Sources/OmniSearchView.swift +136 -2
  37. package/app/Sources/OmniSearchWindow.swift +65 -5
  38. package/app/Sources/OnboardingView.swift +30 -16
  39. package/app/Sources/PaletteCommand.swift +26 -6
  40. package/app/Sources/PermissionChecker.swift +76 -2
  41. package/app/Sources/PiAuthNextStepCard.swift +148 -0
  42. package/app/Sources/PiAuthPromptCard.swift +90 -0
  43. package/app/Sources/PiChatDock.swift +137 -74
  44. package/app/Sources/PiChatSession.swift +608 -108
  45. package/app/Sources/PiInstallCallout.swift +86 -0
  46. package/app/Sources/PiProviderSetupCallout.swift +99 -0
  47. package/app/Sources/PiWorkspaceView.swift +174 -77
  48. package/app/Sources/Preferences.swift +78 -0
  49. package/app/Sources/ScreenMapState.swift +91 -31
  50. package/app/Sources/ScreenMapView.swift +510 -524
  51. package/app/Sources/ScreenMapWindowController.swift +12 -4
  52. package/app/Sources/SettingsView.swift +869 -152
  53. package/app/Sources/SystemTelemetryMonitor.swift +273 -0
  54. package/app/Sources/VoiceCommandWindow.swift +23 -2
  55. package/app/Sources/WindowDragSnapController.swift +628 -0
  56. package/app/Sources/WindowTiler.swift +328 -65
  57. package/app/Sources/WorkspaceManager.swift +288 -0
  58. package/bin/assistant-intelligence.ts +874 -0
  59. package/bin/handsoff-infer.ts +16 -209
  60. package/bin/handsoff-worker.ts +45 -258
  61. package/bin/lattices-app.ts +65 -1
  62. package/bin/lattices-dev +4 -0
  63. package/bin/lattices.ts +125 -14
  64. package/docs/agents.md +14 -0
  65. package/docs/api.md +55 -0
  66. package/docs/app.md +3 -0
  67. package/docs/companion-deck.md +180 -0
  68. package/docs/config.md +25 -0
  69. package/docs/tiling-reference.md +55 -0
  70. package/docs/voice-error-model.md +73 -0
  71. package/package.json +4 -2
@@ -0,0 +1,98 @@
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
+ }
@@ -0,0 +1,272 @@
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
+ }
@@ -0,0 +1,107 @@
1
+ import AppKit
2
+ import Combine
3
+ import Foundation
4
+
5
+ final class MouseShortcutStore: ObservableObject {
6
+ static let shared = MouseShortcutStore()
7
+
8
+ @Published private(set) var config: MouseShortcutConfig
9
+
10
+ let configURL: URL
11
+ private var lastLoadedModifiedDate: Date?
12
+
13
+ private init() {
14
+ let dir = FileManager.default.homeDirectoryForCurrentUser
15
+ .appendingPathComponent(".lattices")
16
+ try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
17
+ self.configURL = dir.appendingPathComponent("mouse-shortcuts.json")
18
+ self.config = .defaults
19
+ ensureConfigFile()
20
+ reload()
21
+ }
22
+
23
+ var tuning: MouseShortcutTuning {
24
+ config.tuning
25
+ }
26
+
27
+ var enabledRules: [MouseShortcutRule] {
28
+ config.rules.filter(\.enabled)
29
+ }
30
+
31
+ var watchedButtonNumbers: Set<Int64> {
32
+ Set(enabledRules.map { Int64($0.trigger.button.rawButtonNumber) })
33
+ }
34
+
35
+ var summaryLines: [String] {
36
+ enabledRules.map { "\($0.trigger.triggerName) -> \($0.action.type.rawValue)" }
37
+ }
38
+
39
+ func ensureConfigFile() {
40
+ guard !FileManager.default.fileExists(atPath: configURL.path) else { return }
41
+ write(config: .defaults)
42
+ }
43
+
44
+ func reload() {
45
+ guard let data = FileManager.default.contents(atPath: configURL.path) else {
46
+ config = .defaults
47
+ return
48
+ }
49
+
50
+ do {
51
+ config = try JSONDecoder().decode(MouseShortcutConfig.self, from: data)
52
+ lastLoadedModifiedDate = modifiedDate()
53
+ } catch {
54
+ DiagnosticLog.shared.error("MouseShortcutStore: failed to decode mouse-shortcuts.json - \(error.localizedDescription)")
55
+ config = .defaults
56
+ }
57
+ }
58
+
59
+ func reloadIfNeeded() {
60
+ let currentModifiedDate = modifiedDate()
61
+ guard currentModifiedDate != lastLoadedModifiedDate else { return }
62
+ reload()
63
+ }
64
+
65
+ func restoreDefaults() {
66
+ write(config: .defaults)
67
+ reload()
68
+ DiagnosticLog.shared.info("Mouse shortcuts restored to defaults")
69
+ }
70
+
71
+ func openConfiguration() {
72
+ ensureConfigFile()
73
+ NSWorkspace.shared.open(configURL)
74
+ }
75
+
76
+ func match(for event: MouseShortcutTriggerEvent) -> MouseShortcutMatchResult? {
77
+ for rule in enabledRules {
78
+ guard rule.trigger.kind == event.kind,
79
+ rule.trigger.button == event.button,
80
+ rule.trigger.direction == event.direction,
81
+ rule.device.matches(event.device) else {
82
+ continue
83
+ }
84
+
85
+ return MouseShortcutMatchResult(
86
+ rule: rule,
87
+ action: rule.action,
88
+ triggerName: rule.trigger.triggerName
89
+ )
90
+ }
91
+
92
+ return nil
93
+ }
94
+
95
+ private func write(config: MouseShortcutConfig) {
96
+ let encoder = JSONEncoder()
97
+ encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
98
+ guard let data = try? encoder.encode(config) else { return }
99
+ try? data.write(to: configURL, options: .atomic)
100
+ lastLoadedModifiedDate = modifiedDate()
101
+ }
102
+
103
+ private func modifiedDate() -> Date? {
104
+ let attrs = try? FileManager.default.attributesOfItem(atPath: configURL.path)
105
+ return attrs?[.modificationDate] as? Date
106
+ }
107
+ }
@@ -3,7 +3,10 @@ import SwiftUI
3
3
  struct OmniSearchView: View {
4
4
  @ObservedObject var state: OmniSearchState
5
5
  var onDismiss: () -> Void
6
+ var isEmbedded: Bool = false
6
7
 
8
+ @ObservedObject private var ocrModel = OcrModel.shared
9
+ @State private var expandedOcrWindow: UInt32?
7
10
  @FocusState private var searchFocused: Bool
8
11
 
9
12
  var body: some View {
@@ -46,8 +49,22 @@ struct OmniSearchView: View {
46
49
  resultsView
47
50
  }
48
51
  }
49
- .frame(minWidth: 520, idealWidth: 520, maxWidth: 700, minHeight: 360, idealHeight: 480, maxHeight: 600)
50
- .background(PanelBackground())
52
+ .frame(
53
+ minWidth: isEmbedded ? 0 : 520,
54
+ idealWidth: isEmbedded ? nil : 520,
55
+ maxWidth: isEmbedded ? .infinity : 700,
56
+ minHeight: isEmbedded ? 0 : 360,
57
+ idealHeight: isEmbedded ? nil : 480,
58
+ maxHeight: isEmbedded ? .infinity : 600,
59
+ alignment: .top
60
+ )
61
+ .background {
62
+ if isEmbedded {
63
+ Palette.bg
64
+ } else {
65
+ PanelBackground()
66
+ }
67
+ }
51
68
  .preferredColorScheme(.dark)
52
69
  .onAppear {
53
70
  searchFocused = true
@@ -234,6 +251,10 @@ struct OmniSearchView: View {
234
251
  }
235
252
  .padding(.horizontal, 14)
236
253
  }
254
+
255
+ if !recentOcrResults.isEmpty {
256
+ ocrResultsSection
257
+ }
237
258
  } else {
238
259
  Text("Loading...")
239
260
  .font(Typo.mono(11))
@@ -245,6 +266,105 @@ struct OmniSearchView: View {
245
266
  }
246
267
  }
247
268
 
269
+ private var recentOcrResults: [OcrWindowResult] {
270
+ Array(ocrModel.results.values.sorted { $0.timestamp > $1.timestamp }.prefix(10))
271
+ }
272
+
273
+ private var ocrResultsSection: some View {
274
+ summarySection("SCREEN TEXT", icon: "doc.text.magnifyingglass", count: ocrModel.results.count) {
275
+ ForEach(recentOcrResults, id: \.wid) { result in
276
+ ocrResultRow(result)
277
+ }
278
+ }
279
+ }
280
+
281
+ private func ocrResultRow(_ result: OcrWindowResult) -> some View {
282
+ let isExpanded = expandedOcrWindow == result.wid
283
+ let title = result.title.isEmpty ? "Untitled" : result.title
284
+ let preview = compactPreview(result.fullText)
285
+
286
+ return VStack(alignment: .leading, spacing: 5) {
287
+ Button {
288
+ withAnimation(.easeOut(duration: 0.12)) {
289
+ expandedOcrWindow = isExpanded ? nil : result.wid
290
+ }
291
+ } label: {
292
+ VStack(alignment: .leading, spacing: 4) {
293
+ HStack(spacing: 7) {
294
+ Image(systemName: isExpanded ? "chevron.down" : "chevron.right")
295
+ .font(.system(size: 8, weight: .semibold))
296
+ .foregroundColor(Palette.textMuted)
297
+ .frame(width: 9)
298
+
299
+ Text(result.app)
300
+ .font(Typo.monoBold(11))
301
+ .foregroundColor(Palette.textDim)
302
+ .lineLimit(1)
303
+
304
+ Text(sourceLabel(result.source))
305
+ .font(Typo.mono(8))
306
+ .foregroundColor(Palette.textMuted)
307
+ .padding(.horizontal, 4)
308
+ .padding(.vertical, 1)
309
+ .background(
310
+ RoundedRectangle(cornerRadius: 3)
311
+ .fill(Palette.surface.opacity(0.8))
312
+ )
313
+
314
+ Spacer()
315
+
316
+ Text(relativeTime(result.timestamp))
317
+ .font(Typo.mono(9))
318
+ .foregroundColor(Palette.textMuted)
319
+ }
320
+
321
+ Text(title)
322
+ .font(Typo.mono(10))
323
+ .foregroundColor(Palette.textMuted)
324
+ .lineLimit(1)
325
+
326
+ if !isExpanded && !preview.isEmpty {
327
+ Text(preview)
328
+ .font(Typo.mono(9))
329
+ .foregroundColor(Palette.textMuted.opacity(0.75))
330
+ .lineLimit(2)
331
+ }
332
+ }
333
+ .padding(8)
334
+ .background(
335
+ RoundedRectangle(cornerRadius: 5)
336
+ .fill(Palette.surface.opacity(isExpanded ? 0.72 : 0.38))
337
+ .overlay(
338
+ RoundedRectangle(cornerRadius: 5)
339
+ .strokeBorder(Color.white.opacity(isExpanded ? 0.10 : 0.05), lineWidth: 0.5)
340
+ )
341
+ )
342
+ .contentShape(Rectangle())
343
+ }
344
+ .buttonStyle(.plain)
345
+
346
+ if isExpanded {
347
+ ScrollView {
348
+ Text(result.fullText.isEmpty ? "No text captured." : result.fullText)
349
+ .font(Typo.mono(10))
350
+ .foregroundColor(Palette.textDim)
351
+ .textSelection(.enabled)
352
+ .frame(maxWidth: .infinity, alignment: .leading)
353
+ .padding(8)
354
+ }
355
+ .frame(maxHeight: 140)
356
+ .background(
357
+ RoundedRectangle(cornerRadius: 5)
358
+ .fill(Color.black.opacity(0.22))
359
+ .overlay(
360
+ RoundedRectangle(cornerRadius: 5)
361
+ .strokeBorder(Color.white.opacity(0.06), lineWidth: 0.5)
362
+ )
363
+ )
364
+ }
365
+ }
366
+ }
367
+
248
368
  private func summarySection<Content: View>(
249
369
  _ title: String,
250
370
  icon: String,
@@ -285,4 +405,18 @@ struct OmniSearchView: View {
285
405
  if seconds < 3600 { return "\(seconds / 60)m ago" }
286
406
  return "\(seconds / 3600)h ago"
287
407
  }
408
+
409
+ private func sourceLabel(_ source: TextSource) -> String {
410
+ switch source {
411
+ case .accessibility: return "AX"
412
+ case .ocr: return "OCR"
413
+ }
414
+ }
415
+
416
+ private func compactPreview(_ text: String) -> String {
417
+ text
418
+ .components(separatedBy: .whitespacesAndNewlines)
419
+ .filter { !$0.isEmpty }
420
+ .joined(separator: " ")
421
+ }
288
422
  }