@arach/lattices 0.2.0 → 0.6.1

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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +172 -86
  3. package/apps/mac/Info.plist +43 -0
  4. package/apps/mac/Lattices.app/Contents/Info.plist +43 -0
  5. package/apps/mac/Lattices.app/Contents/MacOS/Lattices +0 -0
  6. package/apps/mac/Lattices.app/Contents/Resources/AppIcon.icns +0 -0
  7. package/apps/mac/Lattices.app/Contents/Resources/docs/assistant-knowledge.md +130 -0
  8. package/apps/mac/Lattices.app/Contents/Resources/tap.wav +0 -0
  9. package/apps/mac/Lattices.app/Contents/_CodeSignature/CodeResources +150 -0
  10. package/apps/mac/Lattices.entitlements +21 -0
  11. package/apps/mac/Resources/Pets/assistant-spark/pet.json +62 -0
  12. package/apps/mac/Resources/Pets/assistant-spark/spritesheet.webp +0 -0
  13. package/apps/mac/Resources/Pets/scout-ranger/pet.json +6 -0
  14. package/apps/mac/Resources/Pets/scout-ranger/spritesheet.webp +0 -0
  15. package/apps/mac/Resources/tap.wav +0 -0
  16. package/assets/AppIcon.icns +0 -0
  17. package/bin/assistant-intelligence.ts +912 -0
  18. package/bin/cli/capture.ts +252 -0
  19. package/bin/cli/daemon.ts +22 -0
  20. package/bin/cli/helpers.ts +105 -0
  21. package/bin/cli/layer.ts +178 -0
  22. package/bin/cli/runs.ts +43 -0
  23. package/bin/cli/search.ts +141 -0
  24. package/bin/cli/session.ts +32 -0
  25. package/bin/client.ts +17 -0
  26. package/bin/cua.ts +26 -0
  27. package/bin/{daemon-client.js → daemon-client.ts} +49 -30
  28. package/bin/handsoff-infer.ts +96 -0
  29. package/bin/handsoff-worker.ts +531 -0
  30. package/bin/infer.ts +424 -0
  31. package/bin/keychain.ts +75 -0
  32. package/bin/lattices-app.ts +655 -0
  33. package/bin/lattices-build +125 -0
  34. package/bin/lattices-build-env.ts +77 -0
  35. package/bin/lattices-dev +362 -0
  36. package/bin/lattices.ts +3260 -0
  37. package/bin/project-twin.ts +645 -0
  38. package/docs/agent-execution-plan.md +562 -0
  39. package/docs/agent-layer-guide.md +207 -0
  40. package/docs/agents.md +233 -0
  41. package/docs/ai-chat-ux-review.md +416 -0
  42. package/docs/api.md +1041 -47
  43. package/docs/app.md +96 -13
  44. package/docs/assistant-knowledge.md +130 -0
  45. package/docs/companion-deck.md +209 -0
  46. package/docs/component-extraction-roadmap.md +392 -0
  47. package/docs/concepts.md +13 -12
  48. package/docs/config.md +83 -10
  49. package/docs/gesture-customization-proposal.md +520 -0
  50. package/docs/handsoff-test-scenarios.md +84 -0
  51. package/docs/hyperspace-grid-snappiness.md +210 -0
  52. package/docs/layers.md +176 -28
  53. package/docs/mouse-gestures.md +244 -0
  54. package/docs/ocr.md +21 -9
  55. package/docs/overview.md +42 -23
  56. package/docs/presentation-execution-review.md +491 -0
  57. package/docs/prompts/hands-off-system.md +382 -0
  58. package/docs/prompts/hands-off-turn.md +30 -0
  59. package/docs/prompts/voice-advisor.md +31 -0
  60. package/docs/prompts/voice-fallback.md +23 -0
  61. package/docs/proposals/LAT-001-gesture-visual-customization.md +522 -0
  62. package/docs/proposals/LAT-002-shared-overlay-canvas.md +353 -0
  63. package/docs/proposals/LAT-003-menu-bar-controller-architecture.md +291 -0
  64. package/docs/proposals/LAT-004-interactive-overlay-actors.md +534 -0
  65. package/docs/proposals/LAT-005-action-runtime-product-spine.md +914 -0
  66. package/docs/proposals/LAT-006-followup-gaps.md +103 -0
  67. package/docs/proposals/LAT-006-runs-and-capture-in-lattices.md +566 -0
  68. package/docs/proposals/LAT-007-unified-app-shell.md +128 -0
  69. package/docs/quickstart.md +8 -12
  70. package/docs/reference/dewey.config.ts +74 -0
  71. package/docs/reference/install-agent.md +79 -0
  72. package/docs/release.md +172 -0
  73. package/docs/repo-structure.md +100 -0
  74. package/docs/terminal-kit.md +87 -0
  75. package/docs/tiling-reference.md +224 -0
  76. package/docs/twins.md +138 -0
  77. package/docs/voice-command-protocol.md +278 -0
  78. package/docs/voice-error-model.md +73 -0
  79. package/docs/voice.md +221 -0
  80. package/package.json +69 -16
  81. package/packages/npm/sdk/cua.d.mts +1 -0
  82. package/packages/npm/sdk/cua.d.ts +188 -0
  83. package/packages/npm/sdk/cua.mjs +376 -0
  84. package/app/Lattices.app/Contents/Info.plist +0 -24
  85. package/app/Package.swift +0 -13
  86. package/app/Sources/ActionRow.swift +0 -61
  87. package/app/Sources/App.swift +0 -10
  88. package/app/Sources/AppDelegate.swift +0 -234
  89. package/app/Sources/AppShellView.swift +0 -62
  90. package/app/Sources/AppTypeClassifier.swift +0 -70
  91. package/app/Sources/AppWindowShell.swift +0 -63
  92. package/app/Sources/CheatSheetHUD.swift +0 -332
  93. package/app/Sources/CommandModeState.swift +0 -1362
  94. package/app/Sources/CommandModeView.swift +0 -1405
  95. package/app/Sources/CommandModeWindow.swift +0 -192
  96. package/app/Sources/CommandPaletteView.swift +0 -307
  97. package/app/Sources/CommandPaletteWindow.swift +0 -134
  98. package/app/Sources/DaemonProtocol.swift +0 -101
  99. package/app/Sources/DaemonServer.swift +0 -414
  100. package/app/Sources/DesktopModel.swift +0 -121
  101. package/app/Sources/DesktopModelTypes.swift +0 -71
  102. package/app/Sources/DiagnosticLog.swift +0 -271
  103. package/app/Sources/EventBus.swift +0 -30
  104. package/app/Sources/HotkeyManager.swift +0 -250
  105. package/app/Sources/HotkeyStore.swift +0 -338
  106. package/app/Sources/InventoryManager.swift +0 -35
  107. package/app/Sources/InventoryPath.swift +0 -43
  108. package/app/Sources/KeyRecorderView.swift +0 -210
  109. package/app/Sources/LatticesApi.swift +0 -1125
  110. package/app/Sources/MainView.swift +0 -467
  111. package/app/Sources/MainWindow.swift +0 -83
  112. package/app/Sources/OcrModel.swift +0 -309
  113. package/app/Sources/OcrStore.swift +0 -295
  114. package/app/Sources/OmniSearchState.swift +0 -283
  115. package/app/Sources/OmniSearchView.swift +0 -288
  116. package/app/Sources/OmniSearchWindow.swift +0 -105
  117. package/app/Sources/OrphanRow.swift +0 -129
  118. package/app/Sources/PaletteCommand.swift +0 -419
  119. package/app/Sources/PermissionChecker.swift +0 -125
  120. package/app/Sources/Preferences.swift +0 -92
  121. package/app/Sources/ProcessModel.swift +0 -199
  122. package/app/Sources/ProcessQuery.swift +0 -151
  123. package/app/Sources/Project.swift +0 -28
  124. package/app/Sources/ProjectRow.swift +0 -368
  125. package/app/Sources/ProjectScanner.swift +0 -121
  126. package/app/Sources/ScreenMapState.swift +0 -2387
  127. package/app/Sources/ScreenMapView.swift +0 -2820
  128. package/app/Sources/ScreenMapWindowController.swift +0 -89
  129. package/app/Sources/SessionManager.swift +0 -72
  130. package/app/Sources/SettingsView.swift +0 -1053
  131. package/app/Sources/SettingsWindow.swift +0 -20
  132. package/app/Sources/TabGroupRow.swift +0 -178
  133. package/app/Sources/Terminal.swift +0 -259
  134. package/app/Sources/TerminalQuery.swift +0 -156
  135. package/app/Sources/TerminalSynthesizer.swift +0 -200
  136. package/app/Sources/Theme.swift +0 -163
  137. package/app/Sources/TilePickerView.swift +0 -209
  138. package/app/Sources/TmuxModel.swift +0 -53
  139. package/app/Sources/TmuxQuery.swift +0 -81
  140. package/app/Sources/WindowTiler.swift +0 -1755
  141. package/app/Sources/WorkspaceManager.swift +0 -434
  142. package/bin/lattices-app.js +0 -221
  143. package/bin/lattices.js +0 -1418
@@ -1,129 +0,0 @@
1
- import SwiftUI
2
-
3
- struct OrphanRow: View {
4
- let session: TmuxSession
5
- var onAttach: () -> Void
6
- var onKill: () -> Void
7
-
8
- @State private var isHovered = false
9
- @State private var isExpanded = false
10
-
11
- private var commandSummary: String {
12
- let commands = session.panes
13
- .map(\.currentCommand)
14
- .filter { !$0.isEmpty }
15
- let unique = commands.count <= 3 ? commands : Array(commands.prefix(3)) + ["..."]
16
- return "\(session.panes.count) pane\(session.panes.count == 1 ? "" : "s") \u{2014} \(unique.joined(separator: ", "))"
17
- }
18
-
19
- var body: some View {
20
- VStack(spacing: 0) {
21
- // Header row
22
- HStack(spacing: 10) {
23
- // Status bar — amber for orphan
24
- RoundedRectangle(cornerRadius: 1)
25
- .fill(Palette.detach)
26
- .frame(width: 3, height: 32)
27
-
28
- // Expand chevron
29
- Button {
30
- withAnimation(.easeOut(duration: 0.15)) { isExpanded.toggle() }
31
- } label: {
32
- Image(systemName: isExpanded ? "chevron.down" : "chevron.right")
33
- .font(.system(size: 9, weight: .semibold))
34
- .foregroundColor(Palette.textMuted)
35
- .frame(width: 14)
36
- }
37
- .buttonStyle(.plain)
38
-
39
- // Info
40
- VStack(alignment: .leading, spacing: 3) {
41
- HStack(spacing: 6) {
42
- Text(session.name)
43
- .font(Typo.heading(13))
44
- .foregroundColor(Palette.text)
45
- .lineLimit(1)
46
-
47
- if session.attached {
48
- Text("attached")
49
- .font(Typo.mono(9))
50
- .foregroundColor(Palette.detach)
51
- .padding(.horizontal, 5)
52
- .padding(.vertical, 1)
53
- .background(
54
- RoundedRectangle(cornerRadius: 3)
55
- .fill(Palette.detach.opacity(0.12))
56
- )
57
- }
58
- }
59
-
60
- Text(commandSummary)
61
- .font(Typo.mono(10))
62
- .foregroundColor(Palette.textMuted)
63
- .lineLimit(1)
64
- }
65
-
66
- Spacer()
67
-
68
- // Actions
69
- HStack(spacing: 4) {
70
- Button(action: onKill) {
71
- Text("Kill")
72
- .angularButton(Palette.kill, filled: false)
73
- }
74
- .buttonStyle(.plain)
75
-
76
- Button(action: onAttach) {
77
- Text("Attach")
78
- .angularButton(Palette.running)
79
- }
80
- .buttonStyle(.plain)
81
- }
82
- }
83
- .padding(.horizontal, 10)
84
- .padding(.vertical, 8)
85
- .glassCard(hovered: isHovered)
86
-
87
- // Expanded pane list
88
- if isExpanded {
89
- VStack(spacing: 2) {
90
- ForEach(session.panes) { pane in
91
- paneRow(pane)
92
- }
93
- }
94
- .padding(.leading, 36)
95
- .padding(.trailing, 10)
96
- .padding(.vertical, 4)
97
- .transition(.opacity.combined(with: .move(edge: .top)))
98
- }
99
- }
100
- .contentShape(Rectangle())
101
- .onHover { isHovered = $0 }
102
- .contextMenu {
103
- Button("Attach") { onAttach() }
104
- Divider()
105
- Button("Kill Session") { onKill() }
106
- }
107
- }
108
-
109
- private func paneRow(_ pane: TmuxPane) -> some View {
110
- HStack(spacing: 8) {
111
- Circle()
112
- .fill(pane.isActive ? Palette.detach.opacity(0.7) : Palette.textMuted)
113
- .frame(width: 5, height: 5)
114
-
115
- Text(pane.title.isEmpty ? pane.currentCommand : pane.title)
116
- .font(Typo.mono(11))
117
- .foregroundColor(Palette.text)
118
- .lineLimit(1)
119
-
120
- Spacer()
121
-
122
- Text(pane.currentCommand)
123
- .font(Typo.mono(9))
124
- .foregroundColor(Palette.textDim)
125
- }
126
- .padding(.horizontal, 8)
127
- .padding(.vertical, 4)
128
- }
129
- }
@@ -1,419 +0,0 @@
1
- import AppKit
2
- import Foundation
3
-
4
- struct PaletteCommand: Identifiable {
5
- let id: String
6
- let title: String
7
- let subtitle: String
8
- let icon: String
9
- let category: Category
10
- let badge: String?
11
- let action: () -> Void
12
-
13
- enum Category: String, CaseIterable {
14
- case project = "Projects"
15
- case window = "Window"
16
- case app = "App"
17
-
18
- var icon: String {
19
- switch self {
20
- case .project: return "terminal"
21
- case .window: return "macwindow"
22
- case .app: return "gearshape"
23
- }
24
- }
25
- }
26
-
27
- /// Fuzzy match score — higher is better, 0 means no match
28
- func matchScore(query: String) -> Int {
29
- let q = query.lowercased()
30
- let t = title.lowercased()
31
- let s = subtitle.lowercased()
32
-
33
- // Exact prefix match on title — best
34
- if t.hasPrefix(q) { return 100 }
35
- // Word-boundary prefix (e.g. "set" matches "Open Settings")
36
- let words = t.split(separator: " ").map(String.init)
37
- if words.contains(where: { $0.hasPrefix(q) }) { return 80 }
38
- // Contains in title
39
- if t.contains(q) { return 60 }
40
- // Subtitle prefix
41
- if s.hasPrefix(q) { return 50 }
42
- // Subtitle contains
43
- if s.contains(q) { return 40 }
44
- // Subsequence match on title
45
- if isSubsequence(q, of: t) { return 20 }
46
- return 0
47
- }
48
-
49
- private func isSubsequence(_ needle: String, of haystack: String) -> Bool {
50
- var it = haystack.makeIterator()
51
- for ch in needle {
52
- while let next = it.next() {
53
- if next == ch { break }
54
- }
55
- // If iterator is exhausted before matching all chars, not a subsequence
56
- // (handled by the while loop returning nil)
57
- }
58
- // Verify: re-check properly
59
- var hi = haystack.startIndex
60
- for ch in needle {
61
- guard let found = haystack[hi...].firstIndex(of: ch) else { return false }
62
- hi = haystack.index(after: found)
63
- }
64
- return true
65
- }
66
- }
67
-
68
- // MARK: - Command Builder
69
-
70
- enum CommandBuilder {
71
- static func build(scanner: ProjectScanner) -> [PaletteCommand] {
72
- var projectCmds: [PaletteCommand] = []
73
- var windowCmds: [PaletteCommand] = []
74
- let terminal = Preferences.shared.terminal
75
-
76
- for project in scanner.projects {
77
- if project.isRunning {
78
- // Project actions
79
- projectCmds.append(PaletteCommand(
80
- id: "attach-\(project.id)",
81
- title: "Attach \(project.name)",
82
- subtitle: "Open terminal to running session",
83
- icon: "play.fill",
84
- category: .project,
85
- badge: "running",
86
- action: { SessionManager.launch(project: project) }
87
- ))
88
- // Window actions
89
- windowCmds.append(PaletteCommand(
90
- id: "goto-\(project.id)",
91
- title: "Go to \(project.name)",
92
- subtitle: "Focus the terminal window",
93
- icon: "macwindow",
94
- category: .window,
95
- badge: nil,
96
- action: {
97
- WindowTiler.navigateToWindow(
98
- session: project.sessionName,
99
- terminal: terminal
100
- )
101
- }
102
- ))
103
- windowCmds.append(PaletteCommand(
104
- id: "tile-left-\(project.id)",
105
- title: "Tile \(project.name) Left",
106
- subtitle: "Snap window to left half",
107
- icon: "rectangle.lefthalf.filled",
108
- category: .window,
109
- badge: nil,
110
- action: {
111
- WindowTiler.tile(session: project.sessionName, terminal: terminal, to: .left)
112
- }
113
- ))
114
- windowCmds.append(PaletteCommand(
115
- id: "tile-right-\(project.id)",
116
- title: "Tile \(project.name) Right",
117
- subtitle: "Snap window to right half",
118
- icon: "rectangle.righthalf.filled",
119
- category: .window,
120
- badge: nil,
121
- action: {
122
- WindowTiler.tile(session: project.sessionName, terminal: terminal, to: .right)
123
- }
124
- ))
125
- windowCmds.append(PaletteCommand(
126
- id: "tile-max-\(project.id)",
127
- title: "Maximize \(project.name)",
128
- subtitle: "Expand window to fill screen",
129
- icon: "rectangle.fill",
130
- category: .window,
131
- badge: nil,
132
- action: {
133
- WindowTiler.tile(session: project.sessionName, terminal: terminal, to: .maximize)
134
- }
135
- ))
136
- windowCmds.append(PaletteCommand(
137
- id: "detach-\(project.id)",
138
- title: "Detach \(project.name)",
139
- subtitle: "Disconnect clients, keep session alive",
140
- icon: "eject.fill",
141
- category: .window,
142
- badge: nil,
143
- action: { SessionManager.detach(project: project) }
144
- ))
145
- windowCmds.append(PaletteCommand(
146
- id: "kill-\(project.id)",
147
- title: "Kill \(project.name)",
148
- subtitle: "Terminate the tmux session",
149
- icon: "xmark.circle.fill",
150
- category: .window,
151
- badge: nil,
152
- action: { SessionManager.kill(project: project) }
153
- ))
154
- // Recovery commands
155
- projectCmds.append(PaletteCommand(
156
- id: "sync-\(project.id)",
157
- title: "Sync \(project.name)",
158
- subtitle: "Reconcile session to declared config",
159
- icon: "arrow.triangle.2.circlepath",
160
- category: .project,
161
- badge: nil,
162
- action: { SessionManager.sync(project: project) }
163
- ))
164
- // Per-pane restart commands
165
- for paneName in project.paneNames {
166
- projectCmds.append(PaletteCommand(
167
- id: "restart-\(paneName)-\(project.id)",
168
- title: "Restart \(paneName) in \(project.name)",
169
- subtitle: "Kill and re-run the \(paneName) pane",
170
- icon: "arrow.counterclockwise",
171
- category: .project,
172
- badge: nil,
173
- action: { SessionManager.restart(project: project, paneName: paneName) }
174
- ))
175
- }
176
- } else {
177
- projectCmds.append(PaletteCommand(
178
- id: "launch-\(project.id)",
179
- title: "Launch \(project.name)",
180
- subtitle: project.paneSummary.isEmpty
181
- ? (project.devCommand ?? project.path)
182
- : project.paneSummary,
183
- icon: "play.circle",
184
- category: .project,
185
- badge: nil,
186
- action: { SessionManager.launch(project: project) }
187
- ))
188
- }
189
- }
190
-
191
- // Move-to-space commands for running projects
192
- let allSpaces = WindowTiler.getDisplaySpaces().flatMap(\.spaces)
193
- if allSpaces.count > 1 {
194
- for project in scanner.projects where project.isRunning {
195
- let tag = Terminal.windowTag(for: project.sessionName)
196
- var windowSpaces: [Int] = []
197
- if let (w, _) = WindowTiler.findWindow(tag: tag) {
198
- windowSpaces = WindowTiler.getSpacesForWindow(w)
199
- }
200
-
201
- for space in allSpaces {
202
- let isCurrentSpace = windowSpaces.contains(space.id)
203
- windowCmds.append(PaletteCommand(
204
- id: "move-space\(space.index)-\(project.id)",
205
- title: "Move \(project.name) to Space \(space.index)",
206
- subtitle: isCurrentSpace ? "Window is already here" : "Move window to Space \(space.index)",
207
- icon: "rectangle.on.rectangle",
208
- category: .window,
209
- badge: isCurrentSpace ? "current" : nil,
210
- action: {
211
- let result = WindowTiler.moveWindowToSpace(
212
- session: project.sessionName,
213
- terminal: terminal,
214
- spaceId: space.id
215
- )
216
- if case .success = result {
217
- WindowTiler.switchToSpace(spaceId: space.id)
218
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
219
- WindowTiler.highlightWindow(session: project.sessionName)
220
- }
221
- }
222
- }
223
- ))
224
- }
225
- }
226
- }
227
-
228
- var commands = projectCmds + windowCmds
229
-
230
- // Layer commands (focus + launch)
231
- let workspace = WorkspaceManager.shared
232
- if let wsConfig = workspace.config {
233
- for (i, layer) in (wsConfig.layers ?? []).enumerated() {
234
- let layerIndex = i
235
- let isActive = i == workspace.activeLayerIndex
236
- let counts = workspace.layerRunningCount(index: i)
237
- commands.append(PaletteCommand(
238
- id: "layer-focus-\(layer.id)",
239
- title: "Focus Layer: \(layer.label)",
240
- subtitle: "\(counts.running)/\(counts.total) running \u{2014} \u{2325}\(i + 1)",
241
- icon: "square.stack.3d.up",
242
- category: .app,
243
- badge: isActive ? "active" : nil,
244
- action: { workspace.tileLayer(index: layerIndex) }
245
- ))
246
- commands.append(PaletteCommand(
247
- id: "layer-launch-\(layer.id)",
248
- title: "Launch Layer: \(layer.label)",
249
- subtitle: "Start all \(layer.projects.count) project\(layer.projects.count == 1 ? "" : "s")",
250
- icon: "play.circle",
251
- category: .app,
252
- badge: isActive ? "active" : nil,
253
- action: { workspace.tileLayer(index: layerIndex, launch: true) }
254
- ))
255
- }
256
-
257
- // Tab group commands
258
- for group in wsConfig.groups ?? [] {
259
- let isRunning = workspace.isGroupRunning(group)
260
-
261
- if isRunning {
262
- commands.append(PaletteCommand(
263
- id: "group-attach-\(group.id)",
264
- title: "Attach \(group.label)",
265
- subtitle: "\(group.tabs.count) tabs",
266
- icon: "rectangle.stack",
267
- category: .project,
268
- badge: "group",
269
- action: {
270
- if let firstTab = group.tabs.first {
271
- let session = WorkspaceManager.sessionName(for: firstTab.path)
272
- let terminal = Preferences.shared.terminal
273
- terminal.focusOrAttach(session: session)
274
- }
275
- }
276
- ))
277
-
278
- // Per-tab focus commands
279
- for (idx, tab) in group.tabs.enumerated() {
280
- let tabLabel = tab.label ?? (tab.path as NSString).lastPathComponent
281
- let tabIndex = idx
282
- commands.append(PaletteCommand(
283
- id: "group-tab-\(group.id)-\(idx)",
284
- title: "\(group.label): \(tabLabel)",
285
- subtitle: "Focus tab \(idx + 1) in group",
286
- icon: "rectangle.topthird.inset.filled",
287
- category: .project,
288
- badge: nil,
289
- action: {
290
- workspace.focusTab(group: group, tabIndex: tabIndex)
291
- }
292
- ))
293
- }
294
-
295
- commands.append(PaletteCommand(
296
- id: "group-kill-\(group.id)",
297
- title: "Kill \(group.label) Group",
298
- subtitle: "Terminate the group session",
299
- icon: "xmark.circle.fill",
300
- category: .window,
301
- badge: nil,
302
- action: {
303
- workspace.killGroup(group)
304
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
305
- scanner.refreshStatus()
306
- }
307
- }
308
- ))
309
- } else {
310
- commands.append(PaletteCommand(
311
- id: "group-launch-\(group.id)",
312
- title: "Launch \(group.label)",
313
- subtitle: "\(group.tabs.count) tabs \u{2014} \(group.tabs.map { $0.label ?? ($0.path as NSString).lastPathComponent }.joined(separator: ", "))",
314
- icon: "rectangle.stack",
315
- category: .project,
316
- badge: "group",
317
- action: { workspace.launchGroup(group) }
318
- ))
319
- }
320
- }
321
- }
322
-
323
- // Orphan session commands
324
- let inventory = InventoryManager.shared
325
- for orphan in inventory.orphans {
326
- commands.append(PaletteCommand(
327
- id: "orphan-attach-\(orphan.name)",
328
- title: "Attach \(orphan.name)",
329
- subtitle: "\(orphan.panes.count) pane\(orphan.panes.count == 1 ? "" : "s") \u{2014} \(orphan.panes.prefix(3).map(\.currentCommand).joined(separator: ", "))",
330
- icon: "play.fill",
331
- category: .project,
332
- badge: "orphan",
333
- action: {
334
- let terminal = Preferences.shared.terminal
335
- terminal.focusOrAttach(session: orphan.name)
336
- }
337
- ))
338
- commands.append(PaletteCommand(
339
- id: "orphan-kill-\(orphan.name)",
340
- title: "Kill \(orphan.name)",
341
- subtitle: "Terminate unmanaged tmux session",
342
- icon: "xmark.circle.fill",
343
- category: .window,
344
- badge: "orphan",
345
- action: {
346
- SessionManager.killByName(orphan.name)
347
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
348
- inventory.refresh()
349
- }
350
- }
351
- ))
352
- }
353
-
354
- // App actions
355
- commands.append(PaletteCommand(
356
- id: "app-settings",
357
- title: "Settings",
358
- subtitle: "Terminal, scan root, mode",
359
- icon: "gearshape",
360
- category: .app,
361
- badge: nil,
362
- action: {
363
- SettingsWindowController.shared.show()
364
- }
365
- ))
366
-
367
- commands.append(PaletteCommand(
368
- id: "app-windows-list",
369
- title: "Windows List",
370
- subtitle: "Browse all windows across displays",
371
- icon: "rectangle.split.2x1",
372
- category: .app,
373
- badge: nil,
374
- action: { CommandModeWindow.shared.show() }
375
- ))
376
-
377
- commands.append(PaletteCommand(
378
- id: "app-screen-map",
379
- title: "Window Map",
380
- subtitle: "Visual window editor",
381
- icon: "rectangle.3.group",
382
- category: .app,
383
- badge: nil,
384
- action: { ScreenMapWindowController.shared.show() }
385
- ))
386
-
387
- commands.append(PaletteCommand(
388
- id: "app-diagnostics",
389
- title: "Diagnostics",
390
- subtitle: "View logs and debug info",
391
- icon: "stethoscope",
392
- category: .app,
393
- badge: nil,
394
- action: { DiagnosticWindow.shared.show() }
395
- ))
396
-
397
- commands.append(PaletteCommand(
398
- id: "app-refresh",
399
- title: "Refresh Projects",
400
- subtitle: "Re-scan for .lattices.json configs",
401
- icon: "arrow.clockwise",
402
- category: .app,
403
- badge: nil,
404
- action: { scanner.scan() }
405
- ))
406
-
407
- commands.append(PaletteCommand(
408
- id: "app-quit",
409
- title: "Quit Lattices",
410
- subtitle: "Exit the menu bar app",
411
- icon: "power",
412
- category: .app,
413
- badge: nil,
414
- action: { NSApp.terminate(nil) }
415
- ))
416
-
417
- return commands
418
- }
419
- }
@@ -1,125 +0,0 @@
1
- import AppKit
2
- import SwiftUI
3
- import Combine
4
-
5
- final class PermissionChecker: ObservableObject {
6
- static let shared = PermissionChecker()
7
-
8
- @Published var accessibility: Bool = false
9
- @Published var screenRecording: Bool = false
10
-
11
- private var pollTimer: Timer?
12
- private var hasLoggedInitial = false
13
-
14
- var allGranted: Bool { accessibility && screenRecording }
15
-
16
- /// Check current permission state, prompting on first launch if not granted.
17
- func check() {
18
- let diag = DiagnosticLog.shared
19
-
20
- let ax = AXIsProcessTrusted()
21
- let sr = CGPreflightScreenCaptureAccess()
22
-
23
- // First check: log identity info and prompt if needed
24
- if !hasLoggedInitial {
25
- hasLoggedInitial = true
26
- let bundleId = Bundle.main.bundleIdentifier ?? "<no bundle id>"
27
- let execPath = Bundle.main.executablePath ?? ProcessInfo.processInfo.arguments.first ?? "<unknown>"
28
- let pid = ProcessInfo.processInfo.processIdentifier
29
- diag.info("PermissionChecker: bundleId=\(bundleId) pid=\(pid)")
30
- diag.info("PermissionChecker: exec=\(execPath)")
31
- diag.info("AXIsProcessTrusted() → \(ax)")
32
- diag.info("CGPreflightScreenCaptureAccess() → \(sr)")
33
-
34
- // Prompt for missing permissions on first check
35
- if !ax {
36
- requestAccessibility()
37
- return
38
- }
39
- if !sr {
40
- requestScreenRecording()
41
- return
42
- }
43
- }
44
-
45
- // Log on state changes
46
- if ax != accessibility || sr != screenRecording {
47
- diag.info("Permissions: Accessibility \(ax ? "✓" : "✗"), Screen Recording \(sr ? "✓" : "✗")")
48
- }
49
-
50
- accessibility = ax
51
- screenRecording = sr
52
-
53
- // If not all granted, start polling so we detect changes while user is in Settings.
54
- // Once all granted, stop polling.
55
- if allGranted {
56
- stopPolling()
57
- } else {
58
- startPolling()
59
- }
60
- }
61
-
62
- /// Request Accessibility permission — shows the system dialog if not yet granted,
63
- /// which adds lattices to the Accessibility list and asks the user to toggle it on.
64
- func requestAccessibility() {
65
- let diag = DiagnosticLog.shared
66
- let beforeCheck = AXIsProcessTrusted()
67
- diag.info("requestAccessibility: before=\(beforeCheck), prompting…")
68
- let opts = [kAXTrustedCheckOptionPrompt.takeUnretainedValue(): true] as CFDictionary
69
- let result = AXIsProcessTrustedWithOptions(opts)
70
- diag.info("AXIsProcessTrustedWithOptions(prompt) → \(result)")
71
- accessibility = result
72
- if !result {
73
- diag.warn("Accessibility not granted — opening System Settings. Toggle ON in Privacy → Accessibility.")
74
- openAccessibilitySettings()
75
- startPolling()
76
- }
77
- }
78
-
79
- /// Request Screen Recording permission — triggers the system prompt on first call,
80
- /// which adds lattices to the Screen Recording list. The user toggles it on in Settings.
81
- func requestScreenRecording() {
82
- let diag = DiagnosticLog.shared
83
- let beforeCheck = CGPreflightScreenCaptureAccess()
84
- diag.info("requestScreenRecording: before=\(beforeCheck), prompting…")
85
- let result = CGRequestScreenCaptureAccess()
86
- diag.info("CGRequestScreenCaptureAccess() → \(result)")
87
- screenRecording = result
88
- if !result {
89
- diag.warn("Screen Recording not granted — opening System Settings. Toggle ON in Privacy → Screen Recording.")
90
- openScreenRecordingSettings()
91
- startPolling()
92
- }
93
- }
94
-
95
- /// Opens System Settings → Privacy & Security → Accessibility
96
- func openAccessibilitySettings() {
97
- if let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility") {
98
- NSWorkspace.shared.open(url)
99
- }
100
- }
101
-
102
- /// Opens System Settings → Privacy & Security → Screen Recording
103
- func openScreenRecordingSettings() {
104
- if let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture") {
105
- NSWorkspace.shared.open(url)
106
- }
107
- }
108
-
109
- // MARK: - Polling
110
-
111
- /// Poll every 2 seconds to detect permission changes made in System Settings.
112
- private func startPolling() {
113
- guard pollTimer == nil else { return }
114
- pollTimer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: true) { [weak self] _ in
115
- DispatchQueue.main.async {
116
- self?.check()
117
- }
118
- }
119
- }
120
-
121
- private func stopPolling() {
122
- pollTimer?.invalidate()
123
- pollTimer = nil
124
- }
125
- }