@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,141 +0,0 @@
1
- import Foundation
2
-
3
- class ProjectScanner: ObservableObject {
4
- static let shared = ProjectScanner()
5
-
6
- @Published var projects: [Project] = []
7
-
8
- private var scanRoot: String
9
-
10
- init(root: String? = nil) {
11
- self.scanRoot = root ?? Preferences.shared.scanRoot
12
- }
13
-
14
- func updateRoot(_ root: String) {
15
- self.scanRoot = root
16
- }
17
-
18
- private static let scanQueue = DispatchQueue(label: "com.lattices.project-scanner", qos: .userInitiated)
19
- private var scanInFlight = false
20
-
21
- func scan() {
22
- guard !scanInFlight else { return }
23
- scanInFlight = true
24
- let root = scanRoot
25
-
26
- Self.scanQueue.async { [weak self] in
27
- guard let self else { return }
28
- let diag = DiagnosticLog.shared
29
-
30
- // Use find to locate all .lattices.json files — no manual directory walking
31
- let tFind = diag.startTimed("ProjectScanner: find .lattices.json")
32
- let task = Process()
33
- task.executableURL = URL(fileURLWithPath: "/usr/bin/find")
34
- task.arguments = [root, "-name", ".lattices.json", "-maxdepth", "3", "-not", "-path", "*/.git/*", "-not", "-path", "*/node_modules/*"]
35
- let pipe = Pipe()
36
- task.standardOutput = pipe
37
- task.standardError = FileHandle.nullDevice
38
- try? task.run()
39
- task.waitUntilExit()
40
- diag.finish(tFind)
41
-
42
- let data = pipe.fileHandleForReading.readDataToEndOfFile()
43
- let output = String(data: data, encoding: .utf8) ?? ""
44
- let configPaths = output.split(separator: "\n").map(String.init).filter { !$0.isEmpty }
45
-
46
- let tParse = diag.startTimed("ProjectScanner: parse \(configPaths.count) configs")
47
- var found: [Project] = []
48
-
49
- for configPath in configPaths.sorted() {
50
- let projectPath = (configPath as NSString).deletingLastPathComponent
51
- let name = (projectPath as NSString).lastPathComponent
52
- let (devCmd, pm) = self.detectDevCommand(at: projectPath)
53
- let paneInfo = self.readPaneInfo(at: configPath)
54
-
55
- var project = Project(
56
- id: projectPath,
57
- path: projectPath,
58
- name: name,
59
- devCommand: devCmd,
60
- packageManager: pm,
61
- hasConfig: true,
62
- paneCount: paneInfo.count,
63
- paneNames: paneInfo.names,
64
- paneSummary: paneInfo.summary,
65
- isRunning: false
66
- )
67
- project.isRunning = self.isSessionRunning(project.sessionName)
68
- found.append(project)
69
- }
70
- diag.finish(tParse)
71
-
72
- diag.info("ProjectScanner: found \(found.count) projects (\(found.filter(\.isRunning).count) running)")
73
- DispatchQueue.main.async {
74
- self.projects = found
75
- self.scanInFlight = false
76
- }
77
- }
78
- }
79
-
80
- func refreshStatus() {
81
- for i in projects.indices {
82
- projects[i].isRunning = isSessionRunning(projects[i].sessionName)
83
- }
84
- }
85
-
86
- // MARK: - Detection
87
-
88
- private func detectDevCommand(at path: String) -> (String?, String?) {
89
- let pkgPath = (path as NSString).appendingPathComponent("package.json")
90
- guard let data = FileManager.default.contents(atPath: pkgPath),
91
- let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
92
- let scripts = json["scripts"] as? [String: String]
93
- else { return (nil, nil) }
94
-
95
- let has = { (f: String) in
96
- FileManager.default.fileExists(atPath: (path as NSString).appendingPathComponent(f))
97
- }
98
-
99
- var pm = "npm"
100
- if has("pnpm-lock.yaml") { pm = "pnpm" }
101
- else if has("bun.lockb") || has("bun.lock") { pm = "bun" }
102
- else if has("yarn.lock") { pm = "yarn" }
103
-
104
- let run = pm == "npm" ? "npm run" : pm
105
- if scripts["dev"] != nil { return ("\(run) dev", pm) }
106
- if scripts["start"] != nil { return ("\(run) start", pm) }
107
- if scripts["serve"] != nil { return ("\(run) serve", pm) }
108
- if scripts["watch"] != nil { return ("\(run) watch", pm) }
109
- return (nil, pm)
110
- }
111
-
112
- private func readPaneInfo(at configPath: String) -> (count: Int, names: [String], summary: String) {
113
- guard let data = FileManager.default.contents(atPath: configPath),
114
- let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
115
- let panes = json["panes"] as? [[String: Any]]
116
- else { return (2, ["claude", "server"], "") }
117
-
118
- let labels = panes.compactMap { pane -> String? in
119
- if let name = pane["name"] as? String { return name }
120
- if let cmd = pane["cmd"] as? String {
121
- let parts = cmd.split(separator: " ")
122
- return parts.first.map(String.init)
123
- }
124
- return nil
125
- }
126
- return (panes.count, labels, labels.joined(separator: " · "))
127
- }
128
-
129
- private static var tmuxPath: String { TmuxQuery.resolvedPath ?? "/opt/homebrew/bin/tmux" }
130
-
131
- private func isSessionRunning(_ name: String) -> Bool {
132
- let task = Process()
133
- task.executableURL = URL(fileURLWithPath: Self.tmuxPath)
134
- task.arguments = ["has-session", "-t", name]
135
- task.standardOutput = FileHandle.nullDevice
136
- task.standardError = FileHandle.nullDevice
137
- try? task.run()
138
- task.waitUntilExit()
139
- return task.terminationStatus == 0
140
- }
141
- }
@@ -1,285 +0,0 @@
1
- import AppKit
2
-
3
- // MARK: - WindowRef
4
-
5
- struct WindowRef: Codable, Identifiable {
6
- let id: String
7
-
8
- // ── Intent (stable, survives restarts) ──
9
- var app: String
10
- var contentHint: String?
11
- var tile: String?
12
- var display: Int?
13
-
14
- // ── Runtime (ephemeral, filled when window is live) ──
15
- var wid: UInt32?
16
- var pid: Int32?
17
- var title: String?
18
- var frame: WindowFrame?
19
-
20
- init(id: String = UUID().uuidString, app: String, contentHint: String? = nil,
21
- tile: String? = nil, display: Int? = nil,
22
- wid: UInt32? = nil, pid: Int32? = nil, title: String? = nil, frame: WindowFrame? = nil) {
23
- self.id = id
24
- self.app = app
25
- self.contentHint = contentHint
26
- self.tile = tile
27
- self.display = display
28
- self.wid = wid
29
- self.pid = pid
30
- self.title = title
31
- self.frame = frame
32
- }
33
- }
34
-
35
- // MARK: - SessionLayer
36
-
37
- struct SessionLayer: Identifiable, Codable {
38
- let id: String
39
- var name: String
40
- var windows: [WindowRef]
41
-
42
- init(id: String = UUID().uuidString, name: String, windows: [WindowRef] = []) {
43
- self.id = id
44
- self.name = name
45
- self.windows = windows
46
- }
47
- }
48
-
49
- // MARK: - SessionLayerStore
50
-
51
- final class SessionLayerStore: ObservableObject {
52
- static let shared = SessionLayerStore()
53
-
54
- @Published var layers: [SessionLayer] = []
55
- @Published var activeIndex: Int = -1
56
-
57
- private init() {
58
- // Listen for window changes to reconcile stale refs
59
- EventBus.shared.subscribe { [weak self] event in
60
- if case .windowsChanged = event {
61
- DispatchQueue.main.async {
62
- self?.reconcile()
63
- }
64
- }
65
- }
66
- }
67
-
68
- // MARK: - CRUD
69
-
70
- @discardableResult
71
- func create(name: String, windows: [WindowRef] = []) -> SessionLayer {
72
- let layer = SessionLayer(name: name, windows: windows)
73
- layers.append(layer)
74
- DiagnosticLog.shared.info("SessionLayerStore: created '\(name)' with \(windows.count) refs")
75
- // If this is the first layer, activate it
76
- if layers.count == 1 { activeIndex = 0 }
77
- return layer
78
- }
79
-
80
- func delete(id: String) {
81
- guard let idx = layers.firstIndex(where: { $0.id == id }) else { return }
82
- // Clear layer tags for windows in this layer
83
- for ref in layers[idx].windows {
84
- if let wid = ref.wid {
85
- DesktopModel.shared.removeLayerTag(wid: wid)
86
- }
87
- }
88
- layers.remove(at: idx)
89
- // Adjust activeIndex
90
- if layers.isEmpty {
91
- activeIndex = -1
92
- } else if activeIndex >= layers.count {
93
- activeIndex = layers.count - 1
94
- }
95
- }
96
-
97
- func rename(id: String, name: String) {
98
- guard let idx = layers.firstIndex(where: { $0.id == id }) else { return }
99
- layers[idx].name = name
100
- }
101
-
102
- func clear() {
103
- DesktopModel.shared.clearLayerTags()
104
- layers.removeAll()
105
- activeIndex = -1
106
- LayerBezel.shared.invalidateCache()
107
- }
108
-
109
- func layerById(_ id: String) -> SessionLayer? {
110
- layers.first { $0.id == id }
111
- }
112
-
113
- func layerByName(_ name: String) -> SessionLayer? {
114
- layers.first { $0.name.localizedCaseInsensitiveCompare(name) == .orderedSame }
115
- }
116
-
117
- // MARK: - Window Management
118
-
119
- func assign(ref: WindowRef, toLayerId id: String) {
120
- guard let idx = layers.firstIndex(where: { $0.id == id }) else { return }
121
- layers[idx].windows.append(ref)
122
- if let wid = ref.wid {
123
- DesktopModel.shared.assignLayer(wid: wid, layerId: layers[idx].name)
124
- }
125
- }
126
-
127
- func assignByWid(_ wid: UInt32, toLayerId id: String) {
128
- guard let idx = layers.firstIndex(where: { $0.id == id }) else { return }
129
- guard let entry = DesktopModel.shared.windows[wid] else { return }
130
- // Don't add duplicates
131
- if layers[idx].windows.contains(where: { $0.wid == wid }) { return }
132
- let ref = WindowRef(
133
- app: entry.app,
134
- contentHint: entry.title,
135
- wid: entry.wid,
136
- pid: entry.pid,
137
- title: entry.title,
138
- frame: entry.frame
139
- )
140
- layers[idx].windows.append(ref)
141
- DesktopModel.shared.assignLayer(wid: wid, layerId: layers[idx].name)
142
- }
143
-
144
- func remove(refId: String, fromLayerId id: String) {
145
- guard let idx = layers.firstIndex(where: { $0.id == id }) else { return }
146
- if let refIdx = layers[idx].windows.firstIndex(where: { $0.id == refId }) {
147
- if let wid = layers[idx].windows[refIdx].wid {
148
- DesktopModel.shared.removeLayerTag(wid: wid)
149
- }
150
- layers[idx].windows.remove(at: refIdx)
151
- }
152
- }
153
-
154
- func tagFrontmostWindow() {
155
- guard let frontApp = NSWorkspace.shared.frontmostApplication,
156
- frontApp.bundleIdentifier != "com.arach.lattices" else { return }
157
-
158
- let pid = frontApp.processIdentifier
159
- // Find the frontmost window for this app
160
- guard let entry = DesktopModel.shared.windows.values
161
- .first(where: { $0.pid == pid }) else { return }
162
-
163
- // If no layers exist, create one
164
- if layers.isEmpty {
165
- create(name: "Layer 1")
166
- }
167
-
168
- // If no active layer, use first
169
- let targetIndex = activeIndex >= 0 ? activeIndex : 0
170
- guard targetIndex < layers.count else { return }
171
-
172
- let layerId = layers[targetIndex].id
173
- assignByWid(entry.wid, toLayerId: layerId)
174
- DiagnosticLog.shared.info("SessionLayerStore: tagged \(entry.app) '\(entry.title)' → '\(layers[targetIndex].name)'")
175
-
176
- // Show bezel feedback
177
- let allNames = layers.map(\.name)
178
- LayerBezel.shared.show(
179
- label: layers[targetIndex].name,
180
- index: targetIndex,
181
- total: layers.count,
182
- allLabels: allNames
183
- )
184
- }
185
-
186
- // MARK: - Switching
187
-
188
- func switchTo(index: Int) {
189
- guard index >= 0, index < layers.count else { return }
190
- activeIndex = index
191
-
192
- DesktopModel.shared.poll()
193
-
194
- var resolved: [(wid: UInt32, pid: Int32)] = []
195
- for i in layers[index].windows.indices {
196
- if let r = resolve(&layers[index].windows[i]) {
197
- resolved.append(r)
198
- }
199
- }
200
-
201
- if !resolved.isEmpty {
202
- WindowTiler.raiseWindowsAndReactivate(windows: resolved)
203
- }
204
-
205
- let allNames = layers.map(\.name)
206
- LayerBezel.shared.show(
207
- label: layers[index].name,
208
- index: index,
209
- total: layers.count,
210
- allLabels: allNames
211
- )
212
-
213
- DiagnosticLog.shared.info("SessionLayerStore: switched to '\(layers[index].name)' (\(resolved.count)/\(layers[index].windows.count) resolved)")
214
- }
215
-
216
- func cycleNext() {
217
- guard !layers.isEmpty else { return }
218
- let next = (activeIndex + 1) % layers.count
219
- switchTo(index: next)
220
- }
221
-
222
- func cyclePrev() {
223
- guard !layers.isEmpty else { return }
224
- let prev = activeIndex <= 0 ? layers.count - 1 : activeIndex - 1
225
- switchTo(index: prev)
226
- }
227
-
228
- // MARK: - Resolution
229
-
230
- private func resolve(_ ref: inout WindowRef) -> (wid: UInt32, pid: Int32)? {
231
- // 1. Fast path: wid still valid
232
- if let wid = ref.wid, let entry = DesktopModel.shared.windows[wid] {
233
- ref.pid = entry.pid
234
- ref.title = entry.title
235
- ref.frame = entry.frame
236
- return (wid, entry.pid)
237
- }
238
-
239
- // 2. Re-resolve by app + contentHint
240
- if let entry = DesktopModel.shared.windowForApp(app: ref.app, title: ref.contentHint) {
241
- ref.wid = entry.wid
242
- ref.pid = entry.pid
243
- ref.title = entry.title
244
- ref.frame = entry.frame
245
- DesktopModel.shared.assignLayer(wid: entry.wid, layerId: layerNameForRef(ref))
246
- return (entry.wid, entry.pid)
247
- }
248
-
249
- // 3. Window not found — dormant
250
- ref.wid = nil
251
- ref.pid = nil
252
- ref.title = nil
253
- ref.frame = nil
254
- return nil
255
- }
256
-
257
- private func layerNameForRef(_ ref: WindowRef) -> String {
258
- for layer in layers {
259
- if layer.windows.contains(where: { $0.id == ref.id }) {
260
- return layer.name
261
- }
262
- }
263
- return ""
264
- }
265
-
266
- // MARK: - Reconciliation
267
-
268
- func reconcile() {
269
- let desktop = DesktopModel.shared
270
- for layerIdx in layers.indices {
271
- for refIdx in layers[layerIdx].windows.indices {
272
- let ref = layers[layerIdx].windows[refIdx]
273
- guard let wid = ref.wid else { continue }
274
- if desktop.windows[wid] == nil {
275
- // Window gone — clear runtime, keep intent
276
- layers[layerIdx].windows[refIdx].wid = nil
277
- layers[layerIdx].windows[refIdx].pid = nil
278
- layers[layerIdx].windows[refIdx].title = nil
279
- layers[layerIdx].windows[refIdx].frame = nil
280
- desktop.removeLayerTag(wid: wid)
281
- }
282
- }
283
- }
284
- }
285
- }
@@ -1,75 +0,0 @@
1
- import AppKit
2
-
3
- enum SessionManager {
4
- private static let latticesPath = "/opt/homebrew/bin/lattices"
5
- private static var tmuxPath: String { TmuxQuery.resolvedPath ?? "/opt/homebrew/bin/tmux" }
6
-
7
- /// Launch or reattach — if session is running, find and focus the existing window
8
- static func launch(project: Project) {
9
- let terminal = Preferences.shared.terminal
10
- if project.isRunning {
11
- if let window = DesktopModel.shared.windowForSession(project.sessionName) {
12
- DesktopModel.shared.markInteraction(wid: window.wid)
13
- }
14
- terminal.focusOrAttach(session: project.sessionName)
15
- } else {
16
- terminal.launch(command: "\(latticesPath) start", in: project.path)
17
- }
18
- }
19
-
20
- /// Detach all clients from a tmux session (keeps it running)
21
- static func detach(project: Project) {
22
- detachByName(project.sessionName)
23
- }
24
-
25
- /// Detach all clients by session name string (for layer switching without a Project object)
26
- static func detachByName(_ sessionName: String) {
27
- let task = Process()
28
- task.executableURL = URL(fileURLWithPath: tmuxPath)
29
- task.arguments = ["detach-client", "-s", sessionName]
30
- task.standardOutput = FileHandle.nullDevice
31
- task.standardError = FileHandle.nullDevice
32
- try? task.run()
33
- task.waitUntilExit()
34
- }
35
-
36
- /// Kill a tmux session
37
- static func kill(project: Project) {
38
- killByName(project.sessionName)
39
- }
40
-
41
- /// Kill a tmux session by name string (for orphan sessions without a Project object)
42
- static func killByName(_ sessionName: String) {
43
- let task = Process()
44
- task.executableURL = URL(fileURLWithPath: tmuxPath)
45
- task.arguments = ["kill-session", "-t", sessionName]
46
- task.standardOutput = FileHandle.nullDevice
47
- task.standardError = FileHandle.nullDevice
48
- try? task.run()
49
- task.waitUntilExit()
50
- }
51
-
52
- /// Reconcile session state to match declared config (recreate missing panes)
53
- static func sync(project: Project) {
54
- let task = Process()
55
- task.executableURL = URL(fileURLWithPath: latticesPath)
56
- task.arguments = ["sync"]
57
- task.currentDirectoryURL = URL(fileURLWithPath: project.path)
58
- task.standardOutput = FileHandle.nullDevice
59
- task.standardError = FileHandle.nullDevice
60
- try? task.run()
61
- task.waitUntilExit()
62
- }
63
-
64
- /// Restart a specific pane's process (kill + re-run declared command)
65
- static func restart(project: Project, paneName: String? = nil) {
66
- let task = Process()
67
- task.executableURL = URL(fileURLWithPath: latticesPath)
68
- task.arguments = paneName != nil ? ["restart", paneName!] : ["restart"]
69
- task.currentDirectoryURL = URL(fileURLWithPath: project.path)
70
- task.standardOutput = FileHandle.nullDevice
71
- task.standardError = FileHandle.nullDevice
72
- try? task.run()
73
- task.waitUntilExit()
74
- }
75
- }