@lattices/cli 0.4.2 → 0.4.6

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 (146) 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/AppShell/App.swift +20 -0
  7. package/app/Sources/{AppDelegate.swift → AppShell/AppDelegate.swift} +94 -34
  8. package/app/Sources/{AppShellView.swift → AppShell/AppShellView.swift} +12 -1
  9. package/app/Sources/AppShell/AppUpdater.swift +92 -0
  10. package/app/Sources/AppShell/CliActionLauncher.swift +50 -0
  11. package/app/Sources/{HomeDashboardView.swift → AppShell/HomeDashboardView.swift} +18 -10
  12. package/app/Sources/AppShell/LatticesRuntime.swift +61 -0
  13. package/app/Sources/{MainView.swift → AppShell/MainView.swift} +351 -191
  14. package/app/Sources/{OnboardingView.swift → AppShell/OnboardingView.swift} +30 -16
  15. package/app/Sources/{Preferences.swift → AppShell/Preferences.swift} +78 -0
  16. package/app/Sources/{SettingsView.swift → AppShell/SettingsView.swift} +869 -152
  17. package/app/Sources/{HotkeyStore.swift → Core/Actions/HotkeyStore.swift} +9 -5
  18. package/app/Sources/{IntentEngine.swift → Core/Actions/IntentEngine.swift} +51 -27
  19. package/app/Sources/Core/Actions/IntentSchema.swift +94 -0
  20. package/app/Sources/{Intents → Core/Actions/Intents}/LatticeIntent.swift +0 -25
  21. package/app/Sources/{PaletteCommand.swift → Core/Actions/PaletteCommand.swift} +26 -6
  22. package/app/Sources/{VoiceIntentResolver.swift → Core/Actions/VoiceIntentResolver.swift} +46 -4
  23. package/app/Sources/Core/Companion/CompanionActivityLog.swift +70 -0
  24. package/app/Sources/Core/Companion/CompanionKeyboardController.swift +141 -0
  25. package/app/Sources/Core/Companion/LatticesCompanionBridgeServer.swift +438 -0
  26. package/app/Sources/Core/Companion/LatticesCompanionCockpit.swift +555 -0
  27. package/app/Sources/Core/Companion/LatticesCompanionSecurityCoordinator.swift +594 -0
  28. package/app/Sources/Core/Companion/LatticesCompanionTrackpadController.swift +204 -0
  29. package/app/Sources/Core/Companion/LatticesDeckHost.swift +1463 -0
  30. package/app/Sources/{LatticesApi.swift → Core/Daemon/LatticesApi.swift} +125 -4
  31. package/app/Sources/{AppTypeClassifier.swift → Core/Desktop/AppTypeClassifier.swift} +36 -0
  32. package/app/Sources/{DesktopModel.swift → Core/Desktop/DesktopModel.swift} +6 -8
  33. package/app/Sources/Core/Desktop/MouseFinder.swift +527 -0
  34. package/app/Sources/Core/Desktop/SessionWindowLocator.swift +139 -0
  35. package/app/Sources/Core/Desktop/WindowDragSnapController.swift +628 -0
  36. package/app/Sources/Core/Desktop/WindowPreviewCard.swift +100 -0
  37. package/app/Sources/Core/Desktop/WindowPreviewStore.swift +113 -0
  38. package/app/Sources/Core/Desktop/WindowSelectionStore.swift +76 -0
  39. package/app/Sources/{WindowTiler.swift → Core/Desktop/WindowTiler.swift} +351 -172
  40. package/app/Sources/Core/Input/MouseGestureConfig.swift +364 -0
  41. package/app/Sources/Core/Input/MouseGestureController.swift +1203 -0
  42. package/app/Sources/Core/Input/MouseInputDeviceStore.swift +98 -0
  43. package/app/Sources/Core/Input/MouseInputEventViewer.swift +272 -0
  44. package/app/Sources/Core/Input/MouseShortcutStore.swift +107 -0
  45. package/app/Sources/{CommandModeState.swift → Core/Overlays/CommandMode/CommandModeState.swift} +127 -24
  46. package/app/Sources/{CommandModeView.swift → Core/Overlays/CommandMode/CommandModeView.swift} +492 -79
  47. package/app/Sources/Core/Overlays/CommandPalette/CommandPaletteWindow.swift +67 -0
  48. package/app/Sources/{CheatSheetHUD.swift → Core/Overlays/HUD/CheatSheetHUD.swift} +1 -0
  49. package/app/Sources/{HUDRightBar.swift → Core/Overlays/HUD/HUDRightBar.swift} +23 -201
  50. package/app/Sources/{LauncherHUD.swift → Core/Overlays/HUD/LauncherHUD.swift} +12 -26
  51. package/app/Sources/{OmniSearchView.swift → Core/Overlays/OmniSearch/OmniSearchView.swift} +136 -2
  52. package/app/Sources/{OmniSearchWindow.swift → Core/Overlays/OmniSearch/OmniSearchWindow.swift} +21 -32
  53. package/app/Sources/Core/Overlays/OverlayPanelShell.swift +241 -0
  54. package/app/Sources/{ScreenMapState.swift → Core/Overlays/ScreenMap/ScreenMapState.swift} +116 -32
  55. package/app/Sources/{ScreenMapView.swift → Core/Overlays/ScreenMap/ScreenMapView.swift} +510 -524
  56. package/app/Sources/{ScreenMapWindowController.swift → Core/Overlays/ScreenMap/ScreenMapWindowController.swift} +12 -4
  57. package/app/Sources/{VoiceCommandWindow.swift → Core/Overlays/Voice/VoiceCommandWindow.swift} +46 -53
  58. package/app/Sources/Core/Pi/PiAuthNextStepCard.swift +148 -0
  59. package/app/Sources/Core/Pi/PiAuthPromptCard.swift +90 -0
  60. package/app/Sources/{PiChatDock.swift → Core/Pi/PiChatDock.swift} +137 -74
  61. package/app/Sources/{PiChatSession.swift → Core/Pi/PiChatSession.swift} +608 -108
  62. package/app/Sources/Core/Pi/PiInstallCallout.swift +86 -0
  63. package/app/Sources/Core/Pi/PiProviderSetupCallout.swift +99 -0
  64. package/app/Sources/{PiWorkspaceView.swift → Core/Pi/PiWorkspaceView.swift} +174 -77
  65. package/app/Sources/{PermissionChecker.swift → Core/System/PermissionChecker.swift} +76 -2
  66. package/app/Sources/Core/System/SystemTelemetryMonitor.swift +273 -0
  67. package/app/Sources/{HandsOffSession.swift → Core/Voice/HandsOffSession.swift} +15 -4
  68. package/app/Sources/{WorkspaceManager.swift → Core/Workspace/WorkspaceManager.swift} +288 -0
  69. package/bin/assistant-intelligence.ts +874 -0
  70. package/bin/handsoff-infer.ts +16 -209
  71. package/bin/handsoff-worker.ts +45 -258
  72. package/bin/lattices-app.ts +62 -0
  73. package/bin/lattices-dev +4 -0
  74. package/bin/lattices.ts +125 -14
  75. package/docs/agents.md +14 -0
  76. package/docs/api.md +55 -0
  77. package/docs/app.md +3 -0
  78. package/docs/companion-deck.md +180 -0
  79. package/docs/component-extraction-roadmap.md +392 -0
  80. package/docs/config.md +25 -0
  81. package/docs/tiling-reference.md +55 -0
  82. package/docs/voice-error-model.md +73 -0
  83. package/package.json +4 -1
  84. package/app/Sources/App.swift +0 -10
  85. package/app/Sources/CommandPaletteWindow.swift +0 -134
  86. package/app/Sources/MouseFinder.swift +0 -222
  87. /package/app/Sources/{KeyRecorderView.swift → AppShell/KeyRecorderView.swift} +0 -0
  88. /package/app/Sources/{MainWindow.swift → AppShell/MainWindow.swift} +0 -0
  89. /package/app/Sources/{SettingsWindow.swift → AppShell/SettingsWindow.swift} +0 -0
  90. /package/app/Sources/{HotkeyManager.swift → Core/Actions/HotkeyManager.swift} +0 -0
  91. /package/app/Sources/{Intents → Core/Actions/Intents}/CreateLayerIntent.swift +0 -0
  92. /package/app/Sources/{Intents → Core/Actions/Intents}/DistributeIntent.swift +0 -0
  93. /package/app/Sources/{Intents → Core/Actions/Intents}/FocusIntent.swift +0 -0
  94. /package/app/Sources/{Intents → Core/Actions/Intents}/HelpIntent.swift +0 -0
  95. /package/app/Sources/{Intents → Core/Actions/Intents}/KillIntent.swift +0 -0
  96. /package/app/Sources/{Intents → Core/Actions/Intents}/LaunchIntent.swift +0 -0
  97. /package/app/Sources/{Intents → Core/Actions/Intents}/ListSessionsIntent.swift +0 -0
  98. /package/app/Sources/{Intents → Core/Actions/Intents}/ListWindowsIntent.swift +0 -0
  99. /package/app/Sources/{Intents → Core/Actions/Intents}/ScanIntent.swift +0 -0
  100. /package/app/Sources/{Intents → Core/Actions/Intents}/SearchIntent.swift +0 -0
  101. /package/app/Sources/{Intents → Core/Actions/Intents}/SwitchLayerIntent.swift +0 -0
  102. /package/app/Sources/{Intents → Core/Actions/Intents}/TileIntent.swift +0 -0
  103. /package/app/Sources/{DaemonProtocol.swift → Core/Daemon/DaemonProtocol.swift} +0 -0
  104. /package/app/Sources/{DaemonServer.swift → Core/Daemon/DaemonServer.swift} +0 -0
  105. /package/app/Sources/{AccessibilityTextExtractor.swift → Core/Desktop/AccessibilityTextExtractor.swift} +0 -0
  106. /package/app/Sources/{DesktopModelTypes.swift → Core/Desktop/DesktopModelTypes.swift} +0 -0
  107. /package/app/Sources/{InventoryManager.swift → Core/Desktop/InventoryManager.swift} +0 -0
  108. /package/app/Sources/{InventoryPath.swift → Core/Desktop/InventoryPath.swift} +0 -0
  109. /package/app/Sources/{OcrModel.swift → Core/Desktop/OcrModel.swift} +0 -0
  110. /package/app/Sources/{OcrStore.swift → Core/Desktop/OcrStore.swift} +0 -0
  111. /package/app/Sources/{PlacementSpec.swift → Core/Desktop/PlacementSpec.swift} +0 -0
  112. /package/app/Sources/{TilePickerView.swift → Core/Desktop/TilePickerView.swift} +0 -0
  113. /package/app/Sources/{AppWindowShell.swift → Core/Overlays/AppWindowShell.swift} +0 -0
  114. /package/app/Sources/{CommandModeWindow.swift → Core/Overlays/CommandMode/CommandModeWindow.swift} +0 -0
  115. /package/app/Sources/{CommandPaletteView.swift → Core/Overlays/CommandPalette/CommandPaletteView.swift} +0 -0
  116. /package/app/Sources/{HUDBottomBar.swift → Core/Overlays/HUD/HUDBottomBar.swift} +0 -0
  117. /package/app/Sources/{HUDController.swift → Core/Overlays/HUD/HUDController.swift} +0 -0
  118. /package/app/Sources/{HUDLeftBar.swift → Core/Overlays/HUD/HUDLeftBar.swift} +0 -0
  119. /package/app/Sources/{HUDMinimap.swift → Core/Overlays/HUD/HUDMinimap.swift} +0 -0
  120. /package/app/Sources/{HUDState.swift → Core/Overlays/HUD/HUDState.swift} +0 -0
  121. /package/app/Sources/{HUDTopBar.swift → Core/Overlays/HUD/HUDTopBar.swift} +0 -0
  122. /package/app/Sources/{LayerBezel.swift → Core/Overlays/HUD/LayerBezel.swift} +0 -0
  123. /package/app/Sources/{OmniSearchState.swift → Core/Overlays/OmniSearch/OmniSearchState.swift} +0 -0
  124. /package/app/Sources/{DiagnosticLog.swift → Core/System/DiagnosticLog.swift} +0 -0
  125. /package/app/Sources/{EventBus.swift → Core/System/EventBus.swift} +0 -0
  126. /package/app/Sources/{ProcessModel.swift → Core/System/ProcessModel.swift} +0 -0
  127. /package/app/Sources/{ProcessQuery.swift → Core/System/ProcessQuery.swift} +0 -0
  128. /package/app/Sources/{AdvisorLearningStore.swift → Core/Voice/AdvisorLearningStore.swift} +0 -0
  129. /package/app/Sources/{AgentSession.swift → Core/Voice/AgentSession.swift} +0 -0
  130. /package/app/Sources/{AudioProvider.swift → Core/Voice/AudioProvider.swift} +0 -0
  131. /package/app/Sources/{VoiceChatView.swift → Core/Voice/VoiceChatView.swift} +0 -0
  132. /package/app/Sources/{VoxClient.swift → Core/Voice/VoxClient.swift} +0 -0
  133. /package/app/Sources/{Project.swift → Core/Workspace/Project.swift} +0 -0
  134. /package/app/Sources/{ProjectScanner.swift → Core/Workspace/ProjectScanner.swift} +0 -0
  135. /package/app/Sources/{SessionLayerStore.swift → Core/Workspace/SessionLayerStore.swift} +0 -0
  136. /package/app/Sources/{SessionManager.swift → Core/Workspace/SessionManager.swift} +0 -0
  137. /package/app/Sources/{Terminal.swift → Core/Workspace/Terminal/Terminal.swift} +0 -0
  138. /package/app/Sources/{TerminalQuery.swift → Core/Workspace/Terminal/TerminalQuery.swift} +0 -0
  139. /package/app/Sources/{TerminalSynthesizer.swift → Core/Workspace/Terminal/TerminalSynthesizer.swift} +0 -0
  140. /package/app/Sources/{TmuxModel.swift → Core/Workspace/Tmux/TmuxModel.swift} +0 -0
  141. /package/app/Sources/{TmuxQuery.swift → Core/Workspace/Tmux/TmuxQuery.swift} +0 -0
  142. /package/app/Sources/{ActionRow.swift → UI/ActionRow.swift} +0 -0
  143. /package/app/Sources/{OrphanRow.swift → UI/OrphanRow.swift} +0 -0
  144. /package/app/Sources/{ProjectRow.swift → UI/ProjectRow.swift} +0 -0
  145. /package/app/Sources/{TabGroupRow.swift → UI/TabGroupRow.swift} +0 -0
  146. /package/app/Sources/{Theme.swift → UI/Theme.swift} +0 -0
@@ -1,5 +1,6 @@
1
1
  import AppKit
2
2
  import ApplicationServices
3
+ import DeckKit
3
4
  import Foundation
4
5
 
5
6
  // MARK: - Registry Types
@@ -197,6 +198,7 @@ final class LatticesApi {
197
198
  api.model(ApiModel(name: "Space", fields: [
198
199
  Field(name: "id", type: "int", required: true, description: "Space ID"),
199
200
  Field(name: "index", type: "int", required: true, description: "Space index"),
201
+ Field(name: "name", type: "string", required: true, description: "Lattices display name for the space"),
200
202
  Field(name: "display", type: "int", required: true, description: "Display index"),
201
203
  Field(name: "isCurrent", type: "bool", required: true, description: "Whether this is the active space"),
202
204
  ]))
@@ -736,6 +738,7 @@ final class LatticesApi {
736
738
  .object([
737
739
  "id": .int(space.id),
738
740
  "index": .int(space.index),
741
+ "name": .string(Self.defaultSpaceName(for: space.index)),
739
742
  "display": .int(space.display),
740
743
  "isCurrent": .bool(space.isCurrent)
741
744
  ])
@@ -773,6 +776,45 @@ final class LatticesApi {
773
776
  }
774
777
  ))
775
778
 
779
+ api.register(Endpoint(
780
+ method: "deck.manifest",
781
+ description: "Get the shared companion deck manifest exposed by the macOS app",
782
+ access: .read,
783
+ params: [],
784
+ returns: .custom("DeckKit manifest for the Lattices companion surface"),
785
+ handler: { _ in
786
+ try Self.encodeDeckValue(LatticesDeckHost.shared.manifestSync())
787
+ }
788
+ ))
789
+
790
+ api.register(Endpoint(
791
+ method: "deck.snapshot",
792
+ description: "Get the current companion deck runtime snapshot",
793
+ access: .read,
794
+ params: [],
795
+ returns: .custom("DeckKit runtime snapshot with voice, layout, switcher, and history state"),
796
+ handler: { _ in
797
+ try Self.encodeDeckValue(LatticesDeckHost.shared.runtimeSnapshotSync())
798
+ }
799
+ ))
800
+
801
+ api.register(Endpoint(
802
+ method: "deck.perform",
803
+ description: "Perform a companion deck action and return the updated runtime snapshot",
804
+ access: .mutate,
805
+ params: [
806
+ Param(name: "pageID", type: "string", required: false, description: "Deck page ID"),
807
+ Param(name: "actionID", type: "string", required: true, description: "Deck action identifier"),
808
+ Param(name: "payload", type: "object", required: false, description: "Deck action payload"),
809
+ ],
810
+ returns: .custom("DeckKit action result"),
811
+ handler: { params in
812
+ let request = try Self.decodeDeckActionRequest(from: params)
813
+ let result = try LatticesDeckHost.shared.performSync(request)
814
+ return try Self.encodeDeckValue(result)
815
+ }
816
+ ))
817
+
776
818
  api.register(Endpoint(
777
819
  method: "daemon.status",
778
820
  description: "Get daemon status including uptime and counts",
@@ -1339,10 +1381,11 @@ final class LatticesApi {
1339
1381
 
1340
1382
  api.register(Endpoint(
1341
1383
  method: "layout.distribute",
1342
- description: "Distribute windows evenly in a grid, optionally filtered by app and constrained to a screen region",
1384
+ description: "Distribute windows evenly in a grid, optionally filtered by app or type and constrained to a screen region",
1343
1385
  access: .mutate,
1344
1386
  params: [
1345
1387
  Param(name: "app", type: "string", required: false, description: "Filter to windows of this app (e.g. 'iTerm2')"),
1388
+ Param(name: "type", type: "string", required: false, description: "Filter to an app type (e.g. 'terminal', 'browser', 'editor')"),
1346
1389
  Param(name: "region", type: "string", required: false, description: "Constrain grid to a screen region (e.g. 'right', 'left', 'top-right'). Uses tile position names."),
1347
1390
  ],
1348
1391
  returns: .ok,
@@ -1351,9 +1394,11 @@ final class LatticesApi {
1351
1394
  if case .object(let obj) = params {
1352
1395
  dict = obj
1353
1396
  }
1354
- // If app is provided, switch to app scope
1397
+ // Explicit filters select the matching scope automatically.
1355
1398
  if dict["app"] != nil && dict["scope"] == nil {
1356
1399
  dict["scope"] = .string("app")
1400
+ } else if dict["type"] != nil && dict["scope"] == nil {
1401
+ dict["scope"] = .string("type")
1357
1402
  } else {
1358
1403
  dict["scope"] = dict["scope"] ?? .string("visible")
1359
1404
  }
@@ -1367,9 +1412,10 @@ final class LatticesApi {
1367
1412
  description: "Optimize a set of windows using an explicit scope and strategy",
1368
1413
  access: .mutate,
1369
1414
  params: [
1370
- Param(name: "scope", type: "string", required: false, description: "Optimization scope: visible, active-app, app, or selection"),
1415
+ Param(name: "scope", type: "string", required: false, description: "Optimization scope: visible, active-app, active-type, app, type, or selection"),
1371
1416
  Param(name: "strategy", type: "string", required: false, description: "Optimization strategy: balanced or mosaic"),
1372
1417
  Param(name: "app", type: "string", required: false, description: "App name for app-scoped optimization"),
1418
+ Param(name: "type", type: "string", required: false, description: "App type for type-scoped optimization"),
1373
1419
  Param(name: "title", type: "string", required: false, description: "Optional title substring for app-scoped optimization"),
1374
1420
  Param(name: "windowIds", type: "[uint32]", required: false, description: "Explicit window selection for selection scope"),
1375
1421
  ],
@@ -1872,6 +1918,27 @@ final class LatticesApi {
1872
1918
  }
1873
1919
 
1874
1920
  private extension LatticesApi {
1921
+ static func decodeDeckActionRequest(from json: JSON?) throws -> DeckActionRequest {
1922
+ guard let json else {
1923
+ throw RouterError.missingParam("actionID")
1924
+ }
1925
+ guard case .object(var object) = json else {
1926
+ throw RouterError.custom("Invalid deck action request: params must be an object")
1927
+ }
1928
+ object["payload"] = object["payload"] ?? .object([:])
1929
+ let data = try JSONEncoder().encode(JSON.object(object))
1930
+ do {
1931
+ return try JSONDecoder().decode(DeckActionRequest.self, from: data)
1932
+ } catch {
1933
+ throw RouterError.custom("Invalid deck action request: \(error.localizedDescription)")
1934
+ }
1935
+ }
1936
+
1937
+ static func encodeDeckValue<T: Encodable>(_ value: T) throws -> JSON {
1938
+ let data = try JSONEncoder().encode(value)
1939
+ return try JSONDecoder().decode(JSON.self, from: data)
1940
+ }
1941
+
1875
1942
  static func parsePlacement(from json: JSON?) -> PlacementSpec? {
1876
1943
  PlacementSpec(json: json)
1877
1944
  }
@@ -2070,6 +2137,19 @@ private extension LatticesApi {
2070
2137
  ])
2071
2138
  }
2072
2139
 
2140
+ static func defaultSpaceName(for index: Int) -> String {
2141
+ if let layers = WorkspaceManager.shared.config?.layers,
2142
+ layers.indices.contains(index - 1) {
2143
+ return layers[index - 1].label
2144
+ }
2145
+
2146
+ let defaults = ["main", "code", "chat", "review", "media", "notes", "ops", "admin", "scratch"]
2147
+ if defaults.indices.contains(index - 1) {
2148
+ return defaults[index - 1]
2149
+ }
2150
+ return "space \(index)"
2151
+ }
2152
+
2073
2153
  static func executeSpaceOptimization(params: JSON?) throws -> JSON {
2074
2154
  let scope = try parseOptimizationScope(from: params)
2075
2155
  let strategy = try parseOptimizationStrategy(params?["strategy"]?.stringValue)
@@ -2135,10 +2215,15 @@ private extension LatticesApi {
2135
2215
  if params?["app"] != nil {
2136
2216
  return "app"
2137
2217
  }
2218
+ if params?["type"] != nil {
2219
+ return "type"
2220
+ }
2138
2221
 
2139
2222
  let scope = normalizeToken(params?["scope"]?.stringValue ?? "visible")
2140
2223
  switch scope {
2141
- case "visible", "selection", "app", "active-app", "frontmost-app", "current-app":
2224
+ case "visible", "selection", "app", "type",
2225
+ "active-app", "frontmost-app", "current-app",
2226
+ "active-type", "frontmost-type", "current-type":
2142
2227
  return scope
2143
2228
  default:
2144
2229
  throw RouterError.custom("Unsupported optimization scope: \(params?["scope"]?.stringValue ?? scope)")
@@ -2179,6 +2264,21 @@ private extension LatticesApi {
2179
2264
  (titleFilter == nil || $0.title.localizedCaseInsensitiveContains(titleFilter!))
2180
2265
  })
2181
2266
 
2267
+ case "type":
2268
+ guard let typeName = params?["type"]?.stringValue,
2269
+ let appType = parseOptimizationAppType(typeName) else {
2270
+ trace.append(.string("missing or unknown type for type scope"))
2271
+ return []
2272
+ }
2273
+ trace.append(.string("filtered by type \(appType.rawValue)"))
2274
+ if let titleFilter {
2275
+ trace.append(.string("title contains \(titleFilter)"))
2276
+ }
2277
+ return dedupeWindows(visible.filter {
2278
+ AppTypeClassifier.matches($0.app, type: appType) &&
2279
+ (titleFilter == nil || $0.title.localizedCaseInsensitiveContains(titleFilter!))
2280
+ })
2281
+
2182
2282
  case "active-app", "frontmost-app", "current-app":
2183
2283
  let activeApp = params?["app"]?.stringValue ?? frontmostOptimizableApp()
2184
2284
  guard let activeApp else {
@@ -2194,12 +2294,33 @@ private extension LatticesApi {
2194
2294
  (titleFilter == nil || $0.title.localizedCaseInsensitiveContains(titleFilter!))
2195
2295
  })
2196
2296
 
2297
+ case "active-type", "frontmost-type", "current-type":
2298
+ let activeApp = params?["app"]?.stringValue ?? frontmostOptimizableApp()
2299
+ guard let activeApp else {
2300
+ trace.append(.string("no active app available"))
2301
+ return []
2302
+ }
2303
+ let grouping = AppTypeClassifier.grouping(for: activeApp)
2304
+ trace.append(.string("resolved active type \(grouping.label) from \(activeApp)"))
2305
+ if let titleFilter {
2306
+ trace.append(.string("title contains \(titleFilter)"))
2307
+ }
2308
+ return dedupeWindows(visible.filter {
2309
+ AppTypeClassifier.matches($0.app, grouping: grouping) &&
2310
+ (titleFilter == nil || $0.title.localizedCaseInsensitiveContains(titleFilter!))
2311
+ })
2312
+
2197
2313
  default:
2198
2314
  trace.append(.string("using visible window scope"))
2199
2315
  return dedupeWindows(visible)
2200
2316
  }
2201
2317
  }
2202
2318
 
2319
+ static func parseOptimizationAppType(_ raw: String) -> AppType? {
2320
+ let normalized = normalizeToken(raw)
2321
+ return AppType.allCases.first { $0.rawValue == normalized }
2322
+ }
2323
+
2203
2324
  static func selectedWindowIds(from json: JSON?) -> [UInt32] {
2204
2325
  guard case .array(let values) = json else { return [] }
2205
2326
  return values.compactMap(\.uint32Value)
@@ -13,6 +13,20 @@ enum AppType: String, CaseIterable {
13
13
  var label: String { rawValue }
14
14
  }
15
15
 
16
+ enum AppGrouping {
17
+ case type(AppType)
18
+ case exactApp(String)
19
+
20
+ var label: String {
21
+ switch self {
22
+ case .type(let type):
23
+ return type.label
24
+ case .exactApp(let appName):
25
+ return appName
26
+ }
27
+ }
28
+ }
29
+
16
30
  enum AppTypeClassifier {
17
31
  private static let nameMap: [String: AppType] = [
18
32
  // Terminals
@@ -67,4 +81,26 @@ enum AppTypeClassifier {
67
81
  if lower.contains("slack") || lower.contains("discord") || lower.contains("chat") || lower.contains("teams") { return .chat }
68
82
  return .other
69
83
  }
84
+
85
+ static func grouping(for appName: String) -> AppGrouping {
86
+ switch classify(appName) {
87
+ case .system, .other:
88
+ return .exactApp(appName)
89
+ case let type:
90
+ return .type(type)
91
+ }
92
+ }
93
+
94
+ static func matches(_ appName: String, grouping: AppGrouping) -> Bool {
95
+ switch grouping {
96
+ case .type(let type):
97
+ return classify(appName) == type
98
+ case .exactApp(let exactApp):
99
+ return appName.localizedCaseInsensitiveCompare(exactApp) == .orderedSame
100
+ }
101
+ }
102
+
103
+ static func matches(_ appName: String, type: AppType) -> Bool {
104
+ classify(appName) == type
105
+ }
70
106
  }
@@ -81,6 +81,10 @@ final class DesktopModel: ObservableObject {
81
81
  Array(windows.values).sorted { $0.zIndex < $1.zIndex }
82
82
  }
83
83
 
84
+ func frontmostWindow() -> WindowEntry? {
85
+ windows.values.min { $0.zIndex < $1.zIndex }
86
+ }
87
+
84
88
  func lastInteractionDate(for wid: UInt32) -> Date? {
85
89
  interactionDates[wid]
86
90
  }
@@ -102,8 +106,7 @@ final class DesktopModel: ObservableObject {
102
106
  }
103
107
 
104
108
  func windowForSession(_ session: String) -> WindowEntry? {
105
- let tag = Terminal.windowTag(for: session)
106
- return windows.values.first { $0.title.contains(tag) }
109
+ SessionWindowLocator.cachedWindow(forSession: session, in: windows)
107
110
  }
108
111
 
109
112
  /// Assign a layer tag to a window (in-memory only)
@@ -201,12 +204,7 @@ final class DesktopModel: ObservableObject {
201
204
 
202
205
  let spaceIds = WindowTiler.getSpacesForWindow(wid)
203
206
 
204
- // Extract lattices session tag from title: [lattices:session-name]
205
- var latticesSession: String?
206
- if let range = title.range(of: #"\[lattices:([^\]]+)\]"#, options: .regularExpression) {
207
- let match = String(title[range])
208
- latticesSession = String(match.dropFirst(9).dropLast(1)) // drop "[lattices:" and "]"
209
- }
207
+ let latticesSession = SessionWindowLocator.extractSessionName(from: title)
210
208
 
211
209
  var entry = WindowEntry(
212
210
  wid: wid,